<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[208270] trunk/Source/WebInspectorUI</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/208270">208270</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2016-11-01 19:38:56 -0700 (Tue, 01 Nov 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>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 &lt;dcrousso+webkit@gmail.com&gt; on 2016-11-01
Reviewed by Timothy Hatcher.

* UserInterface/Views/CSSStyleDeclarationSection.css:
(.style-declaration-section:not(.invalid-selector).rule-disabled &gt; .header &gt; .icon):
(.style-declaration-section.invalid-selector &gt; .header &gt; .icon):
(.style-declaration-section.invalid-selector &gt; .header &gt; .selector,):
(.style-declaration-section.rule-disabled &gt; .header &gt; .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.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebInspectorUIChangeLog">trunk/Source/WebInspectorUI/ChangeLog</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceViewsCSSStyleDeclarationSectioncss">trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.css</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceViewsCSSStyleDeclarationSectionjs">trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebInspectorUIChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/ChangeLog (208269 => 208270)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,31 @@
</span><ins>+2016-11-01  Devin Rousso  &lt;dcrousso+webkit@gmail.com&gt;
+
+        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 &gt; .header &gt; .icon):
+        (.style-declaration-section.invalid-selector &gt; .header &gt; .icon):
+        (.style-declaration-section.invalid-selector &gt; .header &gt; .selector,):
+        (.style-declaration-section.rule-disabled &gt; .header &gt; .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.
+
</ins><span class="cx"> 2016-11-01  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Web Inspector: Improve debugger highlight in some exception cases
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceViewsCSSStyleDeclarationSectioncss"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.css (208269 => 208270)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -90,7 +90,7 @@
</span><span class="cx">     filter: brightness(0.8);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-.style-declaration-section.rule-disabled &gt; .header &gt; .icon {
</del><ins>+.style-declaration-section:not(.invalid-selector).rule-disabled &gt; .header &gt; .icon {
</ins><span class="cx">     opacity: 0.5;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -151,6 +151,19 @@
</span><span class="cx">     color: inherit !important;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+.style-declaration-section.invalid-selector &gt; .header &gt; .icon {
+    top: 4px;
+    left: 6px;
+    width: 12px;
+    height: 12px;
+    content: url(../Images/Error.svg);
+}
+
+.style-declaration-section.invalid-selector &gt; .header &gt; .selector,
+.style-declaration-section.invalid-selector &gt; .header &gt; .selector &gt; * {
+    color: red;
+}
+
</ins><span class="cx"> @media (-webkit-min-device-pixel-ratio: 2) {
</span><span class="cx">     .style-declaration-section,
</span><span class="cx">     .sidebar &gt; .panel.details.css-style &gt; .content &gt; .pseudo-classes {
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceViewsCSSStyleDeclarationSectionjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.js (208269 => 208270)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -36,6 +36,7 @@
</span><span class="cx">         this._style = style || null;
</span><span class="cx">         this._selectorElements = [];
</span><span class="cx">         this._ruleDisabled = false;
</span><ins>+        this._hasInvalidSelector = false;
</ins><span class="cx"> 
</span><span class="cx">         this._element = document.createElement(&quot;div&quot;);
</span><span class="cx">         this._element.classList.add(&quot;style-declaration-section&quot;);
</span><span class="lines">@@ -53,6 +54,7 @@
</span><span class="cx">             this._selectorInput.spellcheck = false;
</span><span class="cx">             this._selectorInput.tabIndex = -1;
</span><span class="cx">             this._selectorInput.addEventListener(&quot;mouseover&quot;, this._handleMouseOver.bind(this));
</span><ins>+            this._selectorInput.addEventListener(&quot;mousemove&quot;, this._handleMouseMove.bind(this));
</ins><span class="cx">             this._selectorInput.addEventListener(&quot;mouseout&quot;, this._handleMouseOut.bind(this));
</span><span class="cx">             this._selectorInput.addEventListener(&quot;keydown&quot;, this._handleKeyDown.bind(this));
</span><span class="cx">             this._selectorInput.addEventListener(&quot;keypress&quot;, this._handleKeyPress.bind(this));
</span><span class="lines">@@ -119,7 +121,7 @@
</span><span class="cx">         if (!style.editable)
</span><span class="cx">             this._element.classList.add(WebInspector.CSSStyleDeclarationSection.LockedStyleClassName);
</span><span class="cx">         else if (style.ownerRule)
</span><del>-            this._style.ownerRule.addEventListener(WebInspector.CSSRule.Event.SelectorChanged, this.refresh.bind(this));
</del><ins>+            this._style.ownerRule.addEventListener(WebInspector.CSSRule.Event.SelectorChanged, this._updateSelectorIcon.bind(this));
</ins><span class="cx">         else
</span><span class="cx">             this._element.classList.add(WebInspector.CSSStyleDeclarationSection.SelectorLockedStyleClassName);
</span><span class="cx"> 
</span><span class="lines">@@ -273,6 +275,7 @@
</span><span class="cx">             break;
</span><span class="cx">         }
</span><span class="cx"> 
</span><ins>+        this._updateSelectorIcon();
</ins><span class="cx">         if (this._selectorInput)
</span><span class="cx">             this._selectorInput.value = this._selectorElement.textContent;
</span><span class="cx">     }
</span><span class="lines">@@ -532,6 +535,12 @@
</span><span class="cx"> 
</span><span class="cx">     _handleIconElementClicked()
</span><span class="cx">     {
</span><ins>+        if (this._hasInvalidSelector) {
+            // This will revert the selector text to the original valid value.
+            this.refresh();
+            return;
+        }
+
</ins><span class="cx">         this._ruleDisabled = this._ruleDisabled ? !this._propertiesTextEditor.uncommentAllProperties() : this._propertiesTextEditor.commentAllProperties();
</span><span class="cx">         this._iconElement.title = this._ruleDisabled ? WebInspector.UIString(&quot;Uncomment All Properties&quot;) : WebInspector.UIString(&quot;Comment All Properties&quot;);
</span><span class="cx">         this._element.classList.toggle(&quot;rule-disabled&quot;, this._ruleDisabled);
</span><span class="lines">@@ -557,6 +566,25 @@
</span><span class="cx">         this._highlightNodesWithSelector();
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    _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 &gt;= left &amp;&amp; event.clientX &lt;= right &amp;&amp; event.clientY &gt;= top &amp;&amp; event.clientY &lt;= bottom) {
+                this._selectorInput.title = element.title;
+                return;
+            }
+        }
+
+        this._selectorInput.title = &quot;&quot;;
+    }
+
</ins><span class="cx">     _handleMouseOut(event)
</span><span class="cx">     {
</span><span class="cx">         this._hideDOMNodeHighlight();
</span><span class="lines">@@ -653,6 +681,23 @@
</span><span class="cx">         this._style.ownerRule.selectorText = newSelectorText;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    _updateSelectorIcon(event)
+    {
+        if (!this._style.ownerRule || !this._style.editable)
+            return;
+
+        this._hasInvalidSelector = event &amp;&amp; event.data &amp;&amp; !event.data.valid;
+        this._element.classList.toggle(&quot;invalid-selector&quot;, !!this._hasInvalidSelector);
+        if (this._hasInvalidSelector) {
+            this._iconElement.title = WebInspector.UIString(&quot;The selector ā€œ%sā€ is invalid.\nClick to revert to the previous selector.&quot;).format(this._selectorElement.textContent.trim());
+            this._selectorInput.title = WebInspector.UIString(&quot;Using the previous selector ā€œ%sā€.&quot;).format(this._style.ownerRule.selectorText);
+            return;
+        }
+
+        this._iconElement.title = this._ruleDisabled ? WebInspector.UIString(&quot;Uncomment All Properties&quot;) : WebInspector.UIString(&quot;Comment All Properties&quot;);
+        this._selectorInput.title = &quot;&quot;;
+    }
+
</ins><span class="cx">     _editorContentChanged(event)
</span><span class="cx">     {
</span><span class="cx">         this._editorActive = true;
</span></span></pre>
</div>
</div>

</body>
</html>