| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ash/wm/ash_activation_controller.h" | 5 #include "ash/wm/ash_activation_controller.h" |
| 6 | 6 |
| 7 #include "ash/launcher/launcher.h" |
| 7 #include "ash/root_window_controller.h" | 8 #include "ash/root_window_controller.h" |
| 8 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/shell_delegate.h" |
| 9 #include "ash/wm/activation_controller.h" | 11 #include "ash/wm/activation_controller.h" |
| 10 #include "ash/wm/property_util.h" | 12 #include "ash/wm/property_util.h" |
| 11 #include "ash/wm/window_util.h" | 13 #include "ash/wm/window_util.h" |
| 12 #include "ash/wm/workspace_controller.h" | 14 #include "ash/wm/workspace_controller.h" |
| 13 #include "ui/views/corewm/window_modality_controller.h" | 15 #include "ui/views/corewm/window_modality_controller.h" |
| 16 #include "ui/views/widget/widget.h" |
| 14 | 17 |
| 15 namespace ash { | 18 namespace ash { |
| 16 namespace internal { | 19 namespace internal { |
| 17 | 20 |
| 18 //////////////////////////////////////////////////////////////////////////////// | 21 //////////////////////////////////////////////////////////////////////////////// |
| 19 // AshActivationController, public: | 22 // AshActivationController, public: |
| 20 | 23 |
| 21 AshActivationController::AshActivationController() { | 24 AshActivationController::AshActivationController() { |
| 22 } | 25 } |
| 23 | 26 |
| 24 AshActivationController::~AshActivationController() { | 27 AshActivationController::~AshActivationController() { |
| 25 } | 28 } |
| 26 | 29 |
| 27 //////////////////////////////////////////////////////////////////////////////// | 30 //////////////////////////////////////////////////////////////////////////////// |
| 28 // AshActivationController, ActivationControllerDelegate implementation: | 31 // AshActivationController, ActivationControllerDelegate implementation: |
| 29 | 32 |
| 30 aura::Window* AshActivationController::WillActivateWindow( | 33 aura::Window* AshActivationController::WillActivateWindow( |
| 31 aura::Window* window) { | 34 aura::Window* window) { |
| 32 aura::Window* window_modal_transient = | 35 aura::Window* window_modal_transient = |
| 33 views::corewm::GetModalTransient(window); | 36 views::corewm::GetModalTransient(window); |
| 34 if (window_modal_transient) | 37 if (window_modal_transient) |
| 35 return window_modal_transient; | 38 return window_modal_transient; |
| 36 | 39 |
| 40 // Fallback to launcher |
| 41 if (!window) |
| 42 window = PrepareToActivateLauncher(); |
| 43 |
| 37 // Make sure the workspace manager switches to the workspace for window. | 44 // Make sure the workspace manager switches to the workspace for window. |
| 38 // Without this CanReceiveEvents() below returns false and activation never | 45 // Without this CanReceiveEvents() below returns false and activation never |
| 39 // changes. CanReceiveEvents() returns false if |window| isn't in the active | 46 // changes. CanReceiveEvents() returns false if |window| isn't in the active |
| 40 // workspace, in which case its parent is not visible. | 47 // workspace, in which case its parent is not visible. |
| 41 // TODO(sky): if I instead change the opacity of the parent this isn't an | 48 // TODO(sky): if I instead change the opacity of the parent this isn't an |
| 42 // issue, but will make animations trickier... Consider which one is better. | 49 // issue, but will make animations trickier... Consider which one is better. |
| 43 if (window) { | 50 if (window) { |
| 44 internal::RootWindowController* root_window_controller = | 51 internal::RootWindowController* root_window_controller = |
| 45 GetRootWindowController(window->GetRootWindow()); | 52 GetRootWindowController(window->GetRootWindow()); |
| 46 root_window_controller->workspace_controller()-> | 53 root_window_controller->workspace_controller()-> |
| (...skipping 23 matching lines...) Expand all Loading... |
| 70 | 77 |
| 71 aura::Window* AshActivationController::WillFocusWindow( | 78 aura::Window* AshActivationController::WillFocusWindow( |
| 72 aura::Window* window) { | 79 aura::Window* window) { |
| 73 aura::Window* window_modal_transient = | 80 aura::Window* window_modal_transient = |
| 74 views::corewm::GetModalTransient(window); | 81 views::corewm::GetModalTransient(window); |
| 75 if (window_modal_transient) | 82 if (window_modal_transient) |
| 76 return window_modal_transient; | 83 return window_modal_transient; |
| 77 return window; | 84 return window; |
| 78 } | 85 } |
| 79 | 86 |
| 87 aura::Window* AshActivationController::PrepareToActivateLauncher() { |
| 88 // If workspace controller is not available, then it means that the root |
| 89 // window is being destroyed. We can't activate any window then. |
| 90 if (!GetRootWindowController( |
| 91 Shell::GetActiveRootWindow())->workspace_controller()) { |
| 92 return NULL; |
| 93 } |
| 94 // Fallback to a launcher only when Spoken feedback is enabled. |
| 95 if (!Shell::GetInstance()->delegate()->IsSpokenFeedbackEnabled()) |
| 96 return NULL; |
| 97 Launcher* launcher; |
| 98 if (Shell::IsLauncherPerDisplayEnabled()) { |
| 99 launcher = GetRootWindowController( |
| 100 Shell::GetActiveRootWindow())->launcher(); |
| 101 } else { |
| 102 launcher = Launcher::ForPrimaryDisplay(); |
| 103 } |
| 104 // Launcher is not always available, eg. not in the login screen. |
| 105 if (!launcher) |
| 106 return NULL; |
| 107 views::Widget* launcher_widget = launcher->widget(); |
| 108 // Launcher's window may be already destroyed in shutting down process. |
| 109 if (!launcher_widget) |
| 110 return NULL; |
| 111 aura::Window* launcher_window = launcher_widget->GetNativeWindow(); |
| 112 // Notify launcher to allow activation via CanActivate(). |
| 113 launcher->WillActivateAsFallback(); |
| 114 return launcher_window; |
| 115 } |
| 116 |
| 80 } // namespace internal | 117 } // namespace internal |
| 81 } // namespace ash | 118 } // namespace ash |
| OLD | NEW |