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

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

Issue 2466123002: DevTools: reformat front-end code to match chromium style. (Closed)
Patch Set: all done Created 4 years, 1 month 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
7 /** 6 /**
8 * @constructor 7 * @unrestricted
9 * @extends {WebInspector.FilteredListWidget.Delegate}
10 * @param {!WebInspector.UISourceCode} uiSourceCode
11 * @param {function(number, number)} selectItemCallback
12 */ 8 */
13 WebInspector.JavaScriptOutlineDialog = function(uiSourceCode, selectItemCallback ) 9 WebInspector.JavaScriptOutlineDialog = class extends WebInspector.FilteredListWi dget.Delegate {
14 { 10 /**
15 WebInspector.FilteredListWidget.Delegate.call(this, []); 11 * @param {!WebInspector.UISourceCode} uiSourceCode
12 * @param {function(number, number)} selectItemCallback
13 */
14 constructor(uiSourceCode, selectItemCallback) {
15 super([]);
16 16
17 this._functionItems = []; 17 this._functionItems = [];
18 this._selectItemCallback = selectItemCallback; 18 this._selectItemCallback = selectItemCallback;
19 WebInspector.formatterWorkerPool.runChunkedTask("javaScriptOutline", {conten t: uiSourceCode.workingCopy() }, this._didBuildOutlineChunk.bind(this)); 19 WebInspector.formatterWorkerPool.runChunkedTask(
20 'javaScriptOutline', {content: uiSourceCode.workingCopy()}, this._didBui ldOutlineChunk.bind(this));
21 }
22
23 /**
24 * @param {!WebInspector.UISourceCode} uiSourceCode
25 * @param {function(number, number)} selectItemCallback
26 */
27 static show(uiSourceCode, selectItemCallback) {
28 WebInspector.JavaScriptOutlineDialog._instanceForTests =
29 new WebInspector.JavaScriptOutlineDialog(uiSourceCode, selectItemCallbac k);
30 new WebInspector.FilteredListWidget(WebInspector.JavaScriptOutlineDialog._in stanceForTests).showAsDialog();
31 }
32
33 /**
34 * @param {?MessageEvent} event
35 */
36 _didBuildOutlineChunk(event) {
37 if (!event) {
38 this.dispose();
39 this.refresh();
40 return;
41 }
42 var data = /** @type {!WebInspector.JavaScriptOutlineDialog.MessageEventData } */ (event.data);
43 var chunk = data.chunk;
44 for (var i = 0; i < chunk.length; ++i)
45 this._functionItems.push(chunk[i]);
46
47 if (data.isLastChunk)
48 this.dispose();
49
50 this.refresh();
51 }
52
53 /**
54 * @override
55 * @return {number}
56 */
57 itemCount() {
58 return this._functionItems.length;
59 }
60
61 /**
62 * @override
63 * @param {number} itemIndex
64 * @return {string}
65 */
66 itemKeyAt(itemIndex) {
67 var item = this._functionItems[itemIndex];
68 return item.name + (item.arguments ? item.arguments : '');
69 }
70
71 /**
72 * @override
73 * @param {number} itemIndex
74 * @param {string} query
75 * @return {number}
76 */
77 itemScoreAt(itemIndex, query) {
78 var item = this._functionItems[itemIndex];
79 var methodName = query.split('(')[0];
80 if (methodName.toLowerCase() === item.name.toLowerCase())
81 return 1 / (1 + item.line);
82 return -item.line - 1;
83 }
84
85 /**
86 * @override
87 * @param {number} itemIndex
88 * @param {string} query
89 * @param {!Element} titleElement
90 * @param {!Element} subtitleElement
91 */
92 renderItem(itemIndex, query, titleElement, subtitleElement) {
93 var item = this._functionItems[itemIndex];
94 titleElement.textContent = item.name + (item.arguments ? item.arguments : '' );
95 this.highlightRanges(titleElement, query);
96 subtitleElement.textContent = ':' + (item.line + 1);
97 }
98
99 /**
100 * @override
101 * @param {?number} itemIndex
102 * @param {string} promptValue
103 */
104 selectItem(itemIndex, promptValue) {
105 if (itemIndex === null)
106 return;
107 var lineNumber = this._functionItems[itemIndex].line;
108 if (!isNaN(lineNumber) && lineNumber >= 0)
109 this._selectItemCallback(lineNumber, this._functionItems[itemIndex].column );
110 }
111
112 /**
113 * @override
114 */
115 dispose() {
116 }
20 }; 117 };
21 118
22 /**
23 * @param {!WebInspector.UISourceCode} uiSourceCode
24 * @param {function(number, number)} selectItemCallback
25 */
26 WebInspector.JavaScriptOutlineDialog.show = function(uiSourceCode, selectItemCal lback)
27 {
28 WebInspector.JavaScriptOutlineDialog._instanceForTests = new WebInspector.Ja vaScriptOutlineDialog(uiSourceCode, selectItemCallback);
29 new WebInspector.FilteredListWidget(WebInspector.JavaScriptOutlineDialog._in stanceForTests).showAsDialog();
30 };
31
32 WebInspector.JavaScriptOutlineDialog.prototype = {
33 /**
34 * @param {?MessageEvent} event
35 */
36 _didBuildOutlineChunk: function(event)
37 {
38 if (!event) {
39 this.dispose();
40 this.refresh();
41 return;
42 }
43 var data = /** @type {!WebInspector.JavaScriptOutlineDialog.MessageEvent Data} */ (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();
52 },
53
54 /**
55 * @override
56 * @return {number}
57 */
58 itemCount: function()
59 {
60 return this._functionItems.length;
61 },
62
63 /**
64 * @override
65 * @param {number} itemIndex
66 * @return {string}
67 */
68 itemKeyAt: function(itemIndex)
69 {
70 var item = this._functionItems[itemIndex];
71 return item.name + (item.arguments ? item.arguments : "");
72 },
73
74 /**
75 * @override
76 * @param {number} itemIndex
77 * @param {string} query
78 * @return {number}
79 */
80 itemScoreAt: function(itemIndex, query)
81 {
82 var item = this._functionItems[itemIndex];
83 var methodName = query.split("(")[0];
84 if (methodName.toLowerCase() === item.name.toLowerCase())
85 return 1 / (1 + item.line);
86 return -item.line - 1;
87 },
88
89 /**
90 * @override
91 * @param {number} itemIndex
92 * @param {string} query
93 * @param {!Element} titleElement
94 * @param {!Element} subtitleElement
95 */
96 renderItem: function(itemIndex, query, titleElement, subtitleElement)
97 {
98 var item = this._functionItems[itemIndex];
99 titleElement.textContent = item.name + (item.arguments ? item.arguments : "");
100 this.highlightRanges(titleElement, query);
101 subtitleElement.textContent = ":" + (item.line + 1);
102 },
103
104 /**
105 * @override
106 * @param {?number} itemIndex
107 * @param {string} promptValue
108 */
109 selectItem: function(itemIndex, promptValue)
110 {
111 if (itemIndex === null)
112 return;
113 var lineNumber = this._functionItems[itemIndex].line;
114 if (!isNaN(lineNumber) && lineNumber >= 0)
115 this._selectItemCallback(lineNumber, this._functionItems[itemIndex]. column);
116 },
117
118 dispose: function()
119 {
120 },
121
122 __proto__: WebInspector.FilteredListWidget.Delegate.prototype
123 };
124 119
125 /** 120 /**
126 * @typedef {{isLastChunk: boolean, chunk: !Array.<!{selectorText: string, lineN umber: number, columnNumber: number}>}} 121 * @typedef {{isLastChunk: boolean, chunk: !Array.<!{selectorText: string, lineN umber: number, columnNumber: number}>}}
127 */ 122 */
128 WebInspector.JavaScriptOutlineDialog.MessageEventData; 123 WebInspector.JavaScriptOutlineDialog.MessageEventData;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698