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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @extends {WebInspector.Object} 6 * @extends {WebInspector.Object}
7 * @constructor 7 * @constructor
8 */ 8 */
9 WebInspector.ComputedStyleModel = function() 9 WebInspector.ComputedStyleModel = function()
10 { 10 {
(...skipping 13 matching lines...) Expand all
24 node: function() 24 node: function()
25 { 25 {
26 return this._node; 26 return this._node;
27 }, 27 },
28 28
29 /** 29 /**
30 * @return {?WebInspector.CSSModel} 30 * @return {?WebInspector.CSSModel}
31 */ 31 */
32 cssModel: function() 32 cssModel: function()
33 { 33 {
34 return this._cssModel; 34 return this._cssModel && this._cssModel.isEnabled() ? this._cssModel : n ull;
35 }, 35 },
36 36
37 /** 37 /**
38 * @param {!WebInspector.Event} event 38 * @param {!WebInspector.Event} event
39 */ 39 */
40 _onNodeChanged: function(event) 40 _onNodeChanged: function(event)
41 { 41 {
42 this._node = /** @type {?WebInspector.DOMNode} */(event.data); 42 this._node = /** @type {?WebInspector.DOMNode} */(event.data);
43 this._updateTarget(this._node ? this._node.target() : null); 43 this._updateTarget(this._node ? this._node.target() : null);
44 this._onComputedStyleChanged(); 44 this._onComputedStyleChanged(null);
45 }, 45 },
46 46
47 /** 47 /**
48 * @param {?WebInspector.Target} target 48 * @param {?WebInspector.Target} target
49 */ 49 */
50 _updateTarget: function(target) 50 _updateTarget: function(target)
51 { 51 {
52 if (this._target === target) 52 if (this._target === target)
53 return; 53 return;
54 if (this._targetEvents) { 54 if (this._targetEvents) {
55 WebInspector.EventTarget.removeEventListeners(this._targetEvents); 55 WebInspector.EventTarget.removeEventListeners(this._targetEvents);
56 this._targetEvents = null; 56 this._targetEvents = null;
57 } 57 }
58 this._target = target; 58 this._target = target;
59
59 var domModel = null; 60 var domModel = null;
61 var resourceTreeModel = null;
60 if (target) { 62 if (target) {
61 this._cssModel = WebInspector.CSSModel.fromTarget(target); 63 this._cssModel = WebInspector.CSSModel.fromTarget(target);
62 domModel = WebInspector.DOMModel.fromTarget(target); 64 domModel = WebInspector.DOMModel.fromTarget(target);
65 resourceTreeModel = target.resourceTreeModel;
63 } 66 }
64 67
65 if (domModel && this._cssModel) { 68 if (this._cssModel && domModel && resourceTreeModel) {
66 this._targetEvents = [ 69 this._targetEvents = [
67 this._cssModel.addEventListener(WebInspector.CSSModel.Events.Sty leSheetAdded, this._onComputedStyleChanged, this), 70 this._cssModel.addEventListener(WebInspector.CSSModel.Events.Sty leSheetAdded, this._onComputedStyleChanged, this),
68 this._cssModel.addEventListener(WebInspector.CSSModel.Events.Sty leSheetRemoved, this._onComputedStyleChanged, this), 71 this._cssModel.addEventListener(WebInspector.CSSModel.Events.Sty leSheetRemoved, this._onComputedStyleChanged, this),
69 this._cssModel.addEventListener(WebInspector.CSSModel.Events.Sty leSheetChanged, this._onComputedStyleChanged, this), 72 this._cssModel.addEventListener(WebInspector.CSSModel.Events.Sty leSheetChanged, this._onComputedStyleChanged, this),
70 this._cssModel.addEventListener(WebInspector.CSSModel.Events.Med iaQueryResultChanged, this._onComputedStyleChanged, this), 73 this._cssModel.addEventListener(WebInspector.CSSModel.Events.Med iaQueryResultChanged, this._onComputedStyleChanged, this),
71 this._cssModel.addEventListener(WebInspector.CSSModel.Events.Pse udoStateForced, this._onComputedStyleChanged, this), 74 this._cssModel.addEventListener(WebInspector.CSSModel.Events.Pse udoStateForced, this._onComputedStyleChanged, this),
72 this._cssModel.addEventListener(WebInspector.CSSModel.Events.Mod elWasEnabled, this._onComputedStyleChanged, this), 75 this._cssModel.addEventListener(WebInspector.CSSModel.Events.Mod elWasEnabled, this._onComputedStyleChanged, this),
73 domModel.addEventListener(WebInspector.DOMModel.Events.DOMMutate d, this._onComputedStyleChanged, this) 76 domModel.addEventListener(WebInspector.DOMModel.Events.DOMMutate d, this._onDOMModelChanged, this),
77 resourceTreeModel.addEventListener(WebInspector.ResourceTreeMode l.EventTypes.FrameResized, this._onFrameResized, this),
74 ]; 78 ];
75 } 79 }
76 }, 80 },
77 81
82 /**
83 * @param {?WebInspector.Event} event
84 */
85 _onComputedStyleChanged: function(event)
lushnikov 2016/07/14 00:58:14 nit: indent is off here (do you use eslint?)
pfeldman 2016/07/14 17:26:12 nope
86 {
87 delete this._computedStylePromise;
88 this.dispatchEventToListeners(WebInspector.ComputedStyleModel.Events.Com putedStyleChanged, event);
lushnikov 2016/07/14 00:58:15 event.data || null (This will save from writing u
pfeldman 2016/07/14 17:26:12 Done.
89 },
90
91 /**
92 * @param {!WebInspector.Event} event
93 */
94 _onDOMModelChanged: function(event)
95 {
96 // Any attribute removal or modification can affect the styles of "relat ed" nodes.
97 var node = /** @type {!WebInspector.DOMNode} */ (event.data);
98 if (!this._node || this._node !== node && node.parentNode !== this._node .parentNode && !node.isAncestor(this._node))
99 return;
100 this._onComputedStyleChanged(null);
101 },
102
103 /**
104 * @param {!WebInspector.Event} event
105 */
106 _onFrameResized: function(event)
107 {
108 /**
109 * @this {WebInspector.ComputedStyleModel}
110 */
111 function refreshContents()
112 {
113 this._onComputedStyleChanged(null);
114 delete this._frameResizedTimer;
115 }
116
117 if (this._frameResizedTimer)
118 clearTimeout(this._frameResizedTimer);
119
120 this._frameResizedTimer = setTimeout(refreshContents.bind(this), 100);
121 },
122
78 /** 123 /**
79 * @return {?WebInspector.DOMNode} 124 * @return {?WebInspector.DOMNode}
80 */ 125 */
81 _elementNode: function() 126 _elementNode: function()
82 { 127 {
83 return this.node() ? this.node().enclosingElementOrSelf() : null; 128 return this.node() ? this.node().enclosingElementOrSelf() : null;
84 }, 129 },
85 130
86 /** 131 /**
87 * @return {!Promise.<?WebInspector.ComputedStyleModel.ComputedStyle>} 132 * @return {!Promise.<?WebInspector.ComputedStyleModel.ComputedStyle>}
(...skipping 15 matching lines...) Expand all
103 * @param {?Map.<string, string>} style 148 * @param {?Map.<string, string>} style
104 * @return {?WebInspector.ComputedStyleModel.ComputedStyle} 149 * @return {?WebInspector.ComputedStyleModel.ComputedStyle}
105 * @this {WebInspector.ComputedStyleModel} 150 * @this {WebInspector.ComputedStyleModel}
106 */ 151 */
107 function verifyOutdated(elementNode, style) 152 function verifyOutdated(elementNode, style)
108 { 153 {
109 return elementNode === this._elementNode() && style ? new WebInspect or.ComputedStyleModel.ComputedStyle(elementNode, style) : /** @type {?WebInspect or.ComputedStyleModel.ComputedStyle} */(null); 154 return elementNode === this._elementNode() && style ? new WebInspect or.ComputedStyleModel.ComputedStyle(elementNode, style) : /** @type {?WebInspect or.ComputedStyleModel.ComputedStyle} */(null);
110 } 155 }
111 }, 156 },
112 157
113 _onComputedStyleChanged: function() 158 __proto__: WebInspector.Object.prototype
lushnikov 2016/07/14 00:58:15 nit: indent
pfeldman 2016/07/14 17:26:12 Done.
114 {
115 delete this._computedStylePromise;
116 this.dispatchEventToListeners(WebInspector.ComputedStyleModel.Events.Com putedStyleChanged);
117 },
118
119 __proto__: WebInspector.Object.prototype
120 } 159 }
121 160
122 /** 161 /**
123 * @constructor 162 * @constructor
124 * @param {!WebInspector.DOMNode} node 163 * @param {!WebInspector.DOMNode} node
125 * @param {!Map.<string, string>} computedStyle 164 * @param {!Map.<string, string>} computedStyle
126 */ 165 */
127 WebInspector.ComputedStyleModel.ComputedStyle = function(node, computedStyle) 166 WebInspector.ComputedStyleModel.ComputedStyle = function(node, computedStyle)
128 { 167 {
129 this.node = node; 168 this.node = node;
130 this.computedStyle = computedStyle; 169 this.computedStyle = computedStyle;
131 } 170 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698