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

Side by Side Diff: ash/wm/power_button_controller.h

Issue 8976012: chromeos: Implement power button animations for Aura. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update copyright year to 2012 Created 8 years, 11 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
« no previous file with comments | « ash/shell.cc ('k') | ash/wm/power_button_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 ASH_WM_POWER_BUTTON_CONTROLLER_H_
6 #define ASH_WM_POWER_BUTTON_CONTROLLER_H_
7 #pragma once
8
9 #include "ash/ash_export.h"
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/time.h"
13 #include "base/timer.h"
14 #include "ui/aura/root_window_observer.h"
15
16 namespace gfx {
17 class Size;
18 }
19
20 namespace ui {
21 class Layer;
22 class LayerDelegate;
23 }
24
25 namespace ash {
26
27 // Performs system-related functions on behalf of PowerButtonController.
28 class ASH_EXPORT PowerButtonControllerDelegate {
29 public:
30 PowerButtonControllerDelegate() {}
31 virtual ~PowerButtonControllerDelegate() {}
32
33 virtual void RequestLockScreen() = 0;
34 virtual void RequestShutdown() = 0;
35
36 private:
37 DISALLOW_COPY_AND_ASSIGN(PowerButtonControllerDelegate);
38 };
39
40 // Displays onscreen animations and locks or suspends the system in response to
41 // the power button being pressed or released.
42 class ASH_EXPORT PowerButtonController : public aura::RootWindowObserver {
43 public:
44 // Animations that can be applied to groups of containers.
45 // Exposed here for TestApi::ContainerGroupIsAnimated().
46 enum AnimationType {
47 ANIMATION_SLOW_CLOSE = 0,
48 ANIMATION_UNDO_SLOW_CLOSE,
49 ANIMATION_FAST_CLOSE,
50 ANIMATION_FADE_IN,
51 ANIMATION_HIDE,
52 ANIMATION_RESTORE,
53 };
54
55 // Groups of containers that can be animated.
56 // Exposed here for TestApi::ContainerGroupIsAnimated().
57 enum ContainerGroup {
58 ALL_CONTAINERS = 0,
59 SCREEN_LOCKER_CONTAINERS,
60 SCREEN_LOCKER_AND_RELATED_CONTAINERS,
61 ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
62 };
63
64 // Helper class used by tests to access internal state.
65 class TestApi {
66 public:
67 TestApi(PowerButtonController* controller) : controller_(controller) {}
68
69 bool lock_timer_is_running() const {
70 return controller_->lock_timer_.IsRunning();
71 }
72 bool lock_fail_timer_is_running() const {
73 return controller_->lock_fail_timer_.IsRunning();
74 }
75 bool lock_to_shutdown_timer_is_running() const {
76 return controller_->lock_to_shutdown_timer_.IsRunning();
77 }
78 bool shutdown_timer_is_running() const {
79 return controller_->shutdown_timer_.IsRunning();
80 }
81 bool real_shutdown_timer_is_running() const {
82 return controller_->real_shutdown_timer_.IsRunning();
83 }
84 bool hide_background_layer_timer_is_running() const {
85 return controller_->hide_background_layer_timer_.IsRunning();
86 }
87
88 void trigger_lock_timeout() { controller_->OnLockTimeout(); }
89 void trigger_lock_fail_timeout() { controller_->OnLockFailTimeout(); }
90 void trigger_lock_to_shutdown_timeout() {
91 controller_->OnLockToShutdownTimeout();
92 }
93 void trigger_shutdown_timeout() { controller_->OnShutdownTimeout(); }
94 void trigger_real_shutdown_timeout() {
95 controller_->OnRealShutdownTimeout();
96 }
97 void trigger_hide_background_layer_timeout() {
98 controller_->HideBackgroundLayer();
99 }
100
101 // Returns true if the given set of containers was last animated with
102 // |type| (probably; the analysis is fairly ad-hoc).
103 bool ContainerGroupIsAnimated(ContainerGroup group,
104 AnimationType type) const;
105
106 // Returns true if |background_layer_| is non-NULL and visible.
107 bool BackgroundLayerIsVisible() const;
108
109 private:
110 PowerButtonController* controller_; // not owned
111
112 DISALLOW_COPY_AND_ASSIGN(TestApi);
113 };
114
115 PowerButtonController();
116 ~PowerButtonController();
117
118 void set_delegate(PowerButtonControllerDelegate* delegate) {
119 delegate_.reset(delegate);
120 }
121
122 // Called when the user logs in.
123 void OnLoginStateChange(bool logged_in, bool is_guest);
124
125 // Called when the screen is locked (after the lock window is visible) or
126 // unlocked.
127 void OnLockStateChange(bool locked);
128
129 // Called when Chrome gets a request to display the lock screen.
130 void OnStartingLock();
131
132 // Called when the power or lock buttons are pressed or released.
133 void OnPowerButtonEvent(bool down, const base::TimeTicks& timestamp);
134 void OnLockButtonEvent(bool down, const base::TimeTicks& timestamp);
135
136 // aura::RootWindowObserver overrides:
137 virtual void OnRootWindowResized(const gfx::Size& new_size) OVERRIDE;
138
139 private:
140 class BackgroundLayerDelegate;
141
142 // Requests that the screen be locked and starts |lock_fail_timer_|.
143 void OnLockTimeout();
144
145 // Aborts the pre-lock animation.
146 void OnLockFailTimeout();
147
148 // Displays the pre-shutdown animation and starts |shutdown_timer_|.
149 void OnLockToShutdownTimeout();
150
151 // Displays the shutdown animation and starts |real_shutdown_timer_|.
152 void OnShutdownTimeout();
153
154 // Requests that the machine be shut down.
155 void OnRealShutdownTimeout();
156
157 // Puts us into the pre-shutdown state.
158 void StartShutdownTimer();
159
160 // Shows or hides |background_layer_|. The show method creates and
161 // initializes the layer if it doesn't already exist.
162 void ShowBackgroundLayer();
163 void HideBackgroundLayer();
164
165 scoped_ptr<PowerButtonControllerDelegate> delegate_;
166
167 // True if a non-guest user is currently logged in.
168 bool logged_in_as_non_guest_;
169
170 // True if the screen is currently locked.
171 bool locked_;
172
173 // Are the power or lock buttons currently held?
174 bool power_button_down_;
175 bool lock_button_down_;
176
177 // Are we in the process of shutting the machine down?
178 bool shutting_down_;
179
180 // Should we start |shutdown_timer_| when we receive notification that the
181 // screen has been locked?
182 bool should_start_shutdown_timer_after_lock_;
183
184 // Responsible for painting |background_layer_|.
185 scoped_ptr<BackgroundLayerDelegate> background_layer_delegate_;
186
187 // Layer that's stacked under all of the root window's children to provide a
188 // black background when we're scaling all of the other windows down.
189 scoped_ptr<ui::Layer> background_layer_;
190
191 // Started when the user first presses the power button while in a
192 // logged-in-as-a-non-guest-user, unlocked state. When it fires, we lock the
193 // screen.
194 base::OneShotTimer<PowerButtonController> lock_timer_;
195
196 // Started when we request that the screen be locked. When it fires, we
197 // assume that our request got dropped.
198 base::OneShotTimer<PowerButtonController> lock_fail_timer_;
199
200 // Started when the screen is locked while the power button is held. Adds a
201 // delay between the appearance of the lock screen and the beginning of the
202 // pre-shutdown animation.
203 base::OneShotTimer<PowerButtonController> lock_to_shutdown_timer_;
204
205 // Started when we begin displaying the pre-shutdown animation. When it
206 // fires, we start the shutdown animation and get ready to request shutdown.
207 base::OneShotTimer<PowerButtonController> shutdown_timer_;
208
209 // Started when we display the shutdown animation. When it fires, we actually
210 // request shutdown. Gives the animation time to complete before Chrome, X,
211 // etc. are shut down.
212 base::OneShotTimer<PowerButtonController> real_shutdown_timer_;
213
214 // Started when we abort the pre-lock state. When it fires, we hide
215 // |background_layer_|, as the desktop background is now covering the whole
216 // screen.
217 base::OneShotTimer<PowerButtonController> hide_background_layer_timer_;
218
219 DISALLOW_COPY_AND_ASSIGN(PowerButtonController);
220 };
221
222 } // namespace ash
223
224 #endif // ASH_WM_POWER_BUTTON_CONTROLLER_H_
OLDNEW
« no previous file with comments | « ash/shell.cc ('k') | ash/wm/power_button_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698