Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 18 matching lines...) Expand all Loading... | |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * @constructor | 32 * @constructor |
| 33 * @extends {WebInspector.BreakpointsSidebarPaneBase} | 33 * @extends {WebInspector.BreakpointsSidebarPaneBase} |
| 34 * @implements {WebInspector.ContextFlavorListener} | 34 * @implements {WebInspector.ContextFlavorListener} |
| 35 */ | 35 */ |
| 36 WebInspector.DOMBreakpointsSidebarPane = function() | 36 WebInspector.DOMBreakpointsSidebarPane = function() |
| 37 { | 37 { |
| 38 WebInspector.BreakpointsSidebarPaneBase.call(this); | 38 WebInspector.BreakpointsSidebarPaneBase.call(this); |
| 39 this._domBreakpointsSetting = WebInspector.settings.createLocalSetting("domB reakpoints", []); | |
| 40 this.listElement.classList.add("dom-breakpoints-list"); | 39 this.listElement.classList.add("dom-breakpoints-list"); |
| 41 | 40 |
| 42 this._breakpointElements = {}; | 41 this._breakpointElements = new Map(); |
| 43 | 42 |
| 44 this._breakpointTypes = { | 43 this._breakpointTypes = { |
| 45 SubtreeModified: "subtree-modified", | 44 SubtreeModified: "subtree-modified", |
| 46 AttributeModified: "attribute-modified", | 45 AttributeModified: "attribute-modified", |
| 47 NodeRemoved: "node-removed" | 46 NodeRemoved: "node-removed" |
| 48 }; | 47 }; |
| 49 this._breakpointTypeLabels = {}; | 48 this._breakpointTypeLabels = {}; |
| 50 this._breakpointTypeLabels[this._breakpointTypes.SubtreeModified] = WebInspe ctor.UIString("Subtree Modified"); | 49 this._breakpointTypeLabels[this._breakpointTypes.SubtreeModified] = WebInspe ctor.UIString("Subtree Modified"); |
| 51 this._breakpointTypeLabels[this._breakpointTypes.AttributeModified] = WebIns pector.UIString("Attribute Modified"); | 50 this._breakpointTypeLabels[this._breakpointTypes.AttributeModified] = WebIns pector.UIString("Attribute Modified"); |
| 52 this._breakpointTypeLabels[this._breakpointTypes.NodeRemoved] = WebInspector .UIString("Node Removed"); | 51 this._breakpointTypeLabels[this._breakpointTypes.NodeRemoved] = WebInspector .UIString("Node Removed"); |
| 53 | 52 |
| 54 this._contextMenuLabels = {}; | 53 this._contextMenuLabels = {}; |
| 55 this._contextMenuLabels[this._breakpointTypes.SubtreeModified] = WebInspecto r.UIString.capitalize("Subtree ^modifications"); | 54 this._contextMenuLabels[this._breakpointTypes.SubtreeModified] = WebInspecto r.UIString.capitalize("Subtree ^modifications"); |
| 56 this._contextMenuLabels[this._breakpointTypes.AttributeModified] = WebInspec tor.UIString.capitalize("Attributes ^modifications"); | 55 this._contextMenuLabels[this._breakpointTypes.AttributeModified] = WebInspec tor.UIString.capitalize("Attributes ^modifications"); |
| 57 this._contextMenuLabels[this._breakpointTypes.NodeRemoved] = WebInspector.UI String.capitalize("Node ^removal"); | 56 this._contextMenuLabels[this._breakpointTypes.NodeRemoved] = WebInspector.UI String.capitalize("Node ^removal"); |
| 58 | 57 |
| 59 WebInspector.targetManager.addModelListener(WebInspector.DOMModel, WebInspec tor.DOMModel.Events.NodeRemoved, this._nodeRemoved, this); | 58 WebInspector.domBreakpointManager.addEventListener(WebInspector.DOMBreakpoin tManager.Events.BreakpointsChanged, this._reloadBreakpointElements, this); |
| 60 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.Event s.InspectedURLChanged, this._inspectedURLChanged, this); | |
| 61 this._inspectedURL = WebInspector.targetManager.inspectedURL(); | |
| 62 this._update(); | 59 this._update(); |
| 63 } | 60 } |
| 64 | 61 |
| 65 WebInspector.DOMBreakpointsSidebarPane.Marker = "breakpoint-marker"; | 62 WebInspector.DOMBreakpointsSidebarPane.Marker = "breakpoint-marker"; |
| 66 | 63 |
| 67 WebInspector.DOMBreakpointsSidebarPane.prototype = { | 64 WebInspector.DOMBreakpointsSidebarPane.prototype = { |
| 68 _inspectedURLChanged: function() | 65 _reloadBreakpointElements: function() |
| 69 { | 66 { |
| 70 this._breakpointElements = {}; | 67 this._breakpointElements.clear(); |
| 71 this.reset(); | 68 this.reset(); |
| 72 this._inspectedURL = WebInspector.targetManager.inspectedURL(); | 69 var breakpoints = WebInspector.domBreakpointManager.domBreakpoints(); |
| 70 for (var breakpoint of breakpoints) { | |
| 71 var id = this._createBreakpointId(breakpoint.node.id, breakpoint.typ e); | |
| 72 this._breakpointElements.set(id, this._createBreakpointElement(break point.node, breakpoint.type, breakpoint.enabled)); | |
| 73 } | |
| 73 }, | 74 }, |
| 74 | 75 |
| 75 /** | 76 /** |
| 76 * @param {!WebInspector.DOMNode} node | 77 * @param {!WebInspector.DOMNode} node |
| 77 * @param {!WebInspector.ContextMenu} contextMenu | 78 * @param {!WebInspector.ContextMenu} contextMenu |
| 78 * @param {boolean} createSubMenu | 79 * @param {boolean} createSubMenu |
| 79 */ | 80 */ |
| 80 populateNodeContextMenu: function(node, contextMenu, createSubMenu) | 81 populateNodeContextMenu: function(node, contextMenu, createSubMenu) |
| 81 { | 82 { |
| 82 if (node.pseudoType()) | 83 if (node.pseudoType()) |
| 83 return; | 84 return; |
| 84 | 85 |
| 85 var nodeBreakpoints = this._nodeBreakpoints(node); | 86 var nodeBreakpoints = WebInspector.domBreakpointManager.nodeBreakpoints( node); |
| 86 | 87 |
| 87 /** | 88 /** |
| 88 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | 89 * @param {!DOMDebuggerAgent.DOMBreakpointType} type |
| 89 * @this {WebInspector.DOMBreakpointsSidebarPane} | |
| 90 */ | 90 */ |
| 91 function toggleBreakpoint(type) | 91 function toggleBreakpoint(type) |
| 92 { | 92 { |
| 93 if (!nodeBreakpoints[type]) | 93 WebInspector.domBreakpointManager.toggleBreakpoint(node, type); |
| 94 this._setBreakpoint(node, type, true); | |
| 95 else | |
| 96 this._removeBreakpoint(node, type); | |
| 97 this._saveBreakpoints(); | |
| 98 } | 94 } |
| 99 | 95 |
| 100 var breakpointsMenu = createSubMenu ? contextMenu.appendSubMenuItem(WebI nspector.UIString("Break on...")) : contextMenu; | 96 var breakpointsMenu = createSubMenu ? contextMenu.appendSubMenuItem(WebI nspector.UIString("Break on...")) : contextMenu; |
| 101 for (var key in this._breakpointTypes) { | 97 for (var key in this._breakpointTypes) { |
| 102 var type = this._breakpointTypes[key]; | 98 var type = this._breakpointTypes[key]; |
| 103 var label = this._contextMenuLabels[type]; | 99 var label = this._contextMenuLabels[type]; |
| 104 breakpointsMenu.appendCheckboxItem(label, toggleBreakpoint.bind(this , type), nodeBreakpoints[type]); | 100 breakpointsMenu.appendCheckboxItem(label, toggleBreakpoint.bind(null , type), nodeBreakpoints.get(type)); |
| 105 } | 101 } |
| 106 }, | 102 }, |
| 107 | 103 |
| 108 /** | 104 /** |
| 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 | 105 * @param {!WebInspector.DebuggerPausedDetails} details |
| 139 * @return {!Element} | 106 * @return {!Element} |
| 140 */ | 107 */ |
| 141 createBreakpointHitStatusMessage: function(details) | 108 createBreakpointHitStatusMessage: function(details) |
| 142 { | 109 { |
| 143 var auxData = /** @type {!Object} */ (details.auxData); | 110 var auxData = /** @type {!Object} */ (details.auxData); |
| 144 var message = "Paused on a \"%s\" breakpoint."; | 111 var message = "Paused on a \"%s\" breakpoint."; |
| 145 var substitutions = []; | 112 var substitutions = []; |
| 146 substitutions.push(this._breakpointTypeLabels[auxData["type"]]); | 113 substitutions.push(this._breakpointTypeLabels[auxData["type"]]); |
| 147 | 114 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 167 message = "Paused on a \"%s\" breakpoint set on %s, because its descendant %s was removed."; | 134 message = "Paused on a \"%s\" breakpoint set on %s, because its descendant %s was removed."; |
| 168 substitutions.push(targetNodeLink); | 135 substitutions.push(targetNodeLink); |
| 169 } | 136 } |
| 170 } else { | 137 } else { |
| 171 message = "Paused on a \"%s\" breakpoint set on %s."; | 138 message = "Paused on a \"%s\" breakpoint set on %s."; |
| 172 } | 139 } |
| 173 | 140 |
| 174 return WebInspector.formatLocalized(message, substitutions); | 141 return WebInspector.formatLocalized(message, substitutions); |
| 175 }, | 142 }, |
| 176 | 143 |
| 177 _nodeRemoved: function(event) | |
| 178 { | |
| 179 var node = event.data.node; | |
| 180 this._removeBreakpointsForNode(event.data.node); | |
| 181 var children = node.children(); | |
| 182 if (!children) | |
| 183 return; | |
| 184 for (var i = 0; i < children.length; ++i) | |
| 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 } | |
| 199 }, | |
| 200 | |
| 201 /** | 144 /** |
| 202 * @param {!WebInspector.DOMNode} node | 145 * @param {!WebInspector.DOMNode} node |
| 203 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | 146 * @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 | |
| 223 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | |
| 224 * @param {boolean} enabled | 147 * @param {boolean} enabled |
| 225 */ | 148 */ |
| 226 _createBreakpointElement: function(node, type, enabled) | 149 _createBreakpointElement: function(node, type, enabled) |
| 227 { | 150 { |
| 228 var element = createElement("li"); | 151 var element = createElement("li"); |
| 229 element._node = node; | 152 element._node = node; |
| 230 element._type = type; | 153 element._type = type; |
| 231 element.addEventListener("contextmenu", this._contextMenu.bind(this, nod e, type), true); | 154 element.addEventListener("contextmenu", this._contextMenu.bind(this, nod e, type), true); |
| 232 | 155 |
| 233 var checkboxLabel = createCheckboxLabel("", enabled); | 156 var checkboxLabel = createCheckboxLabel("", enabled); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 250 var currentElement = this.listElement.firstChild; | 173 var currentElement = this.listElement.firstChild; |
| 251 while (currentElement) { | 174 while (currentElement) { |
| 252 if (currentElement._type && currentElement._type < element._type) | 175 if (currentElement._type && currentElement._type < element._type) |
| 253 break; | 176 break; |
| 254 currentElement = currentElement.nextSibling; | 177 currentElement = currentElement.nextSibling; |
| 255 } | 178 } |
| 256 this.addListElement(element, currentElement); | 179 this.addListElement(element, currentElement); |
| 257 return element; | 180 return element; |
| 258 }, | 181 }, |
| 259 | 182 |
| 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 /** | 183 /** |
| 270 * @param {!WebInspector.DOMNode} node | 184 * @param {!WebInspector.DOMNode} node |
| 271 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | 185 * @param {!DOMDebuggerAgent.DOMBreakpointType} type |
| 272 */ | |
| 273 _removeBreakpoint: function(node, type) | |
| 274 { | |
| 275 var breakpointId = this._createBreakpointId(node.id, type); | |
| 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 }, | |
| 286 | |
| 287 /** | |
| 288 * @param {!WebInspector.DOMNode} node | |
| 289 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | |
| 290 * @param {!Event} event | 186 * @param {!Event} event |
| 291 */ | 187 */ |
| 292 _contextMenu: function(node, type, event) | 188 _contextMenu: function(node, type, event) |
| 293 { | 189 { |
| 294 var contextMenu = new WebInspector.ContextMenu(event); | 190 var contextMenu = new WebInspector.ContextMenu(event); |
| 295 | 191 var removeBreakpoint = () => WebInspector.domBreakpointManager.removeBre akpoint(node, type); |
| 296 /** | 192 contextMenu.appendItem(WebInspector.UIString.capitalize("Remove ^breakpo int"), removeBreakpoint); |
| 297 * @this {WebInspector.DOMBreakpointsSidebarPane} | 193 var removeAllBreakpoints = () => WebInspector.domBreakpointManager.remov eAllBreakpoints(); |
| 298 */ | 194 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(); | 195 contextMenu.show(); |
| 307 }, | 196 }, |
| 308 | 197 |
| 309 /** | 198 /** |
| 310 * @param {!WebInspector.DOMNode} node | 199 * @param {!WebInspector.DOMNode} node |
| 311 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | 200 * @param {!DOMDebuggerAgent.DOMBreakpointType} type |
| 312 * @param {!Event} event | 201 * @param {!Event} event |
| 313 */ | 202 */ |
| 314 _checkboxClicked: function(node, type, event) | 203 _checkboxClicked: function(node, type, event) |
| 315 { | 204 { |
| 316 if (event.target.checked) | 205 WebInspector.domBreakpointManager.setBreakpoint(node, type, event.target ["checkboxElement"].checked); |
| 317 node.target().domdebuggerAgent().setDOMBreakpoint(node.id, type); | |
| 318 else | |
| 319 node.target().domdebuggerAgent().removeDOMBreakpoint(node.id, type); | |
| 320 this._saveBreakpoints(); | |
| 321 }, | 206 }, |
| 322 | 207 |
| 323 /** | 208 /** |
| 324 * @override | 209 * @override |
| 325 * @param {?Object} object | 210 * @param {?Object} object |
| 326 */ | 211 */ |
| 327 flavorChanged: function(object) | 212 flavorChanged: function(object) |
| 328 { | 213 { |
| 329 this._update(); | 214 this._update(); |
| 330 }, | 215 }, |
| 331 | 216 |
| 332 _update: function() | 217 _update: function() |
| 333 { | 218 { |
| 334 var details = WebInspector.context.flavor(WebInspector.DebuggerPausedDet ails); | 219 var details = WebInspector.context.flavor(WebInspector.DebuggerPausedDet ails); |
| 335 if (!details || details.reason !== WebInspector.DebuggerModel.BreakReaso n.DOM) { | 220 if (!details || details.reason !== WebInspector.DebuggerModel.BreakReaso n.DOM) { |
| 336 if (this._highlightedElement) { | 221 if (this._highlightedElement) { |
| 337 this._highlightedElement.classList.remove("breakpoint-hit"); | 222 this._highlightedElement.classList.remove("breakpoint-hit"); |
| 338 delete this._highlightedElement; | 223 delete this._highlightedElement; |
| 339 } | 224 } |
| 340 return; | 225 return; |
| 341 } | 226 } |
| 342 var auxData = details.auxData; | 227 var auxData = details.auxData; |
| 343 var breakpointId = this._createBreakpointId(auxData.nodeId, auxData.type ); | 228 var breakpointId = this._createBreakpointId(auxData.nodeId, auxData.type ); |
| 344 var element = this._breakpointElements[breakpointId]; | 229 var element = this._breakpointElements.get(breakpointId); |
| 345 if (!element) | 230 if (!element) |
| 346 return; | 231 return; |
| 347 WebInspector.viewManager.showView("sources.domBreakpoints"); | 232 WebInspector.viewManager.showView("sources.domBreakpoints"); |
| 348 element.classList.add("breakpoint-hit"); | 233 element.classList.add("breakpoint-hit"); |
| 349 this._highlightedElement = element; | 234 this._highlightedElement = element; |
| 350 }, | 235 }, |
| 351 | 236 |
| 352 /** | 237 /** |
| 353 * @param {number} nodeId | 238 * @param {number} nodeId |
| 354 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | 239 * @param {!DOMDebuggerAgent.DOMBreakpointType} type |
| 240 * @return {string} | |
| 355 */ | 241 */ |
| 356 _createBreakpointId: function(nodeId, type) | 242 _createBreakpointId: function(nodeId, type) |
| 357 { | 243 { |
| 358 return nodeId + ":" + type; | 244 return nodeId + ":" + type; |
| 359 }, | 245 }, |
| 360 | 246 |
| 361 _saveBreakpoints: function() | 247 __proto__: WebInspector.BreakpointsSidebarPaneBase.prototype |
| 248 } | |
| 249 | |
| 250 /** | |
| 251 * @constructor | |
| 252 * @extends {WebInspector.VBox} | |
| 253 */ | |
| 254 WebInspector.DOMBreakpointsSidebarPane.Proxy = function() | |
|
lushnikov
2016/08/18 21:16:34
let's move this below the WI.DOMBreakpointManager
chenwilliam
2016/08/18 22:26:50
Done.
| |
| 255 { | |
| 256 WebInspector.VBox.call(this); | |
| 257 this.registerRequiredCSS("components/breakpointsList.css"); | |
| 258 } | |
| 259 | |
| 260 WebInspector.DOMBreakpointsSidebarPane.Proxy.prototype = { | |
| 261 wasShown: function() | |
| 262 { | |
| 263 WebInspector.SimpleView.prototype.wasShown.call(this); | |
| 264 var pane = WebInspector.domBreakpointsSidebarPane; | |
| 265 if (pane.element.parentNode !== this.element) | |
| 266 pane.show(this.element); | |
| 267 }, | |
| 268 | |
| 269 __proto__: WebInspector.VBox.prototype | |
| 270 } | |
| 271 | |
| 272 /** | |
| 273 * @type {!WebInspector.DOMBreakpointsSidebarPane} | |
| 274 */ | |
| 275 WebInspector.domBreakpointsSidebarPane; | |
| 276 | |
| 277 /** | |
| 278 * @constructor | |
| 279 * @extends {WebInspector.Object} | |
| 280 * @implements {WebInspector.TargetManager.Observer} | |
| 281 */ | |
| 282 WebInspector.DOMBreakpointManager = function() | |
| 283 { | |
| 284 /** @type {!Map<!WebInspector.Target, !Protocol.DOMDebuggerAgent>} */ | |
| 285 this._agents = new Map(); | |
| 286 this._domBreakpointsSetting = WebInspector.settings.createLocalSetting("domB reakpoints", []); | |
| 287 /** @type {!Map<string, !WebInspector.DOMBreakpointManager.Breakpoint>} */ | |
| 288 this._breakpoints = new Map(); | |
| 289 WebInspector.targetManager.addModelListener(WebInspector.DOMModel, WebInspec tor.DOMModel.Events.DocumentUpdated, this._restoreBreakpoints, this); | |
| 290 WebInspector.targetManager.addModelListener(WebInspector.DOMModel, WebInspec tor.DOMModel.Events.NodeRemoved, this._nodeRemoved, this); | |
| 291 WebInspector.targetManager.observeTargets(this); | |
| 292 } | |
| 293 | |
| 294 WebInspector.DOMBreakpointManager.Marker = "breakpoint-marker"; | |
| 295 | |
| 296 WebInspector.DOMBreakpointManager.Events = { | |
| 297 BreakpointsChanged: "BreakpointsChanged" | |
| 298 } | |
| 299 | |
| 300 WebInspector.DOMBreakpointManager.prototype = { | |
| 301 /** | |
| 302 * @override | |
| 303 * @param {!WebInspector.Target} target | |
| 304 */ | |
| 305 targetAdded: function(target) | |
| 306 { | |
| 307 if (target.hasDOMCapability()) | |
| 308 this._agents.set(target, target.domdebuggerAgent()); | |
| 309 }, | |
| 310 | |
| 311 /** | |
| 312 * @override | |
| 313 * @param {!WebInspector.Target} target | |
| 314 */ | |
| 315 targetRemoved: function(target) | |
| 316 { | |
| 317 if (target.hasDOMCapability()) | |
| 318 this._agents.delete(target); | |
| 319 }, | |
| 320 | |
| 321 /** | |
| 322 * @return {!Array<!WebInspector.DOMBreakpointManager.Breakpoint>} | |
| 323 */ | |
| 324 domBreakpoints: function() | |
| 362 { | 325 { |
| 363 var breakpoints = []; | 326 var breakpoints = []; |
| 364 var storedBreakpoints = this._domBreakpointsSetting.get(); | 327 for (var breakpoint of this._breakpoints.values()) |
| 365 for (var i = 0; i < storedBreakpoints.length; ++i) { | 328 breakpoints.push(breakpoint); |
| 366 var breakpoint = storedBreakpoints[i]; | 329 return breakpoints; |
| 367 if (breakpoint.url !== this._inspectedURL) | 330 }, |
| 368 breakpoints.push(breakpoint); | 331 |
| 332 /** | |
| 333 * @param {!WebInspector.DOMNode} node | |
| 334 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | |
| 335 * @param {boolean} enabled | |
| 336 */ | |
| 337 setBreakpoint: function(node, type, enabled) | |
| 338 { | |
| 339 this._innerSetBreakpoint(node, type, enabled); | |
| 340 this._saveBreakpoints(); | |
| 341 }, | |
| 342 | |
| 343 /** | |
| 344 * @param {!WebInspector.DOMNode} node | |
| 345 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | |
| 346 * @param {boolean} enabled | |
| 347 */ | |
| 348 _innerSetBreakpoint: function(node, type, enabled) | |
| 349 { | |
| 350 var url = node.ownerDocument.documentURL.removeURLFragment(); | |
| 351 var breakpoint = new WebInspector.DOMBreakpointManager.Breakpoint(node, type, url, enabled); | |
| 352 this._breakpoints.set(this._createBreakpointId(node, type), breakpoint); | |
| 353 var agent = this._agents.get(node.target()); | |
| 354 if (enabled) { | |
| 355 agent.setDOMBreakpoint(node.id, type); | |
| 356 node.setMarker(WebInspector.DOMBreakpointManager.Marker, true); | |
| 357 } else { | |
| 358 agent.removeDOMBreakpoint(node.id, type); | |
| 359 node.setMarker(WebInspector.DOMBreakpointManager.Marker, this._hasOt herBreakpoints(node, type) ? true : null); | |
| 369 } | 360 } |
| 370 for (var id in this._breakpointElements) { | 361 }, |
| 371 var element = this._breakpointElements[id]; | 362 |
| 372 breakpoints.push({ url: this._inspectedURL, path: element._node.path (), type: element._type, enabled: element._checkboxElement.checked }); | 363 /** |
| 364 * @param {!WebInspector.DOMNode} node | |
| 365 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | |
| 366 */ | |
| 367 removeBreakpoint: function(node, type) | |
| 368 { | |
| 369 this._innerRemoveBreakpoint(node, type); | |
| 370 this._saveBreakpoints(); | |
| 371 }, | |
| 372 | |
| 373 /** | |
| 374 * @param {!WebInspector.DOMNode} node | |
| 375 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | |
| 376 */ | |
| 377 _innerRemoveBreakpoint: function(node, type) | |
| 378 { | |
| 379 var breakpointId = this._createBreakpointId(node, type); | |
| 380 var breakpoint = this._breakpoints.get(breakpointId); | |
| 381 if (breakpoint.enabled) { | |
| 382 var agent = this._agents.get(node.target()); | |
| 383 agent.removeDOMBreakpoint(node.id, type); | |
| 384 node.setMarker(WebInspector.DOMBreakpointManager.Marker, this._hasOt herBreakpoints(node, type) ? true : null); | |
| 373 } | 385 } |
| 374 this._domBreakpointsSetting.set(breakpoints); | 386 this._breakpoints.remove(breakpointId); |
| 375 }, | 387 }, |
| 376 | 388 |
| 377 /** | 389 /** |
| 378 * @param {!WebInspector.DOMModel} domModel | 390 * @param {!WebInspector.DOMNode} node |
| 379 */ | 391 * @param {!DOMDebuggerAgent.DOMBreakpointType} type |
| 380 restoreBreakpoints: function(domModel) | 392 */ |
| 381 { | 393 toggleBreakpoint: function(node, type) |
| 394 { | |
| 395 var nodeBreakpoints = this.nodeBreakpoints(node); | |
| 396 if (!nodeBreakpoints.get(type)) | |
| 397 this.setBreakpoint(node, type, true); | |
| 398 else | |
| 399 this.removeBreakpoint(node, type); | |
| 400 }, | |
| 401 | |
| 402 removeAllBreakpoints: function() | |
| 403 { | |
| 404 for (var breakpoint of this._breakpoints.values()) | |
| 405 this._innerRemoveBreakpoint(breakpoint.node, breakpoint.type); | |
| 406 this._saveBreakpoints(); | |
| 407 }, | |
| 408 | |
| 409 /** | |
| 410 * @param {!WebInspector.DOMNode} node | |
| 411 * @return {!Map<string, boolean>} | |
| 412 */ | |
| 413 nodeBreakpoints: function(node) | |
| 414 { | |
| 415 var nodeBreakpoints = new Map(); | |
| 416 for (var breakpoint of this._breakpoints.values()) { | |
| 417 if (breakpoint.node === node && breakpoint.enabled) | |
| 418 nodeBreakpoints.set(breakpoint.type, true); | |
| 419 } | |
| 420 return nodeBreakpoints; | |
| 421 }, | |
| 422 | |
| 423 /** | |
| 424 * @param {!WebInspector.Event} event | |
| 425 */ | |
| 426 _restoreBreakpoints: function(event) | |
| 427 { | |
| 428 var inspectedRootDocument = /** @type {!WebInspector.DOMDocument} */ (ev ent.data); | |
| 429 if (!inspectedRootDocument) | |
|
chenwilliam
2016/08/17 23:02:49
I saw Elements panel doing something similar in it
| |
| 430 return; | |
| 431 var domModel = /** @type {!WebInspector.DOMModel} */ (event.target); | |
| 382 var pathToBreakpoints = {}; | 432 var pathToBreakpoints = {}; |
| 433 this._breakpoints.clear(); | |
| 434 this.dispatchEventToListeners(WebInspector.DOMBreakpointManager.Events.B reakpointsChanged); | |
| 383 | 435 |
| 384 /** | 436 /** |
| 385 * @param {string} path | 437 * @param {string} path |
| 386 * @param {?DOMAgent.NodeId} nodeId | 438 * @param {?DOMAgent.NodeId} nodeId |
| 387 * @this {WebInspector.DOMBreakpointsSidebarPane} | 439 * @this {WebInspector.DOMBreakpointManager} |
| 388 */ | 440 */ |
| 389 function didPushNodeByPathToFrontend(path, nodeId) | 441 function didPushNodeByPathToFrontend(path, nodeId) |
| 390 { | 442 { |
| 391 var node = nodeId ? domModel.nodeForId(nodeId) : null; | 443 var node = nodeId ? domModel.nodeForId(nodeId) : null; |
| 392 if (!node) | 444 if (!node) |
| 393 return; | 445 return; |
| 394 | 446 |
| 395 var breakpoints = pathToBreakpoints[path]; | 447 for (var breakpoint of pathToBreakpoints[path]) |
| 396 for (var i = 0; i < breakpoints.length; ++i) | 448 this._innerSetBreakpoint(node, breakpoint.type, breakpoint.enabl ed); |
| 397 this._setBreakpoint(node, breakpoints[i].type, breakpoints[i].en abled); | 449 this.dispatchEventToListeners(WebInspector.DOMBreakpointManager.Even ts.BreakpointsChanged); |
| 398 } | 450 } |
| 399 | 451 |
| 400 var breakpoints = this._domBreakpointsSetting.get(); | 452 var breakpoints = this._domBreakpointsSetting.get(); |
| 401 for (var i = 0; i < breakpoints.length; ++i) { | 453 for (var breakpoint of breakpoints) { |
| 402 var breakpoint = breakpoints[i]; | 454 if (breakpoint.url !== WebInspector.targetManager.inspectedURL()) |
| 403 if (breakpoint.url !== this._inspectedURL) | |
| 404 continue; | 455 continue; |
| 405 var path = breakpoint.path; | 456 var path = breakpoint.path; |
| 406 if (!pathToBreakpoints[path]) { | 457 if (!pathToBreakpoints[path]) { |
| 407 pathToBreakpoints[path] = []; | 458 pathToBreakpoints[path] = []; |
| 408 domModel.pushNodeByPathToFrontend(path, didPushNodeByPathToFront end.bind(this, path)); | 459 domModel.pushNodeByPathToFrontend(path, didPushNodeByPathToFront end.bind(this, path)); |
| 409 } | 460 } |
| 410 pathToBreakpoints[path].push(breakpoint); | 461 pathToBreakpoints[path].push(breakpoint); |
| 411 } | 462 } |
| 412 }, | 463 }, |
| 413 | 464 |
| 414 __proto__: WebInspector.BreakpointsSidebarPaneBase.prototype | 465 _saveBreakpoints: function() |
| 466 { | |
| 467 var breakpoints = []; | |
| 468 var storedBreakpoints = this._domBreakpointsSetting.get(); | |
| 469 for (var breakpoint of storedBreakpoints) { | |
| 470 if (breakpoint.url !== WebInspector.targetManager.inspectedURL()) | |
| 471 breakpoints.push(breakpoint); | |
| 472 } | |
| 473 for (var breakpoint of this._breakpoints.values()) { | |
| 474 breakpoints.push({ | |
| 475 url: breakpoint.url, | |
| 476 path: breakpoint.node.path(), | |
| 477 type: breakpoint.type, | |
| 478 enabled: breakpoint.enabled | |
| 479 }); | |
| 480 } | |
| 481 this._domBreakpointsSetting.set(breakpoints); | |
| 482 this.dispatchEventToListeners(WebInspector.DOMBreakpointManager.Events.B reakpointsChanged); | |
| 483 }, | |
| 484 | |
| 485 /** | |
| 486 * @param {!WebInspector.DOMNode} node | |
| 487 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | |
| 488 * @return {boolean} | |
| 489 */ | |
| 490 _hasOtherBreakpoints: function(node, type) | |
| 491 { | |
| 492 for (var breakpoint of this._breakpoints.values()) { | |
| 493 if (breakpoint.node === node && breakpoint.type !== type && breakpoi nt.enabled) | |
| 494 return true; | |
| 495 } | |
| 496 return false; | |
| 497 }, | |
| 498 | |
| 499 /** | |
| 500 * @param {!WebInspector.Event} event | |
| 501 */ | |
| 502 _nodeRemoved: function(event) | |
| 503 { | |
| 504 var node = event.data.node; | |
| 505 this._removeBreakpointsForNode(node); | |
| 506 var children = node.children(); | |
| 507 if (!children) | |
| 508 return; | |
| 509 for (var child of children) | |
| 510 this._removeBreakpointsForNode(child); | |
| 511 }, | |
| 512 | |
| 513 /** | |
| 514 * @param {!WebInspector.DOMNode} node | |
| 515 */ | |
| 516 _removeBreakpointsForNode: function(node) | |
| 517 { | |
| 518 for (var breakpoint of this._breakpoints.values()) { | |
| 519 if (breakpoint.node === node) | |
| 520 this._innerRemoveBreakpoint(breakpoint.node, breakpoint.type); | |
| 521 } | |
| 522 this._saveBreakpoints(); | |
| 523 }, | |
| 524 | |
| 525 /** | |
| 526 * @param {!WebInspector.DOMNode} node | |
| 527 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | |
| 528 * @return {string} | |
| 529 */ | |
| 530 _createBreakpointId: function(node, type) | |
| 531 { | |
| 532 return node.id + ":" + type; | |
| 533 }, | |
| 534 | |
| 535 __proto__: WebInspector.Object.prototype | |
| 536 }; | |
| 537 | |
| 538 /** | |
| 539 * @constructor | |
| 540 * @param {!WebInspector.DOMNode} node | |
| 541 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | |
| 542 * @param {string} url | |
| 543 * @param {boolean} enabled | |
| 544 */ | |
| 545 WebInspector.DOMBreakpointManager.Breakpoint = function(node, type, url, enabled ) | |
| 546 { | |
| 547 this.node = node; | |
| 548 this.path = node.path(); | |
| 549 this.type = type; | |
| 550 this.url = url; | |
| 551 this.enabled = enabled; | |
| 415 } | 552 } |
| 416 | 553 |
| 417 /** | 554 /** |
| 418 * @constructor | 555 * @type {!WebInspector.DOMBreakpointManager} |
| 419 * @extends {WebInspector.VBox} | |
| 420 */ | 556 */ |
| 421 WebInspector.DOMBreakpointsSidebarPane.Proxy = function() | 557 WebInspector.domBreakpointManager; |
| 422 { | |
| 423 WebInspector.VBox.call(this); | |
| 424 this.registerRequiredCSS("components/breakpointsList.css"); | |
| 425 } | |
| 426 | |
| 427 WebInspector.DOMBreakpointsSidebarPane.Proxy.prototype = { | |
| 428 wasShown: function() | |
| 429 { | |
| 430 WebInspector.SimpleView.prototype.wasShown.call(this); | |
| 431 var pane = WebInspector.domBreakpointsSidebarPane; | |
| 432 if (pane.element.parentNode !== this.element) | |
| 433 pane.show(this.element); | |
| 434 }, | |
| 435 | |
| 436 __proto__: WebInspector.VBox.prototype | |
| 437 } | |
| 438 | |
| 439 /** | |
| 440 * @type {!WebInspector.DOMBreakpointsSidebarPane} | |
| 441 */ | |
| 442 WebInspector.domBreakpointsSidebarPane; | |
| OLD | NEW |