<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[206406] trunk/Source/WebInspectorUI</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/206406">206406</a></dd>
<dt>Author</dt> <dd>mattbaker@apple.com</dd>
<dt>Date</dt> <dd>2016-09-26 17:06:55 -0700 (Mon, 26 Sep 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>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).</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebInspectorUIChangeLog">trunk/Source/WebInspectorUI/ChangeLog</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceViewsBoxModelDetailsSectionRowjs">trunk/Source/WebInspectorUI/UserInterface/Views/BoxModelDetailsSectionRow.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebInspectorUIChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/ChangeLog (206405 => 206406)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/ChangeLog        2016-09-26 23:56:37 UTC (rev 206405)
+++ trunk/Source/WebInspectorUI/ChangeLog        2016-09-27 00:06:55 UTC (rev 206406)
</span><span class="lines">@@ -1 +1,29 @@
</span><ins>+2016-09-26  Matt Baker  &lt;mattbaker@apple.com&gt;
+
+        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).
+
</ins><span class="cx"> == Rolled over to ChangeLog-2016-09-26 ==
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceViewsBoxModelDetailsSectionRowjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Views/BoxModelDetailsSectionRow.js (206405 => 206406)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/UserInterface/Views/BoxModelDetailsSectionRow.js        2016-09-26 23:56:37 UTC (rev 206405)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/BoxModelDetailsSectionRow.js        2016-09-27 00:06:55 UTC (rev 206406)
</span><span class="lines">@@ -43,7 +43,12 @@
</span><span class="cx"> 
</span><span class="cx">     set nodeStyles(nodeStyles)
</span><span class="cx">     {
</span><ins>+        if (this._nodeStyles &amp;&amp; this._nodeStyles.computedStyle)
+            this._nodeStyles.computedStyle.removeEventListener(WebInspector.CSSStyleDeclaration.Event.PropertiesChanged, this._refresh, this);
+
</ins><span class="cx">         this._nodeStyles = nodeStyles;
</span><ins>+        if (this._nodeStyles &amp;&amp; this._nodeStyles.computedStyle)
+            this._nodeStyles.computedStyle.addEventListener(WebInspector.CSSStyleDeclaration.Event.PropertiesChanged, this._refresh, this);
</ins><span class="cx"> 
</span><span class="cx">         this._refresh();
</span><span class="cx">     }
</span><span class="lines">@@ -67,7 +72,7 @@
</span><span class="cx"> 
</span><span class="cx">     _getBox(computedStyle, componentName)
</span><span class="cx">     {
</span><del>-        var suffix = componentName === &quot;border&quot; ? &quot;-width&quot; : &quot;&quot;;
</del><ins>+        var suffix = this._getComponentSuffix(componentName);
</ins><span class="cx">         var left = this._getPropertyValueAsPx(computedStyle, componentName + &quot;-left&quot; + suffix);
</span><span class="cx">         var top = this._getPropertyValueAsPx(computedStyle, componentName + &quot;-top&quot; + suffix);
</span><span class="cx">         var right = this._getPropertyValueAsPx(computedStyle, componentName + &quot;-right&quot; + suffix);
</span><span class="lines">@@ -75,6 +80,11 @@
</span><span class="cx">         return {left, top, right, bottom};
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    _getComponentSuffix(componentName)
+    {
+        return componentName === &quot;border&quot; ? &quot;-width&quot; : &quot;&quot;;
+    }
+
</ins><span class="cx">     _highlightDOMNode(showHighlight, mode, event)
</span><span class="cx">     {
</span><span class="cx">         event.stopPropagation();
</span><span class="lines">@@ -103,13 +113,10 @@
</span><span class="cx"> 
</span><span class="cx">     _updateMetrics()
</span><span class="cx">     {
</span><del>-        // Updating with computed style.
</del><span class="cx">         var metricsElement = document.createElement(&quot;div&quot;);
</span><del>-
-        var self = this;
</del><span class="cx">         var style = this._nodeStyles.computedStyle;
</span><span class="cx"> 
</span><del>-        function createElement(type, value, name, propertyName, style)
</del><ins>+        function createValueElement(type, value, name, propertyName)
</ins><span class="cx">         {
</span><span class="cx">             // Check if the value is a float and whether it should be rounded.
</span><span class="cx">             let floatValue = parseFloat(value);
</span><span class="lines">@@ -126,8 +133,9 @@
</span><span class="cx">             return element;
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        function createBoxPartElement(style, name, side, suffix)
</del><ins>+        function createBoxPartElement(name, side)
</ins><span class="cx">         {
</span><ins>+            let suffix = this._getComponentSuffix(name);
</ins><span class="cx">             let propertyName = (name !== &quot;position&quot; ? name + &quot;-&quot; : &quot;&quot;) + side + suffix;
</span><span class="cx">             let value = style.propertyForName(propertyName).value;
</span><span class="cx">             if (value === &quot;&quot; || (name !== &quot;position&quot; &amp;&amp; value === &quot;0px&quot;) || (name === &quot;position&quot; &amp;&amp; value === &quot;auto&quot;))
</span><span class="lines">@@ -135,35 +143,25 @@
</span><span class="cx">             else
</span><span class="cx">                 value = value.replace(/px$/, &quot;&quot;);
</span><span class="cx"> 
</span><del>-            let element = createElement.call(this, &quot;div&quot;, value, name, propertyName, style);
</del><ins>+            let element = createValueElement.call(this, &quot;div&quot;, value, name, propertyName);
</ins><span class="cx">             element.className = side;
</span><span class="cx">             return element;
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        function createContentAreaWidthElement(style)
</del><ins>+        function createContentAreaElement(name)
</ins><span class="cx">         {
</span><del>-            var width = style.propertyForName(&quot;width&quot;).value.replace(/px$/, &quot;&quot;);
-            if (style.propertyForName(&quot;box-sizing&quot;).value === &quot;border-box&quot;) {
-                var borderBox = self._getBox(style, &quot;border&quot;);
-                var paddingBox = self._getBox(style, &quot;padding&quot;);
</del><ins>+            console.assert(name === &quot;width&quot; || name === &quot;height&quot;);
</ins><span class="cx"> 
</span><del>-                width = width - borderBox.left - borderBox.right - paddingBox.left - paddingBox.right;
-            }
-
-            return createElement.call(this, &quot;span&quot;, width, &quot;width&quot;, &quot;width&quot;, style);
-        }
-
-        function createContentAreaHeightElement(style)
-        {
-            var height = style.propertyForName(&quot;height&quot;).value.replace(/px$/, &quot;&quot;);
</del><ins>+            let size = style.propertyForName(name).value.replace(/px$/, &quot;&quot;);
</ins><span class="cx">             if (style.propertyForName(&quot;box-sizing&quot;).value === &quot;border-box&quot;) {
</span><del>-                var borderBox = self._getBox(style, &quot;border&quot;);
-                var paddingBox = self._getBox(style, &quot;padding&quot;);
</del><ins>+                let borderBox = this._getBox(style, &quot;border&quot;);
+                let paddingBox = this._getBox(style, &quot;padding&quot;);
</ins><span class="cx"> 
</span><del>-                height = height - borderBox.top - borderBox.bottom - paddingBox.top - paddingBox.bottom;
</del><ins>+                let [side, oppositeSide] = name === &quot;width&quot; ? [&quot;left&quot;, &quot;right&quot;] : [&quot;top&quot;, &quot;bottom&quot;];
+                size = size - borderBox[side] - borderBox[oppositeSide] - paddingBox[side] - paddingBox[oppositeSide];
</ins><span class="cx">             }
</span><span class="cx"> 
</span><del>-            return createElement.call(this, &quot;span&quot;, height, &quot;height&quot;, &quot;height&quot;, style);
</del><ins>+            return createValueElement.call(this, &quot;span&quot;, size, name, name);
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         // Display types for which margin is ignored.
</span><span class="lines">@@ -193,7 +191,6 @@
</span><span class="cx">         };
</span><span class="cx"> 
</span><span class="cx">         this._boxElements = [];
</span><del>-        var boxes = [&quot;content&quot;, &quot;padding&quot;, &quot;border&quot;, &quot;margin&quot;, &quot;position&quot;];
</del><span class="cx"> 
</span><span class="cx">         if (!style.hasProperties()) {
</span><span class="cx">             this.showEmptyMessage();
</span><span class="lines">@@ -201,9 +198,7 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         var previousBox = null;
</span><del>-        for (var i = 0; i &lt; boxes.length; ++i) {
-            var name = boxes[i];
-
</del><ins>+        for (let name of [&quot;content&quot;, &quot;padding&quot;, &quot;border&quot;, &quot;margin&quot;, &quot;position&quot;]) {
</ins><span class="cx">             if (name === &quot;margin&quot; &amp;&amp; noMarginDisplayType[style.propertyForName(&quot;display&quot;).value])
</span><span class="cx">                 continue;
</span><span class="cx">             if (name === &quot;padding&quot; &amp;&amp; noPaddingDisplayType[style.propertyForName(&quot;display&quot;).value])
</span><span class="lines">@@ -218,27 +213,25 @@
</span><span class="cx">             this._boxElements.push(boxElement);
</span><span class="cx"> 
</span><span class="cx">             if (name === &quot;content&quot;) {
</span><del>-                var widthElement = createContentAreaWidthElement.call(this, style);
-                var heightElement = createContentAreaHeightElement.call(this, style);
</del><ins>+                let widthElement = createContentAreaElement.call(this, &quot;width&quot;);
+                let heightElement = createContentAreaElement.call(this, &quot;height&quot;);
</ins><span class="cx">                 boxElement.append(widthElement, &quot; \u00D7 &quot;, heightElement);
</span><span class="cx">             } else {
</span><del>-                var suffix = name === &quot;border&quot; ? &quot;-width&quot; : &quot;&quot;;
-
</del><span class="cx">                 var labelElement = document.createElement(&quot;div&quot;);
</span><span class="cx">                 labelElement.className = &quot;label&quot;;
</span><del>-                labelElement.textContent = boxes[i];
</del><ins>+                labelElement.textContent = name;
</ins><span class="cx">                 boxElement.appendChild(labelElement);
</span><span class="cx"> 
</span><del>-                boxElement.appendChild(createBoxPartElement.call(this, style, name, &quot;top&quot;, suffix));
</del><ins>+                boxElement.appendChild(createBoxPartElement.call(this, name, &quot;top&quot;));
</ins><span class="cx">                 boxElement.appendChild(document.createElement(&quot;br&quot;));
</span><del>-                boxElement.appendChild(createBoxPartElement.call(this, style, name, &quot;left&quot;, suffix));
</del><ins>+                boxElement.appendChild(createBoxPartElement.call(this, name, &quot;left&quot;));
</ins><span class="cx"> 
</span><span class="cx">                 if (previousBox)
</span><span class="cx">                     boxElement.appendChild(previousBox);
</span><span class="cx"> 
</span><del>-                boxElement.appendChild(createBoxPartElement.call(this, style, name, &quot;right&quot;, suffix));
</del><ins>+                boxElement.appendChild(createBoxPartElement.call(this, name, &quot;right&quot;));
</ins><span class="cx">                 boxElement.appendChild(document.createElement(&quot;br&quot;));
</span><del>-                boxElement.appendChild(createBoxPartElement.call(this, style, name, &quot;bottom&quot;, suffix));
</del><ins>+                boxElement.appendChild(createBoxPartElement.call(this, name, &quot;bottom&quot;));
</ins><span class="cx">             }
</span><span class="cx"> 
</span><span class="cx">             previousBox = boxElement;
</span></span></pre>
</div>
</div>

</body>
</html>