Selaa lähdekoodia

LibWeb: Add "object-fit" CSS property into ComputedValues

Aliaksandr Kalenik 1 vuosi sitten
vanhempi
commit
677a00ed92

+ 3 - 0
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<Vector<String>> 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<MaskReference> 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; }

+ 3 - 0
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();
 }
 

+ 1 - 7
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::Element>(*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();