Changeset 273912 in webkit
- Timestamp:
- Mar 4, 2021 12:12:09 PM (17 months ago)
- Location:
- trunk/Source/WebInspectorUI
- Files:
-
- 3 edited
-
ChangeLog (modified) (1 diff)
-
UserInterface/Controllers/OverlayManager.js (modified) (6 diffs)
-
UserInterface/Views/CSSGridSection.js (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebInspectorUI/ChangeLog
r273900 r273912 1 2021-03-04 Razvan Caliman <rcaliman@apple.com> 2 3 Web Inspector: Persist CSS Grid overlay colors 4 https://bugs.webkit.org/show_bug.cgi?id=222319 5 <rdar://problem/74647242> 6 7 Reviewed by Devin Rousso. 8 9 Save and restore CSS Grid overlay colors edited by a user. 10 11 * UserInterface/Controllers/OverlayManager.js: 12 (WI.OverlayManager): 13 (WI.OverlayManager.prototype.showGridOverlay): 14 (WI.OverlayManager.prototype.getGridColorForNode): 15 (WI.OverlayManager.prototype.setGridColorForNode): 16 (WI.OverlayManager.prototype._handleMainResourceDidChange): 17 * UserInterface/Views/CSSGridSection.js: 18 (WI.CSSGridSection.prototype.layout): 19 1 20 2021-03-04 Razvan Caliman <rcaliman@apple.com> 2 21 -
trunk/Source/WebInspectorUI/UserInterface/Controllers/OverlayManager.js
r273164 r273912 31 31 32 32 this._gridOverlayForNodeMap = new Map; 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; 33 this._nextDefaultGridColorIndex = 0; 34 this._gridColorForNodeMap = new WeakMap; 35 this._gridColorSettingForNodeMap = new WeakMap; 37 36 38 37 WI.settings.gridOverlayShowExtendedGridLines.addEventListener(WI.Setting.Event.Changed, this._handleGridSettingChanged, this); … … 61 60 console.assert(domNode.layoutContextType === WI.DOMNode.LayoutContextType.Grid, domNode.layoutContextType); 62 61 63 color ||= this. colorForNode(domNode);62 color ||= this.getGridColorForNode(domNode); 64 63 let target = WI.assumingMainTarget(); 65 64 let commandArguments = { … … 75 74 76 75 let overlay = {domNode, ...commandArguments}; 76 77 // The method to show the overlay will be called repeatedly while updating the grid overlay color. Avoid adding duplicate event listeners 78 if (!this._gridOverlayForNodeMap.has(domNode)) 79 domNode.addEventListener(WI.DOMNode.Event.LayoutContextTypeChanged, this._handleLayoutContextTypeChanged, this); 80 77 81 this._gridOverlayForNodeMap.set(domNode, overlay); 78 this._colorForNodeMap.set(domNode, color); 79 80 domNode.addEventListener(WI.DOMNode.Event.LayoutContextTypeChanged, this._handleLayoutContextTypeChanged, this); 82 81 83 this.dispatchEventToListeners(WI.OverlayManager.Event.GridOverlayShown, overlay); 82 84 } … … 114 116 } 115 117 116 colorForNode(domNode)117 { 118 let color = this._ colorForNodeMap.get(domNode);118 getGridColorForNode(domNode) 119 { 120 let color = this._gridColorForNodeMap.get(domNode); 119 121 if (color) 120 122 return color; 121 123 122 const hslColors = [124 const defaultGridHSLColors = [ 123 125 [329, 91, 70], 124 126 [207, 96, 69], … … 128 130 ]; 129 131 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; 132 let colorSetting = this._gridColorSettingForNodeMap.get(domNode); 133 if (!colorSetting) { 134 let defaultColor = defaultGridHSLColors[this._nextDefaultGridColorIndex]; 135 this._nextDefaultGridColorIndex = (this._nextDefaultGridColorIndex + 1) % defaultGridHSLColors.length; 136 137 let url = domNode.ownerDocument.documentURL || WI.networkManager.mainFrame.url; 138 colorSetting = new WI.Setting(`grid-overlay-color-${url.hash}-${domNode.path().hash}`, defaultColor); 139 this._gridColorSettingForNodeMap.set(domNode, colorSetting); 140 } 141 142 color = new WI.Color(WI.Color.Format.HSL, colorSetting.value); 143 this._gridColorForNodeMap.set(domNode, color); 133 144 134 145 return color; 146 } 147 148 setGridColorForNode(domNode, color) 149 { 150 console.assert(domNode instanceof WI.DOMNode, domNode); 151 console.assert(color instanceof WI.Color, color); 152 153 let colorSetting = this._gridColorSettingForNodeMap.get(domNode); 154 console.assert(colorSetting, "There should already be a setting created form a previous call to getGridColorForNode()"); 155 colorSetting.value = color.hsl; 156 157 this._gridColorForNodeMap.set(domNode, color); 135 158 } 136 159 … … 164 187 // 3. Click on the badge of the same element. 165 188 // 166 // We should see the same 1st default overlay color. If we don't reset _nextD OMNodeColorIndex,189 // We should see the same 1st default overlay color. If we don't reset _nextDefaultGridColorIndex, 167 190 // the 2nd default color would be used instead. 168 191 // 169 192 // `domNode.id` is different for the same DOM element after page reload. 170 this._nextD OMNodeColorIndex = 0;193 this._nextDefaultGridColorIndex = 0; 171 194 } 172 195 }; -
trunk/Source/WebInspectorUI/UserInterface/Views/CSSGridSection.js
r273847 r273912 113 113 }); 114 114 115 let gridColor = WI.overlayManager. colorForNode(domNode);115 let gridColor = WI.overlayManager.getGridColorForNode(domNode); 116 116 let swatch = new WI.InlineSwatch(WI.InlineSwatch.Type.Color, gridColor); 117 117 itemContainerElement.append(swatch.element); … … 120 120 if (checkboxElement.checked) 121 121 WI.overlayManager.showGridOverlay(domNode, {color: event.data.value}); 122 }, swatch); 123 124 swatch.addEventListener(WI.InlineSwatch.Event.Deactivated, (event) => { 125 if (event.target.value === gridColor) 126 return; 127 128 gridColor = event.target.value; 129 WI.overlayManager.setGridColorForNode(domNode, gridColor); 122 130 }, swatch); 123 131 }
Note: See TracChangeset
for help on using the changeset viewer.