OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015 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 * @constructor |
| 7 * @extends {WebInspector.SidebarPane} |
| 8 * @param {!WebInspector.BreakpointManager} breakpointManager |
| 9 * @param {function(!WebInspector.UISourceCode, number=, number=, boolean=)} sho
wSourceLineDelegate |
| 10 */ |
| 11 WebInspector.JavaScriptBreakpointsSidebarPane = function(breakpointManager, show
SourceLineDelegate) |
| 12 { |
| 13 WebInspector.SidebarPane.call(this, WebInspector.UIString("Breakpoints")); |
| 14 this.registerRequiredCSS("components/breakpointsList.css"); |
| 15 |
| 16 this._breakpointManager = breakpointManager; |
| 17 this._showSourceLineDelegate = showSourceLineDelegate; |
| 18 |
| 19 this.listElement = createElementWithClass("ol", "breakpoint-list"); |
| 20 |
| 21 this.emptyElement = this.bodyElement.createChild("div", "info"); |
| 22 this.emptyElement.textContent = WebInspector.UIString("No Breakpoints"); |
| 23 |
| 24 this._items = new Map(); |
| 25 |
| 26 var breakpointLocations = this._breakpointManager.allBreakpointLocations(); |
| 27 for (var i = 0; i < breakpointLocations.length; ++i) |
| 28 this._addBreakpoint(breakpointLocations[i].breakpoint, breakpointLocatio
ns[i].uiLocation); |
| 29 |
| 30 this._breakpointManager.addEventListener(WebInspector.BreakpointManager.Even
ts.BreakpointAdded, this._breakpointAdded, this); |
| 31 this._breakpointManager.addEventListener(WebInspector.BreakpointManager.Even
ts.BreakpointRemoved, this._breakpointRemoved, this); |
| 32 |
| 33 this.emptyElement.addEventListener("contextmenu", this._emptyElementContextM
enu.bind(this), true); |
| 34 } |
| 35 |
| 36 WebInspector.JavaScriptBreakpointsSidebarPane.prototype = { |
| 37 _emptyElementContextMenu: function(event) |
| 38 { |
| 39 var contextMenu = new WebInspector.ContextMenu(event); |
| 40 this._appendBreakpointActiveItem(contextMenu); |
| 41 contextMenu.show(); |
| 42 }, |
| 43 |
| 44 /** |
| 45 * @param {!WebInspector.ContextMenu} contextMenu |
| 46 */ |
| 47 _appendBreakpointActiveItem: function(contextMenu) |
| 48 { |
| 49 var breakpointActive = this._breakpointManager.breakpointsActive(); |
| 50 var breakpointActiveTitle = breakpointActive ? |
| 51 WebInspector.UIString.capitalize("Deactivate ^breakpoints") : |
| 52 WebInspector.UIString.capitalize("Activate ^breakpoints"); |
| 53 contextMenu.appendItem(breakpointActiveTitle, this._breakpointManager.se
tBreakpointsActive.bind(this._breakpointManager, !breakpointActive)); |
| 54 }, |
| 55 |
| 56 /** |
| 57 * @param {!WebInspector.Event} event |
| 58 */ |
| 59 _breakpointAdded: function(event) |
| 60 { |
| 61 this._breakpointRemoved(event); |
| 62 |
| 63 var breakpoint = /** @type {!WebInspector.BreakpointManager.Breakpoint}
*/ (event.data.breakpoint); |
| 64 var uiLocation = /** @type {!WebInspector.UILocation} */ (event.data.uiL
ocation); |
| 65 this._addBreakpoint(breakpoint, uiLocation); |
| 66 }, |
| 67 |
| 68 /** |
| 69 * @param {!WebInspector.BreakpointManager.Breakpoint} breakpoint |
| 70 * @param {!WebInspector.UILocation} uiLocation |
| 71 */ |
| 72 _addBreakpoint: function(breakpoint, uiLocation) |
| 73 { |
| 74 var element = createElementWithClass("li", "cursor-pointer"); |
| 75 element.addEventListener("contextmenu", this._breakpointContextMenu.bind
(this, breakpoint), true); |
| 76 element.addEventListener("click", this._breakpointClicked.bind(this, uiL
ocation), false); |
| 77 |
| 78 var checkbox = element.createChild("input", "checkbox-elem"); |
| 79 checkbox.type = "checkbox"; |
| 80 checkbox.checked = breakpoint.enabled(); |
| 81 checkbox.addEventListener("click", this._breakpointCheckboxClicked.bind(
this, breakpoint), false); |
| 82 |
| 83 element.createTextChild(uiLocation.linkText()); |
| 84 |
| 85 var snippetElement = element.createChild("div", "source-text monospace")
; |
| 86 |
| 87 /** |
| 88 * @param {?string} content |
| 89 */ |
| 90 function didRequestContent(content) |
| 91 { |
| 92 var lineNumber = uiLocation.lineNumber |
| 93 var columnNumber = uiLocation.columnNumber; |
| 94 var contentString = new String(content); |
| 95 if (lineNumber < contentString.lineCount()) { |
| 96 var lineText = contentString.lineAt(lineNumber); |
| 97 var maxSnippetLength = 200; |
| 98 var snippetStartIndex = columnNumber > 100 ? columnNumber : 0; |
| 99 snippetElement.textContent = lineText.substr(snippetStartIndex).
trimEnd(maxSnippetLength); |
| 100 } |
| 101 } |
| 102 |
| 103 uiLocation.uiSourceCode.requestContent(didRequestContent); |
| 104 |
| 105 element._data = uiLocation; |
| 106 var currentElement = this.listElement.firstChild; |
| 107 while (currentElement) { |
| 108 if (currentElement._data && this._compareBreakpoints(currentElement.
_data, element._data) > 0) |
| 109 break; |
| 110 currentElement = currentElement.nextSibling; |
| 111 } |
| 112 this._addListElement(element, currentElement); |
| 113 |
| 114 var breakpointItem = { element: element, checkbox: checkbox }; |
| 115 this._items.set(breakpoint, breakpointItem); |
| 116 |
| 117 this.expand(); |
| 118 }, |
| 119 |
| 120 /** |
| 121 * @param {!WebInspector.Event} event |
| 122 */ |
| 123 _breakpointRemoved: function(event) |
| 124 { |
| 125 var breakpoint = /** @type {!WebInspector.BreakpointManager.Breakpoint}
*/ (event.data.breakpoint); |
| 126 var breakpointItem = this._items.get(breakpoint); |
| 127 if (!breakpointItem) |
| 128 return; |
| 129 this._items.remove(breakpoint); |
| 130 this._removeListElement(breakpointItem.element); |
| 131 }, |
| 132 |
| 133 /** |
| 134 * @param {!WebInspector.BreakpointManager.Breakpoint} breakpoint |
| 135 */ |
| 136 highlightBreakpoint: function(breakpoint) |
| 137 { |
| 138 var breakpointItem = this._items.get(breakpoint); |
| 139 if (!breakpointItem) |
| 140 return; |
| 141 breakpointItem.element.classList.add("breakpoint-hit"); |
| 142 this._highlightedBreakpointItem = breakpointItem; |
| 143 }, |
| 144 |
| 145 clearBreakpointHighlight: function() |
| 146 { |
| 147 if (this._highlightedBreakpointItem) { |
| 148 this._highlightedBreakpointItem.element.classList.remove("breakpoint
-hit"); |
| 149 delete this._highlightedBreakpointItem; |
| 150 } |
| 151 }, |
| 152 |
| 153 _breakpointClicked: function(uiLocation, event) |
| 154 { |
| 155 this._showSourceLineDelegate(uiLocation.uiSourceCode, uiLocation.lineNum
ber); |
| 156 }, |
| 157 |
| 158 /** |
| 159 * @param {!WebInspector.BreakpointManager.Breakpoint} breakpoint |
| 160 * @param {!Event} event |
| 161 */ |
| 162 _breakpointCheckboxClicked: function(breakpoint, event) |
| 163 { |
| 164 // Breakpoint element has it's own click handler. |
| 165 event.consume(); |
| 166 breakpoint.setEnabled(event.target.checked); |
| 167 }, |
| 168 |
| 169 /** |
| 170 * @param {!WebInspector.BreakpointManager.Breakpoint} breakpoint |
| 171 * @param {!Event} event |
| 172 */ |
| 173 _breakpointContextMenu: function(breakpoint, event) |
| 174 { |
| 175 var breakpoints = this._items.valuesArray(); |
| 176 var contextMenu = new WebInspector.ContextMenu(event); |
| 177 contextMenu.appendItem(WebInspector.UIString.capitalize("Remove ^breakpo
int"), breakpoint.remove.bind(breakpoint)); |
| 178 if (breakpoints.length > 1) { |
| 179 var removeAllTitle = WebInspector.UIString.capitalize("Remove ^all ^
breakpoints"); |
| 180 contextMenu.appendItem(removeAllTitle, this._breakpointManager.remov
eAllBreakpoints.bind(this._breakpointManager)); |
| 181 } |
| 182 |
| 183 contextMenu.appendSeparator(); |
| 184 this._appendBreakpointActiveItem(contextMenu); |
| 185 |
| 186 function enabledBreakpointCount(breakpoints) |
| 187 { |
| 188 var count = 0; |
| 189 for (var i = 0; i < breakpoints.length; ++i) { |
| 190 if (breakpoints[i].checkbox.checked) |
| 191 count++; |
| 192 } |
| 193 return count; |
| 194 } |
| 195 if (breakpoints.length > 1) { |
| 196 var enableBreakpointCount = enabledBreakpointCount(breakpoints); |
| 197 var enableTitle = WebInspector.UIString.capitalize("Enable ^all ^bre
akpoints"); |
| 198 var disableTitle = WebInspector.UIString.capitalize("Disable ^all ^b
reakpoints"); |
| 199 |
| 200 contextMenu.appendSeparator(); |
| 201 |
| 202 contextMenu.appendItem(enableTitle, this._breakpointManager.toggleAl
lBreakpoints.bind(this._breakpointManager, true), !(enableBreakpointCount != bre
akpoints.length)); |
| 203 contextMenu.appendItem(disableTitle, this._breakpointManager.toggleA
llBreakpoints.bind(this._breakpointManager, false), !(enableBreakpointCount > 1)
); |
| 204 } |
| 205 |
| 206 contextMenu.show(); |
| 207 }, |
| 208 |
| 209 _addListElement: function(element, beforeElement) |
| 210 { |
| 211 if (beforeElement) |
| 212 this.listElement.insertBefore(element, beforeElement); |
| 213 else { |
| 214 if (!this.listElement.firstChild) { |
| 215 this.bodyElement.removeChild(this.emptyElement); |
| 216 this.bodyElement.appendChild(this.listElement); |
| 217 } |
| 218 this.listElement.appendChild(element); |
| 219 } |
| 220 }, |
| 221 |
| 222 _removeListElement: function(element) |
| 223 { |
| 224 this.listElement.removeChild(element); |
| 225 if (!this.listElement.firstChild) { |
| 226 this.bodyElement.removeChild(this.listElement); |
| 227 this.bodyElement.appendChild(this.emptyElement); |
| 228 } |
| 229 }, |
| 230 |
| 231 _compare: function(x, y) |
| 232 { |
| 233 if (x !== y) |
| 234 return x < y ? -1 : 1; |
| 235 return 0; |
| 236 }, |
| 237 |
| 238 _compareBreakpoints: function(b1, b2) |
| 239 { |
| 240 return this._compare(b1.uiSourceCode.originURL(), b2.uiSourceCode.origin
URL()) || this._compare(b1.lineNumber, b2.lineNumber); |
| 241 }, |
| 242 |
| 243 reset: function() |
| 244 { |
| 245 this.listElement.removeChildren(); |
| 246 if (this.listElement.parentElement) { |
| 247 this.bodyElement.removeChild(this.listElement); |
| 248 this.bodyElement.appendChild(this.emptyElement); |
| 249 } |
| 250 this._items.clear(); |
| 251 }, |
| 252 |
| 253 __proto__: WebInspector.SidebarPane.prototype |
| 254 } |
OLD | NEW |