From 6a549f62702e8b733dd4fc0caf1fa3e114243070 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Sun, 13 Oct 2024 21:29:47 +0200 Subject: [PATCH] LibWeb: Replace InlinePaintable with PaintableWithLines created per line InlinePaintable was an ad-hoc paintable type required to support the fragmentation of inline nodes across multiple lines. It existed because there was no way to associate multiple paintables with a single layout node. This resulted in a lot of duplicated code between PaintableBox and InlinePaintable. For example, most of the CSS properties like background, border, shadows, etc. and hit-testing are almost identical for both of them. However, the code had to be duplicated to account for the fact that InlinePaintable creates a box for each line. And we had quite many places that operate on paintables with a code like: ``` if (box.is_paintable_box()) { // do something } else (box.is_inline_paintable()) { // do exactly the same as for paintable box but using InlinePaintable } ``` This change replaces the usage of `InlinePaintable` with `PaintableWithLines` created for each line, which is now possible because we support having multiple paintables per layout node. By doing that, we remove lots of duplicated code and bring our implementation closer to the spec. --- Tests/LibWeb/Layout/expected/acid1.txt | 6 +- .../float-clear-by-line-break.txt | 4 +- ...ed-break-stops-non-whitespace-sequence.txt | 2 +- .../inline-block-vertical-align-middle.txt | 2 +- ...hat-starts-with-collapsible-whitespace.txt | 4 +- .../margin-padding-block-inline-start.txt | 2 +- .../margin-padding-block-inline.txt | 2 +- .../relpos-inline-element-js-offsets.txt | 6 +- .../relpos-inline-elements.txt | 8 +- .../br-should-not-generate-pseudo-before.txt | 2 +- .../LibWeb/Layout/expected/css-all-unset.txt | 6 +- .../expected/css-attr-typed-fallback.txt | 3 +- .../Layout/expected/css-counters/basic.txt | 20 +-- .../css-counters/counters-function.txt | 30 ++-- .../expected/css-counters/hidden-elements.txt | 10 +- .../Layout/expected/css-font-size-math.txt | 10 +- .../expected/css-namespace-rule-matches.txt | 2 +- .../expected/css-namespace-rule-no-match.txt | 2 +- .../css-namespace-tag-name-selector.txt | 2 +- .../Layout/expected/css-quotes-nesting.txt | 80 ++++------ Tests/LibWeb/Layout/expected/details-open.txt | 2 +- .../Layout/expected/dialog-open-non-modal.txt | 2 +- .../display-contents-with-in-children.txt | 2 +- .../display-table-inline-children.txt | 2 +- .../Layout/expected/font-fractional-size.txt | 6 +- .../Layout/expected/font-size-legacy.txt | 2 +- .../expected/font-with-many-normal-values.txt | 8 +- .../expected/host-pseudo-class-basic.txt | 2 +- .../nowrap-and-no-line-break-opportunity.txt | 8 +- .../Layout/expected/overflow-with-padding.txt | 2 +- ...containing-block-has-indefinite-height.txt | 2 +- .../expected/picture-source-media-query.txt | 4 +- Tests/LibWeb/Layout/expected/pre.txt | 2 +- ...w-tree-removed-from-dom-receives-event.txt | 2 +- .../space-is-soft-line-break-opportunity.txt | 6 +- .../Layout/expected/span-with-padding.txt | 2 +- ...ith-zero-intrinsic-size-and-no-viewbox.txt | 2 +- .../row-outer-size-with-computed-size.txt | 2 +- .../Layout/expected/vertical-align-middle.txt | 2 +- .../writing-modes-direction-inline.txt | 6 +- .../expected/HTML/dimension-attributes.txt | 12 +- .../hit_testing/inline-stacking-context.html | 2 +- Userland/Libraries/LibWeb/DOM/Element.cpp | 4 +- Userland/Libraries/LibWeb/Dump.cpp | 12 +- Userland/Libraries/LibWeb/Forward.h | 1 + Userland/Libraries/LibWeb/Layout/Box.cpp | 31 ---- Userland/Libraries/LibWeb/Layout/Box.h | 4 - .../Libraries/LibWeb/Layout/InlineNode.cpp | 13 +- Userland/Libraries/LibWeb/Layout/InlineNode.h | 2 +- .../Libraries/LibWeb/Layout/LayoutState.cpp | 151 +++++++++++------- Userland/Libraries/LibWeb/Layout/Node.cpp | 29 ++++ Userland/Libraries/LibWeb/Layout/Node.h | 5 + .../LibWeb/Painting/LabelablePaintable.cpp | 4 +- .../LibWeb/Painting/MediaPaintable.cpp | 6 +- .../LibWeb/Painting/PaintableBox.cpp | 65 +++++--- .../Libraries/LibWeb/Painting/PaintableBox.h | 32 ++-- .../LibWeb/Painting/ViewportPaintable.cpp | 11 +- .../LibWeb/Painting/ViewportPaintable.h | 1 + 58 files changed, 364 insertions(+), 290 deletions(-) diff --git a/Tests/LibWeb/Layout/expected/acid1.txt b/Tests/LibWeb/Layout/expected/acid1.txt index 7379b1b2706..c56a8e445c6 100644 --- a/Tests/LibWeb/Layout/expected/acid1.txt +++ b/Tests/LibWeb/Layout/expected/acid1.txt @@ -135,7 +135,7 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600] PaintableWithLines (BlockContainer

) [235,55 139.96875x10] TextPaintable (TextNode<#text>) PaintableWithLines (BlockContainer(anonymous)) [235,65 139.96875x0] - InlinePaintable (InlineNode

) + PaintableWithLines (InlineNode) PaintableWithLines (BlockContainer

) [235,65 139.96875x19] TextPaintable (TextNode<#text>) RadioButtonPaintable (RadioButton) [263,65 12x12] @@ -158,10 +158,10 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600] PaintableWithLines (BlockContainer(anonymous)) [20,30 480x0] PaintableWithLines (BlockContainer

) [20,335 480x65] TextPaintable (TextNode<#text>) - InlinePaintable (InlineNode) + PaintableWithLines (InlineNode) TextPaintable (TextNode<#text>) TextPaintable (TextNode<#text>) - InlinePaintable (InlineNode) + PaintableWithLines (InlineNode) TextPaintable (TextNode<#text>) TextPaintable (TextNode<#text>) PaintableWithLines (BlockContainer(anonymous)) [20,400 480x0] 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 c96941ed95a..2a0949a8709 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 @@ -26,9 +26,9 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600] PaintableWithLines (BlockContainer) [8,8 784x34] PaintableWithLines (BlockContainer.a) [8,8 100x17] TextPaintable (TextNode<#text>) - InlinePaintable (InlineNode) + PaintableWithLines (InlineNode) TextPaintable (TextNode<#text>) PaintableWithLines (BlockContainer.a) [8,25 100x17] TextPaintable (TextNode<#text>) - InlinePaintable (InlineNode) + PaintableWithLines (InlineNode) TextPaintable (TextNode<#text>) 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 64521cdbd8b..699f4c2f365 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 @@ -12,5 +12,5 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600] PaintableWithLines (BlockContainer) [0,0 800x600] PaintableWithLines (BlockContainer) [8,16 784x19] PaintableWithLines (BlockContainer

) [8,16 784x19]
-        InlinePaintable (InlineNode)
+        PaintableWithLines (InlineNode)
           TextPaintable (TextNode<#text>)
diff --git a/Tests/LibWeb/Layout/expected/block-and-inline/inline-block-vertical-align-middle.txt b/Tests/LibWeb/Layout/expected/block-and-inline/inline-block-vertical-align-middle.txt
index 7b39efb7f13..daff1aa4fd9 100644
--- a/Tests/LibWeb/Layout/expected/block-and-inline/inline-block-vertical-align-middle.txt
+++ b/Tests/LibWeb/Layout/expected/block-and-inline/inline-block-vertical-align-middle.txt
@@ -11,6 +11,6 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline
 ViewportPaintable (Viewport<#document>) [0,0 800x600]
   PaintableWithLines (BlockContainer) [0,0 800x116]
     PaintableWithLines (BlockContainer) [8,8 784x100]
-      InlinePaintable (InlineNode)
+      PaintableWithLines (InlineNode)
         TextPaintable (TextNode<#text>)
         PaintableWithLines (BlockContainer.thing) [43,8 100x100]
diff --git a/Tests/LibWeb/Layout/expected/block-and-inline/leading-margin-on-inline-content-that-starts-with-collapsible-whitespace.txt b/Tests/LibWeb/Layout/expected/block-and-inline/leading-margin-on-inline-content-that-starts-with-collapsible-whitespace.txt
index 09cea00ce30..3c62197bdee 100644
--- a/Tests/LibWeb/Layout/expected/block-and-inline/leading-margin-on-inline-content-that-starts-with-collapsible-whitespace.txt
+++ b/Tests/LibWeb/Layout/expected/block-and-inline/leading-margin-on-inline-content-that-starts-with-collapsible-whitespace.txt
@@ -14,7 +14,7 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline
 ViewportPaintable (Viewport<#document>) [0,0 800x600]
   PaintableWithLines (BlockContainer) [0,0 800x33]
     PaintableWithLines (BlockContainer) [8,8 784x17]
-      InlinePaintable (InlineNode
) + PaintableWithLines (InlineNode
) TextPaintable (TextNode<#text>) - InlinePaintable (InlineNode
) + PaintableWithLines (InlineNode
) TextPaintable (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 7a38d34245d..56a2e9ffe89 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 @@ -13,5 +13,5 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600] PaintableWithLines (BlockContainer) [9,9 502x83] PaintableWithLines (BlockContainer
.a) [10,10 500x81] PaintableWithLines (BlockContainer
.b) [91,31 328x19] - InlinePaintable (InlineNode) + PaintableWithLines (InlineNode) TextPaintable (TextNode<#text>) 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 0197b88adbe..e3092abf5d4 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 @@ -13,5 +13,5 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600] PaintableWithLines (BlockContainer) [9,9 502x103] PaintableWithLines (BlockContainer
.a) [10,10 500x101] PaintableWithLines (BlockContainer
.b) [71,51 378x19] - InlinePaintable (InlineNode) + PaintableWithLines (InlineNode) TextPaintable (TextNode<#text>) 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 dd47cd5571f..a1c900bb1a1 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 @@ -37,11 +37,11 @@ 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] - InlinePaintable (InlineNode) + PaintableWithLines (InlineNode) TextPaintable (TextNode<#text>) - InlinePaintable (InlineNode) + PaintableWithLines (InlineNode) TextPaintable (TextNode<#text>) - InlinePaintable (InlineNode) + PaintableWithLines (InlineNode) TextPaintable (TextNode<#text>) PaintableWithLines (BlockContainer
) [8,25 784x135] PaintableWithLines (BlockContainer(anonymous)) [8,25 784x68] 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 deba5cb1de7..944c8e86afd 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 @@ -20,11 +20,11 @@ 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 784x17] overflow: [8,8 784x42] + PaintableWithLines (BlockContainer) [8,8 784x17] TextPaintable (TextNode<#text>) - InlinePaintable (InlineNode) + PaintableWithLines (InlineNode) TextPaintable (TextNode<#text>) TextPaintable (TextNode<#text>) - InlinePaintable (InlineNode) - InlinePaintable (InlineNode) + PaintableWithLines (InlineNode) + PaintableWithLines (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 864e5a550ad..3b9d8baa737 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 @@ -19,7 +19,7 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600] PaintableWithLines (BlockContainer) [0,0 800x83] PaintableWithLines (BlockContainer) [8,16 784x67] PaintableWithLines (BlockContainer

) [8,16 784x17] - InlinePaintable (InlineNode(anonymous)) + PaintableWithLines (InlineNode(anonymous)) TextPaintable (TextNode<#text>) TextPaintable (TextNode<#text>) PaintableWithLines (BlockContainer(anonymous)) [8,49 784x34] diff --git a/Tests/LibWeb/Layout/expected/css-all-unset.txt b/Tests/LibWeb/Layout/expected/css-all-unset.txt index 4ec6d920d4a..c79c13c6530 100644 --- a/Tests/LibWeb/Layout/expected/css-all-unset.txt +++ b/Tests/LibWeb/Layout/expected/css-all-unset.txt @@ -12,8 +12,8 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline ViewportPaintable (Viewport<#document>) [0,0 800x600] PaintableWithLines (BlockContainer) [0,0 800x17] - InlinePaintable (InlineNode) - InlinePaintable (InlineNode