OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/ash/multi_user/user_switch_animator_chromeos.h" | 5 #include "chrome/browser/ui/ash/multi_user/user_switch_animator_chromeos.h" |
6 | 6 |
7 #include "ash/desktop_background/user_wallpaper_delegate.h" | 7 #include "ash/desktop_background/user_wallpaper_delegate.h" |
8 #include "ash/root_window_controller.h" | 8 #include "ash/root_window_controller.h" |
9 #include "ash/shelf/shelf_layout_manager.h" | 9 #include "ash/shelf/shelf_layout_manager.h" |
10 #include "ash/shelf/shelf_widget.h" | 10 #include "ash/shelf/shelf_widget.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 ash::Shell::GetInstance()->mru_window_tracker()->SetIgnoreActivations( | 39 ash::Shell::GetInstance()->mru_window_tracker()->SetIgnoreActivations( |
40 false); | 40 false); |
41 } | 41 } |
42 private: | 42 private: |
43 | 43 |
44 DISALLOW_COPY_AND_ASSIGN(UserChangeActionDisabler); | 44 DISALLOW_COPY_AND_ASSIGN(UserChangeActionDisabler); |
45 }; | 45 }; |
46 | 46 |
47 } // namespace | 47 } // namespace |
48 | 48 |
49 UserSwichAnimatorChromeOS::UserSwichAnimatorChromeOS( | 49 UserSwitchAnimatorChromeOS::UserSwitchAnimatorChromeOS( |
50 MultiUserWindowManagerChromeOS* owner, | 50 MultiUserWindowManagerChromeOS* owner, |
51 const std::string& new_user_id, | 51 const std::string& new_user_id, |
52 int animation_speed_ms) | 52 int animation_speed_ms) |
53 : owner_(owner), | 53 : owner_(owner), |
54 new_user_id_(new_user_id), | 54 new_user_id_(new_user_id), |
55 animation_speed_ms_(animation_speed_ms), | 55 animation_speed_ms_(animation_speed_ms), |
56 animation_step_(ANIMATION_STEP_HIDE_OLD_USER), | 56 animation_step_(ANIMATION_STEP_HIDE_OLD_USER), |
57 screen_cover_(GetScreenCover(NULL)) { | 57 screen_cover_(GetScreenCover(NULL)) { |
58 AdvanceUserTransitionAnimation(); | 58 AdvanceUserTransitionAnimation(); |
59 | 59 |
60 if (!animation_speed_ms_) { | 60 if (!animation_speed_ms_) { |
61 FinalizeAnimation(); | 61 FinalizeAnimation(); |
62 } else { | 62 } else { |
63 user_changed_animation_timer_.reset(new base::Timer( | 63 user_changed_animation_timer_.reset(new base::Timer( |
64 FROM_HERE, | 64 FROM_HERE, |
65 base::TimeDelta::FromMilliseconds(animation_speed_ms_), | 65 base::TimeDelta::FromMilliseconds(animation_speed_ms_), |
66 base::Bind( | 66 base::Bind( |
67 &UserSwichAnimatorChromeOS::AdvanceUserTransitionAnimation, | 67 &UserSwitchAnimatorChromeOS::AdvanceUserTransitionAnimation, |
68 base::Unretained(this)), | 68 base::Unretained(this)), |
69 true)); | 69 true)); |
70 user_changed_animation_timer_->Reset(); | 70 user_changed_animation_timer_->Reset(); |
71 } | 71 } |
72 } | 72 } |
73 | 73 |
74 UserSwichAnimatorChromeOS::~UserSwichAnimatorChromeOS() { | 74 UserSwitchAnimatorChromeOS::~UserSwitchAnimatorChromeOS() { |
75 FinalizeAnimation(); | 75 FinalizeAnimation(); |
76 } | 76 } |
77 | 77 |
78 // static | 78 // static |
79 bool UserSwichAnimatorChromeOS::CoversScreen(aura::Window* window) { | 79 bool UserSwitchAnimatorChromeOS::CoversScreen(aura::Window* window) { |
80 // Full screen covers the screen naturally. Since a normal window can have the | 80 // Full screen covers the screen naturally. Since a normal window can have the |
81 // same size as the work area, we only compare the bounds against the work | 81 // same size as the work area, we only compare the bounds against the work |
82 // area. | 82 // area. |
83 if (ash::wm::GetWindowState(window)->IsFullscreen()) | 83 if (ash::wm::GetWindowState(window)->IsFullscreen()) |
84 return true; | 84 return true; |
85 gfx::Rect bounds = window->GetBoundsInRootWindow(); | 85 gfx::Rect bounds = window->GetBoundsInRootWindow(); |
86 gfx::Rect work_area = gfx::Screen::GetScreenFor(window)-> | 86 gfx::Rect work_area = gfx::Screen::GetScreenFor(window)-> |
87 GetDisplayNearestWindow(window).work_area(); | 87 GetDisplayNearestWindow(window).work_area(); |
88 bounds.Intersect(work_area); | 88 bounds.Intersect(work_area); |
89 return work_area == bounds; | 89 return work_area == bounds; |
90 } | 90 } |
91 | 91 |
92 void UserSwichAnimatorChromeOS::AdvanceUserTransitionAnimation() { | 92 void UserSwitchAnimatorChromeOS::AdvanceUserTransitionAnimation() { |
93 DCHECK_NE(animation_step_, ANIMATION_STEP_ENDED); | 93 DCHECK_NE(animation_step_, ANIMATION_STEP_ENDED); |
94 | 94 |
95 TransitionWallpaper(animation_step_); | 95 TransitionWallpaper(animation_step_); |
96 TransitionUserShelf(animation_step_); | 96 TransitionUserShelf(animation_step_); |
97 TransitionWindows(animation_step_); | 97 TransitionWindows(animation_step_); |
98 | 98 |
99 // Advance to the next step. | 99 // Advance to the next step. |
100 switch (animation_step_) { | 100 switch (animation_step_) { |
101 case ANIMATION_STEP_HIDE_OLD_USER: | 101 case ANIMATION_STEP_HIDE_OLD_USER: |
102 animation_step_ = ANIMATION_STEP_SHOW_NEW_USER; | 102 animation_step_ = ANIMATION_STEP_SHOW_NEW_USER; |
103 break; | 103 break; |
104 case ANIMATION_STEP_SHOW_NEW_USER: | 104 case ANIMATION_STEP_SHOW_NEW_USER: |
105 animation_step_ = ANIMATION_STEP_FINALIZE; | 105 animation_step_ = ANIMATION_STEP_FINALIZE; |
106 break; | 106 break; |
107 case ANIMATION_STEP_FINALIZE: | 107 case ANIMATION_STEP_FINALIZE: |
108 user_changed_animation_timer_.reset(); | 108 user_changed_animation_timer_.reset(); |
109 animation_step_ = ANIMATION_STEP_ENDED; | 109 animation_step_ = ANIMATION_STEP_ENDED; |
110 break; | 110 break; |
111 case ANIMATION_STEP_ENDED: | 111 case ANIMATION_STEP_ENDED: |
112 NOTREACHED(); | 112 NOTREACHED(); |
113 break; | 113 break; |
114 } | 114 } |
115 } | 115 } |
116 | 116 |
117 void UserSwichAnimatorChromeOS::CancelAnimation() { | 117 void UserSwitchAnimatorChromeOS::CancelAnimation() { |
118 animation_step_ = ANIMATION_STEP_ENDED; | 118 animation_step_ = ANIMATION_STEP_ENDED; |
119 } | 119 } |
120 | 120 |
121 void UserSwichAnimatorChromeOS::FinalizeAnimation() { | 121 void UserSwitchAnimatorChromeOS::FinalizeAnimation() { |
122 user_changed_animation_timer_.reset(); | 122 user_changed_animation_timer_.reset(); |
123 while (ANIMATION_STEP_ENDED != animation_step_) | 123 while (ANIMATION_STEP_ENDED != animation_step_) |
124 AdvanceUserTransitionAnimation(); | 124 AdvanceUserTransitionAnimation(); |
125 } | 125 } |
126 | 126 |
127 void UserSwichAnimatorChromeOS::TransitionWallpaper( | 127 void UserSwitchAnimatorChromeOS::TransitionWallpaper( |
128 AnimationStep animation_step) { | 128 AnimationStep animation_step) { |
129 // Handle the wallpaper switch. | 129 // Handle the wallpaper switch. |
130 ash::UserWallpaperDelegate* wallpaper_delegate = | 130 ash::UserWallpaperDelegate* wallpaper_delegate = |
131 ash::Shell::GetInstance()->user_wallpaper_delegate(); | 131 ash::Shell::GetInstance()->user_wallpaper_delegate(); |
132 if (animation_step == ANIMATION_STEP_HIDE_OLD_USER) { | 132 if (animation_step == ANIMATION_STEP_HIDE_OLD_USER) { |
133 // Set the wallpaper cross dissolve animation duration to our complete | 133 // Set the wallpaper cross dissolve animation duration to our complete |
134 // animation cycle for a fade in and fade out. | 134 // animation cycle for a fade in and fade out. |
135 int duration = | 135 int duration = |
136 NO_USER_COVERS_SCREEN == screen_cover_ ? (2 * animation_speed_ms_) : 0; | 136 NO_USER_COVERS_SCREEN == screen_cover_ ? (2 * animation_speed_ms_) : 0; |
137 wallpaper_delegate->SetAnimationDurationOverride( | 137 wallpaper_delegate->SetAnimationDurationOverride( |
(...skipping 10 matching lines...) Expand all Loading... |
148 if (screen_cover_ == NEW_USER_COVERS_SCREEN) | 148 if (screen_cover_ == NEW_USER_COVERS_SCREEN) |
149 chromeos::WallpaperManager::Get()->SetUserWallpaperNow(new_user_id_); | 149 chromeos::WallpaperManager::Get()->SetUserWallpaperNow(new_user_id_); |
150 | 150 |
151 // Coming here the wallpaper user id is the final result. No matter how we | 151 // Coming here the wallpaper user id is the final result. No matter how we |
152 // got here. | 152 // got here. |
153 wallpaper_user_id_ = new_user_id_; | 153 wallpaper_user_id_ = new_user_id_; |
154 wallpaper_delegate->SetAnimationDurationOverride(0); | 154 wallpaper_delegate->SetAnimationDurationOverride(0); |
155 } | 155 } |
156 } | 156 } |
157 | 157 |
158 void UserSwichAnimatorChromeOS::TransitionUserShelf( | 158 void UserSwitchAnimatorChromeOS::TransitionUserShelf( |
159 AnimationStep animation_step) { | 159 AnimationStep animation_step) { |
160 ChromeLauncherController* chrome_launcher_controller = | 160 ChromeLauncherController* chrome_launcher_controller = |
161 ChromeLauncherController::instance(); | 161 ChromeLauncherController::instance(); |
162 // The shelf animation duration override. | 162 // The shelf animation duration override. |
163 int duration_override = animation_speed_ms_; | 163 int duration_override = animation_speed_ms_; |
164 // Handle the shelf order of items. This is done once the old user is hidden. | 164 // Handle the shelf order of items. This is done once the old user is hidden. |
165 if (animation_step == ANIMATION_STEP_SHOW_NEW_USER) { | 165 if (animation_step == ANIMATION_STEP_SHOW_NEW_USER) { |
166 // Some unit tests have no ChromeLauncherController. | 166 // Some unit tests have no ChromeLauncherController. |
167 if (chrome_launcher_controller) | 167 if (chrome_launcher_controller) |
168 chrome_launcher_controller->ActiveUserChanged(new_user_id_); | 168 chrome_launcher_controller->ActiveUserChanged(new_user_id_); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 } else { | 216 } else { |
217 // This shelf change is only part of the animation and will be updated by | 217 // This shelf change is only part of the animation and will be updated by |
218 // ChromeLauncherController::ActiveUserChanged() to the new users value. | 218 // ChromeLauncherController::ActiveUserChanged() to the new users value. |
219 // Note that the user preference will not be changed. | 219 // Note that the user preference will not be changed. |
220 ash::Shell::GetInstance()->SetShelfAutoHideBehavior( | 220 ash::Shell::GetInstance()->SetShelfAutoHideBehavior( |
221 ash::SHELF_AUTO_HIDE_ALWAYS_HIDDEN, *iter); | 221 ash::SHELF_AUTO_HIDE_ALWAYS_HIDDEN, *iter); |
222 } | 222 } |
223 } | 223 } |
224 } | 224 } |
225 | 225 |
226 void UserSwichAnimatorChromeOS::TransitionWindows( | 226 void UserSwitchAnimatorChromeOS::TransitionWindows( |
227 AnimationStep animation_step) { | 227 AnimationStep animation_step) { |
228 // Disable the window position manager and the MRU window tracker temporarily. | 228 // Disable the window position manager and the MRU window tracker temporarily. |
229 UserChangeActionDisabler disabler; | 229 UserChangeActionDisabler disabler; |
230 | 230 |
231 if (animation_step == ANIMATION_STEP_HIDE_OLD_USER || | 231 if (animation_step == ANIMATION_STEP_HIDE_OLD_USER || |
232 (animation_step == ANIMATION_STEP_FINALIZE && | 232 (animation_step == ANIMATION_STEP_FINALIZE && |
233 screen_cover_ == BOTH_USERS_COVER_SCREEN)) { | 233 screen_cover_ == BOTH_USERS_COVER_SCREEN)) { |
234 // We need to show/hide the windows in the same order as they were created | 234 // We need to show/hide the windows in the same order as they were created |
235 // in their parent window(s) to keep the layer / window hierarchy in sync. | 235 // in their parent window(s) to keep the layer / window hierarchy in sync. |
236 // To achieve that we first collect all parent windows and then enumerate | 236 // To achieve that we first collect all parent windows and then enumerate |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 client->ActivateWindow(window); | 322 client->ActivateWindow(window); |
323 } | 323 } |
324 } | 324 } |
325 | 325 |
326 // This is called directly here to make sure notification_blocker will see | 326 // This is called directly here to make sure notification_blocker will see |
327 // the new window status. | 327 // the new window status. |
328 owner_->notification_blocker()->ActiveUserChanged(new_user_id_); | 328 owner_->notification_blocker()->ActiveUserChanged(new_user_id_); |
329 } | 329 } |
330 } | 330 } |
331 | 331 |
332 UserSwichAnimatorChromeOS::TransitioningScreenCover | 332 UserSwitchAnimatorChromeOS::TransitioningScreenCover |
333 UserSwichAnimatorChromeOS::GetScreenCover(aura::Window* root_window) { | 333 UserSwitchAnimatorChromeOS::GetScreenCover(aura::Window* root_window) { |
334 TransitioningScreenCover cover = NO_USER_COVERS_SCREEN; | 334 TransitioningScreenCover cover = NO_USER_COVERS_SCREEN; |
335 for (MultiUserWindowManagerChromeOS::WindowToEntryMap::const_iterator it_map = | 335 for (MultiUserWindowManagerChromeOS::WindowToEntryMap::const_iterator it_map = |
336 owner_->window_to_entry().begin(); | 336 owner_->window_to_entry().begin(); |
337 it_map != owner_->window_to_entry().end(); | 337 it_map != owner_->window_to_entry().end(); |
338 ++it_map) { | 338 ++it_map) { |
339 aura::Window* window = it_map->first; | 339 aura::Window* window = it_map->first; |
340 if (root_window && window->GetRootWindow() != root_window) | 340 if (root_window && window->GetRootWindow() != root_window) |
341 continue; | 341 continue; |
342 if (window->IsVisible() && CoversScreen(window)) { | 342 if (window->IsVisible() && CoversScreen(window)) { |
343 if (cover == NEW_USER_COVERS_SCREEN) | 343 if (cover == NEW_USER_COVERS_SCREEN) |
344 return BOTH_USERS_COVER_SCREEN; | 344 return BOTH_USERS_COVER_SCREEN; |
345 else | 345 else |
346 cover = OLD_USER_COVERS_SCREEN; | 346 cover = OLD_USER_COVERS_SCREEN; |
347 } else if (owner_->IsWindowOnDesktopOfUser(window, new_user_id_) && | 347 } else if (owner_->IsWindowOnDesktopOfUser(window, new_user_id_) && |
348 CoversScreen(window)) { | 348 CoversScreen(window)) { |
349 if (cover == OLD_USER_COVERS_SCREEN) | 349 if (cover == OLD_USER_COVERS_SCREEN) |
350 return BOTH_USERS_COVER_SCREEN; | 350 return BOTH_USERS_COVER_SCREEN; |
351 else | 351 else |
352 cover = NEW_USER_COVERS_SCREEN; | 352 cover = NEW_USER_COVERS_SCREEN; |
353 } | 353 } |
354 } | 354 } |
355 return cover; | 355 return cover; |
356 } | 356 } |
357 | 357 |
358 } // namespace chrome | 358 } // namespace chrome |
OLD | NEW |