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 CHROME_BROWSER_UI_TOUCH_ANIMATION_SCREEN_ROTATION_H_ | |
6 #define CHROME_BROWSER_UI_TOUCH_ANIMATION_SCREEN_ROTATION_H_ | |
7 #pragma once | |
8 | |
9 #include "base/basictypes.h" | |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/bind.h" | |
12 #include "ui/base/animation/animation_delegate.h" | |
13 #include "ui/gfx/compositor/compositor_observer.h" | |
14 #include "ui/gfx/point.h" | |
15 #include "ui/gfx/size.h" | |
16 | |
17 namespace ui { | |
18 class InterpolatedTransform; | |
19 class Layer; | |
20 class SlideAnimation; | |
21 class Transform; | |
22 } | |
23 | |
24 namespace gfx { | |
25 class Rect; | |
26 } | |
27 | |
28 namespace views { | |
29 class PaintLock; | |
30 class View; | |
31 class Widget; | |
32 } | |
33 | |
34 // Classes that wish to be notified when a screen rotation completes must | |
35 // implement the screen rotation listener interface. | |
36 class ScreenRotationListener { | |
37 public: | |
38 virtual void OnScreenRotationCompleted(const ui::Transform& target_transform, | |
39 const gfx::Rect& target_bounds) = 0; | |
40 protected: | |
41 virtual ~ScreenRotationListener(); | |
42 }; | |
43 | |
44 // A screen rotation represents a single transition from one screen orientation | |
45 // to another. The intended usage is that a new instance of the class is | |
46 // created for every transition. It is possible to update the target orientation | |
47 // in the middle of a transition. | |
48 class ScreenRotation : public ui::AnimationDelegate, | |
49 public ui::CompositorObserver { | |
50 public: | |
51 // The screen rotation does not own the view or the listener, and these | |
52 // objects are required to outlive the Screen rotation object. | |
53 ScreenRotation(views::View* view, | |
54 ScreenRotationListener* listener, | |
55 float old_degrees, | |
56 float new_degrees); | |
57 virtual ~ScreenRotation(); | |
58 | |
59 // Aborts the animation by skipping to the end and applying the final | |
60 // transform before calling |Finalize|. | |
61 void Stop(); | |
62 | |
63 private: | |
64 // Implementation of ui::AnimationDelegate | |
65 virtual void AnimationEnded(const ui::Animation* anim) OVERRIDE; | |
66 virtual void AnimationProgressed(const ui::Animation* anim) OVERRIDE; | |
67 | |
68 // Implementation of ui::CompositorObserver | |
69 void OnCompositingEnded(ui::Compositor* compositor) OVERRIDE; | |
70 | |
71 // Initializes |interpolated_transform_|, |new_origin_|, |new_size_|, and | |
72 // (if it has not already been initialized) |old_transform_| | |
73 void Init(); | |
74 | |
75 // Initializes the screen rotation and starts |animation_|. | |
76 void Start(); | |
77 | |
78 // Called after the animation is finished and the view has completed painting | |
79 // in its final state. | |
80 void Finalize(); | |
81 | |
82 // Converts degrees to an angle in the range [-180, 180). | |
83 int NormalizeAngle(int degrees); | |
84 | |
85 // We occasionally need to wait for a paint to finish before progressing. | |
86 // This function (which is triggered by OnPainted and OnComposited) does | |
87 // any pending work. | |
88 void DoPendingWork(); | |
89 | |
90 // This is the view that will be animated. The animation will operate mainly | |
91 // on |view_|'s layer, but it is used upon completion of the rotation to | |
92 // update the bounds. | |
93 views::View* view_; | |
94 | |
95 // This widget will be used for scheduling paints. | |
96 views::Widget* widget_; | |
97 | |
98 // A ScreenRotation may be associated with a listener that is notified when | |
99 // the screen rotation completes. | |
100 ScreenRotationListener* listener_; | |
101 | |
102 // The animation object that instigates stepping of the animation. | |
103 scoped_ptr<ui::SlideAnimation> animation_; | |
104 | |
105 // Generates the intermediate transformation matrices used during the | |
106 // animation. | |
107 scoped_ptr<ui::InterpolatedTransform> interpolated_transform_; | |
108 | |
109 // Ensures that the view is not repainted during the screen rotation. | |
110 scoped_ptr<views::PaintLock> paint_lock_; | |
111 | |
112 // The original orientation (not updated by |SetTarget|. | |
113 float old_degrees_; | |
114 | |
115 // The target orientation. | |
116 float new_degrees_; | |
117 | |
118 // The target size for |view_| | |
119 gfx::Size new_size_; | |
120 | |
121 // The target origin for |view_| | |
122 gfx::Point new_origin_; | |
123 | |
124 // This is the duration of the transition in milliseconds | |
125 int duration_; | |
126 | |
127 // These are used by DoPendingWork to decide what needs to be done. | |
128 bool animation_started_; | |
129 bool animation_stopped_; | |
130 | |
131 DISALLOW_COPY_AND_ASSIGN(ScreenRotation); | |
132 }; | |
133 | |
134 #endif // CHROME_BROWSER_UI_TOUCH_ANIMATION_SCREEN_ROTATION_H_ | |
OLD | NEW |