Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / devtools / front_end / View.js
index 0b45201..84168b5 100644 (file)
@@ -53,6 +53,11 @@ WebInspector.View.prototype = {
         this._isRoot = true;
     },
 
+    makeLayoutBoundary: function()
+    {
+        this._isLayoutBoundary = true;
+    },
+
     /**
      * @return {?WebInspector.View}
      */
@@ -145,6 +150,41 @@ WebInspector.View.prototype = {
         this._callOnVisibleChildren(this._processOnResize);
     },
 
+    _processDiscardCachedSize: function()
+    {
+        if (this._isLayoutBoundary) {
+            this.element.style.removeProperty("width");
+            this.element.style.removeProperty("height");
+        }
+        this._callOnVisibleChildren(this._processDiscardCachedSize);
+    },
+
+    _cacheSize: function()
+    {
+        this._prepareCacheSize();
+        this._applyCacheSize();
+    },
+
+    _prepareCacheSize: function()
+    {
+        if (this._isLayoutBoundary) {
+            this._cachedOffsetWidth = this.element.offsetWidth;
+            this._cachedOffsetHeight = this.element.offsetHeight;
+        }
+        this._callOnVisibleChildren(this._prepareCacheSize);
+    },
+
+    _applyCacheSize: function()
+    {
+        if (this._isLayoutBoundary) {
+            this.element.style.setProperty("width", this._cachedOffsetWidth + "px");
+            this.element.style.setProperty("height", this._cachedOffsetHeight + "px");
+            delete this._cachedOffsetWidth;
+            delete this._cachedOffsetHeight;
+        }
+        this._callOnVisibleChildren(this._applyCacheSize);
+    },
+
     /**
      * @param {function(this:WebInspector.View)} notification
      */
@@ -213,8 +253,10 @@ WebInspector.View.prototype = {
                 WebInspector.View._originalAppendChild.call(parentElement, this.element);
         }
 
-        if (this._parentIsShowing())
+        if (this._parentIsShowing()) {
             this._processWasShown();
+            this._cacheSize();
+        }
     },
 
     /**
@@ -226,8 +268,10 @@ WebInspector.View.prototype = {
         if (!parentElement)
             return;
 
-        if (this._parentIsShowing())
+        if (this._parentIsShowing()) {
+            this._processDiscardCachedSize();
             this._processWillHide();
+        }
 
         if (this._hideOnDetach && !overrideHideOnDetach) {
             this.element.classList.remove("visible");
@@ -310,7 +354,13 @@ WebInspector.View.prototype = {
 
     doResize: function()
     {
-        this._processOnResize();
+        if (!this.isShowing())
+            return;
+        this._processDiscardCachedSize();
+        // No matter what notification we are in, dispatching onResize is not needed.
+        if (!this._inNotification())
+            this._callOnVisibleChildren(this._processOnResize);
+        this._cacheSize();
     },
 
     registerRequiredCSS: function(cssFile)
@@ -514,13 +564,13 @@ WebInspector.ViewWithResizeCallback.prototype = {
 
 Element.prototype.appendChild = function(child)
 {
-    WebInspector.View._assert(!child.__view, "Attempt to add view via regular DOM operation.");
+    WebInspector.View._assert(!child.__view || child.parentElement === this, "Attempt to add view via regular DOM operation.");
     return WebInspector.View._originalAppendChild.call(this, child);
 }
 
 Element.prototype.insertBefore = function(child, anchor)
 {
-    WebInspector.View._assert(!child.__view, "Attempt to add view via regular DOM operation.");
+    WebInspector.View._assert(!child.__view || child.parentElement === this, "Attempt to add view via regular DOM operation.");
     return WebInspector.View._originalInsertBefore.call(this, child, anchor);
 }