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

Side by Side Diff: ash/wm/session_state_controller_impl2.cc

Issue 11220002: Add new animations in second implementation. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added shutdown animations Created 8 years, 2 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
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 #include "ash/wm/session_state_controller_impl2.h"
Daniel Erat 2012/10/22 17:45:48 i didn't review this yet. do you mind moving it t
6
7 #include "ash/ash_switches.h"
8 #include "ash/shell.h"
9 #include "ash/shell_delegate.h"
10 #include "ash/shell_window_ids.h"
11 #include "ash/wm/session_state_animator.h"
12 #include "base/command_line.h"
13 #include "ui/aura/root_window.h"
14 #include "ui/aura/shared/compound_event_filter.h"
15
16 #if defined(OS_CHROMEOS)
17 #include "base/chromeos/chromeos_version.h"
18 #endif
19
20 namespace ash {
21
22 SessionStateControllerImpl2::TestApi::TestApi(
23 SessionStateControllerImpl2* controller)
24 : controller_(controller) {
25 }
26
27 SessionStateControllerImpl2::TestApi::~TestApi() {
28 }
29
30 SessionStateControllerImpl2::SessionStateControllerImpl2()
31 : login_status_(user::LOGGED_IN_NONE),
32 system_is_locked_(false),
33 shutting_down_(false),
34 shutdown_after_lock_(false) {
35 Shell::GetPrimaryRootWindow()->AddRootWindowObserver(this);
36 }
37
38 SessionStateControllerImpl2::~SessionStateControllerImpl2() {
39 Shell::GetPrimaryRootWindow()->RemoveRootWindowObserver(this);
40 }
41
42 void SessionStateControllerImpl2::OnLoginStateChanged(
43 user::LoginStatus status) {
44 if (status != user::LOGGED_IN_LOCKED)
45 login_status_ = status;
46 system_is_locked_ = (status == user::LOGGED_IN_LOCKED);
47 }
48
49 void SessionStateControllerImpl2::OnAppTerminating() {
50 // If we hear that Chrome is exiting but didn't request it ourselves, all we
51 // can really hope for is that we'll have time to clear the screen.
52 if (!shutting_down_) {
53 shutting_down_ = true;
54 Shell* shell = ash::Shell::GetInstance();
55 shell->env_filter()->set_cursor_hidden_by_filter(false);
56 shell->cursor_manager()->ShowCursor(false);
57 animator_->StartAnimation(
58 internal::SessionStateAnimator::kAllContainersMask,
59 internal::SessionStateAnimator::ANIMATION_HIDE);
60 }
61 }
62
63 void SessionStateControllerImpl2::OnLockStateChanged(bool locked) {
64 if (shutting_down_ || (IsLocked()) == locked)
65 return;
66
67 system_is_locked_ = locked;
68
69 if (locked) {
70 animator_->StartAnimation(
71 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
72 internal::SessionStateAnimator::ANIMATION_PUT_DOWN);
73 lock_timer_.Stop();
74 lock_fail_timer_.Stop();
75
76 if (shutdown_after_lock_) {
77 shutdown_after_lock_ = false;
78 StartLockToShutdownTimer();
79 }
80 } else {
81 animator_->StartAnimation(
82 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
83 internal::SessionStateAnimator::ANIMATION_PUT_DOWN);
84 }
85 }
86
87 void SessionStateControllerImpl2::OnStartingLock() {
88 if (shutting_down_ || system_is_locked_)
89 return;
90
91 animator_->StartAnimation(
92 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
93 internal::SessionStateAnimator::ANIMATION_LIFT_UP);
94
95 // Hide the screen locker containers so we can make them fade in later.
96 animator_->StartAnimation(
97 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
98 internal::SessionStateAnimator::ANIMATION_HIDE);
99 }
100
101 void SessionStateControllerImpl2::StartLockAnimationAndLockImmediately() {
102 animator_->StartAnimation(
103 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS |
104 internal::SessionStateAnimator::LAUNCHER,
105 internal::SessionStateAnimator::ANIMATION_LIFT_UP);
106 OnLockTimeout();
107 }
108
109 void SessionStateControllerImpl2::StartLockAnimation() {
110 shutdown_after_lock_ = true;
111
112 animator_->StartAnimation(
113 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS |
114 internal::SessionStateAnimator::LAUNCHER,
115 internal::SessionStateAnimator::ANIMATION_LIFT_UP);
116 StartLockTimer();
117 }
118
119 void SessionStateControllerImpl2::StartShutdownAnimation() {
120 animator_->CreateForeground();
121 animator_->StartAnimation(
122 internal::SessionStateAnimator::LOCK_SCREEN_SYSTEM_FOREGROUND,
123 internal::SessionStateAnimator::ANIMATION_PARTIAL_FADE_IN);
124 StartPreShutdownAnimationTimer();
125 }
126
127 bool SessionStateControllerImpl2::IsEligibleForLock() {
128 return IsLoggedInAsNonGuest() && !IsLocked() && !LockRequested();
129 }
130
131 bool SessionStateControllerImpl2::IsLocked() {
132 return system_is_locked_;
133 }
134
135 bool SessionStateControllerImpl2::LockRequested() {
136 return lock_fail_timer_.IsRunning();
137 }
138
139 bool SessionStateControllerImpl2::ShutdownRequested() {
140 return shutting_down_;
141 }
142
143 bool SessionStateControllerImpl2::CanCancelLockAnimation() {
144 return lock_timer_.IsRunning();
145 }
146
147 void SessionStateControllerImpl2::CancelLockAnimation() {
148 if (!CanCancelLockAnimation())
149 return;
150 shutdown_after_lock_ = false;
151 animator_->StartAnimation(
152 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
153 internal::SessionStateAnimator::ANIMATION_PUT_DOWN);
154 lock_timer_.Stop();
155 }
156
157 bool SessionStateControllerImpl2::CanCancelShutdownAnimation() {
158 return pre_shutdown_timer_.IsRunning() ||
159 shutdown_after_lock_ ||
160 lock_to_shutdown_timer_.IsRunning();
161 }
162
163 void SessionStateControllerImpl2::CancelShutdownAnimation() {
164 if (!CanCancelShutdownAnimation())
165 return;
166 if (lock_to_shutdown_timer_.IsRunning()) {
167 lock_to_shutdown_timer_.Stop();
168 return;
169 }
170 if (shutdown_after_lock_) {
171 shutdown_after_lock_ = false;
172 return;
173 }
174 animator_->CreateForeground();
175 animator_->StartAnimation(
176 internal::SessionStateAnimator::LOCK_SCREEN_SYSTEM_FOREGROUND,
177 internal::SessionStateAnimator::ANIMATION_UNDO_PARTIAL_FADE_IN);
178
179 pre_shutdown_timer_.Stop();
180 }
181
182 void SessionStateControllerImpl2::RequestShutdown() {
183 if (!shutting_down_)
184 RequestShutdownImpl();
185 }
186
187 void SessionStateControllerImpl2::RequestShutdownImpl() {
188 DCHECK(!shutting_down_);
189 shutting_down_ = true;
190
191 Shell* shell = ash::Shell::GetInstance();
192 shell->env_filter()->set_cursor_hidden_by_filter(false);
193 shell->cursor_manager()->ShowCursor(false);
194
195 animator_->CreateForeground();
196 animator_->StartAnimation(
197 internal::SessionStateAnimator::LOCK_SCREEN_SYSTEM_FOREGROUND,
198 internal::SessionStateAnimator::ANIMATION_FULL_FADE_IN);
199 StartRealShutdownTimer();
200 }
201
202 void SessionStateControllerImpl2::OnRootWindowHostCloseRequested(
203 const aura::RootWindow*) {
204 if(Shell::GetInstance() && Shell::GetInstance()->delegate())
205 Shell::GetInstance()->delegate()->Exit();
206 }
207
208 bool SessionStateControllerImpl2::IsLoggedInAsNonGuest() const {
209 // TODO(mukai): think about kiosk mode.
210 return (login_status_ != user::LOGGED_IN_NONE) &&
211 (login_status_ != user::LOGGED_IN_GUEST);
212 }
213
214 void SessionStateControllerImpl2::StartLockTimer() {
215 lock_timer_.Stop();
216 lock_timer_.Start(FROM_HERE,
217 base::TimeDelta::FromMilliseconds(kSlowCloseAnimMs),
218 this, &SessionStateControllerImpl2::OnLockTimeout);
219 }
220
221 void SessionStateControllerImpl2::OnLockTimeout() {
222 delegate_->RequestLockScreen();
223 lock_fail_timer_.Start(
224 FROM_HERE,
225 base::TimeDelta::FromMilliseconds(kLockFailTimeoutMs),
226 this, &SessionStateControllerImpl2::OnLockFailTimeout);
227 }
228
229 void SessionStateControllerImpl2::OnLockFailTimeout() {
230 DCHECK(!system_is_locked_);
231 // Undo lock animation.
232 animator_->StartAnimation(
233 internal::SessionStateAnimator::LAUNCHER |
234 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
235 internal::SessionStateAnimator::ANIMATION_PUT_DOWN);
236 }
237
238 void SessionStateControllerImpl2::StartLockToShutdownTimer() {
239 shutdown_after_lock_ = false;
240 lock_to_shutdown_timer_.Stop();
241 lock_to_shutdown_timer_.Start(
242 FROM_HERE,
243 base::TimeDelta::FromMilliseconds(kLockToShutdownTimeoutMs),
244 this, &SessionStateControllerImpl2::OnLockToShutdownTimeout);
245 }
246
247
248 void SessionStateControllerImpl2::OnLockToShutdownTimeout() {
249 DCHECK(system_is_locked_);
250 StartShutdownAnimation();
251 }
252
253 void SessionStateControllerImpl2::StartPreShutdownAnimationTimer() {
254 pre_shutdown_timer_.Stop();
255 pre_shutdown_timer_.Start(
256 FROM_HERE,
257 base::TimeDelta::FromMilliseconds(kShutdownTimeoutMs),
258 this, &SessionStateControllerImpl2::OnPreShutdownAnimationTimeout);
259 }
260
261 void SessionStateControllerImpl2::OnPreShutdownAnimationTimeout() {
262 if (!shutting_down_)
263 RequestShutdownImpl();
264 }
265
266 void SessionStateControllerImpl2::StartRealShutdownTimer() {
267 real_shutdown_timer_.Start(
268 FROM_HERE,
269 base::TimeDelta::FromMilliseconds(kFastCloseAnimMs +
270 kShutdownRequestDelayMs),
271 this, &SessionStateControllerImpl2::OnRealShutdownTimeout);
272 }
273
274 void SessionStateControllerImpl2::OnRealShutdownTimeout() {
275 DCHECK(shutting_down_);
276 #if defined(OS_CHROMEOS)
277 if (!base::chromeos::IsRunningOnChromeOS()) {
278 ShellDelegate* delegate = Shell::GetInstance()->delegate();
279 if (delegate) {
280 delegate->Exit();
281 return;
282 }
283 }
284 #endif
285 delegate_->RequestShutdown();
286 }
287
288 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698