Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: cc/animation/scroll_offset_animation_curve.cc

Issue 584503005: Make scroll offset type of float in cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: link crbug to TODO Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "cc/animation/scroll_offset_animation_curve.h" 5 #include "cc/animation/scroll_offset_animation_curve.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 26 matching lines...) Expand all
37 const double r2 = 0.42 * 0.42; 37 const double r2 = 0.42 * 0.42;
38 const double v2 = velocity * velocity; 38 const double v2 = velocity * velocity;
39 const double x1 = std::sqrt(r2 / (v2 + 1)); 39 const double x1 = std::sqrt(r2 / (v2 + 1));
40 const double y1 = std::sqrt(r2 * v2 / (v2 + 1)); 40 const double y1 = std::sqrt(r2 * v2 / (v2 + 1));
41 return CubicBezierTimingFunction::Create(x1, y1, 0.58, 1); 41 return CubicBezierTimingFunction::Create(x1, y1, 0.58, 1);
42 } 42 }
43 43
44 } // namespace 44 } // namespace
45 45
46 scoped_ptr<ScrollOffsetAnimationCurve> ScrollOffsetAnimationCurve::Create( 46 scoped_ptr<ScrollOffsetAnimationCurve> ScrollOffsetAnimationCurve::Create(
47 const gfx::Vector2dF& target_value, 47 const gfx::ScrollOffset& target_value,
48 scoped_ptr<TimingFunction> timing_function) { 48 scoped_ptr<TimingFunction> timing_function) {
49 return make_scoped_ptr( 49 return make_scoped_ptr(
50 new ScrollOffsetAnimationCurve(target_value, timing_function.Pass())); 50 new ScrollOffsetAnimationCurve(target_value, timing_function.Pass()));
51 } 51 }
52 52
53 ScrollOffsetAnimationCurve::ScrollOffsetAnimationCurve( 53 ScrollOffsetAnimationCurve::ScrollOffsetAnimationCurve(
54 const gfx::Vector2dF& target_value, 54 const gfx::ScrollOffset& target_value,
55 scoped_ptr<TimingFunction> timing_function) 55 scoped_ptr<TimingFunction> timing_function)
56 : target_value_(target_value), timing_function_(timing_function.Pass()) { 56 : target_value_(target_value), timing_function_(timing_function.Pass()) {
57 } 57 }
58 58
59 ScrollOffsetAnimationCurve::~ScrollOffsetAnimationCurve() {} 59 ScrollOffsetAnimationCurve::~ScrollOffsetAnimationCurve() {}
60 60
61 void ScrollOffsetAnimationCurve::SetInitialValue( 61 void ScrollOffsetAnimationCurve::SetInitialValue(
62 const gfx::Vector2dF& initial_value) { 62 const gfx::ScrollOffset& initial_value) {
63 initial_value_ = initial_value; 63 initial_value_ = initial_value;
64 total_animation_duration_ = DurationFromDelta(target_value_ - initial_value_); 64 total_animation_duration_ = DurationFromDelta(
65 target_value_.DeltaFrom(initial_value_));
65 } 66 }
66 67
67 gfx::Vector2dF ScrollOffsetAnimationCurve::GetValue(double t) const { 68 gfx::ScrollOffset ScrollOffsetAnimationCurve::GetValue(double t) const {
68 double duration = (total_animation_duration_ - last_retarget_).InSecondsF(); 69 double duration = (total_animation_duration_ - last_retarget_).InSecondsF();
69 t -= last_retarget_.InSecondsF(); 70 t -= last_retarget_.InSecondsF();
70 71
71 if (t <= 0) 72 if (t <= 0)
72 return initial_value_; 73 return initial_value_;
73 74
74 if (t >= duration) 75 if (t >= duration)
75 return target_value_; 76 return target_value_;
76 77
77 double progress = (timing_function_->GetValue(t / duration)); 78 double progress = (timing_function_->GetValue(t / duration));
78 return gfx::Vector2dF(gfx::Tween::FloatValueBetween( 79 return gfx::ScrollOffset(
79 progress, initial_value_.x(), target_value_.x()), 80 gfx::Tween::FloatValueBetween(
80 gfx::Tween::FloatValueBetween( 81 progress, initial_value_.x(), target_value_.x()),
81 progress, initial_value_.y(), target_value_.y())); 82 gfx::Tween::FloatValueBetween(
83 progress, initial_value_.y(), target_value_.y()));
82 } 84 }
83 85
84 double ScrollOffsetAnimationCurve::Duration() const { 86 double ScrollOffsetAnimationCurve::Duration() const {
85 return total_animation_duration_.InSecondsF(); 87 return total_animation_duration_.InSecondsF();
86 } 88 }
87 89
88 AnimationCurve::CurveType ScrollOffsetAnimationCurve::Type() const { 90 AnimationCurve::CurveType ScrollOffsetAnimationCurve::Type() const {
89 return ScrollOffset; 91 return ScrollOffset;
90 } 92 }
91 93
92 scoped_ptr<AnimationCurve> ScrollOffsetAnimationCurve::Clone() const { 94 scoped_ptr<AnimationCurve> ScrollOffsetAnimationCurve::Clone() const {
93 scoped_ptr<TimingFunction> timing_function( 95 scoped_ptr<TimingFunction> timing_function(
94 static_cast<TimingFunction*>(timing_function_->Clone().release())); 96 static_cast<TimingFunction*>(timing_function_->Clone().release()));
95 scoped_ptr<ScrollOffsetAnimationCurve> curve_clone = 97 scoped_ptr<ScrollOffsetAnimationCurve> curve_clone =
96 Create(target_value_, timing_function.Pass()); 98 Create(target_value_, timing_function.Pass());
97 curve_clone->initial_value_ = initial_value_; 99 curve_clone->initial_value_ = initial_value_;
98 curve_clone->total_animation_duration_ = total_animation_duration_; 100 curve_clone->total_animation_duration_ = total_animation_duration_;
99 curve_clone->last_retarget_ = last_retarget_; 101 curve_clone->last_retarget_ = last_retarget_;
100 return curve_clone.Pass(); 102 return curve_clone.Pass();
101 } 103 }
102 104
103 void ScrollOffsetAnimationCurve::UpdateTarget( 105 void ScrollOffsetAnimationCurve::UpdateTarget(
104 double t, 106 double t,
105 const gfx::Vector2dF& new_target) { 107 const gfx::ScrollOffset& new_target) {
106 gfx::Vector2dF current_position = GetValue(t); 108 gfx::ScrollOffset current_position = GetValue(t);
107 gfx::Vector2dF old_delta = target_value_ - initial_value_; 109 gfx::Vector2dF old_delta = target_value_.DeltaFrom(initial_value_);
108 gfx::Vector2dF new_delta = new_target - current_position; 110 gfx::Vector2dF new_delta = new_target.DeltaFrom(current_position);
109 111
110 double old_duration = 112 double old_duration =
111 (total_animation_duration_ - last_retarget_).InSecondsF(); 113 (total_animation_duration_ - last_retarget_).InSecondsF();
112 double new_duration = DurationFromDelta(new_delta).InSecondsF(); 114 double new_duration = DurationFromDelta(new_delta).InSecondsF();
113 115
114 double old_velocity = timing_function_->Velocity( 116 double old_velocity = timing_function_->Velocity(
115 (t - last_retarget_.InSecondsF()) / old_duration); 117 (t - last_retarget_.InSecondsF()) / old_duration);
116 118
117 // TimingFunction::Velocity gives the slope of the curve from 0 to 1. 119 // TimingFunction::Velocity gives the slope of the curve from 0 to 1.
118 // To match the "true" velocity in px/sec we must adjust this slope for 120 // To match the "true" velocity in px/sec we must adjust this slope for
119 // differences in duration and scroll delta between old and new curves. 121 // differences in duration and scroll delta between old and new curves.
120 double new_velocity = 122 double new_velocity =
121 old_velocity * (new_duration / old_duration) * 123 old_velocity * (new_duration / old_duration) *
122 (MaximumDimension(old_delta) / MaximumDimension(new_delta)); 124 (MaximumDimension(old_delta) / MaximumDimension(new_delta));
123 125
124 initial_value_ = current_position; 126 initial_value_ = current_position;
125 target_value_ = new_target; 127 target_value_ = new_target;
126 total_animation_duration_ = base::TimeDelta::FromSecondsD(t + new_duration); 128 total_animation_duration_ = base::TimeDelta::FromSecondsD(t + new_duration);
127 last_retarget_ = base::TimeDelta::FromSecondsD(t); 129 last_retarget_ = base::TimeDelta::FromSecondsD(t);
128 timing_function_ = EaseOutWithInitialVelocity(new_velocity); 130 timing_function_ = EaseOutWithInitialVelocity(new_velocity);
129 } 131 }
130 132
131 } // namespace cc 133 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/scroll_offset_animation_curve.h ('k') | cc/animation/scroll_offset_animation_curve_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698