浏览代码

LibWeb: Precision when using background-size: cover

This ensures that precision is maintained when calculating the image
size when using `background-size: cover`.
Jamie Mansfield 1 年之前
父节点
当前提交
e48cb80a66

二进制
Tests/LibWeb/Ref/reference/images/css-backgrounds-ref.png


+ 2 - 2
Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp

@@ -284,8 +284,8 @@ void paint_background(PaintContext& context, Layout::NodeWithStyleAndBoxModelMet
             break;
         }
         case CSS::BackgroundSize::Cover: {
-            double max_width_ratio = (background_positioning_area.width() / concrete_image_size.width()).to_double();
-            double max_height_ratio = (background_positioning_area.height() / concrete_image_size.height()).to_double();
+            double max_width_ratio = background_positioning_area.width().to_double() / concrete_image_size.width().to_double();
+            double max_height_ratio = background_positioning_area.height().to_double() / concrete_image_size.height().to_double();
             double ratio = max(max_width_ratio, max_height_ratio);
             image_rect.set_size(concrete_image_size.width().scaled(ratio), concrete_image_size.height().scaled(ratio));
             break;