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

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

Issue 1866203004: Convert //cc from scoped_ptr to std::unique_ptr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: scopedptrcc: rebase Created 4 years, 8 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"
11 #include "base/memory/ptr_util.h"
11 #include "cc/animation/timing_function.h" 12 #include "cc/animation/timing_function.h"
12 #include "cc/base/time_util.h" 13 #include "cc/base/time_util.h"
13 #include "ui/gfx/animation/tween.h" 14 #include "ui/gfx/animation/tween.h"
14 15
15 using DurationBehavior = cc::ScrollOffsetAnimationCurve::DurationBehavior; 16 using DurationBehavior = cc::ScrollOffsetAnimationCurve::DurationBehavior;
16 17
17 const double kConstantDuration = 9.0; 18 const double kConstantDuration = 9.0;
18 const double kDurationDivisor = 60.0; 19 const double kDurationDivisor = 60.0;
19 20
20 const double kInverseDeltaRampStartPx = 120.0; 21 const double kInverseDeltaRampStartPx = 120.0;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 kInverseDeltaMinDuration), 57 kInverseDeltaMinDuration),
57 kInverseDeltaMaxDuration); 58 kInverseDeltaMaxDuration);
58 break; 59 break;
59 default: 60 default:
60 NOTREACHED(); 61 NOTREACHED();
61 } 62 }
62 return base::TimeDelta::FromMicroseconds(duration / kDurationDivisor * 63 return base::TimeDelta::FromMicroseconds(duration / kDurationDivisor *
63 base::Time::kMicrosecondsPerSecond); 64 base::Time::kMicrosecondsPerSecond);
64 } 65 }
65 66
66 static scoped_ptr<TimingFunction> EaseOutWithInitialVelocity(double velocity) { 67 static std::unique_ptr<TimingFunction> EaseOutWithInitialVelocity(
68 double velocity) {
67 // Clamp velocity to a sane value. 69 // Clamp velocity to a sane value.
68 velocity = std::min(std::max(velocity, -1000.0), 1000.0); 70 velocity = std::min(std::max(velocity, -1000.0), 1000.0);
69 71
70 // Based on EaseInOutTimingFunction::Create with first control point scaled. 72 // Based on EaseInOutTimingFunction::Create with first control point scaled.
71 const double x1 = 0.42; 73 const double x1 = 0.42;
72 const double y1 = velocity * x1; 74 const double y1 = velocity * x1;
73 return CubicBezierTimingFunction::Create(x1, y1, 0.58, 1); 75 return CubicBezierTimingFunction::Create(x1, y1, 0.58, 1);
74 } 76 }
75 77
76 } // namespace 78 } // namespace
77 79
78 scoped_ptr<ScrollOffsetAnimationCurve> ScrollOffsetAnimationCurve::Create( 80 std::unique_ptr<ScrollOffsetAnimationCurve> ScrollOffsetAnimationCurve::Create(
79 const gfx::ScrollOffset& target_value, 81 const gfx::ScrollOffset& target_value,
80 scoped_ptr<TimingFunction> timing_function, 82 std::unique_ptr<TimingFunction> timing_function,
81 DurationBehavior duration_behavior) { 83 DurationBehavior duration_behavior) {
82 return make_scoped_ptr(new ScrollOffsetAnimationCurve( 84 return base::WrapUnique(new ScrollOffsetAnimationCurve(
83 target_value, std::move(timing_function), duration_behavior)); 85 target_value, std::move(timing_function), duration_behavior));
84 } 86 }
85 87
86 ScrollOffsetAnimationCurve::ScrollOffsetAnimationCurve( 88 ScrollOffsetAnimationCurve::ScrollOffsetAnimationCurve(
87 const gfx::ScrollOffset& target_value, 89 const gfx::ScrollOffset& target_value,
88 scoped_ptr<TimingFunction> timing_function, 90 std::unique_ptr<TimingFunction> timing_function,
89 DurationBehavior duration_behavior) 91 DurationBehavior duration_behavior)
90 : target_value_(target_value), 92 : target_value_(target_value),
91 timing_function_(std::move(timing_function)), 93 timing_function_(std::move(timing_function)),
92 duration_behavior_(duration_behavior), 94 duration_behavior_(duration_behavior),
93 has_set_initial_value_(false) {} 95 has_set_initial_value_(false) {}
94 96
95 ScrollOffsetAnimationCurve::~ScrollOffsetAnimationCurve() {} 97 ScrollOffsetAnimationCurve::~ScrollOffsetAnimationCurve() {}
96 98
97 void ScrollOffsetAnimationCurve::SetInitialValue( 99 void ScrollOffsetAnimationCurve::SetInitialValue(
98 const gfx::ScrollOffset& initial_value) { 100 const gfx::ScrollOffset& initial_value) {
(...skipping 27 matching lines...) Expand all
126 } 128 }
127 129
128 base::TimeDelta ScrollOffsetAnimationCurve::Duration() const { 130 base::TimeDelta ScrollOffsetAnimationCurve::Duration() const {
129 return total_animation_duration_; 131 return total_animation_duration_;
130 } 132 }
131 133
132 AnimationCurve::CurveType ScrollOffsetAnimationCurve::Type() const { 134 AnimationCurve::CurveType ScrollOffsetAnimationCurve::Type() const {
133 return SCROLL_OFFSET; 135 return SCROLL_OFFSET;
134 } 136 }
135 137
136 scoped_ptr<AnimationCurve> ScrollOffsetAnimationCurve::Clone() const { 138 std::unique_ptr<AnimationCurve> ScrollOffsetAnimationCurve::Clone() const {
137 return CloneToScrollOffsetAnimationCurve(); 139 return CloneToScrollOffsetAnimationCurve();
138 } 140 }
139 141
140 scoped_ptr<ScrollOffsetAnimationCurve> 142 std::unique_ptr<ScrollOffsetAnimationCurve>
141 ScrollOffsetAnimationCurve::CloneToScrollOffsetAnimationCurve() const { 143 ScrollOffsetAnimationCurve::CloneToScrollOffsetAnimationCurve() const {
142 scoped_ptr<TimingFunction> timing_function( 144 std::unique_ptr<TimingFunction> timing_function(
143 static_cast<TimingFunction*>(timing_function_->Clone().release())); 145 static_cast<TimingFunction*>(timing_function_->Clone().release()));
144 scoped_ptr<ScrollOffsetAnimationCurve> curve_clone = 146 std::unique_ptr<ScrollOffsetAnimationCurve> curve_clone =
145 Create(target_value_, std::move(timing_function), duration_behavior_); 147 Create(target_value_, std::move(timing_function), duration_behavior_);
146 curve_clone->initial_value_ = initial_value_; 148 curve_clone->initial_value_ = initial_value_;
147 curve_clone->total_animation_duration_ = total_animation_duration_; 149 curve_clone->total_animation_duration_ = total_animation_duration_;
148 curve_clone->last_retarget_ = last_retarget_; 150 curve_clone->last_retarget_ = last_retarget_;
149 curve_clone->has_set_initial_value_ = has_set_initial_value_; 151 curve_clone->has_set_initial_value_ = has_set_initial_value_;
150 return curve_clone; 152 return curve_clone;
151 } 153 }
152 154
153 static double VelocityBasedDurationBound(gfx::Vector2dF old_delta, 155 static double VelocityBasedDurationBound(gfx::Vector2dF old_delta,
154 double old_normalized_velocity, 156 double old_normalized_velocity,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 (MaximumDimension(old_delta) / MaximumDimension(new_delta)); 215 (MaximumDimension(old_delta) / MaximumDimension(new_delta));
214 216
215 initial_value_ = current_position; 217 initial_value_ = current_position;
216 target_value_ = new_target; 218 target_value_ = new_target;
217 total_animation_duration_ = base::TimeDelta::FromSecondsD(t + new_duration); 219 total_animation_duration_ = base::TimeDelta::FromSecondsD(t + new_duration);
218 last_retarget_ = base::TimeDelta::FromSecondsD(t); 220 last_retarget_ = base::TimeDelta::FromSecondsD(t);
219 timing_function_ = EaseOutWithInitialVelocity(new_normalized_velocity); 221 timing_function_ = EaseOutWithInitialVelocity(new_normalized_velocity);
220 } 222 }
221 223
222 } // namespace cc 224 } // 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