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

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: blow up the patchset :( 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 27 matching lines...) Expand all
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 .PassAs<TimingFunction>(); 42 .PassAs<TimingFunction>();
43 } 43 }
44 44
45 } // namespace 45 } // namespace
46 46
47 scoped_ptr<ScrollOffsetAnimationCurve> ScrollOffsetAnimationCurve::Create( 47 scoped_ptr<ScrollOffsetAnimationCurve> ScrollOffsetAnimationCurve::Create(
48 const gfx::Vector2dF& target_value, 48 const gfx::ScrollOffset& target_value,
49 scoped_ptr<TimingFunction> timing_function) { 49 scoped_ptr<TimingFunction> timing_function) {
50 return make_scoped_ptr( 50 return make_scoped_ptr(
51 new ScrollOffsetAnimationCurve(target_value, timing_function.Pass())); 51 new ScrollOffsetAnimationCurve(target_value, timing_function.Pass()));
52 } 52 }
53 53
54 ScrollOffsetAnimationCurve::ScrollOffsetAnimationCurve( 54 ScrollOffsetAnimationCurve::ScrollOffsetAnimationCurve(
55 const gfx::Vector2dF& target_value, 55 const gfx::ScrollOffset& target_value,
56 scoped_ptr<TimingFunction> timing_function) 56 scoped_ptr<TimingFunction> timing_function)
57 : target_value_(target_value), timing_function_(timing_function.Pass()) { 57 : target_value_(target_value), timing_function_(timing_function.Pass()) {
58 } 58 }
59 59
60 ScrollOffsetAnimationCurve::~ScrollOffsetAnimationCurve() {} 60 ScrollOffsetAnimationCurve::~ScrollOffsetAnimationCurve() {}
61 61
62 void ScrollOffsetAnimationCurve::SetInitialValue( 62 void ScrollOffsetAnimationCurve::SetInitialValue(
63 const gfx::Vector2dF& initial_value) { 63 const gfx::ScrollOffset& initial_value) {
64 initial_value_ = initial_value; 64 initial_value_ = initial_value;
65 total_animation_duration_ = DurationFromDelta(target_value_ - initial_value_); 65 total_animation_duration_ = DurationFromDelta(
66 ScrollOffsetToVector2dF(target_value_ - initial_value_));
66 } 67 }
67 68
68 gfx::Vector2dF ScrollOffsetAnimationCurve::GetValue(double t) const { 69 gfx::ScrollOffset ScrollOffsetAnimationCurve::GetValue(double t) const {
69 double duration = (total_animation_duration_ - last_retarget_).InSecondsF(); 70 double duration = (total_animation_duration_ - last_retarget_).InSecondsF();
70 t -= last_retarget_.InSecondsF(); 71 t -= last_retarget_.InSecondsF();
71 72
72 if (t <= 0) 73 if (t <= 0)
73 return initial_value_; 74 return initial_value_;
74 75
75 if (t >= duration) 76 if (t >= duration)
76 return target_value_; 77 return target_value_;
77 78
78 double progress = (timing_function_->GetValue(t / duration)); 79 double progress = (timing_function_->GetValue(t / duration));
79 return gfx::Vector2dF(gfx::Tween::FloatValueBetween( 80 return gfx::ScrollOffset(
80 progress, initial_value_.x(), target_value_.x()), 81 gfx::Tween::FloatValueBetween(
81 gfx::Tween::FloatValueBetween( 82 progress, initial_value_.x(), target_value_.x()),
82 progress, initial_value_.y(), target_value_.y())); 83 gfx::Tween::FloatValueBetween(
84 progress, initial_value_.y(), target_value_.y()));
83 } 85 }
84 86
85 double ScrollOffsetAnimationCurve::Duration() const { 87 double ScrollOffsetAnimationCurve::Duration() const {
86 return total_animation_duration_.InSecondsF(); 88 return total_animation_duration_.InSecondsF();
87 } 89 }
88 90
89 AnimationCurve::CurveType ScrollOffsetAnimationCurve::Type() const { 91 AnimationCurve::CurveType ScrollOffsetAnimationCurve::Type() const {
90 return ScrollOffset; 92 return ScrollOffset;
91 } 93 }
92 94
93 scoped_ptr<AnimationCurve> ScrollOffsetAnimationCurve::Clone() const { 95 scoped_ptr<AnimationCurve> ScrollOffsetAnimationCurve::Clone() const {
94 scoped_ptr<TimingFunction> timing_function( 96 scoped_ptr<TimingFunction> timing_function(
95 static_cast<TimingFunction*>(timing_function_->Clone().release())); 97 static_cast<TimingFunction*>(timing_function_->Clone().release()));
96 scoped_ptr<ScrollOffsetAnimationCurve> curve_clone = 98 scoped_ptr<ScrollOffsetAnimationCurve> curve_clone =
97 Create(target_value_, timing_function.Pass()); 99 Create(target_value_, timing_function.Pass());
98 curve_clone->initial_value_ = initial_value_; 100 curve_clone->initial_value_ = initial_value_;
99 curve_clone->total_animation_duration_ = total_animation_duration_; 101 curve_clone->total_animation_duration_ = total_animation_duration_;
100 curve_clone->last_retarget_ = last_retarget_; 102 curve_clone->last_retarget_ = last_retarget_;
101 return curve_clone.PassAs<AnimationCurve>(); 103 return curve_clone.PassAs<AnimationCurve>();
102 } 104 }
103 105
104 void ScrollOffsetAnimationCurve::UpdateTarget( 106 void ScrollOffsetAnimationCurve::UpdateTarget(
105 double t, 107 double t,
106 const gfx::Vector2dF& new_target) { 108 const gfx::ScrollOffset& new_target) {
107 gfx::Vector2dF current_position = GetValue(t); 109 gfx::ScrollOffset current_position = GetValue(t);
108 gfx::Vector2dF old_delta = target_value_ - initial_value_; 110 gfx::Vector2dF old_delta =
109 gfx::Vector2dF new_delta = new_target - current_position; 111 ScrollOffsetToVector2dF(target_value_ - initial_value_);
112 gfx::Vector2dF new_delta =
113 ScrollOffsetToVector2dF(new_target - current_position);
110 114
111 double old_duration = 115 double old_duration =
112 (total_animation_duration_ - last_retarget_).InSecondsF(); 116 (total_animation_duration_ - last_retarget_).InSecondsF();
113 double new_duration = DurationFromDelta(new_delta).InSecondsF(); 117 double new_duration = DurationFromDelta(new_delta).InSecondsF();
114 118
115 double old_velocity = timing_function_->Velocity( 119 double old_velocity = timing_function_->Velocity(
116 (t - last_retarget_.InSecondsF()) / old_duration); 120 (t - last_retarget_.InSecondsF()) / old_duration);
117 121
118 // TimingFunction::Velocity gives the slope of the curve from 0 to 1. 122 // TimingFunction::Velocity gives the slope of the curve from 0 to 1.
119 // To match the "true" velocity in px/sec we must adjust this slope for 123 // To match the "true" velocity in px/sec we must adjust this slope for
120 // differences in duration and scroll delta between old and new curves. 124 // differences in duration and scroll delta between old and new curves.
121 double new_velocity = 125 double new_velocity =
122 old_velocity * (new_duration / old_duration) * 126 old_velocity * (new_duration / old_duration) *
123 (MaximumDimension(old_delta) / MaximumDimension(new_delta)); 127 (MaximumDimension(old_delta) / MaximumDimension(new_delta));
124 128
125 initial_value_ = current_position; 129 initial_value_ = current_position;
126 target_value_ = new_target; 130 target_value_ = new_target;
127 total_animation_duration_ = base::TimeDelta::FromSecondsD(t + new_duration); 131 total_animation_duration_ = base::TimeDelta::FromSecondsD(t + new_duration);
128 last_retarget_ = base::TimeDelta::FromSecondsD(t); 132 last_retarget_ = base::TimeDelta::FromSecondsD(t);
129 timing_function_ = EaseOutWithInitialVelocity(new_velocity); 133 timing_function_ = EaseOutWithInitialVelocity(new_velocity);
130 } 134 }
131 135
132 } // namespace cc 136 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698