diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-09 02:21:02 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-09 02:21:02 +0000 |
commit | 26c53e661daf5f1a0146aab1ed50bdfbf9b847fc (patch) | |
tree | eb787bd6caa44d04031802cabd1d47b3d7cc2704 /chrome/browser | |
parent | 8805cbef87330f44a2cf913ab05e8962f6adef84 (diff) | |
download | chromium_src-26c53e661daf5f1a0146aab1ed50bdfbf9b847fc.zip chromium_src-26c53e661daf5f1a0146aab1ed50bdfbf9b847fc.tar.gz chromium_src-26c53e661daf5f1a0146aab1ed50bdfbf9b847fc.tar.bz2 |
Move focus from the omnibox when opening a new tab with alt-enter.
BUG=2538
TEST=BrowserNavigatorTest.NavigateFromOmniboxIntoNewTab
Review URL: http://codereview.chromium.org/7312020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91941 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_edit.h | 2 | ||||
-rw-r--r-- | chrome/browser/ui/browser_navigator.cc | 9 | ||||
-rw-r--r-- | chrome/browser/ui/browser_navigator_browsertest.cc | 42 |
3 files changed, 53 insertions, 0 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit.h b/chrome/browser/autocomplete/autocomplete_edit.h index 171a716..5bd9ce2 100644 --- a/chrome/browser/autocomplete/autocomplete_edit.h +++ b/chrome/browser/autocomplete/autocomplete_edit.h @@ -117,6 +117,8 @@ class AutocompleteEditModel : public AutocompleteControllerDelegate { // making this accessor unnecessary. AutocompletePopupModel* popup_model() const { return popup_; } + AutocompleteEditController* controller() const { return controller_; } + // Invoked when the profile has changed. void SetProfile(Profile* profile); diff --git a/chrome/browser/ui/browser_navigator.cc b/chrome/browser/ui/browser_navigator.cc index 495d4e4..81ae69b 100644 --- a/chrome/browser/ui/browser_navigator.cc +++ b/chrome/browser/ui/browser_navigator.cc @@ -453,6 +453,15 @@ void Navigate(NavigateParams* params) { // add it to the appropriate tabstrip. } + // If the user navigated from the omnibox, and the selected tab is going to + // lose focus, then make sure the focus for the source tab goes away from the + // omnibox. + if (params->source_contents && + (params->disposition == NEW_FOREGROUND_TAB || + params->disposition == NEW_WINDOW) && + (params->tabstrip_add_types & TabStripModel::ADD_INHERIT_OPENER)) + params->source_contents->tab_contents()->Focus(); + if (params->source_contents == params->target_contents) { // The navigation occurred in the source tab. params->browser->UpdateUIForNavigationInTab( diff --git a/chrome/browser/ui/browser_navigator_browsertest.cc b/chrome/browser/ui/browser_navigator_browsertest.cc index a6dd316..21c3315 100644 --- a/chrome/browser/ui/browser_navigator_browsertest.cc +++ b/chrome/browser/ui/browser_navigator_browsertest.cc @@ -5,11 +5,15 @@ #include "chrome/browser/ui/browser_navigator_browsertest.h" #include "base/command_line.h" +#include "chrome/app/chrome_command_ids.h" +#include "chrome/browser/autocomplete/autocomplete_edit.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_navigator.h" #include "chrome/browser/ui/browser_window.h" +#include "chrome/browser/ui/omnibox/location_bar.h" +#include "chrome/browser/ui/omnibox/omnibox_view.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/common/chrome_switches.h" #include "chrome/test/ui_test_utils.h" @@ -988,4 +992,42 @@ IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, browser()->GetSelectedTabContents()->GetURL()); } +// Tests that when a new tab is opened from the omnibox, the focus is moved from +// the omnibox for the current tab. +IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, + NavigateFromOmniboxIntoNewTab) { + GURL url("http://www.google.com/"); + GURL url2("http://maps.google.com/"); + + // Navigate to url. + browser::NavigateParams p(MakeNavigateParams()); + p.disposition = CURRENT_TAB; + p.url = url; + browser::Navigate(&p); + + // Focus the omnibox. + browser()->FocusLocationBar(); + + AutocompleteEditController* controller = + browser()->window()->GetLocationBar()->location_entry()->model()-> + controller(); + + // Simulate an alt-enter. + controller->OnAutocompleteAccept(url2, NEW_FOREGROUND_TAB, + PageTransition::TYPED, GURL()); + + // Make sure the second tab is selected. + EXPECT_EQ(1, browser()->active_index()); + + // The tab contents should have the focus in the second tab. + EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), + VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + + // Go back to the first tab. The focus should not be in the omnibox. + browser()->SelectPreviousTab(); + EXPECT_EQ(0, browser()->active_index()); + EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), + VIEW_ID_LOCATION_BAR)); +} + } // namespace |