Browse Source

LibWeb/CSS: Use double in `CSSHWB::to_color()`

See previous the commit description for more details about the floating
points operations.

The hwb test cases in `css-color-functions` are now rendered identically
to what firefox does (I haven't checked the others tests, but they
aren't affected by this commit).
Lucas CHOLLET 8 months ago
parent
commit
a1687854ab

+ 2 - 2
Libraries/LibWeb/CSS/StyleValues/CSSHWB.cpp

@@ -25,8 +25,8 @@ Color CSSHWB::to_color(Optional<Layout::NodeWithStyle const&>) const
         return Color(gray, gray, gray, to_byte(alpha_val));
     }
 
-    float value = 1 - b_val;
-    float saturation = 1 - (w_val / value);
+    auto value = 1 - b_val;
+    auto saturation = 1 - (w_val / value);
     return Color::from_hsv(h_val, saturation, value).with_opacity(alpha_val);
 }
 

+ 10 - 0
Tests/LibWeb/Ref/expected/wpt-import/css/css-color/hwb-004-ref.html

@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Color 4: CSS Color 4: hwb</title>
+<style>
+    .test { background-color: rgb(20% 70% 20%); width: 12em; height: 12em; } /* hwb(120 20% 30%) converted to sRGB */
+</style>
+<body>
+    <p>Test passes if you see a single square, and not two rectangles of different colors.</p>
+    <div class="test"></div>
+</body>

+ 17 - 0
Tests/LibWeb/Ref/input/wpt-import/css/css-color/hwb-004.html

@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Color 4: hwb</title>
+<link rel="author" title="Sam Weinig" href="mailto:weinig@apple.com">
+<link rel="help" href="https://drafts.csswg.org/css-color-4/#the-hwb-notation">
+<link rel="match" href="../../../../expected/wpt-import/css/css-color/hwb-004-ref.html">
+<meta name="assert" content="hwb with no alpha">
+<style>
+    .test { background-color: red; width: 12em; height: 6em; margin-top: 0; }
+    .ref { background-color: rgb(20% 70% 20%); width: 12em; height: 6em; margin-bottom: 0; } /* hwb(120 20% 30%) converted to sRGB */
+    .test { background-color: hwb(120 20% 30%); }
+</style>
+<body>
+    <p>Test passes if you see a single square, and not two rectangles of different colors.</p>
+    <div class="ref"></div>
+    <div class="test"></div>
+</body>

BIN
Tests/LibWeb/Screenshot/images/css-color-functions-ref.png


+ 0 - 4
Tests/LibWeb/TestConfig.ini

@@ -162,7 +162,3 @@ Text/input/wpt-import/css/css-backgrounds/animations/discrete-no-interpolation.h
 
 ; https://github.com/LadybirdBrowser/ladybird/issues/2314
 Text/input/test-http-test-server.html
-
-; Multiple bugs are affecting these tests. To avoid having to rebase them every
-; single time, let's deactivate them for a bit.
-Screenshot/input/css-color-functions.html