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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sdk/CSSParser.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 2014 The Chromium Authors. All rights reserved. 2 * Copyright 2014 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.Object}
10 */ 8 */
11 WebInspector.CSSParser = function() 9 WebInspector.CSSParser = class extends WebInspector.Object {
12 { 10 constructor() {
11 super();
13 this._rules = []; 12 this._rules = [];
14 this._terminated = false; 13 this._terminated = false;
14 }
15
16 /**
17 * @param {!WebInspector.CSSStyleSheetHeader} styleSheetHeader
18 * @param {function(!Array.<!WebInspector.CSSParser.Rule>)=} callback
19 */
20 fetchAndParse(styleSheetHeader, callback) {
21 this._lock();
22 this._finishedCallback = callback;
23 styleSheetHeader.requestContent().then(this._innerParse.bind(this));
24 }
25
26 /**
27 * @param {string} text
28 * @param {function(!Array.<!WebInspector.CSSParser.Rule>)=} callback
29 */
30 parse(text, callback) {
31 this._lock();
32 this._finishedCallback = callback;
33 this._innerParse(text);
34 }
35
36 /**
37 * @param {string} text
38 * @return {!Promise<!Array.<!WebInspector.CSSParser.Rule>>}
39 */
40 parsePromise(text) {
41 return new Promise(promiseConstructor.bind(this));
42
43 /**
44 * @param {function()} succ
45 * @param {function()} fail
46 * @this {WebInspector.CSSParser}
47 */
48 function promiseConstructor(succ, fail) {
49 this.parse(text, succ);
50 }
51 }
52
53 dispose() {
54 if (this._terminated)
55 return;
56 this._terminated = true;
57 this._runFinishedCallback([]);
58 }
59
60 /**
61 * @return {!Array.<!WebInspector.CSSParser.Rule>}
62 */
63 rules() {
64 return this._rules;
65 }
66
67 _lock() {
68 console.assert(!this._parsingStyleSheet, 'Received request to parse styleshe et before previous was completed.');
69 this._parsingStyleSheet = true;
70 }
71
72 _unlock() {
73 delete this._parsingStyleSheet;
74 }
75
76 /**
77 * @param {?string} text
78 */
79 _innerParse(text) {
80 this._rules = [];
81 var params = {content: text};
82 WebInspector.formatterWorkerPool.runChunkedTask('parseCSS', params, this._on RuleChunk.bind(this));
83 }
84
85 /**
86 * @param {?MessageEvent} event
87 */
88 _onRuleChunk(event) {
89 if (this._terminated)
90 return;
91 if (!event) {
92 this._onFinishedParsing();
93 this.dispatchEventToListeners(WebInspector.CSSParser.Events.RulesParsed);
94 return;
95 }
96 var data = /** @type {!WebInspector.CSSParser.DataChunk} */ (event.data);
97 var chunk = data.chunk;
98 for (var i = 0; i < chunk.length; ++i)
99 this._rules.push(chunk[i]);
100
101 if (data.isLastChunk)
102 this._onFinishedParsing();
103 this.dispatchEventToListeners(WebInspector.CSSParser.Events.RulesParsed);
104 }
105
106 _onFinishedParsing() {
107 this._unlock();
108 this._runFinishedCallback(this._rules);
109 }
110
111 /**
112 * @param {!Array<!WebInspector.CSSRule>} rules
113 */
114 _runFinishedCallback(rules) {
115 var callback = this._finishedCallback;
116 delete this._finishedCallback;
117 if (callback)
118 callback.call(null, rules);
119 }
15 }; 120 };
16 121
17 /** @enum {symbol} */ 122 /** @enum {symbol} */
18 WebInspector.CSSParser.Events = { 123 WebInspector.CSSParser.Events = {
19 RulesParsed: Symbol("RulesParsed") 124 RulesParsed: Symbol('RulesParsed')
20 };
21
22 WebInspector.CSSParser.prototype = {
23 /**
24 * @param {!WebInspector.CSSStyleSheetHeader} styleSheetHeader
25 * @param {function(!Array.<!WebInspector.CSSParser.Rule>)=} callback
26 */
27 fetchAndParse: function(styleSheetHeader, callback)
28 {
29 this._lock();
30 this._finishedCallback = callback;
31 styleSheetHeader.requestContent().then(this._innerParse.bind(this));
32 },
33
34 /**
35 * @param {string} text
36 * @param {function(!Array.<!WebInspector.CSSParser.Rule>)=} callback
37 */
38 parse: function(text, callback)
39 {
40 this._lock();
41 this._finishedCallback = callback;
42 this._innerParse(text);
43 },
44
45 /**
46 * @param {string} text
47 * @return {!Promise<!Array.<!WebInspector.CSSParser.Rule>>}
48 */
49 parsePromise: function(text)
50 {
51 return new Promise(promiseConstructor.bind(this));
52
53 /**
54 * @param {function()} succ
55 * @param {function()} fail
56 * @this {WebInspector.CSSParser}
57 */
58 function promiseConstructor(succ, fail)
59 {
60 this.parse(text, succ);
61 }
62 },
63
64 dispose: function()
65 {
66 if (this._terminated)
67 return;
68 this._terminated = true;
69 this._runFinishedCallback([]);
70 },
71
72 /**
73 * @return {!Array.<!WebInspector.CSSParser.Rule>}
74 */
75 rules: function()
76 {
77 return this._rules;
78 },
79
80 _lock: function()
81 {
82 console.assert(!this._parsingStyleSheet, "Received request to parse styl esheet before previous was completed.");
83 this._parsingStyleSheet = true;
84 },
85
86 _unlock: function()
87 {
88 delete this._parsingStyleSheet;
89 },
90
91 /**
92 * @param {?string} text
93 */
94 _innerParse: function(text)
95 {
96 this._rules = [];
97 var params = { content: text };
98 WebInspector.formatterWorkerPool.runChunkedTask("parseCSS", params, this ._onRuleChunk.bind(this));
99 },
100
101 /**
102 * @param {?MessageEvent} event
103 */
104 _onRuleChunk: function(event)
105 {
106 if (this._terminated)
107 return;
108 if (!event) {
109 this._onFinishedParsing();
110 this.dispatchEventToListeners(WebInspector.CSSParser.Events.RulesPar sed);
111 return;
112 }
113 var data = /** @type {!WebInspector.CSSParser.DataChunk} */ (event.data) ;
114 var chunk = data.chunk;
115 for (var i = 0; i < chunk.length; ++i)
116 this._rules.push(chunk[i]);
117
118 if (data.isLastChunk)
119 this._onFinishedParsing();
120 this.dispatchEventToListeners(WebInspector.CSSParser.Events.RulesParsed) ;
121 },
122
123 _onFinishedParsing: function()
124 {
125 this._unlock();
126 this._runFinishedCallback(this._rules);
127 },
128
129 /**
130 * @param {!Array<!WebInspector.CSSRule>} rules
131 */
132 _runFinishedCallback: function(rules)
133 {
134 var callback = this._finishedCallback;
135 delete this._finishedCallback;
136 if (callback)
137 callback.call(null, rules);
138 },
139
140 __proto__: WebInspector.Object.prototype,
141 }; 125 };
142 126
143 /** 127 /**
144 * @typedef {{isLastChunk: boolean, chunk: !Array.<!WebInspector.CSSParser.Rule> }} 128 * @typedef {{isLastChunk: boolean, chunk: !Array.<!WebInspector.CSSParser.Rule> }}
145 */ 129 */
146 WebInspector.CSSParser.DataChunk; 130 WebInspector.CSSParser.DataChunk;
147 131
148 /** 132 /**
149 * @constructor 133 * @unrestricted
150 */ 134 */
151 WebInspector.CSSParser.StyleRule = function() 135 WebInspector.CSSParser.StyleRule = class {
152 { 136 constructor() {
153 /** @type {string} */ 137 /** @type {string} */
154 this.selectorText; 138 this.selectorText;
155 /** @type {!WebInspector.CSSParser.Range} */ 139 /** @type {!WebInspector.CSSParser.Range} */
156 this.styleRange; 140 this.styleRange;
157 /** @type {number} */ 141 /** @type {number} */
158 this.lineNumber; 142 this.lineNumber;
159 /** @type {number} */ 143 /** @type {number} */
160 this.columnNumber; 144 this.columnNumber;
161 /** @type {!Array.<!WebInspector.CSSParser.Property>} */ 145 /** @type {!Array.<!WebInspector.CSSParser.Property>} */
162 this.properties; 146 this.properties;
147 }
163 }; 148 };
164 149
165 /** 150 /**
166 * @typedef {{atRule: string, lineNumber: number, columnNumber: number}} 151 * @typedef {{atRule: string, lineNumber: number, columnNumber: number}}
167 */ 152 */
168 WebInspector.CSSParser.AtRule; 153 WebInspector.CSSParser.AtRule;
169 154
170 /** 155 /**
171 * @typedef {(WebInspector.CSSParser.StyleRule|WebInspector.CSSParser.AtRule)} 156 * @typedef {(WebInspector.CSSParser.StyleRule|WebInspector.CSSParser.AtRule)}
172 */ 157 */
173 WebInspector.CSSParser.Rule; 158 WebInspector.CSSParser.Rule;
174 159
175 /** 160 /**
176 * @typedef {{startLine: number, startColumn: number, endLine: number, endColumn : number}} 161 * @typedef {{startLine: number, startColumn: number, endLine: number, endColumn : number}}
177 */ 162 */
178 WebInspector.CSSParser.Range; 163 WebInspector.CSSParser.Range;
179 164
180 /** 165 /**
181 * @constructor 166 * @unrestricted
182 */ 167 */
183 WebInspector.CSSParser.Property = function() 168 WebInspector.CSSParser.Property = class {
184 { 169 constructor() {
185 /** @type {string} */ 170 /** @type {string} */
186 this.name; 171 this.name;
187 /** @type {!WebInspector.CSSParser.Range} */ 172 /** @type {!WebInspector.CSSParser.Range} */
188 this.nameRange; 173 this.nameRange;
189 /** @type {string} */ 174 /** @type {string} */
190 this.value; 175 this.value;
191 /** @type {!WebInspector.CSSParser.Range} */ 176 /** @type {!WebInspector.CSSParser.Range} */
192 this.valueRange; 177 this.valueRange;
193 /** @type {!WebInspector.CSSParser.Range} */ 178 /** @type {!WebInspector.CSSParser.Range} */
194 this.range; 179 this.range;
195 /** @type {(boolean|undefined)} */ 180 /** @type {(boolean|undefined)} */
196 this.disabled; 181 this.disabled;
182 }
197 }; 183 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698