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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sources/StyleSheetOutlineDialog.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 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 10 *
11 * 2. Redistributions in binary form must reproduce the above 11 * 2. Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer 12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the 13 * in the documentation and/or other materials provided with the
14 * distribution. 14 * distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. AND ITS CONTRIBUTORS 16 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. AND ITS CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC.
20 * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28
29 /** 28 /**
30 * @constructor 29 * @unrestricted
31 * @extends {WebInspector.FilteredListWidget.Delegate}
32 * @param {!WebInspector.UISourceCode} uiSourceCode
33 * @param {function(number, number)} selectItemCallback
34 */ 30 */
35 WebInspector.StyleSheetOutlineDialog = function(uiSourceCode, selectItemCallback ) 31 WebInspector.StyleSheetOutlineDialog = class extends WebInspector.FilteredListWi dget.Delegate {
36 { 32 /**
37 WebInspector.FilteredListWidget.Delegate.call(this, []); 33 * @param {!WebInspector.UISourceCode} uiSourceCode
34 * @param {function(number, number)} selectItemCallback
35 */
36 constructor(uiSourceCode, selectItemCallback) {
37 super([]);
38 this._selectItemCallback = selectItemCallback; 38 this._selectItemCallback = selectItemCallback;
39 this._cssParser = new WebInspector.CSSParser(); 39 this._cssParser = new WebInspector.CSSParser();
40 this._cssParser.addEventListener(WebInspector.CSSParser.Events.RulesParsed, this.refresh.bind(this)); 40 this._cssParser.addEventListener(WebInspector.CSSParser.Events.RulesParsed, this.refresh.bind(this));
41 this._cssParser.parse(uiSourceCode.workingCopy()); 41 this._cssParser.parse(uiSourceCode.workingCopy());
42 }
43
44 /**
45 * @param {!WebInspector.UISourceCode} uiSourceCode
46 * @param {function(number, number)} selectItemCallback
47 */
48 static show(uiSourceCode, selectItemCallback) {
49 WebInspector.StyleSheetOutlineDialog._instanceForTests =
50 new WebInspector.StyleSheetOutlineDialog(uiSourceCode, selectItemCallbac k);
51 new WebInspector.FilteredListWidget(WebInspector.StyleSheetOutlineDialog._in stanceForTests).showAsDialog();
52 }
53
54 /**
55 * @override
56 * @return {number}
57 */
58 itemCount() {
59 return this._cssParser.rules().length;
60 }
61
62 /**
63 * @override
64 * @param {number} itemIndex
65 * @return {string}
66 */
67 itemKeyAt(itemIndex) {
68 var rule = this._cssParser.rules()[itemIndex];
69 return rule.selectorText || rule.atRule;
70 }
71
72 /**
73 * @override
74 * @param {number} itemIndex
75 * @param {string} query
76 * @return {number}
77 */
78 itemScoreAt(itemIndex, query) {
79 var rule = this._cssParser.rules()[itemIndex];
80 return -rule.lineNumber;
81 }
82
83 /**
84 * @override
85 * @param {number} itemIndex
86 * @param {string} query
87 * @param {!Element} titleElement
88 * @param {!Element} subtitleElement
89 */
90 renderItem(itemIndex, query, titleElement, subtitleElement) {
91 var rule = this._cssParser.rules()[itemIndex];
92 titleElement.textContent = rule.selectorText || rule.atRule;
93 this.highlightRanges(titleElement, query);
94 subtitleElement.textContent = ':' + (rule.lineNumber + 1);
95 }
96
97 /**
98 * @override
99 * @param {number} itemIndex
100 * @param {string} promptValue
101 */
102 selectItem(itemIndex, promptValue) {
103 var rule = this._cssParser.rules()[itemIndex];
104 var lineNumber = rule.lineNumber;
105 if (!isNaN(lineNumber) && lineNumber >= 0)
106 this._selectItemCallback(lineNumber, rule.columnNumber);
107 }
108
109 /**
110 * @override
111 */
112 dispose() {
113 this._cssParser.dispose();
114 }
42 }; 115 };
43 116
44 /**
45 * @param {!WebInspector.UISourceCode} uiSourceCode
46 * @param {function(number, number)} selectItemCallback
47 */
48 WebInspector.StyleSheetOutlineDialog.show = function(uiSourceCode, selectItemCal lback)
49 {
50 WebInspector.StyleSheetOutlineDialog._instanceForTests = new WebInspector.St yleSheetOutlineDialog(uiSourceCode, selectItemCallback);
51 new WebInspector.FilteredListWidget(WebInspector.StyleSheetOutlineDialog._in stanceForTests).showAsDialog();
52 };
53 117
54 WebInspector.StyleSheetOutlineDialog.prototype = {
55 /**
56 * @override
57 * @return {number}
58 */
59 itemCount: function()
60 {
61 return this._cssParser.rules().length;
62 },
63
64 /**
65 * @override
66 * @param {number} itemIndex
67 * @return {string}
68 */
69 itemKeyAt: function(itemIndex)
70 {
71 var rule = this._cssParser.rules()[itemIndex];
72 return rule.selectorText || rule.atRule;
73 },
74
75 /**
76 * @override
77 * @param {number} itemIndex
78 * @param {string} query
79 * @return {number}
80 */
81 itemScoreAt: function(itemIndex, query)
82 {
83 var rule = this._cssParser.rules()[itemIndex];
84 return -rule.lineNumber;
85 },
86
87 /**
88 * @override
89 * @param {number} itemIndex
90 * @param {string} query
91 * @param {!Element} titleElement
92 * @param {!Element} subtitleElement
93 */
94 renderItem: function(itemIndex, query, titleElement, subtitleElement)
95 {
96 var rule = this._cssParser.rules()[itemIndex];
97 titleElement.textContent = rule.selectorText || rule.atRule;
98 this.highlightRanges(titleElement, query);
99 subtitleElement.textContent = ":" + (rule.lineNumber + 1);
100 },
101
102 /**
103 * @override
104 * @param {number} itemIndex
105 * @param {string} promptValue
106 */
107 selectItem: function(itemIndex, promptValue)
108 {
109 var rule = this._cssParser.rules()[itemIndex];
110 var lineNumber = rule.lineNumber;
111 if (!isNaN(lineNumber) && lineNumber >= 0)
112 this._selectItemCallback(lineNumber, rule.columnNumber);
113 },
114
115 dispose: function()
116 {
117 this._cssParser.dispose();
118 },
119
120 __proto__: WebInspector.FilteredListWidget.Delegate.prototype
121 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698