| 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_focus_rules.h" | 5 #include "ash/wm/ash_focus_rules.h" |
| 6 | 6 |
| 7 #include "ash/aura/wm_window_aura.h" |
| 7 #include "ash/common/shell_window_ids.h" | 8 #include "ash/common/shell_window_ids.h" |
| 9 #include "ash/common/wm/focus_rules.h" |
| 8 #include "ash/common/wm/window_state.h" | 10 #include "ash/common/wm/window_state.h" |
| 9 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 10 #include "ash/shell_delegate.h" | 12 #include "ash/shell_delegate.h" |
| 11 #include "ash/wm/mru_window_tracker.h" | 13 #include "ash/wm/mru_window_tracker.h" |
| 12 #include "ash/wm/window_state_aura.h" | 14 #include "ash/wm/window_state_aura.h" |
| 13 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 14 | 16 |
| 15 namespace ash { | 17 namespace ash { |
| 16 namespace wm { | 18 namespace wm { |
| 17 namespace { | 19 namespace { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 30 //////////////////////////////////////////////////////////////////////////////// | 32 //////////////////////////////////////////////////////////////////////////////// |
| 31 // AshFocusRules, public: | 33 // AshFocusRules, public: |
| 32 | 34 |
| 33 AshFocusRules::AshFocusRules() { | 35 AshFocusRules::AshFocusRules() { |
| 34 } | 36 } |
| 35 | 37 |
| 36 AshFocusRules::~AshFocusRules() { | 38 AshFocusRules::~AshFocusRules() { |
| 37 } | 39 } |
| 38 | 40 |
| 39 bool AshFocusRules::IsWindowConsideredActivatable(aura::Window* window) const { | 41 bool AshFocusRules::IsWindowConsideredActivatable(aura::Window* window) const { |
| 40 // Only toplevel windows can be activated. | 42 return ash::IsWindowConsideredActivatable(WmWindowAura::Get(window)); |
| 41 if (!IsToplevelWindow(window)) | |
| 42 return false; | |
| 43 | |
| 44 // The window must be visible. | |
| 45 if (!IsWindowConsideredVisibleForActivation(window)) | |
| 46 return false; | |
| 47 | |
| 48 return true; | |
| 49 } | 43 } |
| 50 | 44 |
| 51 //////////////////////////////////////////////////////////////////////////////// | 45 //////////////////////////////////////////////////////////////////////////////// |
| 52 // AshFocusRules, ::wm::FocusRules: | 46 // AshFocusRules, ::wm::FocusRules: |
| 53 | 47 |
| 48 bool AshFocusRules::IsToplevelWindow(aura::Window* window) const { |
| 49 return ash::IsToplevelWindow(WmWindowAura::Get(window)); |
| 50 } |
| 51 |
| 54 bool AshFocusRules::SupportsChildActivation(aura::Window* window) const { | 52 bool AshFocusRules::SupportsChildActivation(aura::Window* window) const { |
| 55 if (window->id() == kShellWindowId_DefaultContainer) | 53 return ash::IsActivatableShellWindowId(window->id()); |
| 56 return true; | |
| 57 | |
| 58 for (size_t i = 0; i < kNumActivatableShellWindowIds; i++) { | |
| 59 if (window->id() == kActivatableShellWindowIds[i]) | |
| 60 return true; | |
| 61 } | |
| 62 return false; | |
| 63 } | 54 } |
| 64 | 55 |
| 65 bool AshFocusRules::IsWindowConsideredVisibleForActivation( | 56 bool AshFocusRules::IsWindowConsideredVisibleForActivation( |
| 66 aura::Window* window) const { | 57 aura::Window* window) const { |
| 67 // If the |window| doesn't belong to the current active user and also doesn't | 58 return ash::IsWindowConsideredVisibleForActivation(WmWindowAura::Get(window)); |
| 68 // show for the current active user, then it should not be activated. | |
| 69 if (!Shell::GetInstance()->delegate()->CanShowWindowForUser(window)) | |
| 70 return false; | |
| 71 | |
| 72 if (BaseFocusRules::IsWindowConsideredVisibleForActivation(window)) | |
| 73 return true; | |
| 74 | |
| 75 // Minimized windows are hidden in their minimized state, but they can always | |
| 76 // be activated. | |
| 77 if (wm::GetWindowState(window)->IsMinimized()) | |
| 78 return true; | |
| 79 | |
| 80 return window->TargetVisibility() && | |
| 81 (window->parent()->id() == kShellWindowId_DefaultContainer || | |
| 82 window->parent()->id() == kShellWindowId_LockScreenContainer); | |
| 83 } | 59 } |
| 84 | 60 |
| 85 bool AshFocusRules::CanActivateWindow(aura::Window* window) const { | 61 bool AshFocusRules::CanActivateWindow(aura::Window* window) const { |
| 86 // Clearing activation is always permissible. | 62 // Clearing activation is always permissible. |
| 87 if (!window) | 63 if (!window) |
| 88 return true; | 64 return true; |
| 89 | 65 |
| 90 if (!BaseFocusRules::CanActivateWindow(window)) | 66 if (!BaseFocusRules::CanActivateWindow(window)) |
| 91 return false; | 67 return false; |
| 92 | 68 |
| 93 if (Shell::GetInstance()->IsSystemModalWindowOpen()) { | 69 if (Shell::GetInstance()->IsSystemModalWindowOpen()) { |
| 94 return BelongsToContainerWithEqualOrGreaterId( | 70 return BelongsToContainerWithEqualOrGreaterId( |
| 95 window, kShellWindowId_SystemModalContainer); | 71 window, kShellWindowId_SystemModalContainer); |
| 96 } | 72 } |
| 97 | 73 |
| 98 return true; | 74 return true; |
| 99 } | 75 } |
| 100 | 76 |
| 101 aura::Window* AshFocusRules::GetNextActivatableWindow( | 77 aura::Window* AshFocusRules::GetNextActivatableWindow( |
| 102 aura::Window* ignore) const { | 78 aura::Window* ignore) const { |
| 103 DCHECK(ignore); | 79 DCHECK(ignore); |
| 104 | 80 |
| 105 // Start from the container of the most-recently-used window. If the list of | 81 // Start from the container of the most-recently-used window. If the list of |
| 106 // MRU windows is empty, then start from the container of the window that just | 82 // MRU windows is empty, then start from the container of the window that just |
| 107 // lost focus |ignore|. | 83 // lost focus |ignore|. |
| 108 ash::MruWindowTracker* mru = ash::Shell::GetInstance()->mru_window_tracker(); | 84 ash::MruWindowTracker* mru = ash::Shell::GetInstance()->mru_window_tracker(); |
| 109 std::vector<aura::Window*> windows = mru->BuildMruWindowList(); | 85 std::vector<WmWindow*> windows = mru->BuildMruWindowList(); |
| 110 aura::Window* starting_window = windows.empty() ? ignore : windows[0]; | 86 aura::Window* starting_window = |
| 87 windows.empty() ? ignore : WmWindowAura::GetAuraWindow(windows[0]); |
| 111 | 88 |
| 112 // Look for windows to focus in |starting_window|'s container. If none are | 89 // Look for windows to focus in |starting_window|'s container. If none are |
| 113 // found, we look in all the containers in front of |starting_window|'s | 90 // found, we look in all the containers in front of |starting_window|'s |
| 114 // container, then all behind. | 91 // container, then all behind. |
| 115 int starting_container_index = 0; | 92 int starting_container_index = 0; |
| 116 aura::Window* root = starting_window->GetRootWindow(); | 93 aura::Window* root = starting_window->GetRootWindow(); |
| 117 if (!root) | 94 if (!root) |
| 118 root = Shell::GetTargetRootWindow(); | 95 root = Shell::GetTargetRootWindow(); |
| 119 int container_count = static_cast<int>(kNumActivatableShellWindowIds); | 96 int container_count = static_cast<int>(kNumActivatableShellWindowIds); |
| 120 for (int i = 0; i < container_count; i++) { | 97 for (int i = 0; i < container_count; i++) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 if (*i != ignore && | 141 if (*i != ignore && |
| 165 window_state->CanActivate() && | 142 window_state->CanActivate() && |
| 166 !window_state->IsMinimized()) | 143 !window_state->IsMinimized()) |
| 167 return *i; | 144 return *i; |
| 168 } | 145 } |
| 169 return NULL; | 146 return NULL; |
| 170 } | 147 } |
| 171 | 148 |
| 172 } // namespace wm | 149 } // namespace wm |
| 173 } // namespace ash | 150 } // namespace ash |
| OLD | NEW |