Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1179)

Unified Diff: Source/platform/animation/TimingFunction.cpp

Issue 149363002: Web Animations API: Implement step-middle and steps(x, middle) timing functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Merged patch into fresh branch (to avoid scary rebase) Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/platform/animation/TimingFunction.h ('k') | Source/platform/animation/TimingFunctionTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/animation/TimingFunction.cpp
diff --git a/Source/platform/animation/TimingFunction.cpp b/Source/platform/animation/TimingFunction.cpp
index f196dab07a1270fabd7cc1599bd541351438e967..8632b5a8cd7c968770164fd4b3d3da0a085a3c20 100644
--- a/Source/platform/animation/TimingFunction.cpp
+++ b/Source/platform/animation/TimingFunction.cpp
@@ -53,11 +53,22 @@ String StepsTimingFunction::toString() const
switch (this->subType()) {
case StepsTimingFunction::Start:
return "step-start";
+ case StepsTimingFunction::Middle:
+ return "step-middle";
case StepsTimingFunction::End:
return "step-end";
case StepsTimingFunction::Custom:
builder.append("steps(" + String::numberToStringECMAScript(this->numberOfSteps()) + ", ");
- builder.append(this->stepAtStart() ? "start" : "end");
+
+ if (this->stepAtPosition() == StepsTimingFunction::StepAtStart)
+ builder.append("start");
+ else if (this->stepAtPosition() == StepsTimingFunction::StepAtMiddle)
+ builder.append("middle");
+ else if (this->stepAtPosition() == StepsTimingFunction::StepAtEnd)
+ builder.append("end");
+ else
+ ASSERT_NOT_REACHED();
+
builder.append(")");
break;
default:
@@ -69,7 +80,22 @@ String StepsTimingFunction::toString() const
double StepsTimingFunction::evaluate(double fraction, double) const
{
ASSERT_WITH_MESSAGE(fraction >= 0 && fraction <= 1, "Web Animations not yet implemented: Timing function behavior outside the range [0, 1] is not yet specified");
- return std::min(1.0, (floor(m_steps * fraction) + m_stepAtStart) / m_steps);
+ double startOffset = 0;
+ switch (m_stepAtPosition) {
+ case StepAtStart:
+ startOffset = 1;
+ break;
+ case StepAtMiddle:
+ startOffset = 0.5;
+ break;
+ case StepAtEnd:
+ startOffset = 0;
+ break;
+ default:
+ ASSERT_NOT_REACHED();
+ break;
+ }
+ return std::min(1.0, floor((m_steps * fraction) + startOffset) / m_steps);
}
String ChainedTimingFunction::toString() const
@@ -101,4 +127,67 @@ double ChainedTimingFunction::evaluate(double fraction, double accuracy) const
return segment->evaluate(fraction, accuracy);
}
+// Equals operators
+bool operator==(const LinearTimingFunction& lhs, const TimingFunction& rhs)
+{
+ return rhs.type() == TimingFunction::LinearFunction;
+}
+
+bool operator==(const CubicBezierTimingFunction& lhs, const TimingFunction& rhs)
+{
+ if (rhs.type() != TimingFunction::CubicBezierFunction)
+ return false;
+
+ const CubicBezierTimingFunction& ctf = toCubicBezierTimingFunction(rhs);
+ if ((lhs.subType() == CubicBezierTimingFunction::Custom) && (ctf.subType() == CubicBezierTimingFunction::Custom))
+ return (lhs.x1() == ctf.x1()) && (lhs.y1() == ctf.y1()) && (lhs.x2() == ctf.x2()) && (lhs.y2() == ctf.y2());
+
+ return lhs.subType() == ctf.subType();
+}
+
+bool operator==(const StepsTimingFunction& lhs, const TimingFunction& rhs)
+{
+ if (rhs.type() != TimingFunction::StepsFunction)
+ return false;
+
+ const StepsTimingFunction& stf = toStepsTimingFunction(rhs);
+ if ((lhs.subType() == StepsTimingFunction::Custom) && (stf.subType() == StepsTimingFunction::Custom))
+ return (lhs.numberOfSteps() == stf.numberOfSteps()) && (lhs.stepAtPosition() == stf.stepAtPosition());
+
+ return lhs.subType() == stf.subType();
+}
+
+// The generic operator== *must* come after the
+// non-generic operator== otherwise it will end up calling itself.
+bool operator==(const TimingFunction& lhs, const TimingFunction& rhs)
+{
+ switch (lhs.type()) {
+ case TimingFunction::LinearFunction: {
+ const LinearTimingFunction& linear = toLinearTimingFunction(lhs);
+ return (linear == rhs);
+ }
+ case TimingFunction::CubicBezierFunction: {
+ const CubicBezierTimingFunction& cubic = toCubicBezierTimingFunction(lhs);
+ return (cubic == rhs);
+ }
+ case TimingFunction::StepsFunction: {
+ const StepsTimingFunction& step = toStepsTimingFunction(lhs);
+ return (step == rhs);
+ }
+ case TimingFunction::ChainedFunction: {
+ const ChainedTimingFunction& chained = toChainedTimingFunction(lhs);
+ return (chained == rhs);
+ }
+ default:
+ ASSERT_NOT_REACHED();
+ }
+ return false;
+}
+
+// No need to define specific operator!= as they can all come via this function.
+bool operator!=(const TimingFunction& lhs, const TimingFunction& rhs)
+{
+ return !(lhs == rhs);
+}
+
} // namespace WebCore
« no previous file with comments | « Source/platform/animation/TimingFunction.h ('k') | Source/platform/animation/TimingFunctionTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698