Changeset 194977 in webkit
- Timestamp:
- Jan 13, 2016 1:14:44 PM (8 years ago)
- Location:
- trunk/Source/WebInspectorUI
- Files:
-
- 13 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebInspectorUI/ChangeLog
r194936 r194977 1 2016-01-13 Devin Rousso <dcrousso+webkit@gmail.com> 2 3 Web Inspector: Add support for the existing GradientEditor in the CSS Rules sidebar 4 https://bugs.webkit.org/show_bug.cgi?id=153004 5 6 Reviewed by Timothy Hatcher. 7 8 Both the Visual sidebar and Resource view have editors for CSS gradient 9 values, but the Rules sidebar instead only adds editors for basic color 10 values. Instead of duplicating the code for gradient swatches, existing 11 code will be used to give this same functionality to the Rules sidebar. 12 13 * Localizations/en.lproj/localizedStrings.js: 14 * UserInterface/Main.html: 15 16 * UserInterface/Models/Gradient.js: 17 (WebInspector.Gradient): 18 (WebInspector.Gradient.fromString): 19 (WebInspector.Gradient.stopsWithComponents): 20 (WebInspector.Gradient.prototype.copy): 21 (WebInspector.Gradient.prototype.toString): 22 Refactored WebInspector.Gradient into its own class. 23 24 (WebInspector.LinearGradient): 25 (WebInspector.LinearGradient.prototype.toString): 26 Now uses WebInspector.Gradient inheritance and methods. 27 28 (WebInspector.RadialGradient): 29 (WebInspector.RadialGradient.prototype.toString): 30 Now uses WebInspector.Gradient inheritance and methods. 31 32 * UserInterface/Views/CSSStyleDeclarationTextEditor.css: 33 Use InlineSwatch.css values instead. 34 35 (.css-style-text-editor > .CodeMirror .CodeMirror-lines .cubic-bezier-marker): Deleted. 36 (@media (-webkit-max-device-pixel-ratio: 1)): Deleted. 37 (.css-style-text-editor > .CodeMirror .CodeMirror-lines .cubic-bezier-marker:hover): Deleted. 38 (.css-style-text-editor > .CodeMirror .CodeMirror-lines .cubic-bezier-marker:active): Deleted. 39 40 * UserInterface/Views/CSSStyleDeclarationTextEditor.js: 41 (WebInspector.CSSStyleDeclarationTextEditor.prototype.didDismissPopover): Deleted. 42 Removed unused popover member variable. 43 44 (WebInspector.CSSStyleDeclarationTextEditor.prototype._contentChanged): 45 (WebInspector.CSSStyleDeclarationTextEditor.prototype._updateTextMarkers.update): 46 (WebInspector.CSSStyleDeclarationTextEditor.prototype._createInlineSwatches.createSwatch): 47 (WebInspector.CSSStyleDeclarationTextEditor.prototype._createInlineSwatches.update): 48 (WebInspector.CSSStyleDeclarationTextEditor.prototype._createInlineSwatches): 49 Renamed variables for more consistent naming and reimplemented the logic 50 to use the new WebInspector.InlineSwatch methods. As a result, it was 51 possible to consolidate the 3 different type of swatch functions into a 52 single function. 53 54 (WebInspector.CSSStyleDeclarationTextEditor.prototype._commentProperty.update): 55 (WebInspector.CSSStyleDeclarationTextEditor.prototype._uncommentRange.update): 56 (WebInspector.CSSStyleDeclarationTextEditor.prototype._inlineSwatchValueChanged.update): 57 (WebInspector.CSSStyleDeclarationTextEditor.prototype._inlineSwatchValueChanged): 58 (WebInspector.CSSStyleDeclarationTextEditor.prototype._resetContent.update): 59 (WebInspector.CSSStyleDeclarationTextEditor.prototype._createColorSwatches.createSwatch): Deleted. 60 (WebInspector.CSSStyleDeclarationTextEditor.prototype._createColorSwatches.update): Deleted. 61 (WebInspector.CSSStyleDeclarationTextEditor.prototype._createColorSwatches): Deleted. 62 (WebInspector.CSSStyleDeclarationTextEditor.prototype._createBezierEditors.update): Deleted. 63 (WebInspector.CSSStyleDeclarationTextEditor.prototype._createBezierEditors): Deleted. 64 (WebInspector.CSSStyleDeclarationTextEditor.prototype._colorSwatchColorChanged.update): Deleted. 65 (WebInspector.CSSStyleDeclarationTextEditor.prototype._colorSwatchColorChanged): Deleted. 66 (WebInspector.CSSStyleDeclarationTextEditor.prototype._cubicBezierMarkerClicked.updateCodeMirror.update): Deleted. 67 (WebInspector.CSSStyleDeclarationTextEditor.prototype._cubicBezierMarkerClicked.updateCodeMirror): Deleted. 68 (WebInspector.CSSStyleDeclarationTextEditor.prototype._cubicBezierMarkerClicked): Deleted. 69 70 * UserInterface/Views/CodeMirrorTextMarkers.js: 71 (createCodeMirrorColorTextMarkers.matchFunction): 72 Added logic so that if the matched color string is found inside a gradient, 73 it will not have a marker created for it. 74 75 * UserInterface/Views/InlineSwatch.css: Renamed from Source/WebInspectorUI/UserInterface/Views/ColorSwatch.css. 76 Consolidated the various swatch CSS classes into one file. 77 78 (.inline-swatch): 79 (.inline-swatch.bezier): 80 (.inline-swatch.bezier:hover): 81 (.inline-swatch.bezier:active): 82 (@media (-webkit-max-device-pixel-ratio: 1)): 83 (.inline-swatch > span): 84 Ensured that the inner swatch element can not be selected so that the "click" 85 listener on its parent always fires. 86 87 (.inline-swatch:hover > span): 88 (.inline-swatch:active > span): 89 (.inline-swatch.bezier > span): 90 91 * UserInterface/Views/InlineSwatch.js: Renamed from Source/WebInspectorUI/UserInterface/Views/ColorSwatch.js. 92 (WebInspector.InlineSwatch): 93 Now accepts a new first argument to indicate what type of color swatch 94 to create and what functionality it will have. Currently has options 95 for WebInspector.Color, WebInspector.Gradient, and WebInspector.CubicBezier. 96 97 (WebInspector.InlineSwatch.prototype.get element): 98 (WebInspector.InlineSwatch.prototype.get value): 99 (WebInspector.InlineSwatch.prototype.set value): 100 (WebInspector.InlineSwatch.prototype._fallbackValue): 101 (WebInspector.InlineSwatch.prototype._updateSwatch): 102 (WebInspector.InlineSwatch.prototype._swatchElementClicked): 103 (WebInspector.InlineSwatch.prototype._valueEditorValueDidChange): 104 (WebInspector.InlineSwatch.prototype._handleContextMenuEvent): 105 (WebInspector.InlineSwatch.prototype._getNextValidHEXFormat.hexMatchesCurrentColor): 106 (WebInspector.InlineSwatch.prototype._getNextValidHEXFormat): 107 108 * UserInterface/Views/VisualStyleBackgroundPicker.css: 109 (.visual-style-property-container.background-picker > .visual-style-property-value-container > .inline-swatch.gradient): 110 (.visual-style-property-container.background-picker > .visual-style-property-value-container:not(.gradient-value) > .inline-swatch.gradient): 111 (.visual-style-property-container.background-picker > .visual-style-property-value-container > .inline-swatch.gradient:hover): 112 (.visual-style-property-container.background-picker > .visual-style-property-value-container > .inline-swatch.gradient:active): 113 (.visual-style-property-container.background-picker > .visual-style-property-value-container > .inline-swatch.gradient > span): 114 (.visual-style-property-container.background-picker > .visual-style-property-value-container.gradient-value > .inline-swatch.gradient + .value-input): 115 (.visual-style-property-container.background-picker > .visual-style-property-value-container > .color-swatch): Deleted. 116 (.visual-style-property-container.background-picker > .visual-style-property-value-container:not(.gradient-value) > .color-swatch): Deleted. 117 (.visual-style-property-container.background-picker > .visual-style-property-value-container > .color-swatch:hover): Deleted. 118 (.visual-style-property-container.background-picker > .visual-style-property-value-container > .color-swatch:active): Deleted. 119 (.visual-style-property-container.background-picker > .visual-style-property-value-container > .color-swatch > span): Deleted. 120 (.visual-style-property-container.background-picker > .visual-style-property-value-container.gradient-value > .color-swatch + .value-input): Deleted. 121 122 * UserInterface/Views/VisualStyleBackgroundPicker.js: 123 Removed the specific code for the gradient swatch and moved to using a 124 gradient-type InlineSwatch for gradient values instead. 125 126 (WebInspector.VisualStyleBackgroundPicker): 127 (WebInspector.VisualStyleBackgroundPicker.prototype.set value): 128 (WebInspector.VisualStyleBackgroundPicker.prototype._updateGradient): 129 (WebInspector.VisualStyleBackgroundPicker.prototype._gradientSwatchColorChanged): 130 (WebInspector.VisualStyleBackgroundPicker.prototype._valueInputValueChanged): 131 (WebInspector.VisualStyleBackgroundPicker.prototype._handleKeywordChanged): 132 (WebInspector.VisualStyleBackgroundPicker.prototype._updateGradientSwatch): Deleted. 133 (WebInspector.VisualStyleBackgroundPicker.prototype._gradientSwatchClicked.handleColorPickerToggled): Deleted. 134 (WebInspector.VisualStyleBackgroundPicker.prototype._gradientSwatchClicked): Deleted. 135 (WebInspector.VisualStyleBackgroundPicker.prototype._gradientEditorGradientChanged): Deleted. 136 137 * UserInterface/Views/VisualStyleColorPicker.css: 138 (.visual-style-property-container.input-color-picker > .visual-style-property-value-container > .inline-swatch.color): 139 (.visual-style-property-container.input-color-picker > .visual-style-property-value-container > .inline-swatch.color:hover): 140 (.visual-style-property-container.input-color-picker > .visual-style-property-value-container > .inline-swatch.color:active): 141 (.visual-style-property-container.input-color-picker > .visual-style-property-value-container > .inline-swatch.color > span): 142 Add override CSS to ensure that the color-type InlineSwatch displays nicely 143 next to the flexbox style Visual sidebar. 144 145 (.visual-style-property-container.input-color-picker > .visual-style-property-value-container > .color-swatch): Deleted. 146 (.visual-style-property-container.input-color-picker > .visual-style-property-value-container > .color-swatch:hover): Deleted. 147 (.visual-style-property-container.input-color-picker > .visual-style-property-value-container > .color-swatch:active): Deleted. 148 (.visual-style-property-container.input-color-picker > .visual-style-property-value-container > .color-swatch > span): Deleted. 149 Refactored to only use overriding properties of the basic .inline-swatch values. 150 151 * UserInterface/Views/VisualStyleColorPicker.js: 152 (WebInspector.VisualStyleColorPicker): 153 (WebInspector.VisualStyleColorPicker.prototype._colorSwatchColorChanged): 154 (WebInspector.VisualStyleColorPicker.prototype._updateColorSwatch): 155 156 * UserInterface/Views/VisualStyleTimingEditor.css: 157 (.visual-style-property-container.timing-editor > .visual-style-property-value-container > .inline-swatch.bezier): 158 (.visual-style-property-container.timing-editor > .visual-style-property-value-container:not(.bezier-value) > .inline-swatch.bezier): 159 (@media (-webkit-min-device-pixel-ratio: 2)): 160 Add override CSS to ensure that the color-type InlineSwatch displays nicely 161 next to the flexbox style Visual sidebar. 162 163 (.visual-style-property-container.timing-editor > .visual-style-property-value-container > .bezier-editor): Deleted. 164 (.visual-style-property-container.timing-editor > .visual-style-property-value-container > .bezier-editor:hover): Deleted. 165 (.visual-style-property-container.timing-editor > .visual-style-property-value-container > .bezier-editor:active): Deleted. 166 Refactored to only use overriding properties of the basic .inline-swatch values. 167 168 * UserInterface/Views/VisualStyleTimingEditor.js: 169 Removed the specific code for the cubic-bezier swatch and moved to using a 170 cubic-bezier-type InlineSwatch for gradient values instead. 171 172 (WebInspector.VisualStyleTimingEditor): 173 (WebInspector.VisualStyleTimingEditor.prototype.get bezierValue): 174 (WebInspector.VisualStyleTimingEditor.prototype.set bezierValue): 175 (WebInspector.VisualStyleTimingEditor.prototype._setValue): 176 (WebInspector.VisualStyleTimingEditor.prototype._handleKeywordChanged): 177 (WebInspector.VisualStyleTimingEditor.prototype._bezierSwatchValueChanged): 178 (WebInspector.VisualStyleTimingEditor.prototype._bezierMarkerClicked): Deleted. 179 1 180 2016-01-12 Matt Baker <mattbaker@apple.com> 2 181 -
trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js
r194936 r194977 131 131 localizedStrings["Click to enable the selected rule"] = "Click to enable the selected rule"; 132 132 localizedStrings["Click to link property values"] = "Click to link property values"; 133 localizedStrings["Click to open a cubic-bezier editor "] = "Click to open a cubic-bezier editor";133 localizedStrings["Click to open a cubic-bezier editor."] = "Click to open a cubic-bezier editor."; 134 134 localizedStrings["Click to remove link"] = "Click to remove link"; 135 135 localizedStrings["Click to remove the selected item."] = "Click to remove the selected item."; 136 136 localizedStrings["Click to restart the animation"] = "Click to restart the animation"; 137 137 localizedStrings["Click to select a color. Shift-click to switch color formats."] = "Click to select a color. Shift-click to switch color formats."; 138 localizedStrings["Click to select a gradient "] = "Click to select a gradient";138 localizedStrings["Click to select a gradient."] = "Click to select a gradient."; 139 139 localizedStrings["Clickable"] = "Clickable"; 140 140 localizedStrings["Clip"] = "Clip"; -
trunk/Source/WebInspectorUI/UserInterface/Main.html
r194728 r194977 49 49 <link rel="stylesheet" href="Views/CodeMirrorOverrides.css"> 50 50 <link rel="stylesheet" href="Views/ColorPicker.css"> 51 <link rel="stylesheet" href="Views/ColorSwatch.css">52 51 <link rel="stylesheet" href="Views/ColorWheel.css"> 53 52 <link rel="stylesheet" href="Views/CompletionSuggestionsView.css"> … … 96 95 <link rel="stylesheet" href="Views/IndeterminateProgressSpinner.css"> 97 96 <link rel="stylesheet" href="Views/IndexedDatabaseObjectStoreContentView.css"> 97 <link rel="stylesheet" href="Views/InlineSwatch.css"> 98 98 <link rel="stylesheet" href="Views/IssueTreeElement.css"> 99 99 <link rel="stylesheet" href="Views/LayerTreeDetailsSidebarPanel.css"> … … 437 437 <script src="Views/CodeMirrorTextMarkers.js"></script> 438 438 <script src="Views/ColorPicker.js"></script> 439 <script src="Views/ColorSwatch.js"></script>440 439 <script src="Views/ColorWheel.js"></script> 441 440 <script src="Views/CompletionSuggestionsView.js"></script> … … 499 498 <script src="Views/IndexedDatabaseObjectStoreTreeElement.js"></script> 500 499 <script src="Views/IndexedDatabaseTreeElement.js"></script> 500 <script src="Views/InlineSwatch.js"></script> 501 501 <script src="Views/IssueTreeElement.js"></script> 502 502 <script src="Views/LayerTreeDataGridNode.js"></script> -
trunk/Source/WebInspectorUI/UserInterface/Models/Gradient.js
r192705 r194977 24 24 */ 25 25 26 // FIXME: Convert to class? 27 WebInspector.Gradient = { 28 Types: { 29 Linear: "linear-gradient", 30 Radial: "radial-gradient" 31 }, 32 33 fromString(cssString) 26 WebInspector.Gradient = class Gradient 27 { 28 constructor(type, stops) 29 { 30 this.type = type; 31 this.stops = stops; 32 } 33 34 // Static 35 36 static fromString(cssString) 34 37 { 35 38 var type; … … 85 88 var gradient; 86 89 if (type === WebInspector.Gradient.Types.Linear) 87 gradient = WebInspector.LinearGradient. linearGradientWithComponents(components);90 gradient = WebInspector.LinearGradient.fromComponents(components); 88 91 else 89 gradient = WebInspector.RadialGradient. radialGradientWithComponents(components);92 gradient = WebInspector.RadialGradient.fromComponents(components); 90 93 91 94 if (gradient) … … 93 96 94 97 return gradient; 95 } ,96 97 st opsWithComponents(components)98 } 99 100 static stopsWithComponents(components) 98 101 { 99 102 // FIXME: handle lengths. … … 127 130 128 131 return stops; 129 }, 132 } 133 134 // Public 130 135 131 136 stringFromStops(stops) … … 139 144 }).join(", "); 140 145 } 146 147 // Public 148 149 copy() 150 { 151 // Implemented by subclasses. 152 } 153 154 toString() 155 { 156 // Implemented by subclasses. 157 } 141 158 }; 142 159 143 WebInspector.LinearGradient = class LinearGradient 160 WebInspector.Gradient.Types = { 161 Linear: "linear-gradient", 162 Radial: "radial-gradient" 163 }; 164 165 WebInspector.LinearGradient = class LinearGradient extends WebInspector.Gradient 144 166 { 145 167 constructor(angle, stops) 146 168 { 147 this.type = WebInspector.Gradient.Types.Linear;169 super(WebInspector.Gradient.Types.Linear, stops); 148 170 this.angle = angle; 149 this.stops = stops;150 171 } 151 172 152 173 // Static 153 174 154 static linearGradientWithComponents(components)175 static fromComponents(components) 155 176 { 156 177 var angle = 180; … … 234 255 str += ", "; 235 256 236 str += WebInspector.Gradient.stringFromStops(this.stops);257 str += this.stringFromStops(this.stops); 237 258 238 259 return (this.repeats ? "repeating-" : "") + this.type + "(" + str + ")"; … … 240 261 }; 241 262 242 WebInspector.RadialGradient = class RadialGradient 263 WebInspector.RadialGradient = class RadialGradient extends WebInspector.Gradient 243 264 { 244 265 constructor(sizing, stops) 245 266 { 246 this.type = WebInspector.Gradient.Types.Radial;267 super(WebInspector.Gradient.Types.Radial, stops); 247 268 this.sizing = sizing; 248 this.stops = stops;249 269 } 250 270 251 271 // Static 252 272 253 static radialGradientWithComponents(components)273 static fromComponents(components) 254 274 { 255 275 var sizing = !WebInspector.Color.fromString(components[0].join(" ")) ? components.shift().join(" ") : ""; … … 276 296 str += ", "; 277 297 278 str += WebInspector.Gradient.stringFromStops(this.stops);298 str += this.stringFromStops(this.stops); 279 299 280 300 return (this.repeats ? "repeating-" : "") + this.type + "(" + str + ")"; -
trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationTextEditor.css
r194568 r194977 92 92 } 93 93 94 .css-style-text-editor > .CodeMirror .CodeMirror-lines .cubic-bezier-marker {95 width: 11px;96 height: 11px;97 margin-right: 2px;98 vertical-align: -2px;99 content: url(../Images/CubicBezier.svg);100 cursor: default;101 }102 103 @media (-webkit-max-device-pixel-ratio: 1) {104 /* Ensure the bezier marker is even by even so it looks a bit less blurry. */105 .css-style-text-editor > .CodeMirror .CodeMirror-lines .cubic-bezier-marker {106 vertical-align: -1px;107 width: 10px;108 height: 10px;109 }110 }111 112 .css-style-text-editor > .CodeMirror .CodeMirror-lines .cubic-bezier-marker:hover {113 filter: brightness(0.9);114 }115 116 .css-style-text-editor > .CodeMirror .CodeMirror-lines .cubic-bezier-marker:active {117 filter: brightness(0.8);118 }119 120 94 .computed .css-style-text-editor > .CodeMirror .CodeMirror-lines .css-style-declaration-property.implicit, 121 95 .css-style-text-editor > .CodeMirror .CodeMirror-lines .css-style-declaration-property.not-inherited { -
trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationTextEditor.js
r194717 r194977 389 389 didDismissPopover(popover) 390 390 { 391 if (popover === this._colorPickerPopover)392 this._colorPickerPopover = null;393 391 if (popover === this._cubicBezierEditorPopover) 394 392 this._cubicBezierEditorPopover = null; … … 772 770 // will not go through _propertiesChanged until completionControllerCompletionsHidden happens. 773 771 // This way any auto completed colors get swatches right away. 774 if (this._completionController.isCompletionChange(change)) { 775 this._createColorSwatches(false, change.from.line); 776 this._createBezierEditors(false, change.from.line); 777 } 772 if (this._completionController.isCompletionChange(change)) 773 this._createInlineSwatches(false, change.from.line); 778 774 779 775 // Use a short delay for user input to coalesce more changes before committing. Other actions like … … 825 821 } 826 822 827 // Look for colors and make swatches. 828 this._createColorSwatches(true); 829 this._createBezierEditors(true); 823 // Look for swatchable values and make inline swatches. 824 this._createInlineSwatches(true); 830 825 831 826 this._markLinesWithCheckboxPlaceholder(); … … 873 868 } 874 869 875 _createColorSwatches(nonatomic, lineNumber) 876 { 870 _createInlineSwatches(nonatomic, lineNumber) 871 { 872 function createSwatch(swatch, marker, valueObject, valueString) 873 { 874 swatch.addEventListener(WebInspector.InlineSwatch.Event.ValueChanged, this._inlineSwatchValueChanged, this); 875 876 let codeMirrorTextMarker = marker.codeMirrorTextMarker; 877 let codeMirrorTextMarkerRange = codeMirrorTextMarker.find(); 878 this._codeMirror.setUniqueBookmark(codeMirrorTextMarkerRange.from, swatch.element); 879 880 swatch.__textMarker = codeMirrorTextMarker; 881 swatch.__textMarkerRange = codeMirrorTextMarkerRange; 882 } 883 877 884 function update() 878 885 { … … 880 887 881 888 // Look for color strings and add swatches in front of them. 882 createCodeMirrorColorTextMarkers(this._codeMirror, range, function(marker, color, colorString) { 883 let swatch = new WebInspector.ColorSwatch(color, this._codeMirror.getOption("readOnly")); 884 swatch.addEventListener(WebInspector.ColorSwatch.Event.ColorChanged, this._colorSwatchColorChanged, this); 885 886 let codeMirrorTextMarker = marker.codeMirrorTextMarker; 887 let codeMirrorTextMarkerRange = codeMirrorTextMarker.find(); 888 this._codeMirror.setUniqueBookmark(codeMirrorTextMarkerRange.from, swatch.element); 889 890 swatch.__colorTextMarker = codeMirrorTextMarker; 891 swatch.__colorTextMarkerRange = codeMirrorTextMarkerRange; 892 }.bind(this)); 893 } 894 895 if (nonatomic) 896 update.call(this); 897 else 898 this._codeMirror.operation(update.bind(this)); 899 } 900 901 _createBezierEditors(nonatomic, lineNumber) 902 { 903 function update() 904 { 905 var range = typeof lineNumber === "number" ? new WebInspector.TextRange(lineNumber, 0, lineNumber + 1, 0) : null; 906 907 // Look for cubic-bezier and timing functions and add cubic-bezier icons in front of them. 908 createCodeMirrorCubicBezierTextMarkers(this._codeMirror, range, function(marker, cubicBezier) { 909 var bezierMarker = document.createElement("span"); 910 bezierMarker.title = WebInspector.UIString("Click to open a cubic-bezier editor"); 911 bezierMarker.className = WebInspector.CSSStyleDeclarationTextEditor.BezierEditorClassName; 912 bezierMarker.addEventListener("click", this._cubicBezierMarkerClicked.bind(this)); 913 914 var codeMirrorTextMarker = marker.codeMirrorTextMarker; 915 this._codeMirror.setUniqueBookmark(codeMirrorTextMarker.find().from, bezierMarker); 916 917 bezierMarker.__textMarker = codeMirrorTextMarker; 918 bezierMarker.__bezier = cubicBezier; 919 }.bind(this)); 889 createCodeMirrorColorTextMarkers(this._codeMirror, range, (marker, color, colorString) => { 890 let swatch = new WebInspector.InlineSwatch(WebInspector.InlineSwatch.Type.Color, color, this._codeMirror.getOption("readOnly")); 891 createSwatch.call(this, swatch, marker, color, colorString); 892 }); 893 894 // Look for gradient strings and add swatches in front of them. 895 createCodeMirrorGradientTextMarkers(this._codeMirror, range, (marker, gradient, gradientString) => { 896 let swatch = new WebInspector.InlineSwatch(WebInspector.InlineSwatch.Type.Gradient, gradient, this._codeMirror.getOption("readOnly")); 897 createSwatch.call(this, swatch, marker, gradient, gradientString); 898 }); 899 900 // Look for cubic-bezier strings and add swatches in front of them. 901 createCodeMirrorCubicBezierTextMarkers(this._codeMirror, range, (marker, bezier, bezierString) => { 902 let swatch = new WebInspector.InlineSwatch(WebInspector.InlineSwatch.Type.Bezier, bezier, this._codeMirror.getOption("readOnly")); 903 createSwatch.call(this, swatch, marker, bezier, bezierString); 904 }); 920 905 } 921 906 … … 1272 1257 this._codeMirror.replaceRange("/* " + text + " */", range.from, range.to); 1273 1258 1274 // Update the line for any color swatches or cubic-beziers that got removed. 1275 this._createColorSwatches(true, range.from.line); 1276 this._createBezierEditors(true, range.from.line); 1259 // Update the line for any inline swatches that got removed. 1260 this._createInlineSwatches(true, range.from.line); 1277 1261 } 1278 1262 … … 1312 1296 this._codeMirror.replaceRange(text, range.from, range.to); 1313 1297 1314 // Update the line for any color swatches or cubic-beziers that got removed. 1315 this._createColorSwatches(true, range.from.line); 1316 this._createBezierEditors(true, range.from.line); 1298 // Update the line for any inline swatches that got removed. 1299 this._createInlineSwatches(true, range.from.line); 1317 1300 } 1318 1301 … … 1320 1303 } 1321 1304 1322 _ colorSwatchColorChanged(event)1305 _inlineSwatchValueChanged(event) 1323 1306 { 1324 1307 let swatch = event && event.target; … … 1327 1310 return; 1328 1311 1329 let colorString = event && event.data && event.data.color && event.data.color.toString();1330 console.assert( colorString);1331 if (! colorString)1332 return; 1333 1334 let colorTextMarker = swatch.__colorTextMarker;1335 let range = swatch.__ colorTextMarkerRange;1312 let value = event.data && event.data.value && event.data.value.toString(); 1313 console.assert(value); 1314 if (!value) 1315 return; 1316 1317 let textMarker = swatch.__textMarker; 1318 let range = swatch.__textMarkerRange; 1336 1319 console.assert(range); 1337 1320 if (!range) … … 1341 1324 { 1342 1325 // The original text marker might have been cleared by a style update, 1343 // in this case we need to find the new color text marker so we know1344 // the right range for the new style colortext.1345 if (! colorTextMarker || !colorTextMarker.find()) {1346 colorTextMarker = null;1326 // in this case we need to find the new text marker so we know the 1327 // right range for the new style text. 1328 if (!textMarker || !textMarker.find()) { 1329 textMarker = null; 1347 1330 1348 1331 let marks = this._codeMirror.findMarksAt(range.from); … … 1351 1334 1352 1335 for (let mark of marks) { 1353 if (WebInspector.TextMarker.textMarkerForCodeMirrorTextMarker(mark).type !== WebInspector.TextMarker.Type.Color) 1336 let type = WebInspector.TextMarker.textMarkerForCodeMirrorTextMarker(mark).type; 1337 if (type !== WebInspector.TextMarker.Type.Color && type !== WebInspector.TextMarker.Type.Gradient && type !== WebInspector.TextMarker.Type.CubicBezier) 1354 1338 continue; 1355 colorTextMarker = mark;1339 textMarker = mark; 1356 1340 break; 1357 1341 } 1358 1342 } 1359 1343 1360 if (! colorTextMarker)1344 if (!textMarker) 1361 1345 return; 1362 1346 1363 1347 // Sometimes we still might find a stale text marker with findMarksAt. 1364 let newRange = colorTextMarker.find();1365 if (! newRange)1348 range = textMarker.find(); 1349 if (!range) 1366 1350 return; 1367 1351 1368 range = newRange; 1369 1370 colorTextMarker.clear(); 1371 1372 this._codeMirror.replaceRange(colorString, range.from, range.to); 1373 1374 // The color's text format could have changed, so we need to update the "range" 1352 textMarker.clear(); 1353 1354 this._codeMirror.replaceRange(value, range.from, range.to); 1355 1356 // The value's text could have changed, so we need to update the "range" 1375 1357 // variable to anticipate a different "range.to" property. 1376 range.to.ch = range.from.ch + colorString.length;1377 1378 colorTextMarker = this._codeMirror.markText(range.from, range.to);1379 1380 swatch.__ colorTextMarker = colorTextMarker;1358 range.to.ch = range.from.ch + value.length; 1359 1360 textMarker = this._codeMirror.markText(range.from, range.to); 1361 1362 swatch.__textMarker = textMarker; 1381 1363 } 1382 1364 1383 1365 this._codeMirror.operation(update.bind(this)); 1384 }1385 1386 _cubicBezierMarkerClicked(event)1387 {1388 if (this._cubicBezierEditorPopover)1389 return;1390 1391 var bezierMarker = event.target;1392 1393 var bezier = bezierMarker.__bezier;1394 console.assert(bezier);1395 if (!bezier)1396 return;1397 1398 var bezierTextMarker = bezierMarker.__textMarker;1399 console.assert(bezierTextMarker);1400 if (!bezierTextMarker)1401 return;1402 1403 var range = bezierTextMarker.find();1404 console.assert(range);1405 if (!range)1406 return;1407 1408 function updateCodeMirror(newCubicBezierText)1409 {1410 function update()1411 {1412 // The original text marker might have been cleared by a style update,1413 // in this case we need to find the new bezier text marker so we know1414 // the right range for the new style bezier text.1415 if (!bezierTextMarker || !bezierTextMarker.find()) {1416 bezierTextMarker = null;1417 1418 var marks = this._codeMirror.findMarksAt(range.from);1419 if (!marks.length)1420 return;1421 1422 for (var i = 0; i < marks.length; ++i) {1423 var mark = marks[i];1424 if (WebInspector.TextMarker.textMarkerForCodeMirrorTextMarker(mark).type !== WebInspector.TextMarker.Type.CubicBezier)1425 continue;1426 bezierTextMarker = mark;1427 break;1428 }1429 }1430 1431 if (!bezierTextMarker)1432 return;1433 1434 // Sometimes we still might find a stale text marker with findMarksAt.1435 var newRange = bezierTextMarker.find();1436 if (!newRange)1437 return;1438 1439 range = newRange;1440 1441 bezierTextMarker.clear();1442 1443 this._codeMirror.replaceRange(newCubicBezierText, range.from, range.to);1444 1445 // The bezier's text format could have changed, so we need to update the "range"1446 // variable to anticipate a different "range.to" property.1447 range.to.ch = range.from.ch + newCubicBezierText.length;1448 1449 bezierTextMarker = this._codeMirror.markText(range.from, range.to);1450 1451 bezierMarker.__textMarker = bezierTextMarker;1452 }1453 1454 this._codeMirror.operation(update.bind(this));1455 }1456 1457 this._cubicBezierEditorPopover = new WebInspector.Popover(this);1458 1459 var bezierEditor = new WebInspector.BezierEditor;1460 1461 bezierEditor.addEventListener(WebInspector.BezierEditor.Event.BezierChanged, function(event) {1462 updateCodeMirror.call(this, event.data.bezier.toString());1463 }.bind(this));1464 1465 var bounds = WebInspector.Rect.rectFromClientRect(bezierMarker.getBoundingClientRect());1466 1467 this._cubicBezierEditorPopover.content = bezierEditor.element;1468 this._cubicBezierEditorPopover.present(bounds.pad(2), [WebInspector.RectEdge.MIN_X]);1469 1470 bezierEditor.bezier = bezier;1471 1366 } 1472 1367 … … 1682 1577 }.bind(this)); 1683 1578 1684 // Look for colors and make swatches. 1685 this._createColorSwatches(true); 1686 this._createBezierEditors(true); 1579 // Look for swatchable values and make inline swatches. 1580 this._createInlineSwatches(true); 1687 1581 1688 1582 // Restore the cursor position/selection. … … 1772 1666 WebInspector.CSSStyleDeclarationTextEditor.StyleClassName = "css-style-text-editor"; 1773 1667 WebInspector.CSSStyleDeclarationTextEditor.ReadOnlyStyleClassName = "read-only"; 1774 WebInspector.CSSStyleDeclarationTextEditor.BezierEditorClassName = "cubic-bezier-marker";1775 1668 WebInspector.CSSStyleDeclarationTextEditor.CheckboxPlaceholderElementStyleClassName = "checkbox-placeholder"; 1776 1669 WebInspector.CSSStyleDeclarationTextEditor.EditingLineStyleClassName = "editing-line"; -
trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorTextMarkers.js
r192040 r194977 85 85 function createCodeMirrorColorTextMarkers(codeMirror, range, callback) 86 86 { 87 // Matches rgba(0, 0, 0, 0.5), rgb(0, 0, 0), hsl(), hsla(), #fff, #ffff ff, white88 varcolorRegex = /((?:rgb|hsl)a?\([^)]+\)|#[0-9a-fA-F]{8}|#[0-9a-fA-F]{6}|#[0-9a-fA-F]{3,4}|\b\w+\b(?![-.]))/g;87 // Matches rgba(0, 0, 0, 0.5), rgb(0, 0, 0), hsl(), hsla(), #fff, #ffff, #ffffff, #ffffffff, white 88 let 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 if (!lineContent || !lineContent.length) 91 return false; 92 93 // In order determine if the matched color is inside a gradient, first 94 // look before the text to find the first unmatched open parenthesis. 95 // This parenthesis, if it exists, will be immediately after the CSS 96 // funciton whose name can be checked to see if it matches a gradient. 97 let openParenthesis = 0; 98 let index = match.index; 99 let c = null; 100 while (c = lineContent[index]) { 101 if (c === "(") 102 ++openParenthesis; 103 if (c === ")") 104 --openParenthesis; 105 106 if (openParenthesis > 0) 107 break; 108 109 --index; 110 if (index < 0) 111 break; 112 } 113 114 if (/(repeating-)?(linear|radial)-gradient$/.test(lineContent.substring(0, index))) 115 return false; 116 90 117 // Act as a negative look-behind and disallow the color from being prefixing with certain characters. 91 118 return !(match.index > 0 && /[-.\"\']/.test(lineContent[match.index - 1])); -
trunk/Source/WebInspectorUI/UserInterface/Views/InlineSwatch.css
r194976 r194977 25 25 */ 26 26 27 . color-swatch {27 .inline-swatch { 28 28 display: inline-block; 29 29 position: relative; … … 43 43 } 44 44 45 .inline-swatch.bezier { 46 margin-right: 2px; 47 content: url(../Images/CubicBezier.svg); 48 background: none; 49 } 50 51 .inline-swatch.bezier:hover { 52 filter: brightness(0.9); 53 } 54 55 .inline-swatch.bezier:active { 56 filter: brightness(0.8); 57 } 58 45 59 @media (-webkit-max-device-pixel-ratio: 1) { 46 60 /* Ensure the color swatch is even by even so that it looks okay checkered. */ 47 . color-swatch {61 .inline-swatch { 48 62 vertical-align: -1px; 49 63 width: 10px; … … 52 66 } 53 67 54 . color-swatch > span {68 .inline-swatch > span { 55 69 position: absolute; 56 70 top: 0; … … 59 73 left: 0; 60 74 border: 1px solid hsla(0, 0%, 25%, 0.4); 75 pointer-events: none; 61 76 } 62 77 63 . color-swatch:hover > span {78 .inline-swatch:hover > span { 64 79 border-color: hsla(0, 0%, 25%, 0.8); 65 80 } 66 81 67 . color-swatch:active > span {82 .inline-swatch:active > span { 68 83 border-color: hsl(0, 0%, 25%); 69 84 } 70 85 86 .inline-swatch.bezier > span { 87 display: none; 88 } 89 -
trunk/Source/WebInspectorUI/UserInterface/Views/InlineSwatch.js
r194976 r194977 25 25 */ 26 26 27 WebInspector. ColorSwatch = class ColorSwatch extends WebInspector.Object27 WebInspector.InlineSwatch = class InlineSwatch extends WebInspector.Object 28 28 { 29 constructor( color, readOnly)29 constructor(type, value, readOnly) 30 30 { 31 31 super(); 32 32 33 this._type = type; 34 33 35 this._swatchElement = document.createElement("span"); 34 this._swatchElement.classList.add("color-swatch"); 35 this._swatchElement.title = WebInspector.UIString("Click to select a color. Shift-click to switch color formats."); 36 this._swatchElement.classList.add("inline-swatch", this._type.split("-").lastValue); 37 38 switch (this._type) { 39 case WebInspector.InlineSwatch.Type.Bezier: 40 this._swatchElement.title = WebInspector.UIString("Click to open a cubic-bezier editor."); 41 break; 42 case WebInspector.InlineSwatch.Type.Gradient: 43 this._swatchElement.title = WebInspector.UIString("Click to select a gradient."); 44 break; 45 default: 46 console.assert(this._type === WebInspector.InlineSwatch.Type.Color); 47 this._swatchElement.title = WebInspector.UIString("Click to select a color. Shift-click to switch color formats."); 48 break; 49 } 50 36 51 if (!readOnly) { 37 this._swatchElement.addEventListener("click", this._ colorSwatchClicked.bind(this));38 this._swatchElement.addEventListener("contextmenu", this._handleContextMenuEvent.bind(this));39 }40 41 this._swatchInnerElement = document.createElement("span"); 42 this._swatch Element.appendChild(this._swatchInnerElement);43 44 this._ color = color || WebInspector.Color.fromString("transparent");52 this._swatchElement.addEventListener("click", this._swatchElementClicked.bind(this)); 53 if (this._type === WebInspector.InlineSwatch.Type.Color) 54 this._swatchElement.addEventListener("contextmenu", this._handleContextMenuEvent.bind(this)); 55 } 56 57 this._swatchInnerElement = this._swatchElement.createChild("span"); 58 59 this._value = value || this._fallbackValue(); 45 60 46 61 this._updateSwatch(); … … 54 69 } 55 70 56 set color(color) 57 { 58 this._color = color || WebInspector.Color.fromString("transparent"); 71 get value() 72 { 73 return this._value; 74 } 75 76 set value(value) 77 { 78 this._value = value; 59 79 this._updateSwatch(true); 60 80 } 61 81 62 get color()63 {64 return this._color;65 }66 67 82 // Private 68 83 69 _colorSwatchClicked(event) 70 { 71 if (event.shiftKey) { 72 let nextFormat = this._color.nextFormat(); 84 _fallbackValue() 85 { 86 switch (this._type) { 87 case WebInspector.InlineSwatch.Type.Bezier: 88 return WebInspector.CubicBezier.fromString("linear"); 89 case WebInspector.InlineSwatch.Type.Gradient: 90 return WebInspector.Gradient.fromString("linear-gradient(transparent, transparent)"); 91 case WebInspector.InlineSwatch.Type.Color: 92 return WebInspector.Color.fromString("transparent"); 93 default: 94 return null; 95 } 96 } 97 98 _updateSwatch(dontFireEvents) 99 { 100 if (this._type === WebInspector.InlineSwatch.Type.Color || this._type === WebInspector.InlineSwatch.Type.Gradient) 101 this._swatchInnerElement.style.background = this._value ? this._value.toString() : null; 102 103 if (!dontFireEvents) 104 this.dispatchEventToListeners(WebInspector.InlineSwatch.Event.ValueChanged, {value: this._value}); 105 } 106 107 _swatchElementClicked(event) 108 { 109 if (this._type === WebInspector.InlineSwatch.Type.Color && event.shiftKey && this._value) { 110 let nextFormat = this._value.nextFormat(); 73 111 console.assert(nextFormat); 74 112 if (!nextFormat) 75 113 return; 76 114 77 this._ color.format = nextFormat;115 this._value.format = nextFormat; 78 116 this._updateSwatch(); 79 117 return; … … 81 119 82 120 let bounds = WebInspector.Rect.rectFromClientRect(this._swatchElement.getBoundingClientRect()); 83 84 let colorPicker = new WebInspector.ColorPicker;85 colorPicker.addEventListener(WebInspector.ColorPicker.Event.ColorChanged, this._colorPickerColorDidChange, this);86 87 121 let popover = new WebInspector.Popover(this); 88 popover.content = colorPicker.element; 122 123 let valueEditor = null; 124 if (this._type === WebInspector.InlineSwatch.Type.Bezier) { 125 valueEditor = new WebInspector.BezierEditor; 126 valueEditor.addEventListener(WebInspector.BezierEditor.Event.BezierChanged, this._valueEditorValueDidChange, this); 127 } else if (this._type === WebInspector.InlineSwatch.Type.Gradient) { 128 valueEditor = new WebInspector.GradientEditor; 129 valueEditor.addEventListener(WebInspector.GradientEditor.Event.GradientChanged, this._valueEditorValueDidChange, this); 130 valueEditor.addEventListener(WebInspector.GradientEditor.Event.ColorPickerToggled, (event) => popover.update()); 131 } else { 132 valueEditor = new WebInspector.ColorPicker; 133 valueEditor.addEventListener(WebInspector.ColorPicker.Event.ColorChanged, this._valueEditorValueDidChange, this); 134 } 135 136 popover.content = valueEditor.element; 89 137 popover.present(bounds.pad(2), [WebInspector.RectEdge.MIN_X]); 90 138 91 colorPicker.color = this._color; 92 } 93 94 _colorPickerColorDidChange(event) 95 { 96 this._color = event.data.color; 139 let value = this._value || this._fallbackValue(); 140 if (this._type === WebInspector.InlineSwatch.Type.Bezier) 141 valueEditor.bezier = value; 142 else if (this._type === WebInspector.InlineSwatch.Type.Gradient) 143 valueEditor.gradient = value; 144 else 145 valueEditor.color = value; 146 } 147 148 _valueEditorValueDidChange(event) 149 { 150 if (this._type === WebInspector.InlineSwatch.Type.Bezier) 151 this._value = event.data.bezier; 152 else if (this._type === WebInspector.InlineSwatch.Type.Gradient) 153 this._value = event.data.gradient; 154 else 155 this._value = event.data.color; 156 97 157 this._updateSwatch(); 98 158 } … … 102 162 let contextMenu = WebInspector.ContextMenu.createFromEvent(event); 103 163 104 if (this._ color.isKeyword() && this._color.format !== WebInspector.Color.Format.Keyword) {164 if (this._value.isKeyword() && this._value.format !== WebInspector.Color.Format.Keyword) { 105 165 contextMenu.appendItem(WebInspector.UIString("Format: Keyword"), () => { 106 this._ color.format = WebInspector.Color.Format.Keyword;166 this._value.format = WebInspector.Color.Format.Keyword; 107 167 this._updateSwatch(); 108 168 }); … … 112 172 if (hexInfo) { 113 173 contextMenu.appendItem(hexInfo.title, () => { 114 this._ color.format = hexInfo.format;115 this._updateSwatch(); 116 }); 117 } 118 119 if (this._ color.simple && this._color.format !== WebInspector.Color.Format.HSL) {174 this._value.format = hexInfo.format; 175 this._updateSwatch(); 176 }); 177 } 178 179 if (this._value.simple && this._value.format !== WebInspector.Color.Format.HSL) { 120 180 contextMenu.appendItem(WebInspector.UIString("Format: HSL"), () => { 121 this._ color.format = WebInspector.Color.Format.HSL;122 this._updateSwatch(); 123 }); 124 } else if (this._ color.format !== WebInspector.Color.Format.HSLA) {181 this._value.format = WebInspector.Color.Format.HSL; 182 this._updateSwatch(); 183 }); 184 } else if (this._value.format !== WebInspector.Color.Format.HSLA) { 125 185 contextMenu.appendItem(WebInspector.UIString("Format: HSLA"), () => { 126 this._ color.format = WebInspector.Color.Format.HSLA;127 this._updateSwatch(); 128 }); 129 } 130 131 if (this._ color.simple && this._color.format !== WebInspector.Color.Format.RGB) {186 this._value.format = WebInspector.Color.Format.HSLA; 187 this._updateSwatch(); 188 }); 189 } 190 191 if (this._value.simple && this._value.format !== WebInspector.Color.Format.RGB) { 132 192 contextMenu.appendItem(WebInspector.UIString("Format: RGB"), () => { 133 this._ color.format = WebInspector.Color.Format.RGB;134 this._updateSwatch(); 135 }); 136 } else if (this._ color.format !== WebInspector.Color.Format.RGBA) {193 this._value.format = WebInspector.Color.Format.RGB; 194 this._updateSwatch(); 195 }); 196 } else if (this._value.format !== WebInspector.Color.Format.RGBA) { 137 197 contextMenu.appendItem(WebInspector.UIString("Format: RGBA"), () => { 138 this._ color.format = WebInspector.Color.Format.RGBA;198 this._value.format = WebInspector.Color.Format.RGBA; 139 199 this._updateSwatch(); 140 200 }); … … 144 204 _getNextValidHEXFormat() 145 205 { 206 if (this._type !== WebInspector.InlineSwatch.Type.Color) 207 return false; 208 146 209 function hexMatchesCurrentColor(hexInfo) { 147 210 let nextIsSimple = hexInfo.format === WebInspector.Color.Format.ShortHEX || hexInfo.format === WebInspector.Color.Format.HEX; 148 if (nextIsSimple && !this._ color.simple)211 if (nextIsSimple && !this._value.simple) 149 212 return false; 150 213 151 214 let nextIsShort = hexInfo.format === WebInspector.Color.Format.ShortHEX || hexInfo.format === WebInspector.Color.Format.ShortHEXAlpha; 152 if (nextIsShort && !this._ color.canBeSerializedAsShortHEX())215 if (nextIsShort && !this._value.canBeSerializedAsShortHEX()) 153 216 return false; 154 217 … … 177 240 // FIXME: <https://webkit.org/b/152497> Arrow functions: "this" isn't lexically bound 178 241 let currentColorIsHEX = hexFormats.some(function(info) { 179 return info.format === this._ color.format;242 return info.format === this._value.format; 180 243 }.bind(this)); 181 244 182 245 for (let i = 0; i < hexFormats.length; ++i) { 183 if (currentColorIsHEX && this._ color.format !== hexFormats[i].format)246 if (currentColorIsHEX && this._value.format !== hexFormats[i].format) 184 247 continue; 185 248 … … 193 256 return hexFormats[0]; 194 257 } 195 196 _updateSwatch(dontFireEvents)197 {198 this._swatchInnerElement.style.backgroundColor = this._color.toString() || null;199 if (!dontFireEvents)200 this.dispatchEventToListeners(WebInspector.ColorSwatch.Event.ColorChanged, {color: this._color});201 }202 258 }; 203 259 204 WebInspector.ColorSwatch.Event = { 205 ColorChanged: "color-swatch-color-changed" 260 WebInspector.InlineSwatch.Type = { 261 Color: "inline-swatch-type-color", 262 Gradient: "inline-swatch-type-gradient", 263 Bezier: "inline-swatch-type-bezier" 206 264 }; 265 266 WebInspector.InlineSwatch.Event = { 267 ValueChanged: "inline-swatch-value-changed" 268 }; -
trunk/Source/WebInspectorUI/UserInterface/Views/VisualStyleBackgroundPicker.css
r192705 r194977 28 28 } 29 29 30 .visual-style-property-container.background-picker > .visual-style-property-value-container > .color-gradient-swatch { 31 display: none; 32 position: relative; 30 .visual-style-property-container.background-picker > .visual-style-property-value-container > .inline-swatch.gradient { 33 31 width: 38px; 34 32 height: 18px; 35 margin-top: 1px; 36 /* Make a checkered background for transparent colors to show against. */ 37 background-image: linear-gradient(to bottom, hsl(0, 0%, 80%), hsl(0, 0%, 80%)), 38 linear-gradient(to bottom, hsl(0, 0%, 80%), hsl(0, 0%, 80%)); 39 background-color: white; 40 background-size: 50%; 41 background-position: top left, bottom right; 42 background-repeat: no-repeat; 33 margin: 1px 0 0; 43 34 border: 1px solid hsla(0, 0%, 25%, 0.4); 44 35 border-radius: 4px; 45 overflow: hidden;46 cursor: default;47 36 } 48 37 49 .visual-style-property-container.background-picker > .visual-style-property-value-container > .color-gradient-swatch:hover { 38 .visual-style-property-container.background-picker > .visual-style-property-value-container:not(.gradient-value) > .inline-swatch.gradient { 39 display: none; 40 } 41 42 .visual-style-property-container.background-picker > .visual-style-property-value-container > .inline-swatch.gradient:hover { 50 43 border-color: hsla(0, 0%, 25%, 0.8); 51 44 } 52 45 53 .visual-style-property-container.background-picker > .visual-style-property-value-container > . color-gradient-swatch:active {46 .visual-style-property-container.background-picker > .visual-style-property-value-container > .inline-swatch.gradient:active { 54 47 border-color: hsl(0, 0%, 25%); 55 48 } 56 49 57 .visual-style-property-container.background-picker > .visual-style-property-value-container > .color-gradient-swatch > span { 58 position: absolute; 59 top: 0; 60 right: 0; 61 bottom: 0; 62 left: 0; 50 .visual-style-property-container.background-picker > .visual-style-property-value-container > .inline-swatch.gradient > span { 51 border: none; 63 52 } 64 53 65 .visual-style-property-container.background-picker > .visual-style-property-value-container.gradient-value > .color-gradient-swatch { 66 display: block; 67 } 68 69 .visual-style-property-container.background-picker > .visual-style-property-value-container.gradient-value > .color-gradient-swatch + .value-input { 54 .visual-style-property-container.background-picker > .visual-style-property-value-container.gradient-value > .inline-swatch.gradient + .value-input { 70 55 margin-left: -3px; 71 56 padding-left: 5px; -
trunk/Source/WebInspectorUI/UserInterface/Views/VisualStyleBackgroundPicker.js
r194901 r194977 30 30 super(propertyNames, text, possibleValues, null, "background-picker", layoutReversed); 31 31 32 this._gradientSwatchElement = document.createElement("span"); 33 this._gradientSwatchElement.classList.add("color-gradient-swatch"); 34 this._gradientSwatchElement.title = WebInspector.UIString("Click to select a gradient"); 35 this._gradientSwatchElement.addEventListener("click", this._gradientSwatchClicked.bind(this)); 36 37 let gradientSwatchInnerElement = document.createElement("span"); 38 this._gradientSwatchElement.appendChild(gradientSwatchInnerElement); 39 40 this.contentElement.appendChild(this._gradientSwatchElement); 32 this._gradientSwatch = new WebInspector.InlineSwatch(WebInspector.InlineSwatch.Type.Gradient); 33 this._gradientSwatch.addEventListener(WebInspector.InlineSwatch.Event.ValueChanged, this._gradientSwatchColorChanged, this); 34 this.contentElement.appendChild(this._gradientSwatch.element); 41 35 42 36 this._valueInputElement = document.createElement("input"); … … 87 81 88 82 this._currentType = "url"; 89 this._gradient = null;90 91 this._updateGradientSwatch();92 83 } 93 84 … … 115 106 return; 116 107 117 this._gradient = WebInspector.Gradient.fromString(value); 118 if (!this._gradient) 119 return; 120 121 this._updateGradientSwatch(); 108 this._updateGradient(); 122 109 } 123 110 … … 160 147 } 161 148 162 _updateGradientSwatch() 163 { 164 this._gradientSwatchElement.firstChild.style.background = ""; 149 _updateGradient() 150 { 165 151 const value = this.synthesizedValue; 166 152 if (!value || value === this._currentType) 167 153 return; 168 154 169 this._gradient = WebInspector.Gradient.fromString(value); 170 this._gradientSwatchElement.firstChild.style.background = this._gradient ? value : null; 171 } 172 173 _gradientSwatchClicked(event) 174 { 175 let bounds = WebInspector.Rect.rectFromClientRect(this._gradientSwatchElement.getBoundingClientRect()); 176 let popover = new WebInspector.Popover(this); 177 178 function handleColorPickerToggled(event) 179 { 180 popover.update(); 181 } 182 183 let gradientEditor = new WebInspector.GradientEditor; 184 gradientEditor.addEventListener(WebInspector.GradientEditor.Event.GradientChanged, this._gradientEditorGradientChanged, this); 185 gradientEditor.addEventListener(WebInspector.GradientEditor.Event.ColorPickerToggled, handleColorPickerToggled, this); 186 187 popover.content = gradientEditor.element; 188 popover.present(bounds.pad(2), [WebInspector.RectEdge.MIN_X]); 189 190 if (!this._gradient) 191 this._gradient = WebInspector.Gradient.fromString(`${this._currentType}(transparent, transparent)`); 192 193 gradientEditor.gradient = this._gradient; 194 } 195 196 _gradientEditorGradientChanged(event) 197 { 198 this.value = event.data.gradient.toString(); 155 this._gradientSwatch.value = WebInspector.Gradient.fromString(value); 156 } 157 158 _gradientSwatchColorChanged(event) 159 { 160 this.value = event.data.value.toString(); 199 161 this._valueDidChange(); 200 162 } … … 202 164 _valueInputValueChanged(event) 203 165 { 204 this._updateGradient Swatch();166 this._updateGradient(); 205 167 this._valueDidChange(); 206 168 } … … 218 180 this._currentType = this._valueTypePickerElement.value; 219 181 this._updateValueInput(); 220 this._updateGradient Swatch();182 this._updateGradient(); 221 183 this._valueDidChange(); 222 184 } -
trunk/Source/WebInspectorUI/UserInterface/Views/VisualStyleColorPicker.css
r194568 r194977 32 32 } 33 33 34 .visual-style-property-container.input-color-picker > .visual-style-property-value-container > . color-swatch{34 .visual-style-property-container.input-color-picker > .visual-style-property-value-container > .inline-swatch.color { 35 35 width: 22px; 36 36 height: 18px; … … 41 41 } 42 42 43 .visual-style-property-container.input-color-picker > .visual-style-property-value-container > . color-swatch:hover {43 .visual-style-property-container.input-color-picker > .visual-style-property-value-container > .inline-swatch.color:hover { 44 44 border-color: hsla(0, 0%, 25%, 0.8); 45 45 } 46 46 47 .visual-style-property-container.input-color-picker > .visual-style-property-value-container > . color-swatch:active {47 .visual-style-property-container.input-color-picker > .visual-style-property-value-container > .inline-swatch.color:active { 48 48 border-color: hsl(0, 0%, 25%); 49 49 } 50 50 51 .visual-style-property-container.input-color-picker > .visual-style-property-value-container > . color-swatch> span {51 .visual-style-property-container.input-color-picker > .visual-style-property-value-container > .inline-swatch.color > span { 52 52 border: none; 53 53 } -
trunk/Source/WebInspectorUI/UserInterface/Views/VisualStyleColorPicker.js
r194568 r194977 30 30 super(propertyNames, text, null, null, "input-color-picker", layoutReversed); 31 31 32 this._colorSwatch = new WebInspector. ColorSwatch;33 this._colorSwatch.addEventListener(WebInspector. ColorSwatch.Event.ColorChanged, this._colorSwatchColorChanged, this);32 this._colorSwatch = new WebInspector.InlineSwatch(WebInspector.InlineSwatch.Type.Color); 33 this._colorSwatch.addEventListener(WebInspector.InlineSwatch.Event.ValueChanged, this._colorSwatchColorChanged, this); 34 34 this.contentElement.appendChild(this._colorSwatch.element); 35 35 … … 100 100 _colorSwatchColorChanged(event) 101 101 { 102 let colorString = event && event.data && event.data. color && event.data.color.toString();102 let colorString = event && event.data && event.data.value && event.data.value.toString(); 103 103 if (!colorString) 104 104 return; … … 111 111 { 112 112 let value = this._textInputElement.value; 113 this._colorSwatch. color = WebInspector.Color.fromString(value || "transparent");113 this._colorSwatch.value = WebInspector.Color.fromString(value); 114 114 } 115 115 -
trunk/Source/WebInspectorUI/UserInterface/Views/VisualStyleTimingEditor.css
r188629 r194977 32 32 } 33 33 34 .visual-style-property-container.timing-editor > .visual-style-property-value-container > . bezier-editor {34 .visual-style-property-container.timing-editor > .visual-style-property-value-container > .inline-swatch.bezier { 35 35 width: 23px; 36 36 height: 20px; 37 margin-right: 2px; 38 content: url(../Images/CubicBezier.svg); 39 cursor: default; 37 } 38 39 .visual-style-property-container.timing-editor > .visual-style-property-value-container:not(.bezier-value) > .inline-swatch.bezier { 40 display: none; 40 41 } 41 42 42 43 @media (-webkit-min-device-pixel-ratio: 2) { 43 .visual-style-property-container.timing-editor > .visual-style-property-value-container > . bezier-editor {44 .visual-style-property-container.timing-editor > .visual-style-property-value-container > .inline-swatch.bezier { 44 45 margin-left: 0.5px; 45 46 } 46 47 } 47 48 .visual-style-property-container.timing-editor > .visual-style-property-value-container > .bezier-editor:hover {49 filter: brightness(0.9);50 }51 52 .visual-style-property-container.timing-editor > .visual-style-property-value-container > .bezier-editor:active {53 filter: brightness(0.8);54 } -
trunk/Source/WebInspectorUI/UserInterface/Views/VisualStyleTimingEditor.js
r188479 r194977 37 37 this._keywordSelectElement.appendChild(this._customValueOptionElement); 38 38 39 this._bezierMarkerElement = document.createElement("span"); 40 this._bezierMarkerElement.title = WebInspector.UIString("Click to open a cubic-bezier editor"); 41 this._bezierMarkerElement.classList.add("bezier-editor"); 42 this._bezierMarkerElement.hidden = true; 43 this._bezierMarkerElement.addEventListener("click", this._bezierMarkerClicked.bind(this)); 44 this.contentElement.appendChild(this._bezierMarkerElement); 45 46 this._bezierEditor = new WebInspector.BezierEditor; 47 this._bezierEditor.addEventListener(WebInspector.BezierEditor.Event.BezierChanged, this._valueDidChange.bind(this)); 48 this._bezierEditor.bezier = WebInspector.CubicBezier.fromString("linear"); 39 this._bezierSwatch = new WebInspector.InlineSwatch(WebInspector.InlineSwatch.Type.Bezier); 40 this._bezierSwatch.addEventListener(WebInspector.InlineSwatch.Event.ValueChanged, this._bezierSwatchValueChanged, this); 41 this.contentElement.appendChild(this._bezierSwatch.element); 49 42 } 50 43 … … 58 51 get bezierValue() 59 52 { 60 let bezier = this._bezier Editor.bezier;53 let bezier = this._bezierSwatch.value; 61 54 if (!bezier) 62 55 return null; … … 68 61 { 69 62 let bezier = WebInspector.CubicBezier.fromString(text); 70 this._bezier Editor.bezier= bezier;63 this._bezierSwatch.value = bezier; 71 64 } 72 65 … … 83 76 if (this.valueIsSupportedKeyword(value)) { 84 77 super._setValue(value); 85 this. _bezierMarkerElement.hidden = true;78 this.contentElement.classList.remove("bezier-value"); 86 79 return; 87 80 } … … 89 82 let bezier = this.bezierValue; 90 83 this._customValueOptionElement.selected = !!bezier; 91 this. _bezierMarkerElement.hidden = !bezier;84 this.contentElement.classList.toggle("bezier-value", !!bezier); 92 85 this.specialPropertyPlaceholderElement.hidden = !!bezier; 93 86 if (!bezier) … … 100 93 } 101 94 102 _bezierMarkerClicked()103 {104 let bounds = WebInspector.Rect.rectFromClientRect(this._bezierMarkerElement.getBoundingClientRect());105 this._cubicBezierEditorPopover = new WebInspector.Popover(this);106 this._cubicBezierEditorPopover.content = this._bezierEditor.element;107 this._cubicBezierEditorPopover.present(bounds.pad(2), [WebInspector.RectEdge.MIN_X]);108 }109 110 95 _handleKeywordChanged() 111 96 { 112 97 super._handleKeywordChanged(); 113 98 let customOptionSelected = this._customValueOptionElement.selected; 114 this. _bezierMarkerElement.hidden = !customOptionSelected;99 this.contentElement.classList.toggle("bezier-value", !!customOptionSelected); 115 100 this.specialPropertyPlaceholderElement.hidden = !!customOptionSelected; 116 101 if (customOptionSelected) 117 102 this.bezierValue = "linear"; 118 103 } 104 105 _bezierSwatchValueChanged(event) 106 { 107 this._valueDidChange(); 108 } 119 109 };
Note: See TracChangeset
for help on using the changeset viewer.