Web Inspector: Standardize on CSSStyleSheet.Type enum and move more protocol enum...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 27 Aug 2015 17:37:22 +0000 (17:37 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 27 Aug 2015 17:37:22 +0000 (17:37 +0000)
https://bugs.webkit.org/show_bug.cgi?id=148515

Patch by Joseph Pecoraro <pecoraro@apple.com> on 2015-08-27
Reviewed by Brian Burg.

Source/WebInspectorUI:

* UserInterface/Controllers/CSSStyleManager.js:
(WebInspector.CSSStyleManager.protocolStyleSheetOriginToEnum):
(WebInspector.CSSStyleManager.protocolMediaSourceToEnum):
Protocol enum to frontend enum conversion.

* UserInterface/Models/DOMNodeStyles.js:
(WebInspector.DOMNodeStyles.prototype.refresh.fetchedComputedStyle):
(WebInspector.DOMNodeStyles.prototype.refresh):
(WebInspector.DOMNodeStyles.prototype._parseRulePayload):
(WebInspector.DOMNodeStyles.prototype._collectStylesInCascadeOrder):
Use the manager to convert from a protocol payload enum to frontend num for css types.

* UserInterface/Models/CSSRule.js:
(WebInspector.CSSRule.prototype.get editable):
* UserInterface/Views/CSSStyleDeclarationSection.js:
(WebInspector.CSSStyleDeclarationSection):
(WebInspector.CSSStyleDeclarationSection.prototype.refresh):
* UserInterface/Views/RulesStyleDetailsPanel.js:
(WebInspector.RulesStyleDetailsPanel.prototype.refresh.appendStyleSection):
(WebInspector.RulesStyleDetailsPanel.prototype.refresh):
* UserInterface/Views/VisualStyleSelectorSection.js:
(WebInspector.VisualStyleSelectorSection.prototype.update.createSelectorItem):
(WebInspector.VisualStyleSelectorSection.prototype.update.uniqueOrderedRules.set return):
(WebInspector.VisualStyleSelectorSection.prototype.update.uniqueOrderedRules):
(WebInspector.VisualStyleSelectorSection.prototype.update):
* UserInterface/Views/VisualStyleSelectorTreeItem.js:
(WebInspector.VisualStyleSelectorTreeItem):
Update enum use.

LayoutTests:

* inspector/css/matched-style-properties.html:
* inspector/css/pseudo-element-matches.html:
* inspector/css/selector-dynamic-specificity.html:
* inspector/css/selector-specificity.html:
* inspector/css/stylesheet-with-mutations.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@189032 268f45cc-cd09-0410-ab3c-d52691b4dbfc

14 files changed:
LayoutTests/ChangeLog
LayoutTests/inspector/css/matched-style-properties.html
LayoutTests/inspector/css/pseudo-element-matches.html
LayoutTests/inspector/css/selector-dynamic-specificity.html
LayoutTests/inspector/css/selector-specificity.html
LayoutTests/inspector/css/stylesheet-with-mutations.html
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Controllers/CSSStyleManager.js
Source/WebInspectorUI/UserInterface/Models/CSSRule.js
Source/WebInspectorUI/UserInterface/Models/DOMNodeStyles.js
Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.js
Source/WebInspectorUI/UserInterface/Views/RulesStyleDetailsPanel.js
Source/WebInspectorUI/UserInterface/Views/VisualStyleSelectorSection.js
Source/WebInspectorUI/UserInterface/Views/VisualStyleSelectorTreeItem.js

index ec9fec9..fa6a290 100644 (file)
@@ -1,3 +1,16 @@
+2015-08-27  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Web Inspector: Standardize on CSSStyleSheet.Type enum and move more protocol enum conversion to the manager
+        https://bugs.webkit.org/show_bug.cgi?id=148515
+
+        Reviewed by Brian Burg.
+
+        * inspector/css/matched-style-properties.html:
+        * inspector/css/pseudo-element-matches.html:
+        * inspector/css/selector-dynamic-specificity.html:
+        * inspector/css/selector-specificity.html:
+        * inspector/css/stylesheet-with-mutations.html:
+
 2015-08-27  Eric Carlson  <eric.carlson@apple.com>
 
         Media Session: MediaSession constructor 'kind' argument optional
index 6780eec..9d81e63 100644 (file)
@@ -35,7 +35,7 @@ function test() {
     {
         for (var i = 0; i < nodeStyles.matchedRules.length; ++i) {
             var rule = nodeStyles.matchedRules[i];
-            if (rule.type !== WebInspector.CSSRule.Type.Author)
+            if (rule.type !== WebInspector.CSSStyleSheet.Type.Author)
                 continue;
 
             for (var j = 0; j < rule.style.properties.length; ++j) {
index 5073f42..539ad22 100644 (file)
@@ -12,7 +12,7 @@ function test() {
 
         for (var i = 0; i < nodeStyles.matchedRules.length; ++i) {
             var rule = nodeStyles.matchedRules[i];
-            if (rule.type !== WebInspector.CSSRule.Type.UserAgent)
+            if (rule.type !== WebInspector.CSSStyleSheet.Type.UserAgent)
                 continue;
             if (rule.selectorText.indexOf("::-webkit-media-text-track-container") === -1)
                 continue;
index 484dea7..70ba73e 100644 (file)
@@ -33,7 +33,7 @@ function test() {
 
         for (var i = 0; i < nodeStyles.matchedRules.length; ++i) {
             var rule = nodeStyles.matchedRules[i];
-            if (rule.type !== WebInspector.CSSRule.Type.Author)
+            if (rule.type !== WebInspector.CSSStyleSheet.Type.Author)
                 continue;
 
             if (seenRules.some(function(r) { return r.isEqualTo(rule); }))
index a59e951..a671515 100644 (file)
@@ -25,7 +25,7 @@ function test() {
     {
         for (var i = 0; i < nodeStyles.matchedRules.length; ++i) {
             var rule = nodeStyles.matchedRules[i];
-            if (rule.type !== WebInspector.CSSRule.Type.Author)
+            if (rule.type !== WebInspector.CSSStyleSheet.Type.Author)
                 continue;
 
             for (var selector of rule.selectors)
index 8c74ef1..bff1149 100644 (file)
@@ -16,7 +16,7 @@ function test() {
     {
         for (var i = 0; i < nodeStyles.matchedRules.length; ++i) {
             var rule = nodeStyles.matchedRules[i];
-            if (rule.type !== WebInspector.CSSRule.Type.Author)
+            if (rule.type !== WebInspector.CSSStyleSheet.Type.Author)
                 continue;
 
             for (var selector of rule.selectors)
index 4512555..58022fe 100644 (file)
@@ -1,3 +1,39 @@
+2015-08-27  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Web Inspector: Standardize on CSSStyleSheet.Type enum and move more protocol enum conversion to the manager
+        https://bugs.webkit.org/show_bug.cgi?id=148515
+
+        Reviewed by Brian Burg.
+
+        * UserInterface/Controllers/CSSStyleManager.js:
+        (WebInspector.CSSStyleManager.protocolStyleSheetOriginToEnum):
+        (WebInspector.CSSStyleManager.protocolMediaSourceToEnum):
+        Protocol enum to frontend enum conversion.
+
+        * UserInterface/Models/DOMNodeStyles.js:
+        (WebInspector.DOMNodeStyles.prototype.refresh.fetchedComputedStyle):
+        (WebInspector.DOMNodeStyles.prototype.refresh):
+        (WebInspector.DOMNodeStyles.prototype._parseRulePayload):
+        (WebInspector.DOMNodeStyles.prototype._collectStylesInCascadeOrder):
+        Use the manager to convert from a protocol payload enum to frontend num for css types.
+
+        * UserInterface/Models/CSSRule.js:
+        (WebInspector.CSSRule.prototype.get editable):
+        * UserInterface/Views/CSSStyleDeclarationSection.js:
+        (WebInspector.CSSStyleDeclarationSection):
+        (WebInspector.CSSStyleDeclarationSection.prototype.refresh):
+        * UserInterface/Views/RulesStyleDetailsPanel.js:
+        (WebInspector.RulesStyleDetailsPanel.prototype.refresh.appendStyleSection):
+        (WebInspector.RulesStyleDetailsPanel.prototype.refresh):
+        * UserInterface/Views/VisualStyleSelectorSection.js:
+        (WebInspector.VisualStyleSelectorSection.prototype.update.createSelectorItem):
+        (WebInspector.VisualStyleSelectorSection.prototype.update.uniqueOrderedRules.set return):
+        (WebInspector.VisualStyleSelectorSection.prototype.update.uniqueOrderedRules):
+        (WebInspector.VisualStyleSelectorSection.prototype.update):
+        * UserInterface/Views/VisualStyleSelectorTreeItem.js:
+        (WebInspector.VisualStyleSelectorTreeItem):
+        Update enum use.
+
 2015-08-26  Nikita Vasilyev  <nvasilyev@apple.com>
 
         Web Inspector: [Regression] [Mavericks]: Undocked Web Inspector toolbar is two different colors and has extra space
index ac2b658..f9901d6 100644 (file)
@@ -56,7 +56,6 @@ WebInspector.CSSStyleManager = class CSSStyleManager extends WebInspector.Object
 
     static protocolStyleSheetOriginToEnum(origin)
     {
-        // FIXME: Switch from CSSRule.Type to CSSStyleSheet.Type everywhere.
         switch (origin) {
         case CSSAgent.StyleSheetOrigin.Regular:
             return WebInspector.CSSStyleSheet.Type.Author;
@@ -67,11 +66,28 @@ WebInspector.CSSStyleManager = class CSSStyleManager extends WebInspector.Object
         case CSSAgent.StyleSheetOrigin.Inspector:
             return WebInspector.CSSStyleSheet.Type.Inspector;
         default:
-            console.assert(false, "Unknown StyleSheetOrigin", origin);
+            console.assert(false, "Unknown CSS.StyleSheetOrigin", origin);
             return CSSAgent.StyleSheetOrigin.Regular;
         }
     }
 
+    static protocolMediaSourceToEnum(source)
+    {
+        switch (source) {
+        case CSSAgent.CSSMediaSource.MediaRule:
+            return WebInspector.CSSMedia.Type.MediaRule;
+        case CSSAgent.CSSMediaSource.ImportRule:
+            return WebInspector.CSSMedia.Type.ImportRule;
+        case CSSAgent.CSSMediaSource.LinkedSheet:
+            return WebInspector.CSSMedia.Type.LinkedStyleSheet;
+        case CSSAgent.CSSMediaSource.InlineSheet:
+            return WebInspector.CSSMedia.Type.InlineStyleSheet;
+        default:
+            console.assert(false, "Unknown CSS.CSSMediaSource", origin);
+            return WebInspector.CSSMedia.Type.MediaRule;
+        }
+    }
+
     // Public
 
     get preferredColorFormat()
index c7a8a57..4a5d9e4 100644 (file)
@@ -53,7 +53,7 @@ WebInspector.CSSRule = class CSSRule extends WebInspector.Object
 
     get editable()
     {
-        return !!this._id && (this._type === WebInspector.CSSRule.Type.Author || this._type === WebInspector.CSSRule.Type.Inspector);
+        return !!this._id && (this._type === WebInspector.CSSStyleSheet.Type.Author || this._type === WebInspector.CSSStyleSheet.Type.Inspector);
     }
 
     update(sourceCodeLocation, selectorText, selectors, matchedSelectorIndices, style, mediaList, dontFireEvents)
@@ -247,10 +247,3 @@ WebInspector.CSSRule.Event = {
     Changed: "css-rule-changed",
     SelectorChanged: "css-rule-invalid-selector"
 };
-
-WebInspector.CSSRule.Type = {
-    Author: "css-rule-type-author",
-    User: "css-rule-type-user",
-    UserAgent: "css-rule-type-user-agent",
-    Inspector: "css-rule-type-inspector"
-};
index 8c88d54..ab96be6 100644 (file)
@@ -170,7 +170,7 @@ WebInspector.DOMNodeStyles = class DOMNodeStyles extends WebInspector.Object
                     if (!this._includeUserAgentRulesOnNextRefresh) {
                         // We can assume all the styles with the same key are from the same stylesheet and rule, so we only check the first.
                         var firstStyle = this._styleDeclarationsMap[key][0];
-                        if (firstStyle && firstStyle.ownerRule && firstStyle.ownerRule.type === WebInspector.CSSRule.Type.UserAgent) {
+                        if (firstStyle && firstStyle.ownerRule && firstStyle.ownerRule.type === WebInspector.CSSStyleSheet.Type.UserAgent) {
                             // User Agent styles get different identifiers after some edits. This would cause us to fire a significant refreshed
                             // event more than it is helpful. And since the user agent stylesheet is static it shouldn't match differently
                             // between refreshes for the same node. This issue is tracked by: https://webkit.org/b/110055
@@ -193,7 +193,7 @@ WebInspector.DOMNodeStyles = class DOMNodeStyles extends WebInspector.Object
                     if (!this._includeUserAgentRulesOnNextRefresh) {
                         // See above for why we skip user agent style rules.
                         var firstStyle = this._previousStyleDeclarationsMap[key][0];
-                        if (firstStyle && firstStyle.ownerRule && firstStyle.ownerRule.type === WebInspector.CSSRule.Type.UserAgent)
+                        if (firstStyle && firstStyle.ownerRule && firstStyle.ownerRule.type === WebInspector.CSSStyleSheet.Type.UserAgent)
                             continue;
                     }
 
@@ -684,6 +684,7 @@ WebInspector.DOMNodeStyles = class DOMNodeStyles extends WebInspector.Object
 
         var selectorText = payload.selectorList.text;
         var selectors = this._parseSelectorListPayload(payload.selectorList);
+        var type = WebInspector.CSSStyleManager.protocolStyleSheetOriginToEnum(payload.origin);
 
         var sourceCodeLocation = null;
         var sourceRange = payload.selectorList.range;
@@ -697,42 +698,10 @@ WebInspector.DOMNodeStyles = class DOMNodeStyles extends WebInspector.Object
         if (styleSheet)
             sourceCodeLocation = styleSheet.offsetSourceCodeLocation(sourceCodeLocation);
 
-        var type;
-        switch (payload.origin) {
-        case "regular":
-            type = WebInspector.CSSRule.Type.Author;
-            break;
-        case "user":
-            type = WebInspector.CSSRule.Type.User;
-            break;
-        case "user-agent":
-            type = WebInspector.CSSRule.Type.UserAgent;
-            break;
-        case "inspector":
-            type = WebInspector.CSSRule.Type.Inspector;
-            break;
-        }
-
         var mediaList = [];
         for (var i = 0; payload.media && i < payload.media.length; ++i) {
             var mediaItem = payload.media[i];
-
-            var mediaType;
-            switch (mediaItem.source) {
-            case "mediaRule":
-                mediaType = WebInspector.CSSMedia.Type.MediaRule;
-                break;
-            case "importRule":
-                mediaType = WebInspector.CSSMedia.Type.ImportRule;
-                break;
-            case "linkedSheet":
-                mediaType = WebInspector.CSSMedia.Type.LinkedStyleSheet;
-                break;
-            case "inlineSheet":
-                mediaType = WebInspector.CSSMedia.Type.InlineStyleSheet;
-                break;
-            }
-
+            var mediaType = WebInspector.CSSStyleManager.protocolMediaSourceToEnum(mediaItem.source);
             var mediaText = mediaItem.text;
             var mediaSourceCodeLocation = this._createSourceCodeLocation(mediaItem.sourceURL, mediaItem.sourceLine);
             if (styleSheet)
@@ -820,13 +789,13 @@ WebInspector.DOMNodeStyles = class DOMNodeStyles extends WebInspector.Object
             // Only append to the result array here for author and inspector rules since attribute
             // styles come between author rules and user/user agent rules.
             switch (rule.type) {
-            case WebInspector.CSSRule.Type.Inspector:
-            case WebInspector.CSSRule.Type.Author:
+            case WebInspector.CSSStyleSheet.Type.Inspector:
+            case WebInspector.CSSStyleSheet.Type.Author:
                 result.push(rule.style);
                 break;
 
-            case WebInspector.CSSRule.Type.User:
-            case WebInspector.CSSRule.Type.UserAgent:
+            case WebInspector.CSSStyleSheet.Type.User:
+            case WebInspector.CSSStyleSheet.Type.UserAgent:
                 userAndUserAgentStyles.push(rule.style);
                 break;
             }
index 7f9bcfa..96d7c7d 100644 (file)
@@ -80,13 +80,13 @@ WebInspector.CSSStyleDeclarationSection = class CSSStyleDeclarationSection exten
 
             if (style.inherited)
                 iconClassName = WebInspector.CSSStyleDeclarationSection.InheritedStyleRuleIconStyleClassName;
-            else if (style.ownerRule.type === WebInspector.CSSRule.Type.Author)
+            else if (style.ownerRule.type === WebInspector.CSSStyleSheet.Type.Author)
                 iconClassName = WebInspector.CSSStyleDeclarationSection.AuthorStyleRuleIconStyleClassName;
-            else if (style.ownerRule.type === WebInspector.CSSRule.Type.User)
+            else if (style.ownerRule.type === WebInspector.CSSStyleSheet.Type.User)
                 iconClassName = WebInspector.CSSStyleDeclarationSection.UserStyleRuleIconStyleClassName;
-            else if (style.ownerRule.type === WebInspector.CSSRule.Type.UserAgent)
+            else if (style.ownerRule.type === WebInspector.CSSStyleSheet.Type.UserAgent)
                 iconClassName = WebInspector.CSSStyleDeclarationSection.UserAgentStyleRuleIconStyleClassName;
-            else if (style.ownerRule.type === WebInspector.CSSRule.Type.Inspector)
+            else if (style.ownerRule.type === WebInspector.CSSStyleSheet.Type.Inspector)
                 iconClassName = WebInspector.CSSStyleDeclarationSection.InspectorStyleRuleIconStyleClassName;
             break;
 
@@ -234,19 +234,19 @@ WebInspector.CSSStyleDeclarationSection = class CSSStyleDeclarationSection exten
             } else {
                 var originString;
                 switch (this._style.ownerRule.type) {
-                case WebInspector.CSSRule.Type.Author:
+                case WebInspector.CSSStyleSheet.Type.Author:
                     originString = WebInspector.UIString("Author Stylesheet");
                     break;
 
-                case WebInspector.CSSRule.Type.User:
+                case WebInspector.CSSStyleSheet.Type.User:
                     originString = WebInspector.UIString("User Stylesheet");
                     break;
 
-                case WebInspector.CSSRule.Type.UserAgent:
+                case WebInspector.CSSStyleSheet.Type.UserAgent:
                     originString = WebInspector.UIString("User Agent Stylesheet");
                     break;
 
-                case WebInspector.CSSRule.Type.Inspector:
+                case WebInspector.CSSStyleSheet.Type.Inspector:
                     originString = WebInspector.UIString("Web Inspector");
                     break;
                 }
index b3c110b..5ff00c4 100644 (file)
@@ -164,7 +164,7 @@ WebInspector.RulesStyleDetailsPanel = class RulesStyleDetailsPanel extends WebIn
             } else
                 section.refresh();
 
-            if (this._focusNextNewInspectorRule && style.ownerRule && style.ownerRule.type === WebInspector.CSSRule.Type.Inspector) {
+            if (this._focusNextNewInspectorRule && style.ownerRule && style.ownerRule.type === WebInspector.CSSStyleSheet.Type.Inspector) {
                 this._previousFocusedSection = section;
                 delete this._focusNextNewInspectorRule;
             }
@@ -282,7 +282,7 @@ WebInspector.RulesStyleDetailsPanel = class RulesStyleDetailsPanel extends WebIn
         this._ruleMediaAndInherticanceList = [];
         var orderedStyles = uniqueOrderedStyles(this.nodeStyles.orderedStyles);
         for (var style of orderedStyles) {
-            var isUserAgentStyle = style.ownerRule && style.ownerRule.type === WebInspector.CSSRule.Type.UserAgent;
+            var isUserAgentStyle = style.ownerRule && style.ownerRule.type === WebInspector.CSSStyleSheet.Type.UserAgent;
             insertAllMatchingPseudoStyles.call(this, isUserAgentStyle || style.inerhited);
 
             insertMediaOrInheritanceLabel.call(this, style);
index c5039e6..99faccc 100644 (file)
@@ -101,7 +101,7 @@ WebInspector.VisualStyleSelectorSection = class VisualStyleSelectorSection exten
             selector.addEventListener(WebInspector.VisualStyleSelectorTreeItem.Event.CheckboxChanged, this._treeElementCheckboxToggled, this);
             this._selectors.appendChild(selector);
 
-            if (this._focusNextNewInspectorRule && style.ownerRule && style.ownerRule.type === WebInspector.CSSRule.Type.Inspector) {
+            if (this._focusNextNewInspectorRule && style.ownerRule && style.ownerRule.type === WebInspector.CSSStyleSheet.Type.Inspector) {
                 selector.select(true);
                 selector.element.scrollIntoView();
                 this._nodeStyles[WebInspector.VisualStyleSelectorSection.LastSelectedRuleSymbol] = style;
@@ -166,7 +166,7 @@ WebInspector.VisualStyleSelectorSection = class VisualStyleSelectorSection exten
 
         // Matched Rules
         for (let rule of uniqueOrderedRules(this._nodeStyles.matchedRules)) {
-            if (rule.type === WebInspector.CSSRule.Type.UserAgent) {
+            if (rule.type === WebInspector.CSSStyleSheet.Type.UserAgent) {
                 insertAllMatchingPseudoRules.call(this, true);
                 continue;
             }
@@ -190,7 +190,7 @@ WebInspector.VisualStyleSelectorSection = class VisualStyleSelectorSection exten
             this._selectors.appendChild(divider);
 
             for (let rule of uniqueOrderedRules(inherited.matchedRules)) {
-                if (rule.type === WebInspector.CSSRule.Type.UserAgent)
+                if (rule.type === WebInspector.CSSStyleSheet.Type.UserAgent)
                     continue;
 
                 createSelectorItem.call(this, rule.style, rule.selectorText, rule.mediaText);
index 3fd1783..c0d9038 100644 (file)
@@ -34,13 +34,13 @@ WebInspector.VisualStyleSelectorTreeItem = class VisualStyleSelectorTreeItem ext
 
             if (style.inherited)
                 iconClassName = WebInspector.CSSStyleDeclarationSection.InheritedStyleRuleIconStyleClassName;
-            else if (style.ownerRule.type === WebInspector.CSSRule.Type.Author)
+            else if (style.ownerRule.type === WebInspector.CSSStyleSheet.Type.Author)
                 iconClassName = WebInspector.CSSStyleDeclarationSection.AuthorStyleRuleIconStyleClassName;
-            else if (style.ownerRule.type === WebInspector.CSSRule.Type.User)
+            else if (style.ownerRule.type === WebInspector.CSSStyleSheet.Type.User)
                 iconClassName = WebInspector.CSSStyleDeclarationSection.UserStyleRuleIconStyleClassName;
-            else if (style.ownerRule.type === WebInspector.CSSRule.Type.UserAgent)
+            else if (style.ownerRule.type === WebInspector.CSSStyleSheet.Type.UserAgent)
                 iconClassName = WebInspector.CSSStyleDeclarationSection.UserAgentStyleRuleIconStyleClassName;
-            else if (style.ownerRule.type === WebInspector.CSSRule.Type.Inspector)
+            else if (style.ownerRule.type === WebInspector.CSSStyleSheet.Type.Inspector)
                 iconClassName = WebInspector.CSSStyleDeclarationSection.InspectorStyleRuleIconStyleClassName;
             break;