Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Side by Side Diff: ash/wm/ash_focus_rules.cc

Issue 11519040: More unittests passing with new focus controller. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 size_t 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 for (size_t i = 0; ignore && i < arraysize(kWindowContainerIds); i++) {
114 aura::Window* container = Shell::GetContainer(root, kWindowContainerIds[i]); 114 aura::Window* container = Shell::GetContainer(root, kWindowContainerIds[i]);
115 if (container && container->Contains(ignore)) { 115 if (container && container->Contains(ignore)) {
116 current_container_index = i; 116 starting_container_index = i;
117 break; 117 break;
118 } 118 }
119 } 119 }
120 120
121 // Look for windows to focus in that container and below. 121 // Look for windows to focus in |ignore|'s container. If none are found, we
122 // look in all the containers in front of |ignore|'s container, then all
123 // behind.
122 aura::Window* window = NULL; 124 aura::Window* window = NULL;
123 for (; !window && current_container_index < arraysize(kWindowContainerIds); 125 for (size_t i = starting_container_index;
124 current_container_index++) { 126 !window && i < arraysize(kWindowContainerIds);
125 aura::Window::Windows containers = 127 i++) {
126 Shell::GetAllContainers(kWindowContainerIds[current_container_index]); 128 window = GetTopmostWindowToActivateForContainerIndex(i, ignore);
127 for (aura::Window::Windows::const_iterator iter = containers.begin(); 129 }
128 iter != containers.end() && !window; ++iter) { 130 if (!window) {
129 window = GetTopmostWindowToActivateInContainer((*iter), ignore); 131 for (size_t i = starting_container_index - 1;
sky 2012/12/13 21:38:06 If starting_container_index == 0 this is going to
Ben Goodger (Google) 2012/12/13 21:47:23 Done.
132 !window && i < arraysize(kWindowContainerIds);
133 i--) {
134 window = GetTopmostWindowToActivateForContainerIndex(i, ignore);
130 } 135 }
131 } 136 }
132 return window; 137 return window;
133 } 138 }
134 139
135 //////////////////////////////////////////////////////////////////////////////// 140 ////////////////////////////////////////////////////////////////////////////////
136 // AshFocusRules, private: 141 // AshFocusRules, private:
137 142
143 aura::Window* AshFocusRules::GetTopmostWindowToActivateForContainerIndex(
144 int index,
145 aura::Window* ignore) const {
146 aura::Window* window = NULL;
147 aura::Window::Windows containers =
148 Shell::GetAllContainers(kWindowContainerIds[index]);
149 for (aura::Window::Windows::const_iterator iter = containers.begin();
150 iter != containers.end() && !window; ++iter) {
151 window = GetTopmostWindowToActivateInContainer((*iter), ignore);
152 }
153 return window;
154 }
155
138 aura::Window* AshFocusRules::GetTopmostWindowToActivateInContainer( 156 aura::Window* AshFocusRules::GetTopmostWindowToActivateInContainer(
139 aura::Window* container, 157 aura::Window* container,
140 aura::Window* ignore) const { 158 aura::Window* ignore) const {
141 // Workspace has an extra level of windows that needs to be special cased. 159 // Workspace has an extra level of windows that needs to be special cased.
142 if (container->id() == internal::kShellWindowId_DefaultContainer) { 160 if (container->id() == internal::kShellWindowId_DefaultContainer) {
143 for (aura::Window::Windows::const_reverse_iterator i = 161 for (aura::Window::Windows::const_reverse_iterator i =
144 container->children().rbegin(); 162 container->children().rbegin();
145 i != container->children().rend(); ++i) { 163 i != container->children().rend(); ++i) {
146 if ((*i)->IsVisible()) { 164 if ((*i)->IsVisible()) {
147 aura::Window* window = 165 aura::Window* window =
148 GetTopmostWindowToActivateInContainer(*i, ignore); 166 GetTopmostWindowToActivateInContainer(*i, ignore);
149 if (window) 167 if (window)
150 return window; 168 return window;
151 } 169 }
152 } 170 }
153 return NULL; 171 return NULL;
154 } 172 }
155 for (aura::Window::Windows::const_reverse_iterator i = 173 for (aura::Window::Windows::const_reverse_iterator i =
156 container->children().rbegin(); 174 container->children().rbegin();
157 i != container->children().rend(); 175 i != container->children().rend();
158 ++i) { 176 ++i) {
159 if (*i != ignore && CanActivateWindow(*i) && !wm::IsWindowMinimized(*i)) 177 if (*i != ignore && CanActivateWindow(*i) && !wm::IsWindowMinimized(*i))
160 return *i; 178 return *i;
161 } 179 }
162 return NULL; 180 return NULL;
163 } 181 }
164 182
165 } // namespace wm 183 } // namespace wm
166 } // namespace ash 184 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698