2015-05-04 11:55:51 +00:00
|
|
|
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
|
|
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
// Set of reusable UI components for the animation-inspector UI.
|
|
|
|
// All components in this module share a common API:
|
|
|
|
// 1. construct the component:
|
|
|
|
// let c = new ComponentName();
|
|
|
|
// 2. initialize the markup of the component in a given parent node:
|
|
|
|
// c.init(containerElement);
|
|
|
|
// 3. render the component, passing in some sort of state:
|
|
|
|
// This may be called over and over again when the state changes, to update
|
|
|
|
// the component output.
|
|
|
|
// c.render(state);
|
|
|
|
// 4. destroy the component:
|
|
|
|
// c.destroy();
|
|
|
|
|
2015-06-11 13:45:57 +00:00
|
|
|
const {Cu} = require("chrome");
|
2015-10-13 23:18:43 +00:00
|
|
|
Cu.import("resource://devtools/client/shared/widgets/ViewHelpers.jsm");
|
2015-06-15 10:03:54 +00:00
|
|
|
const {Task} = Cu.import("resource://gre/modules/Task.jsm", {});
|
2015-06-11 13:45:57 +00:00
|
|
|
const {
|
|
|
|
createNode,
|
|
|
|
drawGraphElementBackground,
|
2015-10-09 08:44:53 +00:00
|
|
|
findOptimalTimeInterval,
|
|
|
|
TargetNodeHighlighter
|
2015-09-21 17:04:18 +00:00
|
|
|
} = require("devtools/client/animationinspector/utils");
|
2015-05-04 11:55:51 +00:00
|
|
|
|
2015-11-04 21:35:53 +00:00
|
|
|
const STRINGS_URI = "chrome://devtools/locale/animationinspector.properties";
|
2015-05-04 11:55:51 +00:00
|
|
|
const L10N = new ViewHelpers.L10N(STRINGS_URI);
|
2015-06-11 13:45:57 +00:00
|
|
|
const MILLIS_TIME_FORMAT_MAX_DURATION = 4000;
|
2015-08-27 14:48:37 +00:00
|
|
|
// The minimum spacing between 2 time graduation headers in the timeline (px).
|
2015-06-11 13:45:57 +00:00
|
|
|
const TIME_GRADUATION_MIN_SPACING = 40;
|
2015-11-02 11:54:07 +00:00
|
|
|
// List of playback rate presets displayed in the timeline toolbar.
|
|
|
|
const PLAYBACK_RATES = [.1, .25, .5, 1, 2, 5, 10];
|
2015-12-02 12:52:15 +00:00
|
|
|
// When the container window is resized, the timeline background gets refreshed,
|
|
|
|
// but only after a timer, and the timer is reset if the window is continuously
|
|
|
|
// resized.
|
|
|
|
const TIMELINE_BACKGROUND_RESIZE_DEBOUNCE_TIMER = 50;
|
2015-05-04 11:55:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* UI component responsible for displaying a preview of the target dom node of
|
|
|
|
* a given animation.
|
|
|
|
* @param {InspectorPanel} inspector Requires a reference to the inspector-panel
|
|
|
|
* to highlight and select the node, as well as refresh it when there are
|
|
|
|
* mutations.
|
2015-06-11 13:45:57 +00:00
|
|
|
* @param {Object} options Supported properties are:
|
|
|
|
* - compact {Boolean} Defaults to false. If true, nodes will be previewed like
|
|
|
|
* tag#id.class instead of <tag id="id" class="class">
|
2015-05-04 11:55:51 +00:00
|
|
|
*/
|
2015-06-11 13:45:57 +00:00
|
|
|
function AnimationTargetNode(inspector, options={}) {
|
2015-05-04 11:55:51 +00:00
|
|
|
this.inspector = inspector;
|
2015-06-11 13:45:57 +00:00
|
|
|
this.options = options;
|
2015-05-04 11:55:51 +00:00
|
|
|
|
|
|
|
this.onPreviewMouseOver = this.onPreviewMouseOver.bind(this);
|
|
|
|
this.onPreviewMouseOut = this.onPreviewMouseOut.bind(this);
|
|
|
|
this.onSelectNodeClick = this.onSelectNodeClick.bind(this);
|
|
|
|
this.onMarkupMutations = this.onMarkupMutations.bind(this);
|
2015-10-09 08:44:53 +00:00
|
|
|
this.onHighlightNodeClick = this.onHighlightNodeClick.bind(this);
|
|
|
|
this.onTargetHighlighterLocked = this.onTargetHighlighterLocked.bind(this);
|
2015-05-04 11:55:51 +00:00
|
|
|
|
|
|
|
EventEmitter.decorate(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.AnimationTargetNode = AnimationTargetNode;
|
|
|
|
|
|
|
|
AnimationTargetNode.prototype = {
|
|
|
|
init: function(containerEl) {
|
|
|
|
let document = containerEl.ownerDocument;
|
|
|
|
|
|
|
|
// Init the markup for displaying the target node.
|
|
|
|
this.el = createNode({
|
|
|
|
parent: containerEl,
|
|
|
|
attributes: {
|
|
|
|
"class": "animation-target"
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Icon to select the node in the inspector.
|
2015-10-09 08:44:53 +00:00
|
|
|
this.highlightNodeEl = createNode({
|
2015-05-04 11:55:51 +00:00
|
|
|
parent: this.el,
|
|
|
|
nodeType: "span",
|
|
|
|
attributes: {
|
2015-10-09 08:44:53 +00:00
|
|
|
"class": "node-highlighter",
|
|
|
|
"title": L10N.getStr("node.highlightNodeLabel")
|
2015-05-04 11:55:51 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Wrapper used for mouseover/out event handling.
|
|
|
|
this.previewEl = createNode({
|
|
|
|
parent: this.el,
|
2015-10-09 08:44:53 +00:00
|
|
|
nodeType: "span",
|
|
|
|
attributes: {
|
|
|
|
"title": L10N.getStr("node.selectNodeLabel")
|
|
|
|
}
|
2015-05-04 11:55:51 +00:00
|
|
|
});
|
|
|
|
|
2015-06-11 13:45:57 +00:00
|
|
|
if (!this.options.compact) {
|
|
|
|
this.previewEl.appendChild(document.createTextNode("<"));
|
|
|
|
}
|
2015-05-04 11:55:51 +00:00
|
|
|
|
|
|
|
// Tag name.
|
|
|
|
this.tagNameEl = createNode({
|
|
|
|
parent: this.previewEl,
|
|
|
|
nodeType: "span",
|
|
|
|
attributes: {
|
|
|
|
"class": "tag-name theme-fg-color3"
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Id attribute container.
|
|
|
|
this.idEl = createNode({
|
|
|
|
parent: this.previewEl,
|
|
|
|
nodeType: "span"
|
|
|
|
});
|
|
|
|
|
2015-06-11 13:45:57 +00:00
|
|
|
if (!this.options.compact) {
|
|
|
|
createNode({
|
|
|
|
parent: this.idEl,
|
|
|
|
nodeType: "span",
|
|
|
|
attributes: {
|
|
|
|
"class": "attribute-name theme-fg-color2"
|
|
|
|
},
|
|
|
|
textContent: "id"
|
|
|
|
});
|
|
|
|
this.idEl.appendChild(document.createTextNode("=\""));
|
|
|
|
} else {
|
|
|
|
createNode({
|
|
|
|
parent: this.idEl,
|
|
|
|
nodeType: "span",
|
|
|
|
attributes: {
|
|
|
|
"class": "theme-fg-color2"
|
|
|
|
},
|
|
|
|
textContent: "#"
|
|
|
|
});
|
|
|
|
}
|
2015-05-04 11:55:51 +00:00
|
|
|
|
|
|
|
createNode({
|
|
|
|
parent: this.idEl,
|
|
|
|
nodeType: "span",
|
|
|
|
attributes: {
|
|
|
|
"class": "attribute-value theme-fg-color6"
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-06-11 13:45:57 +00:00
|
|
|
if (!this.options.compact) {
|
|
|
|
this.idEl.appendChild(document.createTextNode("\""));
|
|
|
|
}
|
2015-05-04 11:55:51 +00:00
|
|
|
|
|
|
|
// Class attribute container.
|
|
|
|
this.classEl = createNode({
|
|
|
|
parent: this.previewEl,
|
|
|
|
nodeType: "span"
|
|
|
|
});
|
|
|
|
|
2015-06-11 13:45:57 +00:00
|
|
|
if (!this.options.compact) {
|
|
|
|
createNode({
|
|
|
|
parent: this.classEl,
|
|
|
|
nodeType: "span",
|
|
|
|
attributes: {
|
|
|
|
"class": "attribute-name theme-fg-color2"
|
|
|
|
},
|
|
|
|
textContent: "class"
|
|
|
|
});
|
|
|
|
this.classEl.appendChild(document.createTextNode("=\""));
|
|
|
|
} else {
|
|
|
|
createNode({
|
|
|
|
parent: this.classEl,
|
|
|
|
nodeType: "span",
|
|
|
|
attributes: {
|
|
|
|
"class": "theme-fg-color6"
|
|
|
|
},
|
|
|
|
textContent: "."
|
|
|
|
});
|
|
|
|
}
|
2015-05-04 11:55:51 +00:00
|
|
|
|
|
|
|
createNode({
|
|
|
|
parent: this.classEl,
|
|
|
|
nodeType: "span",
|
|
|
|
attributes: {
|
|
|
|
"class": "attribute-value theme-fg-color6"
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-06-11 13:45:57 +00:00
|
|
|
if (!this.options.compact) {
|
|
|
|
this.classEl.appendChild(document.createTextNode("\""));
|
|
|
|
this.previewEl.appendChild(document.createTextNode(">"));
|
|
|
|
}
|
2015-05-04 11:55:51 +00:00
|
|
|
|
2015-11-02 11:54:07 +00:00
|
|
|
this.startListeners();
|
|
|
|
},
|
|
|
|
|
|
|
|
startListeners: function() {
|
2015-05-04 11:55:51 +00:00
|
|
|
// Init events for highlighting and selecting the node.
|
|
|
|
this.previewEl.addEventListener("mouseover", this.onPreviewMouseOver);
|
|
|
|
this.previewEl.addEventListener("mouseout", this.onPreviewMouseOut);
|
2015-10-09 08:44:53 +00:00
|
|
|
this.previewEl.addEventListener("click", this.onSelectNodeClick);
|
|
|
|
this.highlightNodeEl.addEventListener("click", this.onHighlightNodeClick);
|
2015-05-04 11:55:51 +00:00
|
|
|
|
|
|
|
// Start to listen for markupmutation events.
|
|
|
|
this.inspector.on("markupmutation", this.onMarkupMutations);
|
2015-10-09 08:44:53 +00:00
|
|
|
|
|
|
|
// Listen to the target node highlighter.
|
|
|
|
TargetNodeHighlighter.on("highlighted", this.onTargetHighlighterLocked);
|
2015-05-04 11:55:51 +00:00
|
|
|
},
|
|
|
|
|
2015-11-02 11:54:07 +00:00
|
|
|
stopListeners: function() {
|
2015-10-09 08:44:53 +00:00
|
|
|
TargetNodeHighlighter.off("highlighted", this.onTargetHighlighterLocked);
|
2015-05-04 11:55:51 +00:00
|
|
|
this.inspector.off("markupmutation", this.onMarkupMutations);
|
|
|
|
this.previewEl.removeEventListener("mouseover", this.onPreviewMouseOver);
|
|
|
|
this.previewEl.removeEventListener("mouseout", this.onPreviewMouseOut);
|
2015-10-09 08:44:53 +00:00
|
|
|
this.previewEl.removeEventListener("click", this.onSelectNodeClick);
|
|
|
|
this.highlightNodeEl.removeEventListener("click", this.onHighlightNodeClick);
|
2015-11-02 11:54:07 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function() {
|
|
|
|
TargetNodeHighlighter.unhighlight().catch(e => console.error(e));
|
|
|
|
|
|
|
|
this.stopListeners();
|
2015-10-09 08:44:53 +00:00
|
|
|
|
2015-05-04 11:55:51 +00:00
|
|
|
this.el.remove();
|
|
|
|
this.el = this.tagNameEl = this.idEl = this.classEl = null;
|
2015-10-09 08:44:53 +00:00
|
|
|
this.highlightNodeEl = this.previewEl = null;
|
2015-05-04 11:55:51 +00:00
|
|
|
this.nodeFront = this.inspector = this.playerFront = null;
|
|
|
|
},
|
|
|
|
|
2015-10-09 08:44:53 +00:00
|
|
|
get highlighterUtils() {
|
2015-11-02 11:54:07 +00:00
|
|
|
if (this.inspector && this.inspector.toolbox) {
|
|
|
|
return this.inspector.toolbox.highlighterUtils;
|
|
|
|
}
|
|
|
|
return null;
|
2015-10-09 08:44:53 +00:00
|
|
|
},
|
|
|
|
|
2015-05-04 11:55:51 +00:00
|
|
|
onPreviewMouseOver: function() {
|
2015-11-02 11:54:07 +00:00
|
|
|
if (!this.nodeFront || !this.highlighterUtils) {
|
2015-05-04 11:55:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-11-02 11:54:07 +00:00
|
|
|
this.highlighterUtils.highlightNodeFront(this.nodeFront)
|
|
|
|
.catch(e => console.error(e));
|
2015-05-04 11:55:51 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onPreviewMouseOut: function() {
|
2015-11-02 11:54:07 +00:00
|
|
|
if (!this.nodeFront || !this.highlighterUtils) {
|
2015-10-09 08:44:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-11-02 11:54:07 +00:00
|
|
|
this.highlighterUtils.unhighlight()
|
|
|
|
.catch(e => console.error(e));
|
2015-05-04 11:55:51 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onSelectNodeClick: function() {
|
|
|
|
if (!this.nodeFront) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.inspector.selection.setNodeFront(this.nodeFront, "animationinspector");
|
|
|
|
},
|
|
|
|
|
2015-12-09 14:49:23 +00:00
|
|
|
onHighlightNodeClick: function(e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
|
2015-10-09 08:44:53 +00:00
|
|
|
let classList = this.highlightNodeEl.classList;
|
|
|
|
|
|
|
|
let isHighlighted = classList.contains("selected");
|
|
|
|
if (isHighlighted) {
|
|
|
|
classList.remove("selected");
|
|
|
|
TargetNodeHighlighter.unhighlight().then(() => {
|
|
|
|
this.emit("target-highlighter-unlocked");
|
|
|
|
}, e => console.error(e));
|
|
|
|
} else {
|
|
|
|
classList.add("selected");
|
|
|
|
TargetNodeHighlighter.highlight(this).then(() => {
|
|
|
|
this.emit("target-highlighter-locked");
|
|
|
|
}, e => console.error(e));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onTargetHighlighterLocked: function(e, animationTargetNode) {
|
|
|
|
if (animationTargetNode !== this) {
|
|
|
|
this.highlightNodeEl.classList.remove("selected");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-05-04 11:55:51 +00:00
|
|
|
onMarkupMutations: function(e, mutations) {
|
|
|
|
if (!this.nodeFront || !this.playerFront) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let {target} of mutations) {
|
|
|
|
if (target === this.nodeFront) {
|
|
|
|
// Re-render with the same nodeFront to update the output.
|
|
|
|
this.render(this.playerFront);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-06-11 13:45:57 +00:00
|
|
|
render: Task.async(function*(playerFront) {
|
2015-05-04 11:55:51 +00:00
|
|
|
this.playerFront = playerFront;
|
2015-06-11 13:45:57 +00:00
|
|
|
this.nodeFront = undefined;
|
|
|
|
|
|
|
|
try {
|
|
|
|
this.nodeFront = yield this.inspector.walker.getNodeFromActor(
|
|
|
|
playerFront.actorID, ["node"]);
|
|
|
|
} catch (e) {
|
|
|
|
if (!this.el) {
|
2015-10-09 08:44:53 +00:00
|
|
|
// The panel was destroyed in the meantime. Just log a warning.
|
2015-06-11 13:45:57 +00:00
|
|
|
console.warn("Cound't retrieve the animation target node, widget " +
|
|
|
|
"destroyed");
|
2015-10-09 08:44:53 +00:00
|
|
|
} else {
|
|
|
|
// This was an unexpected error, log it.
|
|
|
|
console.error(e);
|
2015-05-04 11:55:51 +00:00
|
|
|
}
|
2015-06-11 13:45:57 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-05-04 11:55:51 +00:00
|
|
|
|
2015-06-11 13:45:57 +00:00
|
|
|
if (!this.nodeFront || !this.el) {
|
|
|
|
return;
|
|
|
|
}
|
2015-05-04 11:55:51 +00:00
|
|
|
|
2015-06-11 13:45:57 +00:00
|
|
|
let {tagName, attributes} = this.nodeFront;
|
2015-05-04 11:55:51 +00:00
|
|
|
|
2015-06-11 13:45:57 +00:00
|
|
|
this.tagNameEl.textContent = tagName.toLowerCase();
|
2015-05-04 11:55:51 +00:00
|
|
|
|
2015-06-11 13:45:57 +00:00
|
|
|
let idIndex = attributes.findIndex(({name}) => name === "id");
|
|
|
|
if (idIndex > -1 && attributes[idIndex].value) {
|
|
|
|
this.idEl.querySelector(".attribute-value").textContent =
|
|
|
|
attributes[idIndex].value;
|
|
|
|
this.idEl.style.display = "inline";
|
|
|
|
} else {
|
|
|
|
this.idEl.style.display = "none";
|
|
|
|
}
|
2015-05-04 11:55:51 +00:00
|
|
|
|
2015-06-11 13:45:57 +00:00
|
|
|
let classIndex = attributes.findIndex(({name}) => name === "class");
|
|
|
|
if (classIndex > -1 && attributes[classIndex].value) {
|
|
|
|
let value = attributes[classIndex].value;
|
|
|
|
if (this.options.compact) {
|
|
|
|
value = value.split(" ").join(".");
|
2015-05-04 11:55:51 +00:00
|
|
|
}
|
2015-06-11 13:45:57 +00:00
|
|
|
|
|
|
|
this.classEl.querySelector(".attribute-value").textContent = value;
|
|
|
|
this.classEl.style.display = "inline";
|
|
|
|
} else {
|
|
|
|
this.classEl.style.display = "none";
|
|
|
|
}
|
|
|
|
|
|
|
|
this.emit("target-retrieved");
|
|
|
|
})
|
2015-05-04 11:55:51 +00:00
|
|
|
};
|
|
|
|
|
2015-11-02 11:54:07 +00:00
|
|
|
/**
|
|
|
|
* UI component responsible for displaying a playback rate selector UI.
|
|
|
|
* The rendering logic is such that a predefined list of rates is generated.
|
|
|
|
* If *all* animations passed to render share the same rate, then that rate is
|
|
|
|
* selected in the <select> element, otherwise, the empty value is selected.
|
|
|
|
* If the rate that all animations share isn't part of the list of predefined
|
|
|
|
* rates, than that rate is added to the list.
|
|
|
|
*/
|
|
|
|
function RateSelector() {
|
|
|
|
this.onRateChanged = this.onRateChanged.bind(this);
|
|
|
|
EventEmitter.decorate(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.RateSelector = RateSelector;
|
|
|
|
|
|
|
|
RateSelector.prototype = {
|
|
|
|
init: function(containerEl) {
|
|
|
|
this.selectEl = createNode({
|
|
|
|
parent: containerEl,
|
|
|
|
nodeType: "select",
|
|
|
|
attributes: {"class": "devtools-button"}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.selectEl.addEventListener("change", this.onRateChanged);
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function() {
|
|
|
|
this.selectEl.removeEventListener("change", this.onRateChanged);
|
|
|
|
this.selectEl.remove();
|
|
|
|
this.selectEl = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
getAnimationsRates: function(animations) {
|
|
|
|
return sortedUnique(animations.map(a => a.state.playbackRate));
|
|
|
|
},
|
|
|
|
|
|
|
|
getAllRates: function(animations) {
|
|
|
|
let animationsRates = this.getAnimationsRates(animations);
|
|
|
|
if (animationsRates.length > 1) {
|
|
|
|
return PLAYBACK_RATES;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sortedUnique(PLAYBACK_RATES.concat(animationsRates));
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function(animations) {
|
|
|
|
let allRates = this.getAnimationsRates(animations);
|
|
|
|
let hasOneRate = allRates.length === 1;
|
|
|
|
|
|
|
|
this.selectEl.innerHTML = "";
|
|
|
|
|
|
|
|
if (!hasOneRate) {
|
|
|
|
// When the animations displayed have mixed playback rates, we can't
|
|
|
|
// select any of the predefined ones, instead, insert an empty rate.
|
|
|
|
createNode({
|
|
|
|
parent: this.selectEl,
|
|
|
|
nodeType: "option",
|
|
|
|
attributes: {value: "", selector: "true"},
|
|
|
|
textContent: "-"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
for (let rate of this.getAllRates(animations)) {
|
|
|
|
let option = createNode({
|
|
|
|
parent: this.selectEl,
|
|
|
|
nodeType: "option",
|
|
|
|
attributes: {value: rate},
|
|
|
|
textContent: L10N.getFormatStr("player.playbackRateLabel", rate)
|
|
|
|
});
|
|
|
|
|
|
|
|
// If there's only one rate and this is the option for it, select it.
|
|
|
|
if (hasOneRate && rate === allRates[0]) {
|
|
|
|
option.setAttribute("selected", "true");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onRateChanged: function() {
|
|
|
|
let rate = parseFloat(this.selectEl.value);
|
|
|
|
if (!isNaN(rate)) {
|
|
|
|
this.emit("rate-changed", rate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-05-04 11:55:51 +00:00
|
|
|
/**
|
2015-06-11 13:45:57 +00:00
|
|
|
* The TimeScale helper object is used to know which size should something be
|
|
|
|
* displayed with in the animation panel, depending on the animations that are
|
|
|
|
* currently displayed.
|
|
|
|
* If there are 5 animations displayed, and the first one starts at 10000ms and
|
|
|
|
* the last one ends at 20000ms, then this helper can be used to convert any
|
|
|
|
* time in this range to a distance in pixels.
|
|
|
|
*
|
|
|
|
* For the helper to know how to convert, it needs to know all the animations.
|
|
|
|
* Whenever a new animation is added to the panel, addAnimation(state) should be
|
|
|
|
* called. reset() can be called to start over.
|
2015-05-04 11:55:51 +00:00
|
|
|
*/
|
2015-09-15 18:19:45 +00:00
|
|
|
var TimeScale = {
|
2015-06-11 13:45:57 +00:00
|
|
|
minStartTime: Infinity,
|
|
|
|
maxEndTime: 0,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new animation to time scale.
|
|
|
|
* @param {Object} state A PlayerFront.state object.
|
|
|
|
*/
|
2015-08-27 14:59:16 +00:00
|
|
|
addAnimation: function(state) {
|
2015-09-18 07:28:14 +00:00
|
|
|
let {previousStartTime, delay, duration,
|
|
|
|
iterationCount, playbackRate} = state;
|
2015-08-27 14:59:16 +00:00
|
|
|
|
2015-09-04 15:43:41 +00:00
|
|
|
// Negative-delayed animations have their startTimes set such that we would
|
|
|
|
// be displaying the delay outside the time window if we didn't take it into
|
|
|
|
// account here.
|
|
|
|
let relevantDelay = delay < 0 ? delay / playbackRate : 0;
|
2015-09-18 07:28:14 +00:00
|
|
|
previousStartTime = previousStartTime || 0;
|
2015-09-04 15:43:41 +00:00
|
|
|
|
2015-09-18 07:28:14 +00:00
|
|
|
this.minStartTime = Math.min(this.minStartTime,
|
|
|
|
previousStartTime + relevantDelay);
|
2015-08-27 14:59:16 +00:00
|
|
|
let length = (delay / playbackRate) +
|
|
|
|
((duration / playbackRate) *
|
|
|
|
(!iterationCount ? 1 : iterationCount));
|
2015-12-09 14:49:23 +00:00
|
|
|
let endTime = previousStartTime + length;
|
|
|
|
this.maxEndTime = Math.max(this.maxEndTime, endTime);
|
2015-06-11 13:45:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset the current time scale.
|
|
|
|
*/
|
|
|
|
reset: function() {
|
|
|
|
this.minStartTime = Infinity;
|
|
|
|
this.maxEndTime = 0;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-12-02 12:52:15 +00:00
|
|
|
* Convert a startTime to a distance in %, in the current time scale.
|
2015-06-11 13:45:57 +00:00
|
|
|
* @param {Number} time
|
|
|
|
* @return {Number}
|
|
|
|
*/
|
2015-12-02 12:52:15 +00:00
|
|
|
startTimeToDistance: function(time) {
|
2015-06-11 13:45:57 +00:00
|
|
|
time -= this.minStartTime;
|
2015-12-02 12:52:15 +00:00
|
|
|
return this.durationToDistance(time);
|
2015-06-11 13:45:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-12-02 12:52:15 +00:00
|
|
|
* Convert a duration to a distance in %, in the current time scale.
|
2015-06-11 13:45:57 +00:00
|
|
|
* @param {Number} time
|
|
|
|
* @return {Number}
|
|
|
|
*/
|
2015-12-02 12:52:15 +00:00
|
|
|
durationToDistance: function(duration) {
|
2015-12-09 14:49:23 +00:00
|
|
|
return duration * 100 / this.getDuration();
|
2015-06-11 13:45:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-12-02 12:52:15 +00:00
|
|
|
* Convert a distance in % to a time, in the current time scale.
|
2015-06-11 13:45:57 +00:00
|
|
|
* @param {Number} distance
|
|
|
|
* @return {Number}
|
|
|
|
*/
|
2015-12-02 12:52:15 +00:00
|
|
|
distanceToTime: function(distance) {
|
2015-12-09 14:49:23 +00:00
|
|
|
return this.minStartTime + (this.getDuration() * distance / 100);
|
2015-06-11 13:45:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-12-02 12:52:15 +00:00
|
|
|
* Convert a distance in % to a time, in the current time scale.
|
2015-06-11 13:45:57 +00:00
|
|
|
* The time will be relative to the current minimum start time.
|
|
|
|
* @param {Number} distance
|
|
|
|
* @return {Number}
|
|
|
|
*/
|
2015-12-02 12:52:15 +00:00
|
|
|
distanceToRelativeTime: function(distance) {
|
|
|
|
let time = this.distanceToTime(distance);
|
2015-06-11 13:45:57 +00:00
|
|
|
return time - this.minStartTime;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Depending on the time scale, format the given time as milliseconds or
|
|
|
|
* seconds.
|
|
|
|
* @param {Number} time
|
|
|
|
* @return {String} The formatted time string.
|
|
|
|
*/
|
|
|
|
formatTime: function(time) {
|
|
|
|
// Format in milliseconds if the total duration is short enough.
|
2015-12-09 14:49:23 +00:00
|
|
|
if (this.getDuration() <= MILLIS_TIME_FORMAT_MAX_DURATION) {
|
2015-06-11 13:45:57 +00:00
|
|
|
return L10N.getFormatStr("timeline.timeGraduationLabel", time.toFixed(0));
|
|
|
|
}
|
2015-05-04 11:55:51 +00:00
|
|
|
|
2015-06-11 13:45:57 +00:00
|
|
|
// Otherwise format in seconds.
|
|
|
|
return L10N.getFormatStr("player.timeLabel", (time / 1000).toFixed(1));
|
2015-12-09 14:49:23 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getDuration: function() {
|
|
|
|
return this.maxEndTime - this.minStartTime;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given an animation, get the various dimensions (in %) useful to draw the
|
|
|
|
* animation in the timeline.
|
|
|
|
*/
|
|
|
|
getAnimationDimensions: function({state}) {
|
|
|
|
let start = state.previousStartTime || 0;
|
|
|
|
let duration = state.duration;
|
|
|
|
let rate = state.playbackRate;
|
|
|
|
let count = state.iterationCount;
|
|
|
|
let delay = state.delay || 0;
|
|
|
|
|
|
|
|
// The start position.
|
|
|
|
let x = this.startTimeToDistance(start + (delay / rate));
|
|
|
|
// The width for a single iteration.
|
|
|
|
let w = this.durationToDistance(duration / rate);
|
|
|
|
// The width for all iterations.
|
|
|
|
let iterationW = w * (count || 1);
|
|
|
|
// The start position of the delay.
|
|
|
|
let delayX = this.durationToDistance((delay < 0 ? 0 : delay) / rate);
|
|
|
|
// The width of the delay.
|
|
|
|
let delayW = this.durationToDistance(Math.abs(delay) / rate);
|
|
|
|
// The width of the delay if it is positive, 0 otherwise.
|
|
|
|
let negativeDelayW = delay < 0 ? delayW : 0;
|
|
|
|
|
|
|
|
return {x, w, iterationW, delayX, delayW, negativeDelayW};
|
2015-05-04 11:55:51 +00:00
|
|
|
}
|
2015-06-11 13:45:57 +00:00
|
|
|
};
|
2015-05-04 11:55:51 +00:00
|
|
|
|
2015-06-15 10:03:54 +00:00
|
|
|
exports.TimeScale = TimeScale;
|
|
|
|
|
2015-06-11 13:45:57 +00:00
|
|
|
/**
|
|
|
|
* UI component responsible for displaying a timeline for animations.
|
|
|
|
* The timeline is essentially a graph with time along the x axis and animations
|
|
|
|
* along the y axis.
|
|
|
|
* The time is represented with a graduation header at the top and a current
|
|
|
|
* time play head.
|
|
|
|
* Animations are organized by lines, with a left margin containing the preview
|
|
|
|
* of the target DOM element the animation applies to.
|
2015-08-21 13:23:17 +00:00
|
|
|
* The current time play head can be moved by clicking/dragging in the header.
|
2015-09-16 15:00:07 +00:00
|
|
|
* when this happens, the component emits "current-data-changed" events with the
|
|
|
|
* new time and state of the timeline.
|
2015-08-21 13:23:17 +00:00
|
|
|
*
|
|
|
|
* @param {InspectorPanel} inspector.
|
2015-06-11 13:45:57 +00:00
|
|
|
*/
|
|
|
|
function AnimationsTimeline(inspector) {
|
|
|
|
this.animations = [];
|
|
|
|
this.targetNodes = [];
|
2015-10-16 20:35:28 +00:00
|
|
|
this.timeBlocks = [];
|
2015-12-09 14:49:23 +00:00
|
|
|
this.details = [];
|
2015-06-11 13:45:57 +00:00
|
|
|
this.inspector = inspector;
|
2015-12-02 12:52:15 +00:00
|
|
|
|
2015-06-11 13:45:57 +00:00
|
|
|
this.onAnimationStateChanged = this.onAnimationStateChanged.bind(this);
|
2015-10-15 08:14:35 +00:00
|
|
|
this.onScrubberMouseDown = this.onScrubberMouseDown.bind(this);
|
|
|
|
this.onScrubberMouseUp = this.onScrubberMouseUp.bind(this);
|
|
|
|
this.onScrubberMouseOut = this.onScrubberMouseOut.bind(this);
|
|
|
|
this.onScrubberMouseMove = this.onScrubberMouseMove.bind(this);
|
2015-11-17 14:05:57 +00:00
|
|
|
this.onAnimationSelected = this.onAnimationSelected.bind(this);
|
2015-12-02 12:52:15 +00:00
|
|
|
this.onWindowResize = this.onWindowResize.bind(this);
|
2015-12-09 14:49:23 +00:00
|
|
|
this.onFrameSelected = this.onFrameSelected.bind(this);
|
2015-12-02 12:52:15 +00:00
|
|
|
|
2015-08-21 13:23:17 +00:00
|
|
|
EventEmitter.decorate(this);
|
2015-05-04 11:55:51 +00:00
|
|
|
}
|
|
|
|
|
2015-06-11 13:45:57 +00:00
|
|
|
exports.AnimationsTimeline = AnimationsTimeline;
|
|
|
|
|
|
|
|
AnimationsTimeline.prototype = {
|
|
|
|
init: function(containerEl) {
|
|
|
|
this.win = containerEl.ownerDocument.defaultView;
|
|
|
|
|
|
|
|
this.rootWrapperEl = createNode({
|
|
|
|
parent: containerEl,
|
|
|
|
attributes: {
|
|
|
|
"class": "animation-timeline"
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-12-02 12:52:15 +00:00
|
|
|
let scrubberContainer = createNode({
|
2015-12-01 23:55:26 +00:00
|
|
|
parent: this.rootWrapperEl,
|
2015-12-09 14:49:23 +00:00
|
|
|
attributes: {"class": "scrubber-wrapper track-container"}
|
2015-12-02 12:52:15 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this.scrubberEl = createNode({
|
|
|
|
parent: scrubberContainer,
|
2015-08-21 13:23:17 +00:00
|
|
|
attributes: {
|
|
|
|
"class": "scrubber"
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-10-15 08:14:35 +00:00
|
|
|
this.scrubberHandleEl = createNode({
|
|
|
|
parent: this.scrubberEl,
|
|
|
|
attributes: {
|
|
|
|
"class": "scrubber-handle"
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.scrubberHandleEl.addEventListener("mousedown", this.onScrubberMouseDown);
|
|
|
|
|
2015-06-11 13:45:57 +00:00
|
|
|
this.timeHeaderEl = createNode({
|
|
|
|
parent: this.rootWrapperEl,
|
|
|
|
attributes: {
|
2015-12-09 14:49:23 +00:00
|
|
|
"class": "time-header track-container"
|
2015-06-11 13:45:57 +00:00
|
|
|
}
|
|
|
|
});
|
2015-10-15 08:14:35 +00:00
|
|
|
this.timeHeaderEl.addEventListener("mousedown", this.onScrubberMouseDown);
|
2015-06-11 13:45:57 +00:00
|
|
|
|
|
|
|
this.animationsEl = createNode({
|
|
|
|
parent: this.rootWrapperEl,
|
|
|
|
nodeType: "ul",
|
|
|
|
attributes: {
|
|
|
|
"class": "animations"
|
|
|
|
}
|
|
|
|
});
|
2015-12-02 12:52:15 +00:00
|
|
|
|
|
|
|
this.win.addEventListener("resize", this.onWindowResize);
|
2015-06-11 13:45:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function() {
|
2015-08-27 14:59:16 +00:00
|
|
|
this.stopAnimatingScrubber();
|
2015-06-11 13:45:57 +00:00
|
|
|
this.unrender();
|
|
|
|
|
2015-12-02 12:52:15 +00:00
|
|
|
this.win.removeEventListener("resize", this.onWindowResize);
|
2015-08-21 13:23:17 +00:00
|
|
|
this.timeHeaderEl.removeEventListener("mousedown",
|
2015-10-15 08:14:35 +00:00
|
|
|
this.onScrubberMouseDown);
|
|
|
|
this.scrubberHandleEl.removeEventListener("mousedown",
|
|
|
|
this.onScrubberMouseDown);
|
2015-08-21 13:23:17 +00:00
|
|
|
|
2015-06-11 13:45:57 +00:00
|
|
|
this.rootWrapperEl.remove();
|
|
|
|
this.animations = [];
|
|
|
|
|
|
|
|
this.rootWrapperEl = null;
|
|
|
|
this.timeHeaderEl = null;
|
|
|
|
this.animationsEl = null;
|
2015-08-21 13:23:17 +00:00
|
|
|
this.scrubberEl = null;
|
2015-10-15 08:14:35 +00:00
|
|
|
this.scrubberHandleEl = null;
|
2015-06-11 13:45:57 +00:00
|
|
|
this.win = null;
|
|
|
|
this.inspector = null;
|
|
|
|
},
|
2015-11-17 14:05:57 +00:00
|
|
|
|
2015-12-09 14:49:23 +00:00
|
|
|
/**
|
|
|
|
* Destroy sub-components that have been created and stored on this instance.
|
|
|
|
* @param {String} name An array of components will be expected in this[name]
|
|
|
|
* @param {Array} handlers An option list of event handlers information that
|
|
|
|
* should be used to remove these handlers.
|
|
|
|
*/
|
|
|
|
destroySubComponents: function(name, handlers = []) {
|
|
|
|
for (let component of this[name]) {
|
|
|
|
for (let {event, fn} of handlers) {
|
|
|
|
component.off(event, fn);
|
|
|
|
}
|
|
|
|
component.destroy();
|
2015-10-16 20:35:28 +00:00
|
|
|
}
|
2015-12-09 14:49:23 +00:00
|
|
|
this[name] = [];
|
2015-10-16 20:35:28 +00:00
|
|
|
},
|
2015-06-11 13:45:57 +00:00
|
|
|
|
|
|
|
unrender: function() {
|
|
|
|
for (let animation of this.animations) {
|
|
|
|
animation.off("changed", this.onAnimationStateChanged);
|
|
|
|
}
|
|
|
|
TimeScale.reset();
|
2015-12-09 14:49:23 +00:00
|
|
|
this.destroySubComponents("targetNodes");
|
|
|
|
this.destroySubComponents("timeBlocks");
|
|
|
|
this.destroySubComponents("details", [{
|
|
|
|
event: "frame-selected",
|
|
|
|
fn: this.onFrameSelected
|
|
|
|
}]);
|
2015-06-11 13:45:57 +00:00
|
|
|
this.animationsEl.innerHTML = "";
|
|
|
|
},
|
2015-10-19 13:51:24 +00:00
|
|
|
|
2015-12-02 12:52:15 +00:00
|
|
|
onWindowResize: function() {
|
|
|
|
if (this.windowResizeTimer) {
|
|
|
|
this.win.clearTimeout(this.windowResizeTimer);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.windowResizeTimer = this.win.setTimeout(() => {
|
|
|
|
this.drawHeaderAndBackground();
|
|
|
|
}, TIMELINE_BACKGROUND_RESIZE_DEBOUNCE_TIMER);
|
|
|
|
},
|
|
|
|
|
2015-11-17 14:05:57 +00:00
|
|
|
onAnimationSelected: function(e, animation) {
|
|
|
|
let index = this.animations.indexOf(animation);
|
|
|
|
if (index === -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-09 14:49:23 +00:00
|
|
|
let el = this.rootWrapperEl;
|
|
|
|
let animationEl = el.querySelectorAll(".animation")[index];
|
|
|
|
let propsEl = el.querySelectorAll(".animated-properties")[index];
|
|
|
|
|
|
|
|
// Toggle the selected state on this animation.
|
|
|
|
animationEl.classList.toggle("selected");
|
|
|
|
propsEl.classList.toggle("selected");
|
|
|
|
|
|
|
|
// Render the details component for this animation if it was shown.
|
|
|
|
if (animationEl.classList.contains("selected")) {
|
|
|
|
this.details[index].render(animation);
|
|
|
|
this.emit("animation-selected", animation);
|
|
|
|
} else {
|
|
|
|
this.emit("animation-unselected", animation);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When a frame gets selected, move the scrubber to the corresponding position
|
|
|
|
*/
|
|
|
|
onFrameSelected: function(e, {x}) {
|
|
|
|
this.moveScrubberTo(x, true);
|
2015-11-17 14:05:57 +00:00
|
|
|
},
|
|
|
|
|
2015-10-15 08:14:35 +00:00
|
|
|
onScrubberMouseDown: function(e) {
|
2015-08-21 13:23:17 +00:00
|
|
|
this.moveScrubberTo(e.pageX);
|
2015-10-15 08:14:35 +00:00
|
|
|
this.win.addEventListener("mouseup", this.onScrubberMouseUp);
|
|
|
|
this.win.addEventListener("mouseout", this.onScrubberMouseOut);
|
|
|
|
this.win.addEventListener("mousemove", this.onScrubberMouseMove);
|
|
|
|
|
|
|
|
// Prevent text selection while dragging.
|
|
|
|
e.preventDefault();
|
2015-08-21 13:23:17 +00:00
|
|
|
},
|
|
|
|
|
2015-10-15 08:14:35 +00:00
|
|
|
onScrubberMouseUp: function() {
|
2015-08-21 13:23:17 +00:00
|
|
|
this.cancelTimeHeaderDragging();
|
|
|
|
},
|
|
|
|
|
2015-10-15 08:14:35 +00:00
|
|
|
onScrubberMouseOut: function(e) {
|
2015-08-21 13:23:17 +00:00
|
|
|
// Check that mouseout happened on the window itself, and if yes, cancel
|
|
|
|
// the dragging.
|
|
|
|
if (!this.win.document.contains(e.relatedTarget)) {
|
|
|
|
this.cancelTimeHeaderDragging();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
cancelTimeHeaderDragging: function() {
|
2015-10-15 08:14:35 +00:00
|
|
|
this.win.removeEventListener("mouseup", this.onScrubberMouseUp);
|
|
|
|
this.win.removeEventListener("mouseout", this.onScrubberMouseOut);
|
|
|
|
this.win.removeEventListener("mousemove", this.onScrubberMouseMove);
|
2015-08-21 13:23:17 +00:00
|
|
|
},
|
|
|
|
|
2015-10-15 08:14:35 +00:00
|
|
|
onScrubberMouseMove: function(e) {
|
2015-08-21 13:23:17 +00:00
|
|
|
this.moveScrubberTo(e.pageX);
|
|
|
|
},
|
|
|
|
|
2015-12-09 14:49:23 +00:00
|
|
|
moveScrubberTo: function(pageX, noOffset) {
|
2015-08-27 14:59:16 +00:00
|
|
|
this.stopAnimatingScrubber();
|
|
|
|
|
2015-12-02 12:52:15 +00:00
|
|
|
// The offset needs to be in % and relative to the timeline's area (so we
|
|
|
|
// subtract the scrubber's left offset, which is equal to the sidebar's
|
|
|
|
// width).
|
2015-12-09 14:49:23 +00:00
|
|
|
let offset = pageX;
|
|
|
|
if (!noOffset) {
|
|
|
|
offset -= this.timeHeaderEl.offsetLeft;
|
|
|
|
}
|
|
|
|
offset = offset * 100 / this.timeHeaderEl.offsetWidth;
|
2015-08-21 13:23:17 +00:00
|
|
|
if (offset < 0) {
|
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
|
2015-12-02 12:52:15 +00:00
|
|
|
this.scrubberEl.style.left = offset + "%";
|
2015-08-21 13:23:17 +00:00
|
|
|
|
2015-12-02 12:52:15 +00:00
|
|
|
let time = TimeScale.distanceToRelativeTime(offset);
|
2015-09-16 15:00:07 +00:00
|
|
|
|
|
|
|
this.emit("timeline-data-changed", {
|
|
|
|
isPaused: true,
|
|
|
|
isMoving: false,
|
2015-10-19 13:51:24 +00:00
|
|
|
isUserDrag: true,
|
2015-09-16 15:00:07 +00:00
|
|
|
time: time
|
|
|
|
});
|
2015-08-21 13:23:17 +00:00
|
|
|
},
|
|
|
|
|
2015-09-03 07:34:08 +00:00
|
|
|
render: function(animations, documentCurrentTime) {
|
2015-06-11 13:45:57 +00:00
|
|
|
this.unrender();
|
|
|
|
|
|
|
|
this.animations = animations;
|
|
|
|
if (!this.animations.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Loop first to set the time scale for all current animations.
|
|
|
|
for (let {state} of animations) {
|
|
|
|
TimeScale.addAnimation(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.drawHeaderAndBackground();
|
|
|
|
|
|
|
|
for (let animation of this.animations) {
|
|
|
|
animation.on("changed", this.onAnimationStateChanged);
|
|
|
|
|
|
|
|
// Each line contains the target animated node and the animation time
|
|
|
|
// block.
|
|
|
|
let animationEl = createNode({
|
|
|
|
parent: this.animationsEl,
|
|
|
|
nodeType: "li",
|
|
|
|
attributes: {
|
2015-10-29 13:12:22 +00:00
|
|
|
"class": "animation" + (animation.state.isRunningOnCompositor
|
|
|
|
? " fast-track"
|
|
|
|
: "")
|
2015-06-11 13:45:57 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-12-09 14:49:23 +00:00
|
|
|
// Right below the line is a hidden-by-default line for displaying the
|
|
|
|
// inline keyframes.
|
|
|
|
let detailsEl = createNode({
|
|
|
|
parent: this.animationsEl,
|
|
|
|
nodeType: "li",
|
|
|
|
attributes: {
|
|
|
|
"class": "animated-properties"
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
let details = new AnimationDetails();
|
|
|
|
details.init(detailsEl);
|
|
|
|
details.on("frame-selected", this.onFrameSelected);
|
|
|
|
this.details.push(details);
|
|
|
|
|
2015-06-11 13:45:57 +00:00
|
|
|
// Left sidebar for the animated node.
|
|
|
|
let animatedNodeEl = createNode({
|
|
|
|
parent: animationEl,
|
|
|
|
attributes: {
|
|
|
|
"class": "target"
|
|
|
|
}
|
|
|
|
});
|
2015-12-09 14:49:23 +00:00
|
|
|
|
2015-10-16 20:35:28 +00:00
|
|
|
// Draw the animated node target.
|
|
|
|
let targetNode = new AnimationTargetNode(this.inspector, {compact: true});
|
|
|
|
targetNode.init(animatedNodeEl);
|
|
|
|
targetNode.render(animation);
|
|
|
|
this.targetNodes.push(targetNode);
|
2015-06-11 13:45:57 +00:00
|
|
|
|
2015-10-16 20:35:28 +00:00
|
|
|
// Right-hand part contains the timeline itself (called time-block here).
|
2015-06-11 13:45:57 +00:00
|
|
|
let timeBlockEl = createNode({
|
|
|
|
parent: animationEl,
|
|
|
|
attributes: {
|
2015-12-09 14:49:23 +00:00
|
|
|
"class": "time-block track-container"
|
2015-06-11 13:45:57 +00:00
|
|
|
}
|
|
|
|
});
|
2015-12-09 14:49:23 +00:00
|
|
|
|
2015-10-16 20:35:28 +00:00
|
|
|
// Draw the animation time block.
|
|
|
|
let timeBlock = new AnimationTimeBlock();
|
|
|
|
timeBlock.init(timeBlockEl);
|
|
|
|
timeBlock.render(animation);
|
|
|
|
this.timeBlocks.push(timeBlock);
|
2015-11-17 14:05:57 +00:00
|
|
|
|
|
|
|
timeBlock.on("selected", this.onAnimationSelected);
|
2015-06-11 13:45:57 +00:00
|
|
|
}
|
2015-12-09 14:49:23 +00:00
|
|
|
|
2015-08-27 14:59:16 +00:00
|
|
|
// Use the document's current time to position the scrubber (if the server
|
|
|
|
// doesn't provide it, hide the scrubber entirely).
|
|
|
|
// Note that because the currentTime was sent via the protocol, some time
|
|
|
|
// may have gone by since then, and so the scrubber might be a bit late.
|
2015-09-03 07:34:08 +00:00
|
|
|
if (!documentCurrentTime) {
|
2015-08-27 14:59:16 +00:00
|
|
|
this.scrubberEl.style.display = "none";
|
|
|
|
} else {
|
|
|
|
this.scrubberEl.style.display = "block";
|
2015-10-12 09:34:59 +00:00
|
|
|
this.startAnimatingScrubber(this.wasRewound()
|
|
|
|
? TimeScale.minStartTime
|
|
|
|
: documentCurrentTime);
|
2015-08-27 14:59:16 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-09-18 07:28:14 +00:00
|
|
|
isAtLeastOneAnimationPlaying: function() {
|
|
|
|
return this.animations.some(({state}) => state.playState === "running");
|
|
|
|
},
|
|
|
|
|
2015-10-12 09:34:59 +00:00
|
|
|
wasRewound: function() {
|
|
|
|
return !this.isAtLeastOneAnimationPlaying() &&
|
|
|
|
this.animations.every(({state}) => state.currentTime === 0);
|
|
|
|
},
|
|
|
|
|
2015-10-28 11:58:39 +00:00
|
|
|
hasInfiniteAnimations: function() {
|
|
|
|
return this.animations.some(({state}) => !state.iterationCount);
|
|
|
|
},
|
|
|
|
|
2015-08-27 14:59:16 +00:00
|
|
|
startAnimatingScrubber: function(time) {
|
2015-12-02 12:52:15 +00:00
|
|
|
let x = TimeScale.startTimeToDistance(time);
|
|
|
|
this.scrubberEl.style.left = x + "%";
|
2015-08-27 14:59:16 +00:00
|
|
|
|
2015-10-28 11:58:39 +00:00
|
|
|
// Only stop the scrubber if it's out of bounds or all animations have been
|
|
|
|
// paused, but not if at least an animation is infinite.
|
|
|
|
let isOutOfBounds = time < TimeScale.minStartTime ||
|
|
|
|
time > TimeScale.maxEndTime;
|
|
|
|
let isAllPaused = !this.isAtLeastOneAnimationPlaying();
|
|
|
|
let hasInfinite = this.hasInfiniteAnimations();
|
|
|
|
|
|
|
|
if (isAllPaused || (isOutOfBounds && !hasInfinite)) {
|
2015-09-16 15:00:07 +00:00
|
|
|
this.stopAnimatingScrubber();
|
|
|
|
this.emit("timeline-data-changed", {
|
2015-10-14 08:03:29 +00:00
|
|
|
isPaused: !this.isAtLeastOneAnimationPlaying(),
|
2015-09-16 15:00:07 +00:00
|
|
|
isMoving: false,
|
2015-10-19 13:51:24 +00:00
|
|
|
isUserDrag: false,
|
2015-12-02 12:52:15 +00:00
|
|
|
time: TimeScale.distanceToRelativeTime(x)
|
2015-09-16 15:00:07 +00:00
|
|
|
});
|
2015-08-27 14:59:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-16 15:00:07 +00:00
|
|
|
this.emit("timeline-data-changed", {
|
|
|
|
isPaused: false,
|
|
|
|
isMoving: true,
|
2015-10-19 13:51:24 +00:00
|
|
|
isUserDrag: false,
|
2015-12-02 12:52:15 +00:00
|
|
|
time: TimeScale.distanceToRelativeTime(x)
|
2015-09-16 15:00:07 +00:00
|
|
|
});
|
|
|
|
|
2015-08-27 14:59:16 +00:00
|
|
|
let now = this.win.performance.now();
|
|
|
|
this.rafID = this.win.requestAnimationFrame(() => {
|
2015-09-16 15:00:07 +00:00
|
|
|
if (!this.rafID) {
|
|
|
|
// In case the scrubber was stopped in the meantime.
|
|
|
|
return;
|
|
|
|
}
|
2015-08-27 14:59:16 +00:00
|
|
|
this.startAnimatingScrubber(time + this.win.performance.now() - now);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
stopAnimatingScrubber: function() {
|
|
|
|
if (this.rafID) {
|
|
|
|
this.win.cancelAnimationFrame(this.rafID);
|
2015-09-16 15:00:07 +00:00
|
|
|
this.rafID = null;
|
2015-08-27 14:59:16 +00:00
|
|
|
}
|
2015-06-11 13:45:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onAnimationStateChanged: function() {
|
|
|
|
// For now, simply re-render the component. The animation front's state has
|
|
|
|
// already been updated.
|
|
|
|
this.render(this.animations);
|
|
|
|
},
|
|
|
|
|
|
|
|
drawHeaderAndBackground: function() {
|
|
|
|
let width = this.timeHeaderEl.offsetWidth;
|
|
|
|
let scale = width / (TimeScale.maxEndTime - TimeScale.minStartTime);
|
2015-08-13 12:07:51 +00:00
|
|
|
drawGraphElementBackground(this.win.document, "time-graduations",
|
|
|
|
width, scale);
|
2015-06-11 13:45:57 +00:00
|
|
|
|
|
|
|
// And the time graduation header.
|
|
|
|
this.timeHeaderEl.innerHTML = "";
|
|
|
|
let interval = findOptimalTimeInterval(scale, TIME_GRADUATION_MIN_SPACING);
|
|
|
|
for (let i = 0; i < width; i += interval) {
|
2015-12-02 12:52:15 +00:00
|
|
|
let pos = 100 * i / width;
|
2015-06-11 13:45:57 +00:00
|
|
|
createNode({
|
|
|
|
parent: this.timeHeaderEl,
|
|
|
|
nodeType: "span",
|
|
|
|
attributes: {
|
|
|
|
"class": "time-tick",
|
2015-12-02 12:52:15 +00:00
|
|
|
"style": `left:${pos}%`
|
2015-06-11 13:45:57 +00:00
|
|
|
},
|
2015-12-02 12:52:15 +00:00
|
|
|
textContent: TimeScale.formatTime(TimeScale.distanceToRelativeTime(pos))
|
2015-06-11 13:45:57 +00:00
|
|
|
});
|
|
|
|
}
|
2015-10-16 20:35:28 +00:00
|
|
|
}
|
|
|
|
};
|
2015-09-01 15:01:48 +00:00
|
|
|
|
2015-10-16 20:35:28 +00:00
|
|
|
/**
|
|
|
|
* UI component responsible for displaying a single animation timeline, which
|
|
|
|
* basically looks like a rectangle that shows the delay and iterations.
|
|
|
|
*/
|
2015-11-17 14:05:57 +00:00
|
|
|
function AnimationTimeBlock() {
|
|
|
|
EventEmitter.decorate(this);
|
|
|
|
this.onClick = this.onClick.bind(this);
|
|
|
|
}
|
2015-09-01 15:01:48 +00:00
|
|
|
|
2015-10-16 20:35:28 +00:00
|
|
|
exports.AnimationTimeBlock = AnimationTimeBlock;
|
2015-10-16 15:10:21 +00:00
|
|
|
|
2015-10-16 20:35:28 +00:00
|
|
|
AnimationTimeBlock.prototype = {
|
|
|
|
init: function(containerEl) {
|
|
|
|
this.containerEl = containerEl;
|
2015-11-17 14:05:57 +00:00
|
|
|
this.containerEl.addEventListener("click", this.onClick);
|
2015-10-16 20:35:28 +00:00
|
|
|
},
|
2015-11-17 14:05:57 +00:00
|
|
|
|
2015-10-16 20:35:28 +00:00
|
|
|
destroy: function() {
|
2015-11-17 14:05:57 +00:00
|
|
|
this.containerEl.removeEventListener("click", this.onClick);
|
2015-12-09 14:49:23 +00:00
|
|
|
this.unrender();
|
|
|
|
this.containerEl = null;
|
|
|
|
this.animation = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
unrender: function() {
|
2015-10-16 20:35:28 +00:00
|
|
|
while (this.containerEl.firstChild) {
|
|
|
|
this.containerEl.firstChild.remove();
|
|
|
|
}
|
2015-09-01 15:01:48 +00:00
|
|
|
},
|
|
|
|
|
2015-10-16 20:35:28 +00:00
|
|
|
render: function(animation) {
|
2015-12-09 14:49:23 +00:00
|
|
|
this.unrender();
|
|
|
|
|
2015-10-16 20:35:28 +00:00
|
|
|
this.animation = animation;
|
|
|
|
let {state} = this.animation;
|
|
|
|
|
2015-08-26 08:39:16 +00:00
|
|
|
// Create a container element to hold the delay and iterations.
|
|
|
|
// It is positioned according to its delay (divided by the playbackrate),
|
|
|
|
// and its width is according to its duration (divided by the playbackrate).
|
2015-12-09 14:49:23 +00:00
|
|
|
let {x, iterationW, delayX, delayW, negativeDelayW} =
|
|
|
|
TimeScale.getAnimationDimensions(animation);
|
2015-06-11 13:45:57 +00:00
|
|
|
|
|
|
|
let iterations = createNode({
|
2015-10-16 20:35:28 +00:00
|
|
|
parent: this.containerEl,
|
2015-06-11 13:45:57 +00:00
|
|
|
attributes: {
|
2015-12-09 14:49:23 +00:00
|
|
|
"class": state.type + " iterations" +
|
|
|
|
(state.iterationCount ? "" : " infinite"),
|
2015-06-11 13:45:57 +00:00
|
|
|
// Individual iterations are represented by setting the size of the
|
|
|
|
// repeating linear-gradient.
|
2015-12-02 12:52:15 +00:00
|
|
|
"style": `left:${x}%;
|
|
|
|
width:${iterationW}%;
|
2015-12-09 14:49:23 +00:00
|
|
|
background-size:${100 / (state.iterationCount || 1)}% 100%;`
|
2015-06-11 13:45:57 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// The animation name is displayed over the iterations.
|
2015-09-04 15:43:41 +00:00
|
|
|
// Note that in case of negative delay, we push the name towards the right
|
|
|
|
// so the delay can be shown.
|
2015-06-11 13:45:57 +00:00
|
|
|
createNode({
|
|
|
|
parent: iterations,
|
|
|
|
attributes: {
|
2015-08-27 14:48:37 +00:00
|
|
|
"class": "name",
|
2015-10-16 20:35:28 +00:00
|
|
|
"title": this.getTooltipText(state),
|
2015-12-02 12:52:15 +00:00
|
|
|
// Make space for the negative delay with a margin-left.
|
|
|
|
"style": `margin-left:${negativeDelayW}%`
|
2015-06-11 13:45:57 +00:00
|
|
|
},
|
|
|
|
textContent: state.name
|
|
|
|
});
|
|
|
|
|
|
|
|
// Delay.
|
2015-12-09 14:49:23 +00:00
|
|
|
if (state.delay) {
|
2015-09-04 15:43:41 +00:00
|
|
|
// Negative delays need to start at 0.
|
2015-06-11 13:45:57 +00:00
|
|
|
createNode({
|
|
|
|
parent: iterations,
|
|
|
|
attributes: {
|
2015-12-09 14:49:23 +00:00
|
|
|
"class": "delay" + (state.delay < 0 ? " negative" : ""),
|
2015-12-02 12:52:15 +00:00
|
|
|
"style": `left:-${delayX}%;
|
|
|
|
width:${delayW}%;`
|
2015-06-11 13:45:57 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-10-16 20:35:28 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getTooltipText: function(state) {
|
|
|
|
let getTime = time => L10N.getFormatStr("player.timeLabel",
|
|
|
|
L10N.numberWithDecimals(time / 1000, 2));
|
2015-11-02 11:54:07 +00:00
|
|
|
|
|
|
|
let text = "";
|
|
|
|
|
2015-12-09 14:49:23 +00:00
|
|
|
// Adding the name.
|
|
|
|
text += getFormattedAnimationTitle({state});
|
2015-11-02 11:54:07 +00:00
|
|
|
text += "\n";
|
|
|
|
|
|
|
|
// Adding the delay.
|
|
|
|
text += L10N.getStr("player.animationDelayLabel") + " ";
|
|
|
|
text += getTime(state.delay);
|
|
|
|
text += "\n";
|
|
|
|
|
|
|
|
// Adding the duration.
|
|
|
|
text += L10N.getStr("player.animationDurationLabel") + " ";
|
|
|
|
text += getTime(state.duration);
|
|
|
|
text += "\n";
|
|
|
|
|
|
|
|
// Adding the iteration count (the infinite symbol, or an integer).
|
2015-12-21 09:45:51 +00:00
|
|
|
if (state.iterationCount !== 1) {
|
|
|
|
text += L10N.getStr("player.animationIterationCountLabel") + " ";
|
|
|
|
text += state.iterationCount ||
|
|
|
|
L10N.getStr("player.infiniteIterationCountText");
|
|
|
|
text += "\n";
|
|
|
|
}
|
2015-11-02 11:54:07 +00:00
|
|
|
|
|
|
|
// Adding the playback rate if it's different than 1.
|
|
|
|
if (state.playbackRate !== 1) {
|
|
|
|
text += L10N.getStr("player.animationRateLabel") + " ";
|
|
|
|
text += state.playbackRate;
|
|
|
|
text += "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adding a note that the animation is running on the compositor thread if
|
|
|
|
// needed.
|
|
|
|
if (state.isRunningOnCompositor) {
|
|
|
|
text += L10N.getStr("player.runningOnCompositorTooltip");
|
|
|
|
}
|
|
|
|
|
|
|
|
return text;
|
2015-11-17 14:05:57 +00:00
|
|
|
},
|
|
|
|
|
2015-12-09 14:49:23 +00:00
|
|
|
onClick: function(e) {
|
|
|
|
e.stopPropagation();
|
2015-11-17 14:05:57 +00:00
|
|
|
this.emit("selected", this.animation);
|
2015-06-11 13:45:57 +00:00
|
|
|
}
|
|
|
|
};
|
2015-11-02 11:54:07 +00:00
|
|
|
|
2015-12-09 14:49:23 +00:00
|
|
|
/**
|
|
|
|
* UI component responsible for displaying detailed information for a given
|
|
|
|
* animation.
|
|
|
|
* This includes information about timing, easing, keyframes, animated
|
|
|
|
* properties.
|
|
|
|
*/
|
|
|
|
function AnimationDetails() {
|
|
|
|
EventEmitter.decorate(this);
|
|
|
|
|
|
|
|
this.onFrameSelected = this.onFrameSelected.bind(this);
|
|
|
|
|
|
|
|
this.keyframeComponents = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.AnimationDetails = AnimationDetails;
|
|
|
|
|
|
|
|
AnimationDetails.prototype = {
|
|
|
|
// These are part of frame objects but are not animated properties. This
|
|
|
|
// array is used to skip them.
|
|
|
|
NON_PROPERTIES: ["easing", "composite", "computedOffset", "offset"],
|
|
|
|
|
|
|
|
init: function(containerEl) {
|
|
|
|
this.containerEl = containerEl;
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function() {
|
|
|
|
this.unrender();
|
|
|
|
this.containerEl = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
unrender: function() {
|
|
|
|
for (let component of this.keyframeComponents) {
|
|
|
|
component.off("frame-selected", this.onFrameSelected);
|
|
|
|
component.destroy();
|
|
|
|
}
|
|
|
|
this.keyframeComponents = [];
|
|
|
|
|
|
|
|
while (this.containerEl.firstChild) {
|
|
|
|
this.containerEl.firstChild.remove();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert a list of frames into a list of tracks, one per animated property,
|
|
|
|
* each with a list of frames.
|
|
|
|
*/
|
|
|
|
getTracksFromFrames: function(frames) {
|
|
|
|
let tracks = {};
|
|
|
|
|
|
|
|
for (let frame of frames) {
|
|
|
|
for (let name in frame) {
|
|
|
|
if (this.NON_PROPERTIES.indexOf(name) != -1) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!tracks[name]) {
|
|
|
|
tracks[name] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
tracks[name].push({
|
|
|
|
value: frame[name],
|
|
|
|
offset: frame.computedOffset
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return tracks;
|
|
|
|
},
|
|
|
|
|
|
|
|
render: Task.async(function*(animation) {
|
|
|
|
this.unrender();
|
|
|
|
|
|
|
|
if (!animation) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.animation = animation;
|
|
|
|
|
|
|
|
let frames = yield animation.getFrames();
|
|
|
|
|
|
|
|
// We might have been destroyed in the meantime, or the component might
|
|
|
|
// have been re-rendered.
|
|
|
|
if (!this.containerEl || this.animation !== animation) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Useful for tests to know when the keyframes have been retrieved.
|
|
|
|
this.emit("keyframes-retrieved");
|
|
|
|
|
|
|
|
// Build an element for each animated property track.
|
|
|
|
this.tracks = this.getTracksFromFrames(frames);
|
|
|
|
for (let propertyName in this.tracks) {
|
|
|
|
let line = createNode({
|
|
|
|
parent: this.containerEl,
|
|
|
|
attributes: {"class": "property"}
|
|
|
|
});
|
|
|
|
|
|
|
|
createNode({
|
|
|
|
// text-overflow doesn't work in flex items, so we need a second level
|
|
|
|
// of container to actually have an ellipsis on the name.
|
|
|
|
// See bug 972664.
|
|
|
|
parent: createNode({
|
|
|
|
parent: line,
|
|
|
|
attributes: {"class": "name"},
|
|
|
|
}),
|
|
|
|
textContent: getCssPropertyName(propertyName)
|
|
|
|
});
|
|
|
|
|
|
|
|
// Add the keyframes diagram for this property.
|
|
|
|
let framesWrapperEl = createNode({
|
|
|
|
parent: line,
|
|
|
|
attributes: {"class": "track-container"}
|
|
|
|
});
|
|
|
|
|
|
|
|
let framesEl = createNode({
|
|
|
|
parent: framesWrapperEl,
|
|
|
|
attributes: {"class": "frames"}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Scale the list of keyframes according to the current time scale.
|
|
|
|
let {x, w} = TimeScale.getAnimationDimensions(animation);
|
|
|
|
framesEl.style.left = `${x}%`;
|
|
|
|
framesEl.style.width = `${w}%`;
|
|
|
|
|
|
|
|
let keyframesComponent = new Keyframes();
|
|
|
|
keyframesComponent.init(framesEl);
|
|
|
|
keyframesComponent.render({
|
|
|
|
keyframes: this.tracks[propertyName],
|
|
|
|
propertyName: propertyName,
|
|
|
|
animation: animation
|
|
|
|
});
|
|
|
|
keyframesComponent.on("frame-selected", this.onFrameSelected);
|
|
|
|
|
|
|
|
this.keyframeComponents.push(keyframesComponent);
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
|
|
|
onFrameSelected: function(e, args) {
|
|
|
|
// Relay the event up, it's needed in parents too.
|
|
|
|
this.emit(e, args);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UI component responsible for displaying a list of keyframes.
|
|
|
|
*/
|
|
|
|
function Keyframes() {
|
|
|
|
EventEmitter.decorate(this);
|
|
|
|
this.onClick = this.onClick.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.Keyframes = Keyframes;
|
|
|
|
|
|
|
|
Keyframes.prototype = {
|
|
|
|
init: function(containerEl) {
|
|
|
|
this.containerEl = containerEl;
|
|
|
|
|
|
|
|
this.keyframesEl = createNode({
|
|
|
|
parent: this.containerEl,
|
|
|
|
attributes: {"class": "keyframes"}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.containerEl.addEventListener("click", this.onClick);
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function() {
|
|
|
|
this.containerEl.removeEventListener("click", this.onClick);
|
|
|
|
this.keyframesEl.remove();
|
|
|
|
this.containerEl = this.keyframesEl = this.animation = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function({keyframes, propertyName, animation}) {
|
|
|
|
this.keyframes = keyframes;
|
|
|
|
this.propertyName = propertyName;
|
|
|
|
this.animation = animation;
|
|
|
|
|
|
|
|
this.keyframesEl.classList.add(animation.state.type);
|
|
|
|
for (let frame of this.keyframes) {
|
|
|
|
createNode({
|
|
|
|
parent: this.keyframesEl,
|
|
|
|
attributes: {
|
|
|
|
"class": "frame",
|
|
|
|
"style": `left:${frame.offset * 100}%;`,
|
|
|
|
"data-offset": frame.offset,
|
|
|
|
"data-property": propertyName,
|
|
|
|
"title": frame.value
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onClick: function(e) {
|
|
|
|
// If the click happened on a frame, tell our parent about it.
|
|
|
|
if (!e.target.classList.contains("frame")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
e.stopPropagation();
|
|
|
|
this.emit("frame-selected", {
|
|
|
|
animation: this.animation,
|
|
|
|
propertyName: this.propertyName,
|
|
|
|
offset: parseFloat(e.target.dataset.offset),
|
|
|
|
value: e.target.getAttribute("title"),
|
|
|
|
x: e.target.offsetLeft + e.target.closest(".frames").offsetLeft
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-11-02 11:54:07 +00:00
|
|
|
let sortedUnique = arr => [...new Set(arr)].sort((a, b) => a > b);
|
2015-12-09 14:49:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a formatted title for this animation. This will be either:
|
|
|
|
* "some-name", "some-name : CSS Transition", or "some-name : CSS Animation",
|
|
|
|
* depending if the server provides the type, and what type it is.
|
|
|
|
* @param {AnimationPlayerFront} animation
|
|
|
|
*/
|
|
|
|
function getFormattedAnimationTitle({state}) {
|
|
|
|
// Older servers don't send the type.
|
|
|
|
return state.type
|
|
|
|
? L10N.getFormatStr("timeline." + state.type + ".nameLabel", state.name)
|
|
|
|
: state.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Turn propertyName into property-name.
|
|
|
|
* @param {String} jsPropertyName A camelcased CSS property name. Typically
|
|
|
|
* something that comes out of computed styles. E.g. borderBottomColor
|
|
|
|
* @return {String} The corresponding CSS property name: border-bottom-color
|
|
|
|
*/
|
|
|
|
function getCssPropertyName(jsPropertyName) {
|
|
|
|
return jsPropertyName.replace(/[A-Z]/g, "-$&").toLowerCase();
|
|
|
|
}
|
2015-12-04 11:14:43 +00:00
|
|
|
exports.getCssPropertyName = getCssPropertyName;
|