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