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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/elements/ElementsSidebarPane.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) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2014 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 * @constructor 6 * @constructor
7 * @extends {WebInspector.SidebarPane} 7 * @extends {WebInspector.SidebarPane}
8 * @param {string} title 8 * @param {string} title
9 */ 9 */
10 WebInspector.ElementsSidebarPane = function(title) 10 WebInspector.ElementsSidebarPane = function(title)
11 { 11 {
12 WebInspector.SidebarPane.call(this, title); 12 WebInspector.SidebarPane.call(this, title);
13 this._node = null; 13 this._computedStyleModel = new WebInspector.ComputedStyleModel();
lushnikov 2016/07/14 00:58:15 Looks like this will result in re-requesting compu
pfeldman 2016/07/14 17:26:12 Not unless you call fetchComputedStyle on it.
14 this._updateController = new WebInspector.ElementsSidebarPane._UpdateControl ler(this, this.doUpdate.bind(this)); 14 this._computedStyleModel.addEventListener(WebInspector.ComputedStyleModel.Ev ents.ComputedStyleChanged, this.onCSSModelChanged, this);
15 WebInspector.context.addFlavorChangeListener(WebInspector.DOMNode, this._nod eChanged, this); 15
16 this._updateThrottler = new WebInspector.Throttler(100);
17 this._updateWhenVisible = false;
16 } 18 }
17 19
18 WebInspector.ElementsSidebarPane.prototype = { 20 WebInspector.ElementsSidebarPane.prototype = {
19 /** 21 /**
20 * @return {?WebInspector.DOMNode} 22 * @return {?WebInspector.DOMNode}
21 */ 23 */
22 node: function() 24 node: function()
23 { 25 {
24 return this._node; 26 return this._computedStyleModel.node();
25 }, 27 },
26 28
27 /** 29 /**
28 * @return {?WebInspector.CSSModel} 30 * @return {?WebInspector.CSSModel}
29 */ 31 */
30 cssModel: function() 32 cssModel: function()
31 { 33 {
32 return this._cssModel && this._cssModel.isEnabled() ? this._cssModel : n ull; 34 return this._computedStyleModel.cssModel();
33 }, 35 },
34 36
35 /** 37 /**
36 * @param {!WebInspector.Event} event
37 */
38 _nodeChanged: function(event)
39 {
40 this.setNode(/** @type {?WebInspector.DOMNode} */ (event.data));
41 },
42
43 /**
44 * @param {?WebInspector.DOMNode} node
45 */
46 setNode: function(node)
47 {
48 this._node = node;
49 this._updateTarget(node ? node.target() : null);
50 this.update();
51 },
52
53 /**
54 * @protected 38 * @protected
55 * @return {!Promise.<?>} 39 * @return {!Promise.<?>}
56 */ 40 */
57 doUpdate: function() 41 doUpdate: function()
58 { 42 {
59 return Promise.resolve(); 43 return Promise.resolve();
60 }, 44 },
61 45
62 update: function() 46 update: function()
63 { 47 {
64 this._updateController.update(); 48 this._updateWhenVisible = !this.isShowing();
49 if (this._updateWhenVisible)
50 return;
51 this._updateThrottler.schedule(innerUpdate.bind(this));
52
53 /**
54 * @return {!Promise.<?>}
55 * @this {WebInspector.ElementsSidebarPane}
56 */
57 function innerUpdate()
58 {
59 return this.isShowing() ? this.doUpdate() : Promise.resolve();
60 }
65 }, 61 },
66 62
67 wasShown: function() 63 wasShown: function()
68 { 64 {
69 WebInspector.SidebarPane.prototype.wasShown.call(this); 65 WebInspector.SidebarPane.prototype.wasShown.call(this);
70 this._updateController.viewWasShown(); 66 if (this._updateWhenVisible)
67 this.update();
71 }, 68 },
72 69
73 /** 70 /**
74 * @param {?WebInspector.Target} target
75 */
76 _updateTarget: function(target)
77 {
78 if (this._target === target)
79 return;
80 if (this._targetEvents) {
81 WebInspector.EventTarget.removeEventListeners(this._targetEvents);
82 this._targetEvents = null;
83 }
84 this._target = target;
85
86 var domModel = null;
87 var resourceTreeModel = null;
88 if (target) {
89 this._cssModel = WebInspector.CSSModel.fromTarget(target);
90 domModel = WebInspector.DOMModel.fromTarget(target);
91 resourceTreeModel = target.resourceTreeModel;
92 }
93
94 if (this._cssModel && domModel && resourceTreeModel) {
95 this._targetEvents = [
96 this._cssModel.addEventListener(WebInspector.CSSModel.Events.Sty leSheetAdded, this.onCSSModelChanged, this),
97 this._cssModel.addEventListener(WebInspector.CSSModel.Events.Sty leSheetRemoved, this.onCSSModelChanged, this),
98 this._cssModel.addEventListener(WebInspector.CSSModel.Events.Sty leSheetChanged, this.onCSSModelChanged, this),
99 this._cssModel.addEventListener(WebInspector.CSSModel.Events.Med iaQueryResultChanged, this.onCSSModelChanged, this),
100 this._cssModel.addEventListener(WebInspector.CSSModel.Events.Pse udoStateForced, this.onCSSModelChanged, this),
101 this._cssModel.addEventListener(WebInspector.CSSModel.Events.Mod elWasEnabled, this.onCSSModelChanged, this),
102 domModel.addEventListener(WebInspector.DOMModel.Events.DOMMutate d, this._domModelChanged, this),
103 resourceTreeModel.addEventListener(WebInspector.ResourceTreeMode l.EventTypes.FrameResized, this._onFrameResized, this),
104 ];
105 }
106 },
107
108 /**
109 * @param {!WebInspector.Event} event
110 */
111 _onFrameResized: function(event)
112 {
113 /**
114 * @this {WebInspector.ElementsSidebarPane}
115 */
116 function refreshContents()
117 {
118 this.onFrameResizedThrottled();
119 delete this._frameResizedTimer;
120 }
121
122 if (this._frameResizedTimer)
123 clearTimeout(this._frameResizedTimer);
124
125 this._frameResizedTimer = setTimeout(refreshContents.bind(this), 100);
126 },
127
128 /**
129 * @param {!WebInspector.Event} event
130 */
131 _domModelChanged: function(event)
132 {
133 var node = /** @type {!WebInspector.DOMNode} */ (event.data);
134 this.onDOMModelChanged(node)
135 },
136
137 /**
138 * @param {!WebInspector.DOMNode} node
139 */
140 onDOMModelChanged: function(node) { },
141
142 /**
143 * @param {!WebInspector.Event} event 71 * @param {!WebInspector.Event} event
144 */ 72 */
145 onCSSModelChanged: function(event) { }, 73 onCSSModelChanged: function(event) { },
146 74
147 onFrameResizedThrottled: function() { },
148
149 __proto__: WebInspector.SidebarPane.prototype 75 __proto__: WebInspector.SidebarPane.prototype
150 } 76 }
151
152 /**
153 * @constructor
154 * @param {!WebInspector.Widget} view
155 * @param {function():!Promise.<?>} doUpdate
156 */
157 WebInspector.ElementsSidebarPane._UpdateController = function(view, doUpdate)
158 {
159 this._view = view;
160 this._updateThrottler = new WebInspector.Throttler(100);
161 this._updateWhenVisible = false;
162 this._doUpdate = doUpdate;
163 }
164
165 WebInspector.ElementsSidebarPane._UpdateController.prototype = {
166 update: function()
167 {
168 this._updateWhenVisible = !this._view.isShowing();
169 if (this._updateWhenVisible)
170 return;
171 this._updateThrottler.schedule(innerUpdate.bind(this));
172
173 /**
174 * @this {WebInspector.ElementsSidebarPane._UpdateController}
175 * @return {!Promise.<?>}
176 */
177 function innerUpdate()
178 {
179 return this._view.isShowing() ? this._doUpdate.call(null) : Promise. resolve();
180 }
181 },
182
183 viewWasShown: function()
184 {
185 if (this._updateWhenVisible)
186 this.update();
187 }
188 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698