<!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>[194547] 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/194547">194547</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2016-01-04 12:39:52 -0800 (Mon, 04 Jan 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>Web Inspector: Add context menu items to CSS selectors to auto-generate pseudo selectors
https://bugs.webkit.org/show_bug.cgi?id=152657
Patch by Devin Rousso <dcrousso+webkit@gmail.com> on 2016-01-04
Reviewed by Timothy Hatcher.
Instead of having to copy a selector, create a new one, paste it, and then add
a pseudo class or element, a context menu item has been added to automate this
process for the user for each CSS pseudo-selector.
* Localizations/en.lproj/localizedStrings.js:
* UserInterface/Controllers/CSSStyleManager.js:
Added a static object containing the list of CSS pseudo-element names.
* UserInterface/Models/DOMNodeStyles.js:
(WebInspector.DOMNodeStyles.prototype.addRule.completed):
(WebInspector.DOMNodeStyles.prototype.addRule.styleChanged):
(WebInspector.DOMNodeStyles.prototype.addRule.addedRule):
(WebInspector.DOMNodeStyles.prototype.addRule):
Now accepts a second argument for setting the starting text value of the new rule.
* UserInterface/Views/CSSStyleDeclarationSection.js:
(WebInspector.CSSStyleDeclarationSection.prototype._handleSelectorPaste):
* UserInterface/Views/VisualStyleSelectorTreeItem.js:
(WebInspector.VisualStyleSelectorTreeItem.prototype._handleContextMenuEvent):</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebInspectorUIChangeLog">trunk/Source/WebInspectorUI/ChangeLog</a></li>
<li><a href="#trunkSourceWebInspectorUILocalizationsenlprojlocalizedStringsjs">trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceControllersCSSStyleManagerjs">trunk/Source/WebInspectorUI/UserInterface/Controllers/CSSStyleManager.js</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceModelsDOMNodeStylesjs">trunk/Source/WebInspectorUI/UserInterface/Models/DOMNodeStyles.js</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceViewsCSSStyleDeclarationSectionjs">trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.js</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceViewsVisualStyleSelectorTreeItemjs">trunk/Source/WebInspectorUI/UserInterface/Views/VisualStyleSelectorTreeItem.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebInspectorUIChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/ChangeLog (194546 => 194547)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/ChangeLog        2016-01-04 20:37:10 UTC (rev 194546)
+++ trunk/Source/WebInspectorUI/ChangeLog        2016-01-04 20:39:52 UTC (rev 194547)
</span><span class="lines">@@ -1,3 +1,32 @@
</span><ins>+2016-01-04 Devin Rousso <dcrousso+webkit@gmail.com>
+
+ Web Inspector: Add context menu items to CSS selectors to auto-generate pseudo selectors
+ https://bugs.webkit.org/show_bug.cgi?id=152657
+
+ Reviewed by Timothy Hatcher.
+
+ Instead of having to copy a selector, create a new one, paste it, and then add
+ a pseudo class or element, a context menu item has been added to automate this
+ process for the user for each CSS pseudo-selector.
+
+ * Localizations/en.lproj/localizedStrings.js:
+
+ * UserInterface/Controllers/CSSStyleManager.js:
+ Added a static object containing the list of CSS pseudo-element names.
+
+ * UserInterface/Models/DOMNodeStyles.js:
+ (WebInspector.DOMNodeStyles.prototype.addRule.completed):
+ (WebInspector.DOMNodeStyles.prototype.addRule.styleChanged):
+ (WebInspector.DOMNodeStyles.prototype.addRule.addedRule):
+ (WebInspector.DOMNodeStyles.prototype.addRule):
+ Now accepts a second argument for setting the starting text value of the new rule.
+
+ * UserInterface/Views/CSSStyleDeclarationSection.js:
+ (WebInspector.CSSStyleDeclarationSection.prototype._handleSelectorPaste):
+
+ * UserInterface/Views/VisualStyleSelectorTreeItem.js:
+ (WebInspector.VisualStyleSelectorTreeItem.prototype._handleContextMenuEvent):
+
</ins><span class="cx"> 2016-01-04 Brian Burg <bburg@apple.com>
</span><span class="cx">
</span><span class="cx"> Web Inspector: add a DebugUI context menu item for saving inspector protocol traffic to file
</span></span></pre></div>
<a id="trunkSourceWebInspectorUILocalizationsenlprojlocalizedStringsjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js (194546 => 194547)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js        2016-01-04 20:37:10 UTC (rev 194546)
+++ trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js        2016-01-04 20:39:52 UTC (rev 194547)
</span><span class="lines">@@ -46,6 +46,7 @@
</span><span class="cx"> localizedStrings["Accessibility"] = "Accessibility";
</span><span class="cx"> localizedStrings["Action"] = "Action";
</span><span class="cx"> localizedStrings["Activity Viewer"] = "Activity Viewer";
</span><ins>+localizedStrings["Add %s Rule"] = "Add %s Rule";
</ins><span class="cx"> localizedStrings["Add Action"] = "Add Action";
</span><span class="cx"> localizedStrings["Add Attribute"] = "Add Attribute";
</span><span class="cx"> localizedStrings["Add Breakpoint"] = "Add Breakpoint";
</span><span class="lines">@@ -172,6 +173,7 @@
</span><span class="cx"> localizedStrings["Copy Rule"] = "Copy Rule";
</span><span class="cx"> localizedStrings["Copy as HTML"] = "Copy as HTML";
</span><span class="cx"> localizedStrings["Could not fetch properties. Object may no longer exist."] = "Could not fetch properties. Object may no longer exist.";
</span><ins>+localizedStrings["Create %s Rule"] = "Create %s Rule";
</ins><span class="cx"> localizedStrings["Create a new tab"] = "Create a new tab";
</span><span class="cx"> localizedStrings["Current"] = "Current";
</span><span class="cx"> localizedStrings["Cursor"] = "Cursor";
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceControllersCSSStyleManagerjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/CSSStyleManager.js (194546 => 194547)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/UserInterface/Controllers/CSSStyleManager.js        2016-01-04 20:37:10 UTC (rev 194546)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/CSSStyleManager.js        2016-01-04 20:39:52 UTC (rev 194547)
</span><span class="lines">@@ -540,5 +540,6 @@
</span><span class="cx"> StyleSheetRemoved: "css-style-manager-style-sheet-removed",
</span><span class="cx"> };
</span><span class="cx">
</span><ins>+WebInspector.CSSStyleManager.PseudoElementNames = ["before", "after"];
</ins><span class="cx"> WebInspector.CSSStyleManager.ForceablePseudoClasses = ["active", "focus", "hover", "visited"];
</span><span class="cx"> WebInspector.CSSStyleManager.PreferredInspectorStyleSheetSymbol = Symbol("css-style-manager-preferred-inspector-stylesheet");
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceModelsDOMNodeStylesjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Models/DOMNodeStyles.js (194546 => 194547)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/UserInterface/Models/DOMNodeStyles.js        2016-01-04 20:37:10 UTC (rev 194546)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/DOMNodeStyles.js        2016-01-04 20:39:52 UTC (rev 194547)
</span><span class="lines">@@ -223,16 +223,35 @@
</span><span class="cx"> CSSAgent.getComputedStyleForNode.invoke({nodeId: this._node.id}, fetchedComputedStyle.bind(this));
</span><span class="cx"> }
</span><span class="cx">
</span><del>- addRule(selector = this._node.appropriateSelectorFor(true))
</del><ins>+ addRule(selector, text)
</ins><span class="cx"> {
</span><ins>+ selector = selector || this._node.appropriateSelectorFor(true);
+
+ function completed()
+ {
+ DOMAgent.markUndoableState();
+ this.refresh();
+ }
+
+ function styleChanged(error, stylePayload)
+ {
+ if (error)
+ return;
+
+ completed.call(this);
+ }
+
</ins><span class="cx"> function addedRule(error, rulePayload)
</span><span class="cx"> {
</span><span class="cx"> if (error)
</span><span class="cx"> return;
</span><span class="cx">
</span><del>- DOMAgent.markUndoableState();
</del><ins>+ if (!text || !text.length) {
+ completed.call(this);
+ return;
+ }
</ins><span class="cx">
</span><del>- this.refresh();
</del><ins>+ CSSAgent.setStyleText(rulePayload.style.styleId, text, styleChanged.bind(this));
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> // COMPATIBILITY (iOS 9): Before CSS.createStyleSheet, CSS.addRule could be called with a contextNode.
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceViewsCSSStyleDeclarationSectionjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.js (194546 => 194547)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.js        2016-01-04 20:37:10 UTC (rev 194546)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationSection.js        2016-01-04 20:39:52 UTC (rev 194547)
</span><span class="lines">@@ -436,18 +436,61 @@
</span><span class="cx">
</span><span class="cx"> let contextMenu = WebInspector.ContextMenu.createFromEvent(event);
</span><span class="cx">
</span><del>- if (!this._style.inherited) {
- contextMenu.appendItem(WebInspector.UIString("Duplicate Selector"), () => {
</del><ins>+ contextMenu.appendItem(WebInspector.UIString("Copy Rule"), () => {
+ InspectorFrontendHost.copyText(this._style.generateCSSRuleString());
+ });
+
+ if (this._style.inherited)
+ return;
+
+ contextMenu.appendItem(WebInspector.UIString("Duplicate Selector"), () => {
+ if (this._delegate && typeof this._delegate.cssStyleDeclarationSectionFocusNextNewInspectorRule === "function")
+ this._delegate.cssStyleDeclarationSectionFocusNextNewInspectorRule();
+
+ this._style.nodeStyles.addRule(this._currentSelectorText);
+ });
+
+ // Only used one colon temporarily since single-colon pseudo elements are valid CSS.
+ if (WebInspector.CSSStyleManager.PseudoElementNames.some((className) => this._style.selectorText.includes(":" + className)))
+ return;
+
+ if (WebInspector.CSSStyleManager.ForceablePseudoClasses.every((className) => !this._style.selectorText.includes(":" + className))) {
+ for (let pseudoClass of WebInspector.CSSStyleManager.ForceablePseudoClasses) {
+ if (pseudoClass === "visited" && this._style.node.nodeName() !== "A")
+ continue;
+
+ let pseudoClassSelector = ":" + pseudoClass;
+
+ contextMenu.appendItem(WebInspector.UIString("Add %s Rule").format(pseudoClassSelector), () => {
+ this._style.node.setPseudoClassEnabled(pseudoClass, true);
+
+ if (this._delegate && typeof this._delegate.cssStyleDeclarationSectionFocusNextNewInspectorRule === "function")
+ this._delegate.cssStyleDeclarationSectionFocusNextNewInspectorRule();
+
+ if (this._style.ownerRule) {
+ let pseudoSelectors = this._style.ownerRule.selectors.map((selector) => selector.text + pseudoClassSelector);
+ this._style.nodeStyles.addRule(pseudoSelectors.join(","));
+ } else
+ this._style.nodeStyles.addRule(this._currentSelectorText + pseudoClassSelector);
+ });
+ }
+ }
+
+ for (let pseudoElement of WebInspector.CSSStyleManager.PseudoElementNames) {
+ let pseudoElementSelector = "::" + pseudoElement;
+ const styleText = "content: \"\";";
+
+ contextMenu.appendItem(WebInspector.UIString("Create %s Rule").format(pseudoElementSelector), () => {
</ins><span class="cx"> if (this._delegate && typeof this._delegate.cssStyleDeclarationSectionFocusNextNewInspectorRule === "function")
</span><span class="cx"> this._delegate.cssStyleDeclarationSectionFocusNextNewInspectorRule();
</span><span class="cx">
</span><del>- this._style.nodeStyles.addRule(this._currentSelectorText);
</del><ins>+ if (this._style.ownerRule) {
+ let pseudoSelectors = this._style.ownerRule.selectors.map((selector) => selector.text + pseudoElementSelector);
+ this._style.nodeStyles.addRule(pseudoSelectors.join(","), styleText);
+ } else
+ this._style.nodeStyles.addRule(this._currentSelectorText + pseudoElementSelector, styleText);
</ins><span class="cx"> });
</span><span class="cx"> }
</span><del>-
- contextMenu.appendItem(WebInspector.UIString("Copy Rule"), () => {
- InspectorFrontendHost.copyText(this._style.generateCSSRuleString());
- });
</del><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> _handleIconElementClicked()
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceViewsVisualStyleSelectorTreeItemjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Views/VisualStyleSelectorTreeItem.js (194546 => 194547)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/UserInterface/Views/VisualStyleSelectorTreeItem.js        2016-01-04 20:37:10 UTC (rev 194546)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/VisualStyleSelectorTreeItem.js        2016-01-04 20:39:52 UTC (rev 194547)
</span><span class="lines">@@ -137,15 +137,6 @@
</span><span class="cx"> {
</span><span class="cx"> let contextMenu = WebInspector.ContextMenu.createFromEvent(event);
</span><span class="cx">
</span><del>- if (this.representedObject.ownerRule) {
- contextMenu.appendItem(WebInspector.UIString("Show Source"), () => {
- if (event.metaKey)
- WebInspector.showOriginalUnformattedSourceCodeLocation(this.representedObject.ownerRule.sourceCodeLocation);
- else
- WebInspector.showSourceCodeLocation(this.representedObject.ownerRule.sourceCodeLocation);
- });
- }
-
</del><span class="cx"> contextMenu.appendItem(WebInspector.UIString("Copy Rule"), () => {
</span><span class="cx"> InspectorFrontendHost.copyText(this.representedObject.generateCSSRuleString());
</span><span class="cx"> });
</span><span class="lines">@@ -154,6 +145,52 @@
</span><span class="cx"> this.representedObject.resetText();
</span><span class="cx"> this.dispatchEventToListeners(WebInspector.VisualStyleSelectorTreeItem.Event.StyleTextReset);
</span><span class="cx"> });
</span><ins>+
+ if (!this.representedObject.ownerRule)
+ return;
+
+ contextMenu.appendItem(WebInspector.UIString("Show Source"), () => {
+ if (event.metaKey)
+ WebInspector.showOriginalUnformattedSourceCodeLocation(this.representedObject.ownerRule.sourceCodeLocation);
+ else
+ WebInspector.showSourceCodeLocation(this.representedObject.ownerRule.sourceCodeLocation);
+ });
+
+ // Only used one colon temporarily since single-colon pseudo elements are valid CSS.
+ if (WebInspector.CSSStyleManager.PseudoElementNames.some((className) => this.representedObject.selectorText.includes(":" + className)))
+ return;
+
+ if (WebInspector.CSSStyleManager.ForceablePseudoClasses.every((className) => !this.representedObject.selectorText.includes(":" + className))) {
+ for (let pseudoClass of WebInspector.CSSStyleManager.ForceablePseudoClasses) {
+ if (pseudoClass === "visited" && this.representedObject.node.nodeName() !== "A")
+ continue;
+
+ let pseudoClassSelector = ":" + pseudoClass;
+
+ contextMenu.appendItem(WebInspector.UIString("Add %s Rule").format(pseudoClassSelector), () => {
+ this.representedObject.node.setPseudoClassEnabled(pseudoClass, true);
+
+ if (this.representedObject.ownerRule) {
+ let pseudoSelectors = this.representedObject.ownerRule.selectors.map((selector) => selector.text + pseudoClassSelector);
+ this.representedObject.nodeStyles.addRule(pseudoSelectors.join(","));
+ } else
+ this.representedObject.nodeStyles.addRule(this._currentSelectorText + pseudoClassSelector);
+ });
+ }
+ }
+
+ for (let pseudoElement of WebInspector.CSSStyleManager.PseudoElementNames) {
+ let pseudoElementSelector = "::" + pseudoElement;
+ const styleText = "content: \"\";";
+
+ contextMenu.appendItem(WebInspector.UIString("Create %s Rule").format(pseudoElementSelector), () => {
+ if (this.representedObject.ownerRule) {
+ let pseudoSelectors = this.representedObject.ownerRule.selectors.map((selector) => selector.text + pseudoElementSelector);
+ this.representedObject.nodeStyles.addRule(pseudoSelectors.join(","), styleText);
+ } else
+ this.representedObject.nodeStyles.addRule(this._currentSelectorText + pseudoElementSelector, styleText);
+ });
+ }
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> _handleCheckboxChanged(event)
</span></span></pre>
</div>
</div>
</body>
</html>