| 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 "platform/wtf/text/StringBuilder.h" | 7 #include "platform/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 steps_->GetPreciseValue(fraction); | 104 return 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 steps_->Clone(); | 108 return 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* min_value, double* max_value) const { |
| 120 *min_value = 0; |
| 121 *max_value = 1; |
| 122 } |
| 123 |
| 124 double FramesTimingFunction::Evaluate(double fraction, double) const { |
| 125 return frames_->GetPreciseValue(fraction); |
| 126 } |
| 127 |
| 128 std::unique_ptr<cc::TimingFunction> FramesTimingFunction::CloneToCC() const { |
| 129 return frames_->Clone(); |
| 130 } |
| 131 |
| 111 PassRefPtr<TimingFunction> CreateCompositorTimingFunctionFromCC( | 132 PassRefPtr<TimingFunction> CreateCompositorTimingFunctionFromCC( |
| 112 const cc::TimingFunction* timing_function) { | 133 const cc::TimingFunction* timing_function) { |
| 113 if (!timing_function) | 134 if (!timing_function) |
| 114 return LinearTimingFunction::Shared(); | 135 return LinearTimingFunction::Shared(); |
| 115 | 136 |
| 116 switch (timing_function->GetType()) { | 137 switch (timing_function->GetType()) { |
| 117 case cc::TimingFunction::Type::CUBIC_BEZIER: { | 138 case cc::TimingFunction::Type::CUBIC_BEZIER: { |
| 118 auto cubic_timing_function = | 139 auto cubic_timing_function = |
| 119 static_cast<const cc::CubicBezierTimingFunction*>(timing_function); | 140 static_cast<const cc::CubicBezierTimingFunction*>(timing_function); |
| 120 if (cubic_timing_function->ease_type() != | 141 if (cubic_timing_function->ease_type() != |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 | 183 |
| 163 bool operator==(const StepsTimingFunction& lhs, const TimingFunction& rhs) { | 184 bool operator==(const StepsTimingFunction& lhs, const TimingFunction& rhs) { |
| 164 if (rhs.GetType() != TimingFunction::Type::STEPS) | 185 if (rhs.GetType() != TimingFunction::Type::STEPS) |
| 165 return false; | 186 return false; |
| 166 | 187 |
| 167 const StepsTimingFunction& stf = ToStepsTimingFunction(rhs); | 188 const StepsTimingFunction& stf = ToStepsTimingFunction(rhs); |
| 168 return (lhs.NumberOfSteps() == stf.NumberOfSteps()) && | 189 return (lhs.NumberOfSteps() == stf.NumberOfSteps()) && |
| 169 (lhs.GetStepPosition() == stf.GetStepPosition()); | 190 (lhs.GetStepPosition() == stf.GetStepPosition()); |
| 170 } | 191 } |
| 171 | 192 |
| 193 bool operator==(const FramesTimingFunction& lhs, const TimingFunction& rhs) { |
| 194 if (rhs.GetType() != TimingFunction::Type::FRAMES) |
| 195 return false; |
| 196 |
| 197 const FramesTimingFunction& ftf = ToFramesTimingFunction(rhs); |
| 198 return lhs.NumberOfFrames() == ftf.NumberOfFrames(); |
| 199 } |
| 200 |
| 172 // The generic operator== *must* come after the | 201 // The generic operator== *must* come after the |
| 173 // non-generic operator== otherwise it will end up calling itself. | 202 // non-generic operator== otherwise it will end up calling itself. |
| 174 bool operator==(const TimingFunction& lhs, const TimingFunction& rhs) { | 203 bool operator==(const TimingFunction& lhs, const TimingFunction& rhs) { |
| 175 switch (lhs.GetType()) { | 204 switch (lhs.GetType()) { |
| 176 case TimingFunction::Type::LINEAR: { | 205 case TimingFunction::Type::LINEAR: { |
| 177 const LinearTimingFunction& linear = ToLinearTimingFunction(lhs); | 206 const LinearTimingFunction& linear = ToLinearTimingFunction(lhs); |
| 178 return (linear == rhs); | 207 return (linear == rhs); |
| 179 } | 208 } |
| 180 case TimingFunction::Type::CUBIC_BEZIER: { | 209 case TimingFunction::Type::CUBIC_BEZIER: { |
| 181 const CubicBezierTimingFunction& cubic = ToCubicBezierTimingFunction(lhs); | 210 const CubicBezierTimingFunction& cubic = ToCubicBezierTimingFunction(lhs); |
| 182 return (cubic == rhs); | 211 return (cubic == rhs); |
| 183 } | 212 } |
| 184 case TimingFunction::Type::STEPS: { | 213 case TimingFunction::Type::STEPS: { |
| 185 const StepsTimingFunction& step = ToStepsTimingFunction(lhs); | 214 const StepsTimingFunction& step = ToStepsTimingFunction(lhs); |
| 186 return (step == rhs); | 215 return (step == rhs); |
| 187 } | 216 } |
| 217 case TimingFunction::Type::FRAMES: { |
| 218 const FramesTimingFunction& frame = ToFramesTimingFunction(lhs); |
| 219 return (frame == rhs); |
| 220 } |
| 188 default: | 221 default: |
| 189 ASSERT_NOT_REACHED(); | 222 ASSERT_NOT_REACHED(); |
| 190 } | 223 } |
| 191 return false; | 224 return false; |
| 192 } | 225 } |
| 193 | 226 |
| 194 // No need to define specific operator!= as they can all come via this function. | 227 // No need to define specific operator!= as they can all come via this function. |
| 195 bool operator!=(const TimingFunction& lhs, const TimingFunction& rhs) { | 228 bool operator!=(const TimingFunction& lhs, const TimingFunction& rhs) { |
| 196 return !(lhs == rhs); | 229 return !(lhs == rhs); |
| 197 } | 230 } |
| 198 | 231 |
| 199 } // namespace blink | 232 } // namespace blink |
| OLD | NEW |