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/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" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 // Returns true if children of |window| can be activated. | 48 // Returns true if children of |window| can be activated. |
49 // These are the only containers in which windows can receive focus. | 49 // These are the only containers in which windows can receive focus. |
50 bool SupportsChildActivation(aura::Window* window) { | 50 bool SupportsChildActivation(aura::Window* window) { |
51 for (size_t i = 0; i < arraysize(kWindowContainerIds); i++) { | 51 for (size_t i = 0; i < arraysize(kWindowContainerIds); i++) { |
52 if (window->id() == kWindowContainerIds[i]) | 52 if (window->id() == kWindowContainerIds[i]) |
53 return true; | 53 return true; |
54 } | 54 } |
55 return false; | 55 return false; |
56 } | 56 } |
57 | 57 |
| 58 bool HasModalTransientChild(aura::Window* window) { |
| 59 aura::Window::Windows::const_iterator it; |
| 60 for (it = window->transient_children().begin(); |
| 61 it != window->transient_children().end(); |
| 62 ++it) { |
| 63 if ((*it)->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_WINDOW) |
| 64 return true; |
| 65 } |
| 66 return false; |
| 67 } |
| 68 |
58 // Returns true if |window| can be activated or deactivated. | 69 // Returns true if |window| can be activated or deactivated. |
59 // A window manager typically defines some notion of "top level window" that | 70 // A window manager typically defines some notion of "top level window" that |
60 // supports activation/deactivation. | 71 // supports activation/deactivation. |
61 bool CanActivateWindow(aura::Window* window, const aura::Event* event) { | 72 bool CanActivateWindowWithEvent(aura::Window* window, |
| 73 const aura::Event* event) { |
62 return window && | 74 return window && |
63 window->IsVisible() && | 75 window->IsVisible() && |
64 (!aura::client::GetActivationDelegate(window) || | 76 (!aura::client::GetActivationDelegate(window) || |
65 aura::client::GetActivationDelegate(window)->ShouldActivate(event)) && | 77 aura::client::GetActivationDelegate(window)->ShouldActivate(event)) && |
66 SupportsChildActivation(window->parent()); | 78 SupportsChildActivation(window->parent()); |
67 } | 79 } |
68 | 80 |
69 // When a modal window is activated, we bring its entire transient parent chain | 81 // When a modal window is activated, we bring its entire transient parent chain |
70 // to the front. This function must be called before the modal transient is | 82 // to the front. This function must be called before the modal transient is |
71 // stacked at the top to ensure correct stacking order. | 83 // stacked at the top to ensure correct stacking order. |
(...skipping 25 matching lines...) Expand all Loading... |
97 aura::Env::GetInstance()->RemoveObserver(this); | 109 aura::Env::GetInstance()->RemoveObserver(this); |
98 } | 110 } |
99 | 111 |
100 // static | 112 // static |
101 aura::Window* ActivationController::GetActivatableWindow( | 113 aura::Window* ActivationController::GetActivatableWindow( |
102 aura::Window* window, | 114 aura::Window* window, |
103 const aura::Event* event) { | 115 const aura::Event* event) { |
104 aura::Window* parent = window->parent(); | 116 aura::Window* parent = window->parent(); |
105 aura::Window* child = window; | 117 aura::Window* child = window; |
106 while (parent) { | 118 while (parent) { |
107 if (CanActivateWindow(child, event)) | 119 if (CanActivateWindowWithEvent(child, event)) |
108 return child; | 120 return child; |
109 // If |child| isn't activatable, but has transient parent, trace | 121 // If |child| isn't activatable, but has transient parent, trace |
110 // that path instead. | 122 // that path instead. |
111 if (child->transient_parent()) | 123 if (child->transient_parent()) |
112 return GetActivatableWindow(child->transient_parent(), event); | 124 return GetActivatableWindow(child->transient_parent(), event); |
113 parent = parent->parent(); | 125 parent = parent->parent(); |
114 child = child->parent(); | 126 child = child->parent(); |
115 } | 127 } |
116 return NULL; | 128 return NULL; |
117 } | 129 } |
118 | 130 |
| 131 bool ActivationController::CanActivateWindow(aura::Window* window) const { |
| 132 return CanActivateWindowWithEvent(window, NULL) && |
| 133 !HasModalTransientChild(window); |
| 134 } |
| 135 |
119 //////////////////////////////////////////////////////////////////////////////// | 136 //////////////////////////////////////////////////////////////////////////////// |
120 // ActivationController, aura::client::ActivationClient implementation: | 137 // ActivationController, aura::client::ActivationClient implementation: |
121 | 138 |
122 void ActivationController::ActivateWindow(aura::Window* window) { | 139 void ActivationController::ActivateWindow(aura::Window* window) { |
123 ActivateWindowWithEvent(window, NULL); | 140 ActivateWindowWithEvent(window, NULL); |
124 } | 141 } |
125 | 142 |
126 void ActivationController::DeactivateWindow(aura::Window* window) { | 143 void ActivationController::DeactivateWindow(aura::Window* window) { |
127 if (window) | 144 if (window) |
128 ActivateNextWindow(window); | 145 ActivateNextWindow(window); |
129 } | 146 } |
130 | 147 |
131 aura::Window* ActivationController::GetActiveWindow() { | 148 aura::Window* ActivationController::GetActiveWindow() { |
132 return Shell::GetRootWindow()->GetProperty( | 149 return Shell::GetRootWindow()->GetProperty( |
133 aura::client::kRootWindowActiveWindowKey); | 150 aura::client::kRootWindowActiveWindowKey); |
134 } | 151 } |
135 | 152 |
136 bool ActivationController::OnWillFocusWindow(aura::Window* window, | 153 bool ActivationController::OnWillFocusWindow(aura::Window* window, |
137 const aura::Event* event) { | 154 const aura::Event* event) { |
138 return CanActivateWindow(GetActivatableWindow(window, event), event); | 155 return CanActivateWindowWithEvent(GetActivatableWindow(window, event), event); |
139 } | 156 } |
140 | 157 |
141 //////////////////////////////////////////////////////////////////////////////// | 158 //////////////////////////////////////////////////////////////////////////////// |
142 // ActivationController, aura::WindowObserver implementation: | 159 // ActivationController, aura::WindowObserver implementation: |
143 | 160 |
144 void ActivationController::OnWindowVisibilityChanged(aura::Window* window, | 161 void ActivationController::OnWindowVisibilityChanged(aura::Window* window, |
145 bool visible) { | 162 bool visible) { |
146 if (!visible) { | 163 if (!visible) { |
147 aura::Window* next_window = ActivateNextWindow(window); | 164 aura::Window* next_window = ActivateNextWindow(window); |
148 if (next_window && next_window->parent() == window->parent()) { | 165 if (next_window && next_window->parent() == window->parent()) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 if (updating_activation_) | 212 if (updating_activation_) |
196 return; | 213 return; |
197 | 214 |
198 AutoReset<bool> in_activate_window(&updating_activation_, true); | 215 AutoReset<bool> in_activate_window(&updating_activation_, true); |
199 // Nothing may actually have changed. | 216 // Nothing may actually have changed. |
200 aura::Window* old_active = GetActiveWindow(); | 217 aura::Window* old_active = GetActiveWindow(); |
201 if (old_active == window) | 218 if (old_active == window) |
202 return; | 219 return; |
203 // The stacking client may impose rules on what window configurations can be | 220 // The stacking client may impose rules on what window configurations can be |
204 // activated or deactivated. | 221 // activated or deactivated. |
205 if (window && !CanActivateWindow(window, event)) | 222 if (window && !CanActivateWindowWithEvent(window, event)) |
206 return; | 223 return; |
207 // If the screen is locked, just bring the window to top so that | 224 // If the screen is locked, just bring the window to top so that |
208 // it will be activated when the lock window is destroyed. | 225 // it will be activated when the lock window is destroyed. |
209 if (window && !window->CanReceiveEvents()) { | 226 if (window && !window->CanReceiveEvents()) { |
210 StackTransientParentsBelowModalWindow(window); | 227 StackTransientParentsBelowModalWindow(window); |
211 window->parent()->StackChildAtTop(window); | 228 window->parent()->StackChildAtTop(window); |
212 return; | 229 return; |
213 } | 230 } |
214 if (window && | 231 if (window && |
215 !window->Contains(window->GetFocusManager()->GetFocusedWindow())) { | 232 !window->Contains(window->GetFocusManager()->GetFocusedWindow())) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 return window; | 282 return window; |
266 } | 283 } |
267 | 284 |
268 aura::Window* ActivationController::GetTopmostWindowToActivateInContainer( | 285 aura::Window* ActivationController::GetTopmostWindowToActivateInContainer( |
269 aura::Window* container, | 286 aura::Window* container, |
270 aura::Window* ignore) const { | 287 aura::Window* ignore) const { |
271 for (aura::Window::Windows::const_reverse_iterator i = | 288 for (aura::Window::Windows::const_reverse_iterator i = |
272 container->children().rbegin(); | 289 container->children().rbegin(); |
273 i != container->children().rend(); | 290 i != container->children().rend(); |
274 ++i) { | 291 ++i) { |
275 if (*i != ignore && CanActivateWindow(*i, NULL)) | 292 if (*i != ignore && CanActivateWindowWithEvent(*i, NULL)) |
276 return *i; | 293 return *i; |
277 } | 294 } |
278 return NULL; | 295 return NULL; |
279 } | 296 } |
280 | 297 |
281 } // namespace internal | 298 } // namespace internal |
282 } // namespace ash | 299 } // namespace ash |
OLD | NEW |