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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sdk/CSSStyleDeclaration.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 // 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 /** 4 /**
5 * @unrestricted 5 * @unrestricted
6 */ 6 */
7 WebInspector.CSSStyleDeclaration = class { 7 SDK.CSSStyleDeclaration = class {
8 /** 8 /**
9 * @param {!WebInspector.CSSModel} cssModel 9 * @param {!SDK.CSSModel} cssModel
10 * @param {?WebInspector.CSSRule} parentRule 10 * @param {?SDK.CSSRule} parentRule
11 * @param {!Protocol.CSS.CSSStyle} payload 11 * @param {!Protocol.CSS.CSSStyle} payload
12 * @param {!WebInspector.CSSStyleDeclaration.Type} type 12 * @param {!SDK.CSSStyleDeclaration.Type} type
13 */ 13 */
14 constructor(cssModel, parentRule, payload, type) { 14 constructor(cssModel, parentRule, payload, type) {
15 this._cssModel = cssModel; 15 this._cssModel = cssModel;
16 this.parentRule = parentRule; 16 this.parentRule = parentRule;
17 this._reinitialize(payload); 17 this._reinitialize(payload);
18 this.type = type; 18 this.type = type;
19 } 19 }
20 20
21 /** 21 /**
22 * @param {!WebInspector.CSSModel.Edit} edit 22 * @param {!SDK.CSSModel.Edit} edit
23 */ 23 */
24 rebase(edit) { 24 rebase(edit) {
25 if (this.styleSheetId !== edit.styleSheetId || !this.range) 25 if (this.styleSheetId !== edit.styleSheetId || !this.range)
26 return; 26 return;
27 if (edit.oldRange.equal(this.range)) { 27 if (edit.oldRange.equal(this.range)) {
28 this._reinitialize(/** @type {!Protocol.CSS.CSSStyle} */ (edit.payload)); 28 this._reinitialize(/** @type {!Protocol.CSS.CSSStyle} */ (edit.payload));
29 } else { 29 } else {
30 this.range = this.range.rebaseAfterTextEdit(edit.oldRange, edit.newRange); 30 this.range = this.range.rebaseAfterTextEdit(edit.oldRange, edit.newRange);
31 for (var i = 0; i < this._allProperties.length; ++i) 31 for (var i = 0; i < this._allProperties.length; ++i)
32 this._allProperties[i].rebase(edit); 32 this._allProperties[i].rebase(edit);
33 } 33 }
34 } 34 }
35 35
36 /** 36 /**
37 * @param {!Protocol.CSS.CSSStyle} payload 37 * @param {!Protocol.CSS.CSSStyle} payload
38 */ 38 */
39 _reinitialize(payload) { 39 _reinitialize(payload) {
40 this.styleSheetId = payload.styleSheetId; 40 this.styleSheetId = payload.styleSheetId;
41 this.range = payload.range ? WebInspector.TextRange.fromObject(payload.range ) : null; 41 this.range = payload.range ? Common.TextRange.fromObject(payload.range) : nu ll;
42 42
43 var shorthandEntries = payload.shorthandEntries; 43 var shorthandEntries = payload.shorthandEntries;
44 /** @type {!Map.<string, string>} */ 44 /** @type {!Map.<string, string>} */
45 this._shorthandValues = new Map(); 45 this._shorthandValues = new Map();
46 /** @type {!Set.<string>} */ 46 /** @type {!Set.<string>} */
47 this._shorthandIsImportant = new Set(); 47 this._shorthandIsImportant = new Set();
48 for (var i = 0; i < shorthandEntries.length; ++i) { 48 for (var i = 0; i < shorthandEntries.length; ++i) {
49 this._shorthandValues.set(shorthandEntries[i].name, shorthandEntries[i].va lue); 49 this._shorthandValues.set(shorthandEntries[i].name, shorthandEntries[i].va lue);
50 if (shorthandEntries[i].important) 50 if (shorthandEntries[i].important)
51 this._shorthandIsImportant.add(shorthandEntries[i].name); 51 this._shorthandIsImportant.add(shorthandEntries[i].name);
52 } 52 }
53 53
54 this._allProperties = []; 54 this._allProperties = [];
55 for (var i = 0; i < payload.cssProperties.length; ++i) { 55 for (var i = 0; i < payload.cssProperties.length; ++i) {
56 var property = WebInspector.CSSProperty.parsePayload(this, i, payload.cssP roperties[i]); 56 var property = SDK.CSSProperty.parsePayload(this, i, payload.cssProperties [i]);
57 this._allProperties.push(property); 57 this._allProperties.push(property);
58 } 58 }
59 59
60 this._generateSyntheticPropertiesIfNeeded(); 60 this._generateSyntheticPropertiesIfNeeded();
61 this._computeInactiveProperties(); 61 this._computeInactiveProperties();
62 62
63 this._activePropertyMap = new Map(); 63 this._activePropertyMap = new Map();
64 for (var property of this._allProperties) { 64 for (var property of this._allProperties) {
65 if (!property.activeInStyle()) 65 if (!property.activeInStyle())
66 continue; 66 continue;
(...skipping 12 matching lines...) Expand all
79 return; 79 return;
80 80
81 var propertiesSet = new Set(); 81 var propertiesSet = new Set();
82 for (var property of this._allProperties) 82 for (var property of this._allProperties)
83 propertiesSet.add(property.name); 83 propertiesSet.add(property.name);
84 84
85 var generatedProperties = []; 85 var generatedProperties = [];
86 // For style-based properties, generate shorthands with values when possible . 86 // For style-based properties, generate shorthands with values when possible .
87 for (var property of this._allProperties) { 87 for (var property of this._allProperties) {
88 // For style-based properties, try generating shorthands. 88 // For style-based properties, try generating shorthands.
89 var shorthands = WebInspector.cssMetadata().shorthands(property.name) || [ ]; 89 var shorthands = SDK.cssMetadata().shorthands(property.name) || [];
90 for (var shorthand of shorthands) { 90 for (var shorthand of shorthands) {
91 if (propertiesSet.has(shorthand)) 91 if (propertiesSet.has(shorthand))
92 continue; // There already is a shorthand this longhands falls under. 92 continue; // There already is a shorthand this longhands falls under.
93 var shorthandValue = this._shorthandValues.get(shorthand); 93 var shorthandValue = this._shorthandValues.get(shorthand);
94 if (!shorthandValue) 94 if (!shorthandValue)
95 continue; // Never generate synthetic shorthands when no value is ava ilable. 95 continue; // Never generate synthetic shorthands when no value is ava ilable.
96 96
97 // Generate synthetic shorthand we have a value for. 97 // Generate synthetic shorthand we have a value for.
98 var shorthandImportance = !!this._shorthandIsImportant.has(shorthand); 98 var shorthandImportance = !!this._shorthandIsImportant.has(shorthand);
99 var shorthandProperty = new WebInspector.CSSProperty( 99 var shorthandProperty = new SDK.CSSProperty(
100 this, this.allProperties.length, shorthand, shorthandValue, shorthan dImportance, false, true, false); 100 this, this.allProperties.length, shorthand, shorthandValue, shorthan dImportance, false, true, false);
101 generatedProperties.push(shorthandProperty); 101 generatedProperties.push(shorthandProperty);
102 propertiesSet.add(shorthand); 102 propertiesSet.add(shorthand);
103 } 103 }
104 } 104 }
105 this._allProperties = this._allProperties.concat(generatedProperties); 105 this._allProperties = this._allProperties.concat(generatedProperties);
106 } 106 }
107 107
108 /** 108 /**
109 * @return {!Array.<!WebInspector.CSSProperty>} 109 * @return {!Array.<!SDK.CSSProperty>}
110 */ 110 */
111 _computeLeadingProperties() { 111 _computeLeadingProperties() {
112 /** 112 /**
113 * @param {!WebInspector.CSSProperty} property 113 * @param {!SDK.CSSProperty} property
114 * @return {boolean} 114 * @return {boolean}
115 */ 115 */
116 function propertyHasRange(property) { 116 function propertyHasRange(property) {
117 return !!property.range; 117 return !!property.range;
118 } 118 }
119 119
120 if (this.range) 120 if (this.range)
121 return this._allProperties.filter(propertyHasRange); 121 return this._allProperties.filter(propertyHasRange);
122 122
123 var leadingProperties = []; 123 var leadingProperties = [];
124 for (var property of this._allProperties) { 124 for (var property of this._allProperties) {
125 var shorthands = WebInspector.cssMetadata().shorthands(property.name) || [ ]; 125 var shorthands = SDK.cssMetadata().shorthands(property.name) || [];
126 var belongToAnyShorthand = false; 126 var belongToAnyShorthand = false;
127 for (var shorthand of shorthands) { 127 for (var shorthand of shorthands) {
128 if (this._shorthandValues.get(shorthand)) { 128 if (this._shorthandValues.get(shorthand)) {
129 belongToAnyShorthand = true; 129 belongToAnyShorthand = true;
130 break; 130 break;
131 } 131 }
132 } 132 }
133 if (!belongToAnyShorthand) 133 if (!belongToAnyShorthand)
134 leadingProperties.push(property); 134 leadingProperties.push(property);
135 } 135 }
136 136
137 return leadingProperties; 137 return leadingProperties;
138 } 138 }
139 139
140 /** 140 /**
141 * @return {!Array.<!WebInspector.CSSProperty>} 141 * @return {!Array.<!SDK.CSSProperty>}
142 */ 142 */
143 leadingProperties() { 143 leadingProperties() {
144 if (!this._leadingProperties) 144 if (!this._leadingProperties)
145 this._leadingProperties = this._computeLeadingProperties(); 145 this._leadingProperties = this._computeLeadingProperties();
146 return this._leadingProperties; 146 return this._leadingProperties;
147 } 147 }
148 148
149 /** 149 /**
150 * @return {!WebInspector.Target} 150 * @return {!SDK.Target}
151 */ 151 */
152 target() { 152 target() {
153 return this._cssModel.target(); 153 return this._cssModel.target();
154 } 154 }
155 155
156 /** 156 /**
157 * @return {!WebInspector.CSSModel} 157 * @return {!SDK.CSSModel}
158 */ 158 */
159 cssModel() { 159 cssModel() {
160 return this._cssModel; 160 return this._cssModel;
161 } 161 }
162 162
163 _computeInactiveProperties() { 163 _computeInactiveProperties() {
164 var activeProperties = {}; 164 var activeProperties = {};
165 for (var i = 0; i < this._allProperties.length; ++i) { 165 for (var i = 0; i < this._allProperties.length; ++i) {
166 var property = this._allProperties[i]; 166 var property = this._allProperties[i];
167 if (property.disabled || !property.parsedOk) { 167 if (property.disabled || !property.parsedOk) {
168 property._setActive(false); 168 property._setActive(false);
169 continue; 169 continue;
170 } 170 }
171 var canonicalName = WebInspector.cssMetadata().canonicalPropertyName(prope rty.name); 171 var canonicalName = SDK.cssMetadata().canonicalPropertyName(property.name) ;
172 var activeProperty = activeProperties[canonicalName]; 172 var activeProperty = activeProperties[canonicalName];
173 if (!activeProperty) { 173 if (!activeProperty) {
174 activeProperties[canonicalName] = property; 174 activeProperties[canonicalName] = property;
175 } else if (!activeProperty.important || property.important) { 175 } else if (!activeProperty.important || property.important) {
176 activeProperty._setActive(false); 176 activeProperty._setActive(false);
177 activeProperties[canonicalName] = property; 177 activeProperties[canonicalName] = property;
178 } else { 178 } else {
179 property._setActive(false); 179 property._setActive(false);
180 } 180 }
181 } 181 }
(...skipping 16 matching lines...) Expand all
198 * @param {string} name 198 * @param {string} name
199 * @return {boolean} 199 * @return {boolean}
200 */ 200 */
201 isPropertyImplicit(name) { 201 isPropertyImplicit(name) {
202 var property = this._activePropertyMap.get(name); 202 var property = this._activePropertyMap.get(name);
203 return property ? property.implicit : ''; 203 return property ? property.implicit : '';
204 } 204 }
205 205
206 /** 206 /**
207 * @param {string} name 207 * @param {string} name
208 * @return {!Array.<!WebInspector.CSSProperty>} 208 * @return {!Array.<!SDK.CSSProperty>}
209 */ 209 */
210 longhandProperties(name) { 210 longhandProperties(name) {
211 var longhands = WebInspector.cssMetadata().longhands(name); 211 var longhands = SDK.cssMetadata().longhands(name);
212 var result = []; 212 var result = [];
213 for (var i = 0; longhands && i < longhands.length; ++i) { 213 for (var i = 0; longhands && i < longhands.length; ++i) {
214 var property = this._activePropertyMap.get(longhands[i]); 214 var property = this._activePropertyMap.get(longhands[i]);
215 if (property) 215 if (property)
216 result.push(property); 216 result.push(property);
217 } 217 }
218 return result; 218 return result;
219 } 219 }
220 220
221 /** 221 /**
222 * @param {number} index 222 * @param {number} index
223 * @return {?WebInspector.CSSProperty} 223 * @return {?SDK.CSSProperty}
224 */ 224 */
225 propertyAt(index) { 225 propertyAt(index) {
226 return (index < this.allProperties.length) ? this.allProperties[index] : nul l; 226 return (index < this.allProperties.length) ? this.allProperties[index] : nul l;
227 } 227 }
228 228
229 /** 229 /**
230 * @return {number} 230 * @return {number}
231 */ 231 */
232 pastLastSourcePropertyIndex() { 232 pastLastSourcePropertyIndex() {
233 for (var i = this.allProperties.length - 1; i >= 0; --i) { 233 for (var i = this.allProperties.length - 1; i >= 0; --i) {
234 if (this.allProperties[i].range) 234 if (this.allProperties[i].range)
235 return i + 1; 235 return i + 1;
236 } 236 }
237 return 0; 237 return 0;
238 } 238 }
239 239
240 /** 240 /**
241 * @param {number} index 241 * @param {number} index
242 * @return {!WebInspector.TextRange} 242 * @return {!Common.TextRange}
243 */ 243 */
244 _insertionRange(index) { 244 _insertionRange(index) {
245 var property = this.propertyAt(index); 245 var property = this.propertyAt(index);
246 return property && property.range ? property.range.collapseToStart() : this. range.collapseToEnd(); 246 return property && property.range ? property.range.collapseToStart() : this. range.collapseToEnd();
247 } 247 }
248 248
249 /** 249 /**
250 * @param {number=} index 250 * @param {number=} index
251 * @return {!WebInspector.CSSProperty} 251 * @return {!SDK.CSSProperty}
252 */ 252 */
253 newBlankProperty(index) { 253 newBlankProperty(index) {
254 index = (typeof index === 'undefined') ? this.pastLastSourcePropertyIndex() : index; 254 index = (typeof index === 'undefined') ? this.pastLastSourcePropertyIndex() : index;
255 var property = 255 var property =
256 new WebInspector.CSSProperty(this, index, '', '', false, false, true, fa lse, '', this._insertionRange(index)); 256 new SDK.CSSProperty(this, index, '', '', false, false, true, false, '', this._insertionRange(index));
257 return property; 257 return property;
258 } 258 }
259 259
260 /** 260 /**
261 * @param {string} text 261 * @param {string} text
262 * @param {boolean} majorChange 262 * @param {boolean} majorChange
263 * @return {!Promise.<boolean>} 263 * @return {!Promise.<boolean>}
264 */ 264 */
265 setText(text, majorChange) { 265 setText(text, majorChange) {
266 return this._cssModel.setStyleText(this.styleSheetId, this.range, text, majo rChange); 266 return this._cssModel.setStyleText(this.styleSheetId, this.range, text, majo rChange);
(...skipping 13 matching lines...) Expand all
280 * @param {string} name 280 * @param {string} name
281 * @param {string} value 281 * @param {string} value
282 * @param {function(boolean)=} userCallback 282 * @param {function(boolean)=} userCallback
283 */ 283 */
284 appendProperty(name, value, userCallback) { 284 appendProperty(name, value, userCallback) {
285 this.insertPropertyAt(this.allProperties.length, name, value, userCallback); 285 this.insertPropertyAt(this.allProperties.length, name, value, userCallback);
286 } 286 }
287 }; 287 };
288 288
289 /** @enum {string} */ 289 /** @enum {string} */
290 WebInspector.CSSStyleDeclaration.Type = { 290 SDK.CSSStyleDeclaration.Type = {
291 Regular: 'Regular', 291 Regular: 'Regular',
292 Inline: 'Inline', 292 Inline: 'Inline',
293 Attributes: 'Attributes' 293 Attributes: 'Attributes'
294 }; 294 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698