Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(409)

Side by Side Diff: ui/wm/core/focus_controller.cc

Issue 173803002: Redesigns the text input focus handling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reset the text input client in FocusController. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 aura::Window* activatable = 127 aura::Window* activatable =
127 focusable ? rules_->GetActivatableWindow(focusable) : NULL; 128 focusable ? rules_->GetActivatableWindow(focusable) : NULL;
128 129
129 // We need valid focusable/activatable windows in the event we're not clearing 130 // We need valid focusable/activatable windows in the event we're not clearing
130 // focus. "Clearing focus" is inferred by whether or not |window| passed to 131 // focus. "Clearing focus" is inferred by whether or not |window| passed to
131 // this function is non-NULL. 132 // this function is non-NULL.
132 if (window && (!focusable || !activatable)) 133 if (window && (!focusable || !activatable))
133 return; 134 return;
134 DCHECK((focusable && activatable) || !window); 135 DCHECK((focusable && activatable) || !window);
135 136
137 // |window| is going to get the focus, so reset the text input client.
138 // SetActiveWindow() and/or SetFocusedWindow() may set a proper text input
139 // client if the implementation supports text input.
140 ui::TextInputFocusManager* text_input_focus_manager =
141 ui::TextInputFocusManager::GetInstance();
142 if (window)
143 text_input_focus_manager->FocusTextInputClient(NULL);
sky 2014/04/25 18:20:21 Shouldn't all this be in SetFocusedWindow?
Yuki 2014/04/28 12:59:29 You're right. Moved.
144
136 // Activation change observers may change the focused window. If this happens 145 // Activation change observers may change the focused window. If this happens
137 // we must not adjust the focus below since this will clobber that change. 146 // we must not adjust the focus below since this will clobber that change.
138 aura::Window* last_focused_window = focused_window_; 147 aura::Window* last_focused_window = focused_window_;
139 if (!updating_activation_) 148 if (!updating_activation_)
140 SetActiveWindow(window, activatable); 149 SetActiveWindow(window, activatable);
141 150
142 // If the window's ActivationChangeObserver shifted focus to a valid window, 151 // If the window's ActivationChangeObserver shifted focus to a valid window,
143 // we don't want to focus the window we thought would be focused by default. 152 // we don't want to focus the window we thought would be focused by default.
144 bool activation_changed_focus = last_focused_window != focused_window_; 153 bool activation_changed_focus = last_focused_window != focused_window_;
145 if (!updating_focus_ && (!activation_changed_focus || !focused_window_)) { 154 if (!updating_focus_ && (!activation_changed_focus || !focused_window_)) {
146 if (active_window_ && focusable) 155 if (active_window_ && focusable)
147 DCHECK(active_window_->Contains(focusable)); 156 DCHECK(active_window_->Contains(focusable));
148 SetFocusedWindow(focusable); 157 SetFocusedWindow(focusable);
149 } 158 }
159
160 // Ensure that the text input client is reset when the window loses the focus.
161 if (!window)
162 text_input_focus_manager->FocusTextInputClient(NULL);
150 } 163 }
151 164
152 void FocusController::ResetFocusWithinActiveWindow(aura::Window* window) { 165 void FocusController::ResetFocusWithinActiveWindow(aura::Window* window) {
153 DCHECK(window); 166 DCHECK(window);
154 if (!active_window_) 167 if (!active_window_)
155 return; 168 return;
156 if (!active_window_->Contains(window)) 169 if (!active_window_->Contains(window))
157 return; 170 return;
158 SetFocusedWindow(window); 171 SetFocusedWindow(window);
159 } 172 }
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 357
345 void FocusController::WindowFocusedFromInputEvent(aura::Window* window) { 358 void FocusController::WindowFocusedFromInputEvent(aura::Window* window) {
346 // Only focus |window| if it or any of its parents can be focused. Otherwise 359 // 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 360 // FocusWindow() will focus the topmost window, which may not be the
348 // currently focused one. 361 // currently focused one.
349 if (rules_->CanFocusWindow(GetToplevelWindow(window))) 362 if (rules_->CanFocusWindow(GetToplevelWindow(window)))
350 FocusWindow(window); 363 FocusWindow(window);
351 } 364 }
352 365
353 } // namespace wm 366 } // namespace wm
OLDNEW
« ui/views/widget/desktop_aura/desktop_native_widget_aura.cc ('K') | « ui/views/widget/widget.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698