diff options
Diffstat (limited to 'chromium/third_party/blink/renderer/core/layout/ng/layout_ng_fieldset.cc')
-rw-r--r-- | chromium/third_party/blink/renderer/core/layout/ng/layout_ng_fieldset.cc | 63 |
1 files changed, 55 insertions, 8 deletions
diff --git a/chromium/third_party/blink/renderer/core/layout/ng/layout_ng_fieldset.cc b/chromium/third_party/blink/renderer/core/layout/ng/layout_ng_fieldset.cc index cf4cd3d83c4..c564536a860 100644 --- a/chromium/third_party/blink/renderer/core/layout/ng/layout_ng_fieldset.cc +++ b/chromium/third_party/blink/renderer/core/layout/ng/layout_ng_fieldset.cc @@ -4,6 +4,7 @@ #include "third_party/blink/renderer/core/layout/ng/layout_ng_fieldset.h" +#include "third_party/blink/renderer/core/dom/layout_tree_builder_traversal.h" #include "third_party/blink/renderer/core/layout/layout_fieldset.h" #include "third_party/blink/renderer/core/layout/layout_object_factory.h" @@ -14,9 +15,50 @@ LayoutNGFieldset::LayoutNGFieldset(Element* element) SetChildrenInline(false); } +LayoutBlock* LayoutNGFieldset::FindAnonymousFieldsetContentBox() const { + LayoutObject* first_child = FirstChild(); + if (!first_child) + return nullptr; + if (first_child->IsAnonymous()) + return To<LayoutBlock>(first_child); + LayoutObject* last_child = first_child->NextSibling(); + DCHECK(!last_child || !last_child->NextSibling()); + if (last_child && last_child->IsAnonymous()) + return To<LayoutBlock>(last_child); + return nullptr; +} + void LayoutNGFieldset::AddChild(LayoutObject* new_child, LayoutObject* before_child) { - LayoutBlock* fieldset_content = To<LayoutBlock>(FirstChild()); + if (!new_child->IsText()) { + // Adding a child LayoutObject always causes reattach of <fieldset>. So + // |before_child| is always nullptr. + // See HTMLFieldSetElement::DidRecalcStyle(). + DCHECK(!before_child); + } else if (before_child && before_child->IsRenderedLegend()) { + // Whitespace changes resulting from removed nodes are handled in + // MarkForWhitespaceReattachment(), and don't trigger + // HTMLFieldSetElement::DidRecalcStyle(). So the fieldset is not + // reattached. We adjust |before_child| instead. + Node* before_node = + LayoutTreeBuilderTraversal::NextLayoutSibling(*before_child->GetNode()); + before_child = before_node ? before_node->GetLayoutObject() : nullptr; + } + + // https://html.spec.whatwg.org/C/#the-fieldset-and-legend-elements + // > * If the element has a rendered legend, then that element is expected + // > to be the first child box. + // > * The anonymous fieldset content box is expected to appear after the + // > rendered legend and is expected to contain the content (including + // > the '::before' and '::after' pseudo-elements) of the fieldset + // > element except for the rendered legend, if there is one. + + if (new_child->IsRenderedLegendCandidate() && + !LayoutFieldset::FindInFlowLegend(*this)) { + LayoutNGBlockFlow::AddChild(new_child, FirstChild()); + return; + } + LayoutBlock* fieldset_content = FindAnonymousFieldsetContentBox(); if (!fieldset_content) { // We wrap everything inside an anonymous child, which will take care of the // fieldset contents. This parent will only be responsible for the fieldset @@ -76,7 +118,7 @@ void LayoutNGFieldset::UpdateAnonymousChildStyle( child_style.SetPaddingBottom(StyleRef().PaddingBottom()); child_style.SetPaddingLeft(StyleRef().PaddingLeft()); - if (StyleRef().SpecifiesColumns()) { + if (StyleRef().SpecifiesColumns() && AllowsColumns()) { child_style.SetColumnCount(StyleRef().ColumnCount()); child_style.SetColumnWidth(StyleRef().ColumnWidth()); } else { @@ -100,12 +142,19 @@ void LayoutNGFieldset::UpdateAnonymousChildStyle( child_style.SetGridColumnStart(StyleRef().GridColumnStart()); child_style.SetGridRowEnd(StyleRef().GridRowEnd()); child_style.SetGridRowStart(StyleRef().GridRowStart()); + + // grid-template-columns, grid-template-rows child_style.SetGridTemplateColumns(StyleRef().GridTemplateColumns()); child_style.SetGridTemplateRows(StyleRef().GridTemplateRows()); child_style.SetNamedGridArea(StyleRef().NamedGridArea()); child_style.SetNamedGridAreaColumnCount( StyleRef().NamedGridAreaColumnCount()); child_style.SetNamedGridAreaRowCount(StyleRef().NamedGridAreaRowCount()); + child_style.SetImplicitNamedGridColumnLines( + StyleRef().ImplicitNamedGridColumnLines()); + child_style.SetImplicitNamedGridRowLines( + StyleRef().ImplicitNamedGridRowLines()); + child_style.SetRowGap(StyleRef().RowGap()); child_style.SetJustifyContent(StyleRef().JustifyContent()); @@ -171,16 +220,14 @@ bool LayoutNGFieldset::HitTestChildren(HitTestResult& result, } LayoutUnit LayoutNGFieldset::ScrollWidth() const { - const LayoutObject* child = FirstChild(); - if (child && child->IsAnonymous()) - return To<LayoutBox>(child)->ScrollWidth(); + if (const auto* content = FindAnonymousFieldsetContentBox()) + return content->ScrollWidth(); return LayoutNGBlockFlow::ScrollWidth(); } LayoutUnit LayoutNGFieldset::ScrollHeight() const { - const LayoutObject* child = FirstChild(); - if (child && child->IsAnonymous()) - return To<LayoutBox>(child)->ScrollHeight(); + if (const auto* content = FindAnonymousFieldsetContentBox()) + return content->ScrollHeight(); return LayoutNGBlockFlow::ScrollHeight(); } |