| 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" | |
| 8 #include "ash/common/wm/container_finder.h" | 7 #include "ash/common/wm/container_finder.h" |
| 9 #include "ash/common/wm/focus_rules.h" | 8 #include "ash/common/wm/focus_rules.h" |
| 10 #include "ash/common/wm/mru_window_tracker.h" | 9 #include "ash/common/wm/mru_window_tracker.h" |
| 11 #include "ash/common/wm/window_state.h" | 10 #include "ash/common/wm/window_state.h" |
| 12 #include "ash/common/wm_shell.h" | 11 #include "ash/common/wm_shell.h" |
| 12 #include "ash/common/wm_window.h" |
| 13 #include "ash/public/cpp/shell_window_ids.h" | 13 #include "ash/public/cpp/shell_window_ids.h" |
| 14 #include "ash/shell.h" | 14 #include "ash/shell.h" |
| 15 #include "ash/wm/window_state_aura.h" | 15 #include "ash/wm/window_state_aura.h" |
| 16 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
| 17 | 17 |
| 18 namespace ash { | 18 namespace ash { |
| 19 namespace wm { | 19 namespace wm { |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 bool BelongsToContainerWithEqualOrGreaterId(const aura::Window* window, | 22 bool BelongsToContainerWithEqualOrGreaterId(const aura::Window* window, |
| 23 int container_id) { | 23 int container_id) { |
| 24 for (; window; window = window->parent()) { | 24 for (; window; window = window->parent()) { |
| 25 if (window->id() >= container_id) | 25 if (window->id() >= container_id) |
| 26 return true; | 26 return true; |
| 27 } | 27 } |
| 28 return false; | 28 return false; |
| 29 } | 29 } |
| 30 | 30 |
| 31 } // namespace | 31 } // namespace |
| 32 | 32 |
| 33 //////////////////////////////////////////////////////////////////////////////// | 33 //////////////////////////////////////////////////////////////////////////////// |
| 34 // AshFocusRules, public: | 34 // AshFocusRules, public: |
| 35 | 35 |
| 36 AshFocusRules::AshFocusRules() {} | 36 AshFocusRules::AshFocusRules() {} |
| 37 | 37 |
| 38 AshFocusRules::~AshFocusRules() {} | 38 AshFocusRules::~AshFocusRules() {} |
| 39 | 39 |
| 40 bool AshFocusRules::IsWindowConsideredActivatable(aura::Window* window) const { | 40 bool AshFocusRules::IsWindowConsideredActivatable(aura::Window* window) const { |
| 41 return ash::IsWindowConsideredActivatable(WmWindowAura::Get(window)); | 41 return ash::IsWindowConsideredActivatable(WmWindow::Get(window)); |
| 42 } | 42 } |
| 43 | 43 |
| 44 //////////////////////////////////////////////////////////////////////////////// | 44 //////////////////////////////////////////////////////////////////////////////// |
| 45 // AshFocusRules, ::wm::FocusRules: | 45 // AshFocusRules, ::wm::FocusRules: |
| 46 | 46 |
| 47 bool AshFocusRules::IsToplevelWindow(aura::Window* window) const { | 47 bool AshFocusRules::IsToplevelWindow(aura::Window* window) const { |
| 48 return ash::IsToplevelWindow(WmWindowAura::Get(window)); | 48 return ash::IsToplevelWindow(WmWindow::Get(window)); |
| 49 } | 49 } |
| 50 | 50 |
| 51 bool AshFocusRules::SupportsChildActivation(aura::Window* window) const { | 51 bool AshFocusRules::SupportsChildActivation(aura::Window* window) const { |
| 52 return ash::IsActivatableShellWindowId(window->id()); | 52 return ash::IsActivatableShellWindowId(window->id()); |
| 53 } | 53 } |
| 54 | 54 |
| 55 bool AshFocusRules::IsWindowConsideredVisibleForActivation( | 55 bool AshFocusRules::IsWindowConsideredVisibleForActivation( |
| 56 aura::Window* window) const { | 56 aura::Window* window) const { |
| 57 return ash::IsWindowConsideredVisibleForActivation(WmWindowAura::Get(window)); | 57 return ash::IsWindowConsideredVisibleForActivation(WmWindow::Get(window)); |
| 58 } | 58 } |
| 59 | 59 |
| 60 bool AshFocusRules::CanActivateWindow(aura::Window* window) const { | 60 bool AshFocusRules::CanActivateWindow(aura::Window* window) const { |
| 61 // Clearing activation is always permissible. | 61 // Clearing activation is always permissible. |
| 62 if (!window) | 62 if (!window) |
| 63 return true; | 63 return true; |
| 64 | 64 |
| 65 if (!BaseFocusRules::CanActivateWindow(window)) | 65 if (!BaseFocusRules::CanActivateWindow(window)) |
| 66 return false; | 66 return false; |
| 67 | 67 |
| 68 if (WmShell::Get()->IsSystemModalWindowOpen()) { | 68 if (WmShell::Get()->IsSystemModalWindowOpen()) { |
| 69 return BelongsToContainerWithEqualOrGreaterId( | 69 return BelongsToContainerWithEqualOrGreaterId( |
| 70 window, kShellWindowId_SystemModalContainer); | 70 window, kShellWindowId_SystemModalContainer); |
| 71 } | 71 } |
| 72 | 72 |
| 73 return true; | 73 return true; |
| 74 } | 74 } |
| 75 | 75 |
| 76 aura::Window* AshFocusRules::GetNextActivatableWindow( | 76 aura::Window* AshFocusRules::GetNextActivatableWindow( |
| 77 aura::Window* ignore) const { | 77 aura::Window* ignore) const { |
| 78 DCHECK(ignore); | 78 DCHECK(ignore); |
| 79 | 79 |
| 80 // Start from the container of the most-recently-used window. If the list of | 80 // Start from the container of the most-recently-used window. If the list of |
| 81 // MRU windows is empty, then start from the container of the window that just | 81 // MRU windows is empty, then start from the container of the window that just |
| 82 // lost focus |ignore|. | 82 // lost focus |ignore|. |
| 83 MruWindowTracker* mru = WmShell::Get()->mru_window_tracker(); | 83 MruWindowTracker* mru = WmShell::Get()->mru_window_tracker(); |
| 84 std::vector<WmWindow*> windows = mru->BuildMruWindowList(); | 84 std::vector<WmWindow*> windows = mru->BuildMruWindowList(); |
| 85 aura::Window* starting_window = | 85 aura::Window* starting_window = |
| 86 windows.empty() ? ignore : WmWindowAura::GetAuraWindow(windows[0]); | 86 windows.empty() ? ignore : WmWindow::GetAuraWindow(windows[0]); |
| 87 | 87 |
| 88 // Look for windows to focus in |starting_window|'s container. If none are | 88 // Look for windows to focus in |starting_window|'s container. If none are |
| 89 // found, we look in all the containers in front of |starting_window|'s | 89 // found, we look in all the containers in front of |starting_window|'s |
| 90 // container, then all behind. | 90 // container, then all behind. |
| 91 int starting_container_index = 0; | 91 int starting_container_index = 0; |
| 92 aura::Window* root = starting_window->GetRootWindow(); | 92 aura::Window* root = starting_window->GetRootWindow(); |
| 93 if (!root) | 93 if (!root) |
| 94 root = Shell::GetTargetRootWindow(); | 94 root = Shell::GetTargetRootWindow(); |
| 95 int container_count = static_cast<int>(kNumActivatableShellWindowIds); | 95 int container_count = static_cast<int>(kNumActivatableShellWindowIds); |
| 96 for (int i = 0; i < container_count; i++) { | 96 for (int i = 0; i < container_count; i++) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 114 | 114 |
| 115 //////////////////////////////////////////////////////////////////////////////// | 115 //////////////////////////////////////////////////////////////////////////////// |
| 116 // AshFocusRules, private: | 116 // AshFocusRules, private: |
| 117 | 117 |
| 118 aura::Window* AshFocusRules::GetTopmostWindowToActivateForContainerIndex( | 118 aura::Window* AshFocusRules::GetTopmostWindowToActivateForContainerIndex( |
| 119 int index, | 119 int index, |
| 120 aura::Window* ignore) const { | 120 aura::Window* ignore) const { |
| 121 aura::Window* window = nullptr; | 121 aura::Window* window = nullptr; |
| 122 aura::Window* root = ignore ? ignore->GetRootWindow() : nullptr; | 122 aura::Window* root = ignore ? ignore->GetRootWindow() : nullptr; |
| 123 WmWindow::Windows containers = GetContainersFromAllRootWindows( | 123 WmWindow::Windows containers = GetContainersFromAllRootWindows( |
| 124 kActivatableShellWindowIds[index], WmWindowAura::Get(root)); | 124 kActivatableShellWindowIds[index], WmWindow::Get(root)); |
| 125 for (WmWindow* container : containers) { | 125 for (WmWindow* container : containers) { |
| 126 window = GetTopmostWindowToActivateInContainer( | 126 window = GetTopmostWindowToActivateInContainer( |
| 127 WmWindowAura::GetAuraWindow(container), ignore); | 127 WmWindow::GetAuraWindow(container), ignore); |
| 128 if (window) | 128 if (window) |
| 129 return window; | 129 return window; |
| 130 } | 130 } |
| 131 return window; | 131 return window; |
| 132 } | 132 } |
| 133 | 133 |
| 134 aura::Window* AshFocusRules::GetTopmostWindowToActivateInContainer( | 134 aura::Window* AshFocusRules::GetTopmostWindowToActivateInContainer( |
| 135 aura::Window* container, | 135 aura::Window* container, |
| 136 aura::Window* ignore) const { | 136 aura::Window* ignore) const { |
| 137 for (aura::Window::Windows::const_reverse_iterator i = | 137 for (aura::Window::Windows::const_reverse_iterator i = |
| 138 container->children().rbegin(); | 138 container->children().rbegin(); |
| 139 i != container->children().rend(); ++i) { | 139 i != container->children().rend(); ++i) { |
| 140 WindowState* window_state = GetWindowState(*i); | 140 WindowState* window_state = GetWindowState(*i); |
| 141 if (*i != ignore && window_state->CanActivate() && | 141 if (*i != ignore && window_state->CanActivate() && |
| 142 !window_state->IsMinimized()) | 142 !window_state->IsMinimized()) |
| 143 return *i; | 143 return *i; |
| 144 } | 144 } |
| 145 return NULL; | 145 return NULL; |
| 146 } | 146 } |
| 147 | 147 |
| 148 } // namespace wm | 148 } // namespace wm |
| 149 } // namespace ash | 149 } // namespace ash |
| OLD | NEW |