Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef VIEWS_ANIMATION_SCREEN_ROTATION_H_ | |
| 6 #define VIEWS_ANIMATION_SCREEN_ROTATION_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include "base/basictypes.h" | |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/task.h" | |
| 12 #include "ui/base/animation/animation_delegate.h" | |
| 13 #include "ui/gfx/point.h" | |
| 14 #include "ui/gfx/size.h" | |
| 15 | |
| 16 namespace ui { | |
| 17 class SlideAnimation; | |
| 18 class InterpolatedTransform; | |
| 19 class Layer; | |
| 20 class Transform; | |
| 21 } | |
| 22 | |
| 23 namespace views { | |
| 24 | |
| 25 class View; | |
| 26 class ScreenRotation; | |
| 27 | |
| 28 // Classes that wish to be notified when a screen rotation completes must | |
| 29 // implement the screen rotation listener interface. | |
| 30 class ScreenRotationListener { | |
| 31 public: | |
| 32 virtual void OnScreenRotationCompleted(ScreenRotation* rotation) = 0; | |
| 33 }; | |
|
sky
2011/08/25 03:00:13
Add a virtual destructor and make it public. This
| |
| 34 | |
| 35 // A screen rotation represents a single transition from one screen orientation | |
| 36 // to another. The intended usage is that a new instance of the class is | |
| 37 // created for every transition. It is possible to update the target orientation | |
| 38 // in the middle of a transition. | |
| 39 class ScreenRotation : public ui::AnimationDelegate { | |
|
sky
2011/08/25 03:00:13
These classes (ScreenRotation and ScreenRotationSe
| |
| 40 public: | |
| 41 ScreenRotation(View* view, float old_degrees, float new_degrees); | |
| 42 virtual ~ScreenRotation(); | |
| 43 | |
| 44 ScreenRotationListener* listener() { return listener_; } | |
| 45 void set_listener(ScreenRotationListener* listener) { listener_ = listener; } | |
| 46 | |
| 47 // Called after the animation is finished and the view has completed painting | |
| 48 // in its final state. | |
| 49 void Finalize(); | |
| 50 | |
| 51 // Use this function to change the target orientation mid animation. The | |
| 52 // currently running transition will complete at the same time as it was going | |
| 53 // to originally, but in a different orientation. | |
| 54 void UpdateTarget(float degrees); | |
|
sky
2011/08/25 03:00:13
nit: Name this SetTarget.
| |
| 55 | |
| 56 // True if the animation is complete and finalized. | |
| 57 bool done() const { return done_; } | |
| 58 | |
| 59 private: | |
| 60 // Implementation of ui::AnimationDelegate | |
| 61 virtual void AnimationEnded(const ui::Animation* anim) OVERRIDE; | |
| 62 virtual void AnimationProgressed(const ui::Animation* anim) OVERRIDE; | |
| 63 | |
| 64 // Initializes |interpolated_transform_|, |new_origin_|, |new_size_|, and | |
| 65 // (if it has not already been initialized) |old_transform_| | |
| 66 void Init(); | |
| 67 | |
| 68 // Initializes the screen rotation and starts |animation_|. | |
| 69 void Start(); | |
| 70 | |
| 71 // Converts degrees to an angle in the range [-180, 180). | |
| 72 int NormalizeAngle(int degrees); | |
| 73 | |
| 74 // This is the view that will be animated. The animation will operate mainly | |
| 75 // on |view_|'s layer, but it is used upon completion of the rotation to | |
| 76 // update the bounds. | |
| 77 View* view_; | |
| 78 | |
| 79 // A ScreenRotation may be associated with a listener that is notified when | |
| 80 // the screen rotation completes. | |
| 81 ScreenRotationListener* listener_; | |
| 82 | |
| 83 // The initial transform of the layer (not updated by |UpdateTarget|). | |
| 84 scoped_ptr<ui::Transform> old_transform_; | |
| 85 | |
| 86 // The animation object that instigates stepping of the animation. | |
| 87 scoped_ptr<ui::SlideAnimation> animation_; | |
| 88 | |
| 89 // Generates the intermediate transformation matrices used during the | |
| 90 // animation. | |
| 91 scoped_ptr<ui::InterpolatedTransform> interpolated_transform_; | |
| 92 | |
| 93 // The original orientation (not updated by |UpdateTarget|. | |
| 94 float old_degrees_; | |
| 95 | |
| 96 // The target orientation. | |
| 97 float new_degrees_; | |
| 98 | |
| 99 // We keep track of the last step of the animation in case we change our | |
| 100 // target in the middle and have to create a new transition from last_t_ to 1 | |
| 101 float last_t_; | |
| 102 | |
| 103 // The target size for |view_| | |
| 104 gfx::Size new_size_; | |
| 105 | |
| 106 // The target origin for |view_| | |
| 107 gfx::Point new_origin_; | |
| 108 | |
| 109 // This is true if the rotation is completed and finalized. | |
| 110 bool done_; | |
| 111 | |
| 112 // This is the duration of the transition in milliseconds | |
| 113 int duration_; | |
| 114 | |
| 115 // This is used to post a task to update the bounds after the final call to | |
| 116 // SchedulePaint completes. | |
| 117 ScopedRunnableMethodFactory<ScreenRotation> method_factory_; | |
| 118 | |
| 119 DISALLOW_COPY_AND_ASSIGN(ScreenRotation); | |
| 120 }; | |
| 121 | |
| 122 } // namespace views | |
| 123 | |
| 124 #endif // VIEWS_ANIMATION_SCREEN_ROTATION_H_ | |
| OLD | NEW |