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 "cc/animation/timing_function.h" | 10 #include "cc/animation/timing_function.h" |
11 #include "ui/gfx/point_f.h" | 11 #include "ui/gfx/point_f.h" |
12 #include "ui/gfx/rect_f.h" | 12 #include "ui/gfx/rect_f.h" |
13 #include "ui/gfx/vector2d_conversions.h" | 13 #include "ui/gfx/vector2d_conversions.h" |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 // This takes a viewport-relative vector and returns a vector whose values are | 17 // 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. | 18 // between 0 and 1, representing the percentage position within the viewport. |
19 gfx::Vector2dF NormalizeFromViewport(gfx::Vector2dF denormalized, | 19 gfx::Vector2dF NormalizeFromViewport(gfx::Vector2dF denormalized, |
20 gfx::SizeF viewport_size) { | 20 const gfx::SizeF& viewport_size) { |
21 return gfx::ScaleVector2d(denormalized, | 21 return gfx::ScaleVector2d(denormalized, |
22 1.f / viewport_size.width(), | 22 1.f / viewport_size.width(), |
23 1.f / viewport_size.height()); | 23 1.f / viewport_size.height()); |
24 } | 24 } |
25 | 25 |
26 gfx::Vector2dF DenormalizeToViewport(gfx::Vector2dF normalized, | 26 gfx::Vector2dF DenormalizeToViewport(gfx::Vector2dF normalized, |
27 gfx::SizeF viewport_size) { | 27 const gfx::SizeF& viewport_size) { |
28 return gfx::ScaleVector2d(normalized, | 28 return gfx::ScaleVector2d(normalized, |
29 viewport_size.width(), | 29 viewport_size.width(), |
30 viewport_size.height()); | 30 viewport_size.height()); |
31 } | 31 } |
32 | 32 |
33 gfx::Vector2dF InterpolateBetween(gfx::Vector2dF start, | 33 gfx::Vector2dF InterpolateBetween(gfx::Vector2dF start, |
34 gfx::Vector2dF end, | 34 gfx::Vector2dF end, |
35 float interp) { | 35 float interp) { |
36 return start + gfx::ScaleVector2d(end - start, interp); | 36 return start + gfx::ScaleVector2d(end - start, interp); |
37 } | 37 } |
38 | 38 |
39 } // namespace | 39 } // namespace |
40 | 40 |
41 namespace cc { | 41 namespace cc { |
42 | 42 |
43 scoped_ptr<PageScaleAnimation> PageScaleAnimation::Create( | 43 scoped_ptr<PageScaleAnimation> PageScaleAnimation::Create( |
44 gfx::Vector2dF start_scroll_offset, | 44 gfx::Vector2dF start_scroll_offset, |
45 float start_page_scale_factor, | 45 float start_page_scale_factor, |
46 gfx::SizeF viewport_size, | 46 const gfx::SizeF& viewport_size, |
47 gfx::SizeF root_layer_size, | 47 const gfx::SizeF& root_layer_size, |
48 scoped_ptr<TimingFunction> timing_function) { | 48 scoped_ptr<TimingFunction> timing_function) { |
49 return make_scoped_ptr(new PageScaleAnimation(start_scroll_offset, | 49 return make_scoped_ptr(new PageScaleAnimation(start_scroll_offset, |
50 start_page_scale_factor, | 50 start_page_scale_factor, |
51 viewport_size, | 51 viewport_size, |
52 root_layer_size, | 52 root_layer_size, |
53 timing_function.Pass())); | 53 timing_function.Pass())); |
54 } | 54 } |
55 | 55 |
56 PageScaleAnimation::PageScaleAnimation( | 56 PageScaleAnimation::PageScaleAnimation( |
57 gfx::Vector2dF start_scroll_offset, | 57 gfx::Vector2dF start_scroll_offset, |
58 float start_page_scale_factor, | 58 float start_page_scale_factor, |
59 gfx::SizeF viewport_size, | 59 const gfx::SizeF& viewport_size, |
60 gfx::SizeF root_layer_size, | 60 const gfx::SizeF& root_layer_size, |
61 scoped_ptr<TimingFunction> timing_function) | 61 scoped_ptr<TimingFunction> timing_function) |
62 : start_page_scale_factor_(start_page_scale_factor), | 62 : start_page_scale_factor_(start_page_scale_factor), |
63 target_page_scale_factor_(0.f), | 63 target_page_scale_factor_(0.f), |
64 start_scroll_offset_(start_scroll_offset), | 64 start_scroll_offset_(start_scroll_offset), |
65 start_anchor_(), | 65 start_anchor_(), |
66 target_anchor_(), | 66 target_anchor_(), |
67 viewport_size_(viewport_size), | 67 viewport_size_(viewport_size), |
68 root_layer_size_(root_layer_size), | 68 root_layer_size_(root_layer_size), |
69 start_time_(-1.0), | 69 start_time_(-1.0), |
70 duration_(0.0), | 70 duration_(0.0), |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 | 233 |
234 // Linearly interpolate the magnitude in log scale. | 234 // Linearly interpolate the magnitude in log scale. |
235 float diff = target_page_scale_factor_ / start_page_scale_factor_; | 235 float diff = target_page_scale_factor_ / start_page_scale_factor_; |
236 float log_diff = log(diff); | 236 float log_diff = log(diff); |
237 log_diff *= interp; | 237 log_diff *= interp; |
238 diff = exp(log_diff); | 238 diff = exp(log_diff); |
239 return start_page_scale_factor_ * diff; | 239 return start_page_scale_factor_ * diff; |
240 } | 240 } |
241 | 241 |
242 } // namespace cc | 242 } // namespace cc |
OLD | NEW |