| 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 "ui/wm/core/focus_controller.h" | 5 #include "ui/wm/core/focus_controller.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "ui/aura/client/aura_constants.h" | 8 #include "ui/aura/client/aura_constants.h" |
| 9 #include "ui/aura/client/capture_client.h" | 9 #include "ui/aura/client/capture_client.h" |
| 10 #include "ui/aura/client/focus_change_observer.h" | 10 #include "ui/aura/client/focus_change_observer.h" |
| 11 #include "ui/aura/env.h" | 11 #include "ui/aura/env.h" |
| 12 #include "ui/aura/window_tracker.h" | 12 #include "ui/aura/window_tracker.h" |
| 13 #include "ui/events/event.h" | 13 #include "ui/events/event.h" |
| 14 #include "ui/wm/core/focus_rules.h" | 14 #include "ui/wm/core/focus_rules.h" |
| 15 #include "ui/wm/core/window_modality_controller.h" |
| 15 #include "ui/wm/core/window_util.h" | 16 #include "ui/wm/core/window_util.h" |
| 16 #include "ui/wm/public/activation_change_observer.h" | 17 #include "ui/wm/public/activation_change_observer.h" |
| 17 | 18 |
| 18 namespace wm { | 19 namespace wm { |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 // When a modal window is activated, we bring its entire transient parent chain | 22 // When a modal window is activated, we bring its entire transient parent chain |
| 22 // to the front. This function must be called before the modal transient is | 23 // to the front. This function must be called before the modal transient is |
| 23 // stacked at the top to ensure correct stacking order. | 24 // stacked at the top to ensure correct stacking order. |
| 24 void StackTransientParentsBelowModalWindow(aura::Window* window) { | 25 void StackTransientParentsBelowModalWindow(aura::Window* window) { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 183 |
| 183 //////////////////////////////////////////////////////////////////////////////// | 184 //////////////////////////////////////////////////////////////////////////////// |
| 184 // FocusController, private: | 185 // FocusController, private: |
| 185 | 186 |
| 186 void FocusController::FocusAndActivateWindow( | 187 void FocusController::FocusAndActivateWindow( |
| 187 aura::client::ActivationChangeObserver::ActivationReason reason, | 188 aura::client::ActivationChangeObserver::ActivationReason reason, |
| 188 aura::Window* window) { | 189 aura::Window* window) { |
| 189 if (window && | 190 if (window && |
| 190 (window->Contains(focused_window_) || window->Contains(active_window_))) { | 191 (window->Contains(focused_window_) || window->Contains(active_window_))) { |
| 191 StackActiveWindow(); | 192 StackActiveWindow(); |
| 192 return; | 193 if (HasWindowModalTransient(window) && active_window_ == window) |
| 194 // Trying to reactivate the window, need to activate the transient first |
| 195 ActivateWindow(HasWindowModalTransient(window)); |
| 196 else |
| 197 return; |
| 193 } | 198 } |
| 194 | 199 |
| 195 // Focusing a window also activates its containing activatable window. Note | 200 // Focusing a window also activates its containing activatable window. Note |
| 196 // that the rules could redirect activation activation and/or focus. | 201 // that the rules could redirect activation activation and/or focus. |
| 197 aura::Window* focusable = rules_->GetFocusableWindow(window); | 202 aura::Window* focusable = rules_->GetFocusableWindow(window); |
| 198 aura::Window* activatable = | 203 aura::Window* activatable = |
| 199 focusable ? rules_->GetActivatableWindow(focusable) : NULL; | 204 focusable ? rules_->GetActivatableWindow(focusable) : NULL; |
| 200 | 205 |
| 201 // We need valid focusable/activatable windows in the event we're not clearing | 206 // We need valid focusable/activatable windows in the event we're not clearing |
| 202 // focus. "Clearing focus" is inferred by whether or not |window| passed to | 207 // focus. "Clearing focus" is inferred by whether or not |window| passed to |
| 203 // this function is non-NULL. | 208 // this function is non-NULL. |
| 204 if (window && (!focusable || !activatable)) | 209 if (window && (!focusable || !activatable)) |
| 205 return; | 210 return; |
| 206 DCHECK((focusable && activatable) || !window); | 211 DCHECK((focusable && activatable) || !window); |
| 207 | 212 |
| 208 // Activation change observers may change the focused window. If this happens | 213 // Activation change observers may change the focused window. If this happens |
| 209 // we must not adjust the focus below since this will clobber that change. | 214 // we must not adjust the focus below since this will clobber that change. |
| 210 aura::Window* last_focused_window = focused_window_; | 215 aura::Window* last_focused_window = focused_window_; |
| 211 if (!updating_activation_) | 216 if (!updating_activation_) |
| 212 SetActiveWindow(reason, window, activatable); | 217 SetActiveWindow(reason, window, activatable); |
| 213 | 218 |
| 214 // If the window's ActivationChangeObserver shifted focus to a valid window, | 219 // If the window's ActivationChangeObserver shifted focus to a valid window, |
| 215 // we don't want to focus the window we thought would be focused by default. | 220 // we don't want to focus the window we thought would be focused by default. |
| 216 bool activation_changed_focus = last_focused_window != focused_window_; | 221 bool activation_changed_focus = last_focused_window != focused_window_; |
| 222 if ((!updating_focus_ && (!activation_changed_focus || !focused_window_)) && |
| 223 active_window_ && focusable && |
| 224 !active_window_->Contains(focusable) && |
| 225 (HasWindowModalTransient(active_window_) == |
| 226 GetToplevelWindow(window))){ |
| 227 return; |
| 228 } |
| 217 if (!updating_focus_ && (!activation_changed_focus || !focused_window_)) { | 229 if (!updating_focus_ && (!activation_changed_focus || !focused_window_)) { |
| 218 if (active_window_ && focusable) | 230 if (active_window_ && focusable) |
| 219 DCHECK(active_window_->Contains(focusable)); | 231 DCHECK(active_window_->Contains(focusable)); |
| 220 SetFocusedWindow(focusable); | 232 SetFocusedWindow(focusable); |
| 221 } | 233 } |
| 222 } | 234 } |
| 223 | 235 |
| 224 void FocusController::SetFocusedWindow(aura::Window* window) { | 236 void FocusController::SetFocusedWindow(aura::Window* window) { |
| 225 if (updating_focus_ || window == focused_window_) | 237 if (updating_focus_ || window == focused_window_) |
| 226 return; | 238 return; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 } | 276 } |
| 265 } | 277 } |
| 266 | 278 |
| 267 void FocusController::SetActiveWindow( | 279 void FocusController::SetActiveWindow( |
| 268 aura::client::ActivationChangeObserver::ActivationReason reason, | 280 aura::client::ActivationChangeObserver::ActivationReason reason, |
| 269 aura::Window* requested_window, | 281 aura::Window* requested_window, |
| 270 aura::Window* window) { | 282 aura::Window* window) { |
| 271 if (updating_activation_) | 283 if (updating_activation_) |
| 272 return; | 284 return; |
| 273 | 285 |
| 274 if (window == active_window_) { | 286 if (window == active_window_ && !HasWindowModalTransient(window)) { |
| 275 if (requested_window) { | 287 if (requested_window) { |
| 276 FOR_EACH_OBSERVER(aura::client::ActivationChangeObserver, | 288 FOR_EACH_OBSERVER(aura::client::ActivationChangeObserver, |
| 277 activation_observers_, | 289 activation_observers_, |
| 278 OnAttemptToReactivateWindow(requested_window, | 290 OnAttemptToReactivateWindow(requested_window, |
| 279 active_window_)); | 291 active_window_)); |
| 280 } | 292 } |
| 281 return; | 293 return; |
| 282 } | 294 } |
| 283 | 295 |
| 284 DCHECK(rules_->CanActivateWindow(window)); | 296 DCHECK(rules_->CanActivateWindow(window)); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 // FocusWindow() will focus the topmost window, which may not be the | 366 // FocusWindow() will focus the topmost window, which may not be the |
| 355 // currently focused one. | 367 // currently focused one. |
| 356 if (rules_->CanFocusWindow(GetToplevelWindow(window))) { | 368 if (rules_->CanFocusWindow(GetToplevelWindow(window))) { |
| 357 FocusAndActivateWindow( | 369 FocusAndActivateWindow( |
| 358 aura::client::ActivationChangeObserver::ActivationReason::INPUT_EVENT, | 370 aura::client::ActivationChangeObserver::ActivationReason::INPUT_EVENT, |
| 359 window); | 371 window); |
| 360 } | 372 } |
| 361 } | 373 } |
| 362 | 374 |
| 363 } // namespace wm | 375 } // namespace wm |
| OLD | NEW |