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

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

Issue 1057283003: Remove parts of //cc we aren't using (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 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
« no previous file with comments | « cc/input/layer_selection_bound.cc ('k') | cc/input/page_scale_animation.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CC_INPUT_PAGE_SCALE_ANIMATION_H_
6 #define CC_INPUT_PAGE_SCALE_ANIMATION_H_
7
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/time/time.h"
11 #include "cc/base/cc_export.h"
12 #include "ui/gfx/geometry/size.h"
13 #include "ui/gfx/geometry/vector2d.h"
14 #include "ui/gfx/geometry/vector2d_f.h"
15
16 namespace cc {
17
18 class TimingFunction;
19
20 // Used in the CC to pass around a scale animation that hasn't yet been
21 // initialized.
22 struct PendingPageScaleAnimation {
23 PendingPageScaleAnimation(
24 const gfx::Vector2d _target_offset,
25 bool _use_anchor,
26 float _scale,
27 const base::TimeDelta& _duration)
28 : target_offset(_target_offset),
29 use_anchor(_use_anchor),
30 scale(_scale),
31 duration(_duration) {}
32 gfx::Vector2d target_offset;
33 bool use_anchor;
34 float scale;
35 base::TimeDelta duration;
36 };
37
38 // A small helper class that does the math for zoom animations, primarily for
39 // double-tap zoom. Initialize it with starting and ending scroll/page scale
40 // positions and an animation length time, then call ...AtTime() at every frame
41 // to obtain the current interpolated position. The supplied timing function
42 // is used to ease the animation.
43 //
44 // All sizes and vectors in this class's public methods are in the root scroll
45 // layer's coordinate space.
46 class CC_EXPORT PageScaleAnimation {
47 public:
48 // Construct with the state at the beginning of the animation.
49 static scoped_ptr<PageScaleAnimation> Create(
50 const gfx::Vector2dF& start_scroll_offset,
51 float start_page_scale_factor,
52 const gfx::SizeF& viewport_size,
53 const gfx::SizeF& root_layer_size,
54 scoped_ptr<TimingFunction> timing_function);
55
56 ~PageScaleAnimation();
57
58 // The following methods initialize the animation. Call one of them
59 // immediately after construction to set the final scroll and page scale.
60
61 // Zoom while explicitly specifying the top-left scroll position.
62 void ZoomTo(const gfx::Vector2dF& target_scroll_offset,
63 float target_page_scale_factor,
64 double duration);
65
66 // Zoom based on a specified anchor. The animator will attempt to keep it
67 // at the same position on the physical display throughout the animation,
68 // unless the edges of the root layer are hit. The anchor is specified
69 // as an offset from the content layer.
70 void ZoomWithAnchor(const gfx::Vector2dF& anchor,
71 float target_page_scale_factor,
72 double duration);
73
74 // These should be called before the first frame of animation to initialize
75 // the start time. StartAnimation should only be called once after creation.
76 bool IsAnimationStarted() const;
77 void StartAnimation(base::TimeTicks time);
78
79 // Call these functions while the animation is in progress to output the
80 // current state.
81 gfx::Vector2dF ScrollOffsetAtTime(base::TimeTicks time) const;
82 float PageScaleFactorAtTime(base::TimeTicks time) const;
83 bool IsAnimationCompleteAtTime(base::TimeTicks time) const;
84
85 // The following methods return state which is invariant throughout the
86 // course of the animation.
87 base::TimeTicks start_time() const { return start_time_; }
88 base::TimeDelta duration() const { return duration_; }
89 base::TimeTicks end_time() const { return start_time_ + duration_; }
90 gfx::Vector2dF target_scroll_offset() const { return target_scroll_offset_; }
91 float target_page_scale_factor() const { return target_page_scale_factor_; }
92
93 protected:
94 PageScaleAnimation(const gfx::Vector2dF& start_scroll_offset,
95 float start_page_scale_factor,
96 const gfx::SizeF& viewport_size,
97 const gfx::SizeF& root_layer_size,
98 scoped_ptr<TimingFunction> timing_function);
99
100 private:
101 void ClampTargetScrollOffset();
102 void InferTargetScrollOffsetFromStartAnchor();
103 void InferTargetAnchorFromScrollOffsets();
104
105 gfx::SizeF StartViewportSize() const;
106 gfx::SizeF TargetViewportSize() const;
107 float InterpAtTime(base::TimeTicks time) const;
108 gfx::SizeF ViewportSizeAt(float interp) const;
109 gfx::Vector2dF ScrollOffsetAt(float interp) const;
110 gfx::Vector2dF AnchorAt(float interp) const;
111 gfx::Vector2dF ViewportRelativeAnchorAt(float interp) const;
112 float PageScaleFactorAt(float interp) const;
113
114 float start_page_scale_factor_;
115 float target_page_scale_factor_;
116 gfx::Vector2dF start_scroll_offset_;
117 gfx::Vector2dF target_scroll_offset_;
118
119 gfx::Vector2dF start_anchor_;
120 gfx::Vector2dF target_anchor_;
121
122 gfx::SizeF viewport_size_;
123 gfx::SizeF root_layer_size_;
124
125 base::TimeTicks start_time_;
126 base::TimeDelta duration_;
127
128 scoped_ptr<TimingFunction> timing_function_;
129
130 DISALLOW_COPY_AND_ASSIGN(PageScaleAnimation);
131 };
132
133 } // namespace cc
134
135 #endif // CC_INPUT_PAGE_SCALE_ANIMATION_H_
OLDNEW
« no previous file with comments | « cc/input/layer_selection_bound.cc ('k') | cc/input/page_scale_animation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698