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" |
| 8 #include "ash/shell_window_ids.h" |
| 9 #include "ash/wm/window_util.h" |
7 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
8 | 11 |
9 namespace ash { | 12 namespace ash { |
10 namespace wm { | 13 namespace wm { |
| 14 namespace { |
| 15 |
| 16 // These are the list of container ids of containers which may contain windows |
| 17 // that need to be activated in the order that they should be activated. |
| 18 const int kWindowContainerIds[] = { |
| 19 internal::kShellWindowId_LockSystemModalContainer, |
| 20 internal::kShellWindowId_SettingBubbleContainer, |
| 21 internal::kShellWindowId_LockScreenContainer, |
| 22 internal::kShellWindowId_SystemModalContainer, |
| 23 internal::kShellWindowId_AlwaysOnTopContainer, |
| 24 internal::kShellWindowId_AppListContainer, |
| 25 internal::kShellWindowId_DefaultContainer, |
| 26 |
| 27 // Panel, launcher and status are intentionally checked after other |
| 28 // containers even though these layers are higher. The user expects their |
| 29 // windows to be focused before these elements. |
| 30 internal::kShellWindowId_PanelContainer, |
| 31 internal::kShellWindowId_LauncherContainer, |
| 32 internal::kShellWindowId_StatusContainer, |
| 33 }; |
| 34 |
| 35 bool BelongsToContainerWithEqualOrGreaterId(const aura::Window* window, |
| 36 int container_id) { |
| 37 for (; window; window = window->parent()) { |
| 38 if (window->id() >= container_id) |
| 39 return true; |
| 40 } |
| 41 return false; |
| 42 } |
| 43 |
| 44 } // namespace |
11 | 45 |
12 //////////////////////////////////////////////////////////////////////////////// | 46 //////////////////////////////////////////////////////////////////////////////// |
13 // AshFocusRules, public: | 47 // AshFocusRules, public: |
14 | 48 |
15 AshFocusRules::AshFocusRules() { | 49 AshFocusRules::AshFocusRules() { |
16 } | 50 } |
17 | 51 |
18 AshFocusRules::~AshFocusRules() { | 52 AshFocusRules::~AshFocusRules() { |
19 } | 53 } |
20 | 54 |
21 //////////////////////////////////////////////////////////////////////////////// | 55 //////////////////////////////////////////////////////////////////////////////// |
22 // AshFocusRules, views::corewm::FocusRules: | 56 // AshFocusRules, views::corewm::FocusRules: |
23 | 57 |
24 bool AshFocusRules::CanActivateWindow(aura::Window* window) { | 58 bool AshFocusRules::SupportsChildActivation(aura::Window* window) { |
25 return window && !!window->parent(); | 59 if (window->id() == internal::kShellWindowId_WorkspaceContainer) |
| 60 return true; |
| 61 |
| 62 if (window->id() != internal::kShellWindowId_DefaultContainer) |
| 63 return false; |
| 64 |
| 65 for (size_t i = 0; i < arraysize(kWindowContainerIds); i++) { |
| 66 if (window->id() == kWindowContainerIds[i]) |
| 67 return true; |
| 68 } |
| 69 return false; |
26 } | 70 } |
27 | 71 |
28 bool AshFocusRules::CanFocusWindow(aura::Window* window) { | 72 bool AshFocusRules::IsWindowConsideredVisibleForActivation( |
29 aura::Window* activatable = GetActivatableWindow(window); | 73 aura::Window* window) { |
30 return activatable->Contains(window) && window->CanFocus(); | 74 if (BaseFocusRules::IsWindowConsideredVisibleForActivation(window)) |
| 75 return true; |
| 76 |
| 77 // Minimized windows are hidden in their minimized state, but they can always |
| 78 // be activated. |
| 79 if (wm::IsWindowMinimized(window)) |
| 80 return true; |
| 81 |
| 82 return window->TargetVisibility() && (window->parent()->id() == |
| 83 internal::kShellWindowId_WorkspaceContainer || window->parent()->id() == |
| 84 internal::kShellWindowId_LockScreenContainer); |
31 } | 85 } |
32 | 86 |
33 aura::Window* AshFocusRules::GetActivatableWindow(aura::Window* window) { | 87 bool AshFocusRules::CanActivateWindow(aura::Window* window) { |
34 return window; | 88 if (!BaseFocusRules::CanActivateWindow(window)) |
35 } | 89 return false; |
36 | 90 |
37 aura::Window* AshFocusRules::GetFocusableWindow(aura::Window* window) { | 91 if (Shell::GetInstance()->IsSystemModalWindowOpen()) { |
38 return window; | 92 return BelongsToContainerWithEqualOrGreaterId( |
39 } | 93 window, internal::kShellWindowId_SystemModalContainer); |
| 94 } |
40 | 95 |
41 aura::Window* AshFocusRules::GetNextActivatableWindow(aura::Window* ignore) { | 96 return true; |
42 return NULL; | |
43 } | |
44 | |
45 aura::Window* AshFocusRules::GetNextFocusableWindow(aura::Window* ignore) { | |
46 return GetFocusableWindow(ignore->parent()); | |
47 } | 97 } |
48 | 98 |
49 } // namespace wm | 99 } // namespace wm |
50 } // namespace ash | 100 } // namespace ash |
OLD | NEW |