Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(902)

Unified Diff: Source/devtools/front_end/elements/AnimationTimeline.js

Issue 1155773002: Devtools Animations: Add cubic bezier easing editor for animations (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/devtools/front_end/elements/AnimationTimeline.js
diff --git a/Source/devtools/front_end/elements/AnimationTimeline.js b/Source/devtools/front_end/elements/AnimationTimeline.js
index 70de76fbc9736c44260053c1331ac0648c4f5401..f067a9414af0dee34470c0d1a597ad1e992d16a5 100644
--- a/Source/devtools/front_end/elements/AnimationTimeline.js
+++ b/Source/devtools/front_end/elements/AnimationTimeline.js
@@ -691,11 +691,19 @@ WebInspector.AnimationUI = function(animation, timeline, parentElement) {
this._nameElement = parentElement.createChild("div", "animation-name");
this._nameElement.textContent = this._animation.name();
+ this._bezierIconElement = WebInspector.BezierPopoverIcon.createIcon(parentElement);
+ this._bezierIconElement.style.backgroundColor = this._color();
+ this._stylesPopoverHelper = new WebInspector.StylesPopoverHelper();
dgozman 2015/05/23 00:53:26 Animations should not depend on StylesPopoverHelpe
samli 2015/05/25 01:55:38 Done. I've had to duplicate some of the code, ptal
+ this._bezierEditor = new WebInspector.BezierEditor();
+ this._bezierIconElement.addEventListener("mousedown", this._toggleBezierEditor.bind(this));
+
this._svg = parentElement.createSVGChild("svg", "animation-ui");
this._svg.setAttribute("height", WebInspector.AnimationUI.Options.AnimationSVGHeight);
this._svg.style.marginLeft = "-" + WebInspector.AnimationUI.Options.AnimationMargin + "px";
this._svg.addEventListener("mousedown", this._mouseDown.bind(this, WebInspector.AnimationUI.MouseEvents.AnimationDrag, null));
this._activeIntervalGroup = this._svg.createSVGChild("g");
+ this._activeIntervalGroup.addEventListener("mouseover", this._toggleBezierIcon.bind(this, true));
+ this._activeIntervalGroup.addEventListener("mouseout", this._toggleBezierIcon.bind(this, false));
/** @type {!Array.<{group: ?Element, animationLine: ?Element, keyframePoints: !Object.<number, !Element>, keyframeRender: !Object.<number, !Element>}>} */
this._cachedElements = [];
@@ -868,7 +876,9 @@ WebInspector.AnimationUI.prototype = {
this._svg.style.transform = "translateX(" + leftMargin.toFixed(2) + "px)";
this._activeIntervalGroup.style.transform = "translateX(" + (this._delay() * this._timeline.pixelMsRatio()).toFixed(2) + "px)";
- this._nameElement.style.transform = "translateX(" + (leftMargin + this._delay() * this._timeline.pixelMsRatio() + WebInspector.AnimationUI.Options.AnimationMargin).toFixed(2) + "px)";
+ var leftPosition = (leftMargin + this._delay() * this._timeline.pixelMsRatio() + WebInspector.AnimationUI.Options.AnimationMargin).toFixed(2);
+ this._nameElement.style.transform = "translateX(" + leftPosition + "px)";
+ this._bezierIconElement.style.marginLeft = leftPosition + "px";
this._nameElement.style.width = (this._duration() * this._timeline.pixelMsRatio().toFixed(2)) + "px";
this._drawDelayLine(this._svg);
@@ -1030,6 +1040,77 @@ WebInspector.AnimationUI.prototype = {
},
/**
+ * @param {boolean} show
+ */
+ _toggleBezierIcon: function(show)
+ {
+ var bezier = WebInspector.Geometry.CubicBezier.parse(this._animation.source().easing());
+ if (show && (this._animation.playState() === "idle" || !bezier))
+ return;
+ this._bezierIconElement.classList.toggle("shown", show);
+ },
+
+ /**
+ * @param {!Event} event
+ */
+ _toggleBezierEditor: function(event)
+ {
+ if (this._stylesPopoverHelper.isShowing()) {
+ this._stylesPopoverHelper.hide();
+ } else {
+ this._originalEasing = this._animation.source().easing();
+ var bezier = WebInspector.Geometry.CubicBezier.parse(this._originalEasing);
+ this._bezierEditor.setBezier(bezier);
+ this._bezierEditor.addEventListener(WebInspector.BezierEditor.Events.BezierChanged, this._bezierChanged, this);
+ this._stylesPopoverHelper.show(this._bezierEditor, this._bezierIconElement, this._onPopoverHidden.bind(this));
+ this._bezierIconElement.classList.add("bezier-editor-open");
+ }
+ event.stopPropagation();
+ event.preventDefault();
+ },
+
+ /**
+ * @param {!WebInspector.Event} event
+ */
+ _bezierChanged: function(event)
+ {
+ this._setEasing(/** @type {string} */ (event.data));
+ },
+
+ /**
+ * @param {boolean} commitEdit
+ */
+ _onPopoverHidden: function(commitEdit)
+ {
+ this._bezierIconElement.classList.remove("bezier-editor-open");
+ this._bezierEditor.removeEventListener(WebInspector.BezierEditor.Events.BezierChanged, this._bezierChanged, this);
+ if (!commitEdit)
+ this._setEasing(this._originalEasing);
+ },
+
+ /**
+ * @param {string} value
+ */
+ _setEasing: function(value)
+ {
+ if (!this._node || this._animation.source().easing() == value)
+ return;
+
+ this._animation.source().setEasing(value);
+ this.redraw();
+
+ var animationType = this._animation.type();
+ if (animationType !== "CSSAnimation") {
+ var target = WebInspector.targetManager.mainTarget();
+ if (target)
+ target.animationAgent().setEasing(this._animation.id(), value);
+ }
+
+ if (animationType !== "WebAnimation")
+ this._setNodeStyle(animationType === "CSSTransition" ? "transition-timing-function" : "animation-timing-function", value);
+ },
+
+ /**
* @param {number} value
*/
_setDelay: function(value)
@@ -1077,7 +1158,7 @@ WebInspector.AnimationUI.prototype = {
if (style)
style = style.replace(new RegExp("\\s*(-webkit-)?" + name + ":[^;]*;?\\s*", "g"), "");
var valueString = name + ": " + value;
- this._node.setAttributeValue("style", style + " " + valueString + "; -webkit-" + valueString + ";");
+ this._node.setAttributeValue("style", style + " " + valueString + ";");
},
/**

Powered by Google App Engine
This is Rietveld 408576698