OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CC_PAGE_SCALE_ANIMATION_H_ | 5 #ifndef CC_PAGE_SCALE_ANIMATION_H_ |
6 #define CC_PAGE_SCALE_ANIMATION_H_ | 6 #define CC_PAGE_SCALE_ANIMATION_H_ |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "ui/gfx/size.h" | 9 #include "ui/gfx/size.h" |
10 #include "ui/gfx/vector2d.h" | 10 #include "ui/gfx/vector2d_f.h" |
11 | 11 |
12 namespace cc { | 12 namespace cc { |
13 | 13 |
14 // A small helper class that does the math for zoom animations, primarily for | 14 // A small helper class that does the math for zoom animations, primarily for |
15 // double-tap zoom. Initialize it with starting and ending scroll/page scale | 15 // double-tap zoom. Initialize it with starting and ending scroll/page scale |
16 // positions and an animation length time, then call ...AtTime() at every frame | 16 // positions and an animation length time, then call ...AtTime() at every frame |
17 // to obtain the current interpolated position. | 17 // to obtain the current interpolated position. |
| 18 // |
| 19 // All sizes and vectors in this class's public methods are in the root scroll |
| 20 // layer's coordinate space. |
18 class PageScaleAnimation { | 21 class PageScaleAnimation { |
19 public: | 22 public: |
20 // Construct with the starting page scale and scroll offset (which is in | 23 // Construct with the state at the beginning of the animation. |
21 // pageScaleStart space). The window size is the user-viewable area | 24 static scoped_ptr<PageScaleAnimation> create(const gfx::Vector2dF& startScro
llOffset, float startPageScaleFactor, const gfx::SizeF& viewportSize, const gfx:
:SizeF& rootLayerSize, double startTime); |
22 // in pixels. | 25 |
23 static scoped_ptr<PageScaleAnimation> create(gfx::Vector2d scrollStart, floa
t pageScaleStart, const gfx::Size& windowSize, const gfx::Size& contentSize, dou
ble startTime); | |
24 ~PageScaleAnimation(); | 26 ~PageScaleAnimation(); |
25 | 27 |
26 // The following methods initialize the animation. Call one of them | 28 // The following methods initialize the animation. Call one of them |
27 // immediately after construction to set the final scroll and page scale. | 29 // immediately after construction to set the final scroll and page scale. |
28 | 30 |
29 // Zoom while explicitly specifying the top-left scroll position. The | 31 // Zoom while explicitly specifying the top-left scroll position. |
30 // scroll offset is in finalPageScale coordinates. | 32 void zoomTo(const gfx::Vector2dF& targetScrollOffset, float targetPageScaleF
actor, double duration); |
31 void zoomTo(gfx::Vector2d finalScroll, float finalPageScale, double duration
); | |
32 | 33 |
33 // Zoom based on a specified onscreen anchor, which will remain at the same | 34 // Zoom based on a specified anchor. The animator will attempt to keep it |
34 // position on the screen throughout the animation. The anchor is in local | 35 // at the same position on the physical display throughout the animation, |
35 // space relative to scrollStart. | 36 // unless the edges of the root layer are hit. The anchor is specified |
36 void zoomWithAnchor(gfx::Vector2d anchor, float finalPageScale, double durat
ion); | 37 // as an offset from the content layer. |
| 38 void zoomWithAnchor(const gfx::Vector2dF& anchor, float targetPageScaleFacto
r, double duration); |
37 | 39 |
38 // Call these functions while the animation is in progress to output the | 40 // Call these functions while the animation is in progress to output the |
39 // current state. | 41 // current state. |
40 gfx::Vector2d scrollOffsetAtTime(double time) const; | 42 gfx::Vector2dF scrollOffsetAtTime(double time) const; |
41 float pageScaleAtTime(double time) const; | 43 float pageScaleFactorAtTime(double time) const; |
42 bool isAnimationCompleteAtTime(double time) const; | 44 bool isAnimationCompleteAtTime(double time) const; |
43 | 45 |
44 // The following methods return state which is invariant throughout the | 46 // The following methods return state which is invariant throughout the |
45 // course of the animation. | 47 // course of the animation. |
46 double startTime() const { return m_startTime; } | 48 double startTime() const { return m_startTime; } |
47 double duration() const { return m_duration; } | 49 double duration() const { return m_duration; } |
48 double endTime() const { return m_startTime + m_duration; } | 50 double endTime() const { return m_startTime + m_duration; } |
49 gfx::Vector2d finalScrollOffset() const { return m_scrollEnd; } | 51 const gfx::Vector2dF& targetScrollOffset() const { return m_targetScrollOffs
et; } |
50 float finalPageScale() const { return m_pageScaleEnd; } | 52 float targetPageScaleFactor() const { return m_targetPageScaleFactor; } |
51 | 53 |
52 protected: | 54 protected: |
53 PageScaleAnimation(gfx::Vector2d scrollStart, float pageScaleStart, const gf
x::Size& windowSize, const gfx::Size& contentSize, double startTime); | 55 PageScaleAnimation(const gfx::Vector2dF& startScrollOffset, float startPageS
caleFactor, const gfx::SizeF& viewportSize, const gfx::SizeF& rootLayerSize, dou
ble startTime); |
54 | 56 |
55 private: | 57 private: |
56 float progressRatioForTime(double time) const; | 58 void clampTargetScrollOffset(); |
57 gfx::Vector2d scrollOffsetAtRatio(float ratio) const; | 59 void inferTargetScrollOffsetFromStartAnchor(); |
58 float pageScaleAtRatio(float ratio) const; | 60 void inferTargetAnchorFromScrollOffsets(); |
| 61 gfx::SizeF viewportSizeAtScale(float pageScaleFactor) const; |
59 | 62 |
60 gfx::Vector2d m_scrollStart; | 63 float interpAtTime(double time) const; |
61 float m_pageScaleStart; | 64 gfx::Vector2dF scrollOffsetAt(float interp) const; |
62 gfx::Size m_windowSize; | 65 gfx::Vector2dF anchorAt(float interp) const; |
63 gfx::Size m_contentSize; | 66 gfx::Vector2dF viewportRelativeAnchorAt(float interp) const; |
| 67 float pageScaleFactorAt(float interp) const; |
64 | 68 |
65 bool m_anchorMode; | 69 float m_startPageScaleFactor; |
66 gfx::Vector2d m_anchor; | 70 float m_targetPageScaleFactor; |
67 gfx::Vector2d m_scrollEnd; | 71 gfx::Vector2dF m_startScrollOffset; |
68 float m_pageScaleEnd; | 72 gfx::Vector2dF m_targetScrollOffset; |
| 73 |
| 74 gfx::Vector2dF m_startAnchor; |
| 75 gfx::Vector2dF m_targetAnchor; |
| 76 |
| 77 gfx::SizeF m_viewportSize; |
| 78 gfx::SizeF m_rootLayerSize; |
69 | 79 |
70 double m_startTime; | 80 double m_startTime; |
71 double m_duration; | 81 double m_duration; |
72 }; | 82 }; |
73 | 83 |
74 } // namespace cc | 84 } // namespace cc |
75 | 85 |
76 #endif // CC_PAGE_SCALE_ANIMATION_H_ | 86 #endif // CC_PAGE_SCALE_ANIMATION_H_ |
OLD | NEW |