Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: chrome/browser/ui/touch/animation/screen_rotation.h

Issue 7273073: Animated Rotation (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Move compositing notifications to Layer Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/layer_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 View;
30 class PaintLock;
31 }
32
33 // Classes that wish to be notified when a screen rotation completes must
34 // implement the screen rotation listener interface.
35 class ScreenRotationListener {
36 public:
37 virtual void OnScreenRotationCompleted(const ui::Transform& target_transform,
38 const gfx::Rect& target_bounds) = 0;
39 protected:
40 virtual ~ScreenRotationListener();
41 };
42
43 // A screen rotation represents a single transition from one screen orientation
44 // to another. The intended usage is that a new instance of the class is
45 // created for every transition. It is possible to update the target orientation
46 // in the middle of a transition.
47 class ScreenRotation : public ui::AnimationDelegate,
48 public ui::LayerObserver {
49 public:
50 // The screen rotation does not own the view or the listener, and these
51 // objects are required to outlive the Screen rotation object.
52 ScreenRotation(views::View* view,
53 ScreenRotationListener* listener,
54 float old_degrees,
55 float new_degrees);
56 virtual ~ScreenRotation();
57
58 // Use this function to change the target orientation mid animation. The
59 // currently running transition will complete at the same time as it was going
60 // to originally, but in a different orientation.
61 void SetTarget(float degrees);
62
63 // Aborts the animation by skipping to the end and applying the final
64 // transform before calling |Finalize|.
65 void Stop();
66
67 private:
68 // Implementation of ui::AnimationDelegate
69 virtual void AnimationEnded(const ui::Animation* anim) OVERRIDE;
70 virtual void AnimationProgressed(const ui::Animation* anim) OVERRIDE;
71
72 // Implementation of ui::LayerObserver
73 void OnDraw(ui::Layer* layer) OVERRIDE;
74
75 // Initializes |interpolated_transform_|, |new_origin_|, |new_size_|, and
76 // (if it has not already been initialized) |old_transform_|
77 void Init();
78
79 // Initializes the screen rotation and starts |animation_|.
80 void Start();
81
82 // Called after the animation is finished and the view has completed painting
83 // in its final state.
84 void Finalize();
85
86 // Converts degrees to an angle in the range [-180, 180).
87 int NormalizeAngle(int degrees);
88
89 // We occasionally need to wait for a paint to finish before progressing.
90 // This function (which is triggered by OnPainted and OnComposited) does
91 // any pending work.
92 void DoPendingWork();
93
94 // This is the view that will be animated. The animation will operate mainly
95 // on |view_|'s layer, but it is used upon completion of the rotation to
96 // update the bounds.
97 views::View* view_;
98
99 // A ScreenRotation may be associated with a listener that is notified when
100 // the screen rotation completes.
101 ScreenRotationListener* listener_;
102
103 // The animation object that instigates stepping of the animation.
104 scoped_ptr<ui::SlideAnimation> animation_;
105
106 // Generates the intermediate transformation matrices used during the
107 // animation.
108 scoped_ptr<ui::InterpolatedTransform> interpolated_transform_;
109
110 // Ensures that the view is not repainted during the screen rotation.
111 scoped_ptr<views::PaintLock> paint_lock_;
112
113 // The original orientation (not updated by |SetTarget|.
114 float old_degrees_;
115
116 // The target orientation.
117 float new_degrees_;
118
119 // We keep track of the last step of the animation in case we change our
120 // target in the middle and have to create a new transition from last_t_ to 1
121 float last_t_;
122
123 // The target size for |view_|
124 gfx::Size new_size_;
125
126 // The target origin for |view_|
127 gfx::Point new_origin_;
128
129 // This is the duration of the transition in milliseconds
130 int duration_;
131
132 // These are used by DoPendingWork to decide what needs to be done.
133 bool animation_started_;
134 bool animation_stopped_;
135
136 DISALLOW_COPY_AND_ASSIGN(ScreenRotation);
137 };
138
139 #endif // CHROME_BROWSER_UI_TOUCH_ANIMATION_SCREEN_ROTATION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698