<!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>[193030] branches/safari-601-branch/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/193030">193030</a></dd>
<dt>Author</dt> <dd>timothy@apple.com</dd>
<dt>Date</dt> <dd>2015-12-03 10:33:26 -0800 (Thu, 03 Dec 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merge <a href="http://trac.webkit.org/projects/webkit/changeset/187500">r187500</a>. rdar://problem/23221163</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari601branchSourceWebInspectorUIChangeLog">branches/safari-601-branch/Source/WebInspectorUI/ChangeLog</a></li>
<li><a href="#branchessafari601branchSourceWebInspectorUILocalizationsenlprojlocalizedStringsjs">branches/safari-601-branch/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js</a></li>
<li><a href="#branchessafari601branchSourceWebInspectorUIUserInterfaceModelsCSSRulejs">branches/safari-601-branch/Source/WebInspectorUI/UserInterface/Models/CSSRule.js</a></li>
<li><a href="#branchessafari601branchSourceWebInspectorUIUserInterfaceModelsDOMNodeStylesjs">branches/safari-601-branch/Source/WebInspectorUI/UserInterface/Models/DOMNodeStyles.js</a></li>
<li><a href="#branchessafari601branchSourceWebInspectorUIUserInterfaceViewsCSSStyleDeclarationSectioncss">branches/safari-601-branch/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.css</a></li>
<li><a href="#branchessafari601branchSourceWebInspectorUIUserInterfaceViewsCSSStyleDeclarationSectionjs">branches/safari-601-branch/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari601branchSourceWebInspectorUIChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-601-branch/Source/WebInspectorUI/ChangeLog (193029 => 193030)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601-branch/Source/WebInspectorUI/ChangeLog        2015-12-03 18:33:18 UTC (rev 193029)
+++ branches/safari-601-branch/Source/WebInspectorUI/ChangeLog        2015-12-03 18:33:26 UTC (rev 193030)
</span><span class="lines">@@ -1,5 +1,48 @@
</span><span class="cx"> 2015-12-01  Timothy Hatcher  &lt;timothy@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Merge r187500. rdar://problem/23221163
+
+    2015-07-28  Devin Rousso  &lt;drousso@apple.com&gt;
+
+            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) &gt; .header &gt; .icon.toggle-able:hover):
+            (.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 &gt; *):
+            (.style-declaration-section &gt; .header &gt; .icon.toggle-able:hover): Deleted.
+            (.style-declaration-section.rule-disabled &gt; .header &gt; .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-12-01  Timothy Hatcher  &lt;timothy@apple.com&gt;
+
</ins><span class="cx">         Merge r187496. rdar://problem/23221163
</span><span class="cx"> 
</span><span class="cx">     2015-07-28  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
</span></span></pre></div>
<a id="branchessafari601branchSourceWebInspectorUILocalizationsenlprojlocalizedStringsjs"></a>
<div class="modfile"><h4>Modified: branches/safari-601-branch/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js (193029 => 193030)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601-branch/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js        2015-12-03 18:33:18 UTC (rev 193029)
+++ branches/safari-601-branch/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js        2015-12-03 18:33:26 UTC (rev 193030)
</span><span class="lines">@@ -487,6 +487,7 @@
</span><span class="cx"> localizedStrings[&quot;The 'webkit' prefix is needed for this property.\nClick to insert a duplicate with the prefix.&quot;] = &quot;The 'webkit' prefix is needed for this property.\nClick to insert a duplicate with the prefix.&quot;;
</span><span class="cx"> localizedStrings[&quot;The 'webkit' prefix is not necessary.\nClick to insert a duplicate without the prefix.&quot;] = &quot;The 'webkit' prefix is not necessary.\nClick to insert a duplicate without the prefix.&quot;;
</span><span class="cx"> localizedStrings[&quot;The property '%s' is not supported.&quot;] = &quot;The property '%s' is not supported.&quot;;
</span><ins>+localizedStrings[&quot;The selector '%s' is invalid.&quot;] = &quot;The selector '%s' is invalid.&quot;;
</ins><span class="cx"> localizedStrings[&quot;The value '%s' is not supported for this property.\nClick to delete and open autocomplete.&quot;] = &quot;The value '%s' is not supported for this property.\nClick to delete and open autocomplete.&quot;;
</span><span class="cx"> localizedStrings[&quot;The value '%s' needs units.\nClick to add 'px' to the value.&quot;] = &quot;The value '%s' needs units.\nClick to add 'px' to the value.&quot;;
</span><span class="cx"> localizedStrings[&quot;The  %s \ntable is empty.&quot;] = &quot;The  %s \ntable is empty.&quot;;
</span><span class="lines">@@ -515,6 +516,7 @@
</span><span class="cx"> localizedStrings[&quot;Untitled&quot;] = &quot;Untitled&quot;;
</span><span class="cx"> localizedStrings[&quot;User Agent Stylesheet&quot;] = &quot;User Agent Stylesheet&quot;;
</span><span class="cx"> localizedStrings[&quot;User Stylesheet&quot;] = &quot;User Stylesheet&quot;;
</span><ins>+localizedStrings[&quot;Using the previous selector '%s'.&quot;] = &quot;Using the previous selector '%s'.&quot;;
</ins><span class="cx"> localizedStrings[&quot;Value&quot;] = &quot;Value&quot;;
</span><span class="cx"> localizedStrings[&quot;Warning: &quot;] = &quot;Warning: &quot;;
</span><span class="cx"> localizedStrings[&quot;Warnings&quot;] = &quot;Warnings&quot;;
</span></span></pre></div>
<a id="branchessafari601branchSourceWebInspectorUIUserInterfaceModelsCSSRulejs"></a>
<div class="modfile"><h4>Modified: branches/safari-601-branch/Source/WebInspectorUI/UserInterface/Models/CSSRule.js (193029 => 193030)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601-branch/Source/WebInspectorUI/UserInterface/Models/CSSRule.js        2015-12-03 18:33:18 UTC (rev 193029)
+++ branches/safari-601-branch/Source/WebInspectorUI/UserInterface/Models/CSSRule.js        2015-12-03 18:33:26 UTC (rev 193030)
</span><span class="lines">@@ -115,10 +115,12 @@
</span><span class="cx">         if (!this.editable)
</span><span class="cx">             return;
</span><span class="cx"> 
</span><del>-        if (this._selectorText === selectorText)
</del><ins>+        if (this._selectorText === selectorText) {
+            this._selectorResolved(true);
</ins><span class="cx">             return;
</span><ins>+        }
</ins><span class="cx"> 
</span><del>-        this._nodeStyles.changeRuleSelector(this, selectorText);
</del><ins>+        this._nodeStyles.changeRuleSelector(this, selectorText).then(this._selectorResolved.bind(this), this._selectorRejected.bind(this));
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     get selectors()
</span><span class="lines">@@ -229,10 +231,21 @@
</span><span class="cx"> 
</span><span class="cx">         return specificSelector;
</span><span class="cx">     }
</span><ins>+
+    _selectorRejected(error)
+    {
+        this.dispatchEventToListeners(WebInspector.CSSRule.Event.SelectorChanged, {valid: !error});
+    }
+
+    _selectorResolved(rulePayload)
+    {
+        this.dispatchEventToListeners(WebInspector.CSSRule.Event.SelectorChanged, {valid: !!rulePayload});
+    }
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> WebInspector.CSSRule.Event = {
</span><del>-    Changed: &quot;css-rule-changed&quot;
</del><ins>+    Changed: &quot;css-rule-changed&quot;,
+    SelectorChanged: &quot;css-rule-invalid-selector&quot;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> WebInspector.CSSRule.Type = {
</span></span></pre></div>
<a id="branchessafari601branchSourceWebInspectorUIUserInterfaceModelsDOMNodeStylesjs"></a>
<div class="modfile"><h4>Modified: branches/safari-601-branch/Source/WebInspectorUI/UserInterface/Models/DOMNodeStyles.js (193029 => 193030)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601-branch/Source/WebInspectorUI/UserInterface/Models/DOMNodeStyles.js        2015-12-03 18:33:18 UTC (rev 193029)
+++ branches/safari-601-branch/Source/WebInspectorUI/UserInterface/Models/DOMNodeStyles.js        2015-12-03 18:33:26 UTC (rev 193030)
</span><span class="lines">@@ -325,20 +325,29 @@
</span><span class="cx">     changeRuleSelector(rule, selector)
</span><span class="cx">     {
</span><span class="cx">         selector = selector || &quot;&quot;;
</span><ins>+        var result = new WebInspector.WrappedPromise;
</ins><span class="cx"> 
</span><span class="cx">         function ruleSelectorChanged(error, rulePayload)
</span><span class="cx">         {
</span><ins>+            if (error) {
+                result.reject(error);
+                return;
+            }
+
</ins><span class="cx">             DOMAgent.markUndoableState();
</span><span class="cx"> 
</span><span class="cx">             // Do a full refresh incase the rule no longer matches the node or the
</span><span class="cx">             // matched selector indices changed.
</span><span class="cx">             this.refresh();
</span><ins>+
+            result.resolve(rulePayload);
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         this._needsRefresh = true;
</span><span class="cx">         this._ignoreNextContentDidChangeForStyleSheet = rule.ownerStyleSheet;
</span><span class="cx"> 
</span><span class="cx">         CSSAgent.setRuleSelector(rule.id, selector, ruleSelectorChanged.bind(this));
</span><ins>+        return result.promise;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     changeStyleText(style, text)
</span></span></pre></div>
<a id="branchessafari601branchSourceWebInspectorUIUserInterfaceViewsCSSStyleDeclarationSectioncss"></a>
<div class="modfile"><h4>Modified: branches/safari-601-branch/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.css (193029 => 193030)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601-branch/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.css        2015-12-03 18:33:18 UTC (rev 193029)
+++ branches/safari-601-branch/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.css        2015-12-03 18:33:26 UTC (rev 193030)
</span><span class="lines">@@ -78,11 +78,11 @@
</span><span class="cx">     height: 16px;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-.style-declaration-section &gt; .header &gt; .icon.toggle-able:hover {
</del><ins>+.style-declaration-section:not(.invalid-selector) &gt; .header &gt; .icon.toggle-able:hover {
</ins><span class="cx">     -webkit-filter: brightness(0.9);
</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">@@ -156,6 +156,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="branchessafari601branchSourceWebInspectorUIUserInterfaceViewsCSSStyleDeclarationSectionjs"></a>
<div class="modfile"><h4>Modified: branches/safari-601-branch/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.js (193029 => 193030)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601-branch/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.js        2015-12-03 18:33:18 UTC (rev 193029)
+++ branches/safari-601-branch/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.js        2015-12-03 18:33:26 UTC (rev 193030)
</span><span class="lines">@@ -106,6 +106,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><ins>+        this._style.ownerRule.addEventListener(WebInspector.CSSRule.Event.SelectorChanged, this._markSelector.bind(this));
</ins><span class="cx">         this._commitSelectorKeyboardShortcut = new WebInspector.KeyboardShortcut(null, WebInspector.KeyboardShortcut.Key.Enter, this._commitSelector.bind(this), this._selectorElement);
</span><span class="cx">         this._selectorElement.addEventListener(&quot;blur&quot;, this._commitSelector.bind(this));
</span><span class="cx">     } else
</span><span class="lines">@@ -125,6 +126,7 @@
</span><span class="cx"> 
</span><span class="cx"> WebInspector.CSSStyleDeclarationSection.LockedStyleClassName = &quot;locked&quot;;
</span><span class="cx"> WebInspector.CSSStyleDeclarationSection.SelectorLockedStyleClassName = &quot;selector-locked&quot;;
</span><ins>+WebInspector.CSSStyleDeclarationSection.SelectorInvalidClassName = &quot;invalid-selector&quot;;
</ins><span class="cx"> WebInspector.CSSStyleDeclarationSection.LastInGroupStyleClassName = &quot;last-in-group&quot;;
</span><span class="cx"> WebInspector.CSSStyleDeclarationSection.MatchedSelectorElementStyleClassName = &quot;matched&quot;;
</span><span class="cx"> 
</span><span class="lines">@@ -450,6 +452,9 @@
</span><span class="cx"> 
</span><span class="cx">     _toggleRuleOnOff: function()
</span><span class="cx">     {
</span><ins>+        if (this._hasInvalidSelector)
+            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">@@ -520,6 +525,28 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         this._style.ownerRule.selectorText = newSelectorText;
</span><ins>+    },
+
+    _markSelector: function(event)
+    {
+        var valid = event &amp;&amp; event.data &amp;&amp; event.data.valid;
+        this._element.classList.toggle(WebInspector.CSSStyleDeclarationSection.SelectorInvalidClassName, !valid);
+        if (valid) {
+            this._iconElement.title = this._ruleDisabled ? WebInspector.UIString(&quot;Uncomment All Properties&quot;) : WebInspector.UIString(&quot;Comment All Properties&quot;);
+            this._selectorElement.title = null;
+            this.refresh();
+            return;
+        }
+
+        this._iconElement.title = WebInspector.UIString(&quot;The selector '%s' is invalid.&quot;).format(this._selectorElement.textContent.trim());
+        this._selectorElement.title = WebInspector.UIString(&quot;Using the previous selector '%s'.&quot;).format(this._style.ownerRule.selectorText);
+        for (var i = 0; i &lt; this._selectorElement.children.length; ++i)
+            this._selectorElement.children[i].title = null;
+    },
+
+    get _hasInvalidSelector()
+    {
+        return this._element.classList.contains(WebInspector.CSSStyleDeclarationSection.SelectorInvalidClassName);
</ins><span class="cx">     }
</span><span class="cx"> };
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>