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

Side by Side Diff: ui/views/corewm/focus_controller.cc

Issue 75933005: Makes FocusdController honor focus change if no previously active window (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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
« no previous file with comments | « no previous file | ui/views/corewm/focus_controller_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/views/corewm/focus_controller.h" 5 #include "ui/views/corewm/focus_controller.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "ui/aura/client/activation_change_observer.h" 8 #include "ui/aura/client/activation_change_observer.h"
9 #include "ui/aura/client/aura_constants.h" 9 #include "ui/aura/client/aura_constants.h"
10 #include "ui/aura/client/capture_client.h" 10 #include "ui/aura/client/capture_client.h"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 // We need valid focusable/activatable windows in the event we're not clearing 146 // We need valid focusable/activatable windows in the event we're not clearing
147 // focus. "Clearing focus" is inferred by whether or not |window| passed to 147 // focus. "Clearing focus" is inferred by whether or not |window| passed to
148 // this function is non-NULL. 148 // this function is non-NULL.
149 if (window && (!focusable || !activatable)) 149 if (window && (!focusable || !activatable))
150 return; 150 return;
151 DCHECK((focusable && activatable) || !window); 151 DCHECK((focusable && activatable) || !window);
152 152
153 // Activation change observers may change the focused window. If this happens 153 // Activation change observers may change the focused window. If this happens
154 // we must not adjust the focus below since this will clobber that change. 154 // we must not adjust the focus below since this will clobber that change.
155 aura::Window* last_focused_window = focused_window_; 155 aura::Window* last_focused_window = focused_window_;
156 aura::Window* last_active_window = active_window_;
156 if (!updating_activation_) 157 if (!updating_activation_)
157 SetActiveWindow(window, activatable); 158 SetActiveWindow(window, activatable);
158 159
159 // If the window's ActivationChangeObserver shifted focus to a valid window, 160 // If the window's ActivationChangeObserver shifted focus to a valid window,
160 // we don't want to focus the window we thought would be focused by default. 161 // we don't want to focus the window we thought would be focused by default.
162 //
163 // Allow the request through if there was previously no active window. When
164 // there is no active window and an attempt is made to activate a window views
165 // may try to restore focus to the view (and thereby window) that previously
166 // had focus. In this case we want to focus the window passed to this function
167 // and not the previously focused window.
161 bool activation_changed_focus = last_focused_window != focused_window_; 168 bool activation_changed_focus = last_focused_window != focused_window_;
162 if (!updating_focus_ && (!activation_changed_focus || !focused_window_)) { 169 if (!updating_focus_ && (!activation_changed_focus || !focused_window_ ||
170 !last_active_window)) {
163 if (active_window_ && focusable) 171 if (active_window_ && focusable)
164 DCHECK(active_window_->Contains(focusable)); 172 DCHECK(active_window_->Contains(focusable));
165 SetFocusedWindow(focusable); 173 SetFocusedWindow(focusable);
166 } 174 }
167 } 175 }
168 176
169 void FocusController::ResetFocusWithinActiveWindow(aura::Window* window) { 177 void FocusController::ResetFocusWithinActiveWindow(aura::Window* window) {
170 DCHECK(window); 178 DCHECK(window);
171 if (!active_window_) 179 if (!active_window_)
172 return; 180 return;
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 void FocusController::WindowFocusedFromInputEvent(aura::Window* window) { 351 void FocusController::WindowFocusedFromInputEvent(aura::Window* window) {
344 // Only focus |window| if it or any of its parents can be focused. Otherwise 352 // Only focus |window| if it or any of its parents can be focused. Otherwise
345 // FocusWindow() will focus the topmost window, which may not be the 353 // FocusWindow() will focus the topmost window, which may not be the
346 // currently focused one. 354 // currently focused one.
347 if (rules_->CanFocusWindow(GetToplevelWindow(window))) 355 if (rules_->CanFocusWindow(GetToplevelWindow(window)))
348 FocusWindow(window); 356 FocusWindow(window);
349 } 357 }
350 358
351 } // namespace corewm 359 } // namespace corewm
352 } // namespace views 360 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | ui/views/corewm/focus_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698