Changeset 289610 in webkit
- Timestamp:
- Feb 11, 2022 12:44:23 AM (5 months ago)
- Location:
- trunk/Source/WebInspectorUI
- Files:
-
- 7 edited
-
ChangeLog (modified) (1 diff)
-
UserInterface/Controllers/GridOverlayConfigurationDiagnosticEventRecorder.js (modified) (3 diffs)
-
UserInterface/Controllers/GridOverlayDiagnosticEventRecorder.js (modified) (2 diffs)
-
UserInterface/Controllers/OverlayManager.js (modified) (5 diffs)
-
UserInterface/Views/CSSGridSection.js (modified) (8 diffs)
-
UserInterface/Views/DOMTreeElement.css (modified) (3 diffs)
-
UserInterface/Views/DOMTreeElement.js (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebInspectorUI/ChangeLog
r289064 r289610 1 2022-02-11 Nikita Vasilyev <nvasilyev@apple.com> 2 3 Web Inspector: [Flexbox] Show flex badge next to flex containers in DOM Tree 4 https://bugs.webkit.org/show_bug.cgi?id=235924 5 6 Reviewed by Patrick Angle. 7 8 Elements with `display: flex` and `display: inline-flex` should include a "flex" badge. 9 Clicking the badge should toggle the overlay for the corresponding element. 10 11 * UserInterface/Controllers/GridOverlayConfigurationDiagnosticEventRecorder.js: 12 (WI.GridOverlayConfigurationDiagnosticEventRecorder.prototype.setup): 13 (WI.GridOverlayConfigurationDiagnosticEventRecorder.prototype.teardown): 14 (WI.GridOverlayConfigurationDiagnosticEventRecorder.prototype._handleGridOverlayShown): 15 * UserInterface/Controllers/GridOverlayDiagnosticEventRecorder.js: 16 (WI.GridOverlayDiagnosticEventRecorder.prototype.setup): 17 (WI.GridOverlayDiagnosticEventRecorder.prototype.teardown): 18 (WI.GridOverlayDiagnosticEventRecorder.prototype._handleGridOverlayShown): 19 (WI.GridOverlayDiagnosticEventRecorder): 20 * UserInterface/Controllers/OverlayManager.js: 21 (WI.OverlayManager): 22 (WI.OverlayManager.prototype.showOverlay): 23 (WI.OverlayManager.prototype.hideOverlay): 24 (WI.OverlayManager.prototype.hasVisibleGridOverlays): 25 (WI.OverlayManager.prototype.hasVisibleOverlay): 26 (WI.OverlayManager.prototype.toggleOverlay): 27 (WI.OverlayManager.prototype.getColorForNode): 28 (WI.OverlayManager.prototype.setColorForNode): 29 (WI.OverlayManager.prototype._handleLayoutContextTypeChanged): 30 (WI.OverlayManager.prototype._handleGridSettingChanged): 31 (WI.OverlayManager.prototype._handleMainResourceDidChange): 32 (WI.OverlayManager.prototype.showGridOverlay): Deleted. 33 (WI.OverlayManager.prototype.hideGridOverlay): Deleted. 34 (WI.OverlayManager.prototype.isGridOverlayVisible): Deleted. 35 (WI.OverlayManager.prototype.toggleGridOverlay): Deleted. 36 (WI.OverlayManager.prototype.getGridColorForNode): Deleted. 37 (WI.OverlayManager.prototype.setGridColorForNode): Deleted. 38 Remove grid-specific methods (such as showGridOverlay) and introduce methods that work with 39 both Grid and Flexbox (such as showOverlay). 40 41 * UserInterface/Views/CSSGridSection.js: 42 (WI.CSSGridSection.prototype.attached): 43 (WI.CSSGridSection.prototype.detached): 44 (WI.CSSGridSection.prototype._handleToggleAllCheckboxChanged): 45 (WI.CSSGridSection.prototype.layout): 46 (WI.CSSGridSection.prototype._handleGridOverlayStateChanged): 47 (WI.CSSGridSection.prototype._updateToggleAllCheckbox): 48 (WI.CSSGridSection): 49 * UserInterface/Views/DOMTreeElement.css: 50 (.tree-outline.dom .layout-badge): 51 (.tree-outline.dom .layout-badge.activated): 52 (body:not(.window-inactive, .window-docked-inactive) .tree-outline.dom:focus-within li.selected .layout-badge): 53 (@media (prefers-color-scheme: dark) .tree-outline.dom .layout-badge): 54 (.tree-outline.dom .badge-css-grid): Deleted. 55 (.tree-outline.dom .badge-css-grid.activated): Deleted. 56 (body:not(.window-inactive, .window-docked-inactive) .tree-outline.dom:focus-within li.selected .badge-css-grid): Deleted. 57 (@media (prefers-color-scheme: dark) .tree-outline.dom .badge-css-grid): Deleted. 58 59 * UserInterface/Views/DOMTreeElement.js: 60 (WI.DOMTreeElement): 61 (WI.DOMTreeElement.prototype.onattach): 62 (WI.DOMTreeElement.prototype.ondetach): 63 (WI.DOMTreeElement.prototype.updateTitle): 64 (WI.DOMTreeElement.prototype._updateLayoutBadge): 65 (WI.DOMTreeElement.prototype._layoutBadgeClicked): 66 (WI.DOMTreeElement.prototype._updateLayoutBadgeStatus): 67 (WI.DOMTreeElement.prototype._handleLayoutContextTypeChanged): 68 (WI.DOMTreeElement.prototype._updateGridBadge): Deleted. 69 (WI.DOMTreeElement.prototype._gridBadgeClicked): Deleted. 70 (WI.DOMTreeElement.prototype._gridBadgeDoubleClicked): Deleted. 71 (WI.DOMTreeElement.prototype._updateGridBadgeStatus): Deleted. 72 Renamed `_gridBadgeElement` to `_layoutBadgeElement`. We can't have both "flex" and "grid" badge on the same element, 73 so I called it "layoutBadge". I didn't call it simply "badge" because we may have other badges in the future. 74 1 75 2022-02-03 Nikita Vasilyev <nvasilyev@apple.com> 2 76 -
trunk/Source/WebInspectorUI/UserInterface/Controllers/GridOverlayConfigurationDiagnosticEventRecorder.js
r285975 r289610 52 52 window.addEventListener("keydown", this, options); 53 53 window.addEventListener("mousedown", this, options); 54 WI.overlayManager.addEventListener(WI.OverlayManager.Event. GridOverlayShown, this._handleGridOverlayShown, this);55 WI.overlayManager.addEventListener(WI.OverlayManager.Event. GridOverlayHidden, this._handleGridOverlayHidden, this);54 WI.overlayManager.addEventListener(WI.OverlayManager.Event.OverlayShown, this._handleGridOverlayShown, this); 55 WI.overlayManager.addEventListener(WI.OverlayManager.Event.OverlayHidden, this._handleGridOverlayHidden, this); 56 56 } 57 57 … … 65 65 window.removeEventListener("keydown", this, options); 66 66 window.removeEventListener("mousedown", this, options); 67 WI.overlayManager.removeEventListener(WI.OverlayManager.Event. GridOverlayShown, this._handleGridOverlayShown, this);68 WI.overlayManager.removeEventListener(WI.OverlayManager.Event. GridOverlayHidden, this._handleGridOverlayHidden, this);67 WI.overlayManager.removeEventListener(WI.OverlayManager.Event.OverlayShown, this._handleGridOverlayShown, this); 68 WI.overlayManager.removeEventListener(WI.OverlayManager.Event.OverlayHidden, this._handleGridOverlayHidden, this); 69 69 70 70 this._stopEventSamplingTimerIfNeeded(); … … 73 73 _handleGridOverlayShown(event) 74 74 { 75 if (event.data.domNode.layoutContextType !== WI.DOMNode.LayoutContextType.Grid) 76 return; 77 75 78 this._overlayOptions.showTrackSizes = event.data.showTrackSizes; 76 79 this._overlayOptions.showLineNumbers = event.data.showLineNumbers; -
trunk/Source/WebInspectorUI/UserInterface/Controllers/GridOverlayDiagnosticEventRecorder.js
r274592 r289610 37 37 setup() 38 38 { 39 WI.overlayManager.addEventListener(WI.OverlayManager.Event. GridOverlayShown, this._handleGridOverlayShown, this);39 WI.overlayManager.addEventListener(WI.OverlayManager.Event.OverlayShown, this._handleGridOverlayShown, this); 40 40 } 41 41 42 42 teardown() 43 43 { 44 WI.overlayManager.removeEventListener(WI.OverlayManager.Event. GridOverlayShown, this._handleGridOverlayShown, this);44 WI.overlayManager.removeEventListener(WI.OverlayManager.Event.OverlayShown, this._handleGridOverlayShown, this); 45 45 } 46 46 … … 49 49 _handleGridOverlayShown(event) 50 50 { 51 if (event.data.domNode.layoutContextType !== WI.DOMNode.LayoutContextType.Grid) 52 return; 53 51 54 let initiator = event.data.initiator; 52 55 if (!initiator || !this._initiators.includes(initiator)) -
trunk/Source/WebInspectorUI/UserInterface/Controllers/OverlayManager.js
r276714 r289610 30 30 super(); 31 31 32 this._ gridOverlayForNodeMap = new Map;32 this._overlayForNodeMap = new Map; 33 33 this._nextDefaultGridColorIndex = 0; 34 this._gridColorForNodeMap = new WeakMap; 35 this._gridColorSettingForNodeMap = new WeakMap; 34 this._nextDefaultFlexColorIndex = 0; 35 this._colorForNodeMap = new WeakMap; 36 this._colorSettingForNodeMap = new WeakMap; 36 37 37 38 WI.settings.gridOverlayShowExtendedGridLines.addEventListener(WI.Setting.Event.Changed, this._handleGridSettingChanged, this); … … 45 46 // Public 46 47 47 show GridOverlay(domNode, {color, initiator} = {})48 showOverlay(domNode, {color, initiator} = {}) 48 49 { 49 50 console.assert(!domNode.destroyed, domNode); … … 53 54 console.assert(domNode instanceof WI.DOMNode, domNode); 54 55 console.assert(!color || color instanceof WI.Color, color); 55 console.assert( domNode.layoutContextType === WI.DOMNode.LayoutContextType.Grid, domNode.layoutContextType);56 57 color ||= this.get GridColorForNode(domNode);56 console.assert(Object.values(WI.DOMNode.LayoutContextType).includes(domNode.layoutContextType), domNode); 57 58 color ||= this.getColorForNode(domNode); 58 59 let target = WI.assumingMainTarget(); 59 let commandArguments = { 60 nodeId: domNode.id, 61 gridColor: color.toProtocol(), 62 showLineNames: WI.settings.gridOverlayShowLineNames.value, 63 showLineNumbers: WI.settings.gridOverlayShowLineNumbers.value, 64 showExtendedGridLines: WI.settings.gridOverlayShowExtendedGridLines.value, 65 showTrackSizes: WI.settings.gridOverlayShowTrackSizes.value, 66 showAreaNames: WI.settings.gridOverlayShowAreaNames.value, 67 }; 68 target.DOMAgent.showGridOverlay.invoke(commandArguments); 60 let commandArguments = {nodeId: domNode.id}; 61 62 switch (domNode.layoutContextType) { 63 case WI.DOMNode.LayoutContextType.Grid: 64 commandArguments.gridColor = color.toProtocol(); 65 commandArguments.showLineNames = WI.settings.gridOverlayShowLineNames.value; 66 commandArguments.showLineNumbers = WI.settings.gridOverlayShowLineNumbers.value; 67 commandArguments.showExtendedGridLines = WI.settings.gridOverlayShowExtendedGridLines.value; 68 commandArguments.showTrackSizes = WI.settings.gridOverlayShowTrackSizes.value; 69 commandArguments.showAreaNames = WI.settings.gridOverlayShowAreaNames.value; 70 target.DOMAgent.showGridOverlay.invoke(commandArguments); 71 break; 72 73 case WI.DOMNode.LayoutContextType.Flex: 74 commandArguments.flexColor = color.toProtocol(); 75 target.DOMAgent.showFlexOverlay.invoke(commandArguments); 76 break; 77 } 69 78 70 79 let overlay = {domNode, ...commandArguments, initiator}; 71 80 72 81 // The method to show the overlay will be called repeatedly while updating the grid overlay color. Avoid adding duplicate event listeners 73 if (!this._ gridOverlayForNodeMap.has(domNode))82 if (!this._overlayForNodeMap.has(domNode)) 74 83 domNode.addEventListener(WI.DOMNode.Event.LayoutContextTypeChanged, this._handleLayoutContextTypeChanged, this); 75 84 76 this._ gridOverlayForNodeMap.set(domNode, overlay);77 78 this.dispatchEventToListeners(WI.OverlayManager.Event. GridOverlayShown, overlay);79 } 80 81 hide GridOverlay(domNode)85 this._overlayForNodeMap.set(domNode, overlay); 86 87 this.dispatchEventToListeners(WI.OverlayManager.Event.OverlayShown, overlay); 88 } 89 90 hideOverlay(domNode) 82 91 { 83 92 console.assert(domNode instanceof WI.DOMNode, domNode); 84 93 console.assert(!domNode.destroyed, domNode); 85 console.assert( domNode.layoutContextType === WI.DOMNode.LayoutContextType.Grid, domNode.layoutContextType);94 console.assert(Object.values(WI.DOMNode.LayoutContextType).includes(domNode.layoutContextType), domNode); 86 95 if (domNode.destroyed) 87 96 return; 88 97 89 let overlay = this._ gridOverlayForNodeMap.take(domNode);98 let overlay = this._overlayForNodeMap.take(domNode); 90 99 if (!overlay) 91 100 return; 92 101 93 102 let target = WI.assumingMainTarget(); 94 target.DOMAgent.hideGridOverlay(domNode.id); 103 104 switch (domNode.layoutContextType) { 105 case WI.DOMNode.LayoutContextType.Grid: 106 target.DOMAgent.hideGridOverlay(domNode.id); 107 break; 108 109 case WI.DOMNode.LayoutContextType.Flex: 110 target.DOMAgent.hideFlexOverlay(domNode.id); 111 break; 112 } 95 113 96 114 domNode.removeEventListener(WI.DOMNode.Event.LayoutContextTypeChanged, this._handleLayoutContextTypeChanged, this); 97 this.dispatchEventToListeners(WI.OverlayManager.Event. GridOverlayHidden, overlay);115 this.dispatchEventToListeners(WI.OverlayManager.Event.OverlayHidden, overlay); 98 116 } 99 117 100 118 hasVisibleGridOverlays() 101 119 { 102 return this._gridOverlayForNodeMap.size > 0; 103 } 104 105 isGridOverlayVisible(domNode) 106 { 107 return this._gridOverlayForNodeMap.has(domNode); 108 } 109 110 toggleGridOverlay(domNode, options) 111 { 112 if (this.isGridOverlayVisible(domNode)) 113 this.hideGridOverlay(domNode); 120 for (let domNode of this._overlayForNodeMap.keys()) { 121 if (domNode.layoutContextType === WI.DOMNode.LayoutContextType.Grid) 122 return true; 123 } 124 return false; 125 } 126 127 hasVisibleOverlay(domNode) 128 { 129 return this._overlayForNodeMap.has(domNode); 130 } 131 132 toggleOverlay(domNode, options) 133 { 134 if (this.hasVisibleOverlay(domNode)) 135 this.hideOverlay(domNode); 114 136 else 115 this.show GridOverlay(domNode, options);116 } 117 118 get GridColorForNode(domNode)119 { 120 let color = this._ gridColorForNodeMap.get(domNode);137 this.showOverlay(domNode, options); 138 } 139 140 getColorForNode(domNode) 141 { 142 let color = this._colorForNodeMap.get(domNode); 121 143 if (color) 122 144 return color; 123 145 124 const defaultGridHSLColors = [ 125 [329, 91, 70], 126 [207, 96, 69], 127 [92, 90, 64], 128 [291, 73, 68], 129 [40, 97, 57], 130 ]; 131 132 let colorSetting = this._gridColorSettingForNodeMap.get(domNode); 146 let colorSetting = this._colorSettingForNodeMap.get(domNode); 133 147 if (!colorSetting) { 134 let defaultColor = defaultGridHSLColors[this._nextDefaultGridColorIndex]; 135 this._nextDefaultGridColorIndex = (this._nextDefaultGridColorIndex + 1) % defaultGridHSLColors.length; 148 let nextColorIndex; 149 switch (domNode.layoutContextType) { 150 case WI.DOMNode.LayoutContextType.Grid: 151 nextColorIndex = this._nextDefaultGridColorIndex; 152 this._nextDefaultGridColorIndex = (nextColorIndex + 1) % WI.OverlayManager._defaultHSLColors.length; 153 break; 154 155 case WI.DOMNode.LayoutContextType.Flex: 156 nextColorIndex = this._nextDefaultFlexColorIndex; 157 this._nextDefaultFlexColorIndex = (nextColorIndex + 1) % WI.OverlayManager._defaultHSLColors.length; 158 break; 159 } 160 let defaultColor = WI.OverlayManager._defaultHSLColors[nextColorIndex]; 136 161 137 162 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);163 colorSetting = new WI.Setting(`overlay-color-${url.hash}-${domNode.path().hash}`, defaultColor); 164 this._colorSettingForNodeMap.set(domNode, colorSetting); 140 165 } 141 166 142 167 color = new WI.Color(WI.Color.Format.HSL, colorSetting.value); 143 this._ gridColorForNodeMap.set(domNode, color);168 this._colorForNodeMap.set(domNode, color); 144 169 145 170 return color; 146 171 } 147 172 148 set GridColorForNode(domNode, color)173 setColorForNode(domNode, color) 149 174 { 150 175 console.assert(domNode instanceof WI.DOMNode, domNode); 151 176 console.assert(color instanceof WI.Color, color); 152 177 153 let colorSetting = this._ gridColorSettingForNodeMap.get(domNode);154 console.assert(colorSetting, "There should already be a setting created form a previous call to get GridColorForNode()");178 let colorSetting = this._colorSettingForNodeMap.get(domNode); 179 console.assert(colorSetting, "There should already be a setting created form a previous call to getColorForNode()"); 155 180 colorSetting.value = color.hsl; 156 181 157 this._ gridColorForNodeMap.set(domNode, color);182 this._colorForNodeMap.set(domNode, color); 158 183 } 159 184 … … 163 188 { 164 189 let domNode = event.target; 165 console.assert(domNode.layoutContextType !== WI.DOMNode.LayoutContextType.Grid, domNode);166 190 167 191 domNode.removeEventListener(WI.DOMNode.Event.LayoutContextTypeChanged, this._handleLayoutContextTypeChanged, this); 168 192 169 // When the context type changes, the overlay is automatically hidden on the backend. Here, we only update the map and notify listeners. 170 let overlay = this._gridOverlayForNodeMap.take(domNode); 171 this.dispatchEventToListeners(WI.OverlayManager.Event.GridOverlayHidden, overlay); 193 // When the context type changes, the overlay is automatically hidden on the backend (even if it changes from Grid to Flex, or vice-versa). 194 // Here, we only update the map and notify listeners. 195 let overlay = this._overlayForNodeMap.take(domNode); 196 this.dispatchEventToListeners(WI.OverlayManager.Event.OverlayHidden, overlay); 172 197 } 173 198 174 199 _handleGridSettingChanged(event) 175 200 { 176 for (let [domNode, overlay] of this._ gridOverlayForNodeMap) {177 // Refresh all shown overlays. Latest settings values will be used.178 this.showGridOverlay(domNode, {color: overlay.color, initiator: overlay.initiator});201 for (let [domNode, overlay] of this._overlayForNodeMap) { 202 if (domNode.layoutContextType === WI.DOMNode.LayoutContextType.Grid) 203 this.showOverlay(domNode, {color: overlay.color, initiator: overlay.initiator}); 179 204 } 180 205 } … … 192 217 // `domNode.id` is different for the same DOM element after page reload. 193 218 this._nextDefaultGridColorIndex = 0; 219 this._nextDefaultFlexColorIndex = 0; 194 220 } 195 221 }; 196 222 223 WI.OverlayManager._defaultHSLColors = [ 224 [329, 91, 70], 225 [207, 96, 69], 226 [92, 90, 64], 227 [291, 73, 68], 228 [40, 97, 57], 229 ]; 230 197 231 WI.OverlayManager.Event = { 198 GridOverlayShown: "overlay-manager-grid-overlay-shown",199 GridOverlayHidden: "overlay-manager-grid-overlay-hidden",232 OverlayShown: "overlay-manager-overlay-shown", 233 OverlayHidden: "overlay-manager-overlay-hidden", 200 234 }; -
trunk/Source/WebInspectorUI/UserInterface/Views/CSSGridSection.js
r277284 r289610 54 54 super.attached(); 55 55 56 WI.overlayManager.addEventListener(WI.OverlayManager.Event. GridOverlayShown, this._handleGridOverlayStateChanged, this);57 WI.overlayManager.addEventListener(WI.OverlayManager.Event. GridOverlayHidden, this._handleGridOverlayStateChanged, this);56 WI.overlayManager.addEventListener(WI.OverlayManager.Event.OverlayShown, this._handleGridOverlayStateChanged, this); 57 WI.overlayManager.addEventListener(WI.OverlayManager.Event.OverlayHidden, this._handleGridOverlayStateChanged, this); 58 58 } 59 59 60 60 detached() 61 61 { 62 WI.overlayManager.removeEventListener(WI.OverlayManager.Event. GridOverlayShown, this._handleGridOverlayStateChanged, this);63 WI.overlayManager.removeEventListener(WI.OverlayManager.Event. GridOverlayHidden, this._handleGridOverlayStateChanged, this);62 WI.overlayManager.removeEventListener(WI.OverlayManager.Event.OverlayShown, this._handleGridOverlayStateChanged, this); 63 WI.overlayManager.removeEventListener(WI.OverlayManager.Event.OverlayHidden, this._handleGridOverlayStateChanged, this); 64 64 65 65 super.detached(); … … 100 100 for (let domNode of this._gridNodeSet) { 101 101 if (isChecked) 102 WI.overlayManager.show GridOverlay(domNode, {initiator: WI.GridOverlayDiagnosticEventRecorder.Initiator.Panel});102 WI.overlayManager.showOverlay(domNode, {initiator: WI.GridOverlayDiagnosticEventRecorder.Initiator.Panel}); 103 103 else 104 WI.overlayManager.hide GridOverlay(domNode);104 WI.overlayManager.hideOverlay(domNode); 105 105 } 106 106 this._suppressUpdateToggleAllCheckbox = false; … … 121 121 let checkboxElement = labelElement.appendChild(document.createElement("input")); 122 122 checkboxElement.type = "checkbox"; 123 checkboxElement.checked = WI.overlayManager. isGridOverlayVisible(domNode);123 checkboxElement.checked = WI.overlayManager.hasVisibleOverlay(domNode); 124 124 125 125 const nodeDisplayName = labelElement.appendChild(document.createElement("span")); … … 131 131 checkboxElement.addEventListener("change", (event) => { 132 132 if (checkboxElement.checked) 133 WI.overlayManager.show GridOverlay(domNode, {color: swatch.value, initiator: WI.GridOverlayDiagnosticEventRecorder.Initiator.Panel});133 WI.overlayManager.showOverlay(domNode, {color: swatch.value, initiator: WI.GridOverlayDiagnosticEventRecorder.Initiator.Panel}); 134 134 else 135 WI.overlayManager.hide GridOverlay(domNode);135 WI.overlayManager.hideOverlay(domNode); 136 136 }); 137 137 138 let gridColor = WI.overlayManager.get GridColorForNode(domNode);138 let gridColor = WI.overlayManager.getColorForNode(domNode); 139 139 let swatch = new WI.InlineSwatch(WI.InlineSwatch.Type.Color, gridColor); 140 140 swatch.shiftClickColorEnabled = false; … … 145 145 // While changing the overlay color, WI.OverlayManager.Event.GridOverlayShown is dispatched with high frequency. 146 146 // An initiator is not provided so as not to skew usage count of overlay options when logging diagnostics in WI.GridOverlayDiagnosticEventRecorder. 147 WI.overlayManager.show GridOverlay(domNode, {color: event.data.value});147 WI.overlayManager.showOverlay(domNode, {color: event.data.value}); 148 148 }, swatch); 149 149 … … 153 153 154 154 gridColor = event.target.value; 155 WI.overlayManager.set GridColorForNode(domNode, gridColor);155 WI.overlayManager.setColorForNode(domNode, gridColor); 156 156 }, swatch); 157 157 … … 168 168 _handleGridOverlayStateChanged(event) 169 169 { 170 if (event.data.domNode.layoutContextType !== WI.DOMNode.LayoutContextType.Grid) 171 return; 172 170 173 let checkboxElement = this._checkboxElementByNodeMap.get(event.data.domNode); 171 174 if (!checkboxElement) 172 175 return; 173 176 174 checkboxElement.checked = event.type === WI.OverlayManager.Event. GridOverlayShown;177 checkboxElement.checked = event.type === WI.OverlayManager.Event.OverlayShown; 175 178 this._updateToggleAllCheckbox(); 176 179 } … … 184 187 let hasHidden = false; 185 188 for (let domNode of this._gridNodeSet) { 186 let isVisible = WI.overlayManager. isGridOverlayVisible(domNode);189 let isVisible = WI.overlayManager.hasVisibleOverlay(domNode); 187 190 if (isVisible) 188 191 hasVisible = true; -
trunk/Source/WebInspectorUI/UserInterface/Views/DOMTreeElement.css
r273992 r289610 24 24 */ 25 25 26 .tree-outline.dom . badge-css-grid{26 .tree-outline.dom .layout-badge { 27 27 /* Using sans-serif San Francisco font here creates a badge 1px taller than the selected 28 28 area. Use the same monospace font as the rest of the DOM tree outline. */ … … 39 39 } 40 40 41 .tree-outline.dom . badge-css-grid.activated {41 .tree-outline.dom .layout-badge.activated { 42 42 background: var(--glyph-color-active); 43 43 color: white; 44 44 } 45 45 46 body:not(.window-inactive, .window-docked-inactive) .tree-outline.dom:focus-within li.selected . badge-css-grid{46 body:not(.window-inactive, .window-docked-inactive) .tree-outline.dom:focus-within li.selected .layout-badge { 47 47 /* Override `li.selected * {color: inherited}` from DOMTreeOutline.css */ 48 48 color: var(--text-color); … … 51 51 52 52 @media (prefers-color-scheme: dark) { 53 .tree-outline.dom . badge-css-grid{53 .tree-outline.dom .layout-badge { 54 54 background: hsla(0, 0%, 30%, 0.8); 55 55 border-color: hsla(0, 0%, 100%, 0.1); -
trunk/Source/WebInspectorUI/UserInterface/Views/DOMTreeElement.js
r281258 r289610 52 52 this._recentlyModifiedAttributes = new Map; 53 53 this._closeTagTreeElement = null; 54 this._ gridBadgeElement = null;54 this._layoutBadgeElement = null; 55 55 56 56 node.addEventListener(WI.DOMNode.Event.EnabledPseudoClassesChanged, this._updatePseudoClassIndicator, this); … … 445 445 } 446 446 447 if (this.representedObject.layoutContextType) { 448 WI.overlayManager.addEventListener(WI.OverlayManager.Event.OverlayShown, this._updateLayoutBadgeStatus, this); 449 WI.overlayManager.addEventListener(WI.OverlayManager.Event.OverlayHidden, this._updateLayoutBadgeStatus, this); 450 } 451 this.representedObject.addEventListener(WI.DOMNode.Event.LayoutContextTypeChanged, this._handleLayoutContextTypeChanged, this); 452 453 this._updateLayoutBadge(); 454 } 455 456 ondetach() 457 { 447 458 if (this.representedObject.layoutContextType === WI.DOMNode.LayoutContextType.Grid) { 448 WI.overlayManager.addEventListener(WI.OverlayManager.Event.GridOverlayShown, this._updateGridBadgeStatus, this); 449 WI.overlayManager.addEventListener(WI.OverlayManager.Event.GridOverlayHidden, this._updateGridBadgeStatus, this); 450 } 451 this.representedObject.addEventListener(WI.DOMNode.Event.LayoutContextTypeChanged, this._handleLayoutContextTypeChanged, this); 452 453 this._updateGridBadge(); 454 } 455 456 ondetach() 457 { 458 if (this.representedObject.layoutContextType === WI.DOMNode.LayoutContextType.Grid) { 459 WI.overlayManager.removeEventListener(WI.OverlayManager.Event.GridOverlayShown, this._updateGridBadgeStatus, this); 460 WI.overlayManager.removeEventListener(WI.OverlayManager.Event.GridOverlayHidden, this._updateGridBadgeStatus, this); 459 WI.overlayManager.removeEventListener(WI.OverlayManager.Event.OverlayShown, this._updateLayoutBadgeStatus, this); 460 WI.overlayManager.removeEventListener(WI.OverlayManager.Event.OverlayHidden, this._updateLayoutBadgeStatus, this); 461 461 } 462 462 this.representedObject.removeEventListener(WI.DOMNode.Event.LayoutContextTypeChanged, this._handleLayoutContextTypeChanged, this); … … 1335 1335 this._highlightResult = undefined; 1336 1336 } 1337 this._update GridBadge();1337 this._updateLayoutBadge(); 1338 1338 1339 1339 // Setting this.title will implicitly remove all children. Clear the … … 2011 2011 } 2012 2012 2013 _update GridBadge()2013 _updateLayoutBadge() 2014 2014 { 2015 2015 if (!this.listItemElement || this._elementCloseTag) 2016 2016 return; 2017 2017 2018 if (this._gridBadgeElement) { 2019 this._gridBadgeElement.remove(); 2020 this._gridBadgeElement = null; 2021 } 2022 2023 if (this.representedObject.layoutContextType !== WI.DOMNode.LayoutContextType.Grid) 2024 return; 2025 2026 this._gridBadgeElement = document.createElement("span"); 2027 this._gridBadgeElement.className = "badge-css-grid"; 2028 this._gridBadgeElement.textContent = WI.unlocalizedString("grid"); 2029 this._updateGridBadgeStatus(); 2030 this.title.append(this._gridBadgeElement); 2031 2032 this._gridBadgeElement.addEventListener("click", this._gridBadgeClicked.bind(this), true); 2033 this._gridBadgeElement.addEventListener("dblclick", this._gridBadgeDoubleClicked, true); 2034 } 2035 2036 _gridBadgeClicked(event) 2018 if (this._layoutBadgeElement) { 2019 this._layoutBadgeElement.remove(); 2020 this._layoutBadgeElement = null; 2021 } 2022 2023 if (!this.representedObject.layoutContextType) 2024 return; 2025 2026 if (this.representedObject.layoutContextType === WI.DOMNode.LayoutContextType.Flex && !WI.settings.engineeringEnableFlexboxInspector.value) 2027 return; 2028 2029 this._layoutBadgeElement = this.title.appendChild(document.createElement("span")); 2030 this._layoutBadgeElement.className = "layout-badge"; 2031 2032 switch (this.representedObject.layoutContextType) { 2033 case WI.DOMNode.LayoutContextType.Grid: 2034 this._layoutBadgeElement.textContent = WI.unlocalizedString("grid"); 2035 break; 2036 2037 case WI.DOMNode.LayoutContextType.Flex: 2038 this._layoutBadgeElement.textContent = WI.unlocalizedString("flex"); 2039 break; 2040 2041 default: 2042 console.assert(false, this.representedObject.layoutContextType); 2043 break; 2044 } 2045 2046 this._updateLayoutBadgeStatus(); 2047 2048 this._layoutBadgeElement.addEventListener("click", this._layoutBadgeClicked.bind(this), true); 2049 this._layoutBadgeElement.addEventListener("dblclick", this._layoutBadgeDoubleClicked, true); 2050 } 2051 2052 _layoutBadgeClicked(event) 2037 2053 { 2038 2054 if (event.button !== 0 || event.ctrlKey) … … 2042 2058 event.stop(); 2043 2059 2044 WI.overlayManager.toggleGridOverlay(this.representedObject, {initiator: WI.GridOverlayDiagnosticEventRecorder.Initiator.Badge}); 2045 } 2046 2047 _gridBadgeDoubleClicked(event) 2060 WI.overlayManager.toggleOverlay(this.representedObject, { 2061 initiator: this.representedObject.layoutContextType === WI.DOMNode.LayoutContextType.Grid ? WI.GridOverlayDiagnosticEventRecorder.Initiator.Badge : null, 2062 }); 2063 } 2064 2065 _layoutBadgeDoubleClicked(event) 2048 2066 { 2049 2067 event.stop(); 2050 2068 } 2051 2069 2052 _update GridBadgeStatus()2053 { 2054 if (!this._ gridBadgeElement)2055 return; 2056 2057 let isGridVisible = WI.overlayManager.isGridOverlayVisible(this.representedObject);2058 this._ gridBadgeElement.classList.toggle("activated", isGridVisible);2059 2060 if ( isGridVisible) {2061 let color = WI.overlayManager.get GridColorForNode(this.representedObject);2070 _updateLayoutBadgeStatus() 2071 { 2072 if (!this._layoutBadgeElement) 2073 return; 2074 2075 let hasVisibleOverlay = WI.overlayManager.hasVisibleOverlay(this.representedObject); 2076 this._layoutBadgeElement.classList.toggle("activated", hasVisibleOverlay); 2077 2078 if (hasVisibleOverlay) { 2079 let color = WI.overlayManager.getColorForNode(this.representedObject); 2062 2080 let hue = color.hsl[0]; 2063 this._ gridBadgeElement.style.borderColor = color.toString();2064 this._ gridBadgeElement.style.backgroundColor = `hsl(${hue}, 90%, 95%)`;2065 this._ gridBadgeElement.style.setProperty("color", `hsl(${hue}, 55%, 40%)`);2081 this._layoutBadgeElement.style.borderColor = color.toString(); 2082 this._layoutBadgeElement.style.backgroundColor = `hsl(${hue}, 90%, 95%)`; 2083 this._layoutBadgeElement.style.setProperty("color", `hsl(${hue}, 55%, 40%)`); 2066 2084 } else 2067 this._ gridBadgeElement.removeAttribute("style");2085 this._layoutBadgeElement.removeAttribute("style"); 2068 2086 } 2069 2087 … … 2071 2089 { 2072 2090 let domNode = event.target; 2073 if (domNode.layoutContextType === WI.DOMNode.LayoutContextType.Grid) {2074 WI.overlayManager.addEventListener(WI.OverlayManager.Event. GridOverlayShown, this._updateGridBadgeStatus, this);2075 WI.overlayManager.addEventListener(WI.OverlayManager.Event. GridOverlayHidden, this._updateGridBadgeStatus, this);2091 if (domNode.layoutContextType) { 2092 WI.overlayManager.addEventListener(WI.OverlayManager.Event.OverlayShown, this._updateLayoutBadgeStatus, this); 2093 WI.overlayManager.addEventListener(WI.OverlayManager.Event.OverlayHidden, this._updateLayoutBadgeStatus, this); 2076 2094 } else { 2077 WI.overlayManager.removeEventListener(WI.OverlayManager.Event. GridOverlayShown, this._updateGridBadgeStatus, this);2078 WI.overlayManager.removeEventListener(WI.OverlayManager.Event. GridOverlayHidden, this._updateGridBadgeStatus, this);2079 } 2080 2081 this._update GridBadge();2095 WI.overlayManager.removeEventListener(WI.OverlayManager.Event.OverlayShown, this._updateLayoutBadgeStatus, this); 2096 WI.overlayManager.removeEventListener(WI.OverlayManager.Event.OverlayHidden, this._updateLayoutBadgeStatus, this); 2097 } 2098 2099 this._updateLayoutBadge(); 2082 2100 } 2083 2101 };
Note: See TracChangeset
for help on using the changeset viewer.