Diff
Modified: trunk/Source/WebInspectorUI/ChangeLog (212272 => 212273)
--- trunk/Source/WebInspectorUI/ChangeLog 2017-02-14 02:28:55 UTC (rev 212272)
+++ trunk/Source/WebInspectorUI/ChangeLog 2017-02-14 02:29:38 UTC (rev 212273)
@@ -1,3 +1,41 @@
+2017-02-13 Devin Rousso <dcrousso+web...@gmail.com>
+
+ Web Inspector: provide a way to show current value of CSS variables in style rules
+ https://bugs.webkit.org/show_bug.cgi?id=168172
+
+ Reviewed by Timothy Hatcher.
+
+ * Localizations/en.lproj/localizedStrings.js:
+ * UserInterface/Images/CSSVariable.svg: Added.
+
+ * UserInterface/Models/TextMarker.js:
+ (WebInspector.TextMarker.Type):
+
+ * UserInterface/Views/CSSStyleDeclarationTextEditor.js:
+ (WebInspector.CSSStyleDeclarationTextEditor._createInlineSwatches.update):
+
+ * UserInterface/Views/CodeMirrorTextMarkers.js:
+ (createCodeMirrorTextMarkers):
+ (createCodeMirrorVariableTextMarkers):
+
+ * UserInterface/Views/InlineSwatch.css:
+ (.inline-swatch.variable):
+ (.inline-swatch:matches(.bezier, .spring, .variable)):
+ (.inline-swatch:matches(.bezier, .spring, .variable):hover):
+ (.inline-swatch:matches(.bezier, .spring, .variable):active):
+ (.inline-swatch-variable-popover):
+ (.inline-swatch-variable-popover .CodeMirror):
+ (.inline-swatch-variable-popover .CodeMirror pre):
+ (.inline-swatch:matches(.bezier, .spring):hover): Deleted.
+ (.inline-swatch:matches(.bezier, .spring):active): Deleted.
+
+ * UserInterface/Views/InlineSwatch.js:
+ (WebInspector.InlineSwatch):
+ (WebInspector.InlineSwatch.prototype._fallbackValue):
+ (WebInspector.InlineSwatch.prototype._swatchElementClicked):
+ (WebInspector.InlineSwatch.prototype._valueEditorValueDidChange):
+ (WebInspector.InlineSwatch.Type):
+
2017-02-13 Matt Baker <mattba...@apple.com>
REGRESSION(r188138): Web Inspector: cannot edit next/previous DOM attribute by using tab/shift-tab
Modified: trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js (212272 => 212273)
--- trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js 2017-02-14 02:28:55 UTC (rev 212272)
+++ trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js 2017-02-14 02:29:38 UTC (rev 212273)
@@ -828,6 +828,7 @@
localizedStrings["Variants"] = "Variants";
localizedStrings["Version"] = "Version";
localizedStrings["Vertical"] = "Vertical";
+localizedStrings["View variable value"] = "View variable value";
localizedStrings["Visibility"] = "Visibility";
localizedStrings["Visible"] = "Visible";
localizedStrings["Waiting to be upgraded"] = "Waiting to be upgraded";
Added: trunk/Source/WebInspectorUI/UserInterface/Images/CSSVariable.svg (0 => 212273)
--- trunk/Source/WebInspectorUI/UserInterface/Images/CSSVariable.svg (rev 0)
+++ trunk/Source/WebInspectorUI/UserInterface/Images/CSSVariable.svg 2017-02-14 02:29:38 UTC (rev 212273)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright © 2017 Devin Rousso <dcrousso+web...@gmail.com>. All rights reserved. -->
+<svg xmlns="http://www.w3.org/2000/svg" id="root" version="1.1" viewBox="0 0 16 16">
+ <rect fill="hsl(212, 92%, 54%)" x="0" y="0" width="16" height="16" rx="3" ry="3"/>
+ <rect fill="white" x="3.5" y="4.5" width="9" height="2.5"/>
+ <rect fill="white" x="3.5" y="9" width="9" height="2.5"/>
+</svg>
Modified: trunk/Source/WebInspectorUI/UserInterface/Models/TextMarker.js (212272 => 212273)
--- trunk/Source/WebInspectorUI/UserInterface/Models/TextMarker.js 2017-02-14 02:28:55 UTC (rev 212272)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/TextMarker.js 2017-02-14 02:29:38 UTC (rev 212273)
@@ -85,4 +85,5 @@
Plain: "text-marker-type-plain",
CubicBezier: "text-marker-type-cubic-bezier",
Spring: "text-marker-type-spring",
+ Variable: "text-marker-type-variable",
};
Modified: trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationTextEditor.js (212272 => 212273)
--- trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationTextEditor.js 2017-02-14 02:28:55 UTC (rev 212272)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationTextEditor.js 2017-02-14 02:29:38 UTC (rev 212273)
@@ -895,6 +895,18 @@
let swatch = new WebInspector.InlineSwatch(WebInspector.InlineSwatch.Type.Spring, spring, this._codeMirror.getOption("readOnly"));
createSwatch.call(this, swatch, marker, spring, springString);
});
+
+ // Look for CSS variables and add swatches in front of them.
+ createCodeMirrorVariableTextMarkers(this._codeMirror, range, (marker, variable, variableString) => {
+ const dontCreateIfMissing = true;
+ let variableProperty = this._style.nodeStyles.computedStyle.propertyForName(variableString, dontCreateIfMissing);
+ if (!variableProperty)
+ return;
+
+ let trimmedValue = variableProperty.value.trim();
+ let swatch = new WebInspector.InlineSwatch(WebInspector.InlineSwatch.Type.Variable, trimmedValue, this._codeMirror.getOption("readOnly"));
+ createSwatch.call(this, swatch, marker, variableProperty, trimmedValue);
+ });
}
if (nonatomic)
Modified: trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorTextMarkers.js (212272 => 212273)
--- trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorTextMarkers.js 2017-02-14 02:28:55 UTC (rev 212272)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorTextMarkers.js 2017-02-14 02:29:38 UTC (rev 212273)
@@ -61,9 +61,9 @@
continue;
}
- var valueString = match[0];
- var value = WebInspector[type].fromString(valueString);
- if (!value) {
+ let valueString = match[1];
+ let value = WebInspector[type] ? WebInspector[type].fromString(valueString) : null;
+ if (WebInspector[type] && !value) {
match = pattern.exec(lineContent);
continue;
}
@@ -201,3 +201,9 @@
const springRegex = /(spring\([^)]+\))/g;
return createCodeMirrorTextMarkers("Spring", springRegex, null, codeMirror, range, callback);
}
+
+function createCodeMirrorVariableTextMarkers(codeMirror, range, callback)
+{
+ const variableRegex = /var\((--[\w-]+)\)/g;
+ return createCodeMirrorTextMarkers("Variable", variableRegex, null, codeMirror, range, callback);
+}
Modified: trunk/Source/WebInspectorUI/UserInterface/Views/InlineSwatch.css (212272 => 212273)
--- trunk/Source/WebInspectorUI/UserInterface/Views/InlineSwatch.css 2017-02-14 02:28:55 UTC (rev 212272)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/InlineSwatch.css 2017-02-14 02:29:38 UTC (rev 212273)
@@ -47,16 +47,20 @@
content: url(../Images/CubicBezier.svg);
}
-.inline-swatch:matches(.bezier, .spring) {
+.inline-swatch.variable {
+ content: url(../Images/CSSVariable.svg);
+}
+
+.inline-swatch:matches(.bezier, .spring, .variable) {
margin-right: 2px;
background: none;
}
-.inline-swatch:matches(.bezier, .spring):hover {
+.inline-swatch:matches(.bezier, .spring, .variable):hover {
filter: brightness(0.9);
}
-.inline-swatch:matches(.bezier, .spring):active {
+.inline-swatch:matches(.bezier, .spring, .variable):active {
filter: brightness(0.8);
}
@@ -92,3 +96,18 @@
display: none;
}
+.inline-swatch-variable-popover {
+ display: flex;
+ align-items: center;
+ min-height: 24px;
+ padding-top: 0.5px;
+}
+
+.inline-swatch-variable-popover .CodeMirror {
+ height: auto;
+ background-color: transparent;
+}
+
+.inline-swatch-variable-popover .CodeMirror pre {
+ padding: 0 3px;
+}
Modified: trunk/Source/WebInspectorUI/UserInterface/Views/InlineSwatch.js (212272 => 212273)
--- trunk/Source/WebInspectorUI/UserInterface/Views/InlineSwatch.js 2017-02-14 02:28:55 UTC (rev 212272)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/InlineSwatch.js 2017-02-14 02:29:38 UTC (rev 212273)
@@ -36,6 +36,12 @@
this._swatchElement.classList.add("inline-swatch", this._type.split("-").lastValue);
switch (this._type) {
+ case WebInspector.InlineSwatch.Type.Color:
+ this._swatchElement.title = WebInspector.UIString("Click to select a color. Shift-click to switch color formats.");
+ break;
+ case WebInspector.InlineSwatch.Type.Gradient:
+ this._swatchElement.title = WebInspector.UIString("Edit custom gradient");
+ break;
case WebInspector.InlineSwatch.Type.Bezier:
this._swatchElement.title = WebInspector.UIString("Edit “cubic-bezier“ function");
break;
@@ -42,12 +48,11 @@
case WebInspector.InlineSwatch.Type.Spring:
this._swatchElement.title = WebInspector.UIString("Edit “spring“ function");
break;
- case WebInspector.InlineSwatch.Type.Gradient:
- this._swatchElement.title = WebInspector.UIString("Edit custom gradient");
+ case WebInspector.InlineSwatch.Type.Variable:
+ this._swatchElement.title = WebInspector.UIString("View variable value");
break;
default:
- console.assert(this._type === WebInspector.InlineSwatch.Type.Color);
- this._swatchElement.title = WebInspector.UIString("Click to select a color. Shift-click to switch color formats.");
+ WebInspector.reportInternalError(`Unknown InlineSwatch type "${type}"`);
break;
}
@@ -108,10 +113,10 @@
switch (this._type) {
case WebInspector.InlineSwatch.Type.Bezier:
return WebInspector.CubicBezier.fromString("linear");
+ case WebInspector.InlineSwatch.Type.Gradient:
+ return WebInspector.Gradient.fromString("linear-gradient(transparent, transparent)");
case WebInspector.InlineSwatch.Type.Spring:
return WebInspector.Spring.fromString("1 100 10 0");
- case WebInspector.InlineSwatch.Type.Gradient:
- return WebInspector.Gradient.fromString("linear-gradient(transparent, transparent)");
case WebInspector.InlineSwatch.Type.Color:
return WebInspector.Color.fromString("white");
default:
@@ -152,22 +157,38 @@
};
this._valueEditor = null;
- if (this._type === WebInspector.InlineSwatch.Type.Bezier) {
+ if (this._type === WebInspector.InlineSwatch.Type.Color) {
+ this._valueEditor = new WebInspector.ColorPicker;
+ this._valueEditor.addEventListener(WebInspector.ColorPicker.Event.ColorChanged, this._valueEditorValueDidChange, this);
+ this._valueEditor.addEventListener(WebInspector.ColorPicker.Event.FormatChanged, (event) => popover.update());
+ } else if (this._type === WebInspector.InlineSwatch.Type.Gradient) {
+ this._valueEditor = new WebInspector.GradientEditor;
+ this._valueEditor.addEventListener(WebInspector.GradientEditor.Event.GradientChanged, this._valueEditorValueDidChange, this);
+ this._valueEditor.addEventListener(WebInspector.GradientEditor.Event.ColorPickerToggled, (event) => popover.update());
+ } else if (this._type === WebInspector.InlineSwatch.Type.Bezier) {
this._valueEditor = new WebInspector.BezierEditor;
this._valueEditor.addEventListener(WebInspector.BezierEditor.Event.BezierChanged, this._valueEditorValueDidChange, this);
} else if (this._type === WebInspector.InlineSwatch.Type.Spring) {
this._valueEditor = new WebInspector.SpringEditor;
this._valueEditor.addEventListener(WebInspector.SpringEditor.Event.SpringChanged, this._valueEditorValueDidChange, this);
- } else if (this._type === WebInspector.InlineSwatch.Type.Gradient) {
- this._valueEditor = new WebInspector.GradientEditor;
- this._valueEditor.addEventListener(WebInspector.GradientEditor.Event.GradientChanged, this._valueEditorValueDidChange, this);
- this._valueEditor.addEventListener(WebInspector.GradientEditor.Event.ColorPickerToggled, (event) => popover.update());
- } else {
- this._valueEditor = new WebInspector.ColorPicker;
- this._valueEditor.addEventListener(WebInspector.ColorPicker.Event.ColorChanged, this._valueEditorValueDidChange, this);
- this._valueEditor.addEventListener(WebInspector.ColorPicker.Event.FormatChanged, (event) => popover.update());
+ } else if (this._type === WebInspector.InlineSwatch.Type.Variable) {
+ this._valueEditor = {};
+
+ this._valueEditor.element = document.createElement("div");
+ this._valueEditor.element.classList.add("inline-swatch-variable-popover");
+
+ this._valueEditor.codeMirror = WebInspector.CodeMirrorEditor.create(this._valueEditor.element, {
+ mode: "css",
+ readOnly: "nocursor",
+ });
+ this._valueEditor.codeMirror.on("update", () => {
+ popover.update();
+ });
}
+ if (!this._valueEditor)
+ return;
+
popover.content = this._valueEditor.element;
popover.present(bounds.pad(2), [WebInspector.RectEdge.MIN_X]);
@@ -177,26 +198,28 @@
this.dispatchEventToListeners(WebInspector.InlineSwatch.Event.Activated);
let value = this._value || this._fallbackValue();
- if (this._type === WebInspector.InlineSwatch.Type.Bezier)
+ if (this._type === WebInspector.InlineSwatch.Type.Color)
+ this._valueEditor.color = value;
+ else if (this._type === WebInspector.InlineSwatch.Type.Gradient)
+ this._valueEditor.gradient = value;
+ else if (this._type === WebInspector.InlineSwatch.Type.Bezier)
this._valueEditor.bezier = value;
else if (this._type === WebInspector.InlineSwatch.Type.Spring)
this._valueEditor.spring = value;
- else if (this._type === WebInspector.InlineSwatch.Type.Gradient)
- this._valueEditor.gradient = value;
- else
- this._valueEditor.color = value;
+ else if (this._type === WebInspector.InlineSwatch.Type.Variable)
+ this._valueEditor.codeMirror.setValue(value);
}
_valueEditorValueDidChange(event)
{
- if (this._type === WebInspector.InlineSwatch.Type.Bezier)
+ if (this._type === WebInspector.InlineSwatch.Type.Color)
+ this._value = event.data.color;
+ else if (this._type === WebInspector.InlineSwatch.Type.Gradient)
+ this._value = event.data.gradient;
+ else if (this._type === WebInspector.InlineSwatch.Type.Bezier)
this._value = event.data.bezier;
else if (this._type === WebInspector.InlineSwatch.Type.Spring)
this._value = event.data.spring;
- else if (this._type === WebInspector.InlineSwatch.Type.Gradient)
- this._value = event.data.gradient;
- else
- this._value = event.data.color;
this._updateSwatch();
}
@@ -306,6 +329,7 @@
Gradient: "inline-swatch-type-gradient",
Bezier: "inline-swatch-type-bezier",
Spring: "inline-swatch-type-spring",
+ Variable: "inline-swatch-type-variable",
};
WebInspector.InlineSwatch.Event = {