mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-05 06:32:30 +02:00
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:
committed by
Andreas Kling
parent
9e064bd3ff
commit
d17f666a8c
Notes:
github-actions[bot]
2025-10-21 14:43:14 +00:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/d17f666a8c5 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6519 Reviewed-by: https://github.com/AtkinsSJ
@@ -19,6 +19,7 @@ AbstractElement::AbstractElement(GC::Ref<Element> element, Optional<CSS::PseudoE
|
||||
void AbstractElement::visit(GC::Cell::Visitor& visitor) const
|
||||
{
|
||||
visitor.visit(m_element);
|
||||
visitor.visit(m_inheritance_override);
|
||||
}
|
||||
|
||||
Document& AbstractElement::document() const
|
||||
@@ -78,6 +79,9 @@ GC::Ptr<Element const> AbstractElement::parent_element() const
|
||||
|
||||
Optional<AbstractElement> AbstractElement::element_to_inherit_style_from() const
|
||||
{
|
||||
if (m_inheritance_override)
|
||||
return AbstractElement { *m_inheritance_override };
|
||||
|
||||
GC::Ptr<Element const> element = m_element->element_to_inherit_style_from(m_pseudo_element);
|
||||
|
||||
if (!element)
|
||||
|
||||
Reference in New Issue
Block a user