Skip to content

Commit 4883297

Browse files
Calme1709gmta
authored andcommitted
LibWeb: Handle -libweb-inherit-or-center in compute_text_align
This seems like a more natural place to handle this
1 parent ca9cb42 commit 4883297

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

Libraries/LibWeb/CSS/StyleComputer.cpp

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,24 +1760,6 @@ void StyleComputer::compute_defaulted_values(ComputedProperties& style, DOM::Ele
17601760
auto const& inherited_value = get_inherit_value(CSS::PropertyID::Color, element, pseudo_element);
17611761
style.set_property(CSS::PropertyID::Color, inherited_value);
17621762
}
1763-
1764-
// AD-HOC: The -libweb-inherit-or-center style defaults to centering, unless a style value usually would have been
1765-
// inherited. This is used to support the ad-hoc default <th> text-align behavior.
1766-
if (element && element->local_name() == HTML::TagNames::th
1767-
&& style.property(PropertyID::TextAlign).to_keyword() == Keyword::LibwebInheritOrCenter) {
1768-
auto const* parent_element = element;
1769-
while ((parent_element = parent_element->element_to_inherit_style_from({}))) {
1770-
auto parent_computed = parent_element->computed_properties();
1771-
auto parent_cascaded = parent_element->cascaded_properties({});
1772-
if (!parent_computed || !parent_cascaded)
1773-
break;
1774-
if (parent_cascaded->property(PropertyID::TextAlign)) {
1775-
auto const& style_value = parent_computed->property(PropertyID::TextAlign);
1776-
style.set_property(PropertyID::TextAlign, style_value, ComputedProperties::Inherited::Yes);
1777-
break;
1778-
}
1779-
}
1780-
}
17811763
}
17821764

17831765
Length::FontMetrics StyleComputer::calculate_root_element_font_metrics(ComputedProperties const& style) const
@@ -2307,11 +2289,13 @@ void StyleComputer::resolve_effective_overflow_values(ComputedProperties& style)
23072289

23082290
static void compute_text_align(ComputedProperties& style, DOM::Element const& element, Optional<PseudoElement> pseudo_element)
23092291
{
2292+
auto text_align_keyword = style.property(PropertyID::TextAlign).to_keyword();
2293+
23102294
// https://drafts.csswg.org/css-text-4/#valdef-text-align-match-parent
23112295
// This value behaves the same as inherit (computes to its parent’s computed value) except that an inherited
23122296
// value of start or end is interpreted against the parent’s direction value and results in a computed value of
23132297
// either left or right. Computes to start when specified on the root element.
2314-
if (style.property(PropertyID::TextAlign).to_keyword() == Keyword::MatchParent) {
2298+
if (text_align_keyword == Keyword::MatchParent) {
23152299
auto const parent = element.element_to_inherit_style_from(pseudo_element);
23162300
if (parent) {
23172301
auto const& parent_text_align = parent->computed_properties()->property(PropertyID::TextAlign);
@@ -2340,6 +2324,23 @@ static void compute_text_align(ComputedProperties& style, DOM::Element const& el
23402324
style.set_property(PropertyID::TextAlign, KeywordStyleValue::create(Keyword::Start));
23412325
}
23422326
}
2327+
2328+
// AD-HOC: The -libweb-inherit-or-center style defaults to centering, unless a style value usually would have been
2329+
// inherited. This is used to support the ad-hoc default <th> text-align behavior.
2330+
if (text_align_keyword == Keyword::LibwebInheritOrCenter && element.local_name() == HTML::TagNames::th) {
2331+
auto const* parent_element = &element;
2332+
while ((parent_element = parent_element->element_to_inherit_style_from({}))) {
2333+
auto parent_computed = parent_element->computed_properties();
2334+
auto parent_cascaded = parent_element->cascaded_properties({});
2335+
if (!parent_computed || !parent_cascaded)
2336+
break;
2337+
if (parent_cascaded->property(PropertyID::TextAlign)) {
2338+
auto const& style_value = parent_computed->property(PropertyID::TextAlign);
2339+
style.set_property(PropertyID::TextAlign, style_value, ComputedProperties::Inherited::Yes);
2340+
break;
2341+
}
2342+
}
2343+
}
23432344
}
23442345

23452346
enum class BoxTypeTransformation {

0 commit comments

Comments
 (0)