Commit 2146d7c4 authored by Koji Ishii's avatar Koji Ishii Committed by Commit Bot

[LayoutNG] Fix NeedsCollectInlines tp stop at atomic inlines

This patch stops propagation of setting NeedsCollectInlines
at atomic inlines.

Usually atomic inlines that have children are LayoutBlockFlow,
but LayoutSVGRoot is one example that are not LayoutBlockFlow.

This patch also clarifies the distinction when a parent of
object needs to collect from when the object itself needs to
collect.

Bug: 966699
Change-Id: I260824f3e8e211f842aa7990c6d504a3c72549b9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1631016
Commit-Queue: Emil A Eklund <eae@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Cr-Commit-Position: refs/heads/master@{#663760}
parent 1a5ea961
...@@ -944,9 +944,24 @@ void LayoutObject::SetNeedsCollectInlines() { ...@@ -944,9 +944,24 @@ void LayoutObject::SetNeedsCollectInlines() {
if (!RuntimeEnabledFeatures::LayoutNGEnabled()) if (!RuntimeEnabledFeatures::LayoutNGEnabled())
return; return;
if (NeedsCollectInlines())
return;
if (UNLIKELY(IsSVGChild())) if (UNLIKELY(IsSVGChild()))
return; return;
// Don't mark |LayoutFlowThread| because |CollectInlines()| skips them.
if (!IsLayoutFlowThread())
SetNeedsCollectInlines(true);
if (LayoutObject* parent = Parent())
parent->SetChildNeedsCollectInlines();
}
void LayoutObject::SetChildNeedsCollectInlines() {
if (!RuntimeEnabledFeatures::LayoutNGEnabled())
return;
LayoutObject* object = this; LayoutObject* object = this;
do { do {
// Should not stop at |LayoutFlowThread| as |CollectInlines()| skips them. // Should not stop at |LayoutFlowThread| as |CollectInlines()| skips them.
...@@ -957,7 +972,10 @@ void LayoutObject::SetNeedsCollectInlines() { ...@@ -957,7 +972,10 @@ void LayoutObject::SetNeedsCollectInlines() {
if (object->NeedsCollectInlines()) if (object->NeedsCollectInlines())
break; break;
object->SetNeedsCollectInlines(true); object->SetNeedsCollectInlines(true);
if (object->IsLayoutBlockFlow()) if (object->IsLayoutBlockFlow() ||
// Some LayoutReplaced have children (e.g., LayoutSVGRoot). Stop marking
// because their children belong to different context.
object->IsAtomicInlineLevel())
break; break;
object = object->Parent(); object = object->Parent();
} while (object); } while (object);
......
...@@ -1282,6 +1282,7 @@ class CORE_EXPORT LayoutObject : public ImageResourceObserver, ...@@ -1282,6 +1282,7 @@ class CORE_EXPORT LayoutObject : public ImageResourceObserver,
// Mark this object needing to re-run |CollectInlines()|. Ancestors may be // Mark this object needing to re-run |CollectInlines()|. Ancestors may be
// marked too if needed. // marked too if needed.
void SetNeedsCollectInlines(); void SetNeedsCollectInlines();
void SetChildNeedsCollectInlines();
void ClearNeedsCollectInlines() { SetNeedsCollectInlines(false); } void ClearNeedsCollectInlines() { SetNeedsCollectInlines(false); }
void MarkContainerChainForLayout(bool schedule_relayout = true, void MarkContainerChainForLayout(bool schedule_relayout = true,
......
...@@ -128,7 +128,7 @@ LayoutObject* LayoutObjectChildList::RemoveChildNode( ...@@ -128,7 +128,7 @@ LayoutObject* LayoutObjectChildList::RemoveChildNode(
} }
if (old_child->IsInLayoutNGInlineFormattingContext()) { if (old_child->IsInLayoutNGInlineFormattingContext()) {
owner->SetNeedsCollectInlines(); owner->SetChildNeedsCollectInlines();
} }
} }
...@@ -218,7 +218,7 @@ void LayoutObjectChildList::InsertChildNode(LayoutObject* owner, ...@@ -218,7 +218,7 @@ void LayoutObjectChildList::InsertChildNode(LayoutObject* owner,
if (owner->IsInLayoutNGInlineFormattingContext() || if (owner->IsInLayoutNGInlineFormattingContext() ||
(owner->EverHadLayout() && owner->ChildrenInline())) { (owner->EverHadLayout() && owner->ChildrenInline())) {
owner->SetNeedsCollectInlines(); owner->SetChildNeedsCollectInlines();
} }
} }
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "third_party/blink/renderer/core/layout/ng/ng_physical_box_fragment.h" #include "third_party/blink/renderer/core/layout/ng/ng_physical_box_fragment.h"
#include "third_party/blink/renderer/core/paint/ng/ng_paint_fragment.h" #include "third_party/blink/renderer/core/paint/ng/ng_paint_fragment.h"
#include "third_party/blink/renderer/core/style/computed_style.h" #include "third_party/blink/renderer/core/style/computed_style.h"
#include "third_party/blink/renderer/core/svg_names.h"
namespace blink { namespace blink {
...@@ -1388,6 +1389,22 @@ TEST_F(NGInlineNodeTest, ClearFirstInlineFragmentOnSplitFlow) { ...@@ -1388,6 +1389,22 @@ TEST_F(NGInlineNodeTest, ClearFirstInlineFragmentOnSplitFlow) {
EXPECT_EQ(line_box_fragment->FirstChild(), text_fragment_after_layout); EXPECT_EQ(line_box_fragment->FirstChild(), text_fragment_after_layout);
} }
TEST_F(NGInlineNodeTest, AddChildToSVGRoot) {
SetBodyInnerHTML(R"HTML(
<div id="container">
text
<svg id="svg"></svg>
</div>
)HTML");
Element* svg = GetElementById("svg");
svg->appendChild(GetDocument().CreateRawElement(svg_names::kTextTag));
GetDocument().UpdateStyleAndLayoutTree();
LayoutObject* container = GetLayoutObjectByElementId("container");
EXPECT_FALSE(container->NeedsCollectInlines());
}
// https://crbug.com/911220 // https://crbug.com/911220
TEST_F(NGInlineNodeTest, PreservedNewlineWithBidiAndRelayout) { TEST_F(NGInlineNodeTest, PreservedNewlineWithBidiAndRelayout) {
SetupHtml("container", SetupHtml("container",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment