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

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

Issue 1320543002: DevTools: simplify & fix property overload logic (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 3 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 // Copyright (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2014 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 /** 5 /**
6 * @constructor 6 * @constructor
7 * @param {!WebInspector.SectionCascade} cascade 7 * @param {!WebInspector.SectionCascade} cascade
8 * @param {?WebInspector.CSSRule} rule 8 * @param {?WebInspector.CSSRule} rule
9 * @param {!WebInspector.CSSStyleDeclaration} style 9 * @param {!WebInspector.CSSStyleDeclaration} style
10 * @param {string} customSelectorText 10 * @param {string} customSelectorText
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 { 150 {
151 this._style = style; 151 this._style = style;
152 if (this._rule) { 152 if (this._rule) {
153 style.parentRule = this._rule; 153 style.parentRule = this._rule;
154 this._rule.style = style; 154 this._rule.style = style;
155 } 155 }
156 this._cascade._resetUsedProperties(); 156 this._cascade._resetUsedProperties();
157 }, 157 },
158 158
159 /** 159 /**
160 * @return {!Set.<string>}
161 */
162 usedProperties: function()
163 {
164 return this._cascade._usedPropertiesForModel(this);
165 },
166
167 /**
168 * @param {string} propertyName 160 * @param {string} propertyName
169 * @param {boolean=} isShorthand
170 * @return {boolean} 161 * @return {boolean}
171 */ 162 */
172 isPropertyOverloaded: function(propertyName, isShorthand) 163 isPropertyOverloaded: function(propertyName)
173 { 164 {
174 if (!this.hasMatchingSelectors()) 165 if (!this.hasMatchingSelectors())
175 return false; 166 return false;
167 if (this.inherited() && !WebInspector.CSSMetadata.isPropertyInherited(pr opertyName))
168 return false;
176 169
177 if (this.inherited() && !WebInspector.CSSMetadata.isPropertyInherited(pr opertyName)) { 170 var usedProperties = this._cascade._usedPropertiesForModel(this);
178 // In the inherited sections, only show overrides for the potentiall y inherited properties.
179 return false;
180 }
181
182 var canonicalName = WebInspector.CSSMetadata.canonicalPropertyName(prope rtyName); 171 var canonicalName = WebInspector.CSSMetadata.canonicalPropertyName(prope rtyName);
183 var used = this.usedProperties().has(canonicalName); 172 return !usedProperties.has(canonicalName);
184 if (used || !isShorthand)
185 return !used;
186
187 // Find out if any of the individual longhand properties of the shorthan d
188 // are used, if none are then the shorthand is overloaded too.
189 var longhandProperties = this.style().longhandProperties(propertyName);
190 for (var j = 0; j < longhandProperties.length; ++j) {
191 var individualProperty = longhandProperties[j];
192 var canonicalPropertyName = WebInspector.CSSMetadata.canonicalProper tyName(individualProperty.name);
193 if (this.usedProperties().has(canonicalPropertyName))
194 return false;
195 }
196
197 return true;
198 } 173 }
199 } 174 }
200 175
201 /** 176 /**
202 * @constructor 177 * @constructor
203 */ 178 */
204 WebInspector.SectionCascade = function() 179 WebInspector.SectionCascade = function()
205 { 180 {
206 this._models = []; 181 this._models = [];
207 this._resetUsedProperties(); 182 this._resetUsedProperties();
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 328
354 foundImportantProperties.add(canonicalName); 329 foundImportantProperties.add(canonicalName);
355 if (isKnownProperty) 330 if (isKnownProperty)
356 propertyToEffectiveRule.get(canonicalName).delete(canonicalN ame); 331 propertyToEffectiveRule.get(canonicalName).delete(canonicalN ame);
357 } 332 }
358 333
359 styleRuleUsedProperties.add(canonicalName); 334 styleRuleUsedProperties.add(canonicalName);
360 allUsedProperties.add(canonicalName); 335 allUsedProperties.add(canonicalName);
361 propertyToEffectiveRule.set(canonicalName, styleRuleUsedProperties); 336 propertyToEffectiveRule.set(canonicalName, styleRuleUsedProperties);
362 } 337 }
338
339 // If every longhand of the shorthand is not active, then the shorthand is not active too.
340 for (var property of style.leadingProperties()) {
pfeldman 2015/08/26 01:32:38 I think we should stop doing this and implement it
lushnikov 2015/08/26 01:35:44 We will still have leadingProperties when your cha
341 var canonicalName = WebInspector.CSSMetadata.canonicalPropertyName(p roperty.name);
342 if (!styleRuleUsedProperties.has(canonicalName))
343 continue;
344 var longhands = style.longhandProperties(property.name);
345 if (!longhands.length)
346 continue;
347 var notUsed = true;
348 for (var longhand of longhands) {
349 var longhandCanonicalName = WebInspector.CSSMetadata.canonicalPr opertyName(longhand.name);
350 notUsed = notUsed && !styleRuleUsedProperties.has(longhandCanoni calName);
351 }
352 if (!notUsed)
353 continue;
354 styleRuleUsedProperties.delete(canonicalName);
355 allUsedProperties.delete(canonicalName);
356 }
363 } 357 }
364 return stylesUsedProperties; 358 return stylesUsedProperties;
365 } 359 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698