Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(464)

Unified Diff: third_party/WebKit/Source/devtools/front_end/ui/Widget.js

Issue 2157363006: DevTools: keep widgets in widget hierarchy upon hide, split attach/detach cycle from show/hide. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: lcean Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/front_end/ui/Widget.js
diff --git a/third_party/WebKit/Source/devtools/front_end/ui/Widget.js b/third_party/WebKit/Source/devtools/front_end/ui/Widget.js
index 5558f589144f8b9e4e97f525bef41f9e0d87a232..cf6f9ceb3112efef51f10279026a7e855bee6ea4 100644
--- a/third_party/WebKit/Source/devtools/front_end/ui/Widget.js
+++ b/third_party/WebKit/Source/devtools/front_end/ui/Widget.js
@@ -41,12 +41,13 @@ WebInspector.Widget = function(isWebComponent)
}
this._isWebComponent = isWebComponent;
this.element.__widget = this;
- this._visible = true;
+ this._visible = false;
this._isRoot = false;
this._isShowing = false;
this._children = [];
this._hideOnDetach = false;
this._notificationDepth = 0;
+ this._invalidationsSuspended = 0;
}
WebInspector.Widget.prototype = {
@@ -119,7 +120,7 @@ WebInspector.Widget.prototype = {
{
if (this._isRoot)
return true;
- return this._parentWidget && this._parentWidget.isShowing();
+ return !!this._parentWidget && this._parentWidget.isShowing();
},
/**
@@ -205,32 +206,53 @@ WebInspector.Widget.prototype = {
},
/**
- * @param {?Element} parentElement
+ * @param {!Element} parentElement
* @param {?Element=} insertBefore
*/
show: function(parentElement, insertBefore)
{
+ this.attach(parentElement, insertBefore);
+ this.showWidget();
+ },
+
+ /**
+ * @param {!Element} parentElement
+ * @param {?Element=} insertBefore
+ */
+ attach: function(parentElement, insertBefore)
+ {
WebInspector.Widget.__assert(parentElement, "Attempt to attach widget with no parent element");
// Update widget hierarchy.
- if (this.element.parentElement !== parentElement) {
- if (this.element.parentElement)
- this.detach();
-
- var currentParent = parentElement;
- while (currentParent && !currentParent.__widget)
- currentParent = currentParent.parentElementOrShadowHost();
+ var currentParent = parentElement;
+ while (currentParent && !currentParent.__widget)
+ currentParent = currentParent.parentElementOrShadowHost();
+ var newParentWidget = currentParent ? currentParent.__widget : null;
+
+ if (this._parentWidget && newParentWidget !== this._parentWidget) {
+ // Reparent.
+ this.detach();
+ }
- if (currentParent) {
- this._parentWidget = currentParent.__widget;
+ if (newParentWidget) {
+ if (this._parentWidget !== newParentWidget) {
+ this._parentWidget = newParentWidget;
this._parentWidget._children.push(this);
- this._isRoot = false;
- } else
- WebInspector.Widget.__assert(this._isRoot, "Attempt to attach widget to orphan node");
- } else if (this._visible) {
- return;
+ }
+ this._isRoot = false;
+ } else {
+ WebInspector.Widget.__assert(this._isRoot, "Attempt to attach widget to orphan node");
}
+ this._parentElement = parentElement;
+ this._insertBeforeElement = insertBefore;
+ },
+
+ showWidget: function()
+ {
+ WebInspector.Widget.__assert(this._parentElement, "Attempt to show detached widget");
+ if (this._visible)
+ return;
this._visible = true;
if (this._parentIsShowing())
@@ -239,12 +261,12 @@ WebInspector.Widget.prototype = {
this.element.classList.remove("hidden");
// Reparent
- if (this.element.parentElement !== parentElement) {
- WebInspector.Widget._incrementWidgetCounter(parentElement, this.element);
- if (insertBefore)
- WebInspector.Widget._originalInsertBefore.call(parentElement, this.element, insertBefore);
+ if (this.element.parentElement !== this._parentElement) {
+ WebInspector.Widget._incrementWidgetCounter(this._parentElement, this.element);
+ if (this._insertBeforeElement)
+ WebInspector.Widget._originalInsertBefore.call(this._parentElement, this.element, this._insertBeforeElement);
else
- WebInspector.Widget._originalAppendChild.call(parentElement, this.element);
+ WebInspector.Widget._originalAppendChild.call(this._parentElement, this.element);
}
if (this._parentIsShowing())
@@ -256,35 +278,48 @@ WebInspector.Widget.prototype = {
this._processOnResize();
},
+ hideWidget: function()
+ {
+ if (!this._parentWidget)
+ return;
+ this._hideWidget();
+ },
+
/**
* @param {boolean=} overrideHideOnDetach
*/
- detach: function(overrideHideOnDetach)
+ _hideWidget: function(overrideHideOnDetach)
{
- var parentElement = this.element.parentElement;
- if (!parentElement)
+ WebInspector.Widget.__assert(this._parentElement, "Attempt to hide detached widget");
+ if (!this._visible)
return;
+ this._visible = false;
+ var parentElement = this._parentElement;
if (this._parentIsShowing())
this._processWillHide();
if (!overrideHideOnDetach && this.shouldHideOnDetach()) {
this.element.classList.add("hidden");
- this._visible = false;
- if (this._parentIsShowing())
- this._processWasHidden();
- if (this._parentWidget && this._hasNonZeroConstraints())
- this._parentWidget.invalidateConstraints();
- return;
+ } else {
+ // Force legal removal
+ WebInspector.Widget._decrementWidgetCounter(parentElement, this.element);
+ WebInspector.Widget._originalRemoveChild.call(parentElement, this.element);
}
- // Force legal removal
- WebInspector.Widget._decrementWidgetCounter(parentElement, this.element);
- WebInspector.Widget._originalRemoveChild.call(parentElement, this.element);
-
- this._visible = false;
if (this._parentIsShowing())
this._processWasHidden();
+ if (this._hasNonZeroConstraints())
+ this._parentWidget.invalidateConstraints();
+ },
+
+ detach: function()
+ {
+ if (!this._parentWidget)
+ return;
+
+ if (this._visible)
+ this._hideWidget(true);
// Update widget hierarchy.
if (this._parentWidget) {
@@ -294,10 +329,11 @@ WebInspector.Widget.prototype = {
this._parentWidget.childWasDetached(this);
var parent = this._parentWidget;
this._parentWidget = null;
- if (this._hasNonZeroConstraints())
- parent.invalidateConstraints();
- } else
+ this._parentElement = null;
+ this._insertBeforeElement = null;
+ } else {
WebInspector.Widget.__assert(this._isRoot, "Removing non-root widget from DOM");
+ }
},
detachChildWidgets: function()
@@ -479,8 +515,25 @@ WebInspector.Widget.prototype = {
return !!(constraints.minimum.width || constraints.minimum.height || constraints.preferred.width || constraints.preferred.height);
},
+ suspendInvalidations()
+ {
+ ++this._invalidationsSuspended;
+ },
+
+ resumeInvalidations()
+ {
+ --this._invalidationsSuspended;
+ if (!this._invalidationsSuspended && this._invalidationsRequested)
+ this.invalidateConstraints();
+ },
+
invalidateConstraints: function()
{
+ if (this._invalidationsSuspended) {
+ this._invalidationsRequested = true;
+ return;
+ }
+ this._invalidationsRequested = false;
var cached = this._cachedConstraints;
delete this._cachedConstraints;
var actual = this.constraints();

Powered by Google App Engine
This is Rietveld 408576698