<!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>[193872] 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/193872">193872</a></dd>
<dt>Author</dt> <dd>mattbaker@apple.com</dd>
<dt>Date</dt> <dd>2015-12-09 15:07:10 -0800 (Wed, 09 Dec 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>Web Inspector: when a marked-dirty subview is attached to a parent View, dirtyDescendantsCount gets out of sync
https://bugs.webkit.org/show_bug.cgi?id=151876
Reviewed by Brian Burg.
* UserInterface/Base/Main.js:
Use root view singleton instead of creating it explicitly.
* UserInterface/Views/View.js:
(WebInspector.View):
(WebInspector.View.rootView):
Singleton root view access. Lazily create and return a view backed
by the document's body element.
(WebInspector.View.prototype.isDescendantOf):
(WebInspector.View.prototype.insertSubviewBefore):
(WebInspector.View.prototype.removeSubview):
(WebInspector.View.prototype.didMoveToWindow):
Notify the view when it becomes, or is no longer, descended from the root view.
(WebInspector.View.prototype.didMoveToParent):
Notify the view when it's added to, or removed from, a parent view.
(WebInspector.View._scheduleLayoutForView):
(WebInspector.View._cancelScheduledLayoutForView):
(WebInspector.View.prototype.makeRootView): Deleted.
No longer needed.
(WebInspector.View.prototype.didAttach): Deleted.
(WebInspector.View.prototype.didDetach): Deleted.
Replaced by didMoveToParent.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebInspectorUIChangeLog">trunk/Source/WebInspectorUI/ChangeLog</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceBaseMainjs">trunk/Source/WebInspectorUI/UserInterface/Base/Main.js</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceViewsViewjs">trunk/Source/WebInspectorUI/UserInterface/Views/View.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebInspectorUIChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/ChangeLog (193871 => 193872)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/ChangeLog        2015-12-09 22:46:10 UTC (rev 193871)
+++ trunk/Source/WebInspectorUI/ChangeLog        2015-12-09 23:07:10 UTC (rev 193872)
</span><span class="lines">@@ -1,3 +1,33 @@
</span><ins>+2015-12-09 Matt Baker <mattbaker@apple.com>
+
+ Web Inspector: when a marked-dirty subview is attached to a parent View, dirtyDescendantsCount gets out of sync
+ https://bugs.webkit.org/show_bug.cgi?id=151876
+
+ Reviewed by Brian Burg.
+
+ * UserInterface/Base/Main.js:
+ Use root view singleton instead of creating it explicitly.
+
+ * UserInterface/Views/View.js:
+ (WebInspector.View):
+ (WebInspector.View.rootView):
+ Singleton root view access. Lazily create and return a view backed
+ by the document's body element.
+ (WebInspector.View.prototype.isDescendantOf):
+ (WebInspector.View.prototype.insertSubviewBefore):
+ (WebInspector.View.prototype.removeSubview):
+ (WebInspector.View.prototype.didMoveToWindow):
+ Notify the view when it becomes, or is no longer, descended from the root view.
+ (WebInspector.View.prototype.didMoveToParent):
+ Notify the view when it's added to, or removed from, a parent view.
+ (WebInspector.View._scheduleLayoutForView):
+ (WebInspector.View._cancelScheduledLayoutForView):
+ (WebInspector.View.prototype.makeRootView): Deleted.
+ No longer needed.
+ (WebInspector.View.prototype.didAttach): Deleted.
+ (WebInspector.View.prototype.didDetach): Deleted.
+ Replaced by didMoveToParent.
+
</ins><span class="cx"> 2015-12-09 Brian Burg <bburg@apple.com>
</span><span class="cx">
</span><span class="cx"> Web Inspector: control whether to collect and dump protocol messages using a WebInspector.Setting
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceBaseMainjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Base/Main.js (193871 => 193872)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/UserInterface/Base/Main.js        2015-12-09 22:46:10 UTC (rev 193871)
+++ trunk/Source/WebInspectorUI/UserInterface/Base/Main.js        2015-12-09 23:07:10 UTC (rev 193872)
</span><span class="lines">@@ -1438,7 +1438,7 @@
</span><span class="cx">
</span><span class="cx"> WebInspector._setupViewHierarchy = function()
</span><span class="cx"> {
</span><del>- let rootView = new WebInspector.View(document.body);
</del><ins>+ let rootView = WebInspector.View.rootView();
</ins><span class="cx"> rootView.addSubview(this.toolbar);
</span><span class="cx"> rootView.addSubview(this.tabBar);
</span><span class="cx"> rootView.addSubview(this.navigationSidebar);
</span><span class="lines">@@ -1446,8 +1446,6 @@
</span><span class="cx"> rootView.addSubview(this.splitContentBrowser);
</span><span class="cx"> rootView.addSubview(this.quickConsole);
</span><span class="cx"> rootView.addSubview(this.detailsSidebar);
</span><del>-
- rootView.makeRootView();
</del><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> WebInspector._tabBrowserSelectedTabContentViewDidChange = function(event)
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceViewsViewjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Views/View.js (193871 => 193872)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/UserInterface/Views/View.js        2015-12-09 22:46:10 UTC (rev 193871)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/View.js        2015-12-09 23:07:10 UTC (rev 193872)
</span><span class="lines">@@ -35,8 +35,20 @@
</span><span class="cx"> this._subviews = [];
</span><span class="cx"> this._dirty = false;
</span><span class="cx"> this._dirtyDescendantsCount = 0;
</span><ins>+ this._needsLayoutWhenAttachedToRoot = false;
+ this._isAttachedToRoot = false;
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+ // Static
+
+ static rootView()
+ {
+ if (!WebInspector.View._rootView)
+ WebInspector.View._rootView = new WebInspector.View(document.body);
+
+ return WebInspector.View._rootView;
+ }
+
</ins><span class="cx"> // Public
</span><span class="cx">
</span><span class="cx"> get element()
</span><span class="lines">@@ -59,14 +71,16 @@
</span><span class="cx"> return this._subviews;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- makeRootView()
</del><ins>+ isDescendantOf(view)
</ins><span class="cx"> {
</span><del>- console.assert(!WebInspector.View._rootView, "Root view already exists.");
- console.assert(!this._parentView, "Root view cannot be a subview.");
- if (WebInspector.View._rootView)
- return;
</del><ins>+ let parentView = this._parentView;
+ while (parentView) {
+ if (parentView === view)
+ return true;
+ parentView = parentView.parentView;
+ }
</ins><span class="cx">
</span><del>- WebInspector.View._rootView = this;
</del><ins>+ return false;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> addSubview(view)
</span><span class="lines">@@ -96,7 +110,7 @@
</span><span class="cx"> if (!view.element.parentNode)
</span><span class="cx"> this._element.insertBefore(view.element, referenceView ? referenceView.element : null);
</span><span class="cx">
</span><del>- view.didAttach(this);
</del><ins>+ view.didMoveToParent(this);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> removeSubview(view)
</span><span class="lines">@@ -111,7 +125,8 @@
</span><span class="cx">
</span><span class="cx"> this._subviews.remove(view, true);
</span><span class="cx"> this._element.removeChild(view.element);
</span><del>- view.didDetach();
</del><ins>+
+ view.didMoveToParent(null);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> replaceSubview(oldView, newView)
</span><span class="lines">@@ -146,16 +161,38 @@
</span><span class="cx">
</span><span class="cx"> // Protected
</span><span class="cx">
</span><del>- didAttach(parentView)
</del><ins>+ didMoveToWindow(isAttachedToRoot)
</ins><span class="cx"> {
</span><del>- console.assert(!this._parentView, "Attached view already has a parent.", this._parentView);
- this._parentView = parentView;
</del><ins>+ this._isAttachedToRoot = isAttachedToRoot;
+
+ if (this._isAttachedToRoot && this._needsLayoutWhenAttachedToRoot) {
+ WebInspector.View._scheduleLayoutForView(this);
+ this._needsLayoutWhenAttachedToRoot = false;
+ }
+
+ for (let view of this._subviews)
+ view.didMoveToWindow(isAttachedToRoot);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- didDetach()
</del><ins>+ didMoveToParent(parentView)
</ins><span class="cx"> {
</span><del>- console.assert(this._parentView, "Detached view has no parent.");
- this._parentView = null;
</del><ins>+ this._parentView = parentView;
+
+ let isAttachedToRoot = this.isDescendantOf(WebInspector.View._rootView);
+ this.didMoveToWindow(isAttachedToRoot);
+
+ if (!this._parentView)
+ return;
+
+ let pendingLayoutsCount = this._dirtyDescendantsCount;
+ if (this._dirty)
+ pendingLayoutsCount++;
+
+ let view = this._parentView;
+ while (view) {
+ view._dirtyDescendantsCount += pendingLayoutsCount;
+ view = view.parentView;
+ }
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> layout()
</span><span class="lines">@@ -178,17 +215,10 @@
</span><span class="cx"> view._layoutSubtree();
</span><span class="cx"> }
</span><span class="cx">
</span><del>- // Private layout controller logic
</del><ins>+ // Layout controller logic
</ins><span class="cx">
</span><span class="cx"> static _scheduleLayoutForView(view)
</span><span class="cx"> {
</span><del>- // Asynchronous layouts aren't scheduled until the root view has been set.
- // If the root view hasn't been set, switch to a synchronous layout.
- if (!WebInspector.View._rootView) {
- view._layoutSubtree();
- return;
- }
-
</del><span class="cx"> view._dirty = true;
</span><span class="cx">
</span><span class="cx"> let parentView = view.parentView;
</span><span class="lines">@@ -197,6 +227,13 @@
</span><span class="cx"> parentView = parentView.parentView;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ if (!view._isAttachedToRoot) {
+ // Don't schedule layout of the view unless it is a descendant of the root view.
+ // When it moves to a rooted view tree, schedule an initial layout.
+ view._needsLayoutWhenAttachedToRoot = true;
+ return;
+ }
+
</ins><span class="cx"> if (WebInspector.View._scheduledLayoutUpdateIdentifier)
</span><span class="cx"> return;
</span><span class="cx">
</span><span class="lines">@@ -205,23 +242,23 @@
</span><span class="cx">
</span><span class="cx"> static _cancelScheduledLayoutForView(view)
</span><span class="cx"> {
</span><del>- // Asynchronous layouts aren't scheduled until the root view has been set.
- if (!WebInspector.View._rootView)
- return;
</del><ins>+ let cancelledLayoutsCount = view._dirtyDescendantsCount;
+ if (view.layoutPending)
+ cancelledLayoutsCount++;
</ins><span class="cx">
</span><del>- let cancelledLayouts = view._dirtyDescendantsCount;
- if (this._dirty)
- cancelledLayouts++;
-
</del><span class="cx"> let parentView = view.parentView;
</span><span class="cx"> while (parentView) {
</span><del>- parentView._dirtyDescendantsCount = Math.max(0, parentView._dirtyDescendantsCount - cancelledLayouts);
</del><ins>+ parentView._dirtyDescendantsCount = Math.max(0, parentView._dirtyDescendantsCount - cancelledLayoutsCount);
</ins><span class="cx"> parentView = parentView.parentView;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- if (WebInspector.View._rootView._dirtyDescendantsCount || !WebInspector.View._scheduledLayoutUpdateIdentifier)
</del><ins>+ if (!WebInspector.View._scheduledLayoutUpdateIdentifier)
</ins><span class="cx"> return;
</span><span class="cx">
</span><ins>+ let rootView = WebInspector.View._rootView;
+ if (!rootView || rootView._dirtyDescendantsCount)
+ return;
+
</ins><span class="cx"> // No views need layout, so cancel the pending requestAnimationFrame.
</span><span class="cx"> cancelAnimationFrame(WebInspector.View._scheduledLayoutUpdateIdentifier);
</span><span class="cx"> WebInspector.View._scheduledLayoutUpdateIdentifier = undefined;
</span></span></pre>
</div>
</div>
</body>
</html>