| 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/shell.h" | 11 #include "ash/shell.h" |
| 11 #include "ash/wm/mru_window_tracker.h" | 12 #include "ash/wm/mru_window_tracker.h" |
| 12 #include "ash/wm/window_positioner.h" | 13 #include "ash/wm/window_positioner.h" |
| 13 #include "ash/wm/window_state.h" | 14 #include "ash/wm/window_state.h" |
| 14 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | 15 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
| 15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 16 #include "chrome/browser/ui/ash/multi_user/multi_user_notification_blocker_chrom
eos.h" | 17 #include "chrome/browser/ui/ash/multi_user/multi_user_notification_blocker_chrom
eos.h" |
| 17 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos.h" | 18 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos.h" |
| 18 #include "ui/wm/public/activation_client.h" | 19 #include "ui/wm/public/activation_client.h" |
| 19 | 20 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 46 } // namespace | 47 } // namespace |
| 47 | 48 |
| 48 UserSwichAnimatorChromeOS::UserSwichAnimatorChromeOS( | 49 UserSwichAnimatorChromeOS::UserSwichAnimatorChromeOS( |
| 49 MultiUserWindowManagerChromeOS* owner, | 50 MultiUserWindowManagerChromeOS* owner, |
| 50 const std::string& new_user_id, | 51 const std::string& new_user_id, |
| 51 int animation_speed_ms) | 52 int animation_speed_ms) |
| 52 : owner_(owner), | 53 : owner_(owner), |
| 53 new_user_id_(new_user_id), | 54 new_user_id_(new_user_id), |
| 54 animation_speed_ms_(animation_speed_ms), | 55 animation_speed_ms_(animation_speed_ms), |
| 55 animation_step_(ANIMATION_STEP_HIDE_OLD_USER), | 56 animation_step_(ANIMATION_STEP_HIDE_OLD_USER), |
| 56 screen_cover_(GetScreenCover()) { | 57 screen_cover_(GetScreenCover(NULL)) { |
| 57 AdvanceUserTransitionAnimation(); | 58 AdvanceUserTransitionAnimation(); |
| 58 | 59 |
| 59 if (!animation_speed_ms_) { | 60 if (!animation_speed_ms_) { |
| 60 FinalizeAnimation(); | 61 FinalizeAnimation(); |
| 61 } else { | 62 } else { |
| 62 user_changed_animation_timer_.reset(new base::Timer( | 63 user_changed_animation_timer_.reset(new base::Timer( |
| 63 FROM_HERE, | 64 FROM_HERE, |
| 64 base::TimeDelta::FromMilliseconds(animation_speed_ms_), | 65 base::TimeDelta::FromMilliseconds(animation_speed_ms_), |
| 65 base::Bind( | 66 base::Bind( |
| 66 &UserSwichAnimatorChromeOS::AdvanceUserTransitionAnimation, | 67 &UserSwichAnimatorChromeOS::AdvanceUserTransitionAnimation, |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 | 150 |
| 150 // 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 |
| 151 // got here. | 152 // got here. |
| 152 wallpaper_user_id_ = new_user_id_; | 153 wallpaper_user_id_ = new_user_id_; |
| 153 wallpaper_delegate->SetAnimationDurationOverride(0); | 154 wallpaper_delegate->SetAnimationDurationOverride(0); |
| 154 } | 155 } |
| 155 } | 156 } |
| 156 | 157 |
| 157 void UserSwichAnimatorChromeOS::TransitionUserShelf( | 158 void UserSwichAnimatorChromeOS::TransitionUserShelf( |
| 158 AnimationStep animation_step) { | 159 AnimationStep animation_step) { |
| 160 ChromeLauncherController* chrome_launcher_controller = |
| 161 ChromeLauncherController::instance(); |
| 159 // The shelf animation duration override. | 162 // The shelf animation duration override. |
| 160 int duration_override = animation_speed_ms_; | 163 int duration_override = animation_speed_ms_; |
| 161 // 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. |
| 162 if (animation_step == ANIMATION_STEP_SHOW_NEW_USER) { | 165 if (animation_step == ANIMATION_STEP_SHOW_NEW_USER) { |
| 163 // Some unit tests have no ChromeLauncherController. | 166 // Some unit tests have no ChromeLauncherController. |
| 164 if (ChromeLauncherController::instance()) | 167 if (chrome_launcher_controller) |
| 165 ChromeLauncherController::instance()->ActiveUserChanged(new_user_id_); | 168 chrome_launcher_controller->ActiveUserChanged(new_user_id_); |
| 166 // We kicked off the shelf animation in the command above. As such we can | 169 // Hide the black rectangle on top of each shelf again. |
| 167 // disable the override now again. | 170 aura::Window::Windows root_windows = ash::Shell::GetAllRootWindows(); |
| 171 for (aura::Window::Windows::const_iterator iter = root_windows.begin(); |
| 172 iter != root_windows.end(); ++iter) { |
| 173 ash::ShelfWidget* shelf = |
| 174 ash::RootWindowController::ForWindow(*iter)->shelf(); |
| 175 shelf->HideShelfBehindBlackBar(false, duration_override); |
| 176 } |
| 177 // We kicked off the shelf animation above and the override can be |
| 178 // removed. |
| 168 duration_override = 0; | 179 duration_override = 0; |
| 169 } | 180 } |
| 170 | 181 |
| 171 if (!animation_speed_ms_ || animation_step == ANIMATION_STEP_FINALIZE) | 182 if (!animation_speed_ms_ || animation_step == ANIMATION_STEP_FINALIZE) |
| 172 return; | 183 return; |
| 173 | 184 |
| 185 // Note: The animation duration override will be set before the old user gets |
| 186 // hidden and reset after the animations for the new user got kicked off. |
| 174 ash::Shell::RootWindowControllerList controller = | 187 ash::Shell::RootWindowControllerList controller = |
| 175 ash::Shell::GetInstance()->GetAllRootWindowControllers(); | 188 ash::Shell::GetInstance()->GetAllRootWindowControllers(); |
| 176 for (ash::Shell::RootWindowControllerList::iterator iter = controller.begin(); | 189 for (ash::Shell::RootWindowControllerList::iterator iter = controller.begin(); |
| 177 iter != controller.end(); ++iter) { | 190 iter != controller.end(); ++iter) { |
| 178 (*iter)->GetShelfLayoutManager()->SetAnimationDurationOverride( | 191 (*iter)->GetShelfLayoutManager()->SetAnimationDurationOverride( |
| 179 duration_override); | 192 duration_override); |
| 180 } | 193 } |
| 181 | 194 |
| 195 if (animation_step != ANIMATION_STEP_HIDE_OLD_USER) |
| 196 return; |
| 197 |
| 182 // For each root window hide the shelf. | 198 // For each root window hide the shelf. |
| 183 if (animation_step == ANIMATION_STEP_HIDE_OLD_USER) { | 199 aura::Window::Windows root_windows = ash::Shell::GetAllRootWindows(); |
| 184 aura::Window::Windows root_windows = ash::Shell::GetAllRootWindows(); | 200 |
| 185 for (aura::Window::Windows::const_iterator iter = root_windows.begin(); | 201 for (aura::Window::Windows::const_iterator iter = root_windows.begin(); |
| 186 iter != root_windows.end(); ++iter) { | 202 iter != root_windows.end(); ++iter) { |
| 203 // Hiding the shelf will cause a resize on a maximized window. |
| 204 // If the shelf is then shown for the following user in the same location, |
| 205 // the window gets resized again. Since each resize can cause a considerable |
| 206 // CPU usage and therefore effect jank, we should avoid hiding the shelf if |
| 207 // the start and end location are the same and cover the shelf instead with |
| 208 // a black rectangle on top. |
| 209 if (GetScreenCover(*iter) != NO_USER_COVERS_SCREEN && |
| 210 (!chrome_launcher_controller || |
| 211 !chrome_launcher_controller->ShelfBoundsChangesProbablyWithUser( |
| 212 *iter, new_user_id_))) { |
| 213 ash::ShelfWidget* shelf = |
| 214 ash::RootWindowController::ForWindow(*iter)->shelf(); |
| 215 shelf->HideShelfBehindBlackBar(true, duration_override); |
| 216 } else { |
| 187 // 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 |
| 188 // ChromeLauncherController::ActiveUserChanged() to the new users value. | 218 // ChromeLauncherController::ActiveUserChanged() to the new users value. |
| 189 // Note that the user preference will not be changed. | 219 // Note that the user preference will not be changed. |
| 190 ash::Shell::GetInstance()->SetShelfAutoHideBehavior( | 220 ash::Shell::GetInstance()->SetShelfAutoHideBehavior( |
| 191 ash::SHELF_AUTO_HIDE_ALWAYS_HIDDEN, *iter); | 221 ash::SHELF_AUTO_HIDE_ALWAYS_HIDDEN, *iter); |
| 192 } | 222 } |
| 193 } | 223 } |
| 194 } | 224 } |
| 195 | 225 |
| 196 void UserSwichAnimatorChromeOS::TransitionWindows( | 226 void UserSwichAnimatorChromeOS::TransitionWindows( |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 } | 323 } |
| 294 } | 324 } |
| 295 | 325 |
| 296 // 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 |
| 297 // the new window status. | 327 // the new window status. |
| 298 owner_->notification_blocker()->ActiveUserChanged(new_user_id_); | 328 owner_->notification_blocker()->ActiveUserChanged(new_user_id_); |
| 299 } | 329 } |
| 300 } | 330 } |
| 301 | 331 |
| 302 UserSwichAnimatorChromeOS::TransitioningScreenCover | 332 UserSwichAnimatorChromeOS::TransitioningScreenCover |
| 303 UserSwichAnimatorChromeOS::GetScreenCover() { | 333 UserSwichAnimatorChromeOS::GetScreenCover(aura::Window* root_window) { |
| 304 TransitioningScreenCover cover = NO_USER_COVERS_SCREEN; | 334 TransitioningScreenCover cover = NO_USER_COVERS_SCREEN; |
| 305 for (MultiUserWindowManagerChromeOS::WindowToEntryMap::const_iterator it_map = | 335 for (MultiUserWindowManagerChromeOS::WindowToEntryMap::const_iterator it_map = |
| 306 owner_->window_to_entry().begin(); | 336 owner_->window_to_entry().begin(); |
| 307 it_map != owner_->window_to_entry().end(); | 337 it_map != owner_->window_to_entry().end(); |
| 308 ++it_map) { | 338 ++it_map) { |
| 309 aura::Window* window = it_map->first; | 339 aura::Window* window = it_map->first; |
| 340 if (root_window && window->GetRootWindow() != root_window) |
| 341 continue; |
| 310 if (window->IsVisible() && CoversScreen(window)) { | 342 if (window->IsVisible() && CoversScreen(window)) { |
| 311 if (cover == NEW_USER_COVERS_SCREEN) | 343 if (cover == NEW_USER_COVERS_SCREEN) |
| 312 return BOTH_USERS_COVER_SCREEN; | 344 return BOTH_USERS_COVER_SCREEN; |
| 313 else | 345 else |
| 314 cover = OLD_USER_COVERS_SCREEN; | 346 cover = OLD_USER_COVERS_SCREEN; |
| 315 } else if (owner_->IsWindowOnDesktopOfUser(window, new_user_id_) && | 347 } else if (owner_->IsWindowOnDesktopOfUser(window, new_user_id_) && |
| 316 CoversScreen(window)) { | 348 CoversScreen(window)) { |
| 317 if (cover == OLD_USER_COVERS_SCREEN) | 349 if (cover == OLD_USER_COVERS_SCREEN) |
| 318 return BOTH_USERS_COVER_SCREEN; | 350 return BOTH_USERS_COVER_SCREEN; |
| 319 else | 351 else |
| 320 cover = NEW_USER_COVERS_SCREEN; | 352 cover = NEW_USER_COVERS_SCREEN; |
| 321 } | 353 } |
| 322 } | 354 } |
| 323 return cover; | 355 return cover; |
| 324 } | 356 } |
| 325 | 357 |
| 326 } // namespace chrome | 358 } // namespace chrome |
| OLD | NEW |