Changeset 251933 in webkit
- Timestamp:
- Nov 1, 2019 12:34:09 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r251930 r251933 1 2019-11-01 Nikita Vasilyev <nvasilyev@apple.com> 2 3 Web Inspector: Display color swatches for p3 colors 4 https://bugs.webkit.org/show_bug.cgi?id=203439 5 <rdar://problem/56637250> 6 7 Reviewed by Devin Rousso. 8 9 * inspector/model/color-expected.txt: 10 * inspector/model/color.html: 11 1 12 2019-11-01 Ryosuke Niwa <rniwa@webkit.org> 2 13 -
trunk/LayoutTests/inspector/model/color-expected.txt
r251885 r251933 332 332 "hsla( 10turn 20% 30% / 40% )" resolves to "hsla(360, 20%, 30%, 0.4)" 333 333 "hsla(999turn 999% 999% / 999%)" resolves to "hsla(360, 100%, 100%, 1)" 334 "color(display-p3 0 1 0.5)" resolves to "color(display-p3 0 1 0.5)" 335 "COLOR(DISPLAY-P3 0 1 0.5)" resolves to "color(display-p3 0 1 0.5)" 336 "color(srgb 0.123 0.999 1)" resolves to "color(srgb 0.123 0.999 1)" 337 "COLOR(SRGB 0.123 0.999 1)" resolves to "color(srgb 0.123 0.999 1)" 338 "color( display-p3 0 1 0.5 )" resolves to "color(display-p3 0 1 0.5)" 339 "color(display-p3 999 999 999)" resolves to "color(display-p3 1 1 1)" 340 "color(srgb 0.123 0.999 1/0.5)" resolves to "color(srgb 0.123 0.999 1 / 0.5)" 341 "COLOR(SRGB 0.123 0.999 1/0.5)" resolves to "color(srgb 0.123 0.999 1 / 0.5)" 342 "color( display-p3 0 1 0.5/0.5)" resolves to "color(display-p3 0 1 0.5 / 0.5)" 343 "color(display-p3 999 999 999/999)" resolves to "color(display-p3 1 1 1)" 344 "color(srgb 0.123 0.999 1 / 0.5)" resolves to "color(srgb 0.123 0.999 1 / 0.5)" 345 "COLOR(SRGB 0.123 0.999 1 / 0.5)" resolves to "color(srgb 0.123 0.999 1 / 0.5)" 346 "color( display-p3 0 1 0.5 / 0.5)" resolves to "color(display-p3 0 1 0.5 / 0.5)" 347 "color(display-p3 999 999 999 / 999)" resolves to "color(display-p3 1 1 1)" 348 "color(srgb 0.123 0.999 1/33%)" resolves to "color(srgb 0.123 0.999 1 / 0.33)" 349 "COLOR(SRGB 0.123 0.999 1/33%)" resolves to "color(srgb 0.123 0.999 1 / 0.33)" 350 "color( display-p3 0 1 0.5/33%)" resolves to "color(display-p3 0 1 0.5 / 0.33)" 351 "color(display-p3 999 999 999/999%)" resolves to "color(display-p3 1 1 1)" 352 "color(srgb 0.123 0.999 1 / 33%)" resolves to "color(srgb 0.123 0.999 1 / 0.33)" 353 "COLOR(SRGB 0.123 0.999 1 / 33%)" resolves to "color(srgb 0.123 0.999 1 / 0.33)" 354 "color( display-p3 0 1 0.5 / 33%)" resolves to "color(display-p3 0 1 0.5 / 0.33)" 355 "color(display-p3 999 999 999 / 999%)" resolves to "color(display-p3 1 1 1)" 334 356 335 357 PASS: ' #000 ' should not be detected … … 345 367 PASS: 'hsla(0, 0%, 50%, 1, 2)' should not be detected 346 368 PASS: 'superblue' should not be detected 369 PASS: 'color(display-p3 0 1)' should not be detected 370 PASS: 'color(display-p3 0 1 2 4 5)' should not be detected 347 371 348 372 -- Running test case: WI.Color properties … … 371 395 PASS: '#11223344' should be serializable as a short Hex 372 396 PASS: '#11223345' should not be serializable as a short Hex 397 PASS: 'color(display-p3 0 1 0.5)' color should have a default alpha of 1 398 PASS: color function is not a keyword 399 PASS: 'color(display-p3 0 1 0.5)' has rgb of [0, 1, 0.5] 400 PASS: 'color(display-p3 0 1 0.5)' has rgba of [0, 1, 0.5, 1] 401 PASS: 'color(display-p3 0 1 0.5 / 0.3)' should have an alpha of 0.3 402 PASS: color function is not a keyword 403 PASS: 'color(display-p3 0 1 0.5 / 0.3)' has rgb of [0, 1, 0.5] 404 PASS: 'color(display-p3 0 1 0.5 / 0.3)' has rgba of [0, 1, 0.5, 0.3] 373 405 374 406 -- Running test case: WI.Color from components -
trunk/LayoutTests/inspector/model/color.html
r251885 r251933 28 28 case WI.Color.Format.HSLA: 29 29 return "HSLA"; 30 case WI.Color.Format.ColorFunction: 31 return "Function"; 30 32 default: 31 33 return "Unexpected format"; … … 224 226 testGood(`hsla(999${unit} 999% 999% / 999%)`, WI.Color.Format.HSLA); 225 227 } 228 229 testGood("color(display-p3 0 1 0.5)", WI.Color.Format.ColorFunction); 230 testGood("COLOR(DISPLAY-P3 0 1 0.5)", WI.Color.Format.ColorFunction); 231 232 testGood("color(srgb 0.123 0.999 1)", WI.Color.Format.ColorFunction); 233 testGood("COLOR(SRGB 0.123 0.999 1)", WI.Color.Format.ColorFunction); 234 testGood("color( display-p3 0 1 0.5 )", WI.Color.Format.ColorFunction); 235 testGood("color(display-p3 999 999 999)", WI.Color.Format.ColorFunction); 236 237 testGood("color(srgb 0.123 0.999 1/0.5)", WI.Color.Format.ColorFunction); 238 testGood("COLOR(SRGB 0.123 0.999 1/0.5)", WI.Color.Format.ColorFunction); 239 testGood("color( display-p3 0 1 0.5/0.5)", WI.Color.Format.ColorFunction); 240 testGood("color(display-p3 999 999 999/999)", WI.Color.Format.ColorFunction); 241 242 testGood("color(srgb 0.123 0.999 1 / 0.5)", WI.Color.Format.ColorFunction); 243 testGood("COLOR(SRGB 0.123 0.999 1 / 0.5)", WI.Color.Format.ColorFunction); 244 testGood("color( display-p3 0 1 0.5 / 0.5)", WI.Color.Format.ColorFunction); 245 testGood("color(display-p3 999 999 999 / 999)", WI.Color.Format.ColorFunction); 246 247 testGood("color(srgb 0.123 0.999 1/33%)", WI.Color.Format.ColorFunction); 248 testGood("COLOR(SRGB 0.123 0.999 1/33%)", WI.Color.Format.ColorFunction); 249 testGood("color( display-p3 0 1 0.5/33%)", WI.Color.Format.ColorFunction); 250 testGood("color(display-p3 999 999 999/999%)", WI.Color.Format.ColorFunction); 251 252 testGood("color(srgb 0.123 0.999 1 / 33%)", WI.Color.Format.ColorFunction); 253 testGood("COLOR(SRGB 0.123 0.999 1 / 33%)", WI.Color.Format.ColorFunction); 254 testGood("color( display-p3 0 1 0.5 / 33%)", WI.Color.Format.ColorFunction); 255 testGood("color(display-p3 999 999 999 / 999%)", WI.Color.Format.ColorFunction); 226 256 227 257 InspectorTest.log(""); … … 239 269 testBad("hsla(0, 0%, 50%, 1, 2)"); // extra values 240 270 testBad("superblue"); // not a keyword 271 testBad("color(display-p3 0 1)"); // 2 272 testBad("color(display-p3 0 1 2 4 5)"); // 5 241 273 242 274 // FIXME: currentColor? … … 288 320 color = WI.Color.fromString("#11223345"); 289 321 InspectorTest.expectThat(color.canBeSerializedAsShortHEX() === false, "'#11223345' should not be serializable as a short Hex"); 322 323 color = WI.Color.fromString("color(display-p3 0 1 0.5)"); 324 InspectorTest.expectThat(color.alpha === 1, "'color(display-p3 0 1 0.5)' color should have a default alpha of 1"); 325 InspectorTest.expectThat(color.isKeyword() === false, "color function is not a keyword"); 326 InspectorTest.expectShallowEqual(color.rgb, [0, 1, 0.5], "'color(display-p3 0 1 0.5)' has rgb of [0, 1, 0.5]"); 327 InspectorTest.expectShallowEqual(color.rgba, [0, 1, 0.5, 1], "'color(display-p3 0 1 0.5)' has rgba of [0, 1, 0.5, 1]"); 328 329 color = WI.Color.fromString("color(display-p3 0 1 0.5 / 0.3)"); 330 InspectorTest.expectThat(color.alpha === 0.3, "'color(display-p3 0 1 0.5 / 0.3)' should have an alpha of 0.3"); 331 InspectorTest.expectThat(color.isKeyword() === false, "color function is not a keyword"); 332 InspectorTest.expectShallowEqual(color.rgb, [0, 1, 0.5], "'color(display-p3 0 1 0.5 / 0.3)' has rgb of [0, 1, 0.5]"); 333 InspectorTest.expectShallowEqual(color.rgba, [0, 1, 0.5, 0.3], "'color(display-p3 0 1 0.5 / 0.3)' has rgba of [0, 1, 0.5, 0.3]"); 290 334 291 335 return true; -
trunk/Source/WebInspectorUI/ChangeLog
r251932 r251933 1 2019-11-01 Nikita Vasilyev <nvasilyev@apple.com> 2 3 Web Inspector: Display color swatches for p3 colors 4 https://bugs.webkit.org/show_bug.cgi?id=203439 5 <rdar://problem/56637250> 6 7 Reviewed by Devin Rousso. 8 9 Detect `color(display-p3 0 1 0)` as a color in the style editor. 10 11 * UserInterface/Models/Color.js: 12 (WI.Color): 13 (WI.Color.fromString): 14 (WI.Color.prototype.copy): 15 (WI.Color.prototype.toString): 16 (WI.Color.prototype.isKeyword): 17 (WI.Color.prototype._toFunctionString): 18 1 19 2019-11-01 Devin Rousso <drousso@apple.com> 2 20 -
trunk/Source/WebInspectorUI/UserInterface/Models/Color.js
r251885 r251933 30 30 WI.Color = class Color 31 31 { 32 constructor(format, components )32 constructor(format, components, gamut) 33 33 { 34 34 this.format = format; 35 this.gamut = gamut || "srgb"; 35 36 36 37 if (components.length === 3) … … 49 50 static fromString(colorString) 50 51 { 51 const matchRegExp = /^(?:#(?<hex>[0-9a-f]{3,8})|rgba?\((?<rgb>[^)]+)\)|(?<keyword>\w+)| hsla?\((?<hsl>[^)]+)\))$/i;52 const matchRegExp = /^(?:#(?<hex>[0-9a-f]{3,8})|rgba?\((?<rgb>[^)]+)\)|(?<keyword>\w+)|color\((?<color>[^)]+)\)|hsla?\((?<hsl>[^)]+)\))$/i; 52 53 let match = colorString.match(matchRegExp); 53 54 if (!match) … … 169 170 alpha, 170 171 ]); 172 } 173 174 if (match.groups.color) { 175 let colorString = match.groups.color.trim(); 176 let components = splitFunctionString(colorString); 177 if (components.length !== 4 && components.length !== 5) 178 return null; 179 180 let gamut = components[0].toLowerCase(); 181 if (gamut !== "srgb" && gamut !== "display-p3") 182 return null; 183 184 let alpha = 1; 185 if (components.length === 5) 186 alpha = parseFunctionAlpha(components[4]); 187 188 function parseFunctionComponent(component) { 189 let value = parseFloat(component); 190 return Number.constrain(value, 0, 1); 191 } 192 193 return new WI.Color(WI.Color.Format.ColorFunction, [ 194 parseFunctionComponent(components[1]), 195 parseFunctionComponent(components[2]), 196 parseFunctionComponent(components[3]), 197 alpha, 198 ], gamut); 171 199 } 172 200 … … 387 415 case WI.Color.Format.Keyword: 388 416 case WI.Color.Format.RGBA: 389 return new WI.Color(this.format, this.rgba); 417 case WI.Color.Format.ColorFunction: 418 return new WI.Color(this.format, this.rgba, this.gamut); 390 419 case WI.Color.Format.HSL: 391 420 case WI.Color.Format.HSLA: 392 return new WI.Color(this.format, this.hsla );421 return new WI.Color(this.format, this.hsla, this.gamut); 393 422 } 394 423 } … … 406 435 case WI.Color.Format.RGBA: 407 436 return this._toRGBAString(); 437 case WI.Color.Format.ColorFunction: 438 return this._toFunctionString(); 408 439 case WI.Color.Format.HSL: 409 440 return this._toHSLString(); … … 431 462 return true; 432 463 464 if (this.gamut !== "srgb") 465 return false; 466 433 467 if (!this.simple) 434 468 return Array.shallowEqual(this._rgba, [0, 0, 0, 0]) || Array.shallowEqual(this._hsla, [0, 0, 0, 0]); … … 566 600 let b = WI.Color._eightBitChannel(Math.round(this.rgba[2])); 567 601 return `rgba(${r}, ${g}, ${b}, ${this.alpha})`; 602 } 603 604 _toFunctionString() 605 { 606 let [r, g, b, alpha] = this.rgba; 607 if (alpha === 1) 608 return `color(${this.gamut} ${r} ${g} ${b})`; 609 return `color(${this.gamut} ${r} ${g} ${b} / ${alpha})`; 568 610 } 569 611 … … 620 662 RGBA: "color-format-rgba", 621 663 HSL: "color-format-hsl", 622 HSLA: "color-format-hsla" 664 HSLA: "color-format-hsla", 665 ColorFunction: "color-format-color-function", 623 666 }; 624 667 … … 628 671 "hsl", 629 672 "hsla", 673 "color", 630 674 ]); 631 675
Note: See TracChangeset
for help on using the changeset viewer.