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

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

Issue 9568045: Activate windows in topmost containers when a window is hidden. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add tests and address review comments. Created 8 years, 9 months 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
« no previous file with comments | « ash/wm/activation_controller.h ('k') | ash/wm/activation_controller_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/activation_controller.h" 5 #include "ash/wm/activation_controller.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_modality_controller.h" 9 #include "ash/wm/window_modality_controller.h"
10 #include "ash/wm/window_util.h" 10 #include "ash/wm/window_util.h"
11 #include "base/auto_reset.h" 11 #include "base/auto_reset.h"
12 #include "ui/aura/client/activation_delegate.h" 12 #include "ui/aura/client/activation_delegate.h"
13 #include "ui/aura/client/aura_constants.h" 13 #include "ui/aura/client/aura_constants.h"
14 #include "ui/aura/env.h" 14 #include "ui/aura/env.h"
15 #include "ui/aura/root_window.h" 15 #include "ui/aura/root_window.h"
16 #include "ui/aura/window.h" 16 #include "ui/aura/window.h"
17 #include "ui/aura/window_delegate.h" 17 #include "ui/aura/window_delegate.h"
18 #include "ui/base/ui_base_types.h" 18 #include "ui/base/ui_base_types.h"
19 19
20 namespace ash { 20 namespace ash {
21 namespace internal { 21 namespace internal {
22 namespace { 22 namespace {
23 23
24 // These are the list of container ids of containers which may contain windows
25 // that need to be activated in the order that they should be activated.
26 const int kWindowContainerIds[] = {
27 kShellWindowId_LockSystemModalContainer,
28 kShellWindowId_LockScreenContainer,
29 kShellWindowId_SystemModalContainer,
30 kShellWindowId_AlwaysOnTopContainer,
31 kShellWindowId_DefaultContainer,
32
33 // Panel, launcher and status are intentionally checked after other
34 // containers even though these layers are higher. The user expects their
35 // windows to be focused before these elements.
36 kShellWindowId_PanelContainer,
37 kShellWindowId_LauncherContainer,
38 kShellWindowId_StatusContainer,
39 };
40
24 aura::Window* GetContainer(int id) { 41 aura::Window* GetContainer(int id) {
25 return Shell::GetInstance()->GetContainer(id); 42 return Shell::GetInstance()->GetContainer(id);
26 } 43 }
27 44
28 // Returns true if children of |window| can be activated. 45 // Returns true if children of |window| can be activated.
29 // These are the only containers in which windows can receive focus. 46 // These are the only containers in which windows can receive focus.
30 bool SupportsChildActivation(aura::Window* window) { 47 bool SupportsChildActivation(aura::Window* window) {
31 return window->id() == kShellWindowId_DefaultContainer || 48 for (size_t i = 0; i < arraysize(kWindowContainerIds); i++) {
32 window->id() == kShellWindowId_AlwaysOnTopContainer || 49 if (window->id() == kWindowContainerIds[i])
33 window->id() == kShellWindowId_PanelContainer || 50 return true;
34 window->id() == kShellWindowId_SystemModalContainer || 51 }
35 window->id() == kShellWindowId_StatusContainer || 52 return false;
36 window->id() == kShellWindowId_LauncherContainer ||
37 window->id() == kShellWindowId_LockScreenContainer ||
38 window->id() == kShellWindowId_LockSystemModalContainer;
39 } 53 }
40 54
41 // Returns true if |window| can be activated or deactivated. 55 // Returns true if |window| can be activated or deactivated.
42 // A window manager typically defines some notion of "top level window" that 56 // A window manager typically defines some notion of "top level window" that
43 // supports activation/deactivation. 57 // supports activation/deactivation.
44 bool CanActivateWindow(aura::Window* window) { 58 bool CanActivateWindow(aura::Window* window) {
45 return window && 59 return window &&
46 window->IsVisible() && 60 window->IsVisible() &&
47 (!aura::client::GetActivationDelegate(window) || 61 (!aura::client::GetActivationDelegate(window) ||
48 aura::client::GetActivationDelegate(window)->ShouldActivate(NULL)) && 62 aura::client::GetActivationDelegate(window)->ShouldActivate(NULL)) &&
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 //////////////////////////////////////////////////////////////////////////////// 215 ////////////////////////////////////////////////////////////////////////////////
202 // ActivationController, private: 216 // ActivationController, private:
203 217
204 void ActivationController::ActivateNextWindow(aura::Window* window) { 218 void ActivationController::ActivateNextWindow(aura::Window* window) {
205 if (wm::IsActiveWindow(window)) 219 if (wm::IsActiveWindow(window))
206 ActivateWindow(GetTopmostWindowToActivate(window)); 220 ActivateWindow(GetTopmostWindowToActivate(window));
207 } 221 }
208 222
209 aura::Window* ActivationController::GetTopmostWindowToActivate( 223 aura::Window* ActivationController::GetTopmostWindowToActivate(
210 aura::Window* ignore) const { 224 aura::Window* ignore) const {
211 const aura::Window* container = 225 if (default_container_for_test_) {
oshima 2012/03/02 18:25:38 I know this isn't the scope of your CL, but asking
flackr 2012/03/02 18:58:40 Done.
212 default_container_for_test_ ? default_container_for_test_ : 226 return GetTopmostWindowToActivateInContainer(default_container_for_test_,
213 GetContainer(kShellWindowId_DefaultContainer); 227 ignore);
214 // When destructing an active window that is in a container destructed after 228 }
215 // the default container during shell shutdown, |container| would be NULL 229
216 // because default container is destructed at this point. 230 size_t i = 0;
oshima 2012/03/02 18:25:38 current_container_index / active_container_index ?
flackr 2012/03/02 18:58:40 Done.
217 if (container) { 231 // If the container of the window losing focus is in the list, start from that
218 for (aura::Window::Windows::const_reverse_iterator i = 232 // container.
219 container->children().rbegin(); 233 for (size_t j = 0; j < arraysize(kWindowContainerIds); j++) {
220 i != container->children().rend(); 234 aura::Window* container = GetContainer(kWindowContainerIds[j]);
221 ++i) { 235 if (container && container->Contains(ignore)) {
222 if (*i != ignore && CanActivateWindow(*i)) 236 i = j;
223 return *i; 237 break;
224 } 238 }
225 } 239 }
240
241 // Look for windows to focus in that container and below.
242 aura::Window* window = NULL;
243 for (; !window && i < arraysize(kWindowContainerIds); i++) {
244 aura::Window* container = GetContainer(kWindowContainerIds[i]);
245 if (container)
246 window = GetTopmostWindowToActivateInContainer(container, ignore);
247 }
248 return window;
249 }
250
251 aura::Window* ActivationController::GetTopmostWindowToActivateInContainer(
252 aura::Window* container,
253 aura::Window* ignore) const {
254 for (aura::Window::Windows::const_reverse_iterator i =
255 container->children().rbegin();
256 i != container->children().rend();
257 ++i) {
258 if (*i != ignore && CanActivateWindow(*i))
259 return *i;
260 }
226 return NULL; 261 return NULL;
227 } 262 }
228 263
229 } // namespace internal 264 } // namespace internal
230 } // namespace ash 265 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/activation_controller.h ('k') | ash/wm/activation_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698