| 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_INPUT_PAGE_SCALE_ANIMATION_H_ | 5 #ifndef CC_INPUT_PAGE_SCALE_ANIMATION_H_ |
| 6 #define CC_INPUT_PAGE_SCALE_ANIMATION_H_ | 6 #define CC_INPUT_PAGE_SCALE_ANIMATION_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/time/time.h" |
| 10 #include "ui/gfx/size.h" | 11 #include "ui/gfx/size.h" |
| 11 #include "ui/gfx/vector2d_f.h" | 12 #include "ui/gfx/vector2d_f.h" |
| 12 | 13 |
| 13 namespace cc { | 14 namespace cc { |
| 15 |
| 16 using base::TimeTicks; |
| 17 using base::TimeDelta; |
| 18 |
| 14 class TimingFunction; | 19 class TimingFunction; |
| 15 | 20 |
| 16 // A small helper class that does the math for zoom animations, primarily for | 21 // A small helper class that does the math for zoom animations, primarily for |
| 17 // double-tap zoom. Initialize it with starting and ending scroll/page scale | 22 // double-tap zoom. Initialize it with starting and ending scroll/page scale |
| 18 // positions and an animation length time, then call ...AtTime() at every frame | 23 // positions and an animation length time, then call ...AtTime() at every frame |
| 19 // to obtain the current interpolated position. The supplied timing function | 24 // to obtain the current interpolated position. The supplied timing function |
| 20 // is used to ease the animation. | 25 // is used to ease the animation. |
| 21 // | 26 // |
| 22 // All sizes and vectors in this class's public methods are in the root scroll | 27 // All sizes and vectors in this class's public methods are in the root scroll |
| 23 // layer's coordinate space. | 28 // layer's coordinate space. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 45 // at the same position on the physical display throughout the animation, | 50 // at the same position on the physical display throughout the animation, |
| 46 // unless the edges of the root layer are hit. The anchor is specified | 51 // unless the edges of the root layer are hit. The anchor is specified |
| 47 // as an offset from the content layer. | 52 // as an offset from the content layer. |
| 48 void ZoomWithAnchor(const gfx::Vector2dF& anchor, | 53 void ZoomWithAnchor(const gfx::Vector2dF& anchor, |
| 49 float target_page_scale_factor, | 54 float target_page_scale_factor, |
| 50 double duration); | 55 double duration); |
| 51 | 56 |
| 52 // These should be called before the first frame of animation to initialize | 57 // These should be called before the first frame of animation to initialize |
| 53 // the start time. StartAnimation should only be called once after creation. | 58 // the start time. StartAnimation should only be called once after creation. |
| 54 bool IsAnimationStarted() const; | 59 bool IsAnimationStarted() const; |
| 55 void StartAnimation(double time); | 60 void StartAnimation(base::TimeTicks time); |
| 56 | 61 |
| 57 // Call these functions while the animation is in progress to output the | 62 // Call these functions while the animation is in progress to output the |
| 58 // current state. | 63 // current state. |
| 59 gfx::Vector2dF ScrollOffsetAtTime(double time) const; | 64 gfx::Vector2dF ScrollOffsetAtTime(base::TimeTicks time) const; |
| 60 float PageScaleFactorAtTime(double time) const; | 65 float PageScaleFactorAtTime(base::TimeTicks time) const; |
| 61 bool IsAnimationCompleteAtTime(double time) const; | 66 bool IsAnimationCompleteAtTime(base::TimeTicks time) const; |
| 62 | 67 |
| 63 // The following methods return state which is invariant throughout the | 68 // The following methods return state which is invariant throughout the |
| 64 // course of the animation. | 69 // course of the animation. |
| 65 double start_time() const { return start_time_; } | 70 TimeTicks start_time() const { return start_time_; } |
| 66 double duration() const { return duration_; } | 71 TimeDelta duration() const { return duration_; } |
| 67 double end_time() const { return start_time_ + duration_; } | 72 TimeTicks end_time() const { return start_time_ + duration_; } |
| 68 gfx::Vector2dF target_scroll_offset() const { return target_scroll_offset_; } | 73 gfx::Vector2dF target_scroll_offset() const { return target_scroll_offset_; } |
| 69 float target_page_scale_factor() const { return target_page_scale_factor_; } | 74 float target_page_scale_factor() const { return target_page_scale_factor_; } |
| 70 | 75 |
| 71 protected: | 76 protected: |
| 72 PageScaleAnimation(const gfx::Vector2dF& start_scroll_offset, | 77 PageScaleAnimation(const gfx::Vector2dF& start_scroll_offset, |
| 73 float start_page_scale_factor, | 78 float start_page_scale_factor, |
| 74 const gfx::SizeF& viewport_size, | 79 const gfx::SizeF& viewport_size, |
| 75 const gfx::SizeF& root_layer_size, | 80 const gfx::SizeF& root_layer_size, |
| 76 scoped_ptr<TimingFunction> timing_function); | 81 scoped_ptr<TimingFunction> timing_function); |
| 77 | 82 |
| 78 private: | 83 private: |
| 79 void ClampTargetScrollOffset(); | 84 void ClampTargetScrollOffset(); |
| 80 void InferTargetScrollOffsetFromStartAnchor(); | 85 void InferTargetScrollOffsetFromStartAnchor(); |
| 81 void InferTargetAnchorFromScrollOffsets(); | 86 void InferTargetAnchorFromScrollOffsets(); |
| 82 | 87 |
| 83 gfx::SizeF StartViewportSize() const; | 88 gfx::SizeF StartViewportSize() const; |
| 84 gfx::SizeF TargetViewportSize() const; | 89 gfx::SizeF TargetViewportSize() const; |
| 85 float InterpAtTime(double time) const; | 90 float InterpAtTime(base::TimeTicks time) const; |
| 86 gfx::SizeF ViewportSizeAt(float interp) const; | 91 gfx::SizeF ViewportSizeAt(float interp) const; |
| 87 gfx::Vector2dF ScrollOffsetAt(float interp) const; | 92 gfx::Vector2dF ScrollOffsetAt(float interp) const; |
| 88 gfx::Vector2dF AnchorAt(float interp) const; | 93 gfx::Vector2dF AnchorAt(float interp) const; |
| 89 gfx::Vector2dF ViewportRelativeAnchorAt(float interp) const; | 94 gfx::Vector2dF ViewportRelativeAnchorAt(float interp) const; |
| 90 float PageScaleFactorAt(float interp) const; | 95 float PageScaleFactorAt(float interp) const; |
| 91 | 96 |
| 92 float start_page_scale_factor_; | 97 float start_page_scale_factor_; |
| 93 float target_page_scale_factor_; | 98 float target_page_scale_factor_; |
| 94 gfx::Vector2dF start_scroll_offset_; | 99 gfx::Vector2dF start_scroll_offset_; |
| 95 gfx::Vector2dF target_scroll_offset_; | 100 gfx::Vector2dF target_scroll_offset_; |
| 96 | 101 |
| 97 gfx::Vector2dF start_anchor_; | 102 gfx::Vector2dF start_anchor_; |
| 98 gfx::Vector2dF target_anchor_; | 103 gfx::Vector2dF target_anchor_; |
| 99 | 104 |
| 100 gfx::SizeF viewport_size_; | 105 gfx::SizeF viewport_size_; |
| 101 gfx::SizeF root_layer_size_; | 106 gfx::SizeF root_layer_size_; |
| 102 | 107 |
| 103 double start_time_; | 108 TimeTicks start_time_; |
| 104 double duration_; | 109 TimeDelta duration_; |
| 105 | 110 |
| 106 scoped_ptr<TimingFunction> timing_function_; | 111 scoped_ptr<TimingFunction> timing_function_; |
| 107 | 112 |
| 108 DISALLOW_COPY_AND_ASSIGN(PageScaleAnimation); | 113 DISALLOW_COPY_AND_ASSIGN(PageScaleAnimation); |
| 109 }; | 114 }; |
| 110 | 115 |
| 111 } // namespace cc | 116 } // namespace cc |
| 112 | 117 |
| 113 #endif // CC_INPUT_PAGE_SCALE_ANIMATION_H_ | 118 #endif // CC_INPUT_PAGE_SCALE_ANIMATION_H_ |
| OLD | NEW |