LibWeb: Better CSS inheritance for nodes that represent a pseudo-element

When we compute style for elements inside a UA-internal shadow tree that
represent a pseudo-element (e.g ::placeholder), we actually run the
StyleComputer machinery for (host element :: pseudo-element).

While that lets us match the correct selectors, it was incorrectly
applying CSS inheritance, since we'd also then inherit from whatever was
above the host element in the tree.

This patch fixes the issue by introducing an inheritance override in
AbstractElement and then using that to force inheritance from whatever
is actually directly above in the DOM for these elements instead of
jumping all the way up past the host.

This fixes an issue where `text-align: center` on input type=text
elements would render the main text centered but placeholder text was
still left-aligned.
This commit is contained in:
Andreas Kling 2025-10-20 11:21:55 +02:00 committed by Andreas Kling
parent 9e064bd3ff
commit d17f666a8c
Notes: github-actions[bot] 2025-10-21 14:43:14 +00:00
8 changed files with 79 additions and 39 deletions

View file

@ -35,6 +35,8 @@ public:
Optional<AbstractElement> previous_sibling_in_tree_order() { return walk_layout_tree(WalkMethod::PreviousSibling); }
bool is_before(AbstractElement const&) const;
void set_inheritance_override(GC::Ref<Element> element) { m_inheritance_override = element; }
GC::Ptr<CSS::ComputedProperties const> computed_properties() const;
void set_custom_properties(OrderedHashMap<FlyString, CSS::StyleProperty>&& custom_properties);
@ -63,6 +65,8 @@ private:
GC::Ref<Element> m_element;
Optional<CSS::PseudoElement> m_pseudo_element;
GC::Ptr<Element> m_inheritance_override;
};
}