mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-25 10:48:53 +00:00
LibWeb: Prioritize inheriting text-align
for <th>
Because we defined `th { text-align: center }` in our UA stylesheet, it received a higher precedence than inherited (inline) styles. Firefox deals with this by defining a custom `text-align` value that prioritizes any inherited value before defaulting to `text-align: center`. We now do this as well :^)
This commit is contained in:
parent
d1678e03ff
commit
9f7447f546
Notes:
github-actions[bot]
2025-07-15 08:07:00 +00:00
Author: https://github.com/gmta
Commit: 9f7447f546
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5441
7 changed files with 259 additions and 3 deletions
|
@ -599,14 +599,14 @@ td, th {
|
|||
th {
|
||||
font-weight: bold;
|
||||
/*
|
||||
The text-align property for table headings is non-standard, but all
|
||||
existing user-agents seem to render them centered by default.
|
||||
The text-align property for table headings is non-standard, but all existing user-agents seem to render them
|
||||
centered by default. We use -libweb-inherit-or-center to prioritize any inherited text-align style.
|
||||
|
||||
See:
|
||||
- https://trac.webkit.org/browser/trunk/Source/WebCore/css/html.css?rev=295625#L272
|
||||
- https://searchfox.org/mozilla-central/rev/0b55b868c17835942d40ca3fedfca8057481207b/layout/style/res/html.css#473
|
||||
*/
|
||||
text-align: center;
|
||||
text-align: -libweb-inherit-or-center;
|
||||
}
|
||||
|
||||
caption {
|
||||
|
|
|
@ -609,6 +609,7 @@
|
|||
"right",
|
||||
"match-parent",
|
||||
"-libweb-center",
|
||||
"-libweb-inherit-or-center",
|
||||
"-libweb-left",
|
||||
"-libweb-right"
|
||||
],
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
"-libweb-buttonfacedisabled",
|
||||
"-libweb-buttonfacehover",
|
||||
"-libweb-center",
|
||||
"-libweb-inherit-or-center",
|
||||
"-libweb-left",
|
||||
"-libweb-link",
|
||||
"-libweb-palette-active-link",
|
||||
|
|
|
@ -1708,6 +1708,24 @@ void StyleComputer::compute_defaulted_values(ComputedProperties& style, DOM::Ele
|
|||
auto const& inherited_value = get_inherit_value(CSS::PropertyID::Color, element, pseudo_element);
|
||||
style.set_property(CSS::PropertyID::Color, inherited_value);
|
||||
}
|
||||
|
||||
// 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.
|
||||
if (element && element->local_name() == HTML::TagNames::th
|
||||
&& style.property(PropertyID::TextAlign).to_keyword() == Keyword::LibwebInheritOrCenter) {
|
||||
auto const* parent_element = element;
|
||||
while ((parent_element = element_to_inherit_style_from(parent_element, {}))) {
|
||||
auto parent_computed = parent_element->computed_properties();
|
||||
auto parent_cascaded = parent_element->cascaded_properties({});
|
||||
if (!parent_computed || !parent_cascaded)
|
||||
break;
|
||||
if (parent_cascaded->property(PropertyID::TextAlign)) {
|
||||
auto const& style_value = parent_computed->property(PropertyID::TextAlign);
|
||||
style.set_property(PropertyID::TextAlign, style_value, ComputedProperties::Inherited::Yes);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Length::FontMetrics StyleComputer::calculate_root_element_font_metrics(ComputedProperties const& style) const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue