Changeset 192040 in webkit
- Timestamp:
- Nov 4, 2015 3:59:48 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r192039 r192040 1 2015-11-04 Joseph Pecoraro <pecoraro@apple.com> 2 3 Web Inspector: Support #rgba and #rrggbbaa syntax 4 https://bugs.webkit.org/show_bug.cgi?id=150894 5 6 Reviewed by Timothy Hatcher. 7 8 * inspector/model/color-expected.txt: Added. 9 * inspector/model/color.html: Added. 10 1 11 2015-11-04 Wenson Hsieh <wenson_hsieh@apple.com> 2 12 -
trunk/Source/WebInspectorUI/ChangeLog
r192005 r192040 1 2015-11-04 Joseph Pecoraro <pecoraro@apple.com> 2 3 Web Inspector: WebInspector.Color should support #rgba and #rrggbbaa syntax 4 https://bugs.webkit.org/show_bug.cgi?id=150894 5 6 Reviewed by Timothy Hatcher. 7 8 Support for hex with alpha color syntax. 9 10 * UserInterface/Models/Color.js: 11 (WebInspector.Color.fromString): 12 (WebInspector.Color.prototype.nextFormat): 13 (WebInspector.Color.prototype.copy): 14 (WebInspector.Color.prototype.toString): 15 (WebInspector.Color.prototype._toShortHEXAlphaString): 16 (WebInspector.Color.prototype._toHEXAlphaString): 17 Add support for new hex syntax. Address some minor issues 18 like case insensitivity and extra comma separate values. 19 20 * UserInterface/Views/CodeMirrorTextMarkers.js: 21 This prevent trailing hex characters from showing up 22 when cycling through color variants. 23 24 * UserInterface/Views/CodeMirrorAdditions.js: 25 When CodeMirror stops treating the new values as error 26 this will give them our hex-color styles. 27 1 28 2015-11-03 Matt Baker <mattbaker@apple.com> 2 29 -
trunk/Source/WebInspectorUI/UserInterface/Models/Color.js
r189965 r192040 56 56 57 57 // Simple - #hex, rgb(), nickname, hsl() 58 var simple = /^(?:#([0-9a-f]{3, 6})|rgb\(([^)]+)\)|(\w+)|hsl\(([^)]+)\))$/i;58 var simple = /^(?:#([0-9a-f]{3,8})|rgb\(([^)]+)\)|(\w+)|hsl\(([^)]+)\))$/i; 59 59 var match = colorString.match(simple); 60 60 if (match) { 61 61 if (match[1]) { // hex 62 62 var hex = match[1].toUpperCase(); 63 if (hex.length === 3) { 63 var len = hex.length; 64 if (len === 3) { 64 65 return new WebInspector.Color(WebInspector.Color.Format.ShortHEX, [ 65 66 parseInt(hex.charAt(0) + hex.charAt(0), 16), … … 68 69 1 69 70 ]); 70 } else {71 } else if (len === 6) { 71 72 return new WebInspector.Color(WebInspector.Color.Format.HEX, [ 72 73 parseInt(hex.substring(0, 2), 16), … … 75 76 1 76 77 ]); 77 } 78 } else if (len === 4) { 79 return new WebInspector.Color(WebInspector.Color.Format.ShortHEXAlpha, [ 80 parseInt(hex.charAt(0) + hex.charAt(0), 16), 81 parseInt(hex.charAt(1) + hex.charAt(1), 16), 82 parseInt(hex.charAt(2) + hex.charAt(2), 16), 83 parseInt(hex.charAt(3) + hex.charAt(3), 16) / 255 84 ]); 85 } else if (len === 8) { 86 return new WebInspector.Color(WebInspector.Color.Format.HEXAlpha, [ 87 parseInt(hex.substring(0, 2), 16), 88 parseInt(hex.substring(2, 4), 16), 89 parseInt(hex.substring(4, 6), 16), 90 parseInt(hex.substring(6, 8), 16) / 255 91 ]); 92 } else 93 return null; 78 94 } else if (match[2]) { // rgb 79 95 var rgb = match[2].split(/\s*,\s*/); 96 if (rgb.length !== 3) 97 return null; 80 98 return new WebInspector.Color(WebInspector.Color.Format.RGB, [ 81 99 parseInt(rgb[0]), … … 95 113 } else if (match[4]) { // hsl 96 114 var hsl = match[4].replace(/%/g, "").split(/\s*,\s*/); 115 if (hsl.length !== 3) 116 return null; 97 117 return new WebInspector.Color(WebInspector.Color.Format.HSL, [ 98 118 parseInt(hsl[0]), … … 105 125 106 126 // Advanced - rgba(), hsla() 107 var advanced = /^(?:rgba\(([^)]+)\)|hsla\(([^)]+)\))$/ ;127 var advanced = /^(?:rgba\(([^)]+)\)|hsla\(([^)]+)\))$/i; 108 128 match = colorString.match(advanced); 109 129 if (match) { 110 130 if (match[1]) { // rgba 111 131 var rgba = match[1].split(/\s*,\s*/); 132 if (rgba.length !== 4) 133 return null; 112 134 return new WebInspector.Color(WebInspector.Color.Format.RGBA, [ 113 135 parseInt(rgba[0]), … … 118 140 } else if (match[2]) { // hsla 119 141 var hsla = match[2].replace(/%/g, "").split(/\s*,\s*/); 142 if (hsla.length !== 4) 143 return null; 120 144 return new WebInspector.Color(WebInspector.Color.Format.HSLA, [ 121 145 parseInt(hsla[0]), … … 223 247 if (this.simple) 224 248 return this._canBeSerializedAsShortHEX() ? WebInspector.Color.Format.ShortHEX : WebInspector.Color.Format.HEX; 225 else 226 return WebInspector.Color.Format.Original; 249 return this._canBeSerializedAsShortHEX() ? WebInspector.Color.Format.ShortHEXAlpha : WebInspector.Color.Format.HEXAlpha; 227 250 228 251 case WebInspector.Color.Format.ShortHEX: 229 252 return WebInspector.Color.Format.HEX; 230 253 254 case WebInspector.Color.Format.ShortHEXAlpha: 255 return WebInspector.Color.Format.HEXAlpha; 256 231 257 case WebInspector.Color.Format.HEX: 258 case WebInspector.Color.Format.HEXAlpha: 232 259 return WebInspector.Color.Format.Original; 233 260 … … 235 262 if (this.simple) 236 263 return this._canBeSerializedAsShortHEX() ? WebInspector.Color.Format.ShortHEX : WebInspector.Color.Format.HEX; 237 else 238 return WebInspector.Color.Format.Original; 264 return this._canBeSerializedAsShortHEX() ? WebInspector.Color.Format.ShortHEXAlpha : WebInspector.Color.Format.HEXAlpha; 239 265 240 266 default: … … 288 314 case WebInspector.Color.Format.HEX: 289 315 case WebInspector.Color.Format.ShortHEX: 316 case WebInspector.Color.Format.HEXAlpha: 317 case WebInspector.Color.Format.ShortHEXAlpha: 290 318 case WebInspector.Color.Format.Nickname: 291 319 case WebInspector.Color.Format.RGBA: … … 317 345 case WebInspector.Color.Format.ShortHEX: 318 346 return this._toShortHEXString(); 347 case WebInspector.Color.Format.HEXAlpha: 348 return this._toHEXAlphaString(); 349 case WebInspector.Color.Format.ShortHEXAlpha: 350 return this._toShortHEXAlphaString(); 319 351 case WebInspector.Color.Format.Nickname: 320 352 return this._toNicknameString(); … … 383 415 384 416 return "#" + r + g + b; 417 } 418 419 _toShortHEXAlphaString() 420 { 421 let rgba = this.rgba; 422 let r = this._componentToHexValue(rgba[0]); 423 let g = this._componentToHexValue(rgba[1]); 424 let b = this._componentToHexValue(rgba[2]); 425 let a = this._componentToHexValue(Math.round(rgba[3] * 255)); 426 427 if (r[0] === r[1] && g[0] === g[1] && b[0] === b[1] && a[0] === a[1]) 428 return "#" + r[0] + g[0] + b[0] + a[0]; 429 else 430 return "#" + r + g + b + a; 431 } 432 433 _toHEXAlphaString() 434 { 435 let rgba = this.rgba; 436 let r = this._componentToHexValue(rgba[0]); 437 let g = this._componentToHexValue(rgba[1]); 438 let b = this._componentToHexValue(rgba[2]); 439 let a = this._componentToHexValue(Math.round(rgba[3] * 255)); 440 441 return "#" + r + g + b + a; 385 442 } 386 443 … … 525 582 HEX: "color-format-hex", 526 583 ShortHEX: "color-format-short-hex", 584 HEXAlpha: "color-format-hex-alpha", 585 ShortHEXAlpha: "color-format-short-hex-alpha", 527 586 RGB: "color-format-rgb", 528 587 RGBA: "color-format-rgba", -
trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorAdditions.js
r191519 r192040 254 254 function extendedCSSToken(stream, state) 255 255 { 256 var hexColorRegex = /#(?:[0-9a-fA-F]{ 6}|[0-9a-fA-F]{3})\b/g;256 var hexColorRegex = /#(?:[0-9a-fA-F]{8}|[0-9a-fA-F]{6}|[0-9a-fA-F]{3,4})\b/g; 257 257 258 258 if (state._urlTokenize) { -
trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorTextMarkers.js
r188028 r192040 86 86 { 87 87 // Matches rgba(0, 0, 0, 0.5), rgb(0, 0, 0), hsl(), hsla(), #fff, #ffffff, white 88 var colorRegex = /((?:rgb|hsl)a?\([^)]+\)|#[0-9a-fA-F]{ 6}|#[0-9a-fA-F]{3}|\b\w+\b(?![-.]))/g;88 var colorRegex = /((?:rgb|hsl)a?\([^)]+\)|#[0-9a-fA-F]{8}|#[0-9a-fA-F]{6}|#[0-9a-fA-F]{3,4}|\b\w+\b(?![-.]))/g; 89 89 function matchFunction(lineContent, match) { 90 90 // Act as a negative look-behind and disallow the color from being prefixing with certain characters.
Note: See TracChangeset
for help on using the changeset viewer.