diff options
author | yutak@chromium.org <yutak@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-15 18:00:04 +0000 |
---|---|---|
committer | yutak@chromium.org <yutak@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-15 18:00:04 +0000 |
commit | 176c8f3187a3b956ad2ec58648e50e83762b88db (patch) | |
tree | 8706e070cab76c4b6599d1b22e952691f7442c5e /views | |
parent | d9fa25b165cfbc788d30f44d0d450f804a791aec (diff) | |
download | chromium_src-176c8f3187a3b956ad2ec58648e50e83762b88db.zip chromium_src-176c8f3187a3b956ad2ec58648e50e83762b88db.tar.gz chromium_src-176c8f3187a3b956ad2ec58648e50e83762b88db.tar.bz2 |
Fix focus traversal cycle.
This change makes traversal order of focus cycle consistent between forward and backward traversal. This is a partial fix for issue 6785.
BUG=http://crbug.com/6785
TEST=Move the focus to the find bar, and push [Shift]+[Tab]. The focus should not cycle inside the find bar, but go out to the omnibox (or somewhere outside the find bar).
Review URL: http://codereview.chromium.org/125130
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18402 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/focus/focus_manager.cc | 34 | ||||
-rw-r--r-- | views/focus/focus_manager.h | 3 | ||||
-rw-r--r-- | views/focus/focus_manager_unittest.cc | 14 |
3 files changed, 11 insertions, 40 deletions
diff --git a/views/focus/focus_manager.cc b/views/focus/focus_manager.cc index abbc456..f4b67ff 100644 --- a/views/focus/focus_manager.cc +++ b/views/focus/focus_manager.cc @@ -413,37 +413,19 @@ View* FocusManager::GetNextFocusableView(View* original_starting_view, parent_focus_traversable->GetFocusTraversableParent(); } - if (!dont_loop) { - // If we get here, we have reached the end of the focus hierarchy, let's - // loop. - if (reverse) { - // When reversing from the top, the next focusable view is at the end - // of the focus hierarchy. - return FindLastFocusableView(); - } else { - // Easy, just clear the selection and press tab again. - if (original_starting_view) { // Make sure there was at least a view to - // start with, to prevent infinitely - // looping in empty windows. - // By calling with NULL as the starting view, we'll start from the - // top_root_view. - return GetNextFocusableView(NULL, false, true); - } - } + // If we get here, we have reached the end of the focus hierarchy, let's + // loop. Make sure there was at least a view to start with, to prevent + // infinitely looping in empty windows. + if (!dont_loop && original_starting_view) { + // Easy, just clear the selection and press tab again. + // By calling with NULL as the starting view, we'll start from the + // top_root_view. + return GetNextFocusableView(NULL, reverse, true); } } return NULL; } -View* FocusManager::FindLastFocusableView() { - // Just walk the entire focus loop from where we're at until we reach the end. - View* new_focused = NULL; - View* last_focused = focused_view_; - while ((new_focused = GetNextFocusableView(last_focused, false, true))) - last_focused = new_focused; - return last_focused; -} - void FocusManager::SetFocusedView(View* view) { if (focused_view_ != view) { View* prev_focused_view = focused_view_; diff --git a/views/focus/focus_manager.h b/views/focus/focus_manager.h index 59e9b3b..fb48188 100644 --- a/views/focus/focus_manager.h +++ b/views/focus/focus_manager.h @@ -299,9 +299,6 @@ class FocusManager { // Returns the next focusable view. View* GetNextFocusableView(View* starting_view, bool reverse, bool dont_loop); - // Returns the last view of the focus traversal hierarchy. - View* FindLastFocusableView(); - // Returns the focusable view found in the FocusTraversable specified starting // at the specified view. This traverses down along the FocusTraversable // hierarchy. diff --git a/views/focus/focus_manager_unittest.cc b/views/focus/focus_manager_unittest.cc index 4821112..cc56271 100644 --- a/views/focus/focus_manager_unittest.cc +++ b/views/focus/focus_manager_unittest.cc @@ -885,11 +885,8 @@ TEST_F(FocusTraversalTest, NormalTraversal) { } } - // Focus the 1st item. - GetFocusManager()->SetFocusedView( - content_view_->GetViewByID(kTraversalIDs[0])); - // Let's traverse in reverse order. + GetFocusManager()->SetFocusedView(NULL); for (int i = 0; i < 3; ++i) { for (int j = arraysize(kTraversalIDs) - 1; j >= 0; --j) { GetFocusManager()->AdvanceFocus(true); @@ -931,6 +928,7 @@ TEST_F(FocusTraversalTest, TraversalWithNonEnabledViews) { View* focused_view; // Let's do one traversal (several times, to make sure it loops ok). + GetFocusManager()->SetFocusedView(NULL); for (int i = 0; i < 3; ++i) { for (int j = 0; j < arraysize(kTraversalIDs); j++) { GetFocusManager()->AdvanceFocus(false); @@ -941,14 +939,8 @@ TEST_F(FocusTraversalTest, TraversalWithNonEnabledViews) { } } - // Focus the 1st item. - GetFocusManager()->AdvanceFocus(false); - focused_view = GetFocusManager()->GetFocusedView(); - EXPECT_TRUE(focused_view != NULL); - if (focused_view) - EXPECT_EQ(kTraversalIDs[0], focused_view->GetID()); - // Same thing in reverse. + GetFocusManager()->SetFocusedView(NULL); for (int i = 0; i < 3; ++i) { for (int j = arraysize(kTraversalIDs) - 1; j >= 0; --j) { GetFocusManager()->AdvanceFocus(true); |