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

Side by Side Diff: cc/input/page_scale_animation.cc

Issue 130443005: [#5] Pass gfx structs by const ref (gfx::Vector2dF) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporated the review comments Created 6 years, 11 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
« no previous file with comments | « cc/input/page_scale_animation.h ('k') | cc/input/top_controls_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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(const gfx::Vector2dF& denormalized,
20 const 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(const gfx::Vector2dF& normalized,
27 const 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(const gfx::Vector2dF& start,
34 gfx::Vector2dF end, 34 const 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 const gfx::Vector2dF& start_scroll_offset,
45 float start_page_scale_factor, 45 float start_page_scale_factor,
46 const gfx::SizeF& viewport_size, 46 const gfx::SizeF& viewport_size,
47 const 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 const gfx::Vector2dF& start_scroll_offset,
58 float start_page_scale_factor, 58 float start_page_scale_factor,
59 const gfx::SizeF& viewport_size, 59 const gfx::SizeF& viewport_size,
60 const 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),
71 timing_function_(timing_function.Pass()) {} 71 timing_function_(timing_function.Pass()) {}
72 72
73 PageScaleAnimation::~PageScaleAnimation() {} 73 PageScaleAnimation::~PageScaleAnimation() {}
74 74
75 void PageScaleAnimation::ZoomTo(gfx::Vector2dF target_scroll_offset, 75 void PageScaleAnimation::ZoomTo(const gfx::Vector2dF& target_scroll_offset,
76 float target_page_scale_factor, 76 float target_page_scale_factor,
77 double duration) { 77 double duration) {
78 target_page_scale_factor_ = target_page_scale_factor; 78 target_page_scale_factor_ = target_page_scale_factor;
79 target_scroll_offset_ = target_scroll_offset; 79 target_scroll_offset_ = target_scroll_offset;
80 ClampTargetScrollOffset(); 80 ClampTargetScrollOffset();
81 duration_ = duration; 81 duration_ = duration;
82 82
83 if (start_page_scale_factor_ == target_page_scale_factor) { 83 if (start_page_scale_factor_ == target_page_scale_factor) {
84 start_anchor_ = start_scroll_offset_; 84 start_anchor_ = start_scroll_offset_;
85 target_anchor_ = target_scroll_offset; 85 target_anchor_ = target_scroll_offset;
86 return; 86 return;
87 } 87 }
88 88
89 // For uniform-looking zooming, infer an anchor from the start and target 89 // For uniform-looking zooming, infer an anchor from the start and target
90 // viewport rects. 90 // viewport rects.
91 InferTargetAnchorFromScrollOffsets(); 91 InferTargetAnchorFromScrollOffsets();
92 start_anchor_ = target_anchor_; 92 start_anchor_ = target_anchor_;
93 } 93 }
94 94
95 void PageScaleAnimation::ZoomWithAnchor(gfx::Vector2dF anchor, 95 void PageScaleAnimation::ZoomWithAnchor(const gfx::Vector2dF& anchor,
96 float target_page_scale_factor, 96 float target_page_scale_factor,
97 double duration) { 97 double duration) {
98 start_anchor_ = anchor; 98 start_anchor_ = anchor;
99 target_page_scale_factor_ = target_page_scale_factor; 99 target_page_scale_factor_ = target_page_scale_factor;
100 duration_ = duration; 100 duration_ = duration;
101 101
102 // We start zooming out from the anchor tapped by the user. But if 102 // We start zooming out from the anchor tapped by the user. But if
103 // the target scale is impossible to attain without hitting the root layer 103 // the target scale is impossible to attain without hitting the root layer
104 // edges, then infer an anchor that doesn't collide with the edges. 104 // edges, then infer an anchor that doesn't collide with the edges.
105 // We will interpolate between the two anchors during the animation. 105 // We will interpolate between the two anchors during the animation.
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « cc/input/page_scale_animation.h ('k') | cc/input/top_controls_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698