OLD | NEW |
1 // Copyright 2011 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 #ifndef CCPageScaleAnimation_h | 5 // Temporary forwarding header |
6 #define CCPageScaleAnimation_h | 6 #include "cc/page_scale_animation.h" |
7 | |
8 #include "IntSize.h" | |
9 #include <wtf/PassOwnPtr.h> | |
10 | |
11 namespace cc { | |
12 | |
13 // 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 // positions and an animation length time, then call ...AtTime() at every frame | |
16 // to obtain the current interpolated position. | |
17 class CCPageScaleAnimation { | |
18 public: | |
19 // Construct with the starting page scale and scroll offset (which is in | |
20 // pageScaleStart space). The window size is the user-viewable area | |
21 // in pixels. | |
22 static PassOwnPtr<CCPageScaleAnimation> create(const IntSize& scrollStart, f
loat pageScaleStart, const IntSize& windowSize, const IntSize& contentSize, doub
le startTime); | |
23 | |
24 // The following methods initialize the animation. Call one of them | |
25 // immediately after construction to set the final scroll and page scale. | |
26 | |
27 // Zoom while explicitly specifying the top-left scroll position. The | |
28 // scroll offset is in finalPageScale coordinates. | |
29 void zoomTo(const IntSize& finalScroll, float finalPageScale, double duratio
n); | |
30 | |
31 // Zoom based on a specified onscreen anchor, which will remain at the same | |
32 // position on the screen throughout the animation. The anchor is in local | |
33 // space relative to scrollStart. | |
34 void zoomWithAnchor(const IntSize& anchor, float finalPageScale, double dura
tion); | |
35 | |
36 // Call these functions while the animation is in progress to output the | |
37 // current state. | |
38 IntSize scrollOffsetAtTime(double time) const; | |
39 float pageScaleAtTime(double time) const; | |
40 bool isAnimationCompleteAtTime(double time) const; | |
41 | |
42 // The following methods return state which is invariant throughout the | |
43 // course of the animation. | |
44 double startTime() const { return m_startTime; } | |
45 double duration() const { return m_duration; } | |
46 double endTime() const { return m_startTime + m_duration; } | |
47 const IntSize& finalScrollOffset() const { return m_scrollEnd; } | |
48 float finalPageScale() const { return m_pageScaleEnd; } | |
49 | |
50 protected: | |
51 CCPageScaleAnimation(const IntSize& scrollStart, float pageScaleStart, const
IntSize& windowSize, const IntSize& contentSize, double startTime); | |
52 | |
53 private: | |
54 float progressRatioForTime(double time) const; | |
55 IntSize scrollOffsetAtRatio(float ratio) const; | |
56 float pageScaleAtRatio(float ratio) const; | |
57 | |
58 IntSize m_scrollStart; | |
59 float m_pageScaleStart; | |
60 IntSize m_windowSize; | |
61 IntSize m_contentSize; | |
62 | |
63 bool m_anchorMode; | |
64 IntSize m_anchor; | |
65 IntSize m_scrollEnd; | |
66 float m_pageScaleEnd; | |
67 | |
68 double m_startTime; | |
69 double m_duration; | |
70 }; | |
71 | |
72 } // namespace cc | |
73 | |
74 #endif | |
OLD | NEW |