| 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/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/shell_window_ids.h" | 8 #include "ash/shell_window_ids.h" |
| 9 #include "ash/wm/window_util.h" | 9 #include "ash/wm/window_util.h" |
| 10 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 window, internal::kShellWindowId_SystemModalContainer); | 97 window, internal::kShellWindowId_SystemModalContainer); |
| 98 } | 98 } |
| 99 | 99 |
| 100 return true; | 100 return true; |
| 101 } | 101 } |
| 102 | 102 |
| 103 aura::Window* AshFocusRules::GetNextActivatableWindow( | 103 aura::Window* AshFocusRules::GetNextActivatableWindow( |
| 104 aura::Window* ignore) const { | 104 aura::Window* ignore) const { |
| 105 DCHECK(ignore); | 105 DCHECK(ignore); |
| 106 | 106 |
| 107 size_t current_container_index = 0; | 107 int starting_container_index = 0; |
| 108 // If the container of the window losing focus is in the list, start from that | 108 // If the container of the window losing focus is in the list, start from that |
| 109 // container. | 109 // container. |
| 110 aura::RootWindow* root = ignore->GetRootWindow(); | 110 aura::RootWindow* root = ignore->GetRootWindow(); |
| 111 if (!root) | 111 if (!root) |
| 112 root = Shell::GetActiveRootWindow(); | 112 root = Shell::GetActiveRootWindow(); |
| 113 for (size_t i = 0; ignore && i < arraysize(kWindowContainerIds); i++) { | 113 int container_count = static_cast<int>(arraysize(kWindowContainerIds)); |
| 114 for (int i = 0; ignore && i < container_count; i++) { |
| 114 aura::Window* container = Shell::GetContainer(root, kWindowContainerIds[i]); | 115 aura::Window* container = Shell::GetContainer(root, kWindowContainerIds[i]); |
| 115 if (container && container->Contains(ignore)) { | 116 if (container && container->Contains(ignore)) { |
| 116 current_container_index = i; | 117 starting_container_index = i; |
| 117 break; | 118 break; |
| 118 } | 119 } |
| 119 } | 120 } |
| 120 | 121 |
| 121 // Look for windows to focus in that container and below. | 122 // Look for windows to focus in |ignore|'s container. If none are found, we |
| 123 // look in all the containers in front of |ignore|'s container, then all |
| 124 // behind. |
| 122 aura::Window* window = NULL; | 125 aura::Window* window = NULL; |
| 123 for (; !window && current_container_index < arraysize(kWindowContainerIds); | 126 for (int i = starting_container_index; !window && i < container_count; i++) |
| 124 current_container_index++) { | 127 window = GetTopmostWindowToActivateForContainerIndex(i, ignore); |
| 125 aura::Window::Windows containers = | 128 if (!window && starting_container_index > 0) { |
| 126 Shell::GetAllContainers(kWindowContainerIds[current_container_index]); | 129 for (int i = starting_container_index - 1; !window && i >= 0; i--) |
| 127 for (aura::Window::Windows::const_iterator iter = containers.begin(); | 130 window = GetTopmostWindowToActivateForContainerIndex(i, ignore); |
| 128 iter != containers.end() && !window; ++iter) { | |
| 129 window = GetTopmostWindowToActivateInContainer((*iter), ignore); | |
| 130 } | |
| 131 } | 131 } |
| 132 return window; | 132 return window; |
| 133 } | 133 } |
| 134 | 134 |
| 135 //////////////////////////////////////////////////////////////////////////////// | 135 //////////////////////////////////////////////////////////////////////////////// |
| 136 // AshFocusRules, private: | 136 // AshFocusRules, private: |
| 137 | 137 |
| 138 aura::Window* AshFocusRules::GetTopmostWindowToActivateForContainerIndex( |
| 139 int index, |
| 140 aura::Window* ignore) const { |
| 141 aura::Window* window = NULL; |
| 142 aura::Window::Windows containers = |
| 143 Shell::GetAllContainers(kWindowContainerIds[index]); |
| 144 for (aura::Window::Windows::const_iterator iter = containers.begin(); |
| 145 iter != containers.end() && !window; ++iter) { |
| 146 window = GetTopmostWindowToActivateInContainer((*iter), ignore); |
| 147 } |
| 148 return window; |
| 149 } |
| 150 |
| 138 aura::Window* AshFocusRules::GetTopmostWindowToActivateInContainer( | 151 aura::Window* AshFocusRules::GetTopmostWindowToActivateInContainer( |
| 139 aura::Window* container, | 152 aura::Window* container, |
| 140 aura::Window* ignore) const { | 153 aura::Window* ignore) const { |
| 141 // Workspace has an extra level of windows that needs to be special cased. | 154 // Workspace has an extra level of windows that needs to be special cased. |
| 142 if (container->id() == internal::kShellWindowId_DefaultContainer) { | 155 if (container->id() == internal::kShellWindowId_DefaultContainer) { |
| 143 for (aura::Window::Windows::const_reverse_iterator i = | 156 for (aura::Window::Windows::const_reverse_iterator i = |
| 144 container->children().rbegin(); | 157 container->children().rbegin(); |
| 145 i != container->children().rend(); ++i) { | 158 i != container->children().rend(); ++i) { |
| 146 if ((*i)->IsVisible()) { | 159 if ((*i)->IsVisible()) { |
| 147 aura::Window* window = | 160 aura::Window* window = |
| 148 GetTopmostWindowToActivateInContainer(*i, ignore); | 161 GetTopmostWindowToActivateInContainer(*i, ignore); |
| 149 if (window) | 162 if (window) |
| 150 return window; | 163 return window; |
| 151 } | 164 } |
| 152 } | 165 } |
| 153 return NULL; | 166 return NULL; |
| 154 } | 167 } |
| 155 for (aura::Window::Windows::const_reverse_iterator i = | 168 for (aura::Window::Windows::const_reverse_iterator i = |
| 156 container->children().rbegin(); | 169 container->children().rbegin(); |
| 157 i != container->children().rend(); | 170 i != container->children().rend(); |
| 158 ++i) { | 171 ++i) { |
| 159 if (*i != ignore && CanActivateWindow(*i) && !wm::IsWindowMinimized(*i)) | 172 if (*i != ignore && CanActivateWindow(*i) && !wm::IsWindowMinimized(*i)) |
| 160 return *i; | 173 return *i; |
| 161 } | 174 } |
| 162 return NULL; | 175 return NULL; |
| 163 } | 176 } |
| 164 | 177 |
| 165 } // namespace wm | 178 } // namespace wm |
| 166 } // namespace ash | 179 } // namespace ash |
| OLD | NEW |