float_animation_curve_adapter.cc 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ui/compositor/float_animation_curve_adapter.h"
  5. #include "base/memory/ptr_util.h"
  6. namespace ui {
  7. FloatAnimationCurveAdapter::FloatAnimationCurveAdapter(
  8. gfx::Tween::Type tween_type,
  9. float initial_value,
  10. float target_value,
  11. base::TimeDelta duration)
  12. : tween_type_(tween_type),
  13. initial_value_(initial_value),
  14. target_value_(target_value),
  15. duration_(duration) {
  16. }
  17. base::TimeDelta FloatAnimationCurveAdapter::Duration() const {
  18. return duration_;
  19. }
  20. std::unique_ptr<gfx::AnimationCurve> FloatAnimationCurveAdapter::Clone() const {
  21. return base::WrapUnique(new FloatAnimationCurveAdapter(
  22. tween_type_, initial_value_, target_value_, duration_));
  23. }
  24. float FloatAnimationCurveAdapter::GetValue(base::TimeDelta t) const {
  25. if (t >= duration_)
  26. return target_value_;
  27. if (t <= base::TimeDelta())
  28. return initial_value_;
  29. return gfx::Tween::FloatValueBetween(
  30. gfx::Tween::CalculateValue(tween_type_, t / duration_), initial_value_,
  31. target_value_);
  32. }
  33. } // namespace ui