Title: [134199] trunk
Revision
134199
Author
[email protected]
Date
2012-11-12 02:13:35 -0800 (Mon, 12 Nov 2012)

Log Message

Web Inspector: wasShown is called twice when show() is called from within wasShown
https://bugs.webkit.org/show_bug.cgi?id=101858

Reviewed by Vsevolod Vlasov.

Source/WebCore:

When we attach views lazily from within wasShown, the views were getting wasShown notification twice.
We now mute one of them.

* inspector/front-end/View.js:
(WebInspector.View):
(WebInspector.View.prototype._inNotification):
(WebInspector.View.prototype._parentIsShowing):
(WebInspector.View.prototype._callOnVisibleChildren):
(WebInspector.View.prototype._processWasShown):
(WebInspector.View.prototype._processWillHide):
(WebInspector.View.prototype._processOnResize):
(WebInspector.View.prototype._notify):
(WebInspector.View.prototype.show):

LayoutTests:

* inspector/view-events-expected.txt:
* inspector/view-events.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (134198 => 134199)


--- trunk/LayoutTests/ChangeLog	2012-11-12 09:34:05 UTC (rev 134198)
+++ trunk/LayoutTests/ChangeLog	2012-11-12 10:13:35 UTC (rev 134199)
@@ -1,3 +1,13 @@
+2012-11-12  Pavel Feldman  <[email protected]>
+
+        Web Inspector: wasShown is called twice when show() is called from within wasShown
+        https://bugs.webkit.org/show_bug.cgi?id=101858
+
+        Reviewed by Vsevolod Vlasov.
+
+        * inspector/view-events-expected.txt:
+        * inspector/view-events.html:
+
 2012-11-12  Mihnea Ovidenie  <[email protected]>
 
         [CSSRegions] region-style-inline-background-color.html failing on MountainLion/Chromium

Modified: trunk/LayoutTests/inspector/view-events-expected.txt (134198 => 134199)


--- trunk/LayoutTests/inspector/view-events-expected.txt	2012-11-12 09:34:05 UTC (rev 134198)
+++ trunk/LayoutTests/inspector/view-events-expected.txt	2012-11-12 10:13:35 UTC (rev 134199)
@@ -139,3 +139,55 @@
 Child.show()
 Error: Attempt to remove element containing view via regular DOM operation
 
+Running: testShowOnWasShown
+Parent()
+Child()
+Parent.show()
+  Parent.wasShown()
+Child.show()
+  Parent.onResize()
+  Child.wasShown()
+  Child.onResize()
+Parent.detach()
+  Child.willHide()
+  Parent.willHide()
+
+Running: testDetachOnWasShown
+Parent()
+Child()
+Child.show()
+Parent.show()
+  Parent.wasShown()
+Child.detach()
+  Parent.onResize()
+Parent.detach()
+  Parent.willHide()
+
+Running: testShowOnWillHide
+Parent()
+Child()
+Parent.show()
+  Parent.wasShown()
+  Parent.onResize()
+Child.show()
+  Child.wasShown()
+  Child.onResize()
+Parent.detach()
+  Child.willHide()
+  Parent.willHide()
+Child.show()
+
+Running: testDetachOnWillHide
+Parent()
+Child()
+Parent.show()
+  Parent.wasShown()
+  Parent.onResize()
+Child.show()
+  Child.wasShown()
+  Child.onResize()
+Parent.detach()
+  Child.willHide()
+  Parent.willHide()
+Child.detach()
+

Modified: trunk/LayoutTests/inspector/view-events.html (134198 => 134199)


--- trunk/LayoutTests/inspector/view-events.html	2012-11-12 09:34:05 UTC (rev 134198)
+++ trunk/LayoutTests/inspector/view-events.html	2012-11-12 10:13:35 UTC (rev 134199)
@@ -35,11 +35,19 @@
         wasShown: function()
         {
             InspectorTest.addResult("  " + this._viewName + ".wasShown()");
+            if (this.showOnWasShown)
+                this.showOnWasShown.show(this.element);
+            if (this.detachOnWasShown)
+                this.detachOnWasShown.detach();
         },
 
         willHide: function()
         {
             InspectorTest.addResult("  " + this._viewName + ".willHide()");
+            if (this.showOnWillHide)
+                this.showOnWillHide.show(this.element);
+            if (this.detachOnWillHide)
+                this.detachOnWillHide.detach();
         },
 
         onResize: function()
@@ -237,6 +245,48 @@
                 InspectorTest.addResult(e);
             }
             next();
+        },
+
+        function testShowOnWasShown(next)
+        {
+            var parentView = new TestView("Parent");
+            parentView.showOnWasShown = new TestView("Child");
+            parentView.show(WebInspector.inspectorView.element);
+            parentView.detach();
+            next();
+        },
+
+        function testDetachOnWasShown(next)
+        {
+            var parentView = new TestView("Parent");
+            var childView = new TestView("Child");
+            childView.show(parentView.element);
+            parentView.detachOnWasShown = childView;
+            parentView.show(WebInspector.inspectorView.element);
+            parentView.detach();
+            next();
+        },
+
+        function testShowOnWillHide(next)
+        {
+            var parentView = new TestView("Parent");
+            var childView = new TestView("Child");
+            parentView.show(WebInspector.inspectorView.element);
+            childView.show(parentView.element);
+            parentView.showOnWillHide = childView;
+            parentView.detach();
+            next();
+        },
+
+        function testDetachOnWillHide(next)
+        {
+            var parentView = new TestView("Parent");
+            var childView = new TestView("Child");
+            parentView.show(WebInspector.inspectorView.element);
+            childView.show(parentView.element);
+            parentView.detachOnWillHide = childView;
+            parentView.detach();
+            next();
         }
     ]);
 }

Modified: trunk/Source/WebCore/ChangeLog (134198 => 134199)


--- trunk/Source/WebCore/ChangeLog	2012-11-12 09:34:05 UTC (rev 134198)
+++ trunk/Source/WebCore/ChangeLog	2012-11-12 10:13:35 UTC (rev 134199)
@@ -1,3 +1,24 @@
+2012-11-12  Pavel Feldman  <[email protected]>
+
+        Web Inspector: wasShown is called twice when show() is called from within wasShown
+        https://bugs.webkit.org/show_bug.cgi?id=101858
+
+        Reviewed by Vsevolod Vlasov.
+
+        When we attach views lazily from within wasShown, the views were getting wasShown notification twice.
+        We now mute one of them.
+
+        * inspector/front-end/View.js:
+        (WebInspector.View):
+        (WebInspector.View.prototype._inNotification):
+        (WebInspector.View.prototype._parentIsShowing):
+        (WebInspector.View.prototype._callOnVisibleChildren):
+        (WebInspector.View.prototype._processWasShown):
+        (WebInspector.View.prototype._processWillHide):
+        (WebInspector.View.prototype._processOnResize):
+        (WebInspector.View.prototype._notify):
+        (WebInspector.View.prototype.show):
+
 2012-11-12  Ryosuke Niwa  <[email protected]>
 
         Build fix after r134191. Turns out that FrameView::performPostLayoutTasks calls FrameSelection::updateAppearance

Modified: trunk/Source/WebCore/inspector/front-end/View.js (134198 => 134199)


--- trunk/Source/WebCore/inspector/front-end/View.js	2012-11-12 09:34:05 UTC (rev 134198)
+++ trunk/Source/WebCore/inspector/front-end/View.js	2012-11-12 10:13:35 UTC (rev 134199)
@@ -38,6 +38,7 @@
     this._children = [];
     this._hideOnDetach = false;
     this._cssFiles = [];
+    this._notificationDepth = 0;
 }
 
 WebInspector.View._cssFileToVisibleViewCount = {};
@@ -59,16 +60,31 @@
         this._hideOnDetach = true;
     },
 
+    /**
+     * @return {boolean} 
+     */
+    _inNotification: function()
+    {
+        return !!this._notificationDepth || (this._parentView && this._parentView._inNotification());
+    },
+
     _parentIsShowing: function()
     {
-        return this._isRoot || (this._parentView && this._parentView.isShowing());
+        if (this._isRoot)
+            return true;
+        return this._parentView && this._parentView.isShowing();
     },
 
+    /**
+     * @param {function(this:WebInspector.View)} method
+     */
     _callOnVisibleChildren: function(method)
     {
-        for (var i = 0; i < this._children.length; ++i)
-            if (this._children[i]._visible)
-                method.call(this._children[i]);
+        var copy = this._children.slice();
+        for (var i = 0; i < copy.length; ++i) {
+            if (copy[i]._parentView === this && copy[i]._visible)
+                method.call(copy[i]);
+        }
     },
 
     _processWillShow: function()
@@ -79,22 +95,23 @@
 
     _processWasShown: function()
     {
+        if (this._inNotification())
+            return;
         this._isShowing = true;
         this.restoreScrollPositions();
-
-        this.wasShown();
-        this.onResize();
-
+        this._notify(this.wasShown);
+        this._notify(this.onResize);
         this._callOnVisibleChildren(this._processWasShown);
     },
 
     _processWillHide: function()
     {
+        if (this._inNotification())
+            return;
         this.storeScrollPositions();
 
         this._callOnVisibleChildren(this._processWillHide);
-
-        this.willHide();
+        this._notify(this.willHide);
         this._isShowing = false;
     },
 
@@ -106,13 +123,27 @@
 
     _processOnResize: function()
     {
+        if (this._inNotification())
+            return;
         if (!this.isShowing())
             return;
-
-        this.onResize();
+        this._notify(this.onResize);
         this._callOnVisibleChildren(this._processOnResize);
     },
 
+    /**
+     * @param {function(this:WebInspector.View)} notification
+     */
+    _notify: function(notification)
+    {
+        ++this._notificationDepth;
+        try {
+            notification.call(this);
+        } finally {
+            --this._notificationDepth;
+        }
+    },
+
     wasShown: function()
     {
     },
@@ -149,6 +180,7 @@
             return;
 
         this._visible = true;
+
         if (this._parentIsShowing())
             this._processWillShow();
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to