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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sdk/CSSParser.js

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

Powered by Google App Engine
This is Rietveld 408576698