Commit 38503dec authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

[LayoutNG] Stop NGInlineFragmentTraversal::SelfFragmentsOf() from collecting...

[LayoutNG] Stop NGInlineFragmentTraversal::SelfFragmentsOf() from collecting descendants of already collected inline fragments

The above function is used to compute rects of a LayoutInline, and is
especially useful when the LayoutInline doesn't generates its own boxes.

However, currently the function may collect a fragment even if there's
an inline ancestor fragment collected. For example:

<span id="culled">
  <span id="preserved" style="border: 1px solid black">
    text
  </span>
</span>

When calling SelfFragmentsOf() on SPAN#culled, it collects both the box
fragment of SPAN#preserved and the text fragment. This results in wrong
calculation of rects of culled inline elements, and also some failures
in client-rect-related tests.

This also conflicts with the legacy behavior, where if a LayoutInline has
already has an InlineBox, the legacy rect generation functions no longer
collect the descendant InlineBoxes.

This patch fixes the issue by storing a stack of currently entered
inline box fragments, and collect a fragment only if none of its
ancestor inline fragments is entered (which means all of them, if any,
are culled).

While being a standalone fix, this patch also helps preserving more inline
fragments to make hit testing inline elements easier.

Bug: 851075
Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_layout_ng
Change-Id: I8567f1258221c78806be1bb1628b8a63c7ea3281
Reviewed-on: https://chromium-review.googlesource.com/1091921
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568211}
parent b139d7a8
......@@ -475,9 +475,6 @@ crbug.com/591099 fast/css3-text/css3-text-justify/text-justify-distribute.html [
crbug.com/591099 fast/doctypes/001.html [ Failure ]
crbug.com/591099 fast/doctypes/003.html [ Failure ]
crbug.com/591099 fast/doctypes/004.html [ Failure ]
crbug.com/714962 fast/dom/Element/client-rect-list-argument.html [ Failure ]
crbug.com/591099 fast/dom/Element/getBoundingClientRect.html [ Failure ]
crbug.com/714962 fast/dom/Element/getClientRects.html [ Failure ]
crbug.com/591099 fast/dom/HTMLAreaElement/area-download.html [ Failure ]
crbug.com/714962 fast/dom/Range/getBoundingClientRect-linebreak-character.html [ Failure ]
crbug.com/591099 fast/dom/Window/window-lookup-precedence.html [ Failure ]
......
......@@ -4,7 +4,7 @@ layer at (0,0) size 800x289
LayoutNGBlockFlow {HTML} at (0,0) size 800x289
LayoutNGBlockFlow {BODY} at (8,16) size 784x257
LayoutNGBlockFlow {P} at (0,0) size 784x257
LayoutInline {<pseudo:before>} at (0,0) size 20x36 [color=#FF0000]
LayoutInline {<pseudo:before>} at (0,0) size 20x19 [color=#FF0000]
LayoutInline {<pseudo:first-letter>} at (0,0) size 20x36 [color=#00FF00]
LayoutTextFragment (anonymous) at (0,0) size 20x36
text run at (0,0) width 20: "T"
......
layer at (0,0) size 800x600
LayoutView at (0,0) size 800x600
layer at (0,0) size 800x289
LayoutNGBlockFlow {HTML} at (0,0) size 800x289
LayoutNGBlockFlow {BODY} at (8,16) size 784x257
LayoutNGBlockFlow {P} at (0,0) size 784x257
LayoutInline {<pseudo:before>} at (0,0) size 20x36 [color=#FF0000]
LayoutInline {<pseudo:first-letter>} at (0,0) size 20x36 [color=#00FF00]
LayoutTextFragment (anonymous) at (0,0) size 20x36
text run at (0,0) width 20: "T"
LayoutTextFragment (anonymous) at (0,0) size 0x0
LayoutText {#text} at (20,13) size 779x243
text run at (20,13) width 731: "his very long paragraph should have a big green first letter T. Dummy text. Dummy text. Dummy text. Dummy text."
text run at (0,37) width 779: "Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text."
text run at (0,57) width 779: "Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text."
text run at (0,77) width 779: "Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text."
text run at (0,97) width 779: "Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text."
text run at (0,117) width 779: "Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text."
text run at (0,137) width 779: "Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text."
text run at (0,157) width 779: "Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text."
text run at (0,177) width 779: "Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text."
text run at (0,197) width 779: "Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text."
text run at (0,217) width 779: "Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text."
text run at (0,237) width 83: "Dummy text."
......@@ -4,7 +4,7 @@ layer at (0,0) size 800x289
LayoutNGBlockFlow {html} at (0,0) size 800x289
LayoutNGBlockFlow {body} at (8,16) size 784x257
LayoutNGBlockFlow {p} at (0,0) size 784x257
LayoutInline {<pseudo:before>} at (0,0) size 20x36 [color=#FF0000]
LayoutInline {<pseudo:before>} at (0,0) size 20x19 [color=#FF0000]
LayoutInline {<pseudo:first-letter>} at (0,0) size 20x36 [color=#00FF00]
LayoutTextFragment (anonymous) at (0,0) size 20x36
text run at (0,0) width 20: "T"
......
layer at (0,0) size 800x600
LayoutView at (0,0) size 800x600
layer at (0,0) size 800x289
LayoutNGBlockFlow {html} at (0,0) size 800x289
LayoutNGBlockFlow {body} at (8,16) size 784x257
LayoutNGBlockFlow {p} at (0,0) size 784x257
LayoutInline {<pseudo:before>} at (0,0) size 20x36 [color=#FF0000]
LayoutInline {<pseudo:first-letter>} at (0,0) size 20x36 [color=#00FF00]
LayoutTextFragment (anonymous) at (0,0) size 20x36
text run at (0,0) width 20: "T"
LayoutTextFragment (anonymous) at (0,0) size 0x0
LayoutText {#text} at (20,13) size 779x243
text run at (20,13) width 731: "his very long paragraph should have a big green first letter T. Dummy text. Dummy text. Dummy text. Dummy text."
text run at (0,37) width 779: "Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text."
text run at (0,57) width 779: "Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text."
text run at (0,77) width 779: "Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text."
text run at (0,97) width 779: "Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text."
text run at (0,117) width 779: "Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text."
text run at (0,137) width 779: "Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text."
text run at (0,157) width 779: "Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text."
text run at (0,177) width 779: "Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text."
text run at (0,197) width 779: "Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text."
text run at (0,217) width 779: "Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text."
text run at (0,237) width 83: "Dummy text."
......@@ -3,7 +3,7 @@ layer at (0,0) size 800x600
layer at (0,0) size 800x289
LayoutNGBlockFlow {test} at (0,0) size 800x289
LayoutNGBlockFlow {p} at (0,16) size 800x257
LayoutInline {<pseudo:before>} at (0,0) size 20x36 [color=#FF0000]
LayoutInline {<pseudo:before>} at (0,0) size 20x19 [color=#FF0000]
LayoutInline {<pseudo:first-letter>} at (0,0) size 20x36 [color=#00FF00]
LayoutTextFragment (anonymous) at (0,0) size 20x36
text run at (0,0) width 20: "T"
......
layer at (0,0) size 800x600
LayoutView at (0,0) size 800x600
layer at (0,0) size 800x289
LayoutNGBlockFlow {test} at (0,0) size 800x289
LayoutNGBlockFlow {p} at (0,16) size 800x257
LayoutInline {<pseudo:before>} at (0,0) size 20x36 [color=#FF0000]
LayoutInline {<pseudo:first-letter>} at (0,0) size 20x36 [color=#00FF00]
LayoutTextFragment (anonymous) at (0,0) size 20x36
text run at (0,0) width 20: "T"
LayoutTextFragment (anonymous) at (0,0) size 0x0
LayoutText {#text} at (20,13) size 779x243
text run at (20,13) width 731: "his very long paragraph should have a big green first letter T. Dummy text. Dummy text. Dummy text. Dummy text."
text run at (0,37) width 779: "Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text."
text run at (0,57) width 779: "Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text."
text run at (0,77) width 779: "Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text."
text run at (0,97) width 779: "Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text."
text run at (0,117) width 779: "Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text."
text run at (0,137) width 779: "Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text."
text run at (0,157) width 779: "Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text."
text run at (0,177) width 779: "Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text."
text run at (0,197) width 779: "Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text."
text run at (0,217) width 779: "Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text. Dummy text."
text run at (0,237) width 83: "Dummy text."
layer at (0,0) size 800x600
LayoutView at (0,0) size 800x600
layer at (0,0) size 800x600
LayoutNGBlockFlow {HTML} at (0,0) size 800x600
LayoutNGBlockFlow {BODY} at (8,8) size 784x582
LayoutNGBlockFlow {P} at (0,0) size 784x20
LayoutInline {EM} at (0,0) size 628x19
LayoutText {#text} at (0,0) size 628x19
text run at (0,0) width 628: "When an :after rule has multiple pieces of content, older versions of Safari display them backwards."
LayoutNGBlockFlow {DIV} at (10,36) size 764x52 [border: (1px solid #000000)]
LayoutText {#text} at (11,21) size 44x19
text run at (11,21) width 44: "Inline: "
LayoutInline {<pseudo:after>} at (0,0) size 483x29
LayoutTextFragment (anonymous) at (55,21) size 235x19
text run at (55,21) width 235: "This should be before the green box. "
LayoutImage (anonymous) at (290,11) size 25x25
LayoutTextFragment (anonymous) at (315,21) size 223x19
text run at (315,21) width 223: " This should be after the green box."
LayoutNGBlockFlow {DIV} at (10,98) size 764x92 [border: (1px solid #000000)]
LayoutText {#text} at (11,61) size 84x19
text run at (11,61) width 84: "Inline-block: "
LayoutNGBlockFlow {<pseudo:after>} at (95,11) size 200x70
LayoutTextFragment (anonymous) at (0,0) size 199x49
text run at (0,0) width 199: "This should be before the green"
text run at (0,30) width 32: "box. "
LayoutImage (anonymous) at (32,20) size 25x25
LayoutTextFragment (anonymous) at (57,30) size 186x39
text run at (57,30) width 129: " This should be after"
text run at (0,50) width 90: "the green box."
LayoutNGBlockFlow {DIV} at (10,200) size 764x112 [border: (1px solid #000000)]
LayoutNGBlockFlow (anonymous) at (11,11) size 742x20
LayoutText {#text} at (0,0) size 42x19
text run at (0,0) width 42: "Block:"
LayoutNGBlockFlow {<pseudo:after>} at (11,31) size 200x70
LayoutTextFragment (anonymous) at (0,0) size 199x49
text run at (0,0) width 199: "This should be before the green"
text run at (0,30) width 32: "box. "
LayoutImage (anonymous) at (32,20) size 25x25
LayoutTextFragment (anonymous) at (57,30) size 186x39
text run at (57,30) width 129: " This should be after"
text run at (0,50) width 90: "the green box."
......@@ -16,7 +16,7 @@ layer at (0,0) size 800x600
LayoutText {#text} at (591,20) size 4x19
text run at (591,20) width 4: "."
LayoutNGBlockFlow {DIV} at (0,56) size 784x34
LayoutInline {<pseudo:before>} at (0,0) size 47x33
LayoutInline {<pseudo:before>} at (0,0) size 47x27
LayoutInline {<pseudo:first-letter>} at (0,0) size 18x33 [color=#008000]
LayoutTextFragment (anonymous) at (0,0) size 18x33
text run at (0,0) width 18: "T"
......
layer at (0,0) size 800x600
LayoutView at (0,0) size 800x600
layer at (0,0) size 800x155
LayoutNGBlockFlow {HTML} at (0,0) size 800x155
LayoutNGBlockFlow {BODY} at (8,16) size 784x131
LayoutNGBlockFlow {P} at (0,0) size 784x16
LayoutText {#text} at (0,0) size 496x16
text run at (0,0) width 496: "There should be an image below:"
LayoutNGBlockFlow (anonymous) at (0,32) size 784x99
LayoutInline {A} at (0,0) size 96x99
LayoutText {#text} at (0,0) size 0x0
layer at (8,48) size 96x96
LayoutImage {IMG} at (0,0) size 96x96
layer at (0,0) size 800x600
LayoutView at (0,0) size 800x600
layer at (0,0) size 800x600
LayoutNGBlockFlow {HTML} at (0,0) size 800x600
LayoutNGBlockFlow {BODY} at (8,8) size 784x584
LayoutNGBlockFlow (anonymous) at (0,0) size 784x22
LayoutInline {SPAN} at (0,0) size 181x22
LayoutText {#text} at (0,0) size 0x0
LayoutTextControl {INPUT} at (0,0) size 181x22 [bgcolor=#FFFFFF] [border: (2px inset #EEEEEE)]
LayoutText {#text} at (0,0) size 0x0
LayoutNGBlockFlow (anonymous) at (0,22) size 784x0
LayoutNGBlockFlow {DIV} at (0,0) size 784x0
LayoutNGBlockFlow (anonymous) at (0,22) size 784x0
LayoutInline {SPAN} at (0,0) size 0x0
layer at (10,11) size 177x16
LayoutBlockFlow {DIV} at (2,3) size 177x16
......@@ -153,9 +153,10 @@ class LayoutInlineCollector final : public NGPhysicalFragmentCollectorBase {
private:
void Visit() final {
if (!GetFragment().IsLineBox() &&
inclusive_descendants_.Contains(GetFragment().GetLayoutObject()))
inclusive_descendants_.Contains(GetFragment().GetLayoutObject())) {
Emit();
// TODO(xiaochengh): Don't visit children after emitting current fragment.
return;
}
VisitChildren();
}
......
......@@ -106,10 +106,7 @@ TEST_F(NGInlineFragmentTraversalTest, SelfFragmentsOf) {
// <b> generates two box fragments since its content is in two lines.
EXPECT_NEXT_BOX(iter, "filter");
EXPECT_NEXT_TEXT(iter, "bar");
EXPECT_NEXT_TEXT(iter, "\n");
EXPECT_NEXT_BOX(iter, "filter");
EXPECT_NEXT_TEXT(iter, "baz");
EXPECT_EQ(iter, descendants.end());
}
......
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