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

@@ -11,7 +11,6 @@
#include <LibGfx/ImmutableBitmap.h>
#include <LibWeb/ARIA/Roles.h>
#include <LibWeb/Bindings/HTMLImageElement.h>
#include <LibWeb/CSS/CascadedProperties.h>
#include <LibWeb/CSS/ComputedProperties.h>
#include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/CSS/StyleComputer.h>
@@ -176,33 +175,33 @@ bool HTMLImageElement::is_presentational_hint(FlyString const& name) const
HTML::AttributeNames::border);
}
void HTMLImageElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
void HTMLImageElement::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::hspace) {
if (auto parsed_value = parse_dimension_value(value)) {
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MarginLeft, *parsed_value);
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MarginRight, *parsed_value);
properties.append({ .property_id = CSS::PropertyID::MarginLeft, .value = *parsed_value });
properties.append({ .property_id = CSS::PropertyID::MarginRight, .value = *parsed_value });
}
} else if (name == HTML::AttributeNames::vspace) {
if (auto parsed_value = parse_dimension_value(value)) {
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MarginTop, *parsed_value);
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MarginBottom, *parsed_value);
properties.append({ .property_id = CSS::PropertyID::MarginTop, .value = *parsed_value });
properties.append({ .property_id = CSS::PropertyID::MarginBottom, .value = *parsed_value });
}
} else if (name == HTML::AttributeNames::border) {
if (auto parsed_value = parse_non_negative_integer(value); parsed_value.has_value()) {
auto width_value = CSS::LengthStyleValue::create(CSS::Length::make_px(*parsed_value));
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderTopWidth, width_value);
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderRightWidth, width_value);
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderBottomWidth, width_value);
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderLeftWidth, width_value);
properties.append({ .property_id = CSS::PropertyID::BorderTopWidth, .value = width_value });
properties.append({ .property_id = CSS::PropertyID::BorderRightWidth, .value = width_value });
properties.append({ .property_id = CSS::PropertyID::BorderBottomWidth, .value = width_value });
properties.append({ .property_id = CSS::PropertyID::BorderLeftWidth, .value = width_value });
auto solid_value = CSS::KeywordStyleValue::create(CSS::Keyword::Solid);
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderTopStyle, solid_value);
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderRightStyle, solid_value);
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderBottomStyle, solid_value);
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderLeftStyle, solid_value);
properties.append({ .property_id = CSS::PropertyID::BorderTopStyle, .value = solid_value });
properties.append({ .property_id = CSS::PropertyID::BorderRightStyle, .value = solid_value });
properties.append({ .property_id = CSS::PropertyID::BorderBottomStyle, .value = solid_value });
properties.append({ .property_id = CSS::PropertyID::BorderLeftStyle, .value = solid_value });
}
}
});