From 4c326fc5f6f64797764e7f32a9789b74665f2fec Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 23 Jul 2024 15:22:28 +0200 Subject: [PATCH] LibWeb: Implement :host and :host() selector matching The :host family of pseudo class selectors select the shadow host element when matching against a rule from within the element's shadow tree. This is a bit convoluted due to the fact that the document-level StyleComputer keeps track of *all* style rules, and not just the document-level ones. In the future, we should refactor style storage so that shadow roots have their own style scope, and we can simplify a lot of this. --- .../expected/host-pseudo-class-basic.txt | 19 ++++ .../Layout/input/host-pseudo-class-basic.html | 4 + .../Libraries/LibWeb/CSS/SelectorEngine.cpp | 103 ++++++++++++------ .../Libraries/LibWeb/CSS/SelectorEngine.h | 4 +- .../Libraries/LibWeb/CSS/StyleComputer.cpp | 32 +++++- Userland/Libraries/LibWeb/DOM/Element.cpp | 4 +- Userland/Libraries/LibWeb/DOM/ParentNode.cpp | 5 +- 7 files changed, 127 insertions(+), 44 deletions(-) create mode 100644 Tests/LibWeb/Layout/expected/host-pseudo-class-basic.txt create mode 100644 Tests/LibWeb/Layout/input/host-pseudo-class-basic.html diff --git a/Tests/LibWeb/Layout/expected/host-pseudo-class-basic.txt b/Tests/LibWeb/Layout/expected/host-pseudo-class-basic.txt new file mode 100644 index 00000000000..95bf12f74a1 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/host-pseudo-class-basic.txt @@ -0,0 +1,19 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x63 [BFC] children: not-inline + BlockContainer at (8,8) content-size 784x47 children: not-inline + BlockContainer
at (8,8) content-size 784x47 children: inline + frag 0 from BlockContainer start: 0, length: 0, rect: [23,23 343.96875x17] baseline: 28.296875 + BlockContainer
at (23,23) content-size 343.96875x17 inline-block [BFC] children: inline + InlineNode + frag 0 from TextNode start: 0, length: 42, rect: [23,23 343.96875x17] baseline: 13.296875 + "hello :host and :host()" + TextNode <#text> + TextNode <#text> + +ViewportPaintable (Viewport<#document>) [0,0 800x600] + PaintableWithLines (BlockContainer) [0,0 800x63] + PaintableWithLines (BlockContainer) [8,8 784x47] + PaintableWithLines (BlockContainer
) [8,8 784x47] + PaintableWithLines (BlockContainer
) [8,8 373.96875x47] + InlinePaintable (InlineNode) + TextPaintable (TextNode<#text>) diff --git a/Tests/LibWeb/Layout/input/host-pseudo-class-basic.html b/Tests/LibWeb/Layout/input/host-pseudo-class-basic.html new file mode 100644 index 00000000000..14a079cd4a3 --- /dev/null +++ b/Tests/LibWeb/Layout/input/host-pseudo-class-basic.html @@ -0,0 +1,4 @@ +