Title: [208270] trunk/Source/WebInspectorUI
Revision
208270
Author
commit-qu...@webkit.org
Date
2016-11-01 19:38:56 -0700 (Tue, 01 Nov 2016)

Log Message

Web Inspector: Creating a new pseudo-selector in the Styles sidebar doesn't work on first attempt
https://bugs.webkit.org/show_bug.cgi?id=164092

Patch by Devin Rousso <dcrousso+web...@gmail.com> on 2016-11-01
Reviewed by Timothy Hatcher.

* UserInterface/Views/CSSStyleDeclarationSection.css:
(.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.rule-disabled > .header > .icon): Deleted.

* UserInterface/Views/CSSStyleDeclarationSection.js:
(WebInspector.CSSStyleDeclarationSection):
(WebInspector.CSSStyleDeclarationSection.prototype.refresh):
(WebInspector.CSSStyleDeclarationSection.prototype._handleIconElementClicked):
(WebInspector.CSSStyleDeclarationSection.prototype._updateSelectorIcon): Added.
Re-add logic removed by https://webkit.org/b/159734 for handling invalid selectors.  Instead
of just refreshing the section whenever the represented CSSRule changes selectors, we only
need to refresh if the selector no longer applies to the current element.

(WebInspector.CSSStyleDeclarationSection.prototype._handleMouseMove): Added.
Fix another issue discovered while adding the invalid selector warnings, where the title
attribute of each individual selector was no longer visible.  To fix this, whenever the user
moves their mouse over the selector input, the position is compared to each selector to find
the first one that matches, whose title is then applied to the input element.

Modified Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (208269 => 208270)


--- trunk/Source/WebInspectorUI/ChangeLog	2016-11-02 01:04:48 UTC (rev 208269)
+++ trunk/Source/WebInspectorUI/ChangeLog	2016-11-02 02:38:56 UTC (rev 208270)
@@ -1,3 +1,31 @@
+2016-11-01  Devin Rousso  <dcrousso+web...@gmail.com>
+
+        Web Inspector: Creating a new pseudo-selector in the Styles sidebar doesn't work on first attempt
+        https://bugs.webkit.org/show_bug.cgi?id=164092
+
+        Reviewed by Timothy Hatcher.
+
+        * UserInterface/Views/CSSStyleDeclarationSection.css:
+        (.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.rule-disabled > .header > .icon): Deleted.
+
+        * UserInterface/Views/CSSStyleDeclarationSection.js:
+        (WebInspector.CSSStyleDeclarationSection):
+        (WebInspector.CSSStyleDeclarationSection.prototype.refresh):
+        (WebInspector.CSSStyleDeclarationSection.prototype._handleIconElementClicked):
+        (WebInspector.CSSStyleDeclarationSection.prototype._updateSelectorIcon): Added.
+        Re-add logic removed by https://webkit.org/b/159734 for handling invalid selectors.  Instead
+        of just refreshing the section whenever the represented CSSRule changes selectors, we only
+        need to refresh if the selector no longer applies to the current element.
+
+        (WebInspector.CSSStyleDeclarationSection.prototype._handleMouseMove): Added.
+        Fix another issue discovered while adding the invalid selector warnings, where the title
+        attribute of each individual selector was no longer visible.  To fix this, whenever the user
+        moves their mouse over the selector input, the position is compared to each selector to find
+        the first one that matches, whose title is then applied to the input element.
+
 2016-11-01  Joseph Pecoraro  <pecor...@apple.com>
 
         Web Inspector: Improve debugger highlight in some exception cases

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.css (208269 => 208270)


--- trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.css	2016-11-02 01:04:48 UTC (rev 208269)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.css	2016-11-02 02:38:56 UTC (rev 208270)
@@ -90,7 +90,7 @@
     filter: brightness(0.8);
 }
 
-.style-declaration-section.rule-disabled > .header > .icon {
+.style-declaration-section:not(.invalid-selector).rule-disabled > .header > .icon {
     opacity: 0.5;
 }
 
@@ -151,6 +151,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 (208269 => 208270)


--- trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.js	2016-11-02 01:04:48 UTC (rev 208269)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.js	2016-11-02 02:38:56 UTC (rev 208270)
@@ -36,6 +36,7 @@
         this._style = style || null;
         this._selectorElements = [];
         this._ruleDisabled = false;
+        this._hasInvalidSelector = false;
 
         this._element = document.createElement("div");
         this._element.classList.add("style-declaration-section");
@@ -53,6 +54,7 @@
             this._selectorInput.spellcheck = false;
             this._selectorInput.tabIndex = -1;
             this._selectorInput.addEventListener("mouseover", this._handleMouseOver.bind(this));
+            this._selectorInput.addEventListener("mousemove", this._handleMouseMove.bind(this));
             this._selectorInput.addEventListener("mouseout", this._handleMouseOut.bind(this));
             this._selectorInput.addEventListener("keydown", this._handleKeyDown.bind(this));
             this._selectorInput.addEventListener("keypress", this._handleKeyPress.bind(this));
@@ -119,7 +121,7 @@
         if (!style.editable)
             this._element.classList.add(WebInspector.CSSStyleDeclarationSection.LockedStyleClassName);
         else if (style.ownerRule)
-            this._style.ownerRule.addEventListener(WebInspector.CSSRule.Event.SelectorChanged, this.refresh.bind(this));
+            this._style.ownerRule.addEventListener(WebInspector.CSSRule.Event.SelectorChanged, this._updateSelectorIcon.bind(this));
         else
             this._element.classList.add(WebInspector.CSSStyleDeclarationSection.SelectorLockedStyleClassName);
 
@@ -273,6 +275,7 @@
             break;
         }
 
+        this._updateSelectorIcon();
         if (this._selectorInput)
             this._selectorInput.value = this._selectorElement.textContent;
     }
@@ -532,6 +535,12 @@
 
     _handleIconElementClicked()
     {
+        if (this._hasInvalidSelector) {
+            // This will revert the selector text to the original valid value.
+            this.refresh();
+            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);
@@ -557,6 +566,25 @@
         this._highlightNodesWithSelector();
     }
 
+    _handleMouseMove(event)
+    {
+        if (this._hasInvalidSelector)
+            return;
+
+        // Attempts to find a selector element under the mouse so that the title (which contains the
+        // specificity information) can be applied to _selectorInput, which will then display the
+        // title if the user hovers long enough.
+        for (let element of this._selectorElements) {
+            let {top, right, bottom, left} = element.getBoundingClientRect();
+            if (event.clientX >= left && event.clientX <= right && event.clientY >= top && event.clientY <= bottom) {
+                this._selectorInput.title = element.title;
+                return;
+            }
+        }
+
+        this._selectorInput.title = "";
+    }
+
     _handleMouseOut(event)
     {
         this._hideDOMNodeHighlight();
@@ -653,6 +681,23 @@
         this._style.ownerRule.selectorText = newSelectorText;
     }
 
+    _updateSelectorIcon(event)
+    {
+        if (!this._style.ownerRule || !this._style.editable)
+            return;
+
+        this._hasInvalidSelector = event && event.data && !event.data.valid;
+        this._element.classList.toggle("invalid-selector", !!this._hasInvalidSelector);
+        if (this._hasInvalidSelector) {
+            this._iconElement.title = WebInspector.UIString("The selector ā€œ%sā€ is invalid.\nClick to revert to the previous selector.").format(this._selectorElement.textContent.trim());
+            this._selectorInput.title = WebInspector.UIString("Using the previous selector ā€œ%sā€.").format(this._style.ownerRule.selectorText);
+            return;
+        }
+
+        this._iconElement.title = this._ruleDisabled ? WebInspector.UIString("Uncomment All Properties") : WebInspector.UIString("Comment All Properties");
+        this._selectorInput.title = "";
+    }
+
     _editorContentChanged(event)
     {
         this._editorActive = true;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to