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

Side by Side Diff: ui/views/focus/focus_manager.cc

Issue 108063004: Give up focus if the focused view becomes unfocusable (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Return early if not focused Created 6 years, 4 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/views/focus/focus_manager.h" 5 #include "ui/views/focus/focus_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 350
351 void FocusManager::ClearFocus() { 351 void FocusManager::ClearFocus() {
352 // SetFocusedView(NULL) is going to clear out the stored view to. We need to 352 // SetFocusedView(NULL) is going to clear out the stored view to. We need to
353 // persist it in this case. 353 // persist it in this case.
354 views::View* focused_view = GetStoredFocusView(); 354 views::View* focused_view = GetStoredFocusView();
355 SetFocusedView(NULL); 355 SetFocusedView(NULL);
356 ClearNativeFocus(); 356 ClearNativeFocus();
357 SetStoredFocusView(focused_view); 357 SetStoredFocusView(focused_view);
358 } 358 }
359 359
360 void FocusManager::AdvanceFocusIfNecessary() {
361 // If widget is inactive, there is no focused view to check. The stored view
362 // will also be checked for focusability when it is being restored.
363 if (!widget_->IsActive())
364 return;
365
366 // If widget is active and focused view is not focusable, advance focus or,
367 // if not possible, clear focus.
368 if (focused_view_ && !focused_view_->IsAccessibilityFocusable()) {
369 AdvanceFocus(false);
370 if (focused_view_ && !focused_view_->IsAccessibilityFocusable())
371 ClearFocus();
372 }
373 }
374
360 void FocusManager::StoreFocusedView(bool clear_native_focus) { 375 void FocusManager::StoreFocusedView(bool clear_native_focus) {
361 View* focused_view = focused_view_; 376 View* focused_view = focused_view_;
362 // Don't do anything if no focused view. Storing the view (which is NULL), in 377 // Don't do anything if no focused view. Storing the view (which is NULL), in
363 // this case, would clobber the view that was previously saved. 378 // this case, would clobber the view that was previously saved.
364 if (!focused_view_) 379 if (!focused_view_)
365 return; 380 return;
366 381
367 View* v = focused_view_; 382 View* v = focused_view_;
368 383
369 if (clear_native_focus) { 384 if (clear_native_focus) {
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 } 600 }
586 if (key_code == ui::VKEY_RIGHT || key_code == ui::VKEY_DOWN) { 601 if (key_code == ui::VKEY_RIGHT || key_code == ui::VKEY_DOWN) {
587 AdvanceFocus(false); 602 AdvanceFocus(false);
588 return true; 603 return true;
589 } 604 }
590 605
591 return false; 606 return false;
592 } 607 }
593 608
594 } // namespace views 609 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/focus/focus_manager.h ('k') | ui/views/view.h » ('j') | ui/views/view.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698