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

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

Issue 125130: Fix focus traversal cycle. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 6 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
« no previous file with comments | « views/focus/focus_manager.h ('k') | views/focus/focus_manager_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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "views/focus/focus_manager.h" 5 #include "views/focus/focus_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 10
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 } 406 }
407 407
408 if (v) 408 if (v)
409 return v; 409 return v;
410 410
411 starting_view = focus_traversable->GetFocusTraversableParentView(); 411 starting_view = focus_traversable->GetFocusTraversableParentView();
412 parent_focus_traversable = 412 parent_focus_traversable =
413 parent_focus_traversable->GetFocusTraversableParent(); 413 parent_focus_traversable->GetFocusTraversableParent();
414 } 414 }
415 415
416 if (!dont_loop) { 416 // If we get here, we have reached the end of the focus hierarchy, let's
417 // If we get here, we have reached the end of the focus hierarchy, let's 417 // loop. Make sure there was at least a view to start with, to prevent
418 // loop. 418 // infinitely looping in empty windows.
419 if (reverse) { 419 if (!dont_loop && original_starting_view) {
420 // When reversing from the top, the next focusable view is at the end 420 // Easy, just clear the selection and press tab again.
421 // of the focus hierarchy. 421 // By calling with NULL as the starting view, we'll start from the
422 return FindLastFocusableView(); 422 // top_root_view.
423 } else { 423 return GetNextFocusableView(NULL, reverse, true);
424 // Easy, just clear the selection and press tab again.
425 if (original_starting_view) { // Make sure there was at least a view to
426 // start with, to prevent infinitely
427 // looping in empty windows.
428 // By calling with NULL as the starting view, we'll start from the
429 // top_root_view.
430 return GetNextFocusableView(NULL, false, true);
431 }
432 }
433 } 424 }
434 } 425 }
435 return NULL; 426 return NULL;
436 } 427 }
437 428
438 View* FocusManager::FindLastFocusableView() {
439 // Just walk the entire focus loop from where we're at until we reach the end.
440 View* new_focused = NULL;
441 View* last_focused = focused_view_;
442 while ((new_focused = GetNextFocusableView(last_focused, false, true)))
443 last_focused = new_focused;
444 return last_focused;
445 }
446
447 void FocusManager::SetFocusedView(View* view) { 429 void FocusManager::SetFocusedView(View* view) {
448 if (focused_view_ != view) { 430 if (focused_view_ != view) {
449 View* prev_focused_view = focused_view_; 431 View* prev_focused_view = focused_view_;
450 if (focused_view_) 432 if (focused_view_)
451 focused_view_->WillLoseFocus(); 433 focused_view_->WillLoseFocus();
452 434
453 if (view) 435 if (view)
454 view->WillGainFocus(); 436 view->WillGainFocus();
455 437
456 // Notified listeners that the focus changed. 438 // Notified listeners that the focus changed.
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 std::find(focus_change_listeners_.begin(), focus_change_listeners_.end(), 692 std::find(focus_change_listeners_.begin(), focus_change_listeners_.end(),
711 listener); 693 listener);
712 if (place == focus_change_listeners_.end()) { 694 if (place == focus_change_listeners_.end()) {
713 NOTREACHED() << "Removing a listener that isn't registered."; 695 NOTREACHED() << "Removing a listener that isn't registered.";
714 return; 696 return;
715 } 697 }
716 focus_change_listeners_.erase(place); 698 focus_change_listeners_.erase(place);
717 } 699 }
718 700
719 } // namespace views 701 } // namespace views
OLDNEW
« no previous file with comments | « views/focus/focus_manager.h ('k') | views/focus/focus_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698