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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sources/CallStackSidebarPane.js

Issue 2238003002: DevTools: migrate sources panel sidebar to views. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments addressed Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 /** 26 /**
27 * @constructor 27 * @constructor
28 * @extends {WebInspector.SimpleView} 28 * @extends {WebInspector.SimpleView}
29 * @implements {WebInspector.ContextFlavorListener}
29 */ 30 */
30 WebInspector.CallStackSidebarPane = function() 31 WebInspector.CallStackSidebarPane = function()
31 { 32 {
32 WebInspector.SimpleView.call(this, WebInspector.UIString("Call Stack")); 33 WebInspector.SimpleView.call(this, WebInspector.UIString("Call Stack"));
33 this.element.addEventListener("keydown", this._keyDown.bind(this), true); 34 this.element.addEventListener("keydown", this._keyDown.bind(this), true);
34 this.element.tabIndex = 0; 35 this.element.tabIndex = 0;
35 this.callFrameList = new WebInspector.UIList(); 36 this.callFrameList = new WebInspector.UIList();
36 this.callFrameList.show(this.element); 37 this.callFrameList.show(this.element);
37 this._linkifier = new WebInspector.Linkifier(); 38 this._linkifier = new WebInspector.Linkifier();
38 WebInspector.moduleSetting("enableAsyncStackTraces").addChangeListener(this. _asyncStackTracesStateChanged, this); 39 WebInspector.moduleSetting("enableAsyncStackTraces").addChangeListener(this. _asyncStackTracesStateChanged, this);
39 WebInspector.moduleSetting("skipStackFramesPattern").addChangeListener(this. _update, this); 40 WebInspector.moduleSetting("skipStackFramesPattern").addChangeListener(this. _update, this);
40 /** @type {!Array<!WebInspector.CallStackSidebarPane.CallFrame>} */ 41 /** @type {!Array<!WebInspector.CallStackSidebarPane.CallFrame>} */
41 this.callFrames = []; 42 this.callFrames = [];
42 this._locationPool = new WebInspector.LiveLocationPool(); 43 this._locationPool = new WebInspector.LiveLocationPool();
43 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.DebuggerPaused, this._update, this); 44 this._update();
44 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.DebuggerResumed, this._update, this);
45 WebInspector.context.addFlavorChangeListener(WebInspector.Target, this._upda te, this);
46 WebInspector.context.addFlavorChangeListener(WebInspector.DebuggerModel.Call Frame, this._updateCallFrame, this);
47 } 45 }
48 46
49 WebInspector.CallStackSidebarPane.prototype = { 47 WebInspector.CallStackSidebarPane.prototype = {
48 /**
49 * @override
50 * @param {?Object} object
51 */
52 flavorChanged: function(object)
53 {
54 this._update();
55 },
56
50 _update: function() 57 _update: function()
51 { 58 {
52 var target = WebInspector.context.flavor(WebInspector.Target); 59 var details = WebInspector.context.flavor(WebInspector.DebuggerPausedDet ails);
53 var debuggerModel = WebInspector.DebuggerModel.fromTarget(target);
54 var details = debuggerModel ? debuggerModel.debuggerPausedDetails() : nu ll;
55 60
56 this.callFrameList.detach(); 61 this.callFrameList.detach();
57 this.callFrameList.clear(); 62 this.callFrameList.clear();
58 this._linkifier.reset(); 63 this._linkifier.reset();
59 this.element.removeChildren(); 64 this.element.removeChildren();
60 this._locationPool.disposeAll(); 65 this._locationPool.disposeAll();
61 66
62 if (!details) {
63 var infoElement = this.element.createChild("div", "callstack-info");
64 infoElement.textContent = WebInspector.UIString("Not Paused");
65 return;
66 }
67
68 this.callFrameList.show(this.element); 67 this.callFrameList.show(this.element);
69 this._debuggerModel = details.debuggerModel;
70 var asyncStackTrace = details.asyncStackTrace;
71
72 delete this._statusMessageElement;
73 delete this._hiddenCallFramesMessageElement; 68 delete this._hiddenCallFramesMessageElement;
74 this.callFrames = []; 69 this.callFrames = [];
75 this._hiddenCallFrames = 0; 70 this._hiddenCallFrames = 0;
76 71
72 this._updateStatusMessage(details);
73
74 if (!details) {
75 WebInspector.context.setFlavor(WebInspector.DebuggerModel.CallFrame, null);
76 return;
77 }
78 this._debuggerModel = details.debuggerModel;
79 var asyncStackTrace = details.asyncStackTrace;
80
77 this._appendSidebarCallFrames(this._callFramesFromDebugger(details.callF rames)); 81 this._appendSidebarCallFrames(this._callFramesFromDebugger(details.callF rames));
78 var topStackHidden = (this._hiddenCallFrames === this.callFrames.length) ; 82 var topStackHidden = (this._hiddenCallFrames === this.callFrames.length) ;
79 83
80 while (asyncStackTrace) { 84 while (asyncStackTrace) {
81 var title = WebInspector.asyncStackTraceLabel(asyncStackTrace.descri ption); 85 var title = WebInspector.asyncStackTraceLabel(asyncStackTrace.descri ption);
82 var asyncCallFrame = new WebInspector.UIList.Item(title, "", true); 86 var asyncCallFrame = new WebInspector.UIList.Item(title, "", true);
83 asyncCallFrame.setHoverable(false); 87 asyncCallFrame.setHoverable(false);
84 asyncCallFrame.element.addEventListener("contextmenu", this._asyncCa llFrameContextMenu.bind(this, this.callFrames.length), true); 88 asyncCallFrame.element.addEventListener("contextmenu", this._asyncCa llFrameContextMenu.bind(this, this.callFrames.length), true);
85 this._appendSidebarCallFrames(this._callFramesFromRuntime(asyncStack Trace.callFrames, asyncCallFrame), asyncCallFrame); 89 this._appendSidebarCallFrames(this._callFramesFromRuntime(asyncStack Trace.callFrames, asyncCallFrame), asyncCallFrame);
86 asyncStackTrace = asyncStackTrace.parent; 90 asyncStackTrace = asyncStackTrace.parent;
87 } 91 }
88 92
89 if (topStackHidden) 93 if (topStackHidden)
90 this._revealHiddenCallFrames(); 94 this._revealHiddenCallFrames();
91 if (this._hiddenCallFrames) { 95 if (this._hiddenCallFrames) {
92 var element = createElementWithClass("div", "hidden-callframes-messa ge"); 96 var element = createElementWithClass("div", "hidden-callframes-messa ge");
93 if (this._hiddenCallFrames === 1) 97 if (this._hiddenCallFrames === 1)
94 element.textContent = WebInspector.UIString("1 stack frame is hi dden (black-boxed)."); 98 element.textContent = WebInspector.UIString("1 stack frame is hi dden (black-boxed).");
95 else 99 else
96 element.textContent = WebInspector.UIString("%d stack frames are hidden (black-boxed).", this._hiddenCallFrames); 100 element.textContent = WebInspector.UIString("%d stack frames are hidden (black-boxed).", this._hiddenCallFrames);
97 element.createTextChild(" "); 101 element.createTextChild(" ");
98 var showAllLink = element.createChild("span", "link"); 102 var showAllLink = element.createChild("span", "link");
99 showAllLink.textContent = WebInspector.UIString("Show"); 103 showAllLink.textContent = WebInspector.UIString("Show");
100 showAllLink.addEventListener("click", this._revealHiddenCallFrames.b ind(this), false); 104 showAllLink.addEventListener("click", this._revealHiddenCallFrames.b ind(this), false);
101 this.element.insertBefore(element, this.element.firstChild); 105 this.element.insertBefore(element, this.element.firstChild);
102 this._hiddenCallFramesMessageElement = element; 106 this._hiddenCallFramesMessageElement = element;
103 } 107 }
104 WebInspector.viewManager.revealViewWithWidget(this); 108 this._selectNextVisibleCallFrame(0);
109 this.revealView();
105 }, 110 },
106 111
107 /** 112 /**
113 * @param {?WebInspector.DebuggerPausedDetails} details
114 */
115 _updateStatusMessage: function(details)
116 {
117 var status = this.contentElement.createChild("div", "callstack-info");
118 status.removeChildren();
119
120 if (!details) {
121 status.textContent = WebInspector.UIString("Not Paused");
122 status.classList.toggle("status", false);
123 return;
124 }
125
126 if (details.reason === WebInspector.DebuggerModel.BreakReason.DOM) {
127 status.appendChild(WebInspector.domBreakpointsSidebarPane.createBrea kpointHitStatusMessage(details));
128 } else if (details.reason === WebInspector.DebuggerModel.BreakReason.Eve ntListener) {
129 var eventName = details.auxData["eventName"];
130 var eventNameForUI = WebInspector.EventListenerBreakpointsSidebarPan e.eventNameForUI(eventName, details.auxData);
131 status.textContent = WebInspector.UIString("Paused on a \"%s\" Event Listener.", eventNameForUI);
132 } else if (details.reason === WebInspector.DebuggerModel.BreakReason.XHR ) {
133 status.textContent = WebInspector.UIString("Paused on a XMLHttpReque st.");
134 } else if (details.reason === WebInspector.DebuggerModel.BreakReason.Exc eption) {
135 var description = details.auxData["description"] || "";
136 status.textContent = WebInspector.UIString("Paused on exception: '%s '.", description.split("\n", 1)[0]);
137 } else if (details.reason === WebInspector.DebuggerModel.BreakReason.Pro miseRejection) {
138 var description = details.auxData["description"] || "";
139 status.textContent = WebInspector.UIString("Paused on promise reject ion: '%s'.", description.split("\n", 1)[0]);
140 } else if (details.reason === WebInspector.DebuggerModel.BreakReason.Ass ert) {
141 status.textContent = WebInspector.UIString("Paused on assertion.");
142 } else if (details.reason === WebInspector.DebuggerModel.BreakReason.Deb ugCommand) {
143 status.textContent = WebInspector.UIString("Paused on a debugged fun ction.");
144 } else {
145 if (details.callFrames.length) {
146 var uiLocation = details && details.callFrames.length ? WebInspe ctor.debuggerWorkspaceBinding.rawLocationToUILocation(details.callFrames[0].loca tion()) : null;
147 var breakpoint = uiLocation ? WebInspector.breakpointManager.fin dBreakpointOnLine(uiLocation.uiSourceCode, uiLocation.lineNumber) : null;
148 if (breakpoint) {
149 status.textContent = WebInspector.UIString("Paused on a Java Script breakpoint.");
150 }
151 } else {
152 console.warn("ScriptsPanel paused, but callFrames.length is zero ."); // TODO remove this once we understand this case better
153 }
154 }
155 status.classList.toggle("hidden", !status.firstChild);
156 },
157
158 /**
108 * @param {!Array.<!WebInspector.DebuggerModel.CallFrame>} callFrames 159 * @param {!Array.<!WebInspector.DebuggerModel.CallFrame>} callFrames
109 * @return {!Array<!WebInspector.CallStackSidebarPane.CallFrame>} 160 * @return {!Array<!WebInspector.CallStackSidebarPane.CallFrame>}
110 */ 161 */
111 _callFramesFromDebugger: function(callFrames) 162 _callFramesFromDebugger: function(callFrames)
112 { 163 {
113 var callFrameItems = []; 164 var callFrameItems = [];
114 for (var i = 0, n = callFrames.length; i < n; ++i) { 165 for (var i = 0, n = callFrames.length; i < n; ++i) {
115 var callFrame = callFrames[i]; 166 var callFrame = callFrames[i];
116 var callFrameItem = new WebInspector.CallStackSidebarPane.CallFrame( callFrame.functionName, callFrame.location(), this._linkifier, callFrame, this._ locationPool); 167 var callFrameItem = new WebInspector.CallStackSidebarPane.CallFrame( callFrame.functionName, callFrame.location(), this._linkifier, callFrame, this._ locationPool);
117 callFrameItem.element.addEventListener("click", this._callFrameSelec ted.bind(this, callFrameItem), false); 168 callFrameItem.element.addEventListener("click", this._callFrameSelec ted.bind(this, callFrameItem), false);
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 callFrame.element.remove(); 320 callFrame.element.remove();
270 } else { 321 } else {
271 lastSyncCallFrameIndex = i; 322 lastSyncCallFrameIndex = i;
272 } 323 }
273 } 324 }
274 this.callFrames.length = lastSyncCallFrameIndex + 1; 325 this.callFrames.length = lastSyncCallFrameIndex + 1;
275 if (shouldSelectTopFrame) 326 if (shouldSelectTopFrame)
276 this._selectNextVisibleCallFrame(0); 327 this._selectNextVisibleCallFrame(0);
277 }, 328 },
278 329
279 _updateCallFrame: function()
280 {
281 var selectedCallFrame = WebInspector.context.flavor(WebInspector.Debugge rModel.CallFrame);
282 for (var i = 0; i < this.callFrames.length; ++i) {
283 var callFrame = this.callFrames[i];
284 callFrame.setSelected(callFrame._debuggerCallFrame === selectedCallF rame);
285 if (callFrame.isSelected() && callFrame.isHidden())
286 this._revealHiddenCallFrames();
287 }
288 },
289
290 /** 330 /**
291 * @return {boolean} 331 * @return {boolean}
292 */ 332 */
293 _selectNextCallFrameOnStack: function() 333 _selectNextCallFrameOnStack: function()
294 { 334 {
295 var index = this._selectedCallFrameIndex(); 335 var index = this._selectedCallFrameIndex();
296 if (index === -1) 336 if (index === -1)
297 return false; 337 return false;
298 return this._selectNextVisibleCallFrame(index + 1); 338 return this._selectNextVisibleCallFrame(index + 1);
299 }, 339 },
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 /** 387 /**
348 * @param {!WebInspector.CallStackSidebarPane.CallFrame} callFrameItem 388 * @param {!WebInspector.CallStackSidebarPane.CallFrame} callFrameItem
349 */ 389 */
350 _asyncCallFrameClicked: function(callFrameItem) 390 _asyncCallFrameClicked: function(callFrameItem)
351 { 391 {
352 var uiLocation = WebInspector.debuggerWorkspaceBinding.rawLocationToUILo cation(callFrameItem._location); 392 var uiLocation = WebInspector.debuggerWorkspaceBinding.rawLocationToUILo cation(callFrameItem._location);
353 WebInspector.Revealer.reveal(uiLocation); 393 WebInspector.Revealer.reveal(uiLocation);
354 }, 394 },
355 395
356 /** 396 /**
357 * @param {!WebInspector.CallStackSidebarPane.CallFrame} callFrameItem 397 * @param {!WebInspector.CallStackSidebarPane.CallFrame} selectedCallFrame
358 */ 398 */
359 _callFrameSelected: function(callFrameItem) 399 _callFrameSelected: function(selectedCallFrame)
360 { 400 {
361 callFrameItem.element.scrollIntoViewIfNeeded(); 401 selectedCallFrame.element.scrollIntoViewIfNeeded();
362 var callFrame = callFrameItem._debuggerCallFrame; 402 var callFrame = selectedCallFrame._debuggerCallFrame;
363 if (callFrame) 403
364 callFrame.debuggerModel.setSelectedCallFrame(callFrame); 404 for (var i = 0; i < this.callFrames.length; ++i) {
405 var callFrameItem = this.callFrames[i];
406 callFrameItem.setSelected(callFrameItem === selectedCallFrame);
407 if (callFrameItem.isSelected() && callFrameItem.isHidden())
408 this._revealHiddenCallFrames();
409 }
410
411 WebInspector.context.setFlavor(WebInspector.DebuggerModel.CallFrame, cal lFrame);
412 callFrame.debuggerModel.setSelectedCallFrame(callFrame);
365 }, 413 },
366 414
367 _copyStackTrace: function() 415 _copyStackTrace: function()
368 { 416 {
369 var text = ""; 417 var text = "";
370 var lastCallFrame = null; 418 var lastCallFrame = null;
371 for (var i = 0; i < this.callFrames.length; ++i) { 419 for (var i = 0; i < this.callFrames.length; ++i) {
372 var callFrame = this.callFrames[i]; 420 var callFrame = this.callFrames[i];
373 if (callFrame.isHidden()) 421 if (callFrame.isHidden())
374 continue; 422 continue;
375 if (lastCallFrame && callFrame._asyncCallFrame !== lastCallFrame._as yncCallFrame) 423 if (lastCallFrame && callFrame._asyncCallFrame !== lastCallFrame._as yncCallFrame)
376 text += callFrame._asyncCallFrame.title() + "\n"; 424 text += callFrame._asyncCallFrame.title() + "\n";
377 text += callFrame.title() + " (" + callFrame.subtitle() + ")\n"; 425 text += callFrame.title() + " (" + callFrame.subtitle() + ")\n";
378 lastCallFrame = callFrame; 426 lastCallFrame = callFrame;
379 } 427 }
380 InspectorFrontendHost.copyText(text); 428 InspectorFrontendHost.copyText(text);
381 }, 429 },
382 430
383 /** 431 /**
384 * @param {function(!Array.<!WebInspector.KeyboardShortcut.Descriptor>, func tion(!Event=):boolean)} registerShortcutDelegate 432 * @param {function(!Array.<!WebInspector.KeyboardShortcut.Descriptor>, func tion(!Event=):boolean)} registerShortcutDelegate
385 */ 433 */
386 registerShortcuts: function(registerShortcutDelegate) 434 registerShortcuts: function(registerShortcutDelegate)
387 { 435 {
388 registerShortcutDelegate(WebInspector.ShortcutsScreen.SourcesPanelShortc uts.NextCallFrame, this._selectNextCallFrameOnStack.bind(this)); 436 registerShortcutDelegate(WebInspector.ShortcutsScreen.SourcesPanelShortc uts.NextCallFrame, this._selectNextCallFrameOnStack.bind(this));
389 registerShortcutDelegate(WebInspector.ShortcutsScreen.SourcesPanelShortc uts.PrevCallFrame, this._selectPreviousCallFrameOnStack.bind(this)); 437 registerShortcutDelegate(WebInspector.ShortcutsScreen.SourcesPanelShortc uts.PrevCallFrame, this._selectPreviousCallFrameOnStack.bind(this));
390 }, 438 },
391 439
392 /**
393 * @param {!Element|string} status
394 */
395 setStatus: function(status)
396 {
397 if (!this._statusMessageElement)
398 this._statusMessageElement = this.element.createChild("div", "callst ack-info status");
399 if (typeof status === "string") {
400 this._statusMessageElement.textContent = status;
401 } else {
402 this._statusMessageElement.removeChildren();
403 this._statusMessageElement.appendChild(status);
404 }
405 },
406
407 _keyDown: function(event) 440 _keyDown: function(event)
408 { 441 {
409 if (event.altKey || event.shiftKey || event.metaKey || event.ctrlKey) 442 if (event.altKey || event.shiftKey || event.metaKey || event.ctrlKey)
410 return; 443 return;
411 if (event.key === "ArrowUp" && this._selectPreviousCallFrameOnStack() || event.key === "ArrowDown" && this._selectNextCallFrameOnStack()) 444 if (event.key === "ArrowUp" && this._selectPreviousCallFrameOnStack() || event.key === "ArrowDown" && this._selectNextCallFrameOnStack())
412 event.consume(true); 445 event.consume(true);
413 }, 446 },
414 447
415 __proto__: WebInspector.SimpleView.prototype 448 __proto__: WebInspector.SimpleView.prototype
416 } 449 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 var uiLocation = liveLocation.uiLocation(); 484 var uiLocation = liveLocation.uiLocation();
452 if (!uiLocation) 485 if (!uiLocation)
453 return; 486 return;
454 var text = uiLocation.linkText(); 487 var text = uiLocation.linkText();
455 this.setSubtitle(text.trimMiddle(30)); 488 this.setSubtitle(text.trimMiddle(30));
456 this.subtitleElement.title = text; 489 this.subtitleElement.title = text;
457 }, 490 },
458 491
459 __proto__: WebInspector.UIList.Item.prototype 492 __proto__: WebInspector.UIList.Item.prototype
460 } 493 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698