Bug 1340322 - Part 5: Split off BuildKeyframes() r?birtles
ServoCSSAnimationBuilder will also have the same name method.
MozReview-Commit-ID: CySTBGuTZn7
--- a/layout/style/nsAnimationManager.cpp
+++ b/layout/style/nsAnimationManager.cpp
@@ -472,20 +472,23 @@ public:
const NonOwningAnimationTarget& aTarget)
: mStyleContext(aStyleContext)
, mTarget(aTarget)
{
MOZ_ASSERT(aStyleContext);
MOZ_ASSERT(aTarget.mElement);
}
+ bool BuildKeyframes(nsPresContext* aPresContext,
+ const StyleAnimation& aSrc,
+ nsTArray<Keyframe>& aKeyframs);
+private:
nsTArray<Keyframe> BuildAnimationFrames(nsPresContext* aPresContext,
const StyleAnimation& aSrc,
const nsCSSKeyframesRule* aRule);
-private:
Maybe<ComputedTimingFunction> GetKeyframeTimingFunction(
nsPresContext* aPresContext,
nsCSSKeyframeRule* aKeyframeRule,
const Maybe<ComputedTimingFunction>& aInheritedTimingFunction);
nsTArray<PropertyValuePair> GetKeyframePropertyValues(
nsPresContext* aPresContext,
nsCSSKeyframeRule* aKeyframeRule,
nsCSSPropertyIDSet& aAnimatedProperties);
@@ -521,36 +524,18 @@ BuildAnimation(nsPresContext* aPresConte
const NonOwningAnimationTarget& aTarget,
const StyleAnimation& aSrc,
CSSAnimationBuilder& aBuilder,
nsAnimationManager::CSSAnimationCollection* aCollection)
{
MOZ_ASSERT(aPresContext);
nsTArray<Keyframe> keyframes;
- if (aPresContext->StyleSet()->IsServo()) {
- ServoStyleSet* styleSet = aPresContext->StyleSet()->AsServo();
- MOZ_ASSERT(styleSet);
- const ServoComputedValues* computedValues =
- aStyleContext->StyleSource().AsServoComputedValues();
- const nsTimingFunction& timingFunction = aSrc.GetTimingFunction();
- if (!styleSet->FillKeyframesForName(aSrc.GetName(),
- timingFunction,
- computedValues,
- keyframes)) {
- return nullptr;
- }
- } else {
- nsCSSKeyframesRule* rule =
- aPresContext->StyleSet()->AsGecko()->KeyframesRuleForName(aSrc.GetName());
- if (!rule) {
- return nullptr;
- }
-
- keyframes = aBuilder.BuildAnimationFrames(aPresContext, aSrc, rule);
+ if (!aBuilder.BuildKeyframes(aPresContext, aSrc, keyframes)) {
+ return nullptr;
}
TimingParams timing = TimingParamsFromCSSParams(aSrc.GetDuration(),
aSrc.GetDelay(),
aSrc.GetIterationCount(),
aSrc.GetDirection(),
aSrc.GetFillMode());
@@ -602,16 +587,47 @@ BuildAnimation(nsPresContext* aPresConte
animation->PauseFromStyle();
} else {
animation->PlayFromStyle();
}
return animation.forget();
}
+bool
+CSSAnimationBuilder::BuildKeyframes(nsPresContext* aPresContext,
+ const StyleAnimation& aSrc,
+ nsTArray<Keyframe>& aKeyframes)
+{
+ MOZ_ASSERT(aPresContext);
+
+ if (aPresContext->StyleSet()->IsServo()) {
+ ServoStyleSet* styleSet = aPresContext->StyleSet()->AsServo();
+ MOZ_ASSERT(styleSet);
+ const ServoComputedValues* computedValues =
+ mStyleContext->StyleSource().AsServoComputedValues();
+ const nsTimingFunction& timingFunction = aSrc.GetTimingFunction();
+ if (!styleSet->FillKeyframesForName(aSrc.GetName(),
+ timingFunction,
+ computedValues,
+ aKeyframes)) {
+ return false;
+ }
+ } else {
+ nsCSSKeyframesRule* rule =
+ aPresContext->StyleSet()->AsGecko()->KeyframesRuleForName(aSrc.GetName());
+ if (!rule) {
+ return false;
+ }
+ aKeyframes = BuildAnimationFrames(aPresContext, aSrc, rule);
+ }
+
+ return true;
+}
+
nsTArray<Keyframe>
CSSAnimationBuilder::BuildAnimationFrames(nsPresContext* aPresContext,
const StyleAnimation& aSrc,
const nsCSSKeyframesRule* aRule)
{
// Ideally we'd like to build up a set of Keyframe objects that more-or-less
// reflect the keyframes as-specified in the @keyframes rule(s) so that
// authors get something intuitive when they call anim.effect.getKeyframes().