From 677a00ed921a50a6292df13eb4378df1d4054c6d Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Mon, 26 Feb 2024 10:46:22 +0100 Subject: [PATCH] LibWeb: Add "object-fit" CSS property into ComputedValues --- Userland/Libraries/LibWeb/CSS/ComputedValues.h | 3 +++ Userland/Libraries/LibWeb/Layout/Node.cpp | 3 +++ Userland/Libraries/LibWeb/Painting/ImagePaintable.cpp | 8 +------- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/ComputedValues.h b/Userland/Libraries/LibWeb/CSS/ComputedValues.h index 616e6736ed..fd760c77ff 100644 --- a/Userland/Libraries/LibWeb/CSS/ComputedValues.h +++ b/Userland/Libraries/LibWeb/CSS/ComputedValues.h @@ -358,6 +358,7 @@ public: CSS::Size const& row_gap() const { return m_noninherited.row_gap; } CSS::BorderCollapse border_collapse() const { return m_inherited.border_collapse; } Vector> const& grid_template_areas() const { return m_noninherited.grid_template_areas; } + CSS::ObjectFit object_fit() const { return m_noninherited.object_fit; } CSS::LengthBox const& inset() const { return m_noninherited.inset; } const CSS::LengthBox& margin() const { return m_noninherited.margin; } @@ -546,6 +547,7 @@ protected: CSS::OutlineStyle outline_style { InitialValues::outline_style() }; CSS::Length outline_width { InitialValues::outline_width() }; CSS::TableLayout table_layout { InitialValues::table_layout() }; + CSS::ObjectFit object_fit { InitialValues::object_fit() }; Optional mask; CSS::MaskType mask_type { InitialValues::mask_type() }; @@ -657,6 +659,7 @@ public: void set_transition_delay(CSS::Time const& transition_delay) { m_noninherited.transition_delay = transition_delay; } void set_table_layout(CSS::TableLayout value) { m_noninherited.table_layout = value; } void set_quotes(CSS::QuotesData value) { m_inherited.quotes = value; } + void set_object_fit(CSS::ObjectFit value) { m_noninherited.object_fit = value; } void set_fill(SVGPaint value) { m_inherited.fill = value; } void set_stroke(SVGPaint value) { m_inherited.stroke = value; } diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index 08adbd8c18..5d7a57c4b5 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -830,6 +830,9 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style) computed_values.set_math_depth(computed_style.math_depth()); computed_values.set_quotes(computed_style.quotes()); + if (auto object_fit = computed_style.object_fit(); object_fit.has_value()) + computed_values.set_object_fit(object_fit.value()); + propagate_style_to_anonymous_wrappers(); } diff --git a/Userland/Libraries/LibWeb/Painting/ImagePaintable.cpp b/Userland/Libraries/LibWeb/Painting/ImagePaintable.cpp index 9d2b0d5c25..d6fa0653dc 100644 --- a/Userland/Libraries/LibWeb/Painting/ImagePaintable.cpp +++ b/Userland/Libraries/LibWeb/Painting/ImagePaintable.cpp @@ -72,7 +72,6 @@ void ImagePaintable::paint(PaintContext& context, PaintPhase phase) const auto bitmap_rect = bitmap->rect(); auto scaling_mode = to_gfx_scaling_mode(computed_values().image_rendering(), bitmap_rect, image_int_rect); auto& dom_element = verify_cast(*dom_node()); - auto object_fit = dom_element.computed_css_values()->object_fit(); auto bitmap_aspect_ratio = (float)bitmap_rect.height() / bitmap_rect.width(); auto image_aspect_ratio = (float)image_rect.height().value() / image_rect.width().value(); @@ -80,12 +79,7 @@ void ImagePaintable::paint(PaintContext& context, PaintPhase phase) const auto scale_y = 0.0f; Gfx::IntRect bitmap_intersect = bitmap_rect; - auto object_fit_value = CSS::InitialValues::object_fit(); - - if (object_fit.has_value()) - object_fit_value = object_fit.value(); - - switch (object_fit_value) { + switch (computed_values().object_fit()) { case CSS::ObjectFit::Fill: scale_x = (float)image_int_rect.width() / bitmap_rect.width(); scale_y = (float)image_int_rect.height() / bitmap_rect.height();