Changeset 273164 in webkit
- Timestamp:
- Feb 19, 2021 1:35:05 PM (3 years ago)
- Location:
- trunk/Source/WebInspectorUI
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebInspectorUI/ChangeLog
r273148 r273164 1 2021-02-19 Nikita Vasilyev <nvasilyev@apple.com> 2 3 Web Inspector: CSS Grid Inspector: use a color palette for default grid overlay colors 4 https://bugs.webkit.org/show_bug.cgi?id=222161 5 6 Reviewed by Devin Rousso. 7 8 Define a 5-color palette. 9 10 * UserInterface/Controllers/OverlayManager.js: 11 (WI.OverlayManager): 12 (WI.OverlayManager.prototype.showGridOverlay): 13 (WI.OverlayManager.prototype.colorForNode): 14 (WI.OverlayManager.prototype._handleMainResourceDidChange): 15 * UserInterface/Views/CSSGridSection.js: 16 (WI.CSSGridSection.prototype.layout): 17 1 18 2021-02-19 Razvan Caliman <rcaliman@apple.com> 2 19 -
trunk/Source/WebInspectorUI/UserInterface/Controllers/OverlayManager.js
r273097 r273164 32 32 this._gridOverlayForNodeMap = new Map; 33 33 34 // Can't reuse `this._gridOverlayForNodeMap` because nodes are removed from it when overlay isn't visible. 35 this._colorForNodeMap = new WeakMap; 36 this._nextDOMNodeColorIndex = 0; 37 34 38 WI.settings.gridOverlayShowExtendedGridLines.addEventListener(WI.Setting.Event.Changed, this._handleGridSettingChanged, this); 35 39 WI.settings.gridOverlayShowLineNames.addEventListener(WI.Setting.Event.Changed, this._handleGridSettingChanged, this); … … 37 41 WI.settings.gridOverlayShowTrackSizes.addEventListener(WI.Setting.Event.Changed, this._handleGridSettingChanged, this); 38 42 WI.settings.gridOverlayShowAreaNames.addEventListener(WI.Setting.Event.Changed, this._handleGridSettingChanged, this); 43 WI.Frame.addEventListener(WI.Frame.Event.MainResourceDidChange, this._handleMainResourceDidChange, this); 39 44 } 40 45 … … 56 61 console.assert(domNode.layoutContextType === WI.DOMNode.LayoutContextType.Grid, domNode.layoutContextType); 57 62 58 color ||= WI.Color.fromString("magenta"); // fallback color 59 63 color ||= this.colorForNode(domNode); 60 64 let target = WI.assumingMainTarget(); 61 65 let commandArguments = { … … 72 76 let overlay = {domNode, ...commandArguments}; 73 77 this._gridOverlayForNodeMap.set(domNode, overlay); 78 this._colorForNodeMap.set(domNode, color); 74 79 75 80 domNode.addEventListener(WI.DOMNode.Event.LayoutContextTypeChanged, this._handleLayoutContextTypeChanged, this); … … 109 114 } 110 115 116 colorForNode(domNode) 117 { 118 let color = this._colorForNodeMap.get(domNode); 119 if (color) 120 return color; 121 122 const hslColors = [ 123 [329, 91, 70], 124 [207, 96, 69], 125 [92, 90, 64], 126 [291, 73, 68], 127 [40, 97, 57], 128 ]; 129 130 color = new WI.Color(WI.Color.Format.HSL, hslColors[this._nextDOMNodeColorIndex]); 131 this._colorForNodeMap.set(domNode, color); 132 this._nextDOMNodeColorIndex = (this._nextDOMNodeColorIndex + 1) % hslColors.length; 133 134 return color; 135 } 136 111 137 // Private 112 138 … … 130 156 } 131 157 } 158 159 _handleMainResourceDidChange(event) 160 { 161 // Consider the following scenario: 162 // 1. Click on the badge of an element with `display: grid`. The 1st overlay color is used. 163 // 2. Reload the webpage. 164 // 3. Click on the badge of the same element. 165 // 166 // We should see the same 1st default overlay color. If we don't reset _nextDOMNodeColorIndex, 167 // the 2nd default color would be used instead. 168 // 169 // `domNode.id` is different for the same DOM element after page reload. 170 this._nextDOMNodeColorIndex = 0; 171 } 132 172 }; 133 173 -
trunk/Source/WebInspectorUI/UserInterface/Views/CSSGridSection.js
r273148 r273164 113 113 }); 114 114 115 let swatch = new WI.InlineSwatch(WI.InlineSwatch.Type.Color, WI.Color.fromString("magenta")); 115 let gridColor = WI.overlayManager.colorForNode(domNode); 116 let swatch = new WI.InlineSwatch(WI.InlineSwatch.Type.Color, gridColor); 116 117 itemContainerElement.append(swatch.element); 117 118
Note: See TracChangeset
for help on using the changeset viewer.