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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/components/DOMBreakpointsSidebarPane.js

Issue 2191183003: DevTools: extract model from DOMBreakpointsSidebarPane (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor nits Created 4 years, 4 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 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 17 matching lines...) Expand all
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 /** 31 /**
32 * @constructor 32 * @constructor
33 * @extends {WebInspector.BreakpointsSidebarPaneBase} 33 * @extends {WebInspector.BreakpointsSidebarPaneBase}
34 */ 34 */
35 WebInspector.DOMBreakpointsSidebarPane = function() 35 WebInspector.DOMBreakpointsSidebarPane = function()
36 { 36 {
37 WebInspector.BreakpointsSidebarPaneBase.call(this, WebInspector.UIString("DO M Breakpoints")); 37 WebInspector.BreakpointsSidebarPaneBase.call(this, WebInspector.UIString("DO M Breakpoints"));
38 this._domBreakpointsSetting = WebInspector.settings.createLocalSetting("domB reakpoints", []);
39 this.listElement.classList.add("dom-breakpoints-list"); 38 this.listElement.classList.add("dom-breakpoints-list");
40 39
41 this._breakpointElements = {}; 40 this._breakpointElements = {};
lushnikov 2016/08/11 18:40:18 let's use Map and type-annotate it
chenwilliam 2016/08/17 01:20:11 Done.
42 41
43 this._breakpointTypes = { 42 this._breakpointTypes = {
44 SubtreeModified: "subtree-modified", 43 SubtreeModified: "subtree-modified",
45 AttributeModified: "attribute-modified", 44 AttributeModified: "attribute-modified",
46 NodeRemoved: "node-removed" 45 NodeRemoved: "node-removed"
47 }; 46 };
47
48 this._breakpointTypeLabels = {}; 48 this._breakpointTypeLabels = {};
49 this._breakpointTypeLabels[this._breakpointTypes.SubtreeModified] = WebInspe ctor.UIString("Subtree Modified"); 49 this._breakpointTypeLabels[this._breakpointTypes.SubtreeModified] = WebInspe ctor.UIString("Subtree Modified");
50 this._breakpointTypeLabels[this._breakpointTypes.AttributeModified] = WebIns pector.UIString("Attribute Modified"); 50 this._breakpointTypeLabels[this._breakpointTypes.AttributeModified] = WebIns pector.UIString("Attribute Modified");
51 this._breakpointTypeLabels[this._breakpointTypes.NodeRemoved] = WebInspector .UIString("Node Removed"); 51 this._breakpointTypeLabels[this._breakpointTypes.NodeRemoved] = WebInspector .UIString("Node Removed");
52 52
53 this._contextMenuLabels = {}; 53 this._contextMenuLabels = {};
54 this._contextMenuLabels[this._breakpointTypes.SubtreeModified] = WebInspecto r.UIString.capitalize("Subtree ^modifications"); 54 this._contextMenuLabels[this._breakpointTypes.SubtreeModified] = WebInspecto r.UIString.capitalize("Subtree ^modifications");
55 this._contextMenuLabels[this._breakpointTypes.AttributeModified] = WebInspec tor.UIString.capitalize("Attributes ^modifications"); 55 this._contextMenuLabels[this._breakpointTypes.AttributeModified] = WebInspec tor.UIString.capitalize("Attributes ^modifications");
56 this._contextMenuLabels[this._breakpointTypes.NodeRemoved] = WebInspector.UI String.capitalize("Node ^removal"); 56 this._contextMenuLabels[this._breakpointTypes.NodeRemoved] = WebInspector.UI String.capitalize("Node ^removal");
57 57
58 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.Event s.InspectedURLChanged, this._inspectedURLChanged, this); 58 WebInspector.domBreakpointManager.addEventListener(WebInspector.DOMBreakpoin tManager.Events.BreakpointsChanged, this._reloadBreakpointElements, this);
59 WebInspector.targetManager.addModelListener(WebInspector.DOMModel, WebInspec tor.DOMModel.Events.NodeRemoved, this._nodeRemoved, this);
60 } 59 }
61 60
62 WebInspector.DOMBreakpointsSidebarPane.Marker = "breakpoint-marker";
63
64 WebInspector.DOMBreakpointsSidebarPane.prototype = { 61 WebInspector.DOMBreakpointsSidebarPane.prototype = {
65 _inspectedURLChanged: function(event)
66 {
67 var target = /** @type {!WebInspector.Target} */ (event.data);
68 if (target !== WebInspector.targetManager.mainTarget())
69 return;
70 this._breakpointElements = {};
71 this.reset();
72 this._inspectedURL = target.inspectedURL().removeURLFragment();
73 },
74
75 /** 62 /**
76 * @param {!WebInspector.DOMNode} node 63 * @param {!WebInspector.DOMNode} node
77 * @param {!WebInspector.ContextMenu} contextMenu 64 * @param {!WebInspector.ContextMenu} contextMenu
78 * @param {boolean} createSubMenu 65 * @param {boolean} createSubMenu
79 */ 66 */
80 populateNodeContextMenu: function(node, contextMenu, createSubMenu) 67 populateNodeContextMenu: function(node, contextMenu, createSubMenu)
lushnikov 2016/08/11 18:40:18 let's move this to the elements's panel
chenwilliam 2016/08/17 01:20:11 Done.
81 { 68 {
82 if (node.pseudoType()) 69 if (node.pseudoType())
83 return; 70 return;
84 71
85 var nodeBreakpoints = this._nodeBreakpoints(node); 72 var nodeBreakpoints = WebInspector.domBreakpointManager.nodeBreakpoints( node);
86 73
87 /** 74 /**
88 * @param {!DOMDebuggerAgent.DOMBreakpointType} type 75 * @param {!DOMDebuggerAgent.DOMBreakpointType} type
89 * @this {WebInspector.DOMBreakpointsSidebarPane}
90 */ 76 */
91 function toggleBreakpoint(type) 77 function toggleBreakpoint(type)
92 { 78 {
93 if (!nodeBreakpoints[type]) 79 WebInspector.domBreakpointManager.toggleBreakpoint(node, type);
94 this._setBreakpoint(node, type, true);
95 else
96 this._removeBreakpoint(node, type);
97 this._saveBreakpoints();
98 } 80 }
99 81
100 var breakpointsMenu = createSubMenu ? contextMenu.appendSubMenuItem(WebI nspector.UIString("Break on...")) : contextMenu; 82 var breakpointsMenu = createSubMenu ? contextMenu.appendSubMenuItem(WebI nspector.UIString("Break on...")) : contextMenu;
101 for (var key in this._breakpointTypes) { 83 for (var key in this._breakpointTypes) {
102 var type = this._breakpointTypes[key]; 84 var type = this._breakpointTypes[key];
103 var label = this._contextMenuLabels[type]; 85 var label = this._contextMenuLabels[type];
104 breakpointsMenu.appendCheckboxItem(label, toggleBreakpoint.bind(this , type), nodeBreakpoints[type]); 86 breakpointsMenu.appendCheckboxItem(label, toggleBreakpoint.bind(null , type), nodeBreakpoints[type]);
105 } 87 }
106 }, 88 },
107 89
108 /** 90 /**
109 * @param {!WebInspector.DOMNode} node
110 * @return {!Object<string, boolean>}
111 */
112 _nodeBreakpoints: function(node)
113 {
114 var nodeBreakpoints = {};
115 for (var id in this._breakpointElements) {
116 var element = this._breakpointElements[id];
117 if (element._node === node && element._checkboxElement.checked)
118 nodeBreakpoints[element._type] = true;
119 }
120 return nodeBreakpoints;
121 },
122
123 /**
124 * @param {!WebInspector.DOMNode} node
125 * @return {boolean}
126 */
127 hasBreakpoints: function(node)
128 {
129 for (var id in this._breakpointElements) {
130 var element = this._breakpointElements[id];
131 if (element._node === node && element._checkboxElement.checked)
132 return true;
133 }
134 return false;
135 },
136
137 /**
138 * @param {!WebInspector.DebuggerPausedDetails} details 91 * @param {!WebInspector.DebuggerPausedDetails} details
139 * @return {!Element} 92 * @return {!Element}
140 */ 93 */
141 createBreakpointHitStatusMessage: function(details) 94 createBreakpointHitStatusMessage: function(details)
142 { 95 {
143 var auxData = /** @type {!Object} */ (details.auxData); 96 var auxData = /** @type {!Object} */ (details.auxData);
144 var message = "Paused on a \"%s\" breakpoint."; 97 var message = "Paused on a \"%s\" breakpoint.";
145 var substitutions = []; 98 var substitutions = [];
146 substitutions.push(this._breakpointTypeLabels[auxData["type"]]); 99 substitutions.push(this._breakpointTypeLabels[auxData["type"]]);
147 100
(...skipping 19 matching lines...) Expand all
167 message = "Paused on a \"%s\" breakpoint set on %s, because its descendant %s was removed."; 120 message = "Paused on a \"%s\" breakpoint set on %s, because its descendant %s was removed.";
168 substitutions.push(targetNodeLink); 121 substitutions.push(targetNodeLink);
169 } 122 }
170 } else { 123 } else {
171 message = "Paused on a \"%s\" breakpoint set on %s."; 124 message = "Paused on a \"%s\" breakpoint set on %s.";
172 } 125 }
173 126
174 return WebInspector.formatLocalized(message, substitutions); 127 return WebInspector.formatLocalized(message, substitutions);
175 }, 128 },
176 129
177 _nodeRemoved: function(event) 130 _reloadBreakpointElements: function()
178 { 131 {
179 var node = event.data.node; 132 this._breakpointElements = {};
180 this._removeBreakpointsForNode(event.data.node); 133 this.reset();
181 var children = node.children(); 134 var breakpoints = WebInspector.domBreakpointManager.domBreakpoints();
182 if (!children) 135 for (var breakpoint of breakpoints.values()) {
183 return; 136 var id = this._createBreakpointId(breakpoint.node.id, breakpoint.typ e);
184 for (var i = 0; i < children.length; ++i) 137 this._breakpointElements[id] = this._createBreakpointElement(breakpo int.node, breakpoint.type, breakpoint.enabled);
185 this._removeBreakpointsForNode(children[i]);
186 this._saveBreakpoints();
187 },
188
189 /**
190 * @param {!WebInspector.DOMNode} node
191 */
192 _removeBreakpointsForNode: function(node)
193 {
194 for (var id in this._breakpointElements) {
195 var element = this._breakpointElements[id];
196 if (element._node === node)
197 this._removeBreakpoint(element._node, element._type);
198 } 138 }
199 }, 139 },
200 140
201 /** 141 /**
202 * @param {!WebInspector.DOMNode} node
203 * @param {!DOMDebuggerAgent.DOMBreakpointType} type
204 * @param {boolean} enabled
205 */
206 _setBreakpoint: function(node, type, enabled)
207 {
208 var breakpointId = this._createBreakpointId(node.id, type);
209 var breakpointElement = this._breakpointElements[breakpointId];
210 if (!breakpointElement) {
211 breakpointElement = this._createBreakpointElement(node, type, enable d);
212 this._breakpointElements[breakpointId] = breakpointElement;
213 } else {
214 breakpointElement._checkboxElement.checked = enabled;
215 }
216 if (enabled)
217 node.target().domdebuggerAgent().setDOMBreakpoint(node.id, type);
218 node.setMarker(WebInspector.DOMBreakpointsSidebarPane.Marker, true);
219 },
220
221 /**
222 * @param {!WebInspector.DOMNode} node 142 * @param {!WebInspector.DOMNode} node
223 * @param {!DOMDebuggerAgent.DOMBreakpointType} type 143 * @param {!DOMDebuggerAgent.DOMBreakpointType} type
224 * @param {boolean} enabled 144 * @param {boolean} enabled
225 */ 145 */
226 _createBreakpointElement: function(node, type, enabled) 146 _createBreakpointElement: function(node, type, enabled)
227 { 147 {
228 var element = createElement("li"); 148 var element = createElement("li");
229 element._node = node; 149 element._node = node;
230 element._type = type; 150 element._type = type;
231 element.addEventListener("contextmenu", this._contextMenu.bind(this, nod e, type), true); 151 element.addEventListener("contextmenu", this._contextMenu.bind(this, nod e, type), true);
(...skipping 18 matching lines...) Expand all
250 var currentElement = this.listElement.firstChild; 170 var currentElement = this.listElement.firstChild;
251 while (currentElement) { 171 while (currentElement) {
252 if (currentElement._type && currentElement._type < element._type) 172 if (currentElement._type && currentElement._type < element._type)
253 break; 173 break;
254 currentElement = currentElement.nextSibling; 174 currentElement = currentElement.nextSibling;
255 } 175 }
256 this.addListElement(element, currentElement); 176 this.addListElement(element, currentElement);
257 return element; 177 return element;
258 }, 178 },
259 179
260 _removeAllBreakpoints: function()
261 {
262 for (var id in this._breakpointElements) {
263 var element = this._breakpointElements[id];
264 this._removeBreakpoint(element._node, element._type);
265 }
266 this._saveBreakpoints();
267 },
268
269 /** 180 /**
270 * @param {!WebInspector.DOMNode} node 181 * @param {!WebInspector.DOMNode} node
271 * @param {!DOMDebuggerAgent.DOMBreakpointType} type 182 * @param {!DOMDebuggerAgent.DOMBreakpointType} type
183 * @param {!Event} event
272 */ 184 */
273 _removeBreakpoint: function(node, type) 185 _checkboxClicked: function(node, type, event)
274 { 186 {
275 var breakpointId = this._createBreakpointId(node.id, type); 187 WebInspector.domBreakpointManager.setBreakpoint(node, type, event.target ["checkboxElement"].checked);
276 var element = this._breakpointElements[breakpointId];
277 if (!element)
278 return;
279
280 this.removeListElement(element);
281 delete this._breakpointElements[breakpointId];
282 if (element._checkboxElement.checked)
283 node.target().domdebuggerAgent().removeDOMBreakpoint(node.id, type);
284 node.setMarker(WebInspector.DOMBreakpointsSidebarPane.Marker, this.hasBr eakpoints(node) ? true : null);
285 }, 188 },
286 189
287 /** 190 /**
288 * @param {!WebInspector.DOMNode} node 191 * @param {!WebInspector.DOMNode} node
289 * @param {!DOMDebuggerAgent.DOMBreakpointType} type 192 * @param {!DOMDebuggerAgent.DOMBreakpointType} type
290 * @param {!Event} event 193 * @param {!Event} event
291 */ 194 */
292 _contextMenu: function(node, type, event) 195 _contextMenu: function(node, type, event)
293 { 196 {
294 var contextMenu = new WebInspector.ContextMenu(event); 197 var contextMenu = new WebInspector.ContextMenu(event);
295 198 var removeBreakpoint = () => WebInspector.domBreakpointManager.removeBre akpoint(node, type);
296 /** 199 contextMenu.appendItem(WebInspector.UIString.capitalize("Remove ^breakpo int"), removeBreakpoint);
297 * @this {WebInspector.DOMBreakpointsSidebarPane} 200 var removeAllBreakpoints = () => WebInspector.domBreakpointManager.remov eAllBreakpoints();
298 */ 201 contextMenu.appendItem(WebInspector.UIString.capitalize("Remove ^all DOM breakpoints"), removeAllBreakpoints);
299 function removeBreakpoint()
300 {
301 this._removeBreakpoint(node, type);
302 this._saveBreakpoints();
303 }
304 contextMenu.appendItem(WebInspector.UIString.capitalize("Remove ^breakpo int"), removeBreakpoint.bind(this));
305 contextMenu.appendItem(WebInspector.UIString.capitalize("Remove ^all DOM breakpoints"), this._removeAllBreakpoints.bind(this));
306 contextMenu.show(); 202 contextMenu.show();
307 }, 203 },
308 204
309 /**
310 * @param {!WebInspector.DOMNode} node
311 * @param {!DOMDebuggerAgent.DOMBreakpointType} type
312 * @param {!Event} event
313 */
314 _checkboxClicked: function(node, type, event)
315 {
316 if (event.target.checked)
317 node.target().domdebuggerAgent().setDOMBreakpoint(node.id, type);
318 else
319 node.target().domdebuggerAgent().removeDOMBreakpoint(node.id, type);
320 this._saveBreakpoints();
321 },
322
323 highlightBreakpoint: function(auxData) 205 highlightBreakpoint: function(auxData)
324 { 206 {
325 var breakpointId = this._createBreakpointId(auxData.nodeId, auxData.type ); 207 var breakpointId = this._createBreakpointId(auxData.nodeId, auxData.type );
326 var element = this._breakpointElements[breakpointId]; 208 var element = this._breakpointElements[breakpointId];
327 if (!element) 209 if (!element)
328 return; 210 return;
329 this.revealView(); 211 this.revealView();
330 element.classList.add("breakpoint-hit"); 212 element.classList.add("breakpoint-hit");
331 this._highlightedElement = element; 213 this._highlightedElement = element;
332 }, 214 },
333 215
334 clearBreakpointHighlight: function() 216 clearBreakpointHighlight: function()
335 { 217 {
336 if (this._highlightedElement) { 218 if (this._highlightedElement) {
337 this._highlightedElement.classList.remove("breakpoint-hit"); 219 this._highlightedElement.classList.remove("breakpoint-hit");
338 delete this._highlightedElement; 220 delete this._highlightedElement;
339 } 221 }
340 }, 222 },
341 223
342 /** 224 /**
343 * @param {number} nodeId 225 * @param {number} nodeId
344 * @param {!DOMDebuggerAgent.DOMBreakpointType} type 226 * @param {!DOMDebuggerAgent.DOMBreakpointType} type
227 * @return {string}
345 */ 228 */
346 _createBreakpointId: function(nodeId, type) 229 _createBreakpointId: function(nodeId, type)
347 { 230 {
348 return nodeId + ":" + type; 231 return `${nodeId}:${type}`;
lushnikov 2016/08/11 18:40:18 nit: The former was easier to understand
chenwilliam 2016/08/17 01:20:11 Done.
349 },
350
351 _saveBreakpoints: function()
352 {
353 var breakpoints = [];
354 var storedBreakpoints = this._domBreakpointsSetting.get();
355 for (var i = 0; i < storedBreakpoints.length; ++i) {
356 var breakpoint = storedBreakpoints[i];
357 if (breakpoint.url !== this._inspectedURL)
358 breakpoints.push(breakpoint);
359 }
360 for (var id in this._breakpointElements) {
361 var element = this._breakpointElements[id];
362 breakpoints.push({ url: this._inspectedURL, path: element._node.path (), type: element._type, enabled: element._checkboxElement.checked });
363 }
364 this._domBreakpointsSetting.set(breakpoints);
365 },
366
367 /**
368 * @param {!WebInspector.DOMModel} domModel
369 */
370 restoreBreakpoints: function(domModel)
371 {
372 var pathToBreakpoints = {};
373
374 /**
375 * @param {string} path
376 * @param {?DOMAgent.NodeId} nodeId
377 * @this {WebInspector.DOMBreakpointsSidebarPane}
378 */
379 function didPushNodeByPathToFrontend(path, nodeId)
380 {
381 var node = nodeId ? domModel.nodeForId(nodeId) : null;
382 if (!node)
383 return;
384
385 var breakpoints = pathToBreakpoints[path];
386 for (var i = 0; i < breakpoints.length; ++i)
387 this._setBreakpoint(node, breakpoints[i].type, breakpoints[i].en abled);
388 }
389
390 var breakpoints = this._domBreakpointsSetting.get();
391 for (var i = 0; i < breakpoints.length; ++i) {
392 var breakpoint = breakpoints[i];
393 if (breakpoint.url !== this._inspectedURL)
394 continue;
395 var path = breakpoint.path;
396 if (!pathToBreakpoints[path]) {
397 pathToBreakpoints[path] = [];
398 domModel.pushNodeByPathToFrontend(path, didPushNodeByPathToFront end.bind(this, path));
399 }
400 pathToBreakpoints[path].push(breakpoint);
401 }
402 }, 232 },
403 233
404 __proto__: WebInspector.BreakpointsSidebarPaneBase.prototype 234 __proto__: WebInspector.BreakpointsSidebarPaneBase.prototype
405 } 235 }
406 236
407 /** 237 /**
408 * @constructor 238 * @constructor
409 * @extends {WebInspector.VBox} 239 * @extends {WebInspector.VBox}
410 */ 240 */
411 WebInspector.DOMBreakpointsSidebarPane.Proxy = function() 241 WebInspector.DOMBreakpointsSidebarPane.Proxy = function()
(...skipping 11 matching lines...) Expand all
423 pane.show(this.element); 253 pane.show(this.element);
424 }, 254 },
425 255
426 __proto__: WebInspector.VBox.prototype 256 __proto__: WebInspector.VBox.prototype
427 } 257 }
428 258
429 /** 259 /**
430 * @type {!WebInspector.DOMBreakpointsSidebarPane} 260 * @type {!WebInspector.DOMBreakpointsSidebarPane}
431 */ 261 */
432 WebInspector.domBreakpointsSidebarPane; 262 WebInspector.domBreakpointsSidebarPane;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698