| 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" |
| 13 #include "ui/events/event.h" | 14 #include "ui/events/event.h" |
| 14 #include "ui/wm/core/focus_rules.h" | 15 #include "ui/wm/core/focus_rules.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 |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 | 224 |
| 224 void FocusController::SetFocusedWindow(aura::Window* window) { | 225 void FocusController::SetFocusedWindow(aura::Window* window) { |
| 225 if (updating_focus_ || window == focused_window_) | 226 if (updating_focus_ || window == focused_window_) |
| 226 return; | 227 return; |
| 227 DCHECK(rules_->CanFocusWindow(window)); | 228 DCHECK(rules_->CanFocusWindow(window)); |
| 228 if (window) | 229 if (window) |
| 229 DCHECK_EQ(window, rules_->GetFocusableWindow(window)); | 230 DCHECK_EQ(window, rules_->GetFocusableWindow(window)); |
| 230 | 231 |
| 231 base::AutoReset<bool> updating_focus(&updating_focus_, true); | 232 base::AutoReset<bool> updating_focus(&updating_focus_, true); |
| 232 aura::Window* lost_focus = focused_window_; | 233 aura::Window* lost_focus = focused_window_; |
| 234 |
| 235 // |window| is going to get the focus, so reset the text input client. |
| 236 // OnWindowFocused() may set a proper text input client if the implementation |
| 237 // supports text input. |
| 238 ui::TextInputFocusManager* text_input_focus_manager = |
| 239 ui::TextInputFocusManager::GetInstance(); |
| 240 if (window) |
| 241 text_input_focus_manager->FocusTextInputClient(NULL); |
| 242 |
| 233 // Allow for the window losing focus to be deleted during dispatch. If it is | 243 // Allow for the window losing focus to be deleted during dispatch. If it is |
| 234 // deleted pass NULL to observers instead of a deleted window. | 244 // deleted pass NULL to observers instead of a deleted window. |
| 235 aura::WindowTracker window_tracker; | 245 aura::WindowTracker window_tracker; |
| 236 if (lost_focus) | 246 if (lost_focus) |
| 237 window_tracker.Add(lost_focus); | 247 window_tracker.Add(lost_focus); |
| 238 if (focused_window_ && observer_manager_.IsObserving(focused_window_) && | 248 if (focused_window_ && observer_manager_.IsObserving(focused_window_) && |
| 239 focused_window_ != active_window_) { | 249 focused_window_ != active_window_) { |
| 240 observer_manager_.Remove(focused_window_); | 250 observer_manager_.Remove(focused_window_); |
| 241 } | 251 } |
| 242 focused_window_ = window; | 252 focused_window_ = window; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 254 if (observer) | 264 if (observer) |
| 255 observer->OnWindowFocused(focused_window_, lost_focus); | 265 observer->OnWindowFocused(focused_window_, lost_focus); |
| 256 } | 266 } |
| 257 aura::client::FocusChangeObserver* observer = | 267 aura::client::FocusChangeObserver* observer = |
| 258 aura::client::GetFocusChangeObserver(focused_window_); | 268 aura::client::GetFocusChangeObserver(focused_window_); |
| 259 if (observer) { | 269 if (observer) { |
| 260 observer->OnWindowFocused( | 270 observer->OnWindowFocused( |
| 261 focused_window_, | 271 focused_window_, |
| 262 window_tracker.Contains(lost_focus) ? lost_focus : NULL); | 272 window_tracker.Contains(lost_focus) ? lost_focus : NULL); |
| 263 } | 273 } |
| 274 |
| 275 // Ensure that the text input client is reset when the window loses the focus. |
| 276 if (!window) |
| 277 text_input_focus_manager->FocusTextInputClient(NULL); |
| 264 } | 278 } |
| 265 | 279 |
| 266 void FocusController::SetActiveWindow(aura::Window* requested_window, | 280 void FocusController::SetActiveWindow(aura::Window* requested_window, |
| 267 aura::Window* window) { | 281 aura::Window* window) { |
| 268 if (updating_activation_) | 282 if (updating_activation_) |
| 269 return; | 283 return; |
| 270 | 284 |
| 271 if (window == active_window_) { | 285 if (window == active_window_) { |
| 272 if (requested_window) { | 286 if (requested_window) { |
| 273 FOR_EACH_OBSERVER(aura::client::ActivationChangeObserver, | 287 FOR_EACH_OBSERVER(aura::client::ActivationChangeObserver, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 | 358 |
| 345 void FocusController::WindowFocusedFromInputEvent(aura::Window* window) { | 359 void FocusController::WindowFocusedFromInputEvent(aura::Window* window) { |
| 346 // Only focus |window| if it or any of its parents can be focused. Otherwise | 360 // Only focus |window| if it or any of its parents can be focused. Otherwise |
| 347 // FocusWindow() will focus the topmost window, which may not be the | 361 // FocusWindow() will focus the topmost window, which may not be the |
| 348 // currently focused one. | 362 // currently focused one. |
| 349 if (rules_->CanFocusWindow(GetToplevelWindow(window))) | 363 if (rules_->CanFocusWindow(GetToplevelWindow(window))) |
| 350 FocusWindow(window); | 364 FocusWindow(window); |
| 351 } | 365 } |
| 352 | 366 |
| 353 } // namespace wm | 367 } // namespace wm |
| OLD | NEW |