LibWeb/CSS: Take AbstractElement in compute_text_align()

This commit is contained in:
Sam Atkins 2025-09-09 14:54:09 +01:00 committed by Alexander Kalenik
commit b49d00996b
Notes: github-actions[bot] 2025-09-11 16:47:06 +00:00

View file

@ -2134,7 +2134,7 @@ void StyleComputer::resolve_effective_overflow_values(ComputedProperties& style)
} }
} }
static void compute_text_align(ComputedProperties& style, DOM::Element const& element, Optional<PseudoElement> pseudo_element) static void compute_text_align(ComputedProperties& style, DOM::AbstractElement abstract_element)
{ {
auto text_align_keyword = style.property(PropertyID::TextAlign).to_keyword(); auto text_align_keyword = style.property(PropertyID::TextAlign).to_keyword();
@ -2143,8 +2143,7 @@ static void compute_text_align(ComputedProperties& style, DOM::Element const& el
// value of start or end is interpreted against the parents direction value and results in a computed value of // value of start or end is interpreted against the parents direction value and results in a computed value of
// either left or right. Computes to start when specified on the root element. // either left or right. Computes to start when specified on the root element.
if (text_align_keyword == Keyword::MatchParent) { if (text_align_keyword == Keyword::MatchParent) {
auto const parent = element.element_to_inherit_style_from(pseudo_element); if (auto const parent = abstract_element.element_to_inherit_style_from(); parent.has_value()) {
if (parent) {
auto const& parent_text_align = parent->computed_properties()->property(PropertyID::TextAlign); auto const& parent_text_align = parent->computed_properties()->property(PropertyID::TextAlign);
auto const& parent_direction = parent->computed_properties()->direction(); auto const& parent_direction = parent->computed_properties()->direction();
switch (parent_text_align.to_keyword()) { switch (parent_text_align.to_keyword()) {
@ -2174,11 +2173,10 @@ static void compute_text_align(ComputedProperties& style, DOM::Element const& el
// AD-HOC: The -libweb-inherit-or-center style defaults to centering, unless a style value usually would have been // AD-HOC: The -libweb-inherit-or-center style defaults to centering, unless a style value usually would have been
// inherited. This is used to support the ad-hoc default <th> text-align behavior. // inherited. This is used to support the ad-hoc default <th> text-align behavior.
if (text_align_keyword == Keyword::LibwebInheritOrCenter && element.local_name() == HTML::TagNames::th) { if (text_align_keyword == Keyword::LibwebInheritOrCenter && abstract_element.element().local_name() == HTML::TagNames::th) {
auto const* parent_element = &element; for (auto parent_element = abstract_element.element_to_inherit_style_from(); parent_element.has_value(); parent_element = parent_element->element_to_inherit_style_from()) {
while ((parent_element = parent_element->element_to_inherit_style_from({}))) {
auto parent_computed = parent_element->computed_properties(); auto parent_computed = parent_element->computed_properties();
auto parent_cascaded = parent_element->cascaded_properties({}); auto parent_cascaded = parent_element->cascaded_properties();
if (!parent_computed || !parent_cascaded) if (!parent_computed || !parent_cascaded)
break; break;
if (parent_cascaded->property(PropertyID::TextAlign)) { if (parent_cascaded->property(PropertyID::TextAlign)) {
@ -2642,7 +2640,7 @@ GC::Ref<ComputedProperties> StyleComputer::compute_properties(DOM::AbstractEleme
// 6. Apply any property-specific computed value logic // 6. Apply any property-specific computed value logic
resolve_effective_overflow_values(computed_style); resolve_effective_overflow_values(computed_style);
compute_text_align(computed_style, element, pseudo_element); compute_text_align(computed_style, abstract_element);
// 7. Let the element adjust computed style // 7. Let the element adjust computed style
element.adjust_computed_style(computed_style); element.adjust_computed_style(computed_style);