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

Unified Diff: third_party/WebKit/Source/devtools/front_end/elements/ComputedStyleModel.js

Issue 2146233002: DevTools: reuse computedstylesmodel in the elements sidebar base class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: (2) 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/elements/ComputedStyleModel.js
diff --git a/third_party/WebKit/Source/devtools/front_end/elements/ComputedStyleModel.js b/third_party/WebKit/Source/devtools/front_end/elements/ComputedStyleModel.js
index 6c67b5ba1fda842e1256c259e3e23b41d09f3558..022fe4ca607697f1ad77ae3c2f30987aa05485c1 100644
--- a/third_party/WebKit/Source/devtools/front_end/elements/ComputedStyleModel.js
+++ b/third_party/WebKit/Source/devtools/front_end/elements/ComputedStyleModel.js
@@ -31,7 +31,7 @@ WebInspector.ComputedStyleModel.prototype = {
*/
cssModel: function()
{
- return this._cssModel;
+ return this._cssModel && this._cssModel.isEnabled() ? this._cssModel : null;
},
/**
@@ -41,7 +41,7 @@ WebInspector.ComputedStyleModel.prototype = {
{
this._node = /** @type {?WebInspector.DOMNode} */(event.data);
this._updateTarget(this._node ? this._node.target() : null);
- this._onComputedStyleChanged();
+ this._onComputedStyleChanged(null);
},
/**
@@ -56,25 +56,70 @@ WebInspector.ComputedStyleModel.prototype = {
this._targetEvents = null;
}
this._target = target;
+
var domModel = null;
+ var resourceTreeModel = null;
if (target) {
this._cssModel = WebInspector.CSSModel.fromTarget(target);
domModel = WebInspector.DOMModel.fromTarget(target);
+ resourceTreeModel = target.resourceTreeModel;
}
- if (domModel && this._cssModel) {
+ if (this._cssModel && domModel && resourceTreeModel) {
this._targetEvents = [
- this._cssModel.addEventListener(WebInspector.CSSModel.Events.StyleSheetAdded, this._onComputedStyleChanged, this),
- this._cssModel.addEventListener(WebInspector.CSSModel.Events.StyleSheetRemoved, this._onComputedStyleChanged, this),
- this._cssModel.addEventListener(WebInspector.CSSModel.Events.StyleSheetChanged, this._onComputedStyleChanged, this),
- this._cssModel.addEventListener(WebInspector.CSSModel.Events.MediaQueryResultChanged, this._onComputedStyleChanged, this),
- this._cssModel.addEventListener(WebInspector.CSSModel.Events.PseudoStateForced, this._onComputedStyleChanged, this),
- this._cssModel.addEventListener(WebInspector.CSSModel.Events.ModelWasEnabled, this._onComputedStyleChanged, this),
- domModel.addEventListener(WebInspector.DOMModel.Events.DOMMutated, this._onComputedStyleChanged, this)
+ this._cssModel.addEventListener(WebInspector.CSSModel.Events.StyleSheetAdded, this._onComputedStyleChanged, this),
+ this._cssModel.addEventListener(WebInspector.CSSModel.Events.StyleSheetRemoved, this._onComputedStyleChanged, this),
+ this._cssModel.addEventListener(WebInspector.CSSModel.Events.StyleSheetChanged, this._onComputedStyleChanged, this),
+ this._cssModel.addEventListener(WebInspector.CSSModel.Events.MediaQueryResultChanged, this._onComputedStyleChanged, this),
+ this._cssModel.addEventListener(WebInspector.CSSModel.Events.PseudoStateForced, this._onComputedStyleChanged, this),
+ this._cssModel.addEventListener(WebInspector.CSSModel.Events.ModelWasEnabled, this._onComputedStyleChanged, this),
+ domModel.addEventListener(WebInspector.DOMModel.Events.DOMMutated, this._onDOMModelChanged, this),
+ resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.FrameResized, this._onFrameResized, this),
];
}
},
+ /**
+ * @param {?WebInspector.Event} event
+ */
+ _onComputedStyleChanged: function(event)
+ {
+ delete this._computedStylePromise;
+ this.dispatchEventToListeners(WebInspector.ComputedStyleModel.Events.ComputedStyleChanged, event ? event.data : null);
+ },
+
+ /**
+ * @param {!WebInspector.Event} event
+ */
+ _onDOMModelChanged: function(event)
+ {
+ // Any attribute removal or modification can affect the styles of "related" nodes.
+ var node = /** @type {!WebInspector.DOMNode} */ (event.data);
+ if (!this._node || this._node !== node && node.parentNode !== this._node.parentNode && !node.isAncestor(this._node))
+ return;
+ this._onComputedStyleChanged(null);
+ },
+
+ /**
+ * @param {!WebInspector.Event} event
+ */
+ _onFrameResized: function(event)
+ {
+ /**
+ * @this {WebInspector.ComputedStyleModel}
+ */
+ function refreshContents()
+ {
+ this._onComputedStyleChanged(null);
+ delete this._frameResizedTimer;
+ }
+
+ if (this._frameResizedTimer)
+ clearTimeout(this._frameResizedTimer);
+
+ this._frameResizedTimer = setTimeout(refreshContents.bind(this), 100);
+ },
+
/**
* @return {?WebInspector.DOMNode}
*/
@@ -110,12 +155,6 @@ WebInspector.ComputedStyleModel.prototype = {
}
},
- _onComputedStyleChanged: function()
- {
- delete this._computedStylePromise;
- this.dispatchEventToListeners(WebInspector.ComputedStyleModel.Events.ComputedStyleChanged);
- },
-
__proto__: WebInspector.Object.prototype
}

Powered by Google App Engine
This is Rietveld 408576698