| 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" |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 //////////////////////////////////////////////////////////////////////////////// | 177 //////////////////////////////////////////////////////////////////////////////// |
| 178 // FocusController, aura::WindowObserver implementation: | 178 // FocusController, aura::WindowObserver implementation: |
| 179 | 179 |
| 180 void FocusController::OnWindowVisibilityChanged(aura::Window* window, | 180 void FocusController::OnWindowVisibilityChanged(aura::Window* window, |
| 181 bool visible) { | 181 bool visible) { |
| 182 if (!visible) | 182 if (!visible) |
| 183 WindowLostFocusFromDispositionChange(window, window->parent()); | 183 WindowLostFocusFromDispositionChange(window, window->parent()); |
| 184 } | 184 } |
| 185 | 185 |
| 186 void FocusController::OnWindowDestroying(aura::Window* window) { | 186 void FocusController::OnWindowDestroying(aura::Window* window) { |
| 187 // A window's modality state will interfere with focus restoration during its |
| 188 // destruction. |
| 189 window->ClearProperty(aura::client::kModalKey); |
| 187 WindowLostFocusFromDispositionChange(window, window->parent()); | 190 WindowLostFocusFromDispositionChange(window, window->parent()); |
| 188 } | 191 } |
| 189 | 192 |
| 190 void FocusController::OnWindowHierarchyChanging( | 193 void FocusController::OnWindowHierarchyChanging( |
| 191 const HierarchyChangeParams& params) { | 194 const HierarchyChangeParams& params) { |
| 192 if (params.receiver == active_window_ && | 195 if (params.receiver == active_window_ && |
| 193 params.target->Contains(params.receiver) && (!params.new_parent || | 196 params.target->Contains(params.receiver) && (!params.new_parent || |
| 194 aura::client::GetFocusClient(params.new_parent) != | 197 aura::client::GetFocusClient(params.new_parent) != |
| 195 aura::client::GetFocusClient(params.receiver))) { | 198 aura::client::GetFocusClient(params.receiver))) { |
| 196 WindowLostFocusFromDispositionChange(params.receiver, params.old_parent); | 199 WindowLostFocusFromDispositionChange(params.receiver, params.old_parent); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 FOR_EACH_OBSERVER(aura::client::ActivationChangeObserver, | 321 FOR_EACH_OBSERVER(aura::client::ActivationChangeObserver, |
| 319 activation_observers_, | 322 activation_observers_, |
| 320 OnWindowActivated(active_window_, | 323 OnWindowActivated(active_window_, |
| 321 window_tracker.Contains(lost_activation) ? | 324 window_tracker.Contains(lost_activation) ? |
| 322 lost_activation : NULL)); | 325 lost_activation : NULL)); |
| 323 } | 326 } |
| 324 | 327 |
| 325 void FocusController::WindowLostFocusFromDispositionChange( | 328 void FocusController::WindowLostFocusFromDispositionChange( |
| 326 aura::Window* window, | 329 aura::Window* window, |
| 327 aura::Window* next) { | 330 aura::Window* next) { |
| 328 // A window's modality state will interfere with focus restoration during its | |
| 329 // destruction. | |
| 330 window->ClearProperty(aura::client::kModalKey); | |
| 331 // TODO(beng): See if this function can be replaced by a call to | 331 // TODO(beng): See if this function can be replaced by a call to |
| 332 // FocusWindow(). | 332 // FocusWindow(). |
| 333 // Activation adjustments are handled first in the event of a disposition | 333 // Activation adjustments are handled first in the event of a disposition |
| 334 // changed. If an activation change is necessary, focus is reset as part of | 334 // changed. If an activation change is necessary, focus is reset as part of |
| 335 // that process so there's no point in updating focus independently. | 335 // that process so there's no point in updating focus independently. |
| 336 if (window == active_window_) { | 336 if (window == active_window_) { |
| 337 aura::Window* next_activatable = rules_->GetNextActivatableWindow(window); | 337 aura::Window* next_activatable = rules_->GetNextActivatableWindow(window); |
| 338 SetActiveWindow(NULL, next_activatable); | 338 SetActiveWindow(NULL, next_activatable); |
| 339 if (!(active_window_ && active_window_->Contains(focused_window_))) | 339 if (!(active_window_ && active_window_->Contains(focused_window_))) |
| 340 SetFocusedWindow(next_activatable); | 340 SetFocusedWindow(next_activatable); |
| 341 } else if (window->Contains(focused_window_)) { | 341 } else if (window->Contains(focused_window_)) { |
| 342 // Active window isn't changing, but focused window might be. | 342 // Active window isn't changing, but focused window might be. |
| 343 SetFocusedWindow(rules_->GetFocusableWindow(next)); | 343 SetFocusedWindow(rules_->GetFocusableWindow(next)); |
| 344 } | 344 } |
| 345 } | 345 } |
| 346 | 346 |
| 347 void FocusController::WindowFocusedFromInputEvent(aura::Window* window) { | 347 void FocusController::WindowFocusedFromInputEvent(aura::Window* window) { |
| 348 // Only focus |window| if it or any of its parents can be focused. Otherwise | 348 // Only focus |window| if it or any of its parents can be focused. Otherwise |
| 349 // FocusWindow() will focus the topmost window, which may not be the | 349 // FocusWindow() will focus the topmost window, which may not be the |
| 350 // currently focused one. | 350 // currently focused one. |
| 351 if (rules_->CanFocusWindow(GetToplevelWindow(window))) | 351 if (rules_->CanFocusWindow(GetToplevelWindow(window))) |
| 352 FocusWindow(window); | 352 FocusWindow(window); |
| 353 } | 353 } |
| 354 | 354 |
| 355 } // namespace wm | 355 } // namespace wm |
| OLD | NEW |