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 "IntSize.h" | 9 #include "ui/gfx/size.h" |
| 10 #include "ui/gfx/vector2d.h" |
10 | 11 |
11 namespace cc { | 12 namespace cc { |
12 | 13 |
13 // 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 |
14 // 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 |
15 // 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 |
16 // to obtain the current interpolated position. | 17 // to obtain the current interpolated position. |
17 class PageScaleAnimation { | 18 class PageScaleAnimation { |
18 public: | 19 public: |
19 // Construct with the starting page scale and scroll offset (which is in | 20 // Construct with the starting page scale and scroll offset (which is in |
20 // pageScaleStart space). The window size is the user-viewable area | 21 // pageScaleStart space). The window size is the user-viewable area |
21 // in pixels. | 22 // in pixels. |
22 static scoped_ptr<PageScaleAnimation> create(const IntSize& scrollStart, flo
at pageScaleStart, const gfx::Size& windowSize, const gfx::Size& contentSize, do
uble startTime); | 23 static scoped_ptr<PageScaleAnimation> create(gfx::Vector2d scrollStart, floa
t pageScaleStart, const gfx::Size& windowSize, const gfx::Size& contentSize, dou
ble startTime); |
23 ~PageScaleAnimation(); | 24 ~PageScaleAnimation(); |
24 | 25 |
25 // The following methods initialize the animation. Call one of them | 26 // The following methods initialize the animation. Call one of them |
26 // immediately after construction to set the final scroll and page scale. | 27 // immediately after construction to set the final scroll and page scale. |
27 | 28 |
28 // Zoom while explicitly specifying the top-left scroll position. The | 29 // Zoom while explicitly specifying the top-left scroll position. The |
29 // scroll offset is in finalPageScale coordinates. | 30 // scroll offset is in finalPageScale coordinates. |
30 void zoomTo(const IntSize& finalScroll, float finalPageScale, double duratio
n); | 31 void zoomTo(gfx::Vector2d finalScroll, float finalPageScale, double duration
); |
31 | 32 |
32 // Zoom based on a specified onscreen anchor, which will remain at the same | 33 // Zoom based on a specified onscreen anchor, which will remain at the same |
33 // position on the screen throughout the animation. The anchor is in local | 34 // position on the screen throughout the animation. The anchor is in local |
34 // space relative to scrollStart. | 35 // space relative to scrollStart. |
35 void zoomWithAnchor(const IntSize& anchor, float finalPageScale, double dura
tion); | 36 void zoomWithAnchor(gfx::Vector2d anchor, float finalPageScale, double durat
ion); |
36 | 37 |
37 // Call these functions while the animation is in progress to output the | 38 // Call these functions while the animation is in progress to output the |
38 // current state. | 39 // current state. |
39 IntSize scrollOffsetAtTime(double time) const; | 40 gfx::Vector2d scrollOffsetAtTime(double time) const; |
40 float pageScaleAtTime(double time) const; | 41 float pageScaleAtTime(double time) const; |
41 bool isAnimationCompleteAtTime(double time) const; | 42 bool isAnimationCompleteAtTime(double time) const; |
42 | 43 |
43 // The following methods return state which is invariant throughout the | 44 // The following methods return state which is invariant throughout the |
44 // course of the animation. | 45 // course of the animation. |
45 double startTime() const { return m_startTime; } | 46 double startTime() const { return m_startTime; } |
46 double duration() const { return m_duration; } | 47 double duration() const { return m_duration; } |
47 double endTime() const { return m_startTime + m_duration; } | 48 double endTime() const { return m_startTime + m_duration; } |
48 const IntSize& finalScrollOffset() const { return m_scrollEnd; } | 49 gfx::Vector2d finalScrollOffset() const { return m_scrollEnd; } |
49 float finalPageScale() const { return m_pageScaleEnd; } | 50 float finalPageScale() const { return m_pageScaleEnd; } |
50 | 51 |
51 protected: | 52 protected: |
52 PageScaleAnimation(const IntSize& scrollStart, float pageScaleStart, const g
fx::Size& windowSize, const gfx::Size& contentSize, double startTime); | 53 PageScaleAnimation(gfx::Vector2d scrollStart, float pageScaleStart, const gf
x::Size& windowSize, const gfx::Size& contentSize, double startTime); |
53 | 54 |
54 private: | 55 private: |
55 float progressRatioForTime(double time) const; | 56 float progressRatioForTime(double time) const; |
56 IntSize scrollOffsetAtRatio(float ratio) const; | 57 gfx::Vector2d scrollOffsetAtRatio(float ratio) const; |
57 float pageScaleAtRatio(float ratio) const; | 58 float pageScaleAtRatio(float ratio) const; |
58 | 59 |
59 IntSize m_scrollStart; | 60 gfx::Vector2d m_scrollStart; |
60 float m_pageScaleStart; | 61 float m_pageScaleStart; |
61 gfx::Size m_windowSize; | 62 gfx::Size m_windowSize; |
62 gfx::Size m_contentSize; | 63 gfx::Size m_contentSize; |
63 | 64 |
64 bool m_anchorMode; | 65 bool m_anchorMode; |
65 IntSize m_anchor; | 66 gfx::Vector2d m_anchor; |
66 IntSize m_scrollEnd; | 67 gfx::Vector2d m_scrollEnd; |
67 float m_pageScaleEnd; | 68 float m_pageScaleEnd; |
68 | 69 |
69 double m_startTime; | 70 double m_startTime; |
70 double m_duration; | 71 double m_duration; |
71 }; | 72 }; |
72 | 73 |
73 } // namespace cc | 74 } // namespace cc |
74 | 75 |
75 #endif // CC_PAGE_SCALE_ANIMATION_H_ | 76 #endif // CC_PAGE_SCALE_ANIMATION_H_ |
OLD | NEW |