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/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 Loading... |
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_; | |
157 if (!updating_activation_) | 156 if (!updating_activation_) |
158 SetActiveWindow(window, activatable); | 157 SetActiveWindow(window, activatable); |
159 | 158 |
160 // If the window's ActivationChangeObserver shifted focus to a valid window, | 159 // If the window's ActivationChangeObserver shifted focus to a valid window, |
161 // we don't want to focus the window we thought would be focused by default. | 160 // 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. | |
168 bool activation_changed_focus = last_focused_window != focused_window_; | 161 bool activation_changed_focus = last_focused_window != focused_window_; |
169 if (!updating_focus_ && (!activation_changed_focus || !focused_window_ || | 162 if (!updating_focus_ && (!activation_changed_focus || !focused_window_)) { |
170 !last_active_window)) { | |
171 if (active_window_ && focusable) | 163 if (active_window_ && focusable) |
172 DCHECK(active_window_->Contains(focusable)); | 164 DCHECK(active_window_->Contains(focusable)); |
173 SetFocusedWindow(focusable); | 165 SetFocusedWindow(focusable); |
174 } | 166 } |
175 } | 167 } |
176 | 168 |
177 void FocusController::ResetFocusWithinActiveWindow(aura::Window* window) { | 169 void FocusController::ResetFocusWithinActiveWindow(aura::Window* window) { |
178 DCHECK(window); | 170 DCHECK(window); |
179 if (!active_window_) | 171 if (!active_window_) |
180 return; | 172 return; |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 void FocusController::WindowFocusedFromInputEvent(aura::Window* window) { | 343 void FocusController::WindowFocusedFromInputEvent(aura::Window* window) { |
352 // Only focus |window| if it or any of its parents can be focused. Otherwise | 344 // Only focus |window| if it or any of its parents can be focused. Otherwise |
353 // FocusWindow() will focus the topmost window, which may not be the | 345 // FocusWindow() will focus the topmost window, which may not be the |
354 // currently focused one. | 346 // currently focused one. |
355 if (rules_->CanFocusWindow(GetToplevelWindow(window))) | 347 if (rules_->CanFocusWindow(GetToplevelWindow(window))) |
356 FocusWindow(window); | 348 FocusWindow(window); |
357 } | 349 } |
358 | 350 |
359 } // namespace corewm | 351 } // namespace corewm |
360 } // namespace views | 352 } // namespace views |
OLD | NEW |