| 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/shell.h" | 10 #include "ash/shell.h" |
| 11 #include "ash/wm/mru_window_tracker.h" | 11 #include "ash/wm/mru_window_tracker.h" |
| 12 #include "ash/wm/window_positioner.h" | 12 #include "ash/wm/window_positioner.h" |
| 13 #include "ash/wm/window_state.h" | 13 #include "ash/wm/window_state.h" |
| 14 #include "chrome/browser/chromeos/login/wallpaper_manager.h" | 14 #include "chrome/browser/chromeos/login/wallpaper_manager.h" |
| 15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 15 #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" | 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_window_manager_chromeos.h" | 17 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos.h" |
| 18 #include "ui/wm/public/activation_client.h" | 18 #include "ui/wm/public/activation_client.h" |
| 19 | 19 |
| 20 namespace chrome { | 20 namespace chrome { |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 // The animation time in milliseconds for the fade in and / or out when | |
| 25 // switching users. | |
| 26 const int kUserFadeTimeMS = 110; | |
| 27 | |
| 28 // The minimal possible animation time for animations which should happen | 24 // The minimal possible animation time for animations which should happen |
| 29 // "instantly". | 25 // "instantly". |
| 30 const int kMinimalAnimationTimeMS = 1; | 26 const int kMinimalAnimationTimeMS = 1; |
| 31 | 27 |
| 32 // logic while the user gets switched. | 28 // logic while the user gets switched. |
| 33 class UserChangeActionDisabler { | 29 class UserChangeActionDisabler { |
| 34 public: | 30 public: |
| 35 UserChangeActionDisabler() { | 31 UserChangeActionDisabler() { |
| 36 ash::WindowPositioner::DisableAutoPositioning(true); | 32 ash::WindowPositioner::DisableAutoPositioning(true); |
| 37 ash::Shell::GetInstance()->mru_window_tracker()->SetIgnoreActivations(true); | 33 ash::Shell::GetInstance()->mru_window_tracker()->SetIgnoreActivations(true); |
| 38 } | 34 } |
| 39 | 35 |
| 40 ~UserChangeActionDisabler() { | 36 ~UserChangeActionDisabler() { |
| 41 ash::WindowPositioner::DisableAutoPositioning(false); | 37 ash::WindowPositioner::DisableAutoPositioning(false); |
| 42 ash::Shell::GetInstance()->mru_window_tracker()->SetIgnoreActivations( | 38 ash::Shell::GetInstance()->mru_window_tracker()->SetIgnoreActivations( |
| 43 false); | 39 false); |
| 44 } | 40 } |
| 45 private: | 41 private: |
| 46 | 42 |
| 47 DISALLOW_COPY_AND_ASSIGN(UserChangeActionDisabler); | 43 DISALLOW_COPY_AND_ASSIGN(UserChangeActionDisabler); |
| 48 }; | 44 }; |
| 49 | 45 |
| 50 } // namespace | 46 } // namespace |
| 51 | 47 |
| 52 UserSwichAnimatorChromeOS::UserSwichAnimatorChromeOS( | 48 UserSwichAnimatorChromeOS::UserSwichAnimatorChromeOS( |
| 53 MultiUserWindowManagerChromeOS* owner, | 49 MultiUserWindowManagerChromeOS* owner, |
| 54 const std::string& new_user_id, | 50 const std::string& new_user_id, |
| 55 bool animation_disabled) | 51 int animation_speed_ms) |
| 56 : owner_(owner), | 52 : owner_(owner), |
| 57 new_user_id_(new_user_id), | 53 new_user_id_(new_user_id), |
| 58 animation_disabled_(animation_disabled), | 54 animation_speed_ms_(animation_speed_ms), |
| 59 animation_step_(ANIMATION_STEP_HIDE_OLD_USER), | 55 animation_step_(ANIMATION_STEP_HIDE_OLD_USER), |
| 60 screen_cover_(GetScreenCover()) { | 56 screen_cover_(GetScreenCover()) { |
| 61 AdvanceUserTransitionAnimation(); | 57 AdvanceUserTransitionAnimation(); |
| 62 | 58 |
| 63 if (animation_disabled_) { | 59 if (!animation_speed_ms_) { |
| 64 FinalizeAnimation(); | 60 FinalizeAnimation(); |
| 65 } else { | 61 } else { |
| 66 user_changed_animation_timer_.reset(new base::Timer( | 62 user_changed_animation_timer_.reset(new base::Timer( |
| 67 FROM_HERE, | 63 FROM_HERE, |
| 68 base::TimeDelta::FromMilliseconds(kUserFadeTimeMS), | 64 base::TimeDelta::FromMilliseconds(animation_speed_ms_), |
| 69 base::Bind( | 65 base::Bind( |
| 70 &UserSwichAnimatorChromeOS::AdvanceUserTransitionAnimation, | 66 &UserSwichAnimatorChromeOS::AdvanceUserTransitionAnimation, |
| 71 base::Unretained(this)), | 67 base::Unretained(this)), |
| 72 true)); | 68 true)); |
| 73 user_changed_animation_timer_->Reset(); | 69 user_changed_animation_timer_->Reset(); |
| 74 } | 70 } |
| 75 } | 71 } |
| 76 | 72 |
| 77 UserSwichAnimatorChromeOS::~UserSwichAnimatorChromeOS() { | 73 UserSwichAnimatorChromeOS::~UserSwichAnimatorChromeOS() { |
| 78 FinalizeAnimation(); | 74 FinalizeAnimation(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 } | 124 } |
| 129 | 125 |
| 130 void UserSwichAnimatorChromeOS::TransitionWallpaper( | 126 void UserSwichAnimatorChromeOS::TransitionWallpaper( |
| 131 AnimationStep animation_step) { | 127 AnimationStep animation_step) { |
| 132 // Handle the wallpaper switch. | 128 // Handle the wallpaper switch. |
| 133 ash::UserWallpaperDelegate* wallpaper_delegate = | 129 ash::UserWallpaperDelegate* wallpaper_delegate = |
| 134 ash::Shell::GetInstance()->user_wallpaper_delegate(); | 130 ash::Shell::GetInstance()->user_wallpaper_delegate(); |
| 135 if (animation_step == ANIMATION_STEP_HIDE_OLD_USER) { | 131 if (animation_step == ANIMATION_STEP_HIDE_OLD_USER) { |
| 136 // Set the wallpaper cross dissolve animation duration to our complete | 132 // Set the wallpaper cross dissolve animation duration to our complete |
| 137 // animation cycle for a fade in and fade out. | 133 // animation cycle for a fade in and fade out. |
| 134 int duration = |
| 135 NO_USER_COVERS_SCREEN == screen_cover_ ? (2 * animation_speed_ms_) : 0; |
| 138 wallpaper_delegate->SetAnimationDurationOverride( | 136 wallpaper_delegate->SetAnimationDurationOverride( |
| 139 NO_USER_COVERS_SCREEN == screen_cover_ ? (2 * kUserFadeTimeMS) : | 137 std::max(duration, kMinimalAnimationTimeMS)); |
| 140 kMinimalAnimationTimeMS); | |
| 141 if (screen_cover_ != NEW_USER_COVERS_SCREEN) { | 138 if (screen_cover_ != NEW_USER_COVERS_SCREEN) { |
| 142 chromeos::WallpaperManager::Get()->SetUserWallpaperNow(new_user_id_); | 139 chromeos::WallpaperManager::Get()->SetUserWallpaperNow(new_user_id_); |
| 143 wallpaper_user_id_ = | 140 wallpaper_user_id_ = |
| 144 (NO_USER_COVERS_SCREEN == screen_cover_ ? "->" : "") + | 141 (NO_USER_COVERS_SCREEN == screen_cover_ ? "->" : "") + |
| 145 new_user_id_; | 142 new_user_id_; |
| 146 } | 143 } |
| 147 } else if (animation_step == ANIMATION_STEP_FINALIZE) { | 144 } else if (animation_step == ANIMATION_STEP_FINALIZE) { |
| 148 // Revert the wallpaper cross dissolve animation duration back to the | 145 // Revert the wallpaper cross dissolve animation duration back to the |
| 149 // default. | 146 // default. |
| 150 if (screen_cover_ == NEW_USER_COVERS_SCREEN) | 147 if (screen_cover_ == NEW_USER_COVERS_SCREEN) |
| 151 chromeos::WallpaperManager::Get()->SetUserWallpaperNow(new_user_id_); | 148 chromeos::WallpaperManager::Get()->SetUserWallpaperNow(new_user_id_); |
| 152 | 149 |
| 153 // Coming here the wallpaper user id is the final result. No matter how we | 150 // Coming here the wallpaper user id is the final result. No matter how we |
| 154 // got here. | 151 // got here. |
| 155 wallpaper_user_id_ = new_user_id_; | 152 wallpaper_user_id_ = new_user_id_; |
| 156 wallpaper_delegate->SetAnimationDurationOverride(0); | 153 wallpaper_delegate->SetAnimationDurationOverride(0); |
| 157 } | 154 } |
| 158 } | 155 } |
| 159 | 156 |
| 160 void UserSwichAnimatorChromeOS::TransitionUserShelf( | 157 void UserSwichAnimatorChromeOS::TransitionUserShelf( |
| 161 AnimationStep animation_step) { | 158 AnimationStep animation_step) { |
| 162 // The shelf animation duration override. | 159 // The shelf animation duration override. |
| 163 int duration_override = kUserFadeTimeMS; | 160 int duration_override = animation_speed_ms_; |
| 164 // Handle the shelf order of items. This is done once the old user is hidden. | 161 // Handle the shelf order of items. This is done once the old user is hidden. |
| 165 if (animation_step == ANIMATION_STEP_SHOW_NEW_USER) { | 162 if (animation_step == ANIMATION_STEP_SHOW_NEW_USER) { |
| 166 // Some unit tests have no ChromeLauncherController. | 163 // Some unit tests have no ChromeLauncherController. |
| 167 if (ChromeLauncherController::instance()) | 164 if (ChromeLauncherController::instance()) |
| 168 ChromeLauncherController::instance()->ActiveUserChanged(new_user_id_); | 165 ChromeLauncherController::instance()->ActiveUserChanged(new_user_id_); |
| 169 // We kicked off the shelf animation in the command above. As such we can | 166 // We kicked off the shelf animation in the command above. As such we can |
| 170 // disable the override now again. | 167 // disable the override now again. |
| 171 duration_override = 0; | 168 duration_override = 0; |
| 172 } | 169 } |
| 173 | 170 |
| 174 if (animation_disabled_ || animation_step == ANIMATION_STEP_FINALIZE) | 171 if (!animation_speed_ms_ || animation_step == ANIMATION_STEP_FINALIZE) |
| 175 return; | 172 return; |
| 176 | 173 |
| 177 ash::Shell::RootWindowControllerList controller = | 174 ash::Shell::RootWindowControllerList controller = |
| 178 ash::Shell::GetInstance()->GetAllRootWindowControllers(); | 175 ash::Shell::GetInstance()->GetAllRootWindowControllers(); |
| 179 for (ash::Shell::RootWindowControllerList::iterator iter = controller.begin(); | 176 for (ash::Shell::RootWindowControllerList::iterator iter = controller.begin(); |
| 180 iter != controller.end(); ++iter) { | 177 iter != controller.end(); ++iter) { |
| 181 (*iter)->GetShelfLayoutManager()->SetAnimationDurationOverride( | 178 (*iter)->GetShelfLayoutManager()->SetAnimationDurationOverride( |
| 182 duration_override); | 179 duration_override); |
| 183 } | 180 } |
| 184 | 181 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 ash::wm::WindowState* window_state = ash::wm::GetWindowState(window); | 243 ash::wm::WindowState* window_state = ash::wm::GetWindowState(window); |
| 247 if (it_map->second->owner() == new_user_id_ && | 244 if (it_map->second->owner() == new_user_id_ && |
| 248 it_map->second->show_for_user() != new_user_id_ && | 245 it_map->second->show_for_user() != new_user_id_ && |
| 249 window_state->IsMinimized()) { | 246 window_state->IsMinimized()) { |
| 250 // Pull back minimized visiting windows to the owners desktop. | 247 // Pull back minimized visiting windows to the owners desktop. |
| 251 owner_->ShowWindowForUserIntern(window, new_user_id_); | 248 owner_->ShowWindowForUserIntern(window, new_user_id_); |
| 252 window_state->Unminimize(); | 249 window_state->Unminimize(); |
| 253 } else if (should_be_visible != is_visible) { | 250 } else if (should_be_visible != is_visible) { |
| 254 bool animate = true; | 251 bool animate = true; |
| 255 int duration = animation_step == ANIMATION_STEP_FINALIZE ? | 252 int duration = animation_step == ANIMATION_STEP_FINALIZE ? |
| 256 kMinimalAnimationTimeMS : (2 * kUserFadeTimeMS); | 253 0 : (2 * animation_speed_ms_); |
| 254 duration = std::max(kMinimalAnimationTimeMS, duration); |
| 257 if (animation_step != ANIMATION_STEP_FINALIZE && | 255 if (animation_step != ANIMATION_STEP_FINALIZE && |
| 258 screen_cover_ == BOTH_USERS_COVER_SCREEN && | 256 screen_cover_ == BOTH_USERS_COVER_SCREEN && |
| 259 CoversScreen(window)) { | 257 CoversScreen(window)) { |
| 260 if (!foreground_window_found) { | 258 if (!foreground_window_found) { |
| 261 foreground_window_found = true; | 259 foreground_window_found = true; |
| 262 foreground_becomes_visible = should_be_visible; | 260 foreground_becomes_visible = should_be_visible; |
| 263 } else if (should_be_visible != foreground_becomes_visible) { | 261 } else if (should_be_visible != foreground_becomes_visible) { |
| 264 // Covering windows behind the foreground window which are | 262 // Covering windows behind the foreground window which are |
| 265 // inverting their visibility should immediately become visible | 263 // inverting their visibility should immediately become visible |
| 266 // or stay visible until the animation is finished. | 264 // or stay visible until the animation is finished. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 if (cover == OLD_USER_COVERS_SCREEN) | 317 if (cover == OLD_USER_COVERS_SCREEN) |
| 320 return BOTH_USERS_COVER_SCREEN; | 318 return BOTH_USERS_COVER_SCREEN; |
| 321 else | 319 else |
| 322 cover = NEW_USER_COVERS_SCREEN; | 320 cover = NEW_USER_COVERS_SCREEN; |
| 323 } | 321 } |
| 324 } | 322 } |
| 325 return cover; | 323 return cover; |
| 326 } | 324 } |
| 327 | 325 |
| 328 } // namespace chrome | 326 } // namespace chrome |
| OLD | NEW |