Index: Source/core/platform/animation/TimingFunctionTestHelper.cpp |
diff --git a/Source/core/platform/animation/TimingFunctionTestHelper.cpp b/Source/core/platform/animation/TimingFunctionTestHelper.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f92906e4c980a83901a69c30311117a9907dfb95 |
--- /dev/null |
+++ b/Source/core/platform/animation/TimingFunctionTestHelper.cpp |
@@ -0,0 +1,145 @@ |
+/* |
+ * Copyright (c) 2013, Google Inc. All rights reserved. |
+ * |
+ * Redistribution and use in source and binary forms, with or without |
+ * modification, are permitted provided that the following conditions are |
+ * met: |
+ * |
+ * * Redistributions of source code must retain the above copyright |
+ * notice, this list of conditions and the following disclaimer. |
+ * * Redistributions in binary form must reproduce the above |
+ * copyright notice, this list of conditions and the following disclaimer |
+ * in the documentation and/or other materials provided with the |
+ * distribution. |
+ * * Neither the name of Google Inc. nor the names of its |
+ * contributors may be used to endorse or promote products derived from |
+ * this software without specific prior written permission. |
+ * |
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ */ |
+ |
+#include "config.h" |
+ |
+#include "core/platform/animation/TimingFunctionTestHelper.h" |
+ |
+#include <ostream> // NOLINT |
+ |
+namespace WebCore { |
+ |
+void PrintTo(const LinearTimingFunction& timefunction, ::std::ostream* os, bool recursiveGuard) |
+{ |
+ *os << "LinearTimingFunction@" << &timefunction; |
+} |
+ |
+void PrintTo(const CubicBezierTimingFunction& timefunction, ::std::ostream* os, bool recursiveGuard) |
+{ |
+ *os << "CubicBezierTimingFunction@" << &timefunction << "("; |
+ switch (timefunction.subType()) { |
+ case CubicBezierTimingFunction::Ease: |
+ *os << "Ease"; |
+ break; |
+ case CubicBezierTimingFunction::EaseIn: |
+ *os << "EaseIn"; |
+ break; |
+ case CubicBezierTimingFunction::EaseOut: |
+ *os << "EaseOut"; |
+ break; |
+ case CubicBezierTimingFunction::EaseInOut: |
+ *os << "EaseInOut"; |
+ break; |
+ case CubicBezierTimingFunction::Custom: |
+ *os << "Custom"; |
+ break; |
+ default: |
+ ASSERT_NOT_REACHED(); |
+ } |
+ *os << ", " << timefunction.x1(); |
+ *os << ", " << timefunction.y1(); |
+ *os << ", " << timefunction.x2(); |
+ *os << ", " << timefunction.y2(); |
+ *os << ")"; |
+} |
+ |
+void PrintTo(const StepsTimingFunction& timefunction, ::std::ostream* os, bool recursiveGuard) |
+{ |
+ *os << "StepsTimingFunction@" << &timefunction << "("; |
+ switch (timefunction.subType()) { |
+ case StepsTimingFunction::Start: |
+ *os << "Start"; |
+ break; |
+ case StepsTimingFunction::End: |
+ *os << "End"; |
+ break; |
+ case StepsTimingFunction::Custom: |
+ *os << "Custom"; |
+ break; |
+ default: |
+ ASSERT_NOT_REACHED(); |
+ } |
+ *os << ", " << timefunction.numberOfSteps(); |
+ *os << ", " << (timefunction.stepAtStart() ? "true" : "false"); |
+ *os << ")"; |
+} |
+ |
+void PrintTo(const ChainedTimingFunction& timefunction, ::std::ostream* os, bool recursiveGuard) |
+{ |
+ // Forward declare the generic PrintTo function as ChainedTimingFunction needs to call it. |
+ void PrintTo(const TimingFunction&, ::std::ostream*, bool); |
+ |
+ *os << "ChainedTimingFunction@" << &timefunction << "("; |
+ for (size_t i = 0; i < timefunction.m_segments.size(); i++) { |
+ ChainedTimingFunction::Segment segment = timefunction.m_segments[i]; |
+ PrintTo(*(segment.m_timingFunction.get()), os, false); |
+ *os << "[" << segment.m_min << " -> " << segment.m_max << "]"; |
+ if (i+1 != timefunction.m_segments.size()) { |
+ *os << ", "; |
+ } |
+ } |
+ *os << ")"; |
+} |
+ |
+// The generic PrintTo *must* come after the non-generic PrintTo otherwise it |
+// will end up calling itself. |
+void PrintTo(const TimingFunction& timefunction, ::std::ostream* os, bool recursiveGuard) |
+{ |
+ // This guards against the generic PrintTo accidentally calling itself. |
+ ASSERT(!recursiveGuard); |
Steve Block
2013/11/03 09:18:32
I don't really like the idea of adding a param to
mithro-old
2013/11/03 09:58:24
I can remove it if you feel strongly about it. Sin
Steve Block
2013/11/03 23:29:44
ASSERT()s are only compiled in debug builds, and r
|
+ |
+ switch (timefunction.type()) { |
+ case TimingFunction::LinearFunction: { |
+ const LinearTimingFunction* linear = static_cast<const LinearTimingFunction*>(&timefunction); |
+ PrintTo(*linear, os, true); |
+ return; |
+ } |
+ case TimingFunction::CubicBezierFunction: { |
+ const CubicBezierTimingFunction* cubic = static_cast<const CubicBezierTimingFunction*>(&timefunction); |
+ PrintTo(*cubic, os, true); |
+ return; |
+ } |
+ case TimingFunction::StepsFunction: { |
+ const StepsTimingFunction* step = static_cast<const StepsTimingFunction*>(&timefunction); |
+ PrintTo(*step, os, true); |
+ return; |
+ } |
+ case TimingFunction::ChainedFunction: { |
+ const ChainedTimingFunction* chained = static_cast<const ChainedTimingFunction*>(&timefunction); |
+ PrintTo(*chained, os, true); |
+ return; |
+ } |
+ default: |
+ ASSERT_NOT_REACHED(); |
+ } |
+ |
+} |
+ |
+} // namespace WebCore |