DevTools: [SSP] refactoring to remove styleRule.section property

The patch is a first step towards cleaning up StylesSidebarPane and
introduction of structured object instead of styleRule objects.

This patch removes styleRule.section property, and kills unneeded
section.uniqueProperties list.

R=vsevik, pfeldman

Review URL: https://codereview.chromium.org/699873002

git-svn-id: svn://svn.chromium.org/blink/trunk@184875 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 96cd6b7a
...@@ -235,7 +235,7 @@ InspectorTest.dumpSelectedElementStyles = function(excludeComputed, excludeMatch ...@@ -235,7 +235,7 @@ InspectorTest.dumpSelectedElementStyles = function(excludeComputed, excludeMatch
continue; continue;
if (section.element.previousSibling && section.element.previousSibling.className === "sidebar-separator") if (section.element.previousSibling && section.element.previousSibling.className === "sidebar-separator")
InspectorTest.addResult("======== " + section.element.previousSibling.textContent + " ========"); InspectorTest.addResult("======== " + section.element.previousSibling.textContent + " ========");
InspectorTest.addResult((section.expanded ? "[expanded] " : "[collapsed] ") + (section.noAffect ? "[no-affect] " : "")); InspectorTest.addResult((section.expanded ? "[expanded] " : "[collapsed] ") + (section.element.classList.contains("no-affect") ? "[no-affect] " : ""));
var chainEntries = section.titleElement.querySelectorAll(".media-list .media"); var chainEntries = section.titleElement.querySelectorAll(".media-list .media");
chainEntries = Array.prototype.slice.call(chainEntries); chainEntries = Array.prototype.slice.call(chainEntries);
if (section.titleElement.children[1]) if (section.titleElement.children[1])
......
...@@ -132,6 +132,14 @@ WebInspector.StylesSidebarPane._colorFormat = function(color) ...@@ -132,6 +132,14 @@ WebInspector.StylesSidebarPane._colorFormat = function(color)
return format; return format;
} }
/**
* @return {boolean}
*/
WebInspector.StylesSidebarPane._hasMatchingSelectors = function(styleRule)
{
return styleRule.rule ? styleRule.rule.matchingSelectors.length > 0 : true;
}
/** /**
* @param {!WebInspector.CSSProperty} property * @param {!WebInspector.CSSProperty} property
*/ */
...@@ -637,15 +645,25 @@ WebInspector.StylesSidebarPane.prototype = { ...@@ -637,15 +645,25 @@ WebInspector.StylesSidebarPane.prototype = {
_innerRefreshUpdate: function(node, computedStyle, editedSection) _innerRefreshUpdate: function(node, computedStyle, editedSection)
{ {
for (var pseudoId in this.sections) { for (var pseudoId in this.sections) {
var styleRules = this._refreshStyleRules(this.sections[pseudoId], computedStyle); var filteredSections = this.sections[pseudoId] ? this.sections[pseudoId].filter(nonBlankSections) : [];
var styleRules = this._refreshStyleRules(filteredSections, computedStyle);
var usedProperties = {}; var usedProperties = {};
this._markUsedProperties(styleRules, usedProperties); this._markUsedProperties(styleRules, usedProperties);
this._refreshSectionsForStyleRules(styleRules, usedProperties, editedSection); this._refreshSectionsForStyleRules(filteredSections, styleRules, usedProperties, editedSection);
} }
if (computedStyle) if (computedStyle)
this.sections[0][0].rebuildComputedTrace(this.sections[0]); this.sections[0][0].rebuildComputedTrace(this.sections[0]);
this._nodeStylesUpdatedForTest(node, false); this._nodeStylesUpdatedForTest(node, false);
/**
* @param {!WebInspector.PropertiesSection} section
* @return {boolean}
*/
function nonBlankSections(section)
{
return !section.isBlank;
}
}, },
_innerRebuildUpdate: function(node, styles) _innerRebuildUpdate: function(node, styles)
...@@ -697,11 +715,9 @@ WebInspector.StylesSidebarPane.prototype = { ...@@ -697,11 +715,9 @@ WebInspector.StylesSidebarPane.prototype = {
var styleRules = []; var styleRules = [];
for (var i = 0; sections && i < sections.length; ++i) { for (var i = 0; sections && i < sections.length; ++i) {
var section = sections[i]; var section = sections[i];
if (section.isBlank)
continue;
if (section.computedStyle) if (section.computedStyle)
section.styleRule.style = nodeComputedStyle; section.styleRule.style = nodeComputedStyle;
var styleRule = { section: section, style: section.styleRule.style, computedStyle: section.computedStyle, rule: section.rule, editable: !!(section.styleRule.style && section.styleRule.style.styleSheetId), var styleRule = { style: section.styleRule.style, computedStyle: section.computedStyle, rule: section.rule, editable: !!(section.styleRule.style && section.styleRule.style.styleSheetId),
isAttribute: section.styleRule.isAttribute, isInherited: section.styleRule.isInherited, parentNode: section.styleRule.parentNode }; isAttribute: section.styleRule.isAttribute, isInherited: section.styleRule.isInherited, parentNode: section.styleRule.parentNode };
styleRules.push(styleRule); styleRules.push(styleRule);
} }
...@@ -800,7 +816,7 @@ WebInspector.StylesSidebarPane.prototype = { ...@@ -800,7 +816,7 @@ WebInspector.StylesSidebarPane.prototype = {
var styleRule = styleRules[i]; var styleRule = styleRules[i];
if (styleRule.computedStyle || styleRule.isStyleSeparator) if (styleRule.computedStyle || styleRule.isStyleSeparator)
continue; continue;
if (styleRule.section && styleRule.section.noAffect) if (!WebInspector.StylesSidebarPane._hasMatchingSelectors(styleRule))
continue; continue;
styleRule.usedProperties = {}; styleRule.usedProperties = {};
...@@ -843,12 +859,12 @@ WebInspector.StylesSidebarPane.prototype = { ...@@ -843,12 +859,12 @@ WebInspector.StylesSidebarPane.prototype = {
} }
}, },
_refreshSectionsForStyleRules: function(styleRules, usedProperties, editedSection) _refreshSectionsForStyleRules: function(sections, styleRules, usedProperties, editedSection)
{ {
// Walk the style rules and update the sections with new overloaded and used properties. // Walk the style rules and update the sections with new overloaded and used properties.
for (var i = 0; i < styleRules.length; ++i) { for (var i = 0; i < styleRules.length; ++i) {
var styleRule = styleRules[i]; var styleRule = styleRules[i];
var section = styleRule.section; var section = sections[i];
if (styleRule.computedStyle) { if (styleRule.computedStyle) {
section._usedProperties = usedProperties; section._usedProperties = usedProperties;
section.update(); section.update();
...@@ -1438,7 +1454,7 @@ WebInspector.StylePropertiesSection.prototype = { ...@@ -1438,7 +1454,7 @@ WebInspector.StylePropertiesSection.prototype = {
*/ */
isPropertyOverloaded: function(propertyName, isShorthand) isPropertyOverloaded: function(propertyName, isShorthand)
{ {
if (!this._usedProperties || this.noAffect) if (!this._usedProperties || !WebInspector.StylesSidebarPane._hasMatchingSelectors(this.styleRule))
return false; return false;
if (this.isInherited && !WebInspector.CSSMetadata.isPropertyInherited(propertyName)) { if (this.isInherited && !WebInspector.CSSMetadata.isPropertyInherited(propertyName)) {
...@@ -1536,13 +1552,11 @@ WebInspector.StylePropertiesSection.prototype = { ...@@ -1536,13 +1552,11 @@ WebInspector.StylePropertiesSection.prototype = {
{ {
var style = this.styleRule.style; var style = this.styleRule.style;
var allProperties = style.allProperties; var allProperties = style.allProperties;
this.uniqueProperties = [];
var styleHasEditableSource = this.editable && !!style.range; var styleHasEditableSource = this.editable && !!style.range;
if (styleHasEditableSource) { if (styleHasEditableSource) {
for (var i = 0; i < allProperties.length; ++i) { for (var i = 0; i < allProperties.length; ++i) {
var property = allProperties[i]; var property = allProperties[i];
this.uniqueProperties.push(property);
if (property.styleBased) if (property.styleBased)
continue; continue;
...@@ -1559,7 +1573,6 @@ WebInspector.StylePropertiesSection.prototype = { ...@@ -1559,7 +1573,6 @@ WebInspector.StylePropertiesSection.prototype = {
// For style-based properties, generate shorthands with values when possible. // For style-based properties, generate shorthands with values when possible.
for (var i = 0; i < allProperties.length; ++i) { for (var i = 0; i < allProperties.length; ++i) {
var property = allProperties[i]; var property = allProperties[i];
this.uniqueProperties.push(property);
var isShorthand = !!WebInspector.CSSMetadata.cssPropertiesMetainfo.longhands(property.name); var isShorthand = !!WebInspector.CSSMetadata.cssPropertiesMetainfo.longhands(property.name);
// For style-based properties, try generating shorthands. // For style-based properties, try generating shorthands.
...@@ -1624,7 +1637,7 @@ WebInspector.StylePropertiesSection.prototype = { ...@@ -1624,7 +1637,7 @@ WebInspector.StylePropertiesSection.prototype = {
var matchingSelectors = rule.matchingSelectors; var matchingSelectors = rule.matchingSelectors;
// .selector is rendered as non-affecting selector by default. // .selector is rendered as non-affecting selector by default.
if (this.noAffect || matchingSelectors) if (!WebInspector.StylesSidebarPane._hasMatchingSelectors(this.styleRule) || matchingSelectors)
this._selectorElement.className = "selector"; this._selectorElement.className = "selector";
if (!matchingSelectors) if (!matchingSelectors)
return; return;
...@@ -1884,17 +1897,11 @@ WebInspector.StylePropertiesSection.prototype = { ...@@ -1884,17 +1897,11 @@ WebInspector.StylePropertiesSection.prototype = {
function successCallback(newRule) function successCallback(newRule)
{ {
var doesAffectSelectedNode = newRule.matchingSelectors.length > 0; var doesAffectSelectedNode = newRule.matchingSelectors.length > 0;
if (!doesAffectSelectedNode) { this.element.classList.toggle("no-affect", !doesAffectSelectedNode);
this.noAffect = true;
this.element.classList.add("no-affect");
} else {
delete this.noAffect;
this.element.classList.remove("no-affect");
}
var oldSelectorRange = this.rule.selectorRange; var oldSelectorRange = this.rule.selectorRange;
this.rule = newRule; this.rule = newRule;
this.styleRule = { section: this, style: newRule.style, selectorText: newRule.selectorText, media: newRule.media, rule: newRule }; this.styleRule = { style: newRule.style, selectorText: newRule.selectorText, media: newRule.media, rule: newRule };
this._parentPane._refreshUpdate(this, false); this._parentPane._refreshUpdate(this, false);
this._parentPane._styleSheetRuleEdited(this.rule, oldSelectorRange, this.rule.selectorRange); this._parentPane._styleSheetRuleEdited(this.rule, oldSelectorRange, this.rule.selectorRange);
...@@ -2060,8 +2067,9 @@ WebInspector.ComputedStylePropertiesSection.prototype = { ...@@ -2060,8 +2067,9 @@ WebInspector.ComputedStylePropertiesSection.prototype = {
if (section.computedStyle || section.isBlank) if (section.computedStyle || section.isBlank)
continue; continue;
for (var j = 0; j < section.uniqueProperties.length; ++j) { var properties = section.styleRule.style.allProperties;
var property = section.uniqueProperties[j]; for (var j = 0; j < properties.length; ++j) {
var property = properties[j];
if (property.disabled) if (property.disabled)
continue; continue;
if (section.isInherited && !WebInspector.CSSMetadata.isPropertyInherited(property.name)) if (section.isInherited && !WebInspector.CSSMetadata.isPropertyInherited(property.name))
...@@ -2168,13 +2176,11 @@ WebInspector.BlankStylePropertiesSection.prototype = { ...@@ -2168,13 +2176,11 @@ WebInspector.BlankStylePropertiesSection.prototype = {
function successCallback(newRule) function successCallback(newRule)
{ {
var doesSelectorAffectSelectedNode = newRule.matchingSelectors.length > 0; var doesSelectorAffectSelectedNode = newRule.matchingSelectors.length > 0;
var styleRule = { media: newRule.media, section: this, style: newRule.style, selectorText: newRule.selectorText, rule: newRule }; var styleRule = { media: newRule.media, style: newRule.style, selectorText: newRule.selectorText, rule: newRule };
this._makeNormal(styleRule); this._makeNormal(styleRule);
if (!doesSelectorAffectSelectedNode) { if (!doesSelectorAffectSelectedNode)
this.noAffect = true;
this.element.classList.add("no-affect"); this.element.classList.add("no-affect");
}
var ruleTextLines = ruleText.split("\n"); var ruleTextLines = ruleText.split("\n");
var startLine = this._ruleLocation.startLine; var startLine = this._ruleLocation.startLine;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment