Changeset 209711 in webkit
- Timestamp:
- Dec 12, 2016, 9:24:03 AM (9 years ago)
- Location:
- trunk/Source/WebInspectorUI
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebInspectorUI/ChangeLog
r209709 r209711 1 2016-12-12 Matt Baker <mattbaker@apple.com> 2 3 Web Inspector: Cleanup HierarchicalPathComponent 4 https://bugs.webkit.org/show_bug.cgi?id=165745 5 6 Reviewed by Brian Burg. 7 8 Prefer toggle for style class names, remove single use CSS class name 9 constants, and back all properties by the model not the DOM. 10 11 * UserInterface/Views/HierarchicalPathComponent.js: 12 (WebInspector.HierarchicalPathComponent): 13 (WebInspector.HierarchicalPathComponent.prototype.get element): 14 (WebInspector.HierarchicalPathComponent.prototype.get representedObject): 15 (WebInspector.HierarchicalPathComponent.prototype.get minimumWidth): 16 (WebInspector.HierarchicalPathComponent.prototype.get forcedWidth): 17 (WebInspector.HierarchicalPathComponent.prototype.set forcedWidth): 18 (WebInspector.HierarchicalPathComponent.prototype.get hidden): 19 (WebInspector.HierarchicalPathComponent.prototype.set hidden): 20 (WebInspector.HierarchicalPathComponent.prototype.get collapsed): 21 (WebInspector.HierarchicalPathComponent.prototype.set collapsed): 22 (WebInspector.HierarchicalPathComponent.prototype.get selectorArrows): 23 (WebInspector.HierarchicalPathComponent.prototype.set selectorArrows): 24 (WebInspector.HierarchicalPathComponent.prototype.get previousSibling): 25 (WebInspector.HierarchicalPathComponent.prototype.set previousSibling): 26 (WebInspector.HierarchicalPathComponent.prototype.get nextSibling): 27 (WebInspector.HierarchicalPathComponent.prototype.set nextSibling): 28 (WebInspector.HierarchicalPathComponent.prototype._updateElementTitleAndText): 29 (WebInspector.HierarchicalPathComponent.prototype._updateSelectElement.createOption): 30 (WebInspector.HierarchicalPathComponent.prototype._updateSelectElement): 31 1 32 2016-12-12 Matt Baker <mattbaker@apple.com> 2 33 -
trunk/Source/WebInspectorUI/UserInterface/Views/HierarchicalPathComponent.js
r200995 r209711 38 38 this._element.className = "hierarchical-path-component"; 39 39 40 if (! (styleClassNames instanceof Array))40 if (!Array.isArray(styleClassNames)) 41 41 styleClassNames = [styleClassNames]; 42 42 43 for (var i = 0; i < styleClassNames.length; ++i) { 44 if (!styleClassNames[i]) 45 continue; 46 this._element.classList.add(styleClassNames[i]); 47 } 43 this._element.classList.add(...styleClassNames); 48 44 49 45 if (!textOnly) { … … 52 48 this._element.appendChild(this._iconElement); 53 49 } else 54 this._element.classList.add( WebInspector.HierarchicalPathComponent.TextOnlyStyleClassName);50 this._element.classList.add("text-only"); 55 51 56 52 this._titleElement = document.createElement("div"); … … 79 75 this._truncatedDisplayNameLength = 0; 80 76 77 this._collapsed = false; 78 this._hidden = false; 79 this._selectorArrows = false; 80 81 this.displayName = displayName; 81 82 this.selectorArrows = showSelectorArrows; 82 this.displayName = displayName;83 83 } 84 84 … … 93 93 } 94 94 95 get element() 96 { 97 return this._element; 98 } 99 100 get representedObject() 101 { 102 return this._representedObject; 103 } 95 get element() { return this._element; } 96 get representedObject() { return this._representedObject; } 104 97 105 98 get displayName() … … 138 131 get minimumWidth() 139 132 { 140 if (this. collapsed)133 if (this._collapsed) 141 134 return WebInspector.HierarchicalPathComponent.MinimumWidthCollapsed; 142 if (this. selectorArrows)135 if (this._selectorArrows) 143 136 return WebInspector.HierarchicalPathComponent.MinimumWidth + WebInspector.HierarchicalPathComponent.SelectorArrowsWidth; 144 137 return WebInspector.HierarchicalPathComponent.MinimumWidth; … … 147 140 get forcedWidth() 148 141 { 149 varmaxWidth = this._element.style.getProperty("width");142 let maxWidth = this._element.style.getProperty("width"); 150 143 if (typeof maxWidth === "string") 151 144 return parseInt(maxWidth); … … 156 149 { 157 150 if (typeof width === "number") { 158 varminimumWidthForOneCharacterTruncatedTitle = WebInspector.HierarchicalPathComponent.MinimumWidthForOneCharacterTruncatedTitle;151 let minimumWidthForOneCharacterTruncatedTitle = WebInspector.HierarchicalPathComponent.MinimumWidthForOneCharacterTruncatedTitle; 159 152 if (this.selectorArrows) 160 153 minimumWidthForOneCharacterTruncatedTitle += WebInspector.HierarchicalPathComponent.SelectorArrowsWidth; … … 174 167 get hidden() 175 168 { 176 return this._ element.classList.contains(WebInspector.HierarchicalPathComponent.HiddenStyleClassName);169 return this._hidden; 177 170 } 178 171 179 172 set hidden(flag) 180 173 { 181 if (flag) 182 this._element.classList.add(WebInspector.HierarchicalPathComponent.HiddenStyleClassName); 183 else 184 this._element.classList.remove(WebInspector.HierarchicalPathComponent.HiddenStyleClassName); 174 if (this._hidden === flag) 175 return; 176 177 this._hidden = flag; 178 this._element.classList.toggle("hidden", this._hidden); 185 179 } 186 180 187 181 get collapsed() 188 182 { 189 return this._ element.classList.contains(WebInspector.HierarchicalPathComponent.CollapsedStyleClassName);183 return this._collapsed; 190 184 } 191 185 192 186 set collapsed(flag) 193 187 { 194 if (flag) 195 this._element.classList.add(WebInspector.HierarchicalPathComponent.CollapsedStyleClassName); 196 else 197 this._element.classList.remove(WebInspector.HierarchicalPathComponent.CollapsedStyleClassName); 188 if (this._collapsed === flag) 189 return; 190 191 this._collapsed = flag; 192 this._element.classList.toggle("collapsed", this._collapsed); 198 193 } 199 194 200 195 get selectorArrows() 201 196 { 202 return this._ element.classList.contains(WebInspector.HierarchicalPathComponent.ShowSelectorArrowsStyleClassName);197 return this._selectorArrows; 203 198 } 204 199 205 200 set selectorArrows(flag) 206 201 { 207 if (flag) { 202 if (this._selectorArrows === flag) 203 return; 204 205 this._selectorArrows = flag; 206 207 if (this._selectorArrows) { 208 208 this._selectorArrowsElement = document.createElement("img"); 209 209 this._selectorArrowsElement.className = "selector-arrows"; 210 210 this._element.insertBefore(this._selectorArrowsElement, this._separatorElement); 211 212 this._element.classList.add(WebInspector.HierarchicalPathComponent.ShowSelectorArrowsStyleClassName); 213 } else { 214 if (this._selectorArrowsElement) { 215 this._selectorArrowsElement.remove(); 216 delete this._selectorArrowsElement; 217 } 218 219 this._element.classList.remove(WebInspector.HierarchicalPathComponent.ShowSelectorArrowsStyleClassName); 211 } else if (this._selectorArrowsElement) { 212 this._selectorArrowsElement.remove(); 213 this._selectorArrowsElement = null; 220 214 } 221 } 222 223 get previousSibling() 224 { 225 return this._previousSibling; 226 } 227 228 set previousSibling(newSlibling) 229 { 230 this._previousSibling = newSlibling || null; 231 } 232 233 get nextSibling() 234 { 235 return this._nextSibling; 236 } 237 238 set nextSibling(newSlibling) 239 { 240 this._nextSibling = newSlibling || null; 241 } 215 216 this._element.classList.toggle("show-selector-arrows", this._selectorArrows); 217 } 218 219 get previousSibling() { return this._previousSibling; } 220 set previousSibling(newSlibling) { this._previousSibling = newSlibling || null; } 221 get nextSibling() { return this._nextSibling; } 222 set nextSibling(newSlibling) { this._nextSibling = newSlibling || null; } 242 223 243 224 // Private … … 245 226 _updateElementTitleAndText() 246 227 { 247 vartruncatedDisplayName = this._displayName;228 let truncatedDisplayName = this._displayName; 248 229 if (this._truncatedDisplayNameLength && truncatedDisplayName.length > this._truncatedDisplayNameLength) 249 230 truncatedDisplayName = truncatedDisplayName.substring(0, this._truncatedDisplayNameLength) + ellipsis; … … 259 240 function createOption(component) 260 241 { 261 varoptionElement = document.createElement("option");262 varmaxPopupMenuLength = 130; // <rdar://problem/13445374> <select> with very long option has clipped text and popup menu is still very wide242 let optionElement = document.createElement("option"); 243 let maxPopupMenuLength = 130; // <rdar://problem/13445374> <select> with very long option has clipped text and popup menu is still very wide 263 244 optionElement.textContent = component.displayName.length <= maxPopupMenuLength ? component.displayName : component.displayName.substring(0, maxPopupMenuLength) + ellipsis; 264 245 optionElement._pathComponent = component; … … 266 247 } 267 248 268 varpreviousSiblingCount = 0;269 varsibling = this.previousSibling;249 let previousSiblingCount = 0; 250 let sibling = this.previousSibling; 270 251 while (sibling) { 271 252 this._selectElement.insertBefore(createOption(sibling), this._selectElement.firstChild); … … 323 304 }; 324 305 325 WebInspector.HierarchicalPathComponent.HiddenStyleClassName = "hidden";326 WebInspector.HierarchicalPathComponent.CollapsedStyleClassName = "collapsed";327 WebInspector.HierarchicalPathComponent.TextOnlyStyleClassName = "text-only";328 WebInspector.HierarchicalPathComponent.ShowSelectorArrowsStyleClassName = "show-selector-arrows";329 330 306 WebInspector.HierarchicalPathComponent.MinimumWidth = 32; 331 307 WebInspector.HierarchicalPathComponent.MinimumWidthCollapsed = 24;
Note:
See TracChangeset
for help on using the changeset viewer.