Diff
Modified: trunk/LayoutTests/ChangeLog (252746 => 252747)
--- trunk/LayoutTests/ChangeLog 2019-11-21 20:27:42 UTC (rev 252746)
+++ trunk/LayoutTests/ChangeLog 2019-11-21 21:11:07 UTC (rev 252747)
@@ -1,3 +1,17 @@
+2019-11-21 Nikita Vasilyev <[email protected]>
+
+ Web Inspector: Outline sRGB-safe areas on P3 color picker
+ https://bugs.webkit.org/show_bug.cgi?id=203533
+ <rdar://problem/56688057>
+
+ Reviewed by Brian Burg.
+
+ Test WI.Color.displayP3toSRGB.
+
+ LayoutTests:
+ * inspector/model/color-expected.txt:
+ * inspector/model/color.html:
+
2019-11-21 Kate Cheney <[email protected]>
REGRESSION (r234440): [Mac WK2 ] Layout Test http/tests/storageAccess/request-and-grant-access-cross-origin-sandboxed-iframe-from-prevalent-domain-with-user-interaction-but-access-from-wrong-frame.html is flaky timeout (194164)
Modified: trunk/LayoutTests/inspector/model/color-expected.txt (252746 => 252747)
--- trunk/LayoutTests/inspector/model/color-expected.txt 2019-11-21 20:27:42 UTC (rev 252746)
+++ trunk/LayoutTests/inspector/model/color-expected.txt 2019-11-21 21:11:07 UTC (rev 252747)
@@ -518,3 +518,12 @@
PASS: Should convert [2,0,0] to [255,0,0].
PASS: Should convert [-1,0,0] to [0,0,0].
+-- Running test case: WI.Color.displayP3toSRGB
+PASS: Should convert [0,0,0] to [0,0,0].
+PASS: Should convert [1,1,1] to [0.9999300658875597,1.0000101408119602,1.0001054916006267].
+PASS: Should convert [1,0,0] to [1.0929902391315327,-0.5433883521407902,-0.2537782522695441].
+PASS: Should convert [0,1,0] to [-2.9057643199691516,1.0182759798644396,-1.0162215225472337].
+PASS: Should convert [0,0,1] to [2.3902361583783006e-7,-2.0487738563140788e-7,1.0421313171983129].
+PASS: Should convert [2,0,0] to [1.0929902391315327,-0.5433883521407902,-0.2537782522695441].
+PASS: Should convert [-1,0,0] to [0,0,0].
+
Modified: trunk/LayoutTests/inspector/model/color.html (252746 => 252747)
--- trunk/LayoutTests/inspector/model/color.html 2019-11-21 20:27:42 UTC (rev 252746)
+++ trunk/LayoutTests/inspector/model/color.html 2019-11-21 21:11:07 UTC (rev 252747)
@@ -612,6 +612,24 @@
}
});
+ suite.addTestCase({
+ name: "WI.Color.displayP3toSRGB",
+ description: "Test conversion from display-P3 gamut to sRGB.",
+ test() {
+ testColorConversion(WI.Color.displayP3toSRGB, [0, 0, 0], [0, 0, 0]);
+ testColorConversion(WI.Color.displayP3toSRGB, [1, 1, 1], [0.9999300658875597, 1.0000101408119602, 1.0001054916006267]);
+ testColorConversion(WI.Color.displayP3toSRGB, [1, 0, 0], [1.0929902391315327, -0.5433883521407902, -0.2537782522695441]);
+ testColorConversion(WI.Color.displayP3toSRGB, [0, 1, 0], [-2.9057643199691516, 1.0182759798644396, -1.0162215225472337]);
+ testColorConversion(WI.Color.displayP3toSRGB, [0, 0, 1], [2.3902361583783006e-7, -2.0487738563140788e-7, 1.0421313171983129]);
+
+ // Out-of-bounds inputs.
+ testColorConversion(WI.Color.displayP3toSRGB, [2, 0, 0], [1.0929902391315327, -0.5433883521407902, -0.2537782522695441]);
+ testColorConversion(WI.Color.displayP3toSRGB, [-1, 0, 0], [0, 0, 0]);
+
+ return true;
+ }
+ });
+
suite.runTestCasesAndFinish();
}
</script>
Modified: trunk/Source/WebInspectorUI/ChangeLog (252746 => 252747)
--- trunk/Source/WebInspectorUI/ChangeLog 2019-11-21 20:27:42 UTC (rev 252746)
+++ trunk/Source/WebInspectorUI/ChangeLog 2019-11-21 21:11:07 UTC (rev 252747)
@@ -1,3 +1,41 @@
+2019-11-21 Nikita Vasilyev <[email protected]>
+
+ Web Inspector: Outline sRGB-safe areas on P3 color picker
+ https://bugs.webkit.org/show_bug.cgi?id=203533
+ <rdar://problem/56688057>
+
+ Reviewed by Brian Burg.
+
+ Visualize the edge of sRGB gamut as a white line.
+
+ * Localizations/en.lproj/localizedStrings.js:
+
+ * UserInterface/Models/Color.js:
+ (WI.Color.displayP3toSRGB.multiplyMatrixByVector):
+ (WI.Color.displayP3toSRGB):
+ (WI.Color._toLinearLight):
+ (WI.Color._gammaCorrect):
+ Use equations from CSS Color Module Level 4.
+
+ * UserInterface/Views/ColorSquare.css:
+ (.color-square):
+ (.color-square > .crosshair):
+ Place the crosshair above the sRGB edge line.
+
+ (.color-square .svg-root):
+ (.color-square .srgb-edge):
+ (.color-square .srgb-label):
+ (.color-square .srgb-label:hover):
+ (.color-square .srgb-label:hover + .svg-root > .srgb-edge):
+ (@media (-webkit-device-pixel-ratio: 1)):
+ Make the optical weight of the line on non-retina screens the same as on retina screens.
+
+ * UserInterface/Views/ColorSquare.js:
+ (WI.ColorSquare):
+ (WI.ColorSquare.prototype.set tintedColor):
+ (WI.ColorSquare.prototype._updateBaseColor):
+ (WI.ColorSquare.prototype._drawSRGBOutline):
+
2019-11-21 Devin Rousso <[email protected]>
Web Inspector: call frames from blackboxed scripts should be visually distinct
Modified: trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js (252746 => 252747)
--- trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js 2019-11-21 20:27:42 UTC (rev 252746)
+++ trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js 2019-11-21 21:11:07 UTC (rev 252747)
@@ -1175,6 +1175,8 @@
localizedStrings["This is what the result of a test that threw an error with no data looks like."] = "This is what the result of a test that threw an error with no data looks like.";
localizedStrings["This is what the result of a warning test with no data looks like."] = "This is what the result of a warning test with no data looks like.";
localizedStrings["This is what the result of an unsupported test with no data looks like."] = "This is what the result of an unsupported test with no data looks like.";
+/* Label for a guide within the color picker */
+localizedStrings["This line marks the edge of sRGB color space"] = "This line marks the edge of sRGB color space";
localizedStrings["This object is a root"] = "This object is a root";
localizedStrings["This object is referenced by internal objects"] = "This object is referenced by internal objects";
localizedStrings["This test will pass with a variety of accessibility information about the <body> element."] = "This test will pass with a variety of accessibility information about the <body> element.";
Modified: trunk/Source/WebInspectorUI/UserInterface/Models/Color.js (252746 => 252747)
--- trunk/Source/WebInspectorUI/UserInterface/Models/Color.js 2019-11-21 20:27:42 UTC (rev 252746)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/Color.js 2019-11-21 21:11:07 UTC (rev 252747)
@@ -348,6 +348,73 @@
return [fraction(5), fraction(3), fraction(1)];
}
+ // https://www.w3.org/TR/css-color-4/#color-conversion-code
+ static displayP3toSRGB(r, g, b)
+ {
+ r = Number.constrain(r, 0, 1);
+ g = Number.constrain(g, 0, 1);
+ b = Number.constrain(b, 0, 1);
+
+ let linearP3 = WI.Color._toLinearLight([r, g, b]);
+
+ // https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Matrix_math_for_the_web#Multiplying_a_matrix_and_a_point
+ function multiplyMatrixByVector(matrix, vector) {
+ let height = matrix.length;
+ let width = matrix[0].length;
+ console.assert(width === vector.length);
+
+ let result = Array(width).fill(0);
+ for (let i = 0; i < width; i++)
+ for (let rowIndex = 0; rowIndex < height; rowIndex++)
+ result[i] += vector[rowIndex] * matrix[i][rowIndex];
+
+ return result;
+ }
+
+ // Convert an array of linear-light display-p3 values to CIE XYZ
+ // using D65 (no chromatic adaptation).
+ // http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
+ let matrix = [
+ [0.4865709486482162, 0.26566769316909306, 0.1982172852343625],
+ [0.2289745640697488, 0.6917385218365064, 0.079286914093745],
+ [0.0000000000000000, 0.04511338185890264, 1.043944368900976]
+ ];
+ let xyz = multiplyMatrixByVector(matrix, linearP3);
+
+ // Convert XYZ to linear-light sRGB.
+ matrix = [
+ [ 3.2404542, -1.5371385, -0.4985314],
+ [-0.9692660, 1.8760108, 0.0415560],
+ [ 0.0556434, -0.2040259, 1.0572252]
+ ];
+ let linearSRGB = multiplyMatrixByVector(matrix, xyz);
+
+ return WI.Color._gammaCorrect(linearSRGB);
+ }
+
+ // Convert gamma-corrected sRGB or Display-P3 to linear light form.
+ static _toLinearLight(rgb)
+ {
+ return rgb.map(function(value) {
+ if (value < 0.04045)
+ return value / 12.92;
+
+ return Math.pow((value + 0.055) / 1.055, 2.4);
+ });
+ }
+
+ // Convert linear-light sRGB or Display-P3 to gamma corrected form.
+ // Inverse of `toLinearLight`.
+ static _gammaCorrect(rgb)
+ {
+ return rgb.map(function(value) {
+ if (value > 0.0031308)
+ return 1.055 * Math.pow(value, 1 / 2.4) - 0.055;
+
+ return 12.92 * value;
+ });
+ }
+
static cmyk2rgb(c, m, y, k)
{
c = Number.constrain(c, 0, 1);
Modified: trunk/Source/WebInspectorUI/UserInterface/Views/ColorSquare.css (252746 => 252747)
--- trunk/Source/WebInspectorUI/UserInterface/Views/ColorSquare.css 2019-11-21 20:27:42 UTC (rev 252746)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/ColorSquare.css 2019-11-21 21:11:07 UTC (rev 252747)
@@ -25,6 +25,8 @@
.color-square {
position: relative;
+
+ --stroke-opacity: 0.8;
}
.color-square > .saturation-gradient {
@@ -53,7 +55,46 @@
box-shadow: 0 0 2px black;
border-radius: 3px;
pointer-events: none;
+ z-index: 9;
--border-width: 1px;
--crosshair-size: 7px;
}
+
+.color-square .svg-root {
+ position: absolute;
+ top: 0;
+ left: 0;
+ width: 100%;
+ height: 100%;
+ pointer-events: none;
+}
+
+.color-square .srgb-edge {
+ fill: none;
+ stroke: white;
+ stroke-width: 0.5px;
+ stroke-opacity: var(--stroke-opacity);
+}
+
+.color-square .srgb-label {
+ position: absolute;
+ padding-right: 3px;
+ color: hsla(0, 0%, 100%, var(--stroke-opacity));
+ font-size: 10px;
+}
+
+.color-square .srgb-label:hover {
+ color: white;
+}
+
+.color-square .srgb-label:hover + .svg-root > .srgb-edge {
+ stroke-width: 1px;
+}
+
+@media (-webkit-device-pixel-ratio: 1) {
+ .color-square .srgb-edge {
+ stroke-width: 1px;
+ stroke-opacity: var(--stroke-opacity) / 2;
+ }
+}
Modified: trunk/Source/WebInspectorUI/UserInterface/Views/ColorSquare.js (252746 => 252747)
--- trunk/Source/WebInspectorUI/UserInterface/Views/ColorSquare.js 2019-11-21 20:27:42 UTC (rev 252746)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/ColorSquare.js 2019-11-21 21:11:07 UTC (rev 252747)
@@ -44,6 +44,10 @@
let lightnessGradientElement = this._element.appendChild(document.createElement("div"));
lightnessGradientElement.className = "lightness-gradient fill";
+ this._srgbLabelElement = null;
+ this._svgElement = null;
+ this._polylineElement = null;
+
this._element.addEventListener("mousedown", this);
this._crosshairElement = this._element.appendChild(document.createElement("div"));
@@ -106,6 +110,8 @@
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);
@@ -207,6 +213,9 @@
this._element.style.backgroundColor = `hsl(${this._hue}, 100%, 50%)`;
this._updateCrosshairBackground();
+
+ if (this._gamut === WI.Color.Gamut.DisplayP3)
+ this._drawSRGBOutline();
}
_updateCrosshairBackground()
@@ -213,4 +222,63 @@
{
this._crosshairElement.style.backgroundColor = this.tintedColor.toString();
}
+
+ _drawSRGBOutline()
+ {
+ if (!this._svgElement) {
+ this._srgbLabelElement = this._element.appendChild(document.createElement("span"));
+ this._srgbLabelElement.className = "srgb-label";
+ this._srgbLabelElement.textContent = WI.unlocalizedString("sRGB");
+ this._srgbLabelElement.title = WI.UIString("This line marks the edge of sRGB color space", "Label for a guide within the color picker");
+
+ const svgNamespace = "http://www.w3.org/2000/svg";
+ this._svgElement = document.createElementNS(svgNamespace, "svg");
+ this._svgElement.classList.add("svg-root");
+ this._element.append(this._svgElement);
+
+ this._polylineElement = this._svgElement.appendChild(document.createElementNS(svgNamespace, "polyline"));
+ this._polylineElement.classList.add("srgb-edge");
+ }
+
+ let points = [];
+ let step = 1 / window.devicePixelRatio;
+ let x = 0;
+ for (let y = 0; y < this._dimension; y += step) {
+ let value = 100 - (y / this._dimension) * 100;
+
+ // Optimization: instead of starting from x = 0, we can benefit from the fact that the next point
+ // always has x >= of the current x. This minimizes processing time over 100 times.
+ for (; x < this._dimension; x += step) {
+ let saturation = x / this._dimension * 100;
+ let rgb = WI.Color.hsv2rgb(this._hue, saturation, value);
+ let srgb = WI.Color.displayP3toSRGB(rgb[0], rgb[1], rgb[2]);
+ if (srgb.some((value) => value > 1 || value < 0)) {
+ // The point is outside of sRGB.
+ points.push({x, y});
+ break;
+ }
+ }
+ }
+
+ if (points.lastValue.y < this._dimension * 0.95) {
+ // For `color(display-p3 0 0 1)`, the line is almost horizontal.
+ // Position the label directly under the line.
+ points.push({x: this._dimension, y: points.lastValue.y});
+ this._srgbLabelElement.style.removeProperty("bottom");
+ this._srgbLabelElement.style.top = `${points.lastValue.y}px`;
+ } else {
+ this._srgbLabelElement.style.removeProperty("top");
+ this._srgbLabelElement.style.bottom = "0px";
+ }
+
+ this._srgbLabelElement.style.right = `${this._dimension - points.lastValue.x}px`;
+
+ this._polylineElement.points.clear();
+ for (let point of points) {
+ let svgPoint = this._svgElement.createSVGPoint();
+ svgPoint.x = point.x;
+ svgPoint.y = point.y;
+ this._polylineElement.points.appendItem(svgPoint);
+ }
+ }
};