OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/input/page_scale_animation.h" | 5 #include "cc/input/page_scale_animation.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ptr_util.h" |
10 #include "cc/animation/timing_function.h" | 11 #include "cc/animation/timing_function.h" |
11 #include "ui/gfx/geometry/point_f.h" | 12 #include "ui/gfx/geometry/point_f.h" |
12 #include "ui/gfx/geometry/rect_f.h" | 13 #include "ui/gfx/geometry/rect_f.h" |
13 #include "ui/gfx/geometry/vector2d_conversions.h" | 14 #include "ui/gfx/geometry/vector2d_conversions.h" |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 // This takes a viewport-relative vector and returns a vector whose values are | 18 // This takes a viewport-relative vector and returns a vector whose values are |
18 // between 0 and 1, representing the percentage position within the viewport. | 19 // between 0 and 1, representing the percentage position within the viewport. |
19 gfx::Vector2dF NormalizeFromViewport(const gfx::Vector2dF& denormalized, | 20 gfx::Vector2dF NormalizeFromViewport(const gfx::Vector2dF& denormalized, |
(...skipping 16 matching lines...) Expand all Loading... |
36 return start + gfx::ScaleVector2d(end - start, interp); | 37 return start + gfx::ScaleVector2d(end - start, interp); |
37 } | 38 } |
38 | 39 |
39 } // namespace | 40 } // namespace |
40 | 41 |
41 namespace cc { | 42 namespace cc { |
42 | 43 |
43 using base::TimeTicks; | 44 using base::TimeTicks; |
44 using base::TimeDelta; | 45 using base::TimeDelta; |
45 | 46 |
46 scoped_ptr<PageScaleAnimation> PageScaleAnimation::Create( | 47 std::unique_ptr<PageScaleAnimation> PageScaleAnimation::Create( |
47 const gfx::Vector2dF& start_scroll_offset, | 48 const gfx::Vector2dF& start_scroll_offset, |
48 float start_page_scale_factor, | 49 float start_page_scale_factor, |
49 const gfx::SizeF& viewport_size, | 50 const gfx::SizeF& viewport_size, |
50 const gfx::SizeF& root_layer_size, | 51 const gfx::SizeF& root_layer_size, |
51 scoped_ptr<TimingFunction> timing_function) { | 52 std::unique_ptr<TimingFunction> timing_function) { |
52 return make_scoped_ptr(new PageScaleAnimation( | 53 return base::WrapUnique(new PageScaleAnimation( |
53 start_scroll_offset, start_page_scale_factor, viewport_size, | 54 start_scroll_offset, start_page_scale_factor, viewport_size, |
54 root_layer_size, std::move(timing_function))); | 55 root_layer_size, std::move(timing_function))); |
55 } | 56 } |
56 | 57 |
57 PageScaleAnimation::PageScaleAnimation( | 58 PageScaleAnimation::PageScaleAnimation( |
58 const gfx::Vector2dF& start_scroll_offset, | 59 const gfx::Vector2dF& start_scroll_offset, |
59 float start_page_scale_factor, | 60 float start_page_scale_factor, |
60 const gfx::SizeF& viewport_size, | 61 const gfx::SizeF& viewport_size, |
61 const gfx::SizeF& root_layer_size, | 62 const gfx::SizeF& root_layer_size, |
62 scoped_ptr<TimingFunction> timing_function) | 63 std::unique_ptr<TimingFunction> timing_function) |
63 : start_page_scale_factor_(start_page_scale_factor), | 64 : start_page_scale_factor_(start_page_scale_factor), |
64 target_page_scale_factor_(0.f), | 65 target_page_scale_factor_(0.f), |
65 start_scroll_offset_(start_scroll_offset), | 66 start_scroll_offset_(start_scroll_offset), |
66 start_anchor_(), | 67 start_anchor_(), |
67 target_anchor_(), | 68 target_anchor_(), |
68 viewport_size_(viewport_size), | 69 viewport_size_(viewport_size), |
69 root_layer_size_(root_layer_size), | 70 root_layer_size_(root_layer_size), |
70 timing_function_(std::move(timing_function)) {} | 71 timing_function_(std::move(timing_function)) {} |
71 | 72 |
72 PageScaleAnimation::~PageScaleAnimation() {} | 73 PageScaleAnimation::~PageScaleAnimation() {} |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 | 234 |
234 // Linearly interpolate the magnitude in log scale. | 235 // Linearly interpolate the magnitude in log scale. |
235 float diff = target_page_scale_factor_ / start_page_scale_factor_; | 236 float diff = target_page_scale_factor_ / start_page_scale_factor_; |
236 float log_diff = log(diff); | 237 float log_diff = log(diff); |
237 log_diff *= interp; | 238 log_diff *= interp; |
238 diff = exp(log_diff); | 239 diff = exp(log_diff); |
239 return start_page_scale_factor_ * diff; | 240 return start_page_scale_factor_ * diff; |
240 } | 241 } |
241 | 242 |
242 } // namespace cc | 243 } // namespace cc |
OLD | NEW |