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()) { |
eseidel
2014/03/03 07:10:47
This seems like a really odd way to do this, but I
rjwright
2014/03/03 08:38:34
I moved this code and haven't walked carefully thr
|
+ 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 |