Bug 1471814 - Ignore the composite member on Keyframe objects when the compositing pref is not set; r=hiro

MozReview-Commit-ID: 9Xn32jLlpq1

--HG--
extra : rebase_source : cbc6d4a972295174e26629845497e22fe1a80aa1
This commit is contained in:
Brian Birtles 2018-07-14 09:23:03 +09:00
parent 382fd2fe39
commit 35fffc8314
2 changed files with 69 additions and 20 deletions

View File

@ -451,7 +451,8 @@ ConvertKeyframeSequence(JSContext* aCx,
keyframe->mOffset.emplace(keyframeDict.mOffset.Value());
}
if (!keyframeDict.mComposite.IsNull()) {
if (StaticPrefs::dom_animations_api_compositing_enabled() &&
!keyframeDict.mComposite.IsNull()) {
keyframe->mComposite.emplace(keyframeDict.mComposite.Value());
}
@ -1186,26 +1187,28 @@ GetKeyframeListFromPropertyIndexedKeyframe(JSContext* aCx,
//
// This corresponds to step 5, "Otherwise," branch, substep 12 of
// https://drafts.csswg.org/web-animations/#processing-a-keyframes-argument
const FallibleTArray<Nullable<dom::CompositeOperation>>* compositeOps =
nullptr;
AutoTArray<Nullable<dom::CompositeOperation>, 1> singleCompositeOp;
auto& composite = keyframeDict.mComposite;
if (composite.IsCompositeOperation()) {
singleCompositeOp.AppendElement(composite.GetAsCompositeOperation());
const FallibleTArray<Nullable<dom::CompositeOperation>>& asFallibleArray =
singleCompositeOp;
compositeOps = &asFallibleArray;
} else if (composite.IsCompositeOperationOrNullSequence()) {
compositeOps = &composite.GetAsCompositeOperationOrNullSequence();
}
if (StaticPrefs::dom_animations_api_compositing_enabled()) {
const FallibleTArray<Nullable<dom::CompositeOperation>>* compositeOps =
nullptr;
AutoTArray<Nullable<dom::CompositeOperation>, 1> singleCompositeOp;
auto& composite = keyframeDict.mComposite;
if (composite.IsCompositeOperation()) {
singleCompositeOp.AppendElement(composite.GetAsCompositeOperation());
const FallibleTArray<Nullable<dom::CompositeOperation>>& asFallibleArray =
singleCompositeOp;
compositeOps = &asFallibleArray;
} else if (composite.IsCompositeOperationOrNullSequence()) {
compositeOps = &composite.GetAsCompositeOperationOrNullSequence();
}
// Fill in and repeat as needed.
if (compositeOps && !compositeOps->IsEmpty()) {
size_t length = compositeOps->Length();
for (size_t i = 0; i < aResult.Length(); i++) {
if (!compositeOps->ElementAt(i % length).IsNull()) {
aResult[i].mComposite.emplace(
compositeOps->ElementAt(i % length).Value());
// Fill in and repeat as needed.
if (compositeOps && !compositeOps->IsEmpty()) {
size_t length = compositeOps->Length();
for (size_t i = 0; i < aResult.Length(); i++) {
if (!compositeOps->ElementAt(i % length).IsNull()) {
aResult[i].mComposite.emplace(
compositeOps->ElementAt(i % length).Value());
}
}
}
}

View File

@ -71,6 +71,52 @@ test(t => {
}, 'KeyframeEffectOptions.composite should be ignored if the'
+ ' compositing pref is disabled');
test(t => {
const div = addDiv(t);
const anim1 = div.animate({ marginLeft: ['0px', '100px'] }, 100 * MS_PER_SEC);
anim1.pause();
anim1.currentTime = 50 * MS_PER_SEC;
const anim2 = div.animate(
[
{ marginLeft: '0px', composite: 'add' },
{ marginLeft: '100px', composite: 'add' },
],
100 * MS_PER_SEC
);
anim2.pause();
anim2.currentTime = 50 * MS_PER_SEC;
assert_equals(
getComputedStyle(div).marginLeft,
'50px',
'Animations should NOT add together'
);
}, 'composite member is ignored on keyframes when using array notation');
test(t => {
const div = addDiv(t);
const anim1 = div.animate(
{ marginLeft: ['0px', '100px'] },
100 * MS_PER_SEC
);
anim1.pause();
anim1.currentTime = 50 * MS_PER_SEC;
const anim2 = div.animate(
{ marginLeft: ['0px', '100px'], composite: ['add', 'add'] },
100 * MS_PER_SEC
);
anim2.pause();
anim2.currentTime = 50 * MS_PER_SEC;
assert_equals(
getComputedStyle(div).marginLeft,
'50px',
'Animations should NOT add together'
);
}, 'composite member is ignored on keyframes when using object notation');
done();
</script>
</body>