From 2960bf4ec8c74b92348b8a78bc159e85c09d266d Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Sat, 13 Jan 2024 13:11:31 +0100 Subject: [PATCH] LibWeb: Make inline paintables own their fragments The paintable tree structure more closely matches the painting order when fragments are owned by corresponding inline paintables. This change does not affect the layout tree, as it is more convenient for layout purposes to have all fragments owned by a block container in one place. Additionally, this improves performance significantly on pages with many fragments, as we no longer have to walk the ancestor chain up to the closest block container to determine if a fragment belongs to an inline paintable. --- Tests/LibWeb/Layout/expected/acid1.txt | 16 +- .../float-clear-by-line-break.txt | 8 +- ...ed-break-stops-non-whitespace-sequence.txt | 4 +- .../margin-padding-block-inline-start.txt | 4 +- .../margin-padding-block-inline.txt | 4 +- .../relpos-inline-element-js-offsets.txt | 14 +- .../relpos-inline-elements.txt | 12 +- .../br-should-not-generate-pseudo-before.txt | 6 +- .../LibWeb/Layout/expected/css-all-unset.txt | 8 +- .../Layout/expected/css-font-size-math.txt | 20 +- .../expected/css-namespace-rule-matches.txt | 4 +- .../expected/css-namespace-rule-no-match.txt | 4 +- .../css-namespace-tag-name-selector.txt | 4 +- .../Layout/expected/css-quotes-nesting.txt | 188 +++++++++--------- Tests/LibWeb/Layout/expected/details-open.txt | 4 +- .../display-contents-with-in-children.txt | 4 +- .../display-table-inline-children.txt | 2 +- .../Layout/expected/font-fractional-size.txt | 16 +- .../Layout/expected/font-size-legacy.txt | 4 +- .../expected/font-with-many-normal-values.txt | 22 +- .../nowrap-and-no-line-break-opportunity.txt | 12 +- ...containing-block-has-indefinite-height.txt | 4 +- .../expected/picture-source-media-query.txt | 2 +- Tests/LibWeb/Layout/expected/pre.txt | 4 +- ...w-tree-removed-from-dom-receives-event.txt | 4 +- .../space-is-soft-line-break-opportunity.txt | 8 +- .../row-outer-size-with-computed-size.txt | 4 +- Userland/Libraries/LibWeb/Dump.cpp | 54 +++-- .../Libraries/LibWeb/Layout/LayoutState.cpp | 45 +++-- Userland/Libraries/LibWeb/Layout/Node.cpp | 33 ++- .../LibWeb/Painting/InlinePaintable.cpp | 32 +-- .../LibWeb/Painting/InlinePaintable.h | 6 +- .../LibWeb/Painting/PaintableBox.cpp | 9 + .../Libraries/LibWeb/Painting/PaintableBox.h | 3 + 34 files changed, 310 insertions(+), 258 deletions(-) diff --git a/Tests/LibWeb/Layout/expected/acid1.txt b/Tests/LibWeb/Layout/expected/acid1.txt index 6eda7bf37c..1b100773a3 100644 --- a/Tests/LibWeb/Layout/expected/acid1.txt +++ b/Tests/LibWeb/Layout/expected/acid1.txt @@ -95,23 +95,23 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline "agents should be able to render the document elements above this paragraph" frag 2 from TextNode start: 167, length: 43, rect: [20,361 207.890625x13] baseline: 9.5 "indistinguishably (to the pixel) from this " - frag 3 from TextNode start: 0, length: 20, rect: [228,361 103.015625x13] baseline: 9.5 - "reference rendering," - frag 4 from TextNode start: 0, length: 31, rect: [331,361 159.671875x13] baseline: 9.5 + frag 3 from TextNode start: 0, length: 31, rect: [331,361 159.671875x13] baseline: 9.5 " (except font rasterization and" - frag 5 from TextNode start: 32, length: 89, rect: [20,374 465.015625x13] baseline: 9.5 + frag 4 from TextNode start: 32, length: 89, rect: [20,374 465.015625x13] baseline: 9.5 "form widgets). All discrepancies should be traceable to CSS1 implementation shortcomings." - frag 6 from TextNode start: 122, length: 67, rect: [20,387 345.546875x13] baseline: 9.5 + frag 5 from TextNode start: 122, length: 67, rect: [20,387 345.546875x13] baseline: 9.5 "Once you have finished evaluating this test, you can return to the " - frag 7 from TextNode start: 0, length: 11, rect: [366,387 59.890625x13] baseline: 9.5 - "parent page" - frag 8 from TextNode start: 0, length: 1, rect: [425,387 2.71875x13] baseline: 9.5 + frag 6 from TextNode start: 0, length: 1, rect: [425,387 2.71875x13] baseline: 9.5 "." TextNode <#text> InlineNode + frag 0 from TextNode start: 0, length: 20, rect: [228,361 103.015625x13] baseline: 9.5 + "reference rendering," TextNode <#text> TextNode <#text> InlineNode + frag 0 from TextNode start: 0, length: 11, rect: [366,387 59.890625x13] baseline: 9.5 + "parent page" TextNode <#text> TextNode <#text> BlockContainer <(anonymous)> at (20,400) content-size 480x0 children: inline diff --git a/Tests/LibWeb/Layout/expected/block-and-inline/float-clear-by-line-break.txt b/Tests/LibWeb/Layout/expected/block-and-inline/float-clear-by-line-break.txt index 17b3b870f3..c96941ed95 100644 --- a/Tests/LibWeb/Layout/expected/block-and-inline/float-clear-by-line-break.txt +++ b/Tests/LibWeb/Layout/expected/block-and-inline/float-clear-by-line-break.txt @@ -1,15 +1,13 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline BlockContainer at (0,0) content-size 800x600 [BFC] children: not-inline BlockContainer at (8,8) content-size 784x34 children: inline - frag 0 from TextNode start: 0, length: 1, rect: [108,8 6.34375x17] baseline: 13.296875 - "1" - frag 1 from TextNode start: 0, length: 1, rect: [108,25 8.8125x17] baseline: 13.296875 - "2" BlockContainer at (8,8) content-size 100x17 floating [BFC] children: inline frag 0 from TextNode start: 0, length: 1, rect: [8,8 14.265625x17] baseline: 13.296875 "A" TextNode <#text> InlineNode + frag 0 from TextNode start: 0, length: 1, rect: [108,8 6.34375x17] baseline: 13.296875 + "1" TextNode <#text> TextNode <#text> BreakNode
@@ -19,6 +17,8 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline "B" TextNode <#text> InlineNode + frag 0 from TextNode start: 0, length: 1, rect: [108,25 8.8125x17] baseline: 13.296875 + "2" TextNode <#text> ViewportPaintable (Viewport<#document>) [0,0 800x600] diff --git a/Tests/LibWeb/Layout/expected/block-and-inline/forced-break-stops-non-whitespace-sequence.txt b/Tests/LibWeb/Layout/expected/block-and-inline/forced-break-stops-non-whitespace-sequence.txt index 59aa92361e..64521cdbd8 100644 --- a/Tests/LibWeb/Layout/expected/block-and-inline/forced-break-stops-non-whitespace-sequence.txt +++ b/Tests/LibWeb/Layout/expected/block-and-inline/forced-break-stops-non-whitespace-sequence.txt @@ -2,9 +2,9 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline BlockContainer at (0,0) content-size 800x600 [BFC] children: not-inline BlockContainer at (8,16) content-size 784x19 children: not-inline BlockContainer
 at (9,17) content-size 782x17 children: inline
-        frag 0 from TextNode start: 0, length: 1, rect: [9,17 8x17] baseline: 13.296875
-            " "
         InlineNode 
+          frag 0 from TextNode start: 0, length: 1, rect: [9,17 8x17] baseline: 13.296875
+              " "
           TextNode <#text>
         TextNode <#text>
 
diff --git a/Tests/LibWeb/Layout/expected/block-and-inline/margin-padding-block-inline-start.txt b/Tests/LibWeb/Layout/expected/block-and-inline/margin-padding-block-inline-start.txt
index 9dd339218c..7a38d34245 100644
--- a/Tests/LibWeb/Layout/expected/block-and-inline/margin-padding-block-inline-start.txt
+++ b/Tests/LibWeb/Layout/expected/block-and-inline/margin-padding-block-inline-start.txt
@@ -3,9 +3,9 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline
     BlockContainer  at (10,10) content-size 500x81 children: not-inline
       BlockContainer  at (51,21) content-size 413x49 children: not-inline
         BlockContainer  at (92,32) content-size 326x17 children: inline
-          frag 0 from TextNode start: 0, length: 5, rect: [93,32 39.78125x17] baseline: 13.296875
-              "Hello"
           InlineNode 
+            frag 0 from TextNode start: 0, length: 5, rect: [93,32 39.78125x17] baseline: 13.296875
+                "Hello"
             TextNode <#text>
 
 ViewportPaintable (Viewport<#document>) [0,0 800x600]
diff --git a/Tests/LibWeb/Layout/expected/block-and-inline/margin-padding-block-inline.txt b/Tests/LibWeb/Layout/expected/block-and-inline/margin-padding-block-inline.txt
index dcb98015e1..0197b88adb 100644
--- a/Tests/LibWeb/Layout/expected/block-and-inline/margin-padding-block-inline.txt
+++ b/Tests/LibWeb/Layout/expected/block-and-inline/margin-padding-block-inline.txt
@@ -3,9 +3,9 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline
     BlockContainer  at (10,10) content-size 500x101 children: not-inline
       BlockContainer  at (31,21) content-size 458x79 children: not-inline
         BlockContainer  at (72,52) content-size 376x17 children: inline
-          frag 0 from TextNode start: 0, length: 5, rect: [73,52 39.78125x17] baseline: 13.296875
-              "Hello"
           InlineNode 
+            frag 0 from TextNode start: 0, length: 5, rect: [73,52 39.78125x17] baseline: 13.296875
+                "Hello"
             TextNode <#text>
 
 ViewportPaintable (Viewport<#document>) [0,0 800x600]
diff --git a/Tests/LibWeb/Layout/expected/block-and-inline/relpos-inline-element-js-offsets.txt b/Tests/LibWeb/Layout/expected/block-and-inline/relpos-inline-element-js-offsets.txt
index ca588a6243..e5ba2553d6 100644
--- a/Tests/LibWeb/Layout/expected/block-and-inline/relpos-inline-element-js-offsets.txt
+++ b/Tests/LibWeb/Layout/expected/block-and-inline/relpos-inline-element-js-offsets.txt
@@ -2,17 +2,17 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline
   BlockContainer  at (0,0) content-size 800x600 [BFC] children: not-inline
     BlockContainer  at (8,8) content-size 784x152 children: not-inline
       BlockContainer <(anonymous)> at (8,8) content-size 784x17 children: inline
-        frag 0 from TextNode start: 0, length: 5, rect: [8,8 36.40625x17] baseline: 13.296875
-            "well "
-        frag 1 from TextNode start: 0, length: 6, rect: [44,33 44.84375x17] baseline: 13.296875
-            "hello "
-        frag 2 from TextNode start: 0, length: 7, rect: [89,58 55.359375x17] baseline: 13.296875
-            "friends"
         InlineNode 
+          frag 0 from TextNode start: 0, length: 5, rect: [8,8 36.40625x17] baseline: 13.296875
+              "well "
           TextNode <#text>
           InlineNode 
+            frag 0 from TextNode start: 0, length: 6, rect: [44,33 44.84375x17] baseline: 13.296875
+                "hello "
             TextNode <#text>
             InlineNode 
+              frag 0 from TextNode start: 0, length: 7, rect: [89,58 55.359375x17] baseline: 13.296875
+                  "friends"
               TextNode <#text>
         TextNode <#text>
       BlockContainer 
at (8,25) content-size 784x135 children: not-inline @@ -36,7 +36,7 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline ViewportPaintable (Viewport<#document>) [0,0 800x600] PaintableWithLines (BlockContainer) [0,0 800x600] PaintableWithLines (BlockContainer) [8,8 784x152] overflow: [8,8 784x168] - PaintableWithLines (BlockContainer(anonymous)) [8,8 784x17] overflow: [8,8 784x67] + PaintableWithLines (BlockContainer(anonymous)) [8,8 784x17] InlinePaintable (InlineNode) TextPaintable (TextNode<#text>) InlinePaintable (InlineNode) diff --git a/Tests/LibWeb/Layout/expected/block-and-inline/relpos-inline-elements.txt b/Tests/LibWeb/Layout/expected/block-and-inline/relpos-inline-elements.txt index 7d0496e2f3..deba5cb1de 100644 --- a/Tests/LibWeb/Layout/expected/block-and-inline/relpos-inline-elements.txt +++ b/Tests/LibWeb/Layout/expected/block-and-inline/relpos-inline-elements.txt @@ -3,24 +3,24 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline BlockContainer at (8,8) content-size 784x17 children: inline frag 0 from TextNode start: 0, length: 4, rect: [8,8 35.15625x17] baseline: 13.296875 "foo " - frag 1 from TextNode start: 0, length: 3, rect: [43,33 27.640625x17] baseline: 13.296875 - "bar" - frag 2 from TextNode start: 0, length: 1, rect: [71,8 8x17] baseline: 13.296875 + frag 1 from TextNode start: 0, length: 1, rect: [71,8 8x17] baseline: 13.296875 " " - frag 3 from TextNode start: 0, length: 3, rect: [54,58 27.203125x17] baseline: 13.296875 - "baz" TextNode <#text> InlineNode + frag 0 from TextNode start: 0, length: 3, rect: [43,33 27.640625x17] baseline: 13.296875 + "bar" TextNode <#text> TextNode <#text> InlineNode InlineNode + frag 0 from TextNode start: 0, length: 3, rect: [54,58 27.203125x17] baseline: 13.296875 + "baz" TextNode <#text> TextNode <#text> ViewportPaintable (Viewport<#document>) [0,0 800x600] PaintableWithLines (BlockContainer) [0,0 800x600] - PaintableWithLines (BlockContainer) [8,8 784x17] overflow: [8,8 784x67] + PaintableWithLines (BlockContainer) [8,8 784x17] overflow: [8,8 784x42] TextPaintable (TextNode<#text>) InlinePaintable (InlineNode) TextPaintable (TextNode<#text>) diff --git a/Tests/LibWeb/Layout/expected/br-should-not-generate-pseudo-before.txt b/Tests/LibWeb/Layout/expected/br-should-not-generate-pseudo-before.txt index 9a673d2168..864e5a550a 100644 --- a/Tests/LibWeb/Layout/expected/br-should-not-generate-pseudo-before.txt +++ b/Tests/LibWeb/Layout/expected/br-should-not-generate-pseudo-before.txt @@ -2,11 +2,11 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline BlockContainer at (0,0) content-size 800x83 [BFC] children: not-inline BlockContainer at (8,16) content-size 784x67 children: not-inline BlockContainer

at (8,16) content-size 784x17 children: inline - frag 0 from TextNode start: 0, length: 1, rect: [8,16 10.625x17] baseline: 13.296875 - "+" - frag 1 from TextNode start: 0, length: 36, rect: [19,16 300x17] baseline: 13.296875 + frag 0 from TextNode start: 0, length: 36, rect: [19,16 300x17] baseline: 13.296875 "P should generate a ::before pseudo." InlineNode <(anonymous)> + frag 0 from TextNode start: 0, length: 1, rect: [8,16 10.625x17] baseline: 13.296875 + "+" TextNode <#text> TextNode <#text> BlockContainer <(anonymous)> at (8,49) content-size 784x34 children: inline diff --git a/Tests/LibWeb/Layout/expected/css-all-unset.txt b/Tests/LibWeb/Layout/expected/css-all-unset.txt index fb66b4b871..c16f70bf4b 100644 --- a/Tests/LibWeb/Layout/expected/css-all-unset.txt +++ b/Tests/LibWeb/Layout/expected/css-all-unset.txt @@ -1,13 +1,13 @@ Viewport <#document> at (0,0) content-size 800x600 children: inline - frag 0 from TextNode start: 1, length: 18, rect: [0,0 134.984375x17] baseline: 13.296875 - "* { all: unset; } " - frag 1 from TextNode start: 0, length: 13, rect: [135,0 103.140625x17] baseline: 13.296875 - "Hello friends" InlineNode InlineNode InlineNode