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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sdk/OverlayModel.js

Issue 2819183002: [DevTools] Consolidate overlay-related functionality in Overlay domain (Closed)
Patch Set: rebased Created 3 years, 8 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
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6 * @implements {Protocol.OverlayDispatcher}
7 */
8 SDK.OverlayModel = class extends SDK.SDKModel {
9 /**
10 * @param {!SDK.Target} target
11 */
12 constructor(target) {
13 super(target);
14 this._domModel = /** @type {!SDK.DOMModel} */ (target.model(SDK.DOMModel));
15
16 target.registerOverlayDispatcher(this);
17 this._overlayAgent = target.overlayAgent();
18 this._overlayAgent.enable();
19 this._overlayAgent.setShowViewportSizeOnResize(true);
20
21 this._debuggerModel = target.model(SDK.DebuggerModel);
22 if (this._debuggerModel) {
23 Common.moduleSetting('disablePausedStateOverlay').addChangeListener(this._ updatePausedInDebuggerMessage, this);
24 this._debuggerModel.addEventListener(
25 SDK.DebuggerModel.Events.DebuggerPaused, this._updatePausedInDebuggerM essage, this);
26 this._debuggerModel.addEventListener(
27 SDK.DebuggerModel.Events.DebuggerResumed, this._updatePausedInDebugger Message, this);
28 // TODO(dgozman): we should get DebuggerResumed on navigations instead of listening to GlobalObjectCleared.
29 this._debuggerModel.addEventListener(
30 SDK.DebuggerModel.Events.GlobalObjectCleared, this._updatePausedInDebu ggerMessage, this);
31 }
32
33 this._inspectModeEnabled = false;
34 this._hideHighlightTimeout = null;
35 this._defaultHighlighter = new SDK.OverlayModel.DefaultHighlighter(this);
36 this._highlighter = this._defaultHighlighter;
37 }
38
39 /**
40 * @param {!SDK.RemoteObject} object
41 */
42 static highlightObjectAsDOMNode(object) {
43 var domModel = object.runtimeModel().target().model(SDK.DOMModel);
44 if (domModel)
45 domModel.overlayModel().highlightDOMNode(undefined, undefined, undefined, object.objectId);
46 }
47
48 static hideDOMNodeHighlight() {
49 for (var overlayModel of SDK.targetManager.models(SDK.OverlayModel))
50 overlayModel.highlightDOMNode(0);
51 }
52
53 static muteHighlight() {
54 SDK.OverlayModel.hideDOMNodeHighlight();
55 SDK.OverlayModel._highlightDisabled = true;
56 }
57
58 static unmuteHighlight() {
59 SDK.OverlayModel._highlightDisabled = false;
60 }
61
62 /**
63 * @override
64 * @return {!Promise}
65 */
66 suspendModel() {
67 return this._overlayAgent.setSuspended(true);
68 }
69
70 /**
71 * @override
72 * @return {!Promise}
73 */
74 resumeModel() {
75 return this._overlayAgent.setSuspended(false);
76 }
77
78 setShowPaintRects(show) {
pfeldman 2017/04/18 00:25:08 Annotate!
79 this._overlayAgent.setShowPaintRects(show);
80 }
81
82 setShowDebugBorders(show) {
83 this._overlayAgent.setShowDebugBorders(show);
84 }
85
86 setShowFPSCounter(show) {
87 this._overlayAgent.setShowFPSCounter(show);
88 }
89
90 setShowScrollBottleneckRects(show) {
91 this._overlayAgent.setShowScrollBottleneckRects(show);
92 }
93
94 setShowViewportSizeOnResize(show) {
95 this._overlayAgent.setShowViewportSizeOnResize(show);
96 }
97
98 _updatePausedInDebuggerMessage() {
99 var message = this._debuggerModel.isPaused() && !Common.moduleSetting('disab lePausedStateOverlay').get() ?
100 Common.UIString('Paused in debugger') :
101 undefined;
102 this._overlayAgent.setPausedInDebuggerMessage(message);
103 }
104
105 /**
106 * @param {?SDK.OverlayModel.Highlighter} highlighter
107 */
108 setHighlighter(highlighter) {
109 this._highlighter = highlighter || this._defaultHighlighter;
110 }
111
112 /**
113 * @param {!Protocol.Overlay.InspectMode} mode
114 * @return {!Promise}
115 */
116 setInspectMode(mode) {
117 this._inspectModeEnabled = mode !== Protocol.Overlay.InspectMode.None;
118 this.dispatchEventToListeners(SDK.OverlayModel.Events.InspectModeWillBeToggl ed, this);
119 return this._highlighter.setInspectMode(mode, this._buildHighlightConfig());
120 }
121
122 /**
123 * @return {boolean}
124 */
125 inspectModeEnabled() {
126 return this._inspectModeEnabled;
127 }
128
129 /**
130 * @param {!Protocol.DOM.NodeId=} nodeId
131 * @param {string=} mode
132 * @param {!Protocol.DOM.BackendNodeId=} backendNodeId
133 * @param {!Protocol.Runtime.RemoteObjectId=} objectId
134 */
135 highlightDOMNode(nodeId, mode, backendNodeId, objectId) {
136 this.highlightDOMNodeWithConfig(nodeId, {mode: mode}, backendNodeId, objectI d);
137 }
138
139 /**
140 * @param {!Protocol.DOM.NodeId=} nodeId
141 * @param {!{mode: (string|undefined), showInfo: (boolean|undefined), selector s: (string|undefined)}=} config
142 * @param {!Protocol.DOM.BackendNodeId=} backendNodeId
143 * @param {!Protocol.Runtime.RemoteObjectId=} objectId
144 */
145 highlightDOMNodeWithConfig(nodeId, config, backendNodeId, objectId) {
146 if (SDK.OverlayModel._highlightDisabled)
147 return;
148 config = config || {mode: 'all', showInfo: undefined, selectors: undefined};
149 if (this._hideHighlightTimeout) {
150 clearTimeout(this._hideHighlightTimeout);
151 this._hideHighlightTimeout = null;
152 }
153 var highlightConfig = this._buildHighlightConfig(config.mode);
154 if (typeof config.showInfo !== 'undefined')
155 highlightConfig.showInfo = config.showInfo;
156 if (typeof config.selectors !== 'undefined')
157 highlightConfig.selectorList = config.selectors;
158 this._highlighter.highlightDOMNode(this._domModel.nodeForId(nodeId || 0), hi ghlightConfig, backendNodeId, objectId);
159 }
160
161 /**
162 * @param {!Protocol.DOM.NodeId} nodeId
163 */
164 highlightDOMNodeForTwoSeconds(nodeId) {
165 this.highlightDOMNode(nodeId);
166 this._hideHighlightTimeout = setTimeout(() => this.highlightDOMNode(0), 2000 );
167 }
168
169 /**
170 * @param {!Protocol.Page.FrameId} frameId
171 */
172 highlightFrame(frameId) {
173 if (SDK.OverlayModel._highlightDisabled)
174 return;
175 this._highlighter.highlightFrame(frameId);
176 }
177
178 /**
179 * @param {string=} mode
180 * @return {!Protocol.Overlay.HighlightConfig}
181 */
182 _buildHighlightConfig(mode) {
183 mode = mode || 'all';
184 var showRulers = Common.moduleSetting('showMetricsRulers').get();
185 var highlightConfig = {showInfo: mode === 'all', showRulers: showRulers, sho wExtensionLines: showRulers};
186 if (mode === 'all' || mode === 'content')
187 highlightConfig.contentColor = Common.Color.PageHighlight.Content.toProtoc olRGBA();
188
189 if (mode === 'all' || mode === 'padding')
190 highlightConfig.paddingColor = Common.Color.PageHighlight.Padding.toProtoc olRGBA();
191
192 if (mode === 'all' || mode === 'border')
193 highlightConfig.borderColor = Common.Color.PageHighlight.Border.toProtocol RGBA();
194
195 if (mode === 'all' || mode === 'margin')
196 highlightConfig.marginColor = Common.Color.PageHighlight.Margin.toProtocol RGBA();
197
198 if (mode === 'all') {
199 highlightConfig.eventTargetColor = Common.Color.PageHighlight.EventTarget. toProtocolRGBA();
200 highlightConfig.shapeColor = Common.Color.PageHighlight.Shape.toProtocolRG BA();
201 highlightConfig.shapeMarginColor = Common.Color.PageHighlight.ShapeMargin. toProtocolRGBA();
202 highlightConfig.displayAsMaterial = true;
203 }
204 return highlightConfig;
205 }
206
207 /**
208 * @override
209 * @param {!Protocol.DOM.NodeId} nodeId
210 */
211 nodeHighlightRequested(nodeId) {
212 var node = this._domModel.nodeForId(nodeId);
213 if (node)
214 this.dispatchEventToListeners(SDK.OverlayModel.Events.HighlightNodeRequest ed, node);
215 }
216
217 /**
218 * @override
219 * @param {!Protocol.DOM.BackendNodeId} backendNodeId
220 */
221 inspectNodeRequested(backendNodeId) {
222 var deferredNode = new SDK.DeferredDOMNode(this.target(), backendNodeId);
223 this.dispatchEventToListeners(SDK.OverlayModel.Events.InspectNodeRequested, deferredNode);
224 }
225 };
226
227 SDK.SDKModel.register(SDK.OverlayModel, SDK.Target.Capability.DOM, true);
228
229 /** @enum {symbol} */
230 SDK.OverlayModel.Events = {
231 InspectModeWillBeToggled: Symbol('InspectModeWillBeToggled'),
232 HighlightNodeRequested: Symbol('HighlightNodeRequested'),
233 InspectNodeRequested: Symbol('InspectNodeRequested'),
234 };
235
236 /**
237 * @interface
238 */
239 SDK.OverlayModel.Highlighter = function() {};
240
241 SDK.OverlayModel.Highlighter.prototype = {
242 /**
243 * @param {?SDK.DOMNode} node
244 * @param {!Protocol.Overlay.HighlightConfig} config
245 * @param {!Protocol.DOM.BackendNodeId=} backendNodeId
246 * @param {!Protocol.Runtime.RemoteObjectId=} objectId
247 */
248 highlightDOMNode(node, config, backendNodeId, objectId) {},
249
250 /**
251 * @param {!Protocol.Overlay.InspectMode} mode
252 * @param {!Protocol.Overlay.HighlightConfig} config
253 * @return {!Promise}
254 */
255 setInspectMode(mode, config) {},
256
257 /**
258 * @param {!Protocol.Page.FrameId} frameId
259 */
260 highlightFrame(frameId) {}
261 };
262
263 /**
264 * @implements {SDK.OverlayModel.Highlighter}
265 */
266 SDK.OverlayModel.DefaultHighlighter = class {
267 /**
268 * @param {!SDK.OverlayModel} model
269 */
270 constructor(model) {
271 this._model = model;
272 }
273
274 /**
275 * @override
276 * @param {?SDK.DOMNode} node
277 * @param {!Protocol.Overlay.HighlightConfig} config
278 * @param {!Protocol.DOM.BackendNodeId=} backendNodeId
279 * @param {!Protocol.Runtime.RemoteObjectId=} objectId
280 */
281 highlightDOMNode(node, config, backendNodeId, objectId) {
282 if (objectId || node || backendNodeId) {
283 this._model._overlayAgent.highlightNode(
284 config, (objectId || backendNodeId) ? undefined : node.id, backendNode Id, objectId);
285 } else {
286 this._model._overlayAgent.hideHighlight();
287 }
288 }
289
290 /**
291 * @override
292 * @param {!Protocol.Overlay.InspectMode} mode
293 * @param {!Protocol.Overlay.HighlightConfig} config
294 * @return {!Promise}
295 */
296 setInspectMode(mode, config) {
297 return this._model._overlayAgent.setInspectMode(mode, config);
298 }
299
300 /**
301 * @override
302 * @param {!Protocol.Page.FrameId} frameId
303 */
304 highlightFrame(frameId) {
305 this._model._overlayAgent.highlightFrame(
306 frameId, Common.Color.PageHighlight.Content.toProtocolRGBA(),
307 Common.Color.PageHighlight.ContentOutline.toProtocolRGBA());
308 }
309 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698