Bug 1248340 - Part 2: Implement Frames in ComputedTimingFunction. r=birtles

MozReview-Commit-ID: 92MAv3OD8Tu

--HG--
extra : rebase_source : 0e14ade9e9f022b641605e2c0f368e3a6c950c18
This commit is contained in:
Boris Chiou 2017-02-24 16:59:02 +08:00
Родитель 89f3bc4396
Коммит 98f895d166
2 изменённых файлов: 35 добавлений и 12 удалений

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

@ -18,10 +18,7 @@ ComputedTimingFunction::Init(const nsTimingFunction &aFunction)
mTimingFunction.Init(aFunction.mFunc.mX1, aFunction.mFunc.mY1,
aFunction.mFunc.mX2, aFunction.mFunc.mY2);
} else {
// TODO: Support Frames
MOZ_ASSERT(nsTimingFunction::Type::StepStart ||
nsTimingFunction::Type::StepEnd);
mSteps = aFunction.mStepsOrFrames;
mStepsOrFrames = aFunction.mStepsOrFrames;
}
}
@ -61,7 +58,22 @@ StepTiming(uint32_t aSteps,
if (result > 1.0 && aPortion <= 1.0) {
return 1.0;
}
return result;
}
static inline double
FramesTiming(uint32_t aFrames, double aPortion)
{
MOZ_ASSERT(aFrames > 1, "the number of frames must be greater than 1");
int32_t currentFrame = floor(aPortion * aFrames);
double result = double(currentFrame) / double(aFrames - 1);
// Don't overshoot the natural range of the animation (by producing an output
// progress greater than 1.0) when we are at the exact end of its interval
// (i.e. the input progress is 1.0).
if (result > 1.0 && aPortion <= 1.0) {
return 1.0;
}
return result;
}
@ -116,7 +128,9 @@ ComputedTimingFunction::GetValue(
return mTimingFunction.GetSplineValue(aPortion);
}
return StepTiming(mSteps, aPortion, aBeforeFlag, mType);
return mType == nsTimingFunction::Type::Frames
? FramesTiming(mStepsOrFrames, aPortion)
: StepTiming(mStepsOrFrames, aPortion, aBeforeFlag, mType);
}
int32_t
@ -132,9 +146,10 @@ ComputedTimingFunction::Compare(const ComputedTimingFunction& aRhs) const
return order;
}
} else if (mType == nsTimingFunction::Type::StepStart ||
mType == nsTimingFunction::Type::StepEnd) {
if (mSteps != aRhs.mSteps) {
return int32_t(mSteps) - int32_t(aRhs.mSteps);
mType == nsTimingFunction::Type::StepEnd ||
mType == nsTimingFunction::Type::Frames) {
if (mStepsOrFrames != aRhs.mStepsOrFrames) {
return int32_t(mStepsOrFrames) - int32_t(aRhs.mStepsOrFrames);
}
}
@ -154,7 +169,10 @@ ComputedTimingFunction::AppendToString(nsAString& aResult) const
break;
case nsTimingFunction::Type::StepStart:
case nsTimingFunction::Type::StepEnd:
nsStyleUtil::AppendStepsTimingFunction(mType, mSteps, aResult);
nsStyleUtil::AppendStepsTimingFunction(mType, mStepsOrFrames, aResult);
break;
case nsTimingFunction::Type::Frames:
// TODO: Serialize Frames timing function.
break;
default:
nsStyleUtil::AppendCubicBezierKeywordTimingFunction(mType, aResult);

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

@ -30,13 +30,18 @@ public:
}
nsTimingFunction::Type GetType() const { return mType; }
bool HasSpline() const { return nsTimingFunction::IsSplineType(mType); }
uint32_t GetSteps() const { return mSteps; }
uint32_t GetSteps() const
{
MOZ_ASSERT(mType == nsTimingFunction::Type::StepStart ||
mType == nsTimingFunction::Type::StepEnd);
return mStepsOrFrames;
}
bool operator==(const ComputedTimingFunction& aOther) const
{
return mType == aOther.mType &&
(HasSpline() ?
mTimingFunction == aOther.mTimingFunction :
mSteps == aOther.mSteps);
mStepsOrFrames == aOther.mStepsOrFrames);
}
bool operator!=(const ComputedTimingFunction& aOther) const
{
@ -57,7 +62,7 @@ public:
private:
nsTimingFunction::Type mType;
nsSMILKeySpline mTimingFunction;
uint32_t mSteps;
uint32_t mStepsOrFrames;
};
} // namespace mozilla