Changeset 206406 in webkit


Ignore:
Timestamp:
Sep 26, 2016, 5:06:55 PM (9 years ago)
Author:
Matt Baker
Message:

Web Inspector: Box Model values not updated when DOM node styles change
https://bugs.webkit.org/show_bug.cgi?id=162525

Reviewed by Brian Burg.

The Box Model section should refresh itself when the selected node's
computed style changes. This is necessary since the Styles sidebar
doesn't always refresh its sections on node changes.

  • UserInterface/Views/BoxModelDetailsSectionRow.js:

(WebInspector.BoxModelDetailsSectionRow.prototype.set nodeStyles):
Refresh metrics whenever the computed style changes.

(WebInspector.BoxModelDetailsSectionRow.prototype._getBox):
(WebInspector.BoxModelDetailsSectionRow.prototype._getComponentSuffix):
(WebInspector.BoxModelDetailsSectionRow.prototype._updateMetrics.createValueElement):
(WebInspector.BoxModelDetailsSectionRow.prototype._updateMetrics.createBoxPartElement):
(WebInspector.BoxModelDetailsSectionRow.prototype._updateMetrics.createContentAreaElement):
(WebInspector.BoxModelDetailsSectionRow.prototype._updateMetrics):
Drive-by cleanup to make this large function easier to read.
(WebInspector.BoxModelDetailsSectionRow.prototype._updateMetrics.createElement): Deleted.
Renamed createValueElement.
(WebInspector.BoxModelDetailsSectionRow.prototype._updateMetrics.createContentAreaWidthElement): Deleted.
(WebInspector.BoxModelDetailsSectionRow.prototype._updateMetrics.createContentAreaHeightElement): Deleted.
Combined these into a single function taking a property name (width or height).

Location:
trunk/Source/WebInspectorUI
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebInspectorUI/ChangeLog

    r206372 r206406  
     12016-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
    129== Rolled over to ChangeLog-2016-09-26 ==
  • trunk/Source/WebInspectorUI/UserInterface/Views/BoxModelDetailsSectionRow.js

    r206363 r206406  
    4444    set nodeStyles(nodeStyles)
    4545    {
     46        if (this._nodeStyles && this._nodeStyles.computedStyle)
     47            this._nodeStyles.computedStyle.removeEventListener(WebInspector.CSSStyleDeclaration.Event.PropertiesChanged, this._refresh, this);
     48
    4649        this._nodeStyles = nodeStyles;
     50        if (this._nodeStyles && this._nodeStyles.computedStyle)
     51            this._nodeStyles.computedStyle.addEventListener(WebInspector.CSSStyleDeclaration.Event.PropertiesChanged, this._refresh, this);
    4752
    4853        this._refresh();
     
    6873    _getBox(computedStyle, componentName)
    6974    {
    70         var suffix = componentName === "border" ? "-width" : "";
     75        var suffix = this._getComponentSuffix(componentName);
    7176        var left = this._getPropertyValueAsPx(computedStyle, componentName + "-left" + suffix);
    7277        var top = this._getPropertyValueAsPx(computedStyle, componentName + "-top" + suffix);
     
    7479        var bottom = this._getPropertyValueAsPx(computedStyle, componentName + "-bottom" + suffix);
    7580        return {left, top, right, bottom};
     81    }
     82
     83    _getComponentSuffix(componentName)
     84    {
     85        return componentName === "border" ? "-width" : "";
    7686    }
    7787
     
    104114    _updateMetrics()
    105115    {
    106         // Updating with computed style.
    107116        var metricsElement = document.createElement("div");
    108 
    109         var self = this;
    110117        var style = this._nodeStyles.computedStyle;
    111118
    112         function createElement(type, value, name, propertyName, style)
     119        function createValueElement(type, value, name, propertyName)
    113120        {
    114121            // Check if the value is a float and whether it should be rounded.
     
    127134        }
    128135
    129         function createBoxPartElement(style, name, side, suffix)
     136        function createBoxPartElement(name, side)
    130137        {
     138            let suffix = this._getComponentSuffix(name);
    131139            let propertyName = (name !== "position" ? name + "-" : "") + side + suffix;
    132140            let value = style.propertyForName(propertyName).value;
     
    136144                value = value.replace(/px$/, "");
    137145
    138             let element = createElement.call(this, "div", value, name, propertyName, style);
     146            let element = createValueElement.call(this, "div", value, name, propertyName);
    139147            element.className = side;
    140148            return element;
    141149        }
    142150
    143         function createContentAreaWidthElement(style)
     151        function createContentAreaElement(name)
    144152        {
    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$/, "");
    146156            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);
    167165        }
    168166
     
    194192
    195193        this._boxElements = [];
    196         var boxes = ["content", "padding", "border", "margin", "position"];
    197194
    198195        if (!style.hasProperties()) {
     
    202199
    203200        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"]) {
    207202            if (name === "margin" && noMarginDisplayType[style.propertyForName("display").value])
    208203                continue;
     
    219214
    220215            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");
    223218                boxElement.append(widthElement, " \u00D7 ", heightElement);
    224219            } else {
    225                 var suffix = name === "border" ? "-width" : "";
    226 
    227220                var labelElement = document.createElement("div");
    228221                labelElement.className = "label";
    229                 labelElement.textContent = boxes[i];
     222                labelElement.textContent = name;
    230223                boxElement.appendChild(labelElement);
    231224
    232                 boxElement.appendChild(createBoxPartElement.call(this, style, name, "top", suffix));
     225                boxElement.appendChild(createBoxPartElement.call(this, name, "top"));
    233226                boxElement.appendChild(document.createElement("br"));
    234                 boxElement.appendChild(createBoxPartElement.call(this, style, name, "left", suffix));
     227                boxElement.appendChild(createBoxPartElement.call(this, name, "left"));
    235228
    236229                if (previousBox)
    237230                    boxElement.appendChild(previousBox);
    238231
    239                 boxElement.appendChild(createBoxPartElement.call(this, style, name, "right", suffix));
     232                boxElement.appendChild(createBoxPartElement.call(this, name, "right"));
    240233                boxElement.appendChild(document.createElement("br"));
    241                 boxElement.appendChild(createBoxPartElement.call(this, style, name, "bottom", suffix));
     234                boxElement.appendChild(createBoxPartElement.call(this, name, "bottom"));
    242235            }
    243236
Note: See TracChangeset for help on using the changeset viewer.