Bug 1471814 - Add a preference for animation composite modes; r=bz,hiro

This feature should not be shipped until the various definitions of addition for
each additive property are properly specified.

Unlike other patches in this series, compositing is not frequently used
internally (e.g. by DevTools etc.) so there is no need to enable this by default
for system code.

Also, it turns out we have inadvertently been shipping part of this feature for
some time now. The next patch in this series will add tests for that case and
disable that part of the feature (a suitable intent to unship will follow). This
patch merely adapts and extends the existing tests without affecting the surface
area covered by the combination of the newly-added pref and the existing
dom.animations-api.core.enabled pref.

MozReview-Commit-ID: Htr6mlyCBav
This commit is contained in:
Brian Birtles
2018-07-14 09:23:03 +09:00
parent 9857d54b1c
commit e72222f013
16 changed files with 125 additions and 70 deletions

View File

@@ -21,6 +21,7 @@
#include "mozilla/LookAndFeel.h" // For LookAndFeel::GetInt
#include "mozilla/KeyframeUtils.h"
#include "mozilla/ServoBindings.h"
#include "mozilla/StaticPrefs.h"
#include "mozilla/TypeTraits.h"
#include "Layers.h" // For Layer
#include "nsComputedDOMStyle.h" // nsComputedDOMStyle::GetComputedStyle
@@ -28,7 +29,6 @@
#include "nsCSSPropertyIDSet.h"
#include "nsCSSProps.h" // For nsCSSProps::PropHasFlags
#include "nsCSSPseudoElements.h" // For CSSPseudoElementType
#include "nsDocument.h" // For nsDocument::IsWebAnimationsEnabled
#include "nsIFrame.h"
#include "nsIPresShell.h"
#include "nsIScriptError.h"
@@ -88,23 +88,15 @@ KeyframeEffect::WrapObject(JSContext* aCx,
return KeyframeEffect_Binding::Wrap(aCx, this, aGivenProto);
}
IterationCompositeOperation KeyframeEffect::IterationComposite(
CallerType /*aCallerType*/) const
IterationCompositeOperation KeyframeEffect::IterationComposite() const
{
return mEffectOptions.mIterationComposite;
}
void
KeyframeEffect::SetIterationComposite(
const IterationCompositeOperation& aIterationComposite,
CallerType aCallerType)
const IterationCompositeOperation& aIterationComposite)
{
// Ignore iterationComposite if the Web Animations API is not enabled,
// then the default value 'Replace' will be used.
if (!nsDocument::IsWebAnimationsEnabled(aCallerType)) {
return;
}
if (mEffectOptions.mIterationComposite == aIterationComposite) {
return;
}
@@ -597,9 +589,9 @@ KeyframeEffectParamsFromUnion(const OptionsType& aOptions,
{
KeyframeEffectParams result;
if (aOptions.IsUnrestrictedDouble() ||
// Ignore iterationComposite if the Web Animations API is not enabled,
// then the default value 'Replace' will be used.
!nsDocument::IsWebAnimationsEnabled(aCallerType)) {
// Ignore iterationComposite and composite if the corresponding pref is
// not set. The default value 'Replace' will be used instead.
!StaticPrefs::dom_animations_api_compositing_enabled()) {
return result;
}

View File

@@ -174,13 +174,9 @@ public:
void GetProperties(nsTArray<AnimationPropertyDetails>& aProperties,
ErrorResult& aRv) const;
// aCallerType is not used in the getter so we supply a default value so that
// internal users don't need to specify this value.
IterationCompositeOperation IterationComposite(
CallerType aCallerType = CallerType::System) const;
IterationCompositeOperation IterationComposite() const;
void SetIterationComposite(
const IterationCompositeOperation& aIterationComposite,
CallerType aCallerType);
const IterationCompositeOperation& aIterationComposite);
CompositeOperation Composite() const;
void SetComposite(const CompositeOperation& aComposite);

View File

@@ -1,4 +1,6 @@
[DEFAULT]
prefs =
dom.animations-api.compositing.enabled=true
support-files =
testcommon.js
../../imptests/testharness.js

View File

@@ -13,25 +13,25 @@ pref(dom.animations-api.timelines.enabled,true) load 1277272-1.html
load 1282691-1.html
pref(dom.animations-api.core.enabled,true) load 1291413-1.html
pref(dom.animations-api.core.enabled,true) load 1291413-2.html
pref(dom.animations-api.core.enabled,true) load 1304886-1.html
pref(dom.animations-api.compositing.enabled,true) load 1304886-1.html
pref(dom.animations-api.core.enabled,true) load 1309198-1.html
pref(dom.animations-api.implicit-keyframes.enabled,true) load 1322382-1.html
pref(dom.animations-api.core.enabled,true) pref(dom.animations-api.implicit-keyframes.enabled,true) load 1322291-1.html
pref(dom.animations-api.core.enabled,true) pref(dom.animations-api.implicit-keyframes.enabled,true) load 1322291-2.html
pref(dom.animations-api.core.enabled,true) pref(dom.animations-api.implicit-keyframes.enabled,true) load 1323114-1.html
pref(dom.animations-api.core.enabled,true) load 1323114-2.html
pref(dom.animations-api.implicit-keyframes.enabled,true) pref(dom.animations-api.compositing.enabled,true) load 1323114-1.html
pref(dom.animations-api.compositing.enabled,true) load 1323114-2.html
pref(dom.animations-api.implicit-keyframes.enabled,true) load 1323119-1.html
pref(dom.animations-api.implicit-keyframes.enabled,true) load 1324554-1.html
pref(dom.animations-api.core.enabled,true) pref(dom.animations-api.implicit-keyframes.enabled,true) load 1325193-1.html
pref(dom.animations-api.implicit-keyframes.enabled,true) pref(dom.animations-api.compositing.enabled,true) load 1325193-1.html
pref(dom.animations-api.implicit-keyframes.enabled,true) load 1330190-1.html
pref(dom.animations-api.core.enabled,true) pref(dom.animations-api.implicit-keyframes.enabled,true) load 1330190-2.html
pref(dom.animations-api.core.enabled,true) pref(dom.animations-api.implicit-keyframes.enabled,true) load 1330513-1.html
pref(dom.animations-api.core.enabled,true) pref(dom.animations-api.implicit-keyframes.enabled,true) pref(dom.animations-api.compositing.enabled,true) load 1330190-2.html
pref(dom.animations-api.implicit-keyframes.enabled,true) pref(dom.animations-api.compositing.enabled,true) load 1330513-1.html
pref(dom.animations-api.core.enabled,true) pref(dom.animations-api.timelines.enabled,true) load 1333539-1.html
pref(dom.animations-api.core.enabled,true) pref(dom.animations-api.timelines.enabled,true) load 1333539-2.html
load 1334582-1.html
load 1334582-2.html
load 1334583-1.html
pref(dom.animations-api.core.enabled,true) load 1335998-1.html
pref(dom.animations-api.core.enabled,true) pref(dom.animations-api.compositing.enabled,true) load 1335998-1.html
pref(dom.animations-api.core.enabled,true) load 1343589-1.html
pref(dom.animations-api.core.enabled,true) load 1359658-1.html
pref(dom.animations-api.implicit-keyframes.enabled,true) load 1373712-1.html

View File

@@ -1,5 +1,6 @@
[DEFAULT]
prefs =
dom.animations-api.compositing.enabled=true
dom.animations-api.core.enabled=true
dom.animations-api.implicit-keyframes.enabled=true
dom.animations-api.timelines.enabled=true
@@ -9,7 +10,7 @@ support-files =
chrome/file_animate_xrays.html
mozilla/xhr_doc.html
mozilla/file_deferred_start.html
mozilla/file_disable_animations_api_core.html
mozilla/file_disable_animations_api_compositing.html
mozilla/file_disable_animations_api_implicit_keyframes.html
mozilla/file_disable_animations_api_timelines.html
mozilla/file_discrete_animations.html
@@ -41,7 +42,7 @@ skip-if = (verify && !debug && (os == 'mac'))
[mozilla/test_cubic_bezier_limits.html]
[mozilla/test_deferred_start.html]
skip-if = (toolkit == 'android' && debug) || (os == 'win' && bits == 64) # Bug 1363957
[mozilla/test_disable_animations_api_core.html]
[mozilla/test_disable_animations_api_compositing.html]
[mozilla/test_disable_animations_api_implicit_keyframes.html]
[mozilla/test_disable_animations_api_timelines.html]
[mozilla/test_disabled_properties.html]

View File

@@ -0,0 +1,76 @@
<!doctype html>
<meta charset=utf-8>
<script src="../testcommon.js"></script>
<body>
<script>
'use strict';
test(t => {
const anim = addDiv(t).animate(
{ marginLeft: ['0px', '10px'] },
{
duration: 100 * MS_PER_SEC,
iterations: 10,
iterationComposite: 'accumulate',
composite: 'add',
}
);
assert_false(
'iterationComposite' in anim.effect,
'The KeyframeEffect.iterationComposite member is not present'
);
assert_false(
'composite' in anim.effect,
'The KeyframeEffect.composite member is not present'
);
}, 'The iterationComposite and composite members are not present on Animation'
+ ' when the compositing pref is disabled');
test(t => {
const div = addDiv(t);
const anim = div.animate(
{ marginLeft: ['0px', '10px'] },
{
duration: 100 * MS_PER_SEC,
iterations: 10,
iterationComposite: 'accumulate',
}
);
anim.pause();
anim.currentTime = 200 * MS_PER_SEC;
assert_equals(
getComputedStyle(div).marginLeft,
'0px',
'Animated style should NOT accumulate'
);
}, 'KeyframeEffectOptions.iterationComposite should be ignored if the'
+ ' compositing pref is disabled');
test(t => {
const div = addDiv(t);
const anim1 = div.animate(
{ marginLeft: ['0px', '100px'] },
{ duration: 100 * MS_PER_SEC }
);
anim1.pause();
anim1.currentTime = 50 * MS_PER_SEC;
const anim2 = div.animate(
{ marginLeft: ['0px', '100px'] },
{ duration: 100 * MS_PER_SEC, composite: 'add' }
);
anim2.pause();
anim2.currentTime = 50 * MS_PER_SEC;
assert_equals(
getComputedStyle(div).marginLeft,
'50px',
'Animations should NOT add together'
);
}, 'KeyframeEffectOptions.composite should be ignored if the'
+ ' compositing pref is disabled');
done();
</script>
</body>

View File

@@ -1,30 +0,0 @@
<!doctype html>
<meta charset=utf-8>
<script src="../testcommon.js"></script>
<body>
<script>
'use strict';
test(function(t) {
var div = addDiv(t);
var anim =
div.animate({ marginLeft: ['0px', '10px'] },
{ duration: 100 * MS_PER_SEC,
easing: 'linear',
iterations: 10,
iterationComposite: 'accumulate' });
anim.pause();
// NOTE: We can't check iterationComposite value itself though API since
// Animation.effect is also behind the the Web Animations API. So we just
// check that style value is not affected by iterationComposite.
anim.currentTime = 200 * MS_PER_SEC;
assert_equals(getComputedStyle(div).marginLeft, '0px',
'Animated style should not be accumulated when the Web Animations API is ' +
'not enabled even if accumulate is specified in the constructor');
}, 'iterationComposite should not affect at all if the Web Animations API ' +
'is not enabled');
done();
</script>
</body>

View File

@@ -7,8 +7,8 @@
'use strict';
setup({explicit_done: true});
SpecialPowers.pushPrefEnv(
{ "set": [["dom.animations-api.core.enabled", false]]},
{ "set": [["dom.animations-api.compositing.enabled", false]]},
function() {
window.open("file_disable_animations_api_core.html");
window.open("file_disable_animations_api_compositing.html");
});
</script>

View File

@@ -30,8 +30,9 @@ dictionary KeyframeEffectOptions : EffectTiming {
Constructor (KeyframeEffect source)]
interface KeyframeEffect : AnimationEffect {
attribute (Element or CSSPseudoElement)? target;
[NeedsCallerType]
[Pref="dom.animations-api.compositing.enabled"]
attribute IterationCompositeOperation iterationComposite;
[Pref="dom.animations-api.compositing.enabled"]
attribute CompositeOperation composite;
[Throws] sequence<object> getKeyframes ();
[Throws] void setKeyframes (object? keyframes);

View File

@@ -17,8 +17,8 @@ test-pref(dom.animations-api.core.enabled,true) == stacking-context-transform-ch
test-pref(dom.animations-api.core.enabled,true) == stacking-context-transform-changing-effect.html stacking-context-animation-ref.html
test-pref(dom.animations-api.core.enabled,true) == stacking-context-transform-changing-display-property.html stacking-context-animation-ref.html
== stacking-context-transform-losing-css-animation-in-delay.html stacking-context-animation-ref.html
test-pref(dom.animations-api.core.enabled,true) == style-updates-on-iteration-composition-changed-from-accumulate-to-replace.html style-updates-for-iteration-composite-ref.html
test-pref(dom.animations-api.core.enabled,true) == style-updates-on-iteration-composition-changed-from-replace-to-accumulate.html style-updates-for-iteration-composite-ref.html
test-pref(dom.animations-api.core.enabled,true) == style-updates-on-current-iteration-changed.html style-updates-for-iteration-composite-ref.html
test-pref(dom.animations-api.core.enabled,true) test-pref(dom.animations-api.compositing.enabled,true) == style-updates-on-iteration-composition-changed-from-accumulate-to-replace.html style-updates-for-iteration-composite-ref.html
test-pref(dom.animations-api.core.enabled,true) test-pref(dom.animations-api.compositing.enabled,true) == style-updates-on-iteration-composition-changed-from-replace-to-accumulate.html style-updates-for-iteration-composite-ref.html
test-pref(dom.animations-api.core.enabled,true) test-pref(dom.animations-api.compositing.enabled,true) == style-updates-on-current-iteration-changed.html style-updates-for-iteration-composite-ref.html
test-pref(dom.animations-api.core.enabled,true) == cancel-animation-with-selector-matching.html about:blank
== child-in-animating-element-display-none.html child-in-animating-element-display-none-ref.html

View File

@@ -195,7 +195,7 @@ load 1381420-1.html
load 1381682.html
load 1382672.html
load 1382710.html
pref(dom.animations-api.core.enabled,true) pref(dom.animations-api.implicit-keyframes.enabled,true) load 1383493-1.html
pref(dom.animations-api.compositing.enabled,true) pref(dom.animations-api.implicit-keyframes.enabled,true) load 1383493-1.html
load 1383001.html
load 1383001-2.html
load 1383319.html
@@ -226,7 +226,7 @@ load 1393791.html
load 1384232.html
load 1395725.html
load 1396041.html
pref(dom.animations-api.implicit-keyframes.enabled,true) load 1397363-1.html
pref(dom.animations-api.implicit-keyframes.enabled,true) pref(dom.animations-api.compositing.enabled,true) load 1397363-1.html
load 1397439-1.html
load 1395719.html
load 1397091.html

View File

@@ -1,5 +1,6 @@
[DEFAULT]
prefs =
dom.animations-api.compositing.enabled=true
dom.animations-api.core.enabled=true
dom.animations-api.implicit-keyframes.enabled=true
dom.animations-api.timelines.enabled=true

View File

@@ -91,6 +91,19 @@ VARCACHE_PREF(
// DOM prefs
//---------------------------------------------------------------------------
// Is support for composite operations from the Web Animations API enabled?
#ifdef RELEASE_OR_BETA
# define PREF_VALUE false
#else
# define PREF_VALUE true
#endif
VARCACHE_PREF(
"dom.animations-api.compositing.enabled",
dom_animations_api_compositing_enabled,
bool, PREF_VALUE
)
#undef PREF_VALUE
// Is support for animations from the Web Animations API without 0%/100%
// keyframes enabled?
#ifdef RELEASE_OR_BETA

View File

@@ -1,3 +1,4 @@
prefs: [dom.animations-api.core.enabled:true,
prefs: [dom.animations-api.compositing.enabled:true,
dom.animations-api.core.enabled:true,
dom.animations-api.implicit-keyframes.enabled:true,
dom.animations-api.timelines.enabled:true]

View File

@@ -1,3 +1,4 @@
prefs: [dom.animations-api.core.enabled:true,
prefs: [dom.animations-api.compositing.enabled:true,
dom.animations-api.core.enabled:true,
dom.animations-api.implicit-keyframes.enabled:true,
dom.animations-api.timelines.enabled:true]

View File

@@ -1,4 +1,5 @@
prefs: [dom.animations-api.core.enabled:true,
prefs: [dom.animations-api.compositing.enabled:true,
dom.animations-api.core.enabled:true,
dom.animations-api.implicit-keyframes.enabled:true,
dom.animations-api.timelines.enabled:true,
layout.css.frames-timing.enabled:true]