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

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

Issue 20347: Fix some focus traversal issues:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 10 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 | « no previous file | no next file » | 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 <algorithm> 5 #include <algorithm>
6 6
7 #include "base/histogram.h" 7 #include "base/histogram.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/win_util.h" 9 #include "base/win_util.h"
10 #include "chrome/browser/renderer_host/render_widget_host_view_win.h" 10 #include "chrome/browser/renderer_host/render_widget_host_view_win.h"
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 while (window) { 462 while (window) {
463 if (window == root_) 463 if (window == root_)
464 return true; 464 return true;
465 window = ::GetParent(window); 465 window = ::GetParent(window);
466 } 466 }
467 return false; 467 return false;
468 } 468 }
469 469
470 void FocusManager::AdvanceFocus(bool reverse) { 470 void FocusManager::AdvanceFocus(bool reverse) {
471 View* v = GetNextFocusableView(focused_view_, reverse, false); 471 View* v = GetNextFocusableView(focused_view_, reverse, false);
472 if (v && (v != focused_view_)) { 472 // Note: Do not skip this next block when v == focused_view_. If the user
473 // tabs past the last focusable element in a webpage, we'll get here, and if
474 // the TabContentsContainerView is the only focusable view (possible in
475 // fullscreen mode), we need to run this block in order to cycle around to the
476 // first element on the page.
477 if (v) {
473 v->AboutToRequestFocusFromTabTraversal(reverse); 478 v->AboutToRequestFocusFromTabTraversal(reverse);
474 v->RequestFocus(); 479 v->RequestFocus();
475 } 480 }
476 } 481 }
477 482
478 View* FocusManager::GetNextFocusableView(View* original_starting_view, 483 View* FocusManager::GetNextFocusableView(View* original_starting_view,
479 bool reverse, 484 bool reverse,
480 bool dont_loop) { 485 bool dont_loop) {
481 FocusTraversable* focus_traversable = NULL; 486 FocusTraversable* focus_traversable = NULL;
482 487
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 // top_root_view. 551 // top_root_view.
547 return GetNextFocusableView(NULL, false, true); 552 return GetNextFocusableView(NULL, false, true);
548 } 553 }
549 } 554 }
550 } 555 }
551 } 556 }
552 return NULL; 557 return NULL;
553 } 558 }
554 559
555 View* FocusManager::FindLastFocusableView() { 560 View* FocusManager::FindLastFocusableView() {
556 // For now we'll just walk the entire focus loop until we reach the end. 561 // Just walk the entire focus loop from where we're at until we reach the end.
557
558 // Let's start at whatever focused view we are at.
559 View* starting_view = focused_view_;
560
561 // Now advance until you reach the end.
562 View* new_focused = NULL; 562 View* new_focused = NULL;
563 View* last_focused = NULL; 563 View* last_focused = focused_view_;
564 while (new_focused = GetNextFocusableView(starting_view, false, true)) { 564 while (new_focused = GetNextFocusableView(last_focused, false, true))
565 last_focused = new_focused; 565 last_focused = new_focused;
566 starting_view = new_focused;
567 }
568 return last_focused; 566 return last_focused;
569 } 567 }
570 568
571 void FocusManager::SetFocusedView(View* view) { 569 void FocusManager::SetFocusedView(View* view) {
572 if (focused_view_ != view) { 570 if (focused_view_ != view) {
573 View* prev_focused_view = focused_view_; 571 View* prev_focused_view = focused_view_;
574 if (focused_view_) 572 if (focused_view_)
575 focused_view_->WillLoseFocus(); 573 focused_view_->WillLoseFocus();
576 574
577 if (view) 575 if (view)
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 listener); 830 listener);
833 if (place == focus_change_listeners_.end()) { 831 if (place == focus_change_listeners_.end()) {
834 NOTREACHED() << "Removing a listener that isn't registered."; 832 NOTREACHED() << "Removing a listener that isn't registered.";
835 return; 833 return;
836 } 834 }
837 focus_change_listeners_.erase(place); 835 focus_change_listeners_.erase(place);
838 } 836 }
839 837
840 } // namespace views 838 } // namespace views
841 839
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698