Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/multi_user_window_manager_chromeos.h" | 5 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos.h" |
| 6 | 6 |
| 7 #include "ash/common/media_controller.h" | 7 #include "ash/common/media_controller.h" |
| 8 #include "ash/common/multi_profile_uma.h" | 8 #include "ash/common/multi_profile_uma.h" |
| 9 #include "ash/common/session/session_state_delegate.h" | 9 #include "ash/common/session/session_state_delegate.h" |
| 10 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | 10 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 // in / out. | 51 // in / out. |
| 52 const int kAnimationTimeMS = 100; | 52 const int kAnimationTimeMS = 100; |
| 53 | 53 |
| 54 // The animation time in milliseconds for the fade in and / or out when | 54 // The animation time in milliseconds for the fade in and / or out when |
| 55 // switching users. | 55 // switching users. |
| 56 const int kUserFadeTimeMS = 110; | 56 const int kUserFadeTimeMS = 110; |
| 57 | 57 |
| 58 // The animation time in ms for a window which get teleported to another screen. | 58 // The animation time in ms for a window which get teleported to another screen. |
| 59 const int kTeleportAnimationTimeMS = 300; | 59 const int kTeleportAnimationTimeMS = 300; |
| 60 | 60 |
| 61 // Checks if a given event is a user event. | |
| 62 bool IsUserEvent(const ui::Event* e) { | |
| 63 if (e) { | |
| 64 ui::EventType type = e->type(); | |
| 65 if (type != ui::ET_CANCEL_MODE && | |
| 66 type != ui::ET_UMA_DATA && | |
| 67 type != ui::ET_UNKNOWN) | |
| 68 return true; | |
| 69 } | |
| 70 return false; | |
| 71 } | |
| 72 | |
| 73 // Test if we are currently processing a user event which might lead to a | |
| 74 // browser / app creation. | |
| 75 bool IsProcessingUserEvent() { | |
| 76 // When there is a nested message loop (e.g. active menu or drag and drop | |
| 77 // operation) - we are in a nested loop and can ignore this. | |
| 78 // Note: Unit tests might not have a message loop. | |
| 79 base::MessageLoop* message_loop = base::MessageLoop::current(); | |
| 80 if (message_loop && message_loop->is_running() && message_loop->IsNested()) | |
| 81 return false; | |
| 82 | |
| 83 // TODO(skuhne): "Open link in new window" will come here after the menu got | |
| 84 // closed, executing the command from the nested menu loop. However at that | |
| 85 // time there is no active event processed. A solution for that need to be | |
| 86 // found past M-32. A global event handler filter (pre and post) might fix | |
| 87 // that problem in conjunction with a depth counter - but - for the menu | |
| 88 // execution we come here after the loop was finished (so it's not nested | |
| 89 // anymore) and the root window should therefore still have the event which | |
| 90 // lead to the menu invocation, but it is not. By fixing that problem this | |
| 91 // would "magically work". | |
| 92 aura::Window::Windows root_window_list = ash::Shell::GetAllRootWindows(); | |
| 93 for (aura::Window::Windows::iterator it = root_window_list.begin(); | |
| 94 it != root_window_list.end(); | |
| 95 ++it) { | |
| 96 if (IsUserEvent((*it)->GetHost()->dispatcher()->current_event())) | |
| 97 return true; | |
| 98 } | |
| 99 return false; | |
| 100 } | |
| 101 | |
| 102 // Records the type of window which was transferred to another desktop. | 61 // Records the type of window which was transferred to another desktop. |
| 103 void RecordUMAForTransferredWindowType(aura::Window* window) { | 62 void RecordUMAForTransferredWindowType(aura::Window* window) { |
| 104 // We need to figure out what kind of window this is to record the transfer. | 63 // We need to figure out what kind of window this is to record the transfer. |
| 105 Browser* browser = chrome::FindBrowserWithWindow(window); | 64 Browser* browser = chrome::FindBrowserWithWindow(window); |
| 106 ash::MultiProfileUMA::TeleportWindowType window_type = | 65 ash::MultiProfileUMA::TeleportWindowType window_type = |
| 107 ash::MultiProfileUMA::TELEPORT_WINDOW_UNKNOWN; | 66 ash::MultiProfileUMA::TELEPORT_WINDOW_UNKNOWN; |
| 108 if (browser) { | 67 if (browser) { |
| 109 if (browser->profile()->IsOffTheRecord()) { | 68 if (browser->profile()->IsOffTheRecord()) { |
| 110 window_type = ash::MultiProfileUMA::TELEPORT_WINDOW_INCOGNITO_BROWSER; | 69 window_type = ash::MultiProfileUMA::TELEPORT_WINDOW_INCOGNITO_BROWSER; |
| 111 } else if (browser->is_app()) { | 70 } else if (browser->is_app()) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 | 123 |
| 165 } // namespace | 124 } // namespace |
| 166 | 125 |
| 167 namespace chrome { | 126 namespace chrome { |
| 168 | 127 |
| 169 // A class to temporarily change the animation properties for a window. | 128 // A class to temporarily change the animation properties for a window. |
| 170 class AnimationSetter { | 129 class AnimationSetter { |
| 171 public: | 130 public: |
| 172 AnimationSetter(aura::Window* window, int animation_time_in_ms) | 131 AnimationSetter(aura::Window* window, int animation_time_in_ms) |
| 173 : window_(window), | 132 : window_(window), |
| 174 previous_animation_type_( | 133 previous_animation_type_(wm::GetWindowVisibilityAnimationType(window_)), |
| 175 wm::GetWindowVisibilityAnimationType(window_)), | |
| 176 previous_animation_time_( | 134 previous_animation_time_( |
| 177 wm::GetWindowVisibilityAnimationDuration(*window_)) { | 135 wm::GetWindowVisibilityAnimationDuration(*window_)) { |
| 178 wm::SetWindowVisibilityAnimationType( | 136 wm::SetWindowVisibilityAnimationType( |
| 179 window_, | 137 window_, wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); |
| 180 wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); | |
| 181 wm::SetWindowVisibilityAnimationDuration( | 138 wm::SetWindowVisibilityAnimationDuration( |
| 182 window_, | 139 window_, base::TimeDelta::FromMilliseconds(animation_time_in_ms)); |
| 183 base::TimeDelta::FromMilliseconds(animation_time_in_ms)); | |
| 184 } | 140 } |
| 185 | 141 |
| 186 ~AnimationSetter() { | 142 ~AnimationSetter() { |
| 187 wm::SetWindowVisibilityAnimationType(window_, | 143 wm::SetWindowVisibilityAnimationType(window_, previous_animation_type_); |
| 188 previous_animation_type_); | 144 wm::SetWindowVisibilityAnimationDuration(window_, previous_animation_time_); |
|
Qiang(Joe) Xu
2017/02/08 00:57:36
This trunk is just formatting.
| |
| 189 wm::SetWindowVisibilityAnimationDuration( | |
| 190 window_, | |
| 191 previous_animation_time_); | |
| 192 } | 145 } |
| 193 | 146 |
| 194 private: | 147 private: |
| 195 // The window which gets used. | 148 // The window which gets used. |
| 196 aura::Window* window_; | 149 aura::Window* window_; |
| 197 | 150 |
| 198 // Previous animation type. | 151 // Previous animation type. |
| 199 const int previous_animation_type_; | 152 const int previous_animation_type_; |
| 200 | 153 |
| 201 // Previous animation time. | 154 // Previous animation time. |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 DCHECK(GetWindowOwner(window).empty()); | 263 DCHECK(GetWindowOwner(window).empty()); |
| 311 window_to_entry_[window] = new WindowEntry(account_id); | 264 window_to_entry_[window] = new WindowEntry(account_id); |
| 312 | 265 |
| 313 // Remember the initial visibility of the window. | 266 // Remember the initial visibility of the window. |
| 314 window_to_entry_[window]->set_show(window->IsVisible()); | 267 window_to_entry_[window]->set_show(window->IsVisible()); |
| 315 | 268 |
| 316 // Add observers to track state changes. | 269 // Add observers to track state changes. |
| 317 window->AddObserver(this); | 270 window->AddObserver(this); |
| 318 wm::TransientWindowManager::Get(window)->AddObserver(this); | 271 wm::TransientWindowManager::Get(window)->AddObserver(this); |
| 319 | 272 |
| 320 // Check if this window was created due to a user interaction. If it was, | |
| 321 // transfer it to the current user. | |
| 322 if (IsProcessingUserEvent()) | |
| 323 window_to_entry_[window]->set_show_for_user(current_account_id_); | |
|
Qiang(Joe) Xu
2017/02/08 00:57:36
we don't need this.. checked https://codereview.ch
| |
| 324 | |
| 325 // Add all transient children to our set of windows. Note that the function | 273 // Add all transient children to our set of windows. Note that the function |
| 326 // will add the children but not the owner to the transient children map. | 274 // will add the children but not the owner to the transient children map. |
| 327 AddTransientOwnerRecursive(window, window); | 275 AddTransientOwnerRecursive(window, window); |
| 328 | 276 |
| 329 // Notify entry adding. | 277 // Notify entry adding. |
| 330 for (Observer& observer : observers_) | 278 for (Observer& observer : observers_) |
| 331 observer.OnOwnerEntryAdded(window); | 279 observer.OnOwnerEntryAdded(window); |
| 332 | 280 |
| 333 if (!IsWindowOnDesktopOfUser(window, current_account_id_)) | 281 if (!IsWindowOnDesktopOfUser(window, current_account_id_)) |
| 334 SetWindowVisibility(window, false, 0); | 282 SetWindowVisibility(window, false, 0); |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 637 void MultiUserWindowManagerChromeOS::NotifyAfterUserSwitchAnimationFinished() { | 585 void MultiUserWindowManagerChromeOS::NotifyAfterUserSwitchAnimationFinished() { |
| 638 for (Observer& observer : observers_) | 586 for (Observer& observer : observers_) |
| 639 observer.OnUserSwitchAnimationFinished(); | 587 observer.OnUserSwitchAnimationFinished(); |
| 640 } | 588 } |
| 641 | 589 |
| 642 void MultiUserWindowManagerChromeOS::AddBrowserWindow(Browser* browser) { | 590 void MultiUserWindowManagerChromeOS::AddBrowserWindow(Browser* browser) { |
| 643 // A unit test (e.g. CrashRestoreComplexTest.RestoreSessionForThreeUsers) can | 591 // A unit test (e.g. CrashRestoreComplexTest.RestoreSessionForThreeUsers) can |
| 644 // come here with no valid window. | 592 // come here with no valid window. |
| 645 if (!browser->window() || !browser->window()->GetNativeWindow()) | 593 if (!browser->window() || !browser->window()->GetNativeWindow()) |
| 646 return; | 594 return; |
| 647 SetWindowOwner(browser->window()->GetNativeWindow(), | 595 aura::Window* native_window = browser->window()->GetNativeWindow(); |
| 596 SetWindowOwner(native_window, | |
| 648 multi_user_util::GetAccountIdFromProfile(browser->profile())); | 597 multi_user_util::GetAccountIdFromProfile(browser->profile())); |
| 598 window_to_entry_[native_window]->set_show_for_user(current_account_id_); | |
|
oshima
2017/02/08 01:29:31
Won't this always open the window in the current a
| |
| 649 } | 599 } |
| 650 | 600 |
| 651 void MultiUserWindowManagerChromeOS::ShowWithTransientChildrenRecursive( | 601 void MultiUserWindowManagerChromeOS::ShowWithTransientChildrenRecursive( |
| 652 aura::Window* window, int animation_time_in_ms) { | 602 aura::Window* window, int animation_time_in_ms) { |
| 653 aura::Window::Windows::const_iterator it = | 603 aura::Window::Windows::const_iterator it = |
| 654 wm::GetTransientChildren(window).begin(); | 604 wm::GetTransientChildren(window).begin(); |
| 655 for (; it != wm::GetTransientChildren(window).end(); ++it) | 605 for (; it != wm::GetTransientChildren(window).end(); ++it) |
| 656 ShowWithTransientChildrenRecursive(*it, animation_time_in_ms); | 606 ShowWithTransientChildrenRecursive(*it, animation_time_in_ms); |
| 657 | 607 |
| 658 // We show all children which were not explicitly hidden. | 608 // We show all children which were not explicitly hidden. |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 756 window->Hide(); | 706 window->Hide(); |
| 757 } | 707 } |
| 758 | 708 |
| 759 int MultiUserWindowManagerChromeOS::GetAdjustedAnimationTimeInMS( | 709 int MultiUserWindowManagerChromeOS::GetAdjustedAnimationTimeInMS( |
| 760 int default_time_in_ms) const { | 710 int default_time_in_ms) const { |
| 761 return animation_speed_ == ANIMATION_SPEED_NORMAL ? default_time_in_ms : | 711 return animation_speed_ == ANIMATION_SPEED_NORMAL ? default_time_in_ms : |
| 762 (animation_speed_ == ANIMATION_SPEED_FAST ? 10 : 0); | 712 (animation_speed_ == ANIMATION_SPEED_FAST ? 10 : 0); |
| 763 } | 713 } |
| 764 | 714 |
| 765 } // namespace chrome | 715 } // namespace chrome |
| OLD | NEW |