OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions | |
6 * are met: | |
7 * 1. Redistributions of source code must retain the above copyright | |
8 * notice, this list of conditions and the following disclaimer. | |
9 * 2. Redistributions in binary form must reproduce the above copyright | |
10 * notice, this list of conditions and the following disclaimer in the | |
11 * documentation and/or other materials provided with the distribution. | |
12 * | |
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 */ | |
25 | |
26 WebInspector.ScriptsPanel = function() | |
27 { | |
28 WebInspector.Panel.call(this); | |
29 | |
30 this.element.addStyleClass("scripts"); | |
31 | |
32 this.topStatusBar = document.createElement("div"); | |
33 this.topStatusBar.className = "status-bar"; | |
34 this.topStatusBar.id = "scripts-status-bar"; | |
35 this.element.appendChild(this.topStatusBar); | |
36 | |
37 this.backButton = document.createElement("button"); | |
38 this.backButton.className = "status-bar-item"; | |
39 this.backButton.id = "scripts-back"; | |
40 this.backButton.title = WebInspector.UIString("Show the previous script reso
urce."); | |
41 this.backButton.disabled = true; | |
42 this.backButton.appendChild(document.createElement("img")); | |
43 this.backButton.addEventListener("click", this._goBack.bind(this), false); | |
44 this.topStatusBar.appendChild(this.backButton); | |
45 | |
46 this.forwardButton = document.createElement("button"); | |
47 this.forwardButton.className = "status-bar-item"; | |
48 this.forwardButton.id = "scripts-forward"; | |
49 this.forwardButton.title = WebInspector.UIString("Show the next script resou
rce."); | |
50 this.forwardButton.disabled = true; | |
51 this.forwardButton.appendChild(document.createElement("img")); | |
52 this.forwardButton.addEventListener("click", this._goForward.bind(this), fal
se); | |
53 this.topStatusBar.appendChild(this.forwardButton); | |
54 | |
55 this.filesSelectElement = document.createElement("select"); | |
56 this.filesSelectElement.className = "status-bar-item"; | |
57 this.filesSelectElement.id = "scripts-files"; | |
58 this.filesSelectElement.addEventListener("change", this._changeVisibleFile.b
ind(this), false); | |
59 this.topStatusBar.appendChild(this.filesSelectElement); | |
60 | |
61 this.functionsSelectElement = document.createElement("select"); | |
62 this.functionsSelectElement.className = "status-bar-item"; | |
63 this.functionsSelectElement.id = "scripts-functions"; | |
64 | |
65 // FIXME: append the functions select element to the top status bar when it
is implemented. | |
66 // this.topStatusBar.appendChild(this.functionsSelectElement); | |
67 | |
68 this.sidebarButtonsElement = document.createElement("div"); | |
69 this.sidebarButtonsElement.id = "scripts-sidebar-buttons"; | |
70 this.topStatusBar.appendChild(this.sidebarButtonsElement); | |
71 | |
72 this.pauseButton = document.createElement("button"); | |
73 this.pauseButton.className = "status-bar-item"; | |
74 this.pauseButton.id = "scripts-pause"; | |
75 this.pauseButton.title = WebInspector.UIString("Pause script execution."); | |
76 this.pauseButton.disabled = true; | |
77 this.pauseButton.appendChild(document.createElement("img")); | |
78 this.pauseButton.addEventListener("click", this._togglePause.bind(this), fal
se); | |
79 this.sidebarButtonsElement.appendChild(this.pauseButton); | |
80 | |
81 this.stepOverButton = document.createElement("button"); | |
82 this.stepOverButton.className = "status-bar-item"; | |
83 this.stepOverButton.id = "scripts-step-over"; | |
84 this.stepOverButton.title = WebInspector.UIString("Step over next function c
all."); | |
85 this.stepOverButton.disabled = true; | |
86 this.stepOverButton.addEventListener("click", this._stepOverClicked.bind(thi
s), false); | |
87 this.stepOverButton.appendChild(document.createElement("img")); | |
88 this.sidebarButtonsElement.appendChild(this.stepOverButton); | |
89 | |
90 this.stepIntoButton = document.createElement("button"); | |
91 this.stepIntoButton.className = "status-bar-item"; | |
92 this.stepIntoButton.id = "scripts-step-into"; | |
93 this.stepIntoButton.title = WebInspector.UIString("Step into next function c
all."); | |
94 this.stepIntoButton.disabled = true; | |
95 this.stepIntoButton.addEventListener("click", this._stepIntoClicked.bind(thi
s), false); | |
96 this.stepIntoButton.appendChild(document.createElement("img")); | |
97 this.sidebarButtonsElement.appendChild(this.stepIntoButton); | |
98 | |
99 this.stepOutButton = document.createElement("button"); | |
100 this.stepOutButton.className = "status-bar-item"; | |
101 this.stepOutButton.id = "scripts-step-out"; | |
102 this.stepOutButton.title = WebInspector.UIString("Step out of current functi
on."); | |
103 this.stepOutButton.disabled = true; | |
104 this.stepOutButton.addEventListener("click", this._stepOutClicked.bind(this)
, false); | |
105 this.stepOutButton.appendChild(document.createElement("img")); | |
106 this.sidebarButtonsElement.appendChild(this.stepOutButton); | |
107 | |
108 this.debuggerStatusElement = document.createElement("div"); | |
109 this.debuggerStatusElement.id = "scripts-debugger-status"; | |
110 this.sidebarButtonsElement.appendChild(this.debuggerStatusElement); | |
111 | |
112 this.viewsContainerElement = document.createElement("div"); | |
113 this.viewsContainerElement.id = "script-resource-views"; | |
114 | |
115 this.sidebarElement = document.createElement("div"); | |
116 this.sidebarElement.id = "scripts-sidebar"; | |
117 | |
118 this.sidebarResizeElement = document.createElement("div"); | |
119 this.sidebarResizeElement.className = "sidebar-resizer-vertical"; | |
120 this.sidebarResizeElement.addEventListener("mousedown", this._startSidebarRe
sizeDrag.bind(this), false); | |
121 | |
122 this.sidebarResizeWidgetElement = document.createElement("div"); | |
123 this.sidebarResizeWidgetElement.id = "scripts-sidebar-resizer-widget"; | |
124 this.sidebarResizeWidgetElement.addEventListener("mousedown", this._startSid
ebarResizeDrag.bind(this), false); | |
125 this.topStatusBar.appendChild(this.sidebarResizeWidgetElement); | |
126 | |
127 this.sidebarPanes = {}; | |
128 this.sidebarPanes.callstack = new WebInspector.CallStackSidebarPane(); | |
129 this.sidebarPanes.scopechain = new WebInspector.ScopeChainSidebarPane(); | |
130 this.sidebarPanes.breakpoints = new WebInspector.BreakpointsSidebarPane(); | |
131 | |
132 for (var pane in this.sidebarPanes) | |
133 this.sidebarElement.appendChild(this.sidebarPanes[pane].element); | |
134 | |
135 // FIXME: remove the following line of code when the Breakpoints pane has co
ntent. | |
136 this.sidebarElement.removeChild(this.sidebarPanes.breakpoints.element); | |
137 | |
138 this.sidebarPanes.callstack.expanded = true; | |
139 this.sidebarPanes.callstack.addEventListener("call frame selected", this._ca
llFrameSelected, this); | |
140 | |
141 this.sidebarPanes.scopechain.expanded = true; | |
142 | |
143 var panelEnablerHeading = WebInspector.UIString("You need to enable debuggin
g before you can use the Scripts panel."); | |
144 var panelEnablerDisclaimer = WebInspector.UIString("Enabling debugging will
make scripts run slower."); | |
145 var panelEnablerButton = WebInspector.UIString("Enable Debugging"); | |
146 | |
147 this.panelEnablerView = new WebInspector.PanelEnablerView("scripts", panelEn
ablerHeading, panelEnablerDisclaimer, panelEnablerButton); | |
148 this.panelEnablerView.addEventListener("enable clicked", this._enableDebuggi
ng, this); | |
149 | |
150 this.element.appendChild(this.panelEnablerView.element); | |
151 this.element.appendChild(this.viewsContainerElement); | |
152 this.element.appendChild(this.sidebarElement); | |
153 this.element.appendChild(this.sidebarResizeElement); | |
154 | |
155 this.enableToggleButton = document.createElement("button"); | |
156 this.enableToggleButton.className = "enable-toggle-status-bar-item status-ba
r-item"; | |
157 this.enableToggleButton.addEventListener("click", this._toggleDebugging.bind
(this), false); | |
158 | |
159 this.pauseOnExceptionButton = document.createElement("button"); | |
160 this.pauseOnExceptionButton.id = "scripts-pause-on-exceptions-status-bar-ite
m"; | |
161 this.pauseOnExceptionButton.className = "status-bar-item"; | |
162 this.pauseOnExceptionButton.addEventListener("click", this._togglePauseOnExc
eptions.bind(this), false); | |
163 | |
164 this._breakpointsURLMap = {}; | |
165 | |
166 this.reset(); | |
167 } | |
168 | |
169 WebInspector.ScriptsPanel.prototype = { | |
170 toolbarItemClass: "scripts", | |
171 | |
172 get toolbarItemLabel() | |
173 { | |
174 return WebInspector.UIString("Scripts"); | |
175 }, | |
176 | |
177 get statusBarItems() | |
178 { | |
179 return [this.enableToggleButton, this.pauseOnExceptionButton]; | |
180 }, | |
181 | |
182 get paused() | |
183 { | |
184 return this._paused; | |
185 }, | |
186 | |
187 show: function() | |
188 { | |
189 WebInspector.Panel.prototype.show.call(this); | |
190 this.sidebarResizeElement.style.right = (this.sidebarElement.offsetWidth
- 3) + "px"; | |
191 | |
192 if (this.visibleView) { | |
193 if (this.visibleView instanceof WebInspector.ResourceView) | |
194 this.visibleView.headersVisible = false; | |
195 this.visibleView.show(this.viewsContainerElement); | |
196 } | |
197 | |
198 // Hide any views that are visible that are not this panel's current vis
ible view. | |
199 // This can happen when a ResourceView is visible in the Resources panel
then switched | |
200 // to the this panel. | |
201 for (var sourceID in this._sourceIDMap) { | |
202 var scriptOrResource = this._sourceIDMap[sourceID]; | |
203 var view = this._sourceViewForScriptOrResource(scriptOrResource); | |
204 if (!view || view === this.visibleView) | |
205 continue; | |
206 view.visible = false; | |
207 } | |
208 }, | |
209 | |
210 get searchableViews() | |
211 { | |
212 var views = []; | |
213 | |
214 const visibleView = this.visibleView; | |
215 if (visibleView && visibleView.performSearch) { | |
216 visibleView.alreadySearching = true; | |
217 views.push(visibleView); | |
218 } | |
219 | |
220 for (var sourceID in this._sourceIDMap) { | |
221 var scriptOrResource = this._sourceIDMap[sourceID]; | |
222 var view = this._sourceViewForScriptOrResource(scriptOrResource); | |
223 if (!view || !view.performSearch || view.alreadySearching) | |
224 continue; | |
225 | |
226 view.alreadySearching = true; | |
227 views.push(view); | |
228 } | |
229 | |
230 for (var i = 0; i < views.length; ++i) | |
231 delete views[i].alreadySearching; | |
232 | |
233 return views; | |
234 }, | |
235 | |
236 addScript: function(sourceID, sourceURL, source, startingLine, errorLine, er
rorMessage) | |
237 { | |
238 var script = new WebInspector.Script(sourceID, sourceURL, source, starti
ngLine, errorLine, errorMessage); | |
239 | |
240 if (sourceURL in WebInspector.resourceURLMap) { | |
241 var resource = WebInspector.resourceURLMap[sourceURL]; | |
242 resource.addScript(script); | |
243 } | |
244 | |
245 if (sourceURL in this._breakpointsURLMap && sourceID) { | |
246 var breakpoints = this._breakpointsURLMap[sourceURL]; | |
247 var breakpointsLength = breakpoints.length; | |
248 for (var i = 0; i < breakpointsLength; ++i) { | |
249 var breakpoint = breakpoints[i]; | |
250 if (startingLine <= breakpoint.line) { | |
251 breakpoint.sourceID = sourceID; | |
252 if (breakpoint.enabled) | |
253 InspectorController.addBreakpoint(breakpoint.sourceID, b
reakpoint.line); | |
254 } | |
255 } | |
256 } | |
257 | |
258 if (sourceID) | |
259 this._sourceIDMap[sourceID] = (resource || script); | |
260 | |
261 this._addScriptToFilesMenu(script); | |
262 }, | |
263 | |
264 addBreakpoint: function(breakpoint) | |
265 { | |
266 this.sidebarPanes.breakpoints.addBreakpoint(breakpoint); | |
267 | |
268 var sourceFrame; | |
269 if (breakpoint.url) { | |
270 if (!(breakpoint.url in this._breakpointsURLMap)) | |
271 this._breakpointsURLMap[breakpoint.url] = []; | |
272 this._breakpointsURLMap[breakpoint.url].unshift(breakpoint); | |
273 | |
274 if (breakpoint.url in WebInspector.resourceURLMap) { | |
275 var resource = WebInspector.resourceURLMap[breakpoint.url]; | |
276 sourceFrame = this._sourceFrameForScriptOrResource(resource); | |
277 } | |
278 } | |
279 | |
280 if (breakpoint.sourceID && !sourceFrame) { | |
281 var object = this._sourceIDMap[breakpoint.sourceID] | |
282 sourceFrame = this._sourceFrameForScriptOrResource(object); | |
283 } | |
284 | |
285 if (sourceFrame) | |
286 sourceFrame.addBreakpoint(breakpoint); | |
287 }, | |
288 | |
289 removeBreakpoint: function(breakpoint) | |
290 { | |
291 this.sidebarPanes.breakpoints.removeBreakpoint(breakpoint); | |
292 | |
293 var sourceFrame; | |
294 if (breakpoint.url && breakpoint.url in this._breakpointsURLMap) { | |
295 var breakpoints = this._breakpointsURLMap[breakpoint.url]; | |
296 breakpoints.remove(breakpoint); | |
297 if (!breakpoints.length) | |
298 delete this._breakpointsURLMap[breakpoint.url]; | |
299 | |
300 if (breakpoint.url in WebInspector.resourceURLMap) { | |
301 var resource = WebInspector.resourceURLMap[breakpoint.url]; | |
302 sourceFrame = this._sourceFrameForScriptOrResource(resource); | |
303 } | |
304 } | |
305 | |
306 if (breakpoint.sourceID && !sourceFrame) { | |
307 var object = this._sourceIDMap[breakpoint.sourceID] | |
308 sourceFrame = this._sourceFrameForScriptOrResource(object); | |
309 } | |
310 | |
311 if (sourceFrame) | |
312 sourceFrame.removeBreakpoint(breakpoint); | |
313 }, | |
314 | |
315 evaluateInSelectedCallFrame: function(code, updateInterface) | |
316 { | |
317 var selectedCallFrame = this.sidebarPanes.callstack.selectedCallFrame; | |
318 if (!this._paused || !selectedCallFrame) | |
319 return; | |
320 if (typeof updateInterface === "undefined") | |
321 updateInterface = true; | |
322 var result = selectedCallFrame.evaluate(code); | |
323 if (updateInterface) | |
324 this.sidebarPanes.scopechain.update(selectedCallFrame); | |
325 return result; | |
326 }, | |
327 | |
328 variablesInScopeForSelectedCallFrame: function() | |
329 { | |
330 var selectedCallFrame = this.sidebarPanes.callstack.selectedCallFrame; | |
331 if (!this._paused || !selectedCallFrame) | |
332 return {}; | |
333 | |
334 var result = {}; | |
335 var scopeChain = selectedCallFrame.scopeChain; | |
336 for (var i = 0; i < scopeChain.length; ++i) { | |
337 var scopeObject = scopeChain[i]; | |
338 for (var property in scopeObject) | |
339 result[property] = true; | |
340 } | |
341 | |
342 return result; | |
343 }, | |
344 | |
345 debuggerPaused: function() | |
346 { | |
347 this._paused = true; | |
348 this._waitingToPause = false; | |
349 this._stepping = false; | |
350 | |
351 this._updateDebuggerButtons(); | |
352 | |
353 var callStackPane = this.sidebarPanes.callstack; | |
354 var currentFrame = InspectorController.currentCallFrame(); | |
355 callStackPane.update(currentFrame, this._sourceIDMap); | |
356 callStackPane.selectedCallFrame = currentFrame; | |
357 | |
358 WebInspector.currentPanel = this; | |
359 window.focus(); | |
360 }, | |
361 | |
362 debuggerWasEnabled: function() | |
363 { | |
364 this.reset(); | |
365 }, | |
366 | |
367 debuggerWasDisabled: function() | |
368 { | |
369 this.reset(); | |
370 }, | |
371 | |
372 reset: function() | |
373 { | |
374 this.visibleView = null; | |
375 | |
376 delete this.currentQuery; | |
377 this.searchCanceled(); | |
378 | |
379 if (!InspectorController.debuggerEnabled()) { | |
380 this._paused = false; | |
381 this._waitingToPause = false; | |
382 this._stepping = false; | |
383 } | |
384 | |
385 this._clearInterface(); | |
386 | |
387 this._backForwardList = []; | |
388 this._currentBackForwardIndex = -1; | |
389 this._updateBackAndForwardButtons(); | |
390 | |
391 this._scriptsForURLsInFilesSelect = {}; | |
392 this.filesSelectElement.removeChildren(); | |
393 this.functionsSelectElement.removeChildren(); | |
394 this.viewsContainerElement.removeChildren(); | |
395 | |
396 if (this._sourceIDMap) { | |
397 for (var sourceID in this._sourceIDMap) { | |
398 var object = this._sourceIDMap[sourceID]; | |
399 if (object instanceof WebInspector.Resource) | |
400 object.removeAllScripts(); | |
401 } | |
402 } | |
403 | |
404 this._sourceIDMap = {}; | |
405 }, | |
406 | |
407 get visibleView() | |
408 { | |
409 return this._visibleView; | |
410 }, | |
411 | |
412 set visibleView(x) | |
413 { | |
414 if (this._visibleView === x) | |
415 return; | |
416 | |
417 if (this._visibleView) | |
418 this._visibleView.hide(); | |
419 | |
420 this._visibleView = x; | |
421 | |
422 if (x) | |
423 x.show(this.viewsContainerElement); | |
424 }, | |
425 | |
426 canShowResource: function(resource) | |
427 { | |
428 return resource && resource.scripts.length && InspectorController.debugg
erEnabled(); | |
429 }, | |
430 | |
431 showScript: function(script, line) | |
432 { | |
433 this._showScriptOrResource(script, line, true); | |
434 }, | |
435 | |
436 showResource: function(resource, line) | |
437 { | |
438 this._showScriptOrResource(resource, line, true); | |
439 }, | |
440 | |
441 showView: function(view) | |
442 { | |
443 if (!view) | |
444 return; | |
445 this._showScriptOrResource((view.resource || view.script)); | |
446 }, | |
447 | |
448 scriptViewForScript: function(script) | |
449 { | |
450 if (!script) | |
451 return null; | |
452 if (!script._scriptView) | |
453 script._scriptView = new WebInspector.ScriptView(script); | |
454 return script._scriptView; | |
455 }, | |
456 | |
457 sourceFrameForScript: function(script) | |
458 { | |
459 var view = this.scriptViewForScript(script); | |
460 if (!view) | |
461 return null; | |
462 | |
463 // Setting up the source frame requires that we be attached. | |
464 if (!this.element.parentNode) | |
465 this.attach(); | |
466 | |
467 view.setupSourceFrameIfNeeded(); | |
468 return view.sourceFrame; | |
469 }, | |
470 | |
471 _sourceViewForScriptOrResource: function(scriptOrResource) | |
472 { | |
473 if (scriptOrResource instanceof WebInspector.Resource) { | |
474 if (!WebInspector.panels.resources) | |
475 return null; | |
476 return WebInspector.panels.resources.resourceViewForResource(scriptO
rResource); | |
477 } | |
478 if (scriptOrResource instanceof WebInspector.Script) | |
479 return this.scriptViewForScript(scriptOrResource); | |
480 }, | |
481 | |
482 _sourceFrameForScriptOrResource: function(scriptOrResource) | |
483 { | |
484 if (scriptOrResource instanceof WebInspector.Resource) { | |
485 if (!WebInspector.panels.resources) | |
486 return null; | |
487 return WebInspector.panels.resources.sourceFrameForResource(scriptOr
Resource); | |
488 } | |
489 if (scriptOrResource instanceof WebInspector.Script) | |
490 return this.sourceFrameForScript(scriptOrResource); | |
491 }, | |
492 | |
493 _showScriptOrResource: function(scriptOrResource, line, shouldHighlightLine,
fromBackForwardAction) | |
494 { | |
495 if (!scriptOrResource) | |
496 return; | |
497 | |
498 var view; | |
499 if (scriptOrResource instanceof WebInspector.Resource) { | |
500 if (!WebInspector.panels.resources) | |
501 return null; | |
502 view = WebInspector.panels.resources.resourceViewForResource(scriptO
rResource); | |
503 view.headersVisible = false; | |
504 | |
505 if (scriptOrResource.url in this._breakpointsURLMap) { | |
506 var sourceFrame = this._sourceFrameForScriptOrResource(scriptOrR
esource); | |
507 if (sourceFrame && !sourceFrame.breakpoints.length) { | |
508 var breakpoints = this._breakpointsURLMap[scriptOrResource.u
rl]; | |
509 var breakpointsLength = breakpoints.length; | |
510 for (var i = 0; i < breakpointsLength; ++i) | |
511 sourceFrame.addBreakpoint(breakpoints[i]); | |
512 } | |
513 } | |
514 } else if (scriptOrResource instanceof WebInspector.Script) | |
515 view = this.scriptViewForScript(scriptOrResource); | |
516 | |
517 if (!view) | |
518 return; | |
519 | |
520 if (!fromBackForwardAction) { | |
521 var oldIndex = this._currentBackForwardIndex; | |
522 if (oldIndex >= 0) | |
523 this._backForwardList.splice(oldIndex + 1, this._backForwardList
.length - oldIndex); | |
524 | |
525 // Check for a previous entry of the same object in _backForwardList
. | |
526 // If one is found, remove it and update _currentBackForwardIndex to
match. | |
527 var previousEntryIndex = this._backForwardList.indexOf(scriptOrResou
rce); | |
528 if (previousEntryIndex !== -1) { | |
529 this._backForwardList.splice(previousEntryIndex, 1); | |
530 --this._currentBackForwardIndex; | |
531 } | |
532 | |
533 this._backForwardList.push(scriptOrResource); | |
534 ++this._currentBackForwardIndex; | |
535 | |
536 this._updateBackAndForwardButtons(); | |
537 } | |
538 | |
539 this.visibleView = view; | |
540 | |
541 if (line) { | |
542 if (view.revealLine) | |
543 view.revealLine(line); | |
544 if (view.highlightLine && shouldHighlightLine) | |
545 view.highlightLine(line); | |
546 } | |
547 | |
548 var option; | |
549 if (scriptOrResource instanceof WebInspector.Script) { | |
550 option = scriptOrResource.filesSelectOption; | |
551 console.assert(option); | |
552 } else { | |
553 var url = scriptOrResource.url; | |
554 var script = this._scriptsForURLsInFilesSelect[url]; | |
555 if (script) | |
556 option = script.filesSelectOption; | |
557 } | |
558 | |
559 if (option) | |
560 this.filesSelectElement.selectedIndex = option.index; | |
561 }, | |
562 | |
563 _addScriptToFilesMenu: function(script) | |
564 { | |
565 if (script.resource && this._scriptsForURLsInFilesSelect[script.sourceUR
L]) | |
566 return; | |
567 | |
568 this._scriptsForURLsInFilesSelect[script.sourceURL] = script; | |
569 | |
570 var select = this.filesSelectElement; | |
571 | |
572 // FIXME: Append in some meaningful order. | |
573 var option = document.createElement("option"); | |
574 option.representedObject = (script.resource || script); | |
575 option.text = (script.sourceURL ? WebInspector.displayNameForURL(script.
sourceURL) : WebInspector.UIString("(program)")); | |
576 select.appendChild(option); | |
577 | |
578 script.filesSelectOption = option; | |
579 | |
580 // Call _showScriptOrResource if the option we just appended ended up be
ing selected. | |
581 // This will happen for the first item added to the menu. | |
582 if (select.options[select.selectedIndex] === option) | |
583 this._showScriptOrResource(option.representedObject); | |
584 }, | |
585 | |
586 _clearCurrentExecutionLine: function() | |
587 { | |
588 if (this._executionSourceFrame) | |
589 this._executionSourceFrame.executionLine = 0; | |
590 delete this._executionSourceFrame; | |
591 }, | |
592 | |
593 _callFrameSelected: function() | |
594 { | |
595 this._clearCurrentExecutionLine(); | |
596 | |
597 var callStackPane = this.sidebarPanes.callstack; | |
598 var currentFrame = callStackPane.selectedCallFrame; | |
599 if (!currentFrame) | |
600 return; | |
601 | |
602 this.sidebarPanes.scopechain.update(currentFrame); | |
603 | |
604 var scriptOrResource = this._sourceIDMap[currentFrame.sourceID]; | |
605 this._showScriptOrResource(scriptOrResource, currentFrame.line); | |
606 | |
607 this._executionSourceFrame = this._sourceFrameForScriptOrResource(script
OrResource); | |
608 if (this._executionSourceFrame) | |
609 this._executionSourceFrame.executionLine = currentFrame.line; | |
610 }, | |
611 | |
612 _changeVisibleFile: function(event) | |
613 { | |
614 var select = this.filesSelectElement; | |
615 this._showScriptOrResource(select.options[select.selectedIndex].represen
tedObject); | |
616 }, | |
617 | |
618 _startSidebarResizeDrag: function(event) | |
619 { | |
620 WebInspector.elementDragStart(this.sidebarElement, this._sidebarResizeDr
ag.bind(this), this._endSidebarResizeDrag.bind(this), event, "col-resize"); | |
621 | |
622 if (event.target === this.sidebarResizeWidgetElement) | |
623 this._dragOffset = (event.target.offsetWidth - (event.pageX - event.
target.totalOffsetLeft)); | |
624 else | |
625 this._dragOffset = 0; | |
626 }, | |
627 | |
628 _endSidebarResizeDrag: function(event) | |
629 { | |
630 WebInspector.elementDragEnd(event); | |
631 | |
632 delete this._dragOffset; | |
633 }, | |
634 | |
635 _sidebarResizeDrag: function(event) | |
636 { | |
637 var x = event.pageX + this._dragOffset; | |
638 var newWidth = Number.constrain(window.innerWidth - x, Preferences.minSc
riptsSidebarWidth, window.innerWidth * 0.66); | |
639 | |
640 this.sidebarElement.style.width = newWidth + "px"; | |
641 this.sidebarButtonsElement.style.width = newWidth + "px"; | |
642 this.viewsContainerElement.style.right = newWidth + "px"; | |
643 this.sidebarResizeWidgetElement.style.right = newWidth + "px"; | |
644 this.sidebarResizeElement.style.right = (newWidth - 3) + "px"; | |
645 | |
646 event.preventDefault(); | |
647 }, | |
648 | |
649 _updatePauseOnExceptionsButton: function() | |
650 { | |
651 if (InspectorController.pauseOnExceptions()) { | |
652 this.pauseOnExceptionButton.title = WebInspector.UIString("Don't pau
se on exceptions."); | |
653 this.pauseOnExceptionButton.addStyleClass("toggled-on"); | |
654 } else { | |
655 this.pauseOnExceptionButton.title = WebInspector.UIString("Pause on
exceptions."); | |
656 this.pauseOnExceptionButton.removeStyleClass("toggled-on"); | |
657 } | |
658 }, | |
659 | |
660 _updateDebuggerButtons: function() | |
661 { | |
662 if (InspectorController.debuggerEnabled()) { | |
663 this.enableToggleButton.title = WebInspector.UIString("Debugging ena
bled. Click to disable."); | |
664 this.enableToggleButton.addStyleClass("toggled-on"); | |
665 this.pauseOnExceptionButton.removeStyleClass("hidden"); | |
666 this.panelEnablerView.visible = false; | |
667 } else { | |
668 this.enableToggleButton.title = WebInspector.UIString("Debugging dis
abled. Click to enable."); | |
669 this.enableToggleButton.removeStyleClass("toggled-on"); | |
670 this.pauseOnExceptionButton.addStyleClass("hidden"); | |
671 this.panelEnablerView.visible = true; | |
672 } | |
673 | |
674 this._updatePauseOnExceptionsButton(); | |
675 | |
676 if (this._paused) { | |
677 this.pauseButton.addStyleClass("paused"); | |
678 | |
679 this.pauseButton.disabled = false; | |
680 this.stepOverButton.disabled = false; | |
681 this.stepIntoButton.disabled = false; | |
682 this.stepOutButton.disabled = false; | |
683 | |
684 this.debuggerStatusElement.textContent = WebInspector.UIString("Paus
ed"); | |
685 } else { | |
686 this.pauseButton.removeStyleClass("paused"); | |
687 | |
688 this.pauseButton.disabled = this._waitingToPause; | |
689 this.stepOverButton.disabled = true; | |
690 this.stepIntoButton.disabled = true; | |
691 this.stepOutButton.disabled = true; | |
692 | |
693 if (this._waitingToPause) | |
694 this.debuggerStatusElement.textContent = WebInspector.UIString("
Pausing"); | |
695 else if (this._stepping) | |
696 this.debuggerStatusElement.textContent = WebInspector.UIString("
Stepping"); | |
697 else | |
698 this.debuggerStatusElement.textContent = ""; | |
699 } | |
700 }, | |
701 | |
702 _updateBackAndForwardButtons: function() | |
703 { | |
704 this.backButton.disabled = this._currentBackForwardIndex <= 0; | |
705 this.forwardButton.disabled = this._currentBackForwardIndex >= (this._ba
ckForwardList.length - 1); | |
706 }, | |
707 | |
708 _clearInterface: function() | |
709 { | |
710 this.sidebarPanes.callstack.update(null); | |
711 this.sidebarPanes.scopechain.update(null); | |
712 | |
713 this._clearCurrentExecutionLine(); | |
714 this._updateDebuggerButtons(); | |
715 }, | |
716 | |
717 _goBack: function() | |
718 { | |
719 if (this._currentBackForwardIndex <= 0) { | |
720 console.error("Can't go back from index " + this._currentBackForward
Index); | |
721 return; | |
722 } | |
723 | |
724 this._showScriptOrResource(this._backForwardList[--this._currentBackForw
ardIndex], null, false, true); | |
725 this._updateBackAndForwardButtons(); | |
726 }, | |
727 | |
728 _goForward: function() | |
729 { | |
730 if (this._currentBackForwardIndex >= this._backForwardList.length - 1) { | |
731 console.error("Can't go forward from index " + this._currentBackForw
ardIndex); | |
732 return; | |
733 } | |
734 | |
735 this._showScriptOrResource(this._backForwardList[++this._currentBackForw
ardIndex], null, false, true); | |
736 this._updateBackAndForwardButtons(); | |
737 }, | |
738 | |
739 _enableDebugging: function() | |
740 { | |
741 if (InspectorController.debuggerEnabled()) | |
742 return; | |
743 this._toggleDebugging(); | |
744 }, | |
745 | |
746 _toggleDebugging: function() | |
747 { | |
748 this._paused = false; | |
749 this._waitingToPause = false; | |
750 this._stepping = false; | |
751 | |
752 if (InspectorController.debuggerEnabled()) | |
753 InspectorController.disableDebugger(); | |
754 else | |
755 InspectorController.enableDebugger(); | |
756 }, | |
757 | |
758 _togglePauseOnExceptions: function() | |
759 { | |
760 InspectorController.setPauseOnExceptions(!InspectorController.pauseOnExc
eptions()); | |
761 this._updatePauseOnExceptionsButton(); | |
762 }, | |
763 | |
764 _togglePause: function() | |
765 { | |
766 if (this._paused) { | |
767 this._paused = false; | |
768 this._waitingToPause = false; | |
769 InspectorController.resumeDebugger(); | |
770 } else { | |
771 this._stepping = false; | |
772 this._waitingToPause = true; | |
773 InspectorController.pauseInDebugger(); | |
774 } | |
775 | |
776 this._clearInterface(); | |
777 }, | |
778 | |
779 _stepOverClicked: function() | |
780 { | |
781 this._paused = false; | |
782 this._stepping = true; | |
783 | |
784 this._clearInterface(); | |
785 | |
786 InspectorController.stepOverStatementInDebugger(); | |
787 }, | |
788 | |
789 _stepIntoClicked: function() | |
790 { | |
791 this._paused = false; | |
792 this._stepping = true; | |
793 | |
794 this._clearInterface(); | |
795 | |
796 InspectorController.stepIntoStatementInDebugger(); | |
797 }, | |
798 | |
799 _stepOutClicked: function() | |
800 { | |
801 this._paused = false; | |
802 this._stepping = true; | |
803 | |
804 this._clearInterface(); | |
805 | |
806 InspectorController.stepOutOfFunctionInDebugger(); | |
807 } | |
808 } | |
809 | |
810 WebInspector.ScriptsPanel.prototype.__proto__ = WebInspector.Panel.prototype; | |
OLD | NEW |