REGRESSION(r251487): Web Inspector: selected color in color picker has wrong lightness
https://bugs.webkit.org/show_bug.cgi?id=206202

Reviewed by Devin Rousso.

Currently, tintedColor setter has two code paths:
- rgb2hsv convertion if the color is defined using color(...) syntax.
- HSL to HSV convertion for any other color.

The latter was defined in the view, was untested, and incorrect.
This patch uses WI.Color.rgb2hsv convertion for all colors. This method is
already covered by tests.

* UserInterface/Views/ColorSquare.js:
(WI.ColorSquare.prototype.set tintedColor):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@254726 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebInspectorUI/ChangeLog b/Source/WebInspectorUI/ChangeLog
index 449aa32..42e7b78 100644
--- a/Source/WebInspectorUI/ChangeLog
+++ b/Source/WebInspectorUI/ChangeLog
@@ -1,3 +1,21 @@
+2020-01-16  Nikita Vasilyev  <nvasilyev@apple.com>
+
+        REGRESSION(r251487): Web Inspector: selected color in color picker has wrong lightness
+        https://bugs.webkit.org/show_bug.cgi?id=206202
+
+        Reviewed by Devin Rousso.
+
+        Currently, tintedColor setter has two code paths:
+        - rgb2hsv convertion if the color is defined using color(...) syntax.
+        - HSL to HSV convertion for any other color.
+
+        The latter was defined in the view, was untested, and incorrect.
+        This patch uses WI.Color.rgb2hsv convertion for all colors. This method is
+        already covered by tests.
+
+        * UserInterface/Views/ColorSquare.js:
+        (WI.ColorSquare.prototype.set tintedColor):
+
 2020-01-16  David Kilzer  <ddkilzer@apple.com>
 
         Enable -Wconditional-uninitialized in WebInspectorUI, WebKitLegacy, WebKit projects
diff --git a/Source/WebInspectorUI/UserInterface/Views/ColorSquare.js b/Source/WebInspectorUI/UserInterface/Views/ColorSquare.js
index f505c61..c500f3f 100644
--- a/Source/WebInspectorUI/UserInterface/Views/ColorSquare.js
+++ b/Source/WebInspectorUI/UserInterface/Views/ColorSquare.js
@@ -106,29 +106,14 @@
 
         this._gamut = tintedColor.gamut;
 
-        if (tintedColor.format === WI.Color.Format.ColorFunction) {
-            // CSS color function only supports RGB. It doesn't support HSL.
-            let hsv = WI.Color.rgb2hsv(...tintedColor.normalizedRGB);
-            let x = hsv[1] / 100 * this._dimension;
-            let y = (1 - (hsv[2] / 100)) * this._dimension;
-            this._setCrosshairPosition(new WI.Point(x, y));
-            if (this._gamut === WI.Color.Gamut.DisplayP3)
-                this._drawSRGBOutline();
-        } else {
-            let hsl = tintedColor.hsl;
-            let saturation = Number.constrain(hsl[1], 0, 100);
-            let x = saturation / 100 * this._dimension;
+        let [hue, saturation, value] = WI.Color.rgb2hsv(...tintedColor.normalizedRGB);
+        let x = saturation / 100 * this._dimension;
+        let y = (1 - (value / 100)) * this._dimension;
 
-            let lightness = hsl[2];
+        if (this._gamut === WI.Color.Gamut.DisplayP3)
+            this._drawSRGBOutline();
 
-            // The color picker is HSV-based. (HSV is also known as HSB.)
-            // Derive lightness by using HSV to HSL equation.
-            let y = 2 * lightness / (200 - saturation);
-            y = -1 * (y - 1) * this._dimension;
-
-            this._setCrosshairPosition(new WI.Point(x, y));
-        }
-
+        this._setCrosshairPosition(new WI.Point(x, y));
         this._updateBaseColor();
     }