OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2013, Google Inc. All rights reserved. |
| 3 * |
| 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are |
| 6 * met: |
| 7 * |
| 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above |
| 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. |
| 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ |
| 30 |
| 31 #include "config.h" |
| 32 #include "core/platform/animation/TimingFunctionTestHelper.h" |
| 33 |
| 34 #include <ostream> // NOLINT |
| 35 |
| 36 namespace WebCore { |
| 37 |
| 38 void PrintTo(const LinearTimingFunction& timingFunction, ::std::ostream* os) |
| 39 { |
| 40 *os << "LinearTimingFunction@" << &timingFunction; |
| 41 } |
| 42 |
| 43 void PrintTo(const CubicBezierTimingFunction& timingFunction, ::std::ostream* os
) |
| 44 { |
| 45 *os << "CubicBezierTimingFunction@" << &timingFunction << "("; |
| 46 switch (timingFunction.subType()) { |
| 47 case CubicBezierTimingFunction::Ease: |
| 48 *os << "Ease"; |
| 49 break; |
| 50 case CubicBezierTimingFunction::EaseIn: |
| 51 *os << "EaseIn"; |
| 52 break; |
| 53 case CubicBezierTimingFunction::EaseOut: |
| 54 *os << "EaseOut"; |
| 55 break; |
| 56 case CubicBezierTimingFunction::EaseInOut: |
| 57 *os << "EaseInOut"; |
| 58 break; |
| 59 case CubicBezierTimingFunction::Custom: |
| 60 *os << "Custom"; |
| 61 break; |
| 62 default: |
| 63 ASSERT_NOT_REACHED(); |
| 64 } |
| 65 *os << ", " << timingFunction.x1(); |
| 66 *os << ", " << timingFunction.y1(); |
| 67 *os << ", " << timingFunction.x2(); |
| 68 *os << ", " << timingFunction.y2(); |
| 69 *os << ")"; |
| 70 } |
| 71 |
| 72 void PrintTo(const StepsTimingFunction& timingFunction, ::std::ostream* os) |
| 73 { |
| 74 *os << "StepsTimingFunction@" << &timingFunction << "("; |
| 75 switch (timingFunction.subType()) { |
| 76 case StepsTimingFunction::Start: |
| 77 *os << "Start"; |
| 78 break; |
| 79 case StepsTimingFunction::End: |
| 80 *os << "End"; |
| 81 break; |
| 82 case StepsTimingFunction::Custom: |
| 83 *os << "Custom"; |
| 84 break; |
| 85 default: |
| 86 ASSERT_NOT_REACHED(); |
| 87 } |
| 88 *os << ", " << timingFunction.numberOfSteps(); |
| 89 *os << ", " << (timingFunction.stepAtStart() ? "true" : "false"); |
| 90 *os << ")"; |
| 91 } |
| 92 |
| 93 class ChainedTimingFunctionPrinter { |
| 94 private: |
| 95 static void PrintTo(const ChainedTimingFunction& timingFunction, ::std::ostr
eam* os) |
| 96 { |
| 97 // Forward declare the generic PrintTo function as ChainedTimingFunction
needs to call it. |
| 98 void PrintTo(const TimingFunction&, ::std::ostream*); |
| 99 |
| 100 *os << "ChainedTimingFunction@" << &timingFunction << "("; |
| 101 for (size_t i = 0; i < timingFunction.m_segments.size(); i++) { |
| 102 ChainedTimingFunction::Segment segment = timingFunction.m_segments[i
]; |
| 103 PrintTo(*(segment.m_timingFunction.get()), os); |
| 104 *os << "[" << segment.m_min << " -> " << segment.m_max << "]"; |
| 105 if (i+1 != timingFunction.m_segments.size()) { |
| 106 *os << ", "; |
| 107 } |
| 108 } |
| 109 *os << ")"; |
| 110 } |
| 111 |
| 112 friend void PrintTo(const ChainedTimingFunction&, ::std::ostream*); |
| 113 }; |
| 114 |
| 115 void PrintTo(const ChainedTimingFunction& timingFunction, ::std::ostream* os) |
| 116 { |
| 117 ChainedTimingFunctionPrinter::PrintTo(timingFunction, os); |
| 118 } |
| 119 |
| 120 // The generic PrintTo *must* come after the non-generic PrintTo otherwise it |
| 121 // will end up calling itself. |
| 122 void PrintTo(const TimingFunction& timingFunction, ::std::ostream* os) |
| 123 { |
| 124 switch (timingFunction.type()) { |
| 125 case TimingFunction::LinearFunction: { |
| 126 const LinearTimingFunction* linear = static_cast<const LinearTimingFunct
ion*>(&timingFunction); |
| 127 PrintTo(*linear, os); |
| 128 return; |
| 129 } |
| 130 case TimingFunction::CubicBezierFunction: { |
| 131 const CubicBezierTimingFunction* cubic = static_cast<const CubicBezierTi
mingFunction*>(&timingFunction); |
| 132 PrintTo(*cubic, os); |
| 133 return; |
| 134 } |
| 135 case TimingFunction::StepsFunction: { |
| 136 const StepsTimingFunction* step = static_cast<const StepsTimingFunction*
>(&timingFunction); |
| 137 PrintTo(*step, os); |
| 138 return; |
| 139 } |
| 140 case TimingFunction::ChainedFunction: { |
| 141 const ChainedTimingFunction* chained = static_cast<const ChainedTimingFu
nction*>(&timingFunction); |
| 142 PrintTo(*chained, os); |
| 143 return; |
| 144 } |
| 145 default: |
| 146 ASSERT_NOT_REACHED(); |
| 147 } |
| 148 } |
| 149 |
| 150 } // namespace WebCore |
OLD | NEW |