diff --git a/Libraries/LibWeb/CSS/StyleComputer.cpp b/Libraries/LibWeb/CSS/StyleComputer.cpp index 459991f48e5..2f2c9de87cf 100644 --- a/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -2461,11 +2461,20 @@ GC::Ptr StyleComputer::compute_style_impl(DOM::AbstractEleme { build_rule_cache_if_needed(); - // Special path for elements that use pseudo element as style selector + // Special path for elements that represent a pseudo-element in some element's internal shadow tree. if (abstract_element.element().use_pseudo_element().has_value()) { auto& element = abstract_element.element(); - auto& parent_element = as(*element.root().parent_or_shadow_host()); - auto style = compute_style({ parent_element, element.use_pseudo_element() }); + auto& host_element = *element.root().parent_or_shadow_host_element(); + + // We have to decide where to inherit from. If the pseudo-element has a parent element, + // we inherit from that. Otherwise, we inherit from the host element in the light DOM. + DOM::AbstractElement abstract_element_for_pseudo_element { host_element, element.use_pseudo_element() }; + if (auto parent_element = element.parent_element()) + abstract_element_for_pseudo_element.set_inheritance_override(*parent_element); + else + abstract_element_for_pseudo_element.set_inheritance_override(host_element); + + auto style = compute_style(abstract_element_for_pseudo_element); // Merge back inline styles if (auto inline_style = element.inline_style()) { diff --git a/Libraries/LibWeb/DOM/AbstractElement.cpp b/Libraries/LibWeb/DOM/AbstractElement.cpp index 1cd2c5ef449..25365eed142 100644 --- a/Libraries/LibWeb/DOM/AbstractElement.cpp +++ b/Libraries/LibWeb/DOM/AbstractElement.cpp @@ -19,6 +19,7 @@ AbstractElement::AbstractElement(GC::Ref element, Optional AbstractElement::parent_element() const Optional AbstractElement::element_to_inherit_style_from() const { + if (m_inheritance_override) + return AbstractElement { *m_inheritance_override }; + GC::Ptr element = m_element->element_to_inherit_style_from(m_pseudo_element); if (!element) diff --git a/Libraries/LibWeb/DOM/AbstractElement.h b/Libraries/LibWeb/DOM/AbstractElement.h index 88379e75a9e..691b4639ed3 100644 --- a/Libraries/LibWeb/DOM/AbstractElement.h +++ b/Libraries/LibWeb/DOM/AbstractElement.h @@ -35,6 +35,8 @@ public: Optional previous_sibling_in_tree_order() { return walk_layout_tree(WalkMethod::PreviousSibling); } bool is_before(AbstractElement const&) const; + void set_inheritance_override(GC::Ref element) { m_inheritance_override = element; } + GC::Ptr computed_properties() const; void set_custom_properties(OrderedHashMap&& custom_properties); @@ -63,6 +65,8 @@ private: GC::Ref m_element; Optional m_pseudo_element; + + GC::Ptr m_inheritance_override; }; } diff --git a/Tests/LibWeb/Layout/expected/empty-editable-shows-cursor.txt b/Tests/LibWeb/Layout/expected/empty-editable-shows-cursor.txt index 042f2ce1d02..2a3ebec554b 100644 --- a/Tests/LibWeb/Layout/expected/empty-editable-shows-cursor.txt +++ b/Tests/LibWeb/Layout/expected/empty-editable-shows-cursor.txt @@ -23,12 +23,10 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] children: not- BlockContainer
at [11,10] flex-item [0+0+0 0 0+0+0] [0+0+0 18 0+0+0] [BFC] children: inline frag 0 from TextNode start: 0, length: 0, rect: [11,10 0x18] baseline: 13.796875 TextNode <#text> (not painted) - BlockContainer <(anonymous)> at [11,10] flex-item [0+0+0 36.84375 0+0+0] [0+0+0 18 0+0+0] [BFC] children: inline - frag 0 from BlockContainer start: 0, length: 0, rect: [11,10 36.84375x18] baseline: 13.796875 - BlockContainer
at [11,10] inline-block [0+0+0 36.84375 0+0+0] [0+0+0 18 0+0+0] [BFC] children: inline - frag 0 from TextNode start: 0, length: 5, rect: [11,10 36.84375x18] baseline: 13.796875 - "hello" - TextNode <#text> (not painted) + BlockContainer
at [11,10] flex-item [0+0+0 196 0+0+0] [0+0+0 18 0+0+0] [BFC] children: inline + frag 0 from TextNode start: 0, length: 5, rect: [11,10 36.84375x18] baseline: 13.796875 + "hello" + TextNode <#text> (not painted) TextNode <#text> (not painted) BlockContainer