LibWeb: Route presentational hints through the CSS cascade

Previously, presentational hints bypassed the regular cascade pipeline
and wrote directly into `CascadedProperties` under
`CascadeOrigin::Author`. That meant `var()` substitution and the
invalid-at-computed-value-time fallback had to be duplicated in a
separate per-element pass, which in practice missed the IACVT step and
could leave a `GuaranteedInvalidStyleValue` in the cascaded
properties. This caused a crash in downstream code that assumed the
value had been resolved.

This introduces an `AuthorPresentationalHint` cascade origin and feeds
them through the cascade as normal declarations. This means that
`var()` resolution now happens in only one place.
This commit is contained in:
Tim Ledbetter
2026-04-30 10:44:26 +01:00
committed by Sam Atkins
parent 297b1af9bf
commit d1fc4b4234
Notes: github-actions[bot] 2026-04-30 18:51:41 +00:00
67 changed files with 316 additions and 374 deletions

View File

@@ -7,7 +7,6 @@
#include <LibWeb/Bindings/HTMLTableCellElement.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/CSS/CascadedProperties.h>
#include <LibWeb/CSS/ComputedProperties.h>
#include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
@@ -54,42 +53,42 @@ bool HTMLTableCellElement::is_presentational_hint(FlyString const& name) const
HTML::AttributeNames::width);
}
void HTMLTableCellElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
void HTMLTableCellElement::apply_presentational_hints(Vector<CSS::StyleProperty>& properties) const
{
Base::apply_presentational_hints(cascaded_properties);
Base::apply_presentational_hints(properties);
for_each_attribute([&](auto& name, auto& value) {
if (name == HTML::AttributeNames::bgcolor) {
// https://html.spec.whatwg.org/multipage/rendering.html#tables-2:rules-for-parsing-a-legacy-colour-value
auto color = parse_legacy_color_value(value);
if (color.has_value())
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BackgroundColor, CSS::ColorStyleValue::create_from_color(color.value(), CSS::ColorSyntax::Legacy));
properties.append({ .property_id = CSS::PropertyID::BackgroundColor, .value = CSS::ColorStyleValue::create_from_color(color.value(), CSS::ColorSyntax::Legacy) });
return;
}
if (name == HTML::AttributeNames::valign) {
if (auto parsed_value = parse_css_value(CSS::Parser::ParsingParams { document() }, value, CSS::PropertyID::VerticalAlign))
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::VerticalAlign, parsed_value.release_nonnull());
properties.append({ .property_id = CSS::PropertyID::VerticalAlign, .value = parsed_value.release_nonnull() });
return;
}
if (name == HTML::AttributeNames::align) {
if (auto parsed_value = parse_table_child_element_align_value(value))
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::TextAlign, parsed_value.release_nonnull());
properties.append({ .property_id = CSS::PropertyID::TextAlign, .value = parsed_value.release_nonnull() });
return;
}
if (name == HTML::AttributeNames::width) {
if (auto parsed_value = parse_nonzero_dimension_value(value))
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Width, parsed_value.release_nonnull());
properties.append({ .property_id = CSS::PropertyID::Width, .value = parsed_value.release_nonnull() });
return;
} else if (name == HTML::AttributeNames::height) {
if (auto parsed_value = parse_nonzero_dimension_value(value))
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Height, parsed_value.release_nonnull());
properties.append({ .property_id = CSS::PropertyID::Height, .value = parsed_value.release_nonnull() });
return;
} else if (name == HTML::AttributeNames::background) {
// https://html.spec.whatwg.org/multipage/rendering.html#tables-2:encoding-parsing-and-serializing-a-url
if (auto parsed_value = document().encoding_parse_url(value); parsed_value.has_value())
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BackgroundImage, CSS::StyleValueList::create({ CSS::ImageStyleValue::create(*parsed_value) }, CSS::StyleValueList::Separator::Comma));
properties.append({ .property_id = CSS::PropertyID::BackgroundImage, .value = CSS::StyleValueList::create({ CSS::ImageStyleValue::create(*parsed_value) }, CSS::StyleValueList::Separator::Comma) });
return;
} else if (name == HTML::AttributeNames::nowrap) {
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::TextWrapMode, CSS::KeywordStyleValue::create(CSS::Keyword::Nowrap));
properties.append({ .property_id = CSS::PropertyID::TextWrapMode, .value = CSS::KeywordStyleValue::create(CSS::Keyword::Nowrap) });
return;
}
});
@@ -99,10 +98,10 @@ void HTMLTableCellElement::apply_presentational_hints(GC::Ref<CSS::CascadedPrope
return;
if (auto padding = table_element->cellpadding(); padding.has_value()) {
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::PaddingTop, CSS::LengthStyleValue::create(CSS::Length::make_px(*padding)));
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::PaddingBottom, CSS::LengthStyleValue::create(CSS::Length::make_px(*padding)));
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::PaddingLeft, CSS::LengthStyleValue::create(CSS::Length::make_px(*padding)));
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::PaddingRight, CSS::LengthStyleValue::create(CSS::Length::make_px(*padding)));
properties.append({ .property_id = CSS::PropertyID::PaddingTop, .value = CSS::LengthStyleValue::create(CSS::Length::make_px(*padding)) });
properties.append({ .property_id = CSS::PropertyID::PaddingBottom, .value = CSS::LengthStyleValue::create(CSS::Length::make_px(*padding)) });
properties.append({ .property_id = CSS::PropertyID::PaddingLeft, .value = CSS::LengthStyleValue::create(CSS::Length::make_px(*padding)) });
properties.append({ .property_id = CSS::PropertyID::PaddingRight, .value = CSS::LengthStyleValue::create(CSS::Length::make_px(*padding)) });
}
auto border = table_element->border();
@@ -110,9 +109,9 @@ void HTMLTableCellElement::apply_presentational_hints(GC::Ref<CSS::CascadedPrope
if (!border)
return;
auto apply_border_style = [&](CSS::PropertyID style_property, CSS::PropertyID width_property, CSS::PropertyID color_property) {
cascaded_properties->set_property_from_presentational_hint(style_property, CSS::KeywordStyleValue::create(CSS::Keyword::Inset));
cascaded_properties->set_property_from_presentational_hint(width_property, CSS::LengthStyleValue::create(CSS::Length::make_px(1)));
cascaded_properties->set_property_from_presentational_hint(color_property, table_element->computed_properties()->property(color_property));
properties.append({ .property_id = style_property, .value = CSS::KeywordStyleValue::create(CSS::Keyword::Inset) });
properties.append({ .property_id = width_property, .value = CSS::LengthStyleValue::create(CSS::Length::make_px(1)) });
properties.append({ .property_id = color_property, .value = table_element->computed_properties()->property(color_property) });
};
apply_border_style(CSS::PropertyID::BorderLeftStyle, CSS::PropertyID::BorderLeftWidth, CSS::PropertyID::BorderLeftColor);
apply_border_style(CSS::PropertyID::BorderTopStyle, CSS::PropertyID::BorderTopWidth, CSS::PropertyID::BorderTopColor);