Changeset 206406 in webkit
- Timestamp:
- Sep 26, 2016, 5:06:55 PM (9 years ago)
- Location:
- trunk/Source/WebInspectorUI
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebInspectorUI/ChangeLog
r206372 r206406 1 2016-09-26 Matt Baker <mattbaker@apple.com> 2 3 Web Inspector: Box Model values not updated when DOM node styles change 4 https://bugs.webkit.org/show_bug.cgi?id=162525 5 6 Reviewed by Brian Burg. 7 8 The Box Model section should refresh itself when the selected node's 9 computed style changes. This is necessary since the Styles sidebar 10 doesn't always refresh its sections on node changes. 11 12 * UserInterface/Views/BoxModelDetailsSectionRow.js: 13 (WebInspector.BoxModelDetailsSectionRow.prototype.set nodeStyles): 14 Refresh metrics whenever the computed style changes. 15 16 (WebInspector.BoxModelDetailsSectionRow.prototype._getBox): 17 (WebInspector.BoxModelDetailsSectionRow.prototype._getComponentSuffix): 18 (WebInspector.BoxModelDetailsSectionRow.prototype._updateMetrics.createValueElement): 19 (WebInspector.BoxModelDetailsSectionRow.prototype._updateMetrics.createBoxPartElement): 20 (WebInspector.BoxModelDetailsSectionRow.prototype._updateMetrics.createContentAreaElement): 21 (WebInspector.BoxModelDetailsSectionRow.prototype._updateMetrics): 22 Drive-by cleanup to make this large function easier to read. 23 (WebInspector.BoxModelDetailsSectionRow.prototype._updateMetrics.createElement): Deleted. 24 Renamed createValueElement. 25 (WebInspector.BoxModelDetailsSectionRow.prototype._updateMetrics.createContentAreaWidthElement): Deleted. 26 (WebInspector.BoxModelDetailsSectionRow.prototype._updateMetrics.createContentAreaHeightElement): Deleted. 27 Combined these into a single function taking a property name (width or height). 28 1 29 == Rolled over to ChangeLog-2016-09-26 == -
trunk/Source/WebInspectorUI/UserInterface/Views/BoxModelDetailsSectionRow.js
r206363 r206406 44 44 set nodeStyles(nodeStyles) 45 45 { 46 if (this._nodeStyles && this._nodeStyles.computedStyle) 47 this._nodeStyles.computedStyle.removeEventListener(WebInspector.CSSStyleDeclaration.Event.PropertiesChanged, this._refresh, this); 48 46 49 this._nodeStyles = nodeStyles; 50 if (this._nodeStyles && this._nodeStyles.computedStyle) 51 this._nodeStyles.computedStyle.addEventListener(WebInspector.CSSStyleDeclaration.Event.PropertiesChanged, this._refresh, this); 47 52 48 53 this._refresh(); … … 68 73 _getBox(computedStyle, componentName) 69 74 { 70 var suffix = componentName === "border" ? "-width" : "";75 var suffix = this._getComponentSuffix(componentName); 71 76 var left = this._getPropertyValueAsPx(computedStyle, componentName + "-left" + suffix); 72 77 var top = this._getPropertyValueAsPx(computedStyle, componentName + "-top" + suffix); … … 74 79 var bottom = this._getPropertyValueAsPx(computedStyle, componentName + "-bottom" + suffix); 75 80 return {left, top, right, bottom}; 81 } 82 83 _getComponentSuffix(componentName) 84 { 85 return componentName === "border" ? "-width" : ""; 76 86 } 77 87 … … 104 114 _updateMetrics() 105 115 { 106 // Updating with computed style.107 116 var metricsElement = document.createElement("div"); 108 109 var self = this;110 117 var style = this._nodeStyles.computedStyle; 111 118 112 function create Element(type, value, name, propertyName, style)119 function createValueElement(type, value, name, propertyName) 113 120 { 114 121 // Check if the value is a float and whether it should be rounded. … … 127 134 } 128 135 129 function createBoxPartElement( style, name, side, suffix)136 function createBoxPartElement(name, side) 130 137 { 138 let suffix = this._getComponentSuffix(name); 131 139 let propertyName = (name !== "position" ? name + "-" : "") + side + suffix; 132 140 let value = style.propertyForName(propertyName).value; … … 136 144 value = value.replace(/px$/, ""); 137 145 138 let element = create Element.call(this, "div", value, name, propertyName, style);146 let element = createValueElement.call(this, "div", value, name, propertyName); 139 147 element.className = side; 140 148 return element; 141 149 } 142 150 143 function createContentArea WidthElement(style)151 function createContentAreaElement(name) 144 152 { 145 var width = style.propertyForName("width").value.replace(/px$/, ""); 153 console.assert(name === "width" || name === "height"); 154 155 let size = style.propertyForName(name).value.replace(/px$/, ""); 146 156 if (style.propertyForName("box-sizing").value === "border-box") { 147 var borderBox = self._getBox(style, "border"); 148 var paddingBox = self._getBox(style, "padding"); 149 150 width = width - borderBox.left - borderBox.right - paddingBox.left - paddingBox.right; 151 } 152 153 return createElement.call(this, "span", width, "width", "width", style); 154 } 155 156 function createContentAreaHeightElement(style) 157 { 158 var height = style.propertyForName("height").value.replace(/px$/, ""); 159 if (style.propertyForName("box-sizing").value === "border-box") { 160 var borderBox = self._getBox(style, "border"); 161 var paddingBox = self._getBox(style, "padding"); 162 163 height = height - borderBox.top - borderBox.bottom - paddingBox.top - paddingBox.bottom; 164 } 165 166 return createElement.call(this, "span", height, "height", "height", style); 157 let borderBox = this._getBox(style, "border"); 158 let paddingBox = this._getBox(style, "padding"); 159 160 let [side, oppositeSide] = name === "width" ? ["left", "right"] : ["top", "bottom"]; 161 size = size - borderBox[side] - borderBox[oppositeSide] - paddingBox[side] - paddingBox[oppositeSide]; 162 } 163 164 return createValueElement.call(this, "span", size, name, name); 167 165 } 168 166 … … 194 192 195 193 this._boxElements = []; 196 var boxes = ["content", "padding", "border", "margin", "position"];197 194 198 195 if (!style.hasProperties()) { … … 202 199 203 200 var previousBox = null; 204 for (var i = 0; i < boxes.length; ++i) { 205 var name = boxes[i]; 206 201 for (let name of ["content", "padding", "border", "margin", "position"]) { 207 202 if (name === "margin" && noMarginDisplayType[style.propertyForName("display").value]) 208 203 continue; … … 219 214 220 215 if (name === "content") { 221 var widthElement = createContentAreaWidthElement.call(this, style);222 var heightElement = createContentAreaHeightElement.call(this, style);216 let widthElement = createContentAreaElement.call(this, "width"); 217 let heightElement = createContentAreaElement.call(this, "height"); 223 218 boxElement.append(widthElement, " \u00D7 ", heightElement); 224 219 } else { 225 var suffix = name === "border" ? "-width" : "";226 227 220 var labelElement = document.createElement("div"); 228 221 labelElement.className = "label"; 229 labelElement.textContent = boxes[i];222 labelElement.textContent = name; 230 223 boxElement.appendChild(labelElement); 231 224 232 boxElement.appendChild(createBoxPartElement.call(this, style, name, "top", suffix));225 boxElement.appendChild(createBoxPartElement.call(this, name, "top")); 233 226 boxElement.appendChild(document.createElement("br")); 234 boxElement.appendChild(createBoxPartElement.call(this, style, name, "left", suffix));227 boxElement.appendChild(createBoxPartElement.call(this, name, "left")); 235 228 236 229 if (previousBox) 237 230 boxElement.appendChild(previousBox); 238 231 239 boxElement.appendChild(createBoxPartElement.call(this, style, name, "right", suffix));232 boxElement.appendChild(createBoxPartElement.call(this, name, "right")); 240 233 boxElement.appendChild(document.createElement("br")); 241 boxElement.appendChild(createBoxPartElement.call(this, style, name, "bottom", suffix));234 boxElement.appendChild(createBoxPartElement.call(this, name, "bottom")); 242 235 } 243 236
Note:
See TracChangeset
for help on using the changeset viewer.