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 { namespace mozilla {
TimingParams::TimingParams(const dom::AnimationEffectTimingProperties& aRhs) TimingParams::TimingParams(const dom::AnimationEffectTimingProperties& aRhs,
const dom::Element* aTarget)
: mDuration(aRhs.mDuration) : mDuration(aRhs.mDuration)
, mDelay(TimeDuration::FromMilliseconds(aRhs.mDelay)) , mDelay(TimeDuration::FromMilliseconds(aRhs.mDelay))
, mIterations(aRhs.mIterations) , mIterations(aRhs.mIterations)
, mDirection(aRhs.mDirection) , mDirection(aRhs.mDirection)
, mFill(aRhs.mFill) , mFill(aRhs.mFill)
{ {
mFunction = AnimationUtils::ParseEasing(aTarget, aRhs.mEasing);
} }
TimingParams::TimingParams(double aDuration) TimingParams::TimingParams(double aDuration)
@ -28,25 +30,27 @@ TimingParams::TimingParams(double aDuration)
/* static */ TimingParams /* static */ TimingParams
TimingParams::FromOptionsUnion( TimingParams::FromOptionsUnion(
const dom::UnrestrictedDoubleOrKeyframeEffectOptions& aOptions) const dom::UnrestrictedDoubleOrKeyframeEffectOptions& aOptions,
const dom::Element* aTarget)
{ {
if (aOptions.IsUnrestrictedDouble()) { if (aOptions.IsUnrestrictedDouble()) {
return TimingParams(aOptions.GetAsUnrestrictedDouble()); return TimingParams(aOptions.GetAsUnrestrictedDouble());
} else { } else {
MOZ_ASSERT(aOptions.IsKeyframeEffectOptions()); MOZ_ASSERT(aOptions.IsKeyframeEffectOptions());
return TimingParams(aOptions.GetAsKeyframeEffectOptions()); return TimingParams(aOptions.GetAsKeyframeEffectOptions(), aTarget);
} }
} }
/* static */ TimingParams /* static */ TimingParams
TimingParams::FromOptionsUnion( TimingParams::FromOptionsUnion(
const dom::UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions) const dom::UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions,
const dom::Element* aTarget)
{ {
if (aOptions.IsUnrestrictedDouble()) { if (aOptions.IsUnrestrictedDouble()) {
return TimingParams(aOptions.GetAsUnrestrictedDouble()); return TimingParams(aOptions.GetAsUnrestrictedDouble());
} else { } else {
MOZ_ASSERT(aOptions.IsKeyframeAnimationOptions()); 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 && mDelay == aOther.mDelay &&
mIterations == aOther.mIterations && mIterations == aOther.mIterations &&
mDirection == aOther.mDirection && mDirection == aOther.mDirection &&
mFill == aOther.mFill; mFill == aOther.mFill &&
mFunction == aOther.mFunction;
} }
namespace dom { namespace dom {
@ -84,5 +89,15 @@ AnimationEffectTimingReadOnly::WrapObject(JSContext* aCx, JS::Handle<JSObject*>
return AnimationEffectTimingReadOnlyBinding::Wrap(aCx, this, aGivenProto); 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 dom
} // namespace mozilla } // namespace mozilla

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

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

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

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

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

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