Diff
Modified: trunk/Source/WebInspectorUI/ChangeLog (197370 => 197371)
--- trunk/Source/WebInspectorUI/ChangeLog 2016-02-29 22:45:16 UTC (rev 197370)
+++ trunk/Source/WebInspectorUI/ChangeLog 2016-02-29 23:06:58 UTC (rev 197371)
@@ -1,3 +1,62 @@
+2016-02-29 Devin Rousso <dcrousso+web...@gmail.com>
+
+ Web Inspector: Add direct number inputs to Bezier editor
+ https://bugs.webkit.org/show_bug.cgi?id=154809
+ <rdar://problem/24881465>
+
+ Reviewed by Timothy Hatcher.
+
+ * UserInterface/Base/Main.js:
+ (WebInspector._updateWindowKeydownListener):
+ Now only adds the shared event listener when the first keydown listener
+ is added via WebInspector.addWindowKeydownListener
+
+ * UserInterface/Controllers/CodeMirrorBezierEditingController.js:
+ (WebInspector.CodeMirrorBezierEditingController.prototype.popoverDidDismiss):
+
+ * UserInterface/Controllers/CodeMirrorEditingController.js:
+ (WebInspector.CodeMirrorEditingController.prototype.popoverDidDismiss):
+ (WebInspector.CodeMirrorEditingController.prototype.didDismissPopover):
+ Added function that is called when the popover is dismissed so that
+ removing event listeners is possible.
+
+ * UserInterface/Views/BezierEditor.css:
+ (.bezier-editor):
+ (.bezier-editor > .number-input-container):
+ (.bezier-editor > .number-input-container > input):
+
+ * UserInterface/Views/BezierEditor.js:
+ (WebInspector.BezierEditor.createControl):
+ (WebInspector.BezierEditor.createBezierInput):
+ (WebInspector.BezierEditor):
+ Added usage of Element.prototype.createChild for ease of readability.
+ Also added input elements for manually changing the values of each bezier
+ point's x and y values.
+
+ (WebInspector.BezierEditor.prototype.set bezier):
+ (WebInspector.BezierEditor.prototype.removeListeners):
+ (WebInspector.BezierEditor.prototype._handleMousedown):
+ (WebInspector.BezierEditor.prototype._updateBezier):
+ (WebInspector.BezierEditor.prototype._updateBezierPreview):
+ (WebInspector.BezierEditor.prototype._triggerPreviewAnimation):
+ (WebInspector.BezierEditor.prototype._handleNumberInputInput):
+ (WebInspector.BezierEditor.prototype._handleNumberInputKeydown):
+ (WebInspector.BezierEditor.prototype._changeBezierForInput):
+ Refactored code to make it more reusable, as well as adding event listeners
+ to the newly created inputs, including value chaning from the arrow keys.
+
+ * UserInterface/Views/CSSStyleDeclarationTextEditor.js:
+ (WebInspector.CSSStyleDeclarationTextEditor.prototype.didDismissPopover): Deleted.
+ Removed unused code.
+
+ * UserInterface/Views/InlineSwatch.js:
+ (WebInspector.InlineSwatch):
+ (WebInspector.InlineSwatch.prototype.didDismissPopover):
+ Removes any global event listeners added by the current editor if able.
+
+ (WebInspector.InlineSwatch.prototype._swatchElementClicked):
+ Now saves the current editor object as a member variable.
+
2016-02-28 Nikita Vasilyev <nvasil...@apple.com>
Web Inspector: DataGrid's resizers aren't horizontally centered
Modified: trunk/Source/WebInspectorUI/UserInterface/Base/Main.js (197370 => 197371)
--- trunk/Source/WebInspectorUI/UserInterface/Base/Main.js 2016-02-29 22:45:16 UTC (rev 197370)
+++ trunk/Source/WebInspectorUI/UserInterface/Base/Main.js 2016-02-29 23:06:58 UTC (rev 197371)
@@ -2379,9 +2379,9 @@
WebInspector._updateWindowKeydownListener = function()
{
- if (this._windowKeydownListeners.length > 0)
+ if (this._windowKeydownListeners.length === 1)
window.addEventListener("keydown", WebInspector._sharedWindowKeydownListener, true);
- else
+ else if (!this._windowKeydownListeners.length)
window.removeEventListener("keydown", WebInspector._sharedWindowKeydownListener, true);
};
Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorBezierEditingController.js (197370 => 197371)
--- trunk/Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorBezierEditingController.js 2016-02-29 22:45:16 UTC (rev 197370)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorBezierEditingController.js 2016-02-29 23:06:58 UTC (rev 197371)
@@ -54,6 +54,11 @@
this._bezierEditor.bezier = this.value;
}
+ popoverDidDismiss(popover)
+ {
+ this._bezierEditor.removeListeners();
+ }
+
// Private
_bezierEditorBezierChanged(event)
Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorEditingController.js (197370 => 197371)
--- trunk/Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorEditingController.js 2016-02-29 22:45:16 UTC (rev 197370)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorEditingController.js 2016-02-29 23:06:58 UTC (rev 197371)
@@ -145,6 +145,11 @@
// Implemented by subclasses.
}
+ popoverDidDismiss(popover)
+ {
+ // Implemented by subclasses.
+ }
+
// Protected
handleKeydownEvent(event)
@@ -181,6 +186,7 @@
delete this._originalValue;
WebInspector.removeWindowKeydownListener(this);
+ this.popoverDidDismiss();
if (this._delegate && typeof this._delegate.editingControllerDidFinishEditing === "function")
this._delegate.editingControllerDidFinishEditing(this);
Modified: trunk/Source/WebInspectorUI/UserInterface/Views/BezierEditor.css (197370 => 197371)
--- trunk/Source/WebInspectorUI/UserInterface/Views/BezierEditor.css 2016-02-29 22:45:16 UTC (rev 197370)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/BezierEditor.css 2016-02-29 23:06:58 UTC (rev 197371)
@@ -25,7 +25,7 @@
.bezier-editor {
width: 200px;
- height: 225px;
+ height: 260px;
}
.bezier-editor > .bezier-preview {
@@ -51,6 +51,7 @@
border-top: 4px solid black;
}
+.bezier-editor > .bezier-preview.animate > div,
.bezier-editor > .bezier-preview-timing.animate {
animation: bezierPreview 2.5s linear 250ms infinite;
}
@@ -95,3 +96,24 @@
.bezier-editor > .bezier-container .control-handle.selected {
r: 7px;
}
+
+.bezier-editor > .number-input-container {
+ display: flex;
+ width: calc(100% - 10px);
+ margin: 0 5px;
+ padding-top: 7px;
+ border-top: 1px solid lightgrey;
+}
+
+.bezier-editor > .number-input-container > input {
+ width: 100%;
+ margin: 0 5px;
+ padding: 1px 2px 1px 1px;
+ text-align: right;
+ font-size: 13px;
+ background-color: white;
+ border: 1px solid hsl(0, 0%, 60%);
+ border-radius: 4px;
+ box-shadow: inset 0 0 1px 1px hsl(0, 0%, 89%);
+ outline: none;
+}
Modified: trunk/Source/WebInspectorUI/UserInterface/Views/BezierEditor.js (197370 => 197371)
--- trunk/Source/WebInspectorUI/UserInterface/Views/BezierEditor.js 2016-02-29 22:45:16 UTC (rev 197370)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/BezierEditor.js 2016-02-29 23:06:58 UTC (rev 197371)
@@ -38,56 +38,47 @@
this._controlHandleRadius = 7;
this._bezierWidth = editorWidth - (this._controlHandleRadius * 2);
this._bezierHeight = editorHeight - (this._controlHandleRadius * 2) - (this._padding * 2);
- this._bezierPreviewAnimationStyleText = "bezierPreview 2.5s 250ms infinite ";
- var bezierPreviewContainer = document.createElement("div");
- bezierPreviewContainer.id = "bezierPreview";
- bezierPreviewContainer.classList.add("bezier-preview");
- bezierPreviewContainer.title = WebInspector.UIString("Click to restart the animation");
- bezierPreviewContainer.addEventListener("mousedown", this._resetPreviewAnimation.bind(this));
+ this._bezierPreviewContainer = this._element.createChild("div", "bezier-preview");
+ this._bezierPreviewContainer.title = WebInspector.UIString("Click to restart the animation");
+ this._bezierPreviewContainer.addEventListener("mousedown", this._resetPreviewAnimation.bind(this));
- this._bezierPreview = document.createElement("div");
- bezierPreviewContainer.appendChild(this._bezierPreview);
+ this._bezierPreview = this._bezierPreviewContainer.createChild("div");
- this._element.appendChild(bezierPreviewContainer);
+ this._bezierPreviewTiming = this._element.createChild("div", "bezier-preview-timing");
- this._bezierContainer = createSVGElement("svg");
- this._bezierContainer.id = "bezierContainer";
+ this._bezierContainer = this._element.appendChild(createSVGElement("svg"));
this._bezierContainer.setAttribute("width", editorWidth);
this._bezierContainer.setAttribute("height", editorHeight);
this._bezierContainer.classList.add("bezier-container");
- var svgGroup = createSVGElement("g");
+ let svgGroup = this._bezierContainer.appendChild(createSVGElement("g"));
svgGroup.setAttribute("transform", "translate(0, " + this._padding + ")");
- var linearCurve = createSVGElement("line");
+ let linearCurve = svgGroup.appendChild(createSVGElement("line"));
linearCurve.classList.add("linear-curve");
linearCurve.setAttribute("x1", this._controlHandleRadius);
linearCurve.setAttribute("y1", this._bezierHeight + this._controlHandleRadius);
linearCurve.setAttribute("x2", this._bezierWidth + this._controlHandleRadius);
linearCurve.setAttribute("y2", this._controlHandleRadius);
- svgGroup.appendChild(linearCurve);
- this._bezierCurve = createSVGElement("path");
+ this._bezierCurve = svgGroup.appendChild(createSVGElement("path"));
this._bezierCurve.classList.add("bezier-curve");
- svgGroup.appendChild(this._bezierCurve);
function createControl(x1, y1)
{
x1 += this._controlHandleRadius;
y1 += this._controlHandleRadius;
- var line = createSVGElement("line");
+ let line = svgGroup.appendChild(createSVGElement("line"));
line.classList.add("control-line");
line.setAttribute("x1", x1);
line.setAttribute("y1", y1);
line.setAttribute("x2", x1);
line.setAttribute("y2", y1);
- svgGroup.appendChild(line);
- var handle = createSVGElement("circle");
+ let handle = svgGroup.appendChild(createSVGElement("circle"));
handle.classList.add("control-handle");
- svgGroup.appendChild(handle);
return {point: null, line, handle};
}
@@ -95,13 +86,21 @@
this._inControl = createControl.call(this, 0, this._bezierHeight);
this._outControl = createControl.call(this, this._bezierWidth, 0);
- this._bezierContainer.appendChild(svgGroup);
- this._element.appendChild(this._bezierContainer);
+ this._numberInputContainer = this._element.createChild("div", "number-input-container");
- this._bezierPreviewTiming = document.createElement("div");
- this._bezierPreviewTiming.classList.add("bezier-preview-timing");
- this._element.appendChild(this._bezierPreviewTiming);
+ function createBezierInput(id, className)
+ {
+ let key = "_bezier" + id + "Input";
+ this[key] = this._numberInputContainer.createChild("input", className);
+ this[key].addEventListener("input", this._handleNumberInputInput.debounce(250, this));
+ this[key].addEventListener("keydown", this._handleNumberInputKeydown.bind(this));
+ }
+ createBezierInput.call(this, "InX", "in-x");
+ createBezierInput.call(this, "InY", "in-y");
+ createBezierInput.call(this, "OutX", "out-x");
+ createBezierInput.call(this, "OutY", "out-y");
+
this._selectedControl = null;
this._mouseDownPosition = null;
this._bezierContainer.addEventListener("mousedown", this);
@@ -127,11 +126,7 @@
return;
this._bezier = bezier;
- this._inControl.point = new WebInspector.Point(this._bezier.inPoint.x * this._bezierWidth, (1 - this._bezier.inPoint.y) * this._bezierHeight);
- this._outControl.point = new WebInspector.Point(this._bezier.outPoint.x * this._bezierWidth, (1 - this._bezier.outPoint.y) * this._bezierHeight);
-
- this._updateBezier();
- this._triggerPreviewAnimation();
+ this._updateBezierPreview();
}
get bezier()
@@ -139,6 +134,11 @@
return this._bezier;
}
+ removeListeners()
+ {
+ WebInspector.removeWindowKeydownListener(this);
+ }
+
// Protected
handleEvent(event)
@@ -161,7 +161,6 @@
if (!this._selectedControl || !this._element.parentNode)
return false;
-
let horizontal = 0;
let vertical = 0;
switch (event.keyCode) {
@@ -207,7 +206,7 @@
window.addEventListener("mousemove", this, true);
window.addEventListener("mouseup", this, true);
- this._bezierPreview.style.animation = null;
+ this._bezierPreviewContainer.classList.remove("animate");
this._bezierPreviewTiming.classList.remove("animate");
this._updateControlPointsForMouseEvent(event, true);
@@ -285,6 +284,11 @@
this._bezierCurve.setAttribute("d", path);
this._updateControl(this._inControl);
this._updateControl(this._outControl);
+
+ this._bezierInXInput.value = this._bezier.inPoint.x;
+ this._bezierInYInput.value = this._bezier.inPoint.y;
+ this._bezierOutXInput.value = this._bezier.outPoint.x;
+ this._bezierOutYInput.value = this._bezier.outPoint.y;
}
_updateControl(control)
@@ -296,9 +300,19 @@
control.line.setAttribute("y2", control.point.y + this._controlHandleRadius);
}
+ _updateBezierPreview()
+ {
+ this._inControl.point = new WebInspector.Point(this._bezier.inPoint.x * this._bezierWidth, (1 - this._bezier.inPoint.y) * this._bezierHeight);
+ this._outControl.point = new WebInspector.Point(this._bezier.outPoint.x * this._bezierWidth, (1 - this._bezier.outPoint.y) * this._bezierHeight);
+
+ this._updateBezier();
+ this._triggerPreviewAnimation();
+ }
+
_triggerPreviewAnimation()
{
- this._bezierPreview.style.animation = this._bezierPreviewAnimationStyleText + this._bezier.toString();
+ this._bezierPreview.style.animationTimingFunction = this._bezier.toString();
+ this._bezierPreviewContainer.classList.add("animate");
this._bezierPreviewTiming.classList.add("animate");
}
@@ -311,6 +325,55 @@
this._element.removeChild(this._bezierPreviewTiming);
this._element.appendChild(this._bezierPreviewTiming);
}
+
+ _handleNumberInputInput(event)
+ {
+ this._changeBezierForInput(event.target, event.target.value);
+ }
+
+ _handleNumberInputKeydown(event)
+ {
+ let shift = 0;
+ if (event.keyIdentifier === "Up")
+ shift = 0.01;
+ else if (event.keyIdentifier === "Down")
+ shift = -0.01;
+
+ if (!shift)
+ return;
+
+ if (event.shiftKey)
+ shift *= 10;
+
+ event.preventDefault();
+ this._changeBezierForInput(event.target, parseFloat(event.target.value) + shift);
+ }
+
+ _changeBezierForInput(target, value)
+ {
+ value = Math.round(value * 100) / 100;
+
+ switch (target) {
+ case this._bezierInXInput:
+ this._bezier.inPoint.x = Number.constrain(value, 0, 1);
+ break;
+ case this._bezierInYInput:
+ this._bezier.inPoint.y = value;
+ break;
+ case this._bezierOutXInput:
+ this._bezier.outPoint.x = Number.constrain(value, 0, 1);
+ break;
+ case this._bezierOutYInput:
+ this._bezier.outPoint.y = value;
+ break;
+ default:
+ return;
+ }
+
+ this._updateBezierPreview();
+
+ this.dispatchEventToListeners(WebInspector.BezierEditor.Event.BezierChanged, {bezier: this._bezier});
+ }
};
WebInspector.BezierEditor.Event = {
Modified: trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationTextEditor.js (197370 => 197371)
--- trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationTextEditor.js 2016-02-29 22:45:16 UTC (rev 197370)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationTextEditor.js 2016-02-29 23:06:58 UTC (rev 197371)
@@ -386,12 +386,6 @@
// Protected
- didDismissPopover(popover)
- {
- if (popover === this._cubicBezierEditorPopover)
- this._cubicBezierEditorPopover = null;
- }
-
completionControllerCompletionsHidden(completionController)
{
var styleText = this._style.text;
Modified: trunk/Source/WebInspectorUI/UserInterface/Views/InlineSwatch.js (197370 => 197371)
--- trunk/Source/WebInspectorUI/UserInterface/Views/InlineSwatch.js 2016-02-29 22:45:16 UTC (rev 197370)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/InlineSwatch.js 2016-02-29 23:06:58 UTC (rev 197371)
@@ -57,6 +57,7 @@
this._swatchInnerElement = this._swatchElement.createChild("span");
this._value = value || this._fallbackValue();
+ this._valueEditor = null;
this._updateSwatch();
}
@@ -79,6 +80,17 @@
this._updateSwatch(true);
}
+ // Protected
+
+ didDismissPopover(popover)
+ {
+ if (!this._valueEditor)
+ return;
+
+ if (typeof this._valueEditor.removeListeners === "function")
+ this._valueEditor.removeListeners();
+ }
+
// Private
_fallbackValue()
@@ -122,29 +134,29 @@
let bounds = WebInspector.Rect.rectFromClientRect(this._swatchElement.getBoundingClientRect());
let popover = new WebInspector.Popover(this);
- let valueEditor = null;
+ this._valueEditor = null;
if (this._type === WebInspector.InlineSwatch.Type.Bezier) {
- valueEditor = new WebInspector.BezierEditor;
- valueEditor.addEventListener(WebInspector.BezierEditor.Event.BezierChanged, this._valueEditorValueDidChange, this);
+ this._valueEditor = new WebInspector.BezierEditor;
+ this._valueEditor.addEventListener(WebInspector.BezierEditor.Event.BezierChanged, this._valueEditorValueDidChange, this);
} else if (this._type === WebInspector.InlineSwatch.Type.Gradient) {
- valueEditor = new WebInspector.GradientEditor;
- valueEditor.addEventListener(WebInspector.GradientEditor.Event.GradientChanged, this._valueEditorValueDidChange, this);
- valueEditor.addEventListener(WebInspector.GradientEditor.Event.ColorPickerToggled, (event) => popover.update());
+ 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 {
- valueEditor = new WebInspector.ColorPicker;
- valueEditor.addEventListener(WebInspector.ColorPicker.Event.ColorChanged, this._valueEditorValueDidChange, this);
+ this._valueEditor = new WebInspector.ColorPicker;
+ this._valueEditor.addEventListener(WebInspector.ColorPicker.Event.ColorChanged, this._valueEditorValueDidChange, this);
}
- popover.content = valueEditor.element;
+ popover.content = this._valueEditor.element;
popover.present(bounds.pad(2), [WebInspector.RectEdge.MIN_X]);
let value = this._value || this._fallbackValue();
if (this._type === WebInspector.InlineSwatch.Type.Bezier)
- valueEditor.bezier = value;
+ this._valueEditor.bezier = value;
else if (this._type === WebInspector.InlineSwatch.Type.Gradient)
- valueEditor.gradient = value;
+ this._valueEditor.gradient = value;
else
- valueEditor.color = value;
+ this._valueEditor.color = value;
}
_valueEditorValueDidChange(event)