| 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/base/ime/text_input_focus_manager.h" | |
| 14 #include "ui/events/event.h" | 13 #include "ui/events/event.h" |
| 15 #include "ui/wm/core/focus_rules.h" | 14 #include "ui/wm/core/focus_rules.h" |
| 16 #include "ui/wm/core/window_util.h" | 15 #include "ui/wm/core/window_util.h" |
| 17 #include "ui/wm/public/activation_change_observer.h" | 16 #include "ui/wm/public/activation_change_observer.h" |
| 18 | 17 |
| 19 namespace wm { | 18 namespace wm { |
| 20 namespace { | 19 namespace { |
| 21 | 20 |
| 22 // When a modal window is activated, we bring its entire transient parent chain | 21 // When a modal window is activated, we bring its entire transient parent chain |
| 23 // to the front. This function must be called before the modal transient is | 22 // to the front. This function must be called before the modal transient is |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 void FocusController::SetFocusedWindow(aura::Window* window) { | 223 void FocusController::SetFocusedWindow(aura::Window* window) { |
| 225 if (updating_focus_ || window == focused_window_) | 224 if (updating_focus_ || window == focused_window_) |
| 226 return; | 225 return; |
| 227 DCHECK(rules_->CanFocusWindow(window)); | 226 DCHECK(rules_->CanFocusWindow(window)); |
| 228 if (window) | 227 if (window) |
| 229 DCHECK_EQ(window, rules_->GetFocusableWindow(window)); | 228 DCHECK_EQ(window, rules_->GetFocusableWindow(window)); |
| 230 | 229 |
| 231 base::AutoReset<bool> updating_focus(&updating_focus_, true); | 230 base::AutoReset<bool> updating_focus(&updating_focus_, true); |
| 232 aura::Window* lost_focus = focused_window_; | 231 aura::Window* lost_focus = focused_window_; |
| 233 | 232 |
| 234 // |window| is going to get the focus, so reset the text input client. | |
| 235 // OnWindowFocused() may set a proper text input client if the implementation | |
| 236 // supports text input. | |
| 237 ui::TextInputFocusManager* text_input_focus_manager = | |
| 238 ui::TextInputFocusManager::GetInstance(); | |
| 239 if (window) | |
| 240 text_input_focus_manager->FocusTextInputClient(NULL); | |
| 241 | |
| 242 // Allow for the window losing focus to be deleted during dispatch. If it is | 233 // Allow for the window losing focus to be deleted during dispatch. If it is |
| 243 // deleted pass NULL to observers instead of a deleted window. | 234 // deleted pass NULL to observers instead of a deleted window. |
| 244 aura::WindowTracker window_tracker; | 235 aura::WindowTracker window_tracker; |
| 245 if (lost_focus) | 236 if (lost_focus) |
| 246 window_tracker.Add(lost_focus); | 237 window_tracker.Add(lost_focus); |
| 247 if (focused_window_ && observer_manager_.IsObserving(focused_window_) && | 238 if (focused_window_ && observer_manager_.IsObserving(focused_window_) && |
| 248 focused_window_ != active_window_) { | 239 focused_window_ != active_window_) { |
| 249 observer_manager_.Remove(focused_window_); | 240 observer_manager_.Remove(focused_window_); |
| 250 } | 241 } |
| 251 focused_window_ = window; | 242 focused_window_ = window; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 263 if (observer) | 254 if (observer) |
| 264 observer->OnWindowFocused(focused_window_, lost_focus); | 255 observer->OnWindowFocused(focused_window_, lost_focus); |
| 265 } | 256 } |
| 266 aura::client::FocusChangeObserver* observer = | 257 aura::client::FocusChangeObserver* observer = |
| 267 aura::client::GetFocusChangeObserver(focused_window_); | 258 aura::client::GetFocusChangeObserver(focused_window_); |
| 268 if (observer) { | 259 if (observer) { |
| 269 observer->OnWindowFocused( | 260 observer->OnWindowFocused( |
| 270 focused_window_, | 261 focused_window_, |
| 271 window_tracker.Contains(lost_focus) ? lost_focus : NULL); | 262 window_tracker.Contains(lost_focus) ? lost_focus : NULL); |
| 272 } | 263 } |
| 273 | |
| 274 // Ensure that the text input client is reset when the window loses the focus. | |
| 275 if (!window) | |
| 276 text_input_focus_manager->FocusTextInputClient(NULL); | |
| 277 } | 264 } |
| 278 | 265 |
| 279 void FocusController::SetActiveWindow( | 266 void FocusController::SetActiveWindow( |
| 280 aura::client::ActivationChangeObserver::ActivationReason reason, | 267 aura::client::ActivationChangeObserver::ActivationReason reason, |
| 281 aura::Window* requested_window, | 268 aura::Window* requested_window, |
| 282 aura::Window* window) { | 269 aura::Window* window) { |
| 283 if (updating_activation_) | 270 if (updating_activation_) |
| 284 return; | 271 return; |
| 285 | 272 |
| 286 if (window == active_window_) { | 273 if (window == active_window_) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 // FocusWindow() will focus the topmost window, which may not be the | 348 // FocusWindow() will focus the topmost window, which may not be the |
| 362 // currently focused one. | 349 // currently focused one. |
| 363 if (rules_->CanFocusWindow(GetToplevelWindow(window))) { | 350 if (rules_->CanFocusWindow(GetToplevelWindow(window))) { |
| 364 FocusAndActivateWindow( | 351 FocusAndActivateWindow( |
| 365 aura::client::ActivationChangeObserver::ActivationReason::INPUT_EVENT, | 352 aura::client::ActivationChangeObserver::ActivationReason::INPUT_EVENT, |
| 366 window); | 353 window); |
| 367 } | 354 } |
| 368 } | 355 } |
| 369 | 356 |
| 370 } // namespace wm | 357 } // namespace wm |
| OLD | NEW |