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 "apps/shell_window.h" | 7 #include "apps/shell_window.h" |
8 #include "apps/shell_window_registry.h" | 8 #include "apps/shell_window_registry.h" |
9 #include "ash/ash_switches.h" | 9 #include "ash/ash_switches.h" |
10 #include "ash/multi_profile_uma.h" | 10 #include "ash/multi_profile_uma.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "chrome/browser/ui/browser_list.h" | 29 #include "chrome/browser/ui/browser_list.h" |
30 #include "chrome/browser/ui/browser_window.h" | 30 #include "chrome/browser/ui/browser_window.h" |
31 #include "content/public/browser/notification_service.h" | 31 #include "content/public/browser/notification_service.h" |
32 #include "google_apis/gaia/gaia_auth_util.h" | 32 #include "google_apis/gaia/gaia_auth_util.h" |
33 #include "ui/aura/client/activation_client.h" | 33 #include "ui/aura/client/activation_client.h" |
34 #include "ui/aura/client/aura_constants.h" | 34 #include "ui/aura/client/aura_constants.h" |
35 #include "ui/aura/root_window.h" | 35 #include "ui/aura/root_window.h" |
36 #include "ui/aura/window.h" | 36 #include "ui/aura/window.h" |
37 #include "ui/base/ui_base_types.h" | 37 #include "ui/base/ui_base_types.h" |
38 #include "ui/events/event.h" | 38 #include "ui/events/event.h" |
| 39 #include "ui/views/corewm/transient_window_manager.h" |
39 #include "ui/views/corewm/window_util.h" | 40 #include "ui/views/corewm/window_util.h" |
40 | 41 |
41 namespace { | 42 namespace { |
42 | 43 |
43 // Checks if a given event is a user event. | 44 // Checks if a given event is a user event. |
44 bool IsUserEvent(ui::Event* e) { | 45 bool IsUserEvent(ui::Event* e) { |
45 if (e) { | 46 if (e) { |
46 ui::EventType type = e->type(); | 47 ui::EventType type = e->type(); |
47 if (type != ui::ET_CANCEL_MODE && | 48 if (type != ui::ET_CANCEL_MODE && |
48 type != ui::ET_UMA_DATA && | 49 type != ui::ET_UMA_DATA && |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 DCHECK(window); | 229 DCHECK(window); |
229 DCHECK(!user_id.empty()); | 230 DCHECK(!user_id.empty()); |
230 if (GetWindowOwner(window) == user_id) | 231 if (GetWindowOwner(window) == user_id) |
231 return; | 232 return; |
232 DCHECK(GetWindowOwner(window).empty()); | 233 DCHECK(GetWindowOwner(window).empty()); |
233 window_to_entry_[window] = new WindowEntry(user_id); | 234 window_to_entry_[window] = new WindowEntry(user_id); |
234 | 235 |
235 // Remember the initial visibility of the window. | 236 // Remember the initial visibility of the window. |
236 window_to_entry_[window]->set_show(window->IsVisible()); | 237 window_to_entry_[window]->set_show(window->IsVisible()); |
237 | 238 |
238 // Set the window and the state observer. | 239 // Add observers to track state changes. |
239 window->AddObserver(this); | 240 window->AddObserver(this); |
240 ash::wm::GetWindowState(window)->AddObserver(this); | 241 ash::wm::GetWindowState(window)->AddObserver(this); |
| 242 views::corewm::TransientWindowManager::Get(window)->AddObserver(this); |
241 | 243 |
242 // Check if this window was created due to a user interaction. If it was, | 244 // Check if this window was created due to a user interaction. If it was, |
243 // transfer it to the current user. | 245 // transfer it to the current user. |
244 if (IsProcessingUserEvent()) | 246 if (IsProcessingUserEvent()) |
245 window_to_entry_[window]->set_show_for_user(current_user_id_); | 247 window_to_entry_[window]->set_show_for_user(current_user_id_); |
246 | 248 |
247 // Add all transient children to our set of windows. Note that the function | 249 // Add all transient children to our set of windows. Note that the function |
248 // will add the children but not the owner to the transient children map. | 250 // will add the children but not the owner to the transient children map. |
249 AddTransientOwnerRecursive(window, window); | 251 AddTransientOwnerRecursive(window, window); |
250 | 252 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 } | 410 } |
409 } | 411 } |
410 | 412 |
411 void MultiUserWindowManagerChromeOS::OnWindowDestroyed(aura::Window* window) { | 413 void MultiUserWindowManagerChromeOS::OnWindowDestroyed(aura::Window* window) { |
412 if (GetWindowOwner(window).empty()) { | 414 if (GetWindowOwner(window).empty()) { |
413 // This must be a window in the transient chain - remove it and its | 415 // This must be a window in the transient chain - remove it and its |
414 // children from the owner. | 416 // children from the owner. |
415 RemoveTransientOwnerRecursive(window); | 417 RemoveTransientOwnerRecursive(window); |
416 return; | 418 return; |
417 } | 419 } |
418 // Remove the state and the window observer. | |
419 ash::wm::GetWindowState(window)->RemoveObserver(this); | 420 ash::wm::GetWindowState(window)->RemoveObserver(this); |
| 421 views::corewm::TransientWindowManager::Get(window)->RemoveObserver(this); |
420 // Remove the window from the owners list. | 422 // Remove the window from the owners list. |
421 delete window_to_entry_[window]; | 423 delete window_to_entry_[window]; |
422 window_to_entry_.erase(window); | 424 window_to_entry_.erase(window); |
423 } | 425 } |
424 | 426 |
425 void MultiUserWindowManagerChromeOS::OnWindowVisibilityChanging( | 427 void MultiUserWindowManagerChromeOS::OnWindowVisibilityChanging( |
426 aura::Window* window, bool visible) { | 428 aura::Window* window, bool visible) { |
427 // This command gets called first and immediately when show or hide gets | 429 // This command gets called first and immediately when show or hide gets |
428 // called. We remember here the desired state for restoration IF we were | 430 // called. We remember here the desired state for restoration IF we were |
429 // not ourselves issuing the call. | 431 // not ourselves issuing the call. |
(...skipping 25 matching lines...) Expand all Loading... |
455 if (visible && !IsWindowOnDesktopOfUser(window, current_user_id_)) { | 457 if (visible && !IsWindowOnDesktopOfUser(window, current_user_id_)) { |
456 SetWindowVisibility(window, false); | 458 SetWindowVisibility(window, false); |
457 return; | 459 return; |
458 } | 460 } |
459 aura::Window* owned_parent = GetOwningWindowInTransientChain(window); | 461 aura::Window* owned_parent = GetOwningWindowInTransientChain(window); |
460 if (owned_parent && owned_parent != window && visible && | 462 if (owned_parent && owned_parent != window && visible && |
461 !IsWindowOnDesktopOfUser(owned_parent, current_user_id_)) | 463 !IsWindowOnDesktopOfUser(owned_parent, current_user_id_)) |
462 SetWindowVisibility(window, false); | 464 SetWindowVisibility(window, false); |
463 } | 465 } |
464 | 466 |
465 void MultiUserWindowManagerChromeOS::OnAddTransientChild( | 467 void MultiUserWindowManagerChromeOS::OnTransientChildAdded( |
466 aura::Window* window, | 468 aura::Window* window, |
467 aura::Window* transient_window) { | 469 aura::Window* transient_window) { |
468 if (!GetWindowOwner(window).empty()) { | 470 if (!GetWindowOwner(window).empty()) { |
469 AddTransientOwnerRecursive(transient_window, window); | 471 AddTransientOwnerRecursive(transient_window, window); |
470 return; | 472 return; |
471 } | 473 } |
472 aura::Window* owned_parent = | 474 aura::Window* owned_parent = |
473 GetOwningWindowInTransientChain(transient_window); | 475 GetOwningWindowInTransientChain(transient_window); |
474 if (!owned_parent) | 476 if (!owned_parent) |
475 return; | 477 return; |
476 | 478 |
477 AddTransientOwnerRecursive(transient_window, owned_parent); | 479 AddTransientOwnerRecursive(transient_window, owned_parent); |
478 } | 480 } |
479 | 481 |
480 void MultiUserWindowManagerChromeOS::OnRemoveTransientChild( | 482 void MultiUserWindowManagerChromeOS::OnTransientChildRemoved( |
481 aura::Window* window, | 483 aura::Window* window, |
482 aura::Window* transient_window) { | 484 aura::Window* transient_window) { |
483 // Remove the transient child if the window itself is owned, or one of the | 485 // Remove the transient child if the window itself is owned, or one of the |
484 // windows in its transient parents chain. | 486 // windows in its transient parents chain. |
485 if (!GetWindowOwner(window).empty() || | 487 if (!GetWindowOwner(window).empty() || |
486 GetOwningWindowInTransientChain(window)) | 488 GetOwningWindowInTransientChain(window)) |
487 RemoveTransientOwnerRecursive(transient_window); | 489 RemoveTransientOwnerRecursive(transient_window); |
488 } | 490 } |
489 | 491 |
490 void MultiUserWindowManagerChromeOS::OnWindowShowTypeChanged( | 492 void MultiUserWindowManagerChromeOS::OnWindowShowTypeChanged( |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 | 600 |
599 // If this window is the owned window, we do not have to handle it again. | 601 // If this window is the owned window, we do not have to handle it again. |
600 if (window == owned_parent) | 602 if (window == owned_parent) |
601 return; | 603 return; |
602 | 604 |
603 // Remember the current visibility. | 605 // Remember the current visibility. |
604 DCHECK(transient_window_to_visibility_.find(window) == | 606 DCHECK(transient_window_to_visibility_.find(window) == |
605 transient_window_to_visibility_.end()); | 607 transient_window_to_visibility_.end()); |
606 transient_window_to_visibility_[window] = window->IsVisible(); | 608 transient_window_to_visibility_[window] = window->IsVisible(); |
607 | 609 |
608 // Add a window observer to make sure that we catch status changes. | 610 // Add observers to track state changes. |
609 window->AddObserver(this); | 611 window->AddObserver(this); |
| 612 views::corewm::TransientWindowManager::Get(window)->AddObserver(this); |
610 | 613 |
611 // Hide the window if it should not be shown. Note that this hide operation | 614 // Hide the window if it should not be shown. Note that this hide operation |
612 // will hide recursively this and all children - but we have already collected | 615 // will hide recursively this and all children - but we have already collected |
613 // their initial view state. | 616 // their initial view state. |
614 if (!IsWindowOnDesktopOfUser(owned_parent, current_user_id_)) | 617 if (!IsWindowOnDesktopOfUser(owned_parent, current_user_id_)) |
615 SetWindowVisibility(window, false); | 618 SetWindowVisibility(window, false); |
616 } | 619 } |
617 | 620 |
618 void MultiUserWindowManagerChromeOS::RemoveTransientOwnerRecursive( | 621 void MultiUserWindowManagerChromeOS::RemoveTransientOwnerRecursive( |
619 aura::Window* window) { | 622 aura::Window* window) { |
620 // First remove all child windows. | 623 // First remove all child windows. |
621 aura::Window::Windows::const_iterator it = | 624 aura::Window::Windows::const_iterator it = |
622 views::corewm::GetTransientChildren(window).begin(); | 625 views::corewm::GetTransientChildren(window).begin(); |
623 for (; it != views::corewm::GetTransientChildren(window).end(); ++it) | 626 for (; it != views::corewm::GetTransientChildren(window).end(); ++it) |
624 RemoveTransientOwnerRecursive(*it); | 627 RemoveTransientOwnerRecursive(*it); |
625 | 628 |
626 // Find from transient window storage the visibility for the given window, | 629 // Find from transient window storage the visibility for the given window, |
627 // set the visibility accordingly and delete the window from the map. | 630 // set the visibility accordingly and delete the window from the map. |
628 TransientWindowToVisibility::iterator visibility_item = | 631 TransientWindowToVisibility::iterator visibility_item = |
629 transient_window_to_visibility_.find(window); | 632 transient_window_to_visibility_.find(window); |
630 DCHECK(visibility_item != transient_window_to_visibility_.end()); | 633 DCHECK(visibility_item != transient_window_to_visibility_.end()); |
631 | 634 |
632 // Remove the window observer. | |
633 window->RemoveObserver(this); | 635 window->RemoveObserver(this); |
| 636 views::corewm::TransientWindowManager::Get(window)->RemoveObserver(this); |
634 | 637 |
635 bool unowned_view_state = visibility_item->second; | 638 bool unowned_view_state = visibility_item->second; |
636 transient_window_to_visibility_.erase(visibility_item); | 639 transient_window_to_visibility_.erase(visibility_item); |
637 if (unowned_view_state && !window->IsVisible()) { | 640 if (unowned_view_state && !window->IsVisible()) { |
638 // To prevent these commands from being recorded as any other commands, we | 641 // To prevent these commands from being recorded as any other commands, we |
639 // are suppressing any window entry changes while this is going on. | 642 // are suppressing any window entry changes while this is going on. |
640 // Instead of calling SetWindowVisible, only show gets called here since all | 643 // Instead of calling SetWindowVisible, only show gets called here since all |
641 // dependents have been shown previously already. | 644 // dependents have been shown previously already. |
642 base::AutoReset<bool> suppressor(&suppress_visibility_changes_, true); | 645 base::AutoReset<bool> suppressor(&suppress_visibility_changes_, true); |
643 window->Show(); | 646 window->Show(); |
644 } | 647 } |
645 } | 648 } |
646 | 649 |
647 } // namespace chrome | 650 } // namespace chrome |
OLD | NEW |