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/sdk/CSSMedia.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 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4
5 /** 4 /**
6 * @constructor 5 * @unrestricted
7 * @param {!CSSAgent.MediaQuery} payload
8 */ 6 */
9 WebInspector.CSSMediaQuery = function(payload) 7 WebInspector.CSSMediaQuery = class {
10 { 8 /**
9 * @param {!CSSAgent.MediaQuery} payload
10 */
11 constructor(payload) {
11 this._active = payload.active; 12 this._active = payload.active;
12 this._expressions = []; 13 this._expressions = [];
13 for (var j = 0; j < payload.expressions.length; ++j) 14 for (var j = 0; j < payload.expressions.length; ++j)
14 this._expressions.push(WebInspector.CSSMediaQueryExpression.parsePayload (payload.expressions[j])); 15 this._expressions.push(WebInspector.CSSMediaQueryExpression.parsePayload(p ayload.expressions[j]));
15 }; 16 }
17
18 /**
19 * @param {!CSSAgent.MediaQuery} payload
20 * @return {!WebInspector.CSSMediaQuery}
21 */
22 static parsePayload(payload) {
23 return new WebInspector.CSSMediaQuery(payload);
24 }
25
26 /**
27 * @return {boolean}
28 */
29 active() {
30 return this._active;
31 }
32
33 /**
34 * @return {!Array.<!WebInspector.CSSMediaQueryExpression>}
35 */
36 expressions() {
37 return this._expressions;
38 }
39 };
40
16 41
17 /** 42 /**
18 * @param {!CSSAgent.MediaQuery} payload 43 * @unrestricted
19 * @return {!WebInspector.CSSMediaQuery}
20 */ 44 */
21 WebInspector.CSSMediaQuery.parsePayload = function(payload) 45 WebInspector.CSSMediaQueryExpression = class {
22 { 46 /**
23 return new WebInspector.CSSMediaQuery(payload); 47 * @param {!CSSAgent.MediaQueryExpression} payload
24 }; 48 */
25 49 constructor(payload) {
26 WebInspector.CSSMediaQuery.prototype = {
27 /**
28 * @return {boolean}
29 */
30 active: function()
31 {
32 return this._active;
33 },
34
35 /**
36 * @return {!Array.<!WebInspector.CSSMediaQueryExpression>}
37 */
38 expressions: function()
39 {
40 return this._expressions;
41 }
42 };
43
44 /**
45 * @constructor
46 * @param {!CSSAgent.MediaQueryExpression} payload
47 */
48 WebInspector.CSSMediaQueryExpression = function(payload)
49 {
50 this._value = payload.value; 50 this._value = payload.value;
51 this._unit = payload.unit; 51 this._unit = payload.unit;
52 this._feature = payload.feature; 52 this._feature = payload.feature;
53 this._valueRange = payload.valueRange ? WebInspector.TextRange.fromObject(pa yload.valueRange) : null; 53 this._valueRange = payload.valueRange ? WebInspector.TextRange.fromObject(pa yload.valueRange) : null;
54 this._computedLength = payload.computedLength || null; 54 this._computedLength = payload.computedLength || null;
55 }; 55 }
56
57 /**
58 * @param {!CSSAgent.MediaQueryExpression} payload
59 * @return {!WebInspector.CSSMediaQueryExpression}
60 */
61 static parsePayload(payload) {
62 return new WebInspector.CSSMediaQueryExpression(payload);
63 }
64
65 /**
66 * @return {number}
67 */
68 value() {
69 return this._value;
70 }
71
72 /**
73 * @return {string}
74 */
75 unit() {
76 return this._unit;
77 }
78
79 /**
80 * @return {string}
81 */
82 feature() {
83 return this._feature;
84 }
85
86 /**
87 * @return {?WebInspector.TextRange}
88 */
89 valueRange() {
90 return this._valueRange;
91 }
92
93 /**
94 * @return {?number}
95 */
96 computedLength() {
97 return this._computedLength;
98 }
99 };
100
56 101
57 /** 102 /**
58 * @param {!CSSAgent.MediaQueryExpression} payload 103 * @unrestricted
59 * @return {!WebInspector.CSSMediaQueryExpression}
60 */ 104 */
61 WebInspector.CSSMediaQueryExpression.parsePayload = function(payload) 105 WebInspector.CSSMedia = class {
62 { 106 /**
63 return new WebInspector.CSSMediaQueryExpression(payload); 107 * @param {!WebInspector.CSSModel} cssModel
64 }; 108 * @param {!CSSAgent.CSSMedia} payload
65 109 */
66 WebInspector.CSSMediaQueryExpression.prototype = { 110 constructor(cssModel, payload) {
67 /**
68 * @return {number}
69 */
70 value: function()
71 {
72 return this._value;
73 },
74
75 /**
76 * @return {string}
77 */
78 unit: function()
79 {
80 return this._unit;
81 },
82
83 /**
84 * @return {string}
85 */
86 feature: function()
87 {
88 return this._feature;
89 },
90
91 /**
92 * @return {?WebInspector.TextRange}
93 */
94 valueRange: function()
95 {
96 return this._valueRange;
97 },
98
99 /**
100 * @return {?number}
101 */
102 computedLength: function()
103 {
104 return this._computedLength;
105 }
106 };
107
108
109 /**
110 * @constructor
111 * @param {!WebInspector.CSSModel} cssModel
112 * @param {!CSSAgent.CSSMedia} payload
113 */
114 WebInspector.CSSMedia = function(cssModel, payload)
115 {
116 this._cssModel = cssModel; 111 this._cssModel = cssModel;
117 this._reinitialize(payload); 112 this._reinitialize(payload);
118 }; 113 }
119 114
120 WebInspector.CSSMedia.Source = { 115 /**
121 LINKED_SHEET: "linkedSheet", 116 * @param {!WebInspector.CSSModel} cssModel
122 INLINE_SHEET: "inlineSheet", 117 * @param {!CSSAgent.CSSMedia} payload
123 MEDIA_RULE: "mediaRule", 118 * @return {!WebInspector.CSSMedia}
124 IMPORT_RULE: "importRule" 119 */
125 }; 120 static parsePayload(cssModel, payload) {
126
127 /**
128 * @param {!WebInspector.CSSModel} cssModel
129 * @param {!CSSAgent.CSSMedia} payload
130 * @return {!WebInspector.CSSMedia}
131 */
132 WebInspector.CSSMedia.parsePayload = function(cssModel, payload)
133 {
134 return new WebInspector.CSSMedia(cssModel, payload); 121 return new WebInspector.CSSMedia(cssModel, payload);
135 }; 122 }
136 123
137 /** 124 /**
138 * @param {!WebInspector.CSSModel} cssModel 125 * @param {!WebInspector.CSSModel} cssModel
139 * @param {!Array.<!CSSAgent.CSSMedia>} payload 126 * @param {!Array.<!CSSAgent.CSSMedia>} payload
140 * @return {!Array.<!WebInspector.CSSMedia>} 127 * @return {!Array.<!WebInspector.CSSMedia>}
141 */ 128 */
142 WebInspector.CSSMedia.parseMediaArrayPayload = function(cssModel, payload) 129 static parseMediaArrayPayload(cssModel, payload) {
143 {
144 var result = []; 130 var result = [];
145 for (var i = 0; i < payload.length; ++i) 131 for (var i = 0; i < payload.length; ++i)
146 result.push(WebInspector.CSSMedia.parsePayload(cssModel, payload[i])); 132 result.push(WebInspector.CSSMedia.parsePayload(cssModel, payload[i]));
147 return result; 133 return result;
148 }; 134 }
149 135
150 WebInspector.CSSMedia.prototype = { 136 /**
151 /** 137 * @param {!CSSAgent.CSSMedia} payload
152 * @param {!CSSAgent.CSSMedia} payload 138 */
153 */ 139 _reinitialize(payload) {
154 _reinitialize: function(payload) 140 this.text = payload.text;
155 { 141 this.source = payload.source;
156 this.text = payload.text; 142 this.sourceURL = payload.sourceURL || '';
157 this.source = payload.source; 143 this.range = payload.range ? WebInspector.TextRange.fromObject(payload.range ) : null;
158 this.sourceURL = payload.sourceURL || ""; 144 this.styleSheetId = payload.styleSheetId;
159 this.range = payload.range ? WebInspector.TextRange.fromObject(payload.r ange) : null; 145 this.mediaList = null;
160 this.styleSheetId = payload.styleSheetId; 146 if (payload.mediaList) {
161 this.mediaList = null; 147 this.mediaList = [];
162 if (payload.mediaList) { 148 for (var i = 0; i < payload.mediaList.length; ++i)
163 this.mediaList = []; 149 this.mediaList.push(WebInspector.CSSMediaQuery.parsePayload(payload.medi aList[i]));
164 for (var i = 0; i < payload.mediaList.length; ++i)
165 this.mediaList.push(WebInspector.CSSMediaQuery.parsePayload(payl oad.mediaList[i]));
166 }
167 },
168
169 /**
170 * @param {!WebInspector.CSSModel.Edit} edit
171 */
172 rebase: function(edit)
173 {
174 if (this.styleSheetId !== edit.styleSheetId || !this.range)
175 return;
176 if (edit.oldRange.equal(this.range))
177 this._reinitialize(/** @type {!CSSAgent.CSSMedia} */(edit.payload));
178 else
179 this.range = this.range.rebaseAfterTextEdit(edit.oldRange, edit.newR ange);
180 },
181
182 /**
183 * @param {!WebInspector.CSSMedia} other
184 * @return {boolean}
185 */
186 equal: function(other)
187 {
188 if (!this.styleSheetId || !this.range || !other.range)
189 return false;
190 return this.styleSheetId === other.styleSheetId && this.range.equal(oth er.range);
191 },
192
193 /**
194 * @return {boolean}
195 */
196 active: function()
197 {
198 if (!this.mediaList)
199 return true;
200 for (var i = 0; i < this.mediaList.length; ++i) {
201 if (this.mediaList[i].active())
202 return true;
203 }
204 return false;
205 },
206
207 /**
208 * @return {number|undefined}
209 */
210 lineNumberInSource: function()
211 {
212 if (!this.range)
213 return undefined;
214 var header = this.header();
215 if (!header)
216 return undefined;
217 return header.lineNumberInSource(this.range.startLine);
218 },
219
220 /**
221 * @return {number|undefined}
222 */
223 columnNumberInSource: function()
224 {
225 if (!this.range)
226 return undefined;
227 var header = this.header();
228 if (!header)
229 return undefined;
230 return header.columnNumberInSource(this.range.startLine, this.range.star tColumn);
231 },
232
233 /**
234 * @return {?WebInspector.CSSStyleSheetHeader}
235 */
236 header: function()
237 {
238 return this.styleSheetId ? this._cssModel.styleSheetHeaderForId(this.sty leSheetId) : null;
239 },
240
241 /**
242 * @return {?WebInspector.CSSLocation}
243 */
244 rawLocation: function()
245 {
246 var header = this.header();
247 if (!header || this.lineNumberInSource() === undefined)
248 return null;
249 var lineNumber = Number(this.lineNumberInSource());
250 return new WebInspector.CSSLocation(header, lineNumber, this.columnNumbe rInSource());
251 } 150 }
252 }; 151 }
152
153 /**
154 * @param {!WebInspector.CSSModel.Edit} edit
155 */
156 rebase(edit) {
157 if (this.styleSheetId !== edit.styleSheetId || !this.range)
158 return;
159 if (edit.oldRange.equal(this.range))
160 this._reinitialize(/** @type {!CSSAgent.CSSMedia} */ (edit.payload));
161 else
162 this.range = this.range.rebaseAfterTextEdit(edit.oldRange, edit.newRange);
163 }
164
165 /**
166 * @param {!WebInspector.CSSMedia} other
167 * @return {boolean}
168 */
169 equal(other) {
170 if (!this.styleSheetId || !this.range || !other.range)
171 return false;
172 return this.styleSheetId === other.styleSheetId && this.range.equal(other.ra nge);
173 }
174
175 /**
176 * @return {boolean}
177 */
178 active() {
179 if (!this.mediaList)
180 return true;
181 for (var i = 0; i < this.mediaList.length; ++i) {
182 if (this.mediaList[i].active())
183 return true;
184 }
185 return false;
186 }
187
188 /**
189 * @return {number|undefined}
190 */
191 lineNumberInSource() {
192 if (!this.range)
193 return undefined;
194 var header = this.header();
195 if (!header)
196 return undefined;
197 return header.lineNumberInSource(this.range.startLine);
198 }
199
200 /**
201 * @return {number|undefined}
202 */
203 columnNumberInSource() {
204 if (!this.range)
205 return undefined;
206 var header = this.header();
207 if (!header)
208 return undefined;
209 return header.columnNumberInSource(this.range.startLine, this.range.startCol umn);
210 }
211
212 /**
213 * @return {?WebInspector.CSSStyleSheetHeader}
214 */
215 header() {
216 return this.styleSheetId ? this._cssModel.styleSheetHeaderForId(this.styleSh eetId) : null;
217 }
218
219 /**
220 * @return {?WebInspector.CSSLocation}
221 */
222 rawLocation() {
223 var header = this.header();
224 if (!header || this.lineNumberInSource() === undefined)
225 return null;
226 var lineNumber = Number(this.lineNumberInSource());
227 return new WebInspector.CSSLocation(header, lineNumber, this.columnNumberInS ource());
228 }
229 };
230
231 WebInspector.CSSMedia.Source = {
232 LINKED_SHEET: 'linkedSheet',
233 INLINE_SHEET: 'inlineSheet',
234 MEDIA_RULE: 'mediaRule',
235 IMPORT_RULE: 'importRule'
236 };
237
238
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698