diff --git a/Libraries/LibWeb/CSS/StyleComputer.cpp b/Libraries/LibWeb/CSS/StyleComputer.cpp index ddd8cfe1ae9..bcfb47680fa 100644 --- a/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -1098,7 +1098,7 @@ void StyleComputer::collect_animation_into(DOM::Element& element, Optional(PropertyID)> const get_property_specified_value = [&](auto property_id) -> NonnullRefPtr { + return style.property(property_id); + }; + + style.for_each_property([&](PropertyID property_id, auto& specified_value) { + auto const& computed_value = compute_value_of_property(property_id, specified_value, get_property_specified_value, computation_context); + + // FIXME: Any required absolutization should be done within compute_value_of_property() - we can remove this once that's implemented. + auto const& absolutized_value = computed_value->absolutized(viewport_rect(), font_metrics, m_root_element_font_metrics); + auto const& is_inherited = style.is_property_inherited(property_id) ? ComputedProperties::Inherited::Yes : ComputedProperties::Inherited::No; style.set_property(property_id, absolutized_value, is_inherited); }); @@ -2393,7 +2410,7 @@ GC::Ref StyleComputer::create_document_style() const compute_math_depth(style, {}); compute_font(style, nullptr, {}); - absolutize_values(style); + compute_property_values(style); style->set_property(CSS::PropertyID::Width, CSS::LengthStyleValue::create(CSS::Length::make_px(viewport_rect().width()))); style->set_property(CSS::PropertyID::Height, CSS::LengthStyleValue::create(CSS::Length::make_px(viewport_rect().height()))); style->set_property(CSS::PropertyID::Display, CSS::DisplayStyleValue::create(CSS::Display::from_short(CSS::Display::Short::Block))); @@ -2702,8 +2719,8 @@ GC::Ref StyleComputer::compute_properties(DOM::Element& elem // 3. Compute the font, since that may be needed for font-relative CSS units compute_font(computed_style, &element, pseudo_element); - // 4. Absolutize values, turning font/viewport relative lengths into absolute lengths - absolutize_values(computed_style); + // 4. Convert properties into their computed forms + compute_property_values(computed_style); // 5. Run automatic box type transformations transform_box_type_if_needed(computed_style, element, pseudo_element); @@ -3157,6 +3174,17 @@ void StyleComputer::compute_custom_properties(ComputedProperties&, DOM::Abstract abstract_element.set_custom_properties(move(resolved_custom_properties)); } +NonnullRefPtr StyleComputer::compute_value_of_property(PropertyID property_id, NonnullRefPtr const& specified_value, Function(PropertyID)> const&, PropertyValueComputationContext const&) +{ + switch (property_id) { + default: + // FIXME: We should replace this with a VERIFY_NOT_REACHED() once all properties have their own handling. + return specified_value; + } + + VERIFY_NOT_REACHED(); +} + void StyleComputer::compute_math_depth(ComputedProperties& style, Optional element) const { // https://w3c.github.io/mathml-core/#propdef-math-depth diff --git a/Libraries/LibWeb/CSS/StyleComputer.h b/Libraries/LibWeb/CSS/StyleComputer.h index 2f78e33da8d..6dcb748538c 100644 --- a/Libraries/LibWeb/CSS/StyleComputer.h +++ b/Libraries/LibWeb/CSS/StyleComputer.h @@ -189,13 +189,18 @@ public: [[nodiscard]] GC::Ref compute_properties(DOM::Element&, Optional, CascadedProperties&) const; - void absolutize_values(ComputedProperties&) const; + void compute_property_values(ComputedProperties&) const; void compute_font(ComputedProperties&, DOM::Element const*, Optional) const; [[nodiscard]] inline bool should_reject_with_ancestor_filter(Selector const&) const; static NonnullRefPtr compute_value_of_custom_property(DOM::AbstractElement, FlyString const& custom_property, Optional = {}); + struct PropertyValueComputationContext { + Length::ResolutionContext length_resolution_context; + }; + static NonnullRefPtr compute_value_of_property(PropertyID, NonnullRefPtr const& specified_value, Function(PropertyID)> const& get_property_specified_value, PropertyValueComputationContext const&); + private: virtual void visit_edges(Visitor&) override; diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp index 758f1d27252..a29fc6a2f02 100644 --- a/Libraries/LibWeb/DOM/Element.cpp +++ b/Libraries/LibWeb/DOM/Element.cpp @@ -835,7 +835,7 @@ CSS::RequiredInvalidationAfterStyleChange Element::recompute_inherited_style() return invalidation; document().style_computer().compute_font(*computed_properties, this, {}); - document().style_computer().absolutize_values(*computed_properties); + document().style_computer().compute_property_values(*computed_properties); for (auto [property_id, old_value] : old_values_with_relative_units) { auto const& new_value = computed_properties->property(static_cast(property_id));