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

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: Listen for painting to complete rather than posting tasks. Created 9 years, 4 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/point.h"
14 #include "ui/gfx/size.h"
15 #include "views/paint_listener.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 views::PaintListener {
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 // Initializes the screen rotation and starts |animation_|.
59 void Start();
60
61 // Called after the animation is finished and the view has completed painting
62 // in its final state.
63 void Finalize();
64
65 // Use this function to change the target orientation mid animation. The
66 // currently running transition will complete at the same time as it was going
67 // to originally, but in a different orientation.
68 void SetTarget(float degrees);
69
70 // Implementation of views::PaintListener
71 void OnPainted(views::View* view) OVERRIDE;
72 void OnComposited(views::View* view) OVERRIDE;
73
74 private:
75 // Implementation of ui::AnimationDelegate
76 virtual void AnimationEnded(const ui::Animation* anim) OVERRIDE;
77 virtual void AnimationProgressed(const ui::Animation* anim) OVERRIDE;
78
79 // Initializes |interpolated_transform_|, |new_origin_|, |new_size_|, and
80 // (if it has not already been initialized) |old_transform_|
81 void Init();
82
83 // Converts degrees to an angle in the range [-180, 180).
84 int NormalizeAngle(int degrees);
85
86 // We occasionally need to wait for a paint to finish before progressing.
87 // This function (which is triggered by OnPainted and OnComposited) does
88 // any pending work.
89 void DoPendingWork();
90
91 // This is the view that will be animated. The animation will operate mainly
92 // on |view_|'s layer, but it is used upon completion of the rotation to
93 // update the bounds.
94 views::View* view_;
95
96 // A ScreenRotation may be associated with a listener that is notified when
97 // the screen rotation completes.
98 ScreenRotationListener* listener_;
99
100 // The animation object that instigates stepping of the animation.
101 scoped_ptr<ui::SlideAnimation> animation_;
102
103 // Generates the intermediate transformation matrices used during the
104 // animation.
105 scoped_ptr<ui::InterpolatedTransform> interpolated_transform_;
106
107 // Ensures that the view is not repainted during the screen rotation.
108 scoped_ptr<views::PaintLock> paint_lock_;
109
110 // The original orientation (not updated by |SetTarget|.
111 float old_degrees_;
112
113 // The target orientation.
114 float new_degrees_;
115
116 // We keep track of the last step of the animation in case we change our
117 // target in the middle and have to create a new transition from last_t_ to 1
118 float last_t_;
119
120 // The target size for |view_|
121 gfx::Size new_size_;
122
123 // The target origin for |view_|
124 gfx::Point new_origin_;
125
126 // This is the duration of the transition in milliseconds
127 int duration_;
128
129 // These are used by DoPendingWork to decide what needs to be done.
130 bool animation_started_;
131 bool animation_stopped_;
132
133 DISALLOW_COPY_AND_ASSIGN(ScreenRotation);
134 };
135
136 #endif // CHROME_BROWSER_UI_TOUCH_ANIMATION_SCREEN_ROTATION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698