Title: [187500] trunk/Source/WebInspectorUI
Revision
187500
Author
[email protected]
Date
2015-07-28 12:23:10 -0700 (Tue, 28 Jul 2015)

Log Message

Web Inspector: Invalid selectors can be applied to the stylesheet
https://bugs.webkit.org/show_bug.cgi?id=147230

Reviewed by Timothy Hatcher.

* Localizations/en.lproj/localizedStrings.js:

* UserInterface/Models/CSSRule.js:
(WebInspector.CSSRule.prototype.set selectorText):
Fires an event with data stating if the newly applied selector was valid or not.
(WebInspector.CSSRule.prototype._selectorRejected):
(WebInspector.CSSRule.prototype._selectorResolved):
(WebInspector.CSSRule):

* UserInterface/Models/DOMNodeStyles.js:
(WebInspector.DOMNodeStyles.prototype.changeRuleSelector.ruleSelectorChanged):
(WebInspector.DOMNodeStyles.prototype.changeRuleSelector):
Now returns a promise that will reject if CSSAgent.setRuleSelector has an
error, such as if the selector is invalid, and resolve otherwise.

* UserInterface/Views/CSSStyleDeclarationSection.css:
(.style-declaration-section:not(.invalid-selector) > .header > .icon.toggle-able:hover):
(.style-declaration-section:not(.invalid-selector).rule-disabled > .header > .icon):
(.style-declaration-section.invalid-selector > .header > .icon):
(.style-declaration-section.invalid-selector > .header > .selector > *):
(.style-declaration-section > .header > .icon.toggle-able:hover): Deleted.
(.style-declaration-section.rule-disabled > .header > .icon): Deleted.

* UserInterface/Views/CSSStyleDeclarationSection.js:
(WebInspector.CSSStyleDeclarationSection):
(WebInspector.CSSStyleDeclarationSection.prototype._toggleRuleOnOff):
Only allow rule toggling if the selector is valid.
(WebInspector.CSSStyleDeclarationSection.prototype._markSelector):
If the new selector is valid, refresh the section. Otherwise, apply a class
to the section element that marks the selector as being invalid.
(WebInspector.CSSStyleDeclarationSection.prototype.get _hasInvalidSelector):

Modified Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (187499 => 187500)


--- trunk/Source/WebInspectorUI/ChangeLog	2015-07-28 19:16:19 UTC (rev 187499)
+++ trunk/Source/WebInspectorUI/ChangeLog	2015-07-28 19:23:10 UTC (rev 187500)
@@ -1,3 +1,42 @@
+2015-07-28  Devin Rousso  <[email protected]>
+
+        Web Inspector: Invalid selectors can be applied to the stylesheet
+        https://bugs.webkit.org/show_bug.cgi?id=147230
+
+        Reviewed by Timothy Hatcher.
+
+        * Localizations/en.lproj/localizedStrings.js:
+
+        * UserInterface/Models/CSSRule.js:
+        (WebInspector.CSSRule.prototype.set selectorText):
+        Fires an event with data stating if the newly applied selector was valid or not.
+        (WebInspector.CSSRule.prototype._selectorRejected):
+        (WebInspector.CSSRule.prototype._selectorResolved):
+        (WebInspector.CSSRule):
+
+        * UserInterface/Models/DOMNodeStyles.js:
+        (WebInspector.DOMNodeStyles.prototype.changeRuleSelector.ruleSelectorChanged):
+        (WebInspector.DOMNodeStyles.prototype.changeRuleSelector):
+        Now returns a promise that will reject if CSSAgent.setRuleSelector has an
+        error, such as if the selector is invalid, and resolve otherwise.
+
+        * UserInterface/Views/CSSStyleDeclarationSection.css:
+        (.style-declaration-section:not(.invalid-selector) > .header > .icon.toggle-able:hover):
+        (.style-declaration-section:not(.invalid-selector).rule-disabled > .header > .icon):
+        (.style-declaration-section.invalid-selector > .header > .icon):
+        (.style-declaration-section.invalid-selector > .header > .selector > *):
+        (.style-declaration-section > .header > .icon.toggle-able:hover): Deleted.
+        (.style-declaration-section.rule-disabled > .header > .icon): Deleted.
+
+        * UserInterface/Views/CSSStyleDeclarationSection.js:
+        (WebInspector.CSSStyleDeclarationSection):
+        (WebInspector.CSSStyleDeclarationSection.prototype._toggleRuleOnOff):
+        Only allow rule toggling if the selector is valid.
+        (WebInspector.CSSStyleDeclarationSection.prototype._markSelector):
+        If the new selector is valid, refresh the section. Otherwise, apply a class
+        to the section element that marks the selector as being invalid.
+        (WebInspector.CSSStyleDeclarationSection.prototype.get _hasInvalidSelector):
+
 2015-07-28  Joseph Pecoraro  <[email protected]>
 
         Web Inspector: Show Pseudo Elements in DOM Tree

Modified: trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js (187499 => 187500)


--- trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js	2015-07-28 19:16:19 UTC (rev 187499)
+++ trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js	2015-07-28 19:23:10 UTC (rev 187500)
@@ -487,6 +487,7 @@
 localizedStrings["The 'webkit' prefix is needed for this property.\nClick to insert a duplicate with the prefix."] = "The 'webkit' prefix is needed for this property.\nClick to insert a duplicate with the prefix.";
 localizedStrings["The 'webkit' prefix is not necessary.\nClick to insert a duplicate without the prefix."] = "The 'webkit' prefix is not necessary.\nClick to insert a duplicate without the prefix.";
 localizedStrings["The property '%s' is not supported."] = "The property '%s' is not supported.";
+localizedStrings["The selector '%s' is invalid."] = "The selector '%s' is invalid.";
 localizedStrings["The value '%s' is not supported for this property.\nClick to delete and open autocomplete."] = "The value '%s' is not supported for this property.\nClick to delete and open autocomplete.";
 localizedStrings["The value '%s' needs units.\nClick to add 'px' to the value."] = "The value '%s' needs units.\nClick to add 'px' to the value.";
 localizedStrings["The  %s \ntable is empty."] = "The  %s \ntable is empty.";
@@ -515,6 +516,7 @@
 localizedStrings["Untitled"] = "Untitled";
 localizedStrings["User Agent Stylesheet"] = "User Agent Stylesheet";
 localizedStrings["User Stylesheet"] = "User Stylesheet";
+localizedStrings["Using the previous selector '%s'."] = "Using the previous selector '%s'.";
 localizedStrings["Value"] = "Value";
 localizedStrings["Warning: "] = "Warning: ";
 localizedStrings["Warnings"] = "Warnings";

Modified: trunk/Source/WebInspectorUI/UserInterface/Models/CSSRule.js (187499 => 187500)


--- trunk/Source/WebInspectorUI/UserInterface/Models/CSSRule.js	2015-07-28 19:16:19 UTC (rev 187499)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/CSSRule.js	2015-07-28 19:23:10 UTC (rev 187500)
@@ -115,10 +115,12 @@
         if (!this.editable)
             return;
 
-        if (this._selectorText === selectorText)
+        if (this._selectorText === selectorText) {
+            this._selectorResolved(true);
             return;
+        }
 
-        this._nodeStyles.changeRuleSelector(this, selectorText);
+        this._nodeStyles.changeRuleSelector(this, selectorText).then(this._selectorResolved.bind(this), this._selectorRejected.bind(this));
     }
 
     get selectors()
@@ -229,10 +231,21 @@
 
         return specificSelector;
     }
+
+    _selectorRejected(error)
+    {
+        this.dispatchEventToListeners(WebInspector.CSSRule.Event.SelectorChanged, {valid: !error});
+    }
+
+    _selectorResolved(rulePayload)
+    {
+        this.dispatchEventToListeners(WebInspector.CSSRule.Event.SelectorChanged, {valid: !!rulePayload});
+    }
 };
 
 WebInspector.CSSRule.Event = {
-    Changed: "css-rule-changed"
+    Changed: "css-rule-changed",
+    SelectorChanged: "css-rule-invalid-selector"
 };
 
 WebInspector.CSSRule.Type = {

Modified: trunk/Source/WebInspectorUI/UserInterface/Models/DOMNodeStyles.js (187499 => 187500)


--- trunk/Source/WebInspectorUI/UserInterface/Models/DOMNodeStyles.js	2015-07-28 19:16:19 UTC (rev 187499)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/DOMNodeStyles.js	2015-07-28 19:23:10 UTC (rev 187500)
@@ -325,20 +325,29 @@
     changeRuleSelector(rule, selector)
     {
         selector = selector || "";
+        var result = new WebInspector.WrappedPromise;
 
         function ruleSelectorChanged(error, rulePayload)
         {
+            if (error) {
+                result.reject(error);
+                return;
+            }
+
             DOMAgent.markUndoableState();
 
             // Do a full refresh incase the rule no longer matches the node or the
             // matched selector indices changed.
             this.refresh();
+
+            result.resolve(rulePayload);
         }
 
         this._needsRefresh = true;
         this._ignoreNextContentDidChangeForStyleSheet = rule.ownerStyleSheet;
 
         CSSAgent.setRuleSelector(rule.id, selector, ruleSelectorChanged.bind(this));
+        return result.promise;
     }
 
     changeStyleText(style, text)

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.css (187499 => 187500)


--- trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.css	2015-07-28 19:16:19 UTC (rev 187499)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.css	2015-07-28 19:23:10 UTC (rev 187500)
@@ -78,11 +78,11 @@
     height: 16px;
 }
 
-.style-declaration-section > .header > .icon.toggle-able:hover {
+.style-declaration-section:not(.invalid-selector) > .header > .icon.toggle-able:hover {
     -webkit-filter: brightness(0.9);
 }
 
-.style-declaration-section.rule-disabled > .header > .icon {
+.style-declaration-section:not(.invalid-selector).rule-disabled > .header > .icon {
     opacity: 0.5;
 }
 
@@ -156,6 +156,19 @@
     color: inherit !important;
 }
 
+.style-declaration-section.invalid-selector > .header > .icon {
+    top: 4px;
+    left: 6px;
+    width: 12px;
+    height: 12px;
+    content: url(../Images/Error.svg);
+}
+
+.style-declaration-section.invalid-selector > .header > .selector,
+.style-declaration-section.invalid-selector > .header > .selector> * {
+    color: red;
+}
+
 @media (-webkit-min-device-pixel-ratio: 2) {
     .style-declaration-section,
     .sidebar > .panel.details.css-style > .content > .pseudo-classes {

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.js (187499 => 187500)


--- trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.js	2015-07-28 19:16:19 UTC (rev 187499)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.js	2015-07-28 19:23:10 UTC (rev 187500)
@@ -106,6 +106,7 @@
     if (!style.editable)
         this._element.classList.add(WebInspector.CSSStyleDeclarationSection.LockedStyleClassName);
     else if (style.ownerRule) {
+        this._style.ownerRule.addEventListener(WebInspector.CSSRule.Event.SelectorChanged, this._markSelector.bind(this));
         this._commitSelectorKeyboardShortcut = new WebInspector.KeyboardShortcut(null, WebInspector.KeyboardShortcut.Key.Enter, this._commitSelector.bind(this), this._selectorElement);
         this._selectorElement.addEventListener("blur", this._commitSelector.bind(this));
     } else
@@ -125,6 +126,7 @@
 
 WebInspector.CSSStyleDeclarationSection.LockedStyleClassName = "locked";
 WebInspector.CSSStyleDeclarationSection.SelectorLockedStyleClassName = "selector-locked";
+WebInspector.CSSStyleDeclarationSection.SelectorInvalidClassName = "invalid-selector";
 WebInspector.CSSStyleDeclarationSection.LastInGroupStyleClassName = "last-in-group";
 WebInspector.CSSStyleDeclarationSection.MatchedSelectorElementStyleClassName = "matched";
 
@@ -450,6 +452,9 @@
 
     _toggleRuleOnOff: function()
     {
+        if (this._hasInvalidSelector)
+            return;
+
         this._ruleDisabled = this._ruleDisabled ? !this._propertiesTextEditor.uncommentAllProperties() : this._propertiesTextEditor.commentAllProperties();
         this._iconElement.title = this._ruleDisabled ? WebInspector.UIString("Uncomment All Properties") : WebInspector.UIString("Comment All Properties");
         this._element.classList.toggle("rule-disabled", this._ruleDisabled);
@@ -520,6 +525,28 @@
         }
 
         this._style.ownerRule.selectorText = newSelectorText;
+    },
+
+    _markSelector: function(event)
+    {
+        var valid = event && event.data && event.data.valid;
+        this._element.classList.toggle(WebInspector.CSSStyleDeclarationSection.SelectorInvalidClassName, !valid);
+        if (valid) {
+            this._iconElement.title = this._ruleDisabled ? WebInspector.UIString("Uncomment All Properties") : WebInspector.UIString("Comment All Properties");
+            this._selectorElement.title = null;
+            this.refresh();
+            return;
+        }
+
+        this._iconElement.title = WebInspector.UIString("The selector '%s' is invalid.").format(this._selectorElement.textContent.trim());
+        this._selectorElement.title = WebInspector.UIString("Using the previous selector '%s'.").format(this._style.ownerRule.selectorText);
+        for (var i = 0; i < this._selectorElement.children.length; ++i)
+            this._selectorElement.children[i].title = null;
+    },
+
+    get _hasInvalidSelector()
+    {
+        return this._element.classList.contains(WebInspector.CSSStyleDeclarationSection.SelectorInvalidClassName);
     }
 };
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to