Bug 1216842 - Part 5: Store ComputedTimingFunction in TimingParams. r=cam

The reason why we use Maybe<> to store the function is that CSS
animations/transitions do not have the function property.
This commit is contained in:
Hiroyuki Ikezoe 2016-01-29 14:45:00 +01:00
Родитель 03409db313
Коммит c3619f4a48
4 изменённых файлов: 33 добавлений и 12 удалений

Просмотреть файл

@ -12,13 +12,15 @@
namespace mozilla {
TimingParams::TimingParams(const dom::AnimationEffectTimingProperties& aRhs)
TimingParams::TimingParams(const dom::AnimationEffectTimingProperties& aRhs,
const dom::Element* aTarget)
: mDuration(aRhs.mDuration)
, mDelay(TimeDuration::FromMilliseconds(aRhs.mDelay))
, mIterations(aRhs.mIterations)
, mDirection(aRhs.mDirection)
, mFill(aRhs.mFill)
{
mFunction = AnimationUtils::ParseEasing(aTarget, aRhs.mEasing);
}
TimingParams::TimingParams(double aDuration)
@ -28,25 +30,27 @@ TimingParams::TimingParams(double aDuration)
/* static */ TimingParams
TimingParams::FromOptionsUnion(
const dom::UnrestrictedDoubleOrKeyframeEffectOptions& aOptions)
const dom::UnrestrictedDoubleOrKeyframeEffectOptions& aOptions,
const dom::Element* aTarget)
{
if (aOptions.IsUnrestrictedDouble()) {
return TimingParams(aOptions.GetAsUnrestrictedDouble());
} else {
MOZ_ASSERT(aOptions.IsKeyframeEffectOptions());
return TimingParams(aOptions.GetAsKeyframeEffectOptions());
return TimingParams(aOptions.GetAsKeyframeEffectOptions(), aTarget);
}
}
/* static */ TimingParams
TimingParams::FromOptionsUnion(
const dom::UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions)
const dom::UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions,
const dom::Element* aTarget)
{
if (aOptions.IsUnrestrictedDouble()) {
return TimingParams(aOptions.GetAsUnrestrictedDouble());
} else {
MOZ_ASSERT(aOptions.IsKeyframeAnimationOptions());
return TimingParams(aOptions.GetAsKeyframeAnimationOptions());
return TimingParams(aOptions.GetAsKeyframeAnimationOptions(), aTarget);
}
}
@ -68,7 +72,8 @@ TimingParams::operator==(const TimingParams& aOther) const
mDelay == aOther.mDelay &&
mIterations == aOther.mIterations &&
mDirection == aOther.mDirection &&
mFill == aOther.mFill;
mFill == aOther.mFill &&
mFunction == aOther.mFunction;
}
namespace dom {
@ -84,5 +89,15 @@ AnimationEffectTimingReadOnly::WrapObject(JSContext* aCx, JS::Handle<JSObject*>
return AnimationEffectTimingReadOnlyBinding::Wrap(aCx, this, aGivenProto);
}
void
AnimationEffectTimingReadOnly::GetEasing(nsString& aRetVal) const
{
if (mTiming.mFunction.isSome()) {
mTiming.mFunction->AppendToString(aRetVal);
} else {
aRetVal.AssignLiteral("linear");
}
}
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -26,6 +26,7 @@ namespace mozilla {
namespace dom {
struct AnimationEffectTimingProperties;
class Element;
class UnrestrictedDoubleOrKeyframeEffectOptions;
class UnrestrictedDoubleOrKeyframeAnimationOptions;
}
@ -34,13 +35,16 @@ struct TimingParams
{
TimingParams() = default;
explicit TimingParams(
const dom::AnimationEffectTimingProperties& aTimingProperties);
const dom::AnimationEffectTimingProperties& aTimingProperties,
const dom::Element* aTarget);
explicit TimingParams(double aDuration);
static TimingParams FromOptionsUnion(
const dom::UnrestrictedDoubleOrKeyframeEffectOptions& aOptions);
const dom::UnrestrictedDoubleOrKeyframeEffectOptions& aOptions,
const dom::Element* aTarget);
static TimingParams FromOptionsUnion(
const dom::UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions);
const dom::UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions,
const dom::Element* aTarget);
// The unitialized state of mDuration represents "auto".
// Bug 1237173: We will replace this with Maybe<TimeDuration>.
@ -49,6 +53,7 @@ struct TimingParams
double mIterations = 1.0; // Can be NaN, negative, +/-Infinity
dom::PlaybackDirection mDirection = dom::PlaybackDirection::Normal;
dom::FillMode mFill = dom::FillMode::Auto;
Maybe<ComputedTimingFunction> mFunction;
bool operator==(const TimingParams& aOther) const;
bool operator!=(const TimingParams& aOther) const
@ -87,7 +92,7 @@ public:
aRetVal = mTiming.mDuration;
}
PlaybackDirection Direction() const { return mTiming.mDirection; }
void GetEasing(nsString& aRetVal) const { aRetVal.AssignLiteral("linear"); }
void GetEasing(nsString& aRetVal) const;
const TimingParams& AsTimingParams() const { return mTiming; }
void SetTimingParams(const TimingParams& aTiming) { mTiming = aTiming; }

Просмотреть файл

@ -194,7 +194,8 @@ public:
ErrorResult& aRv)
{
return Constructor(aGlobal, aTarget, aFrames,
TimingParams::FromOptionsUnion(aOptions), aRv);
TimingParams::FromOptionsUnion(aOptions, aTarget),
aRv);
}
// More generalized version for Animatable.animate.

Просмотреть файл

@ -3339,7 +3339,7 @@ Element::Animate(JSContext* aContext,
// Bug 1211783: Use KeyframeEffect here (instead of KeyframeEffectReadOnly)
RefPtr<KeyframeEffectReadOnly> effect =
KeyframeEffectReadOnly::Constructor(global, this, frames,
TimingParams::FromOptionsUnion(aOptions), aError);
TimingParams::FromOptionsUnion(aOptions, this), aError);
if (aError.Failed()) {
return nullptr;
}