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/JavaScriptOutlineDialog.js

Issue 2570263002: DevTools: introduce API for the Common.FormatterWorkerPool. (Closed)
Patch Set: address comments Created 4 years 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) 2012 The Chromium Authors. All rights reserved. 2 * Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 /** 7 /**
8 * @unrestricted 8 * @unrestricted
9 */ 9 */
10 Sources.JavaScriptOutlineDialog = class extends UI.FilteredListWidget.Delegate { 10 Sources.JavaScriptOutlineDialog = class extends UI.FilteredListWidget.Delegate {
11 /** 11 /**
12 * @param {!Workspace.UISourceCode} uiSourceCode 12 * @param {!Workspace.UISourceCode} uiSourceCode
13 * @param {function(number, number)} selectItemCallback 13 * @param {function(number, number)} selectItemCallback
14 */ 14 */
15 constructor(uiSourceCode, selectItemCallback) { 15 constructor(uiSourceCode, selectItemCallback) {
16 super([]); 16 super([]);
17 17
18 this._functionItems = []; 18 this._functionItems = [];
19 this._selectItemCallback = selectItemCallback; 19 this._selectItemCallback = selectItemCallback;
20 Common.formatterWorkerPool.runChunkedTask( 20 Common.formatterWorkerPool.javaScriptOutline(uiSourceCode.workingCopy(), thi s._didBuildOutlineChunk.bind(this));
21 'javaScriptOutline', {content: uiSourceCode.workingCopy()}, this._didBui ldOutlineChunk.bind(this));
22 } 21 }
23 22
24 /** 23 /**
25 * @param {!Workspace.UISourceCode} uiSourceCode 24 * @param {!Workspace.UISourceCode} uiSourceCode
26 * @param {function(number, number)} selectItemCallback 25 * @param {function(number, number)} selectItemCallback
27 */ 26 */
28 static show(uiSourceCode, selectItemCallback) { 27 static show(uiSourceCode, selectItemCallback) {
29 Sources.JavaScriptOutlineDialog._instanceForTests = 28 Sources.JavaScriptOutlineDialog._instanceForTests =
30 new Sources.JavaScriptOutlineDialog(uiSourceCode, selectItemCallback); 29 new Sources.JavaScriptOutlineDialog(uiSourceCode, selectItemCallback);
31 new UI.FilteredListWidget(Sources.JavaScriptOutlineDialog._instanceForTests) .showAsDialog(); 30 new UI.FilteredListWidget(Sources.JavaScriptOutlineDialog._instanceForTests) .showAsDialog();
32 } 31 }
33 32
34 /** 33 /**
35 * @param {?MessageEvent} event 34 * @param {boolean} isLastChunk
35 * @param {!Array<!Common.FormatterWorkerPool.JSOutlineItem>} items
36 */ 36 */
37 _didBuildOutlineChunk(event) { 37 _didBuildOutlineChunk(isLastChunk, items) {
38 if (!event) { 38 this._functionItems.push(...items);
39 this.dispose();
40 this.refresh();
41 return;
42 }
43 var data = /** @type {!Sources.JavaScriptOutlineDialog.MessageEventData} */ (event.data);
44 var chunk = data.chunk;
45 for (var i = 0; i < chunk.length; ++i)
46 this._functionItems.push(chunk[i]);
47
48 if (data.isLastChunk)
49 this.dispose();
50
51 this.refresh(); 39 this.refresh();
52 } 40 }
53 41
54 /** 42 /**
55 * @override 43 * @override
56 * @return {number} 44 * @return {number}
57 */ 45 */
58 itemCount() { 46 itemCount() {
59 return this._functionItems.length; 47 return this._functionItems.length;
60 } 48 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 * @param {?number} itemIndex 90 * @param {?number} itemIndex
103 * @param {string} promptValue 91 * @param {string} promptValue
104 */ 92 */
105 selectItem(itemIndex, promptValue) { 93 selectItem(itemIndex, promptValue) {
106 if (itemIndex === null) 94 if (itemIndex === null)
107 return; 95 return;
108 var lineNumber = this._functionItems[itemIndex].line; 96 var lineNumber = this._functionItems[itemIndex].line;
109 if (!isNaN(lineNumber) && lineNumber >= 0) 97 if (!isNaN(lineNumber) && lineNumber >= 0)
110 this._selectItemCallback(lineNumber, this._functionItems[itemIndex].column ); 98 this._selectItemCallback(lineNumber, this._functionItems[itemIndex].column );
111 } 99 }
112
113 /**
114 * @override
115 */
116 dispose() {
117 }
118 }; 100 };
119
120
121 /**
122 * @typedef {{isLastChunk: boolean, chunk: !Array.<!{selectorText: string, lineN umber: number, columnNumber: number}>}}
123 */
124 Sources.JavaScriptOutlineDialog.MessageEventData;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698