| 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.targetManager.addModelListener(WebInspector.DOMModel, WebInspec
tor.DOMModel.Events.NodeRemoved, this._nodeRemoved, this); |
| 60 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.Event
s.InspectedURLChanged, this._inspectedURLChanged, this); | 59 WebInspector.domBreakpointManager.addEventListener(WebInspector.DOMBreakpoin
tManager.Events.BreakpointsChanged, this._reloadBreakpointElements, this); |
| 61 this._inspectedURL = WebInspector.targetManager.inspectedURL(); | |
| 62 this._update(); | 60 this._update(); |
| 63 } | 61 } |
| 64 | 62 |
| 65 WebInspector.DOMBreakpointsSidebarPane.Marker = "breakpoint-marker"; | |
| 66 | |
| 67 WebInspector.DOMBreakpointsSidebarPane.prototype = { | 63 WebInspector.DOMBreakpointsSidebarPane.prototype = { |
| 68 _inspectedURLChanged: function() | 64 _reloadBreakpointElements: function() |
| 69 { | 65 { |
| 70 this._breakpointElements = {}; | 66 this._breakpointElements.clear(); |
| 71 this.reset(); | 67 this.reset(); |
| 72 this._inspectedURL = WebInspector.targetManager.inspectedURL(); | 68 var breakpoints = WebInspector.domBreakpointManager.domBreakpoints(); |
| 69 for (var breakpoint of breakpoints) { |
| 70 var id = this._createBreakpointId(breakpoint.node.id, breakpoint.typ
e); |
| 71 this._breakpointElements.set(id, this._createBreakpointElement(break
point.node, breakpoint.type, breakpoint.enabled)); |
| 72 } |
| 73 }, | 73 }, |
| 74 | 74 |
| 75 /** | 75 /** |
| 76 * @param {!WebInspector.DOMNode} node | 76 * @param {!WebInspector.DOMNode} node |
| 77 * @param {!WebInspector.ContextMenu} contextMenu | 77 * @param {!WebInspector.ContextMenu} contextMenu |
| 78 * @param {boolean} createSubMenu | 78 * @param {boolean} createSubMenu |
| 79 */ | 79 */ |
| 80 populateNodeContextMenu: function(node, contextMenu, createSubMenu) | 80 populateNodeContextMenu: function(node, contextMenu, createSubMenu) |
| 81 { | 81 { |
| 82 if (node.pseudoType()) | 82 if (node.pseudoType()) |
| 83 return; | 83 return; |
| 84 | 84 |
| 85 var nodeBreakpoints = this._nodeBreakpoints(node); | 85 var nodeBreakpoints = this._nodeBreakpoints(node); |
| 86 | 86 |
| 87 /** | 87 /** |
| 88 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | 88 * @param {!DOMDebuggerAgent.DOMBreakpointType} type |
| 89 * @this {WebInspector.DOMBreakpointsSidebarPane} | |
| 90 */ | 89 */ |
| 91 function toggleBreakpoint(type) | 90 function toggleBreakpoint(type) |
| 92 { | 91 { |
| 93 if (!nodeBreakpoints[type]) | 92 if (!nodeBreakpoints.get(type)) |
| 94 this._setBreakpoint(node, type, true); | 93 WebInspector.domBreakpointManager.setBreakpoint(node, type, true
); |
| 95 else | 94 else |
| 96 this._removeBreakpoint(node, type); | 95 WebInspector.domBreakpointManager.removeBreakpoint(node, type); |
| 97 this._saveBreakpoints(); | |
| 98 } | 96 } |
| 99 | 97 |
| 100 var breakpointsMenu = createSubMenu ? contextMenu.appendSubMenuItem(WebI
nspector.UIString("Break on...")) : contextMenu; | 98 var breakpointsMenu = createSubMenu ? contextMenu.appendSubMenuItem(WebI
nspector.UIString("Break on...")) : contextMenu; |
| 101 for (var key in this._breakpointTypes) { | 99 for (var key in this._breakpointTypes) { |
| 102 var type = this._breakpointTypes[key]; | 100 var type = this._breakpointTypes[key]; |
| 103 var label = this._contextMenuLabels[type]; | 101 var label = this._contextMenuLabels[type]; |
| 104 breakpointsMenu.appendCheckboxItem(label, toggleBreakpoint.bind(this
, type), nodeBreakpoints[type]); | 102 breakpointsMenu.appendCheckboxItem(label, toggleBreakpoint.bind(null
, type), nodeBreakpoints.get(type)); |
| 105 } | 103 } |
| 106 }, | 104 }, |
| 107 | 105 |
| 108 /** | 106 /** |
| 109 * @param {!WebInspector.DOMNode} node | 107 * @param {!WebInspector.DOMNode} node |
| 110 * @return {!Object<string, boolean>} | 108 * @return {!Map<string, boolean>} |
| 111 */ | 109 */ |
| 112 _nodeBreakpoints: function(node) | 110 _nodeBreakpoints: function(node) |
| 113 { | 111 { |
| 114 var nodeBreakpoints = {}; | 112 var nodeBreakpoints = new Map(); |
| 115 for (var id in this._breakpointElements) { | 113 var breakpoints = WebInspector.domBreakpointManager.domBreakpoints(); |
| 116 var element = this._breakpointElements[id]; | 114 for (var breakpoint of breakpoints) { |
| 117 if (element._node === node && element._checkboxElement.checked) | 115 if (breakpoint.node === node && breakpoint.enabled) |
| 118 nodeBreakpoints[element._type] = true; | 116 nodeBreakpoints.set(breakpoint.type, true); |
| 119 } | 117 } |
| 120 return nodeBreakpoints; | 118 return nodeBreakpoints; |
| 121 }, | 119 }, |
| 122 | 120 |
| 123 /** | 121 /** |
| 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 | 122 * @param {!WebInspector.DebuggerPausedDetails} details |
| 139 * @return {!Element} | 123 * @return {!Element} |
| 140 */ | 124 */ |
| 141 createBreakpointHitStatusMessage: function(details) | 125 createBreakpointHitStatusMessage: function(details) |
| 142 { | 126 { |
| 143 var auxData = /** @type {!Object} */ (details.auxData); | 127 var auxData = /** @type {!Object} */ (details.auxData); |
| 144 var message = "Paused on a \"%s\" breakpoint."; | 128 var message = "Paused on a \"%s\" breakpoint."; |
| 145 var substitutions = []; | 129 var substitutions = []; |
| 146 substitutions.push(this._breakpointTypeLabels[auxData["type"]]); | 130 substitutions.push(this._breakpointTypeLabels[auxData["type"]]); |
| 147 | 131 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 167 message = "Paused on a \"%s\" breakpoint set on %s, because its
descendant %s was removed."; | 151 message = "Paused on a \"%s\" breakpoint set on %s, because its
descendant %s was removed."; |
| 168 substitutions.push(targetNodeLink); | 152 substitutions.push(targetNodeLink); |
| 169 } | 153 } |
| 170 } else { | 154 } else { |
| 171 message = "Paused on a \"%s\" breakpoint set on %s."; | 155 message = "Paused on a \"%s\" breakpoint set on %s."; |
| 172 } | 156 } |
| 173 | 157 |
| 174 return WebInspector.formatLocalized(message, substitutions); | 158 return WebInspector.formatLocalized(message, substitutions); |
| 175 }, | 159 }, |
| 176 | 160 |
| 161 /** |
| 162 * @param {!WebInspector.Event} event |
| 163 */ |
| 177 _nodeRemoved: function(event) | 164 _nodeRemoved: function(event) |
| 178 { | 165 { |
| 179 var node = event.data.node; | 166 var node = event.data.node; |
| 180 this._removeBreakpointsForNode(event.data.node); | 167 this._removeBreakpointsForNode(node); |
| 181 var children = node.children(); | 168 var children = node.children(); |
| 182 if (!children) | 169 if (!children) |
| 183 return; | 170 return; |
| 184 for (var i = 0; i < children.length; ++i) | 171 for (var child of children) |
| 185 this._removeBreakpointsForNode(children[i]); | 172 this._removeBreakpointsForNode(child); |
| 186 this._saveBreakpoints(); | |
| 187 }, | 173 }, |
| 188 | 174 |
| 189 /** | 175 /** |
| 190 * @param {!WebInspector.DOMNode} node | 176 * @param {!WebInspector.DOMNode} node |
| 191 */ | 177 */ |
| 192 _removeBreakpointsForNode: function(node) | 178 _removeBreakpointsForNode: function(node) |
| 193 { | 179 { |
| 194 for (var id in this._breakpointElements) { | 180 var breakpoints = WebInspector.domBreakpointManager.domBreakpoints(); |
| 195 var element = this._breakpointElements[id]; | 181 for (var breakpoint of breakpoints) { |
| 196 if (element._node === node) | 182 if (breakpoint.node === node) |
| 197 this._removeBreakpoint(element._node, element._type); | 183 WebInspector.domBreakpointManager.removeBreakpoint(breakpoint.no
de, breakpoint.type); |
| 198 } | 184 } |
| 199 }, | 185 }, |
| 200 | 186 |
| 201 /** | 187 /** |
| 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 | 188 * @param {!WebInspector.DOMNode} node |
| 223 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | 189 * @param {!DOMDebuggerAgent.DOMBreakpointType} type |
| 224 * @param {boolean} enabled | 190 * @param {boolean} enabled |
| 225 */ | 191 */ |
| 226 _createBreakpointElement: function(node, type, enabled) | 192 _createBreakpointElement: function(node, type, enabled) |
| 227 { | 193 { |
| 228 var element = createElement("li"); | 194 var element = createElement("li"); |
| 229 element._node = node; | 195 element._node = node; |
| 230 element._type = type; | 196 element._type = type; |
| 231 element.addEventListener("contextmenu", this._contextMenu.bind(this, nod
e, type), true); | 197 element.addEventListener("contextmenu", this._contextMenu.bind(this, nod
e, type), true); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 250 var currentElement = this.listElement.firstChild; | 216 var currentElement = this.listElement.firstChild; |
| 251 while (currentElement) { | 217 while (currentElement) { |
| 252 if (currentElement._type && currentElement._type < element._type) | 218 if (currentElement._type && currentElement._type < element._type) |
| 253 break; | 219 break; |
| 254 currentElement = currentElement.nextSibling; | 220 currentElement = currentElement.nextSibling; |
| 255 } | 221 } |
| 256 this.addListElement(element, currentElement); | 222 this.addListElement(element, currentElement); |
| 257 return element; | 223 return element; |
| 258 }, | 224 }, |
| 259 | 225 |
| 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 /** | 226 /** |
| 270 * @param {!WebInspector.DOMNode} node | 227 * @param {!WebInspector.DOMNode} node |
| 271 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | 228 * @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 | 229 * @param {!Event} event |
| 291 */ | 230 */ |
| 292 _contextMenu: function(node, type, event) | 231 _contextMenu: function(node, type, event) |
| 293 { | 232 { |
| 294 var contextMenu = new WebInspector.ContextMenu(event); | 233 var contextMenu = new WebInspector.ContextMenu(event); |
| 295 | 234 var removeBreakpoint = () => WebInspector.domBreakpointManager.removeBre
akpoint(node, type); |
| 296 /** | 235 contextMenu.appendItem(WebInspector.UIString.capitalize("Remove ^breakpo
int"), removeBreakpoint); |
| 297 * @this {WebInspector.DOMBreakpointsSidebarPane} | 236 var removeAllBreakpoints = () => WebInspector.domBreakpointManager.remov
eAllBreakpoints(); |
| 298 */ | 237 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(); | 238 contextMenu.show(); |
| 307 }, | 239 }, |
| 308 | 240 |
| 309 /** | 241 /** |
| 310 * @param {!WebInspector.DOMNode} node | 242 * @param {!WebInspector.DOMNode} node |
| 311 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | 243 * @param {!DOMDebuggerAgent.DOMBreakpointType} type |
| 312 * @param {!Event} event | 244 * @param {!Event} event |
| 313 */ | 245 */ |
| 314 _checkboxClicked: function(node, type, event) | 246 _checkboxClicked: function(node, type, event) |
| 315 { | 247 { |
| 316 if (event.target.checked) | 248 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 }, | 249 }, |
| 322 | 250 |
| 323 /** | 251 /** |
| 324 * @override | 252 * @override |
| 325 * @param {?Object} object | 253 * @param {?Object} object |
| 326 */ | 254 */ |
| 327 flavorChanged: function(object) | 255 flavorChanged: function(object) |
| 328 { | 256 { |
| 329 this._update(); | 257 this._update(); |
| 330 }, | 258 }, |
| 331 | 259 |
| 332 _update: function() | 260 _update: function() |
| 333 { | 261 { |
| 334 var details = WebInspector.context.flavor(WebInspector.DebuggerPausedDet
ails); | 262 var details = WebInspector.context.flavor(WebInspector.DebuggerPausedDet
ails); |
| 335 if (!details || details.reason !== WebInspector.DebuggerModel.BreakReaso
n.DOM) { | 263 if (!details || details.reason !== WebInspector.DebuggerModel.BreakReaso
n.DOM) { |
| 336 if (this._highlightedElement) { | 264 if (this._highlightedElement) { |
| 337 this._highlightedElement.classList.remove("breakpoint-hit"); | 265 this._highlightedElement.classList.remove("breakpoint-hit"); |
| 338 delete this._highlightedElement; | 266 delete this._highlightedElement; |
| 339 } | 267 } |
| 340 return; | 268 return; |
| 341 } | 269 } |
| 342 var auxData = details.auxData; | 270 var auxData = details.auxData; |
| 343 var breakpointId = this._createBreakpointId(auxData.nodeId, auxData.type
); | 271 var breakpointId = this._createBreakpointId(auxData.nodeId, auxData.type
); |
| 344 var element = this._breakpointElements[breakpointId]; | 272 var element = this._breakpointElements.get(breakpointId); |
| 345 if (!element) | 273 if (!element) |
| 346 return; | 274 return; |
| 347 WebInspector.viewManager.showView("sources.domBreakpoints"); | 275 WebInspector.viewManager.showView("sources.domBreakpoints"); |
| 348 element.classList.add("breakpoint-hit"); | 276 element.classList.add("breakpoint-hit"); |
| 349 this._highlightedElement = element; | 277 this._highlightedElement = element; |
| 350 }, | 278 }, |
| 351 | 279 |
| 352 /** | 280 /** |
| 353 * @param {number} nodeId | 281 * @param {number} nodeId |
| 354 * @param {!DOMDebuggerAgent.DOMBreakpointType} type | 282 * @param {!DOMDebuggerAgent.DOMBreakpointType} type |
| 283 * @return {string} |
| 355 */ | 284 */ |
| 356 _createBreakpointId: function(nodeId, type) | 285 _createBreakpointId: function(nodeId, type) |
| 357 { | 286 { |
| 358 return nodeId + ":" + type; | 287 return nodeId + ":" + type; |
| 359 }, | 288 }, |
| 360 | 289 |
| 361 _saveBreakpoints: function() | 290 __proto__: WebInspector.BreakpointsSidebarPaneBase.prototype |
| 291 } |
| 292 |
| 293 /** |
| 294 * @type {!WebInspector.DOMBreakpointsSidebarPane} |
| 295 */ |
| 296 WebInspector.domBreakpointsSidebarPane; |
| 297 |
| 298 /** |
| 299 * @constructor |
| 300 * @extends {WebInspector.Object} |
| 301 * @implements {WebInspector.TargetManager.Observer} |
| 302 */ |
| 303 WebInspector.DOMBreakpointManager = function() |
| 304 { |
| 305 /** @type {!Map<!WebInspector.Target, !Protocol.DOMDebuggerAgent>} */ |
| 306 this._agents = new Map(); |
| 307 this._domBreakpointsSetting = WebInspector.settings.createLocalSetting("domB
reakpoints", []); |
| 308 /** @type {!Map<string, !WebInspector.DOMBreakpointManager.Breakpoint>} */ |
| 309 this._breakpoints = new Map(); |
| 310 WebInspector.targetManager.addModelListener(WebInspector.DOMModel, WebInspec
tor.DOMModel.Events.DocumentUpdated, this._restoreBreakpoints, this); |
| 311 WebInspector.targetManager.observeTargets(this); |
| 312 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.Event
s.InspectedURLChanged, this._inspectedURLChanged, this); |
| 313 this._inspectedURL = WebInspector.targetManager.inspectedURL(); |
| 314 } |
| 315 |
| 316 WebInspector.DOMBreakpointManager.Marker = "breakpoint-marker"; |
| 317 |
| 318 WebInspector.DOMBreakpointManager.Events = { |
| 319 BreakpointsChanged: "BreakpointsChanged" |
| 320 } |
| 321 |
| 322 WebInspector.DOMBreakpointManager.prototype = { |
| 323 _inspectedURLChanged: function() |
| 362 { | 324 { |
| 363 var breakpoints = []; | 325 this._inspectedURL = WebInspector.targetManager.inspectedURL(); |
| 364 var storedBreakpoints = this._domBreakpointsSetting.get(); | |
| 365 for (var i = 0; i < storedBreakpoints.length; ++i) { | |
| 366 var breakpoint = storedBreakpoints[i]; | |
| 367 if (breakpoint.url !== this._inspectedURL) | |
| 368 breakpoints.push(breakpoint); | |
| 369 } | |
| 370 for (var id in this._breakpointElements) { | |
| 371 var element = this._breakpointElements[id]; | |
| 372 breakpoints.push({ url: this._inspectedURL, path: element._node.path
(), type: element._type, enabled: element._checkboxElement.checked }); | |
| 373 } | |
| 374 this._domBreakpointsSetting.set(breakpoints); | |
| 375 }, | 326 }, |
| 376 | 327 |
| 377 /** | 328 /** |
| 378 * @param {!WebInspector.DOMModel} domModel | 329 * @override |
| 330 * @param {!WebInspector.Target} target |
| 379 */ | 331 */ |
| 380 restoreBreakpoints: function(domModel) | 332 targetAdded: function(target) |
| 381 { | 333 { |
| 334 if (target.hasDOMCapability()) |
| 335 this._agents.set(target, target.domdebuggerAgent()); |
| 336 }, |
| 337 |
| 338 /** |
| 339 * @override |
| 340 * @param {!WebInspector.Target} target |
| 341 */ |
| 342 targetRemoved: function(target) |
| 343 { |
| 344 if (target.hasDOMCapability()) |
| 345 this._agents.delete(target); |
| 346 }, |
| 347 |
| 348 /** |
| 349 * @return {!Array<!WebInspector.DOMBreakpointManager.Breakpoint>} |
| 350 */ |
| 351 domBreakpoints: function() |
| 352 { |
| 353 var breakpoints = []; |
| 354 for (var breakpoint of this._breakpoints.values()) |
| 355 breakpoints.push(breakpoint); |
| 356 return breakpoints; |
| 357 }, |
| 358 |
| 359 /** |
| 360 * @param {!WebInspector.DOMNode} node |
| 361 * @param {!DOMDebuggerAgent.DOMBreakpointType} type |
| 362 * @param {boolean} enabled |
| 363 */ |
| 364 setBreakpoint: function(node, type, enabled) |
| 365 { |
| 366 this._innerSetBreakpoint(node, type, enabled); |
| 367 this._saveBreakpoints(); |
| 368 }, |
| 369 |
| 370 /** |
| 371 * @param {!WebInspector.DOMNode} node |
| 372 * @param {!DOMDebuggerAgent.DOMBreakpointType} type |
| 373 * @param {boolean} enabled |
| 374 */ |
| 375 _innerSetBreakpoint: function(node, type, enabled) |
| 376 { |
| 377 var url = this._inspectedURL; |
| 378 var breakpoint = new WebInspector.DOMBreakpointManager.Breakpoint(node,
type, url, enabled); |
| 379 this._breakpoints.set(this._createBreakpointId(node, type), breakpoint); |
| 380 var agent = this._agents.get(node.target()); |
| 381 if (enabled) { |
| 382 agent.setDOMBreakpoint(node.id, type); |
| 383 node.setMarker(WebInspector.DOMBreakpointManager.Marker, true); |
| 384 } else { |
| 385 agent.removeDOMBreakpoint(node.id, type); |
| 386 node.setMarker(WebInspector.DOMBreakpointManager.Marker, this._hasOt
herBreakpoints(node, type) ? true : null); |
| 387 } |
| 388 }, |
| 389 |
| 390 /** |
| 391 * @param {!WebInspector.DOMNode} node |
| 392 * @param {!DOMDebuggerAgent.DOMBreakpointType} type |
| 393 */ |
| 394 removeBreakpoint: function(node, type) |
| 395 { |
| 396 this._innerRemoveBreakpoint(node, type); |
| 397 this._saveBreakpoints(); |
| 398 }, |
| 399 |
| 400 /** |
| 401 * @param {!WebInspector.DOMNode} node |
| 402 * @param {!DOMDebuggerAgent.DOMBreakpointType} type |
| 403 */ |
| 404 _innerRemoveBreakpoint: function(node, type) |
| 405 { |
| 406 var breakpointId = this._createBreakpointId(node, type); |
| 407 var breakpoint = this._breakpoints.get(breakpointId); |
| 408 if (breakpoint.enabled) { |
| 409 var agent = this._agents.get(node.target()); |
| 410 agent.removeDOMBreakpoint(node.id, type); |
| 411 node.setMarker(WebInspector.DOMBreakpointManager.Marker, this._hasOt
herBreakpoints(node, type) ? true : null); |
| 412 } |
| 413 this._breakpoints.remove(breakpointId); |
| 414 }, |
| 415 |
| 416 removeAllBreakpoints: function() |
| 417 { |
| 418 for (var breakpoint of this._breakpoints.values()) |
| 419 this._innerRemoveBreakpoint(breakpoint.node, breakpoint.type); |
| 420 this._saveBreakpoints(); |
| 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) |
| 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]; | |
| 403 if (breakpoint.url !== this._inspectedURL) | 454 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 !== this._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.DOMNode} node |
| 501 * @param {!DOMDebuggerAgent.DOMBreakpointType} type |
| 502 * @return {string} |
| 503 */ |
| 504 _createBreakpointId: function(node, type) |
| 505 { |
| 506 return node.id + ":" + type; |
| 507 }, |
| 508 |
| 509 __proto__: WebInspector.Object.prototype |
| 510 }; |
| 511 |
| 512 /** |
| 513 * @constructor |
| 514 * @param {!WebInspector.DOMNode} node |
| 515 * @param {!DOMDebuggerAgent.DOMBreakpointType} type |
| 516 * @param {string} url |
| 517 * @param {boolean} enabled |
| 518 */ |
| 519 WebInspector.DOMBreakpointManager.Breakpoint = function(node, type, url, enabled
) |
| 520 { |
| 521 this.node = node; |
| 522 this.path = node.path(); |
| 523 this.type = type; |
| 524 this.url = url; |
| 525 this.enabled = enabled; |
| 415 } | 526 } |
| 416 | 527 |
| 417 /** | 528 /** |
| 529 * @type {!WebInspector.DOMBreakpointManager} |
| 530 */ |
| 531 WebInspector.domBreakpointManager; |
| 532 |
| 533 /** |
| 418 * @constructor | 534 * @constructor |
| 419 * @extends {WebInspector.VBox} | 535 * @extends {WebInspector.VBox} |
| 420 */ | 536 */ |
| 421 WebInspector.DOMBreakpointsSidebarPane.Proxy = function() | 537 WebInspector.DOMBreakpointsSidebarPane.Proxy = function() |
| 422 { | 538 { |
| 423 WebInspector.VBox.call(this); | 539 WebInspector.VBox.call(this); |
| 424 this.registerRequiredCSS("components/breakpointsList.css"); | 540 this.registerRequiredCSS("components/breakpointsList.css"); |
| 425 } | 541 } |
| 426 | 542 |
| 427 WebInspector.DOMBreakpointsSidebarPane.Proxy.prototype = { | 543 WebInspector.DOMBreakpointsSidebarPane.Proxy.prototype = { |
| 428 wasShown: function() | 544 wasShown: function() |
| 429 { | 545 { |
| 430 WebInspector.SimpleView.prototype.wasShown.call(this); | 546 WebInspector.SimpleView.prototype.wasShown.call(this); |
| 431 var pane = WebInspector.domBreakpointsSidebarPane; | 547 var pane = WebInspector.domBreakpointsSidebarPane; |
| 432 if (pane.element.parentNode !== this.element) | 548 if (pane.element.parentNode !== this.element) |
| 433 pane.show(this.element); | 549 pane.show(this.element); |
| 434 }, | 550 }, |
| 435 | 551 |
| 436 __proto__: WebInspector.VBox.prototype | 552 __proto__: WebInspector.VBox.prototype |
| 437 } | 553 } |
| 438 | |
| 439 /** | |
| 440 * @type {!WebInspector.DOMBreakpointsSidebarPane} | |
| 441 */ | |
| 442 WebInspector.domBreakpointsSidebarPane; | |
| OLD | NEW |