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

Side by Side Diff: Source/devtools/front_end/elements/StylesSidebarPane.js

Issue 1308663002: DevTools: simplify WI.CSSProperty and WI.CSSStyleDeclaration interfaces (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 4 months 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Joseph Pecoraro 3 * Copyright (C) 2009 Joseph Pecoraro
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 313
314 /** 314 /**
315 * @override 315 * @override
316 * @return {!Promise.<?>} 316 * @return {!Promise.<?>}
317 */ 317 */
318 doUpdate: function() 318 doUpdate: function()
319 { 319 {
320 this._discardElementUnderMouse(); 320 this._discardElementUnderMouse();
321 321
322 return this.fetchMatchedCascade() 322 return this.fetchMatchedCascade()
323 .then(this._innerRebuildUpdate.bind(this)) 323 .then(this._innerRebuildUpdate.bind(this));
324 }, 324 },
325 325
326 _resetCache: function() 326 _resetCache: function()
327 { 327 {
328 delete this._matchedCascadePromise; 328 delete this._matchedCascadePromise;
329 }, 329 },
330 330
331 /** 331 /**
332 * @return {!Promise.<?{matched: !WebInspector.SectionCascade, pseudo: !Map. <number, !WebInspector.SectionCascade>}>} 332 * @return {!Promise.<?{matched: !WebInspector.SectionCascade, pseudo: !Map. <number, !WebInspector.SectionCascade>}>}
333 */ 333 */
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 /** 618 /**
619 * @param {!WebInspector.CSSStyleDeclaration} style 619 * @param {!WebInspector.CSSStyleDeclaration} style
620 * @return {boolean} 620 * @return {boolean}
621 */ 621 */
622 _containsInherited: function(style) 622 _containsInherited: function(style)
623 { 623 {
624 var properties = style.allProperties; 624 var properties = style.allProperties;
625 for (var i = 0; i < properties.length; ++i) { 625 for (var i = 0; i < properties.length; ++i) {
626 var property = properties[i]; 626 var property = properties[i];
627 // Does this style contain non-overridden inherited property? 627 // Does this style contain non-overridden inherited property?
628 if (property.isLive && WebInspector.CSSMetadata.isPropertyInherited( property.name)) 628 if (property.activeInStyle() && WebInspector.CSSMetadata.isPropertyI nherited(property.name))
629 return true; 629 return true;
630 } 630 }
631 return false; 631 return false;
632 }, 632 },
633 633
634 _createNewRuleInViaInspectorStyleSheet: function() 634 _createNewRuleInViaInspectorStyleSheet: function()
635 { 635 {
636 var cssModel = this.cssModel(); 636 var cssModel = this.cssModel();
637 var node = this.node(); 637 var node = this.node();
638 if (!cssModel || !node) 638 if (!cssModel || !node)
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
1276 } 1276 }
1277 }, 1277 },
1278 1278
1279 _afterUpdateFinishedForTest: function() 1279 _afterUpdateFinishedForTest: function()
1280 { 1280 {
1281 }, 1281 },
1282 1282
1283 onpopulate: function() 1283 onpopulate: function()
1284 { 1284 {
1285 var style = this.styleRule.style(); 1285 var style = this.styleRule.style();
1286 var allProperties = style.allProperties; 1286 for (var property of style.leadingProperties()) {
1287
1288 var styleHasEditableSource = this.editable && !!style.range;
1289 if (styleHasEditableSource) {
1290 for (var i = 0; i < allProperties.length; ++i) {
1291 var property = allProperties[i];
1292 if (property.styleBased)
1293 continue;
1294
1295 var isShorthand = !!WebInspector.CSSMetadata.cssPropertiesMetain fo.longhands(property.name);
1296 var inherited = this.isPropertyInherited(property.name);
1297 var overloaded = property.inactive || this.styleRule.isPropertyO verloaded(property.name);
1298 var item = new WebInspector.StylePropertyTreeElement(this._paren tPane, this.styleRule, property, isShorthand, inherited, overloaded);
1299 this.propertiesTreeOutline.appendChild(item);
1300 }
1301 return;
1302 }
1303
1304 var generatedShorthands = {};
1305 // For style-based properties, generate shorthands with values when poss ible.
1306 for (var i = 0; i < allProperties.length; ++i) {
1307 var property = allProperties[i];
1308 var isShorthand = !!WebInspector.CSSMetadata.cssPropertiesMetainfo.l onghands(property.name); 1287 var isShorthand = !!WebInspector.CSSMetadata.cssPropertiesMetainfo.l onghands(property.name);
1309
1310 // For style-based properties, try generating shorthands.
1311 var shorthands = isShorthand ? null : WebInspector.CSSMetadata.cssPr opertiesMetainfo.shorthands(property.name);
1312 var shorthandPropertyAvailable = false;
1313 for (var j = 0; shorthands && !shorthandPropertyAvailable && j < sho rthands.length; ++j) {
1314 var shorthand = shorthands[j];
1315 if (shorthand in generatedShorthands) {
1316 shorthandPropertyAvailable = true;
1317 continue; // There already is a shorthand this longhands fa lls under.
1318 }
1319 if (style.getLiveProperty(shorthand)) {
pfeldman 2015/08/21 17:40:42 Could you please split the move and the refactorin
1320 shorthandPropertyAvailable = true;
1321 continue; // There is an explict shorthand property this lo nghands falls under.
1322 }
1323 if (!style.shorthandValue(shorthand)) {
1324 shorthandPropertyAvailable = false;
1325 continue; // Never generate synthetic shorthands when no va lue is available.
1326 }
1327
1328 // Generate synthetic shorthand we have a value for.
1329 var shorthandProperty = new WebInspector.CSSProperty(style, styl e.allProperties.length, shorthand, style.shorthandValue(shorthand), style.shorth andIsImportant(shorthand), false, true, true);
1330 var overloaded = property.inactive || this.styleRule.isPropertyO verloaded(property.name, true);
1331 var item = new WebInspector.StylePropertyTreeElement(this._paren tPane, this.styleRule, shorthandProperty, /* isShorthand */ true, /* inherited */ false, overloaded);
1332 this.propertiesTreeOutline.appendChild(item);
1333 generatedShorthands[shorthand] = shorthandProperty;
1334 shorthandPropertyAvailable = true;
1335 }
1336 if (shorthandPropertyAvailable)
1337 continue; // Shorthand for the property found.
1338
1339 var inherited = this.isPropertyInherited(property.name); 1288 var inherited = this.isPropertyInherited(property.name);
1340 var overloaded = property.inactive || this.styleRule.isPropertyOverl oaded(property.name, isShorthand); 1289 var overloaded = this.styleRule.isPropertyOverloaded(property.name, isShorthand);
1341 var item = new WebInspector.StylePropertyTreeElement(this._parentPan e, this.styleRule, property, isShorthand, inherited, overloaded); 1290 var item = new WebInspector.StylePropertyTreeElement(this._parentPan e, this.styleRule, property, isShorthand, inherited, overloaded);
1342 this.propertiesTreeOutline.appendChild(item); 1291 this.propertiesTreeOutline.appendChild(item);
1343 } 1292 }
1344 }, 1293 },
1345 1294
1346 /** 1295 /**
1347 * @return {boolean} 1296 * @return {boolean}
1348 */ 1297 */
1349 _updateFilter: function() 1298 _updateFilter: function()
1350 { 1299 {
(...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after
2217 var name = longhandProperties[i].name; 2166 var name = longhandProperties[i].name;
2218 var inherited = false; 2167 var inherited = false;
2219 var overloaded = false; 2168 var overloaded = false;
2220 2169
2221 var section = this.section(); 2170 var section = this.section();
2222 if (section) { 2171 if (section) {
2223 inherited = section.isPropertyInherited(name); 2172 inherited = section.isPropertyInherited(name);
2224 overloaded = section.styleRule.isPropertyOverloaded(name); 2173 overloaded = section.styleRule.isPropertyOverloaded(name);
2225 } 2174 }
2226 2175
2227 var liveProperty = this.style().getLiveProperty(name); 2176 var item = new WebInspector.StylePropertyTreeElement(this._parentPan e, this._styleRule, longhandProperties[i], false, inherited, overloaded);
2228 if (!liveProperty)
2229 continue;
2230
2231 var item = new WebInspector.StylePropertyTreeElement(this._parentPan e, this._styleRule, liveProperty, false, inherited, overloaded);
2232 this.appendChild(item); 2177 this.appendChild(item);
2233 } 2178 }
2234 }, 2179 },
2235 2180
2236 /** 2181 /**
2237 * @override 2182 * @override
2238 */ 2183 */
2239 onattach: function() 2184 onattach: function()
2240 { 2185 {
2241 this.updateTitle(); 2186 this.updateTitle();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2295 if (this.property.disabled) 2240 if (this.property.disabled)
2296 this.listItemElement.createChild("span", "styles-clipboard-only").cr eateTextChild(" */"); 2241 this.listItemElement.createChild("span", "styles-clipboard-only").cr eateTextChild(" */");
2297 2242
2298 if (!this.property.parsedOk) { 2243 if (!this.property.parsedOk) {
2299 // Avoid having longhands under an invalid shorthand. 2244 // Avoid having longhands under an invalid shorthand.
2300 this.listItemElement.classList.add("not-parsed-ok"); 2245 this.listItemElement.classList.add("not-parsed-ok");
2301 2246
2302 // Add a separate exclamation mark IMG element with a tooltip. 2247 // Add a separate exclamation mark IMG element with a tooltip.
2303 this.listItemElement.insertBefore(WebInspector.StylesSidebarPane.cre ateExclamationMark(this.property), this.listItemElement.firstChild); 2248 this.listItemElement.insertBefore(WebInspector.StylesSidebarPane.cre ateExclamationMark(this.property), this.listItemElement.firstChild);
2304 } 2249 }
2305 if (this.property.inactive) 2250 if (!this.property.activeInStyle())
2306 this.listItemElement.classList.add("inactive"); 2251 this.listItemElement.classList.add("inactive");
2307 this._updateFilter(); 2252 this._updateFilter();
2308 2253
2309 if (this.property.parsedOk && this.section() && this.parent.root) { 2254 if (this.property.parsedOk && this.section() && this.parent.root) {
2310 var enabledCheckboxElement = createElement("input"); 2255 var enabledCheckboxElement = createElement("input");
2311 enabledCheckboxElement.className = "enabled-button"; 2256 enabledCheckboxElement.className = "enabled-button";
2312 enabledCheckboxElement.type = "checkbox"; 2257 enabledCheckboxElement.type = "checkbox";
2313 enabledCheckboxElement.checked = !this.property.disabled; 2258 enabledCheckboxElement.checked = !this.property.disabled;
2314 enabledCheckboxElement.addEventListener("click", this._toggleEnabled .bind(this), false); 2259 enabledCheckboxElement.addEventListener("click", this._toggleEnabled .bind(this), false);
2315 this.listItemElement.insertBefore(enabledCheckboxElement, this.listI temElement.firstChild); 2260 this.listItemElement.insertBefore(enabledCheckboxElement, this.listI temElement.firstChild);
(...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after
3241 3186
3242 /** 3187 /**
3243 * @override 3188 * @override
3244 * @return {?WebInspector.ToolbarItem} 3189 * @return {?WebInspector.ToolbarItem}
3245 */ 3190 */
3246 item: function() 3191 item: function()
3247 { 3192 {
3248 return this._button; 3193 return this._button;
3249 } 3194 }
3250 } 3195 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698