Files
palemoon27/devtools/client/animationinspector/animation-controller.js
T
roytam1 ff0033e97d import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1231975 - Part 3: Break a reference cycle between PendingResolution and DNSRequestChild. r=drno (ecf45de535)
- Bug 1231975 - Part 4: Add some logging and simplification in TestNrSocket. r=drno (fa811f7743)
- Bug 1231975 - Part 5: Fix an intermittent failure caused by the NAT simulator erroneously canceling NR_ASYNC_WAIT_READ. r=drno (e436a8cc75)
- var-let (d228288673)
- Bug 1256022 - dom/network slow GC on mochitest fix r=dragana (e0dffd5033)
- Bug 1231130 - added mHadLocalInstance to constructor.r=jaas (c4f6d0c530)
- Bug 1121290: Use "%ls" instead of "%s" in _snwprintf_s format string# r=bsmedberg (e0434aca5a)
- Bug 1206952 - Rename MagicRequest to ByteRangeRequest. r=sicking (6780309aa2)
- Bug 1206952 - Convert PluginStreamListener to use channel->AsyncOpen2(). r=sicking (8f41f3e148)
- Bug 1262335 - Part 2. Remove Android GB/HC defines from OMX. r=snorp (e5b7435d92)
- Bug 956899 - Add a std::condition_variable work-alike; r=froydnj (98076c707e)
- Bug 1254123 - Handle OOM more gracefully in js::ErrorToException. (r=Waldo) (f9a2ef18d1)
- Bug 1255128 - Standard argument coercion in new ArrayBuffer(length). r=nbp. Thanks to snowmantw for tests. (06e5cedd80)
- Bug 1251919 - Nuke Debugger wrappers on failure. (r=shu) (64bc41b1f1)
- Bug 1254190 - Propagate failure of matchAllDebuggeeGlobals() in Debugger. (r=shu) (927bf01ec5)
- Bug 1254172 - Make UnboxedLayout::makeNativeGroup robust to unknownProperties on unboxed type. (r=jandem) (398a6b3aa7)
- Bug 1268213 - BlobImplFile::GetTypeRunnable can be a WorkerMainThreadRunnable, r=khuey (30e4ff4b75)
- Bug 1250523 - Wait for the markup-view to be loaded in browser_markup_load_01.js; r=gl (acf9e9d88b)
- Bug 1230325 - markup-view: skip keyboard shortcuts if any modifier;r=pbrosset (ab974dfac7)
- Bug 1155465 - part1: layout-view: use content-type CSS_VALUE for editors;r=miker (d21e70b811)
- Bug 1155465 - part2: inplace-editor: disable increment on up/down for PLAIN_TEXT;r=miker (5d72e05f63)
- Bug 1241126 - ruleview property: open editor for prop. name on click on ":";r=gl (4889010c34)
- Bug 1128340 - Allow renaming with non-ASCII characters in WebIDE. r=jryans (f9844e3afb)
- Bug 1039482 - Properly position and style the file name edit field in the projecteditor. r=bgrins (4c29b80958)
- Bug 1268231 - Get rid of StopSyncLoopRunnable, r=khuey (29b0a0ed4f)
- Bug 1267904 - Add telemetry for WorkerMainThreadRunnable, r=khuey (970d39bcce)
- Bug 1261317 - part1: inplace-editor: small refactor of keypress event handler;r=pbro (5261bca85a)
- Bug 1261317 - part2: prevent autocomplete on arrow keys in multiline editor;r=pbro (859738623a)
- Bug 1246677 - 1 - Make waitForSuccess work with async functions; r=miker (3927347635)
- Bug 1227810 - split browser_ruleview_authored.js into three tests; r=pbrosset (f6e4760908)
- Bug 1246677 - 2 - Stop using CPOWs in simulateColorPickerChange; r=miker (69a31024cf)
- Bug 1246677 - 3 - Remove all usages of getNode in ruleview tests; r=tromey (2f25bec099)
- Bug 1240813 - Fixed the unhandled promise rejections in browser_rules_colorpicker-* tests; r=ochameau (bd534ec71b)
- Bug 1217328 - let filter editor work on invalid values. r=pbrosset (91602cac94)
- Bug 1225236 - Removed the 360 value limit for the hue-rotate field in the CSS filter popup. r=pbro (9bceb9947d)
- Bug 1223076 - make FilterWidget handle "unset", "initial", and "inherit". r=pbrosset (6542d5cc99)
- Bug 1221156 - make FilterWidget try to preserve URL quoting; r=pbrosset (3e1105c3d5)
- Bug 1226543 - fix URL quoting in CSSFilterEditorWidget.getValueAt. r=pbrosset (1770cc279a)
- Bug 1241527 - 1 - Fix some unhandled rejected promises in colorpicker, cubicbezier and cssfilter ruleview tests; r=gl (059df355be)
- Bug 1241527 - 2 - Use ruleview-changed event to avoid pending requests when browser_rules_search-filter* tests end; r=gl (407d5866b0)
- Bug 1241527 - 3 - Fix typo in hideTooltipAndWaitForRuleviewChanged; r=gl (964270c8c3)
- Bug 1241527 - 4 - Use ruleview-changed event to avoid pending requests in browser_rules_multiple* tests; r=gl (2947abf296)
- Bug 1241527 - 5 - Use ruleview-changed event to fix remaining pending requests in tests; r=gl (5391857e12)
- Bug 1246677 - 4 - Stop using content.getComputedStyle in ruleview tests; r=miker (f61cd8d5aa)
- Bug 1237885 - fix add-rules_01 intermittent by splitting in two tests;r=gl (45e4de6012)
- Bug 1166956 - add valid unit when incrementing CSS value "0";r=tromey (40ca31b909)
- Bug 1241155 - correctly use indexOf in browser_rules_user-agent-styles.js; r=bgrins (0966d23f7e)
- Bug 1229911 - recognize DevToolsUtils.defineLazyGetter and defineLazyModuleGetter. r=miker (876e4b9f3b)
- Bug 1230093 - Make the import-headjs-globals rule store variables correctly; r=Mossop (be3ddcb7fb)
- Bug 1229224: Support more forms of defining globals and make anywhere we import scripts use them too. r=miker (c9a243fcae)
- Bug 1231963 - handle top-level "this.mumble" assignments in eslint; r=mikeratcliffe (be07835449)
- Bug 1224289 - add eslint rule to reject Cu.importGlobalProperties; r=mikeratcliffe (eac54ddcce)
- Bug 1241544 - add documentation for this-top-level-scope eslint rule; r=mikeratcliffe (9d832af29d)
- Bug 1239426 - handle arrow functions in getASTSource; r=mikeratcliffe (889b5ff89c)
- Bug 1242584 - Remove dead code in import-headjs-globals. r=tromey (e7b07c59b3)
- Bug 1229224: Support more forms of defining globals and make anywhere we import scripts use them too. r=miker (cf4a3d4d48)
- Bug 1242584 - import-globals-from should carry over to tests. r=tromey (f1f7d7269a)
- Bug 1224735 - only emit one error per possible CPOW use; r=miker,Ms2ger (621dba76e1)
- Bug 1245916: Unify eslint global discovery rules. r=pbrosset (e80d38e097)
- Bug 1246677 - 7 - Clean remaining ruleview and tests eslint warnings; r=jdescottes (9415147b5b)
- Bug 1246677 - 5 - Get rid of 'content' in ruleview test files; r=jdescottes (d868fde632)
- Bug 1209295 - Ensure browser_rules_add-property-cancel_02.js waits for the correct change notification. r=pbrosset (4099437554)
- Bug 1240778 - Fixed the unhandled promise rejection in browser_rules_add-property_01.js; r=ochameau (838bd1f99c)
- Bug 1246677 - 8 - Use addProperty and remove code duplication; r=gl (2c33059028)
- Bug 1246677 - 9 - Get rid of all remaining _applyingModifications usage in tests; r=ochameau (a9bc3b2495)
- Bug 1143742 - part1: multiline inplace editor: cleanup existing tests;r=gl (2bc96e58d3)
- Bug 1243695 - ensure caret is visible in ruleview prop editor;r=miker (3353a5a77c)
- Bug 1143742 - part2: multiline inplace-editor should support a maxWidth option;r=gl (98809c04cb)
- Bug 1178462 - Cancel inplace editor autocomplete on window blur;r=gl (c4af4c03d2)
- Bug 1261827 - inplace-editor: copyTextStyles should not copy line-height property;r=pbro (1fc8d7d432)
- Bug 1069829 - 1 - Remove a usage of domUtils.cssPropertyIsValid in inplace-editor; r=tromey (7898eed84b)
- Bug 1143742 - part3: multiline inplace-editor autocomplete behavior;r=gl (53b369dccb)
- Bug 1143742 - part4: add textarea to valid targets when copying;r=gl (84af495716)
- Bug 1143742 - part5: fix eslint error in inspector ruleview test;r=bustage (d7a53a6217)
- Bug 1249888 - try/catch SourceMapConsumer to avoid empty rule-view when source map is invalid; r=gl (c78a7a6ac7)
- Bug 1255787 - Do not assume sourceMap appears only in external stylesheets; r=gl (7c69e1e559)
- Bug 1029459 - remove output-parser iteration limit. r=pbrosset (f2438a8642)
- Bug 1250835 - Display swatch for angles in the rules panel. r=miker (87721e80f2)
- Bug 1259777 - Remove unnecessary DOMUtils lazy load in css-angle.js . r=pbro (e199a014d5)
- Bug 1259559 - Units cycling with shift+click persists value in Style editor. r=miker (b7074813e9)
- Bug 1245996 - inspector: fix xul scrollbars stealing focus;r=pbro (bcb19ffa83)
- Bug 1180349 - Increase the timeout for browser_markupview_links_01.js (b67cd0d2be)
- Bug 1253935 - Remove all CPOW usages in styleeditor tests and use ContentTask instead of custom frame-script; r=ochameau (485308e7b1)
- Bug 1257246: Update devtools for eslint 2. r=pbro (c04f7f3046)
- Bug 1264968 part 2 - Allow persisting attributes of xul:window if its owner document is not root. r=enndeakin (ca8182b534)
- Bug 1244948 - silence the 'loaded script twice' warning. r=bz (fa571b837c)
2024-08-30 20:58:51 +08:00

387 lines
13 KiB
JavaScript

/* -*- 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/. */
/* animation-panel.js is loaded in the same scope but we don't use
import-globals-from to avoid infinite loops since animation-panel.js already
imports globals from animation-controller.js */
/* globals AnimationsPanel */
/* eslint no-unused-vars: [2, {"vars": "local", "args": "none"}] */
"use strict";
var { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
Cu.import("resource://gre/modules/Task.jsm");
var { loader, require } = Cu.import("resource://devtools/shared/Loader.jsm");
Cu.import("resource://gre/modules/Console.jsm");
Cu.import("resource://devtools/client/shared/widgets/ViewHelpers.jsm");
loader.lazyRequireGetter(this, "promise");
loader.lazyRequireGetter(this, "EventEmitter", "devtools/shared/event-emitter");
loader.lazyRequireGetter(this, "AnimationsFront", "devtools/server/actors/animation", true);
const { LocalizationHelper } = require("devtools/client/shared/l10n");
const STRINGS_URI = "chrome://devtools/locale/animationinspector.properties";
const L10N = new LocalizationHelper(STRINGS_URI);
// Global toolbox/inspector, set when startup is called.
var gToolbox, gInspector;
/**
* Startup the animationinspector controller and view, called by the sidebar
* widget when loading/unloading the iframe into the tab.
*/
var startup = Task.async(function* (inspector) {
gInspector = inspector;
gToolbox = inspector.toolbox;
// Don't assume that AnimationsPanel is defined here, it's in another file.
if (!typeof AnimationsPanel === "undefined") {
throw new Error("AnimationsPanel was not loaded in the " +
"animationinspector window");
}
// Startup first initalizes the controller and then the panel, in sequence.
// If you want to know when everything's ready, do:
// AnimationsPanel.once(AnimationsPanel.PANEL_INITIALIZED)
yield AnimationsController.initialize();
yield AnimationsPanel.initialize();
});
/**
* Shutdown the animationinspector controller and view, called by the sidebar
* widget when loading/unloading the iframe into the tab.
*/
var shutdown = Task.async(function* () {
yield AnimationsController.destroy();
// Don't assume that AnimationsPanel is defined here, it's in another file.
if (typeof AnimationsPanel !== "undefined") {
yield AnimationsPanel.destroy();
}
gToolbox = gInspector = null;
});
// This is what makes the sidebar widget able to load/unload the panel.
function setPanel(panel) {
return startup(panel).catch(e => console.error(e));
}
function destroy() {
return shutdown().catch(e => console.error(e));
}
/**
* Get all the server-side capabilities (traits) so the UI knows whether or not
* features should be enabled/disabled.
* @param {Target} target The current toolbox target.
* @return {Object} An object with boolean properties.
*/
var getServerTraits = Task.async(function* (target) {
let config = [
{ name: "hasToggleAll", actor: "animations",
method: "toggleAll" },
{ name: "hasToggleSeveral", actor: "animations",
method: "toggleSeveral" },
{ name: "hasSetCurrentTime", actor: "animationplayer",
method: "setCurrentTime" },
{ name: "hasMutationEvents", actor: "animations",
method: "stopAnimationPlayerUpdates" },
{ name: "hasSetPlaybackRate", actor: "animationplayer",
method: "setPlaybackRate" },
{ name: "hasSetPlaybackRates", actor: "animations",
method: "setPlaybackRates" },
{ name: "hasTargetNode", actor: "domwalker",
method: "getNodeFromActor" },
{ name: "hasSetCurrentTimes", actor: "animations",
method: "setCurrentTimes" },
{ name: "hasGetFrames", actor: "animationplayer",
method: "getFrames" },
{ name: "hasGetProperties", actor: "animationplayer",
method: "getProperties" },
{ name: "hasSetWalkerActor", actor: "animations",
method: "setWalkerActor" },
];
let traits = {};
for (let {name, actor, method} of config) {
traits[name] = yield target.actorHasMethod(actor, method);
}
return traits;
});
/**
* The animationinspector controller's job is to retrieve AnimationPlayerFronts
* from the server. It is also responsible for keeping the list of players up to
* date when the node selection changes in the inspector, as well as making sure
* no updates are done when the animationinspector sidebar panel is not visible.
*
* AnimationPlayerFronts are available in AnimationsController.animationPlayers.
*
* Usage example:
*
* AnimationsController.on(AnimationsController.PLAYERS_UPDATED_EVENT,
* onPlayers);
* function onPlayers() {
* for (let player of AnimationsController.animationPlayers) {
* // do something with player
* }
* }
*/
var AnimationsController = {
PLAYERS_UPDATED_EVENT: "players-updated",
ALL_ANIMATIONS_TOGGLED_EVENT: "all-animations-toggled",
initialize: Task.async(function* () {
if (this.initialized) {
yield this.initialized.promise;
return;
}
this.initialized = promise.defer();
this.onPanelVisibilityChange = this.onPanelVisibilityChange.bind(this);
this.onNewNodeFront = this.onNewNodeFront.bind(this);
this.onAnimationMutations = this.onAnimationMutations.bind(this);
let target = gToolbox.target;
this.animationsFront = new AnimationsFront(target.client, target.form);
// Expose actor capabilities.
this.traits = yield getServerTraits(target);
if (this.destroyed) {
console.warn("Could not fully initialize the AnimationsController");
return;
}
// Let the AnimationsActor know what WalkerActor we're using. This will
// come in handy later to return references to DOM Nodes.
if (this.traits.hasSetWalkerActor) {
yield this.animationsFront.setWalkerActor(gInspector.walker);
}
this.startListeners();
yield this.onNewNodeFront();
this.initialized.resolve();
}),
destroy: Task.async(function* () {
if (!this.initialized) {
return;
}
if (this.destroyed) {
yield this.destroyed.promise;
return;
}
this.destroyed = promise.defer();
this.stopListeners();
this.destroyAnimationPlayers();
this.nodeFront = null;
if (this.animationsFront) {
this.animationsFront.destroy();
this.animationsFront = null;
}
this.destroyed.resolve();
}),
startListeners: function() {
// Re-create the list of players when a new node is selected, except if the
// sidebar isn't visible.
gInspector.selection.on("new-node-front", this.onNewNodeFront);
gInspector.sidebar.on("select", this.onPanelVisibilityChange);
gToolbox.on("select", this.onPanelVisibilityChange);
},
stopListeners: function() {
gInspector.selection.off("new-node-front", this.onNewNodeFront);
gInspector.sidebar.off("select", this.onPanelVisibilityChange);
gToolbox.off("select", this.onPanelVisibilityChange);
if (this.isListeningToMutations) {
this.animationsFront.off("mutations", this.onAnimationMutations);
}
},
isPanelVisible: function() {
return gToolbox.currentToolId === "inspector" &&
gInspector.sidebar &&
gInspector.sidebar.getCurrentTabID() == "animationinspector";
},
onPanelVisibilityChange: Task.async(function* () {
if (this.isPanelVisible()) {
this.onNewNodeFront();
}
}),
onNewNodeFront: Task.async(function* () {
// Ignore if the panel isn't visible or the node selection hasn't changed.
if (!this.isPanelVisible() ||
this.nodeFront === gInspector.selection.nodeFront) {
return;
}
this.nodeFront = gInspector.selection.nodeFront;
let done = gInspector.updating("animationscontroller");
if (!gInspector.selection.isConnected() ||
!gInspector.selection.isElementNode()) {
this.destroyAnimationPlayers();
this.emit(this.PLAYERS_UPDATED_EVENT);
done();
return;
}
yield this.refreshAnimationPlayers(this.nodeFront);
this.emit(this.PLAYERS_UPDATED_EVENT, this.animationPlayers);
done();
}),
/**
* Toggle (pause/play) all animations in the current target.
*/
toggleAll: function() {
if (!this.traits.hasToggleAll) {
return promise.resolve();
}
return this.animationsFront.toggleAll()
.then(() => this.emit(this.ALL_ANIMATIONS_TOGGLED_EVENT, this))
.catch(e => console.error(e));
},
/**
* Similar to toggleAll except that it only plays/pauses the currently known
* animations (those listed in this.animationPlayers).
* @param {Boolean} shouldPause True if the animations should be paused, false
* if they should be played.
* @return {Promise} Resolves when the playState has been changed.
*/
toggleCurrentAnimations: Task.async(function* (shouldPause) {
if (this.traits.hasToggleSeveral) {
yield this.animationsFront.toggleSeveral(this.animationPlayers,
shouldPause);
} else {
// Fall back to pausing/playing the players one by one, which is bound to
// introduce some de-synchronization.
for (let player of this.animationPlayers) {
if (shouldPause) {
yield player.pause();
} else {
yield player.play();
}
}
}
}),
/**
* Set all known animations' currentTimes to the provided time.
* @param {Number} time.
* @param {Boolean} shouldPause Should the animations be paused too.
* @return {Promise} Resolves when the current time has been set.
*/
setCurrentTimeAll: Task.async(function* (time, shouldPause) {
if (this.traits.hasSetCurrentTimes) {
yield this.animationsFront.setCurrentTimes(this.animationPlayers, time,
shouldPause);
} else {
// Fall back to pausing and setting the current time on each player, one
// by one, which is bound to introduce some de-synchronization.
for (let animation of this.animationPlayers) {
if (shouldPause) {
yield animation.pause();
}
yield animation.setCurrentTime(time);
}
}
}),
/**
* Set all known animations' playback rates to the provided rate.
* @param {Number} rate.
* @return {Promise} Resolves when the rate has been set.
*/
setPlaybackRateAll: Task.async(function* (rate) {
if (this.traits.hasSetPlaybackRates) {
// If the backend can set all playback rates at the same time, use that.
yield this.animationsFront.setPlaybackRates(this.animationPlayers, rate);
} else if (this.traits.hasSetPlaybackRate) {
// Otherwise, fall back to setting each rate individually.
for (let animation of this.animationPlayers) {
yield animation.setPlaybackRate(rate);
}
}
}),
// AnimationPlayerFront objects are managed by this controller. They are
// retrieved when refreshAnimationPlayers is called, stored in the
// animationPlayers array, and destroyed when refreshAnimationPlayers is
// called again.
animationPlayers: [],
refreshAnimationPlayers: Task.async(function* (nodeFront) {
this.destroyAnimationPlayers();
this.animationPlayers = yield this.animationsFront
.getAnimationPlayersForNode(nodeFront);
// Start listening for animation mutations only after the first method call
// otherwise events won't be sent.
if (!this.isListeningToMutations && this.traits.hasMutationEvents) {
this.animationsFront.on("mutations", this.onAnimationMutations);
this.isListeningToMutations = true;
}
}),
onAnimationMutations: function(changes) {
// Insert new players into this.animationPlayers when new animations are
// added.
for (let {type, player} of changes) {
if (type === "added") {
this.animationPlayers.push(player);
}
if (type === "removed") {
let index = this.animationPlayers.indexOf(player);
this.animationPlayers.splice(index, 1);
}
}
// Let the UI know the list has been updated.
this.emit(this.PLAYERS_UPDATED_EVENT, this.animationPlayers);
},
/**
* Get the latest known current time of document.timeline.
* This value is sent along with all AnimationPlayerActors' states, but it
* isn't updated after that, so this function loops over all know animations
* to find the highest value.
* @return {Number|Boolean} False is returned if this server version doesn't
* provide document's current time.
*/
get documentCurrentTime() {
let time = 0;
for (let {state} of this.animationPlayers) {
if (!state.documentCurrentTime) {
return false;
}
time = Math.max(time, state.documentCurrentTime);
}
return time;
},
destroyAnimationPlayers: function() {
this.animationPlayers = [];
}
};
EventEmitter.decorate(AnimationsController);