| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/animation/TimingFunction.h" | 5 #include "platform/animation/TimingFunction.h" |
| 6 | 6 |
| 7 #include "wtf/text/StringBuilder.h" | 7 #include "wtf/text/StringBuilder.h" |
| 8 | 8 |
| 9 namespace blink { | 9 namespace blink { |
| 10 | 10 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 } | 101 } |
| 102 | 102 |
| 103 double StepsTimingFunction::evaluate(double fraction, double) const { | 103 double StepsTimingFunction::evaluate(double fraction, double) const { |
| 104 return m_steps->GetPreciseValue(fraction); | 104 return m_steps->GetPreciseValue(fraction); |
| 105 } | 105 } |
| 106 | 106 |
| 107 std::unique_ptr<cc::TimingFunction> StepsTimingFunction::cloneToCC() const { | 107 std::unique_ptr<cc::TimingFunction> StepsTimingFunction::cloneToCC() const { |
| 108 return m_steps->Clone(); | 108 return m_steps->Clone(); |
| 109 } | 109 } |
| 110 | 110 |
| 111 String FramesTimingFunction::toString() const { |
| 112 StringBuilder builder; |
| 113 builder.append("frames("); |
| 114 builder.append(String::numberToStringECMAScript(this->numberOfFrames())); |
| 115 builder.append(")"); |
| 116 return builder.toString(); |
| 117 } |
| 118 |
| 119 void FramesTimingFunction::range(double* minValue, double* maxValue) const { |
| 120 *minValue = 0; |
| 121 *maxValue = 1; |
| 122 } |
| 123 |
| 124 double FramesTimingFunction::evaluate(double fraction, double) const { |
| 125 return m_frames->GetPreciseValue(fraction); |
| 126 } |
| 127 |
| 128 std::unique_ptr<cc::TimingFunction> FramesTimingFunction::cloneToCC() const { |
| 129 return m_frames->Clone(); |
| 130 } |
| 131 |
| 111 PassRefPtr<TimingFunction> createCompositorTimingFunctionFromCC( | 132 PassRefPtr<TimingFunction> createCompositorTimingFunctionFromCC( |
| 112 const cc::TimingFunction* timingFunction) { | 133 const cc::TimingFunction* timingFunction) { |
| 113 if (!timingFunction) | 134 if (!timingFunction) |
| 114 return LinearTimingFunction::shared(); | 135 return LinearTimingFunction::shared(); |
| 115 | 136 |
| 116 switch (timingFunction->GetType()) { | 137 switch (timingFunction->GetType()) { |
| 117 case cc::TimingFunction::Type::CUBIC_BEZIER: { | 138 case cc::TimingFunction::Type::CUBIC_BEZIER: { |
| 118 auto cubicTimingFunction = | 139 auto cubicTimingFunction = |
| 119 static_cast<const cc::CubicBezierTimingFunction*>(timingFunction); | 140 static_cast<const cc::CubicBezierTimingFunction*>(timingFunction); |
| 120 if (cubicTimingFunction->ease_type() != | 141 if (cubicTimingFunction->ease_type() != |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 | 182 |
| 162 bool operator==(const StepsTimingFunction& lhs, const TimingFunction& rhs) { | 183 bool operator==(const StepsTimingFunction& lhs, const TimingFunction& rhs) { |
| 163 if (rhs.getType() != TimingFunction::Type::STEPS) | 184 if (rhs.getType() != TimingFunction::Type::STEPS) |
| 164 return false; | 185 return false; |
| 165 | 186 |
| 166 const StepsTimingFunction& stf = toStepsTimingFunction(rhs); | 187 const StepsTimingFunction& stf = toStepsTimingFunction(rhs); |
| 167 return (lhs.numberOfSteps() == stf.numberOfSteps()) && | 188 return (lhs.numberOfSteps() == stf.numberOfSteps()) && |
| 168 (lhs.getStepPosition() == stf.getStepPosition()); | 189 (lhs.getStepPosition() == stf.getStepPosition()); |
| 169 } | 190 } |
| 170 | 191 |
| 192 bool operator==(const FramesTimingFunction& lhs, const TimingFunction& rhs) { |
| 193 if (rhs.getType() != TimingFunction::Type::FRAMES) |
| 194 return false; |
| 195 |
| 196 const FramesTimingFunction& stf = toFramesTimingFunction(rhs); |
| 197 return lhs.numberOfFrames() == stf.numberOfFrames(); |
| 198 } |
| 199 |
| 171 // The generic operator== *must* come after the | 200 // The generic operator== *must* come after the |
| 172 // non-generic operator== otherwise it will end up calling itself. | 201 // non-generic operator== otherwise it will end up calling itself. |
| 173 bool operator==(const TimingFunction& lhs, const TimingFunction& rhs) { | 202 bool operator==(const TimingFunction& lhs, const TimingFunction& rhs) { |
| 174 switch (lhs.getType()) { | 203 switch (lhs.getType()) { |
| 175 case TimingFunction::Type::LINEAR: { | 204 case TimingFunction::Type::LINEAR: { |
| 176 const LinearTimingFunction& linear = toLinearTimingFunction(lhs); | 205 const LinearTimingFunction& linear = toLinearTimingFunction(lhs); |
| 177 return (linear == rhs); | 206 return (linear == rhs); |
| 178 } | 207 } |
| 179 case TimingFunction::Type::CUBIC_BEZIER: { | 208 case TimingFunction::Type::CUBIC_BEZIER: { |
| 180 const CubicBezierTimingFunction& cubic = toCubicBezierTimingFunction(lhs); | 209 const CubicBezierTimingFunction& cubic = toCubicBezierTimingFunction(lhs); |
| 181 return (cubic == rhs); | 210 return (cubic == rhs); |
| 182 } | 211 } |
| 183 case TimingFunction::Type::STEPS: { | 212 case TimingFunction::Type::STEPS: { |
| 184 const StepsTimingFunction& step = toStepsTimingFunction(lhs); | 213 const StepsTimingFunction& step = toStepsTimingFunction(lhs); |
| 185 return (step == rhs); | 214 return (step == rhs); |
| 186 } | 215 } |
| 216 case TimingFunction::Type::FRAMES: { |
| 217 const FramesTimingFunction& frame = toFramesTimingFunction(lhs); |
| 218 return (frame == rhs); |
| 219 } |
| 187 default: | 220 default: |
| 188 ASSERT_NOT_REACHED(); | 221 ASSERT_NOT_REACHED(); |
| 189 } | 222 } |
| 190 return false; | 223 return false; |
| 191 } | 224 } |
| 192 | 225 |
| 193 // No need to define specific operator!= as they can all come via this function. | 226 // No need to define specific operator!= as they can all come via this function. |
| 194 bool operator!=(const TimingFunction& lhs, const TimingFunction& rhs) { | 227 bool operator!=(const TimingFunction& lhs, const TimingFunction& rhs) { |
| 195 return !(lhs == rhs); | 228 return !(lhs == rhs); |
| 196 } | 229 } |
| 197 | 230 |
| 198 } // namespace blink | 231 } // namespace blink |
| OLD | NEW |