diff options
49 files changed, 94 insertions, 89 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_browsertest.cc b/chrome/browser/autocomplete/autocomplete_browsertest.cc index f54e535..ba77285 100644 --- a/chrome/browser/autocomplete/autocomplete_browsertest.cc +++ b/chrome/browser/autocomplete/autocomplete_browsertest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -62,7 +62,7 @@ IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, Basic) { // TODO(phajdan.jr): check state of IsSelectAll when it's consistent across // platforms. - location_bar->FocusLocation(); + location_bar->FocusLocation(true); EXPECT_EQ(std::wstring(), location_bar->GetInputString()); EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.h b/chrome/browser/autocomplete/autocomplete_edit_view_mac.h index 11bb62f..4cf7aee 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.h +++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -91,8 +91,8 @@ class AutocompleteEditViewMac : public AutocompleteEditView, virtual void OnDidEndEditing(); virtual bool OnDoCommandBySelector(SEL cmd); - // Helper for LocationBarViewMac. Selects all in |field_|. - void FocusLocation(); + // Helper for LocationBarViewMac. Optionally selects all in |field_|. + void FocusLocation(bool select_all); // Helper to get appropriate contents from |clipboard|. Returns // empty string if no appropriate data is found on |clipboard|. diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm index 81a3daf..e337744 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm +++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm @@ -316,7 +316,7 @@ void AutocompleteEditViewMac::SetWindowTextAndCaretPos(const std::wstring& text, void AutocompleteEditViewMac::SetForcedQuery() { // We need to do this first, else |SetSelectedRange()| won't work. - FocusLocation(); + FocusLocation(true); const std::wstring current_text(GetText()); if (current_text.empty() || (current_text[0] != '?')) { @@ -825,7 +825,9 @@ void AutocompleteEditViewMac::OnControlKeyChanged(bool pressed) { model_->OnControlKeyChanged(pressed); } -void AutocompleteEditViewMac::FocusLocation() { +void AutocompleteEditViewMac::FocusLocation(bool select_all) { + // TODO(pkasting): Figure out Mac's weird focus-handling and do the right + // thing here :( if ([field_ isEditable]) { [[field_ window] makeFirstResponder:field_]; DCHECK_EQ([field_ currentEditor], [[field_ window] firstResponder]); diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index 5d9495f..98d2166 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -1371,7 +1371,7 @@ void Browser::FocusPageAndAppMenus() { void Browser::FocusLocationBar() { UserMetrics::RecordAction(UserMetricsAction("FocusLocation"), profile_); - window_->SetFocusToLocationBar(); + window_->SetFocusToLocationBar(true); } void Browser::FocusSearch() { @@ -2474,7 +2474,7 @@ void Browser::ShowHtmlDialog(HtmlDialogUIDelegate* delegate, window_->ShowHTMLDialog(delegate, parent_window); } -void Browser::SetFocusToLocationBar() { +void Browser::SetFocusToLocationBar(bool select_all) { // Two differences between this and FocusLocationBar(): // (1) This doesn't get recorded in user metrics, since it's called // internally. @@ -2482,7 +2482,7 @@ void Browser::SetFocusToLocationBar() { // the focus. FocusLocationBar() is only reached when the location bar is // focusable, but this may be reached at other times, e.g. while in // fullscreen mode, where we need to leave focus in a consistent state. - window_->SetFocusToLocationBar(); + window_->SetFocusToLocationBar(select_all); } void Browser::RenderWidgetShowing() { diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h index 67d940c..c293e97f 100644 --- a/chrome/browser/browser.h +++ b/chrome/browser/browser.h @@ -455,7 +455,7 @@ class Browser : public TabStripModelDelegate, // Focus various bits of UI void FocusToolbar(); - void FocusLocationBar(); + void FocusLocationBar(); // Also selects any existing text. void FocusSearch(); void FocusPageAndAppMenus(); @@ -663,7 +663,7 @@ class Browser : public TabStripModelDelegate, virtual void BeforeUnloadFired(TabContents* source, bool proceed, bool* proceed_to_fire_unload); - virtual void SetFocusToLocationBar(); + virtual void SetFocusToLocationBar(bool select_all); virtual void RenderWidgetShowing(); virtual int GetExtraRenderViewHeight() const; virtual void OnStartDownload(DownloadItem* download); diff --git a/chrome/browser/browser_window.h b/chrome/browser/browser_window.h index e0d7001..c4ff0c77a 100644 --- a/chrome/browser/browser_window.h +++ b/chrome/browser/browser_window.h @@ -129,7 +129,7 @@ class BrowserWindow { // Tries to focus the location bar. Clears the window focus (to avoid // inconsistent state) if this fails. - virtual void SetFocusToLocationBar() = 0; + virtual void SetFocusToLocationBar(bool select_all) = 0; // Informs the view whether or not a load is in progress for the current tab. // The view can use this notification to update the go/stop button. diff --git a/chrome/browser/chromeos/compact_location_bar_host.cc b/chrome/browser/chromeos/compact_location_bar_host.cc index a412cb6..1806421 100644 --- a/chrome/browser/chromeos/compact_location_bar_host.cc +++ b/chrome/browser/chromeos/compact_location_bar_host.cc @@ -185,7 +185,7 @@ void CompactLocationBarHost::TabSelectedAt(TabContents* old_contents, bool user_gesture) { if (user_gesture) { // Show the compact location bar only when a user selected the tab. - Update(index, false); + Update(index, false, true); } else { Hide(false); } @@ -194,7 +194,7 @@ void CompactLocationBarHost::TabSelectedAt(TabContents* old_contents, void CompactLocationBarHost::TabMoved(TabContents* contents, int from_index, int to_index) { - Update(to_index, false); + Update(to_index, false, true); } void CompactLocationBarHost::TabChangedAt(TabContents* contents, int index, @@ -242,7 +242,9 @@ gfx::Rect CompactLocationBarHost::GetBoundsUnderTab(int index) const { return navbar_bounds.AdjustToFit(browser_view()->bounds()); } -void CompactLocationBarHost::Update(int index, bool animate_x) { +void CompactLocationBarHost::Update(int index, + bool animate_x, + bool select_all) { DCHECK_GE(index, 0); if (IsCurrentTabIndex(index) && IsVisible()) { return; @@ -252,7 +254,7 @@ void CompactLocationBarHost::Update(int index, bool animate_x) { bool animate = !animation()->IsShowing(); Hide(false); GetClbView()->Update(browser_view()->browser()->GetSelectedTabContents()); - GetClbView()->SetFocusAndSelection(); + GetClbView()->SetFocusAndSelection(select_all); Show(animate && animate_x); } diff --git a/chrome/browser/chromeos/compact_location_bar_host.h b/chrome/browser/chromeos/compact_location_bar_host.h index e6816fc..5b59afa 100644 --- a/chrome/browser/chromeos/compact_location_bar_host.h +++ b/chrome/browser/chromeos/compact_location_bar_host.h @@ -50,7 +50,7 @@ class CompactLocationBarHost : public DropdownBarHost, // |index| is the index of the tab the compact location bar // will be attached to and |animate| specifies if the location bar // should animate when shown. - void Update(int index, bool animate); + void Update(int index, bool animate, bool select_all); // (Re)Starts the popup timer that hides the popup after X seconds. void StartAutoHideTimer(); diff --git a/chrome/browser/chromeos/compact_location_bar_view.cc b/chrome/browser/chromeos/compact_location_bar_view.cc index af803e4..93a7d2b 100644 --- a/chrome/browser/chromeos/compact_location_bar_view.cc +++ b/chrome/browser/chromeos/compact_location_bar_view.cc @@ -62,9 +62,10 @@ CompactLocationBarView::~CompactLocationBarView() { //////////////////////////////////////////////////////////////////////////////// // CompactLocationBarView public: -void CompactLocationBarView::SetFocusAndSelection() { +void CompactLocationBarView::SetFocusAndSelection(bool select_all) { location_entry_->SetFocus(); - location_entry_->SelectAll(true); + if (select_all) + location_entry_->SelectAll(true); } void CompactLocationBarView::Update(const TabContents* contents) { diff --git a/chrome/browser/chromeos/compact_location_bar_view.h b/chrome/browser/chromeos/compact_location_bar_view.h index e4f8d73..889a630 100644 --- a/chrome/browser/chromeos/compact_location_bar_view.h +++ b/chrome/browser/chromeos/compact_location_bar_view.h @@ -42,8 +42,8 @@ class CompactLocationBarView : public DropdownBarView, explicit CompactLocationBarView(CompactLocationBarHost* host); ~CompactLocationBarView(); - // Claims focus for the text field and selects its contents. - virtual void SetFocusAndSelection(); + // Claims focus for the text field and optionally selects its contents. + virtual void SetFocusAndSelection(bool select_all); void Update(const TabContents* contents); diff --git a/chrome/browser/chromeos/frame/browser_view.cc b/chrome/browser/chromeos/frame/browser_view.cc index 254be1d..bf2dac7 100644 --- a/chrome/browser/chromeos/frame/browser_view.cc +++ b/chrome/browser/chromeos/frame/browser_view.cc @@ -84,7 +84,7 @@ class ChromeosTab : public Tab { // Overridden from views::View. virtual void OnMouseEntered(const views::MouseEvent& event) { TabRenderer::OnMouseEntered(event); - browser_view_->ShowCompactLocationBarUnderSelectedTab(); + browser_view_->ShowCompactLocationBarUnderSelectedTab(true); } private: @@ -255,7 +255,7 @@ class BrowserViewLayout : public ::BrowserViewLayout { if (compact_navigation_bar_->IsVisible()) { // Update the size and location of the compact location bar. int index = browser_view()->browser()->selected_index(); - compact_location_bar_host_->Update(index, false); + compact_location_bar_host_->Update(index, false, true); } */ @@ -412,12 +412,11 @@ bool BrowserView::IsToolbarVisible() const { return ::BrowserView::IsToolbarVisible(); } -void BrowserView::SetFocusToLocationBar() { - if (is_compact_style()) { - ShowCompactLocationBarUnderSelectedTab(); - } else { - ::BrowserView::SetFocusToLocationBar(); - } +void BrowserView::SetFocusToLocationBar(bool select_all) { + if (is_compact_style()) + ShowCompactLocationBarUnderSelectedTab(select_all); + else + ::BrowserView::SetFocusToLocationBar(select_all); } void BrowserView::ToggleCompactNavigationBar() { @@ -516,11 +515,11 @@ bool BrowserView::IsButtonVisible(const views::View* button_view) const { //////////////////////////////////////////////////////////////////////////////// // BrowserView public: -void BrowserView::ShowCompactLocationBarUnderSelectedTab() { +void BrowserView::ShowCompactLocationBarUnderSelectedTab(bool select_all) { if (!is_compact_style()) return; int index = browser()->selected_index(); - compact_location_bar_host_->Update(index, true); + compact_location_bar_host_->Update(index, true, select_all); } //////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/chromeos/frame/browser_view.h b/chrome/browser/chromeos/frame/browser_view.h index 0d3dd2a..3bdea4f 100644 --- a/chrome/browser/chromeos/frame/browser_view.h +++ b/chrome/browser/chromeos/frame/browser_view.h @@ -61,7 +61,7 @@ class BrowserView : public ::BrowserView, virtual void Init(); virtual void Show(); virtual bool IsToolbarVisible() const; - virtual void SetFocusToLocationBar(); + virtual void SetFocusToLocationBar(bool select_all); virtual void ToggleCompactNavigationBar(); virtual views::LayoutManager* CreateLayoutManager() const; virtual BaseTabStrip* CreateTabStrip(TabStripModel* tab_strip_model); @@ -86,7 +86,7 @@ class BrowserView : public ::BrowserView, virtual bool IsButtonVisible(const views::View* button_view) const; // Shows the compact location bar under the selected tab. - void ShowCompactLocationBarUnderSelectedTab(); + void ShowCompactLocationBarUnderSelectedTab(bool select_all); // Returns true if the ui style is in Compact mode. bool is_compact_style() const { diff --git a/chrome/browser/cocoa/browser_window_cocoa.h b/chrome/browser/cocoa/browser_window_cocoa.h index 753a645..b0861f1 100644 --- a/chrome/browser/cocoa/browser_window_cocoa.h +++ b/chrome/browser/cocoa/browser_window_cocoa.h @@ -52,7 +52,7 @@ class BrowserWindowCocoa : public BrowserWindow, virtual bool IsFullscreen() const; virtual bool IsFullscreenBubbleVisible() const; virtual LocationBar* GetLocationBar() const; - virtual void SetFocusToLocationBar(); + virtual void SetFocusToLocationBar(bool select_all); virtual void UpdateStopGoState(bool is_loading, bool force); virtual void UpdateToolbar(TabContents* contents, bool should_restore_state); diff --git a/chrome/browser/cocoa/browser_window_cocoa.mm b/chrome/browser/cocoa/browser_window_cocoa.mm index 186ec86..7df9ee1 100644 --- a/chrome/browser/cocoa/browser_window_cocoa.mm +++ b/chrome/browser/cocoa/browser_window_cocoa.mm @@ -205,8 +205,8 @@ LocationBar* BrowserWindowCocoa::GetLocationBar() const { return [controller_ locationBarBridge]; } -void BrowserWindowCocoa::SetFocusToLocationBar() { - [controller_ focusLocationBar]; +void BrowserWindowCocoa::SetFocusToLocationBar(bool select_all) { + [controller_ focusLocationBar:select_all ? YES : NO]; } void BrowserWindowCocoa::UpdateStopGoState(bool is_loading, bool force) { diff --git a/chrome/browser/cocoa/browser_window_controller.h b/chrome/browser/cocoa/browser_window_controller.h index 975594c..08d9c46 100644 --- a/chrome/browser/cocoa/browser_window_controller.h +++ b/chrome/browser/cocoa/browser_window_controller.h @@ -178,7 +178,7 @@ class TabStripModelObserverBridge; - (void)activate; // Make the location bar the first responder, if possible. -- (void)focusLocationBar; +- (void)focusLocationBar:(BOOL)selectAll; // Make the (currently-selected) tab contents the first responder, if possible. - (void)focusTabContents; diff --git a/chrome/browser/cocoa/browser_window_controller.mm b/chrome/browser/cocoa/browser_window_controller.mm index 101807d..f482990 100644 --- a/chrome/browser/cocoa/browser_window_controller.mm +++ b/chrome/browser/cocoa/browser_window_controller.mm @@ -1111,8 +1111,8 @@ } // Make the location bar the first responder, if possible. -- (void)focusLocationBar { - [toolbarController_ focusLocationBar]; +- (void)focusLocationBar:(BOOL)selectAll { + [toolbarController_ focusLocationBar:selectAll]; } - (void)focusTabContents { diff --git a/chrome/browser/cocoa/location_bar_view_mac.h b/chrome/browser/cocoa/location_bar_view_mac.h index 2107ec3..5a82d67 100644 --- a/chrome/browser/cocoa/location_bar_view_mac.h +++ b/chrome/browser/cocoa/location_bar_view_mac.h @@ -57,7 +57,7 @@ class LocationBarViewMac : public AutocompleteEditController, virtual PageTransition::Type GetPageTransition() const; virtual void AcceptInput(); virtual void AcceptInputWithDisposition(WindowOpenDisposition disposition); - virtual void FocusLocation(); + virtual void FocusLocation(bool select_all); virtual void FocusSearch(); virtual void UpdateContentSettingsIcons(); virtual void UpdatePageActions(); diff --git a/chrome/browser/cocoa/location_bar_view_mac.mm b/chrome/browser/cocoa/location_bar_view_mac.mm index 62b12d4..dde3095 100644 --- a/chrome/browser/cocoa/location_bar_view_mac.mm +++ b/chrome/browser/cocoa/location_bar_view_mac.mm @@ -161,8 +161,8 @@ void LocationBarViewMac::AcceptInputWithDisposition( edit_view_->model()->AcceptInput(disposition, false); } -void LocationBarViewMac::FocusLocation() { - edit_view_->FocusLocation(); +void LocationBarViewMac::FocusLocation(bool select_all) { + edit_view_->FocusLocation(select_all); } void LocationBarViewMac::FocusSearch() { diff --git a/chrome/browser/cocoa/toolbar_controller.h b/chrome/browser/cocoa/toolbar_controller.h index 3c5086b..0fdd8c4 100644 --- a/chrome/browser/cocoa/toolbar_controller.h +++ b/chrome/browser/cocoa/toolbar_controller.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -126,7 +126,7 @@ class ToolbarModel; - (id)customFieldEditorForObject:(id)obj; // Make the location bar the first responder, if possible. -- (void)focusLocationBar; +- (void)focusLocationBar:(BOOL)selectAll; // Updates the toolbar (and transitively the location bar) with the states of // the specified |tab|. If |shouldRestore| is true, we're switching diff --git a/chrome/browser/cocoa/toolbar_controller.mm b/chrome/browser/cocoa/toolbar_controller.mm index 0d12ee5..1412fc1 100644 --- a/chrome/browser/cocoa/toolbar_controller.mm +++ b/chrome/browser/cocoa/toolbar_controller.mm @@ -371,10 +371,9 @@ class PrefObserverBridge : public NotificationObserver { return locationBarView_.get(); } -- (void)focusLocationBar { - if (locationBarView_.get()) { - locationBarView_->FocusLocation(); - } +- (void)focusLocationBar:(BOOL)selectAll { + if (locationBarView_.get()) + locationBarView_->FocusLocation(selectAll ? true : false); } // Called when the state for a command changes to |enabled|. Update the diff --git a/chrome/browser/dom_ui/dom_ui_unittest.cc b/chrome/browser/dom_ui/dom_ui_unittest.cc index 0172837..51f5e1e 100644 --- a/chrome/browser/dom_ui/dom_ui_unittest.cc +++ b/chrome/browser/dom_ui/dom_ui_unittest.cc @@ -148,7 +148,7 @@ class TabContentsForFocusTest : public TestTabContents { : TestTabContents(profile, instance), focus_called_(0) { } - virtual void SetFocusToLocationBar() { ++focus_called_; } + virtual void SetFocusToLocationBar(bool select_all) { ++focus_called_; } int focus_called() const { return focus_called_; } private: diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc index 03f9228..3eba2c5 100644 --- a/chrome/browser/gtk/browser_window_gtk.cc +++ b/chrome/browser/gtk/browser_window_gtk.cc @@ -775,10 +775,9 @@ LocationBar* BrowserWindowGtk::GetLocationBar() const { return toolbar_->GetLocationBar(); } -void BrowserWindowGtk::SetFocusToLocationBar() { - if (!IsFullscreen()) { - GetLocationBar()->FocusLocation(); - } +void BrowserWindowGtk::SetFocusToLocationBar(bool select_all) { + if (!IsFullscreen()) + GetLocationBar()->FocusLocation(select_all); } void BrowserWindowGtk::UpdateStopGoState(bool is_loading, bool force) { diff --git a/chrome/browser/gtk/browser_window_gtk.h b/chrome/browser/gtk/browser_window_gtk.h index 53e58cc..2610539 100644 --- a/chrome/browser/gtk/browser_window_gtk.h +++ b/chrome/browser/gtk/browser_window_gtk.h @@ -70,7 +70,7 @@ class BrowserWindowGtk : public BrowserWindow, virtual bool IsFullscreen() const; virtual bool IsFullscreenBubbleVisible() const; virtual LocationBar* GetLocationBar() const; - virtual void SetFocusToLocationBar(); + virtual void SetFocusToLocationBar(bool select_all); virtual void UpdateStopGoState(bool is_loading, bool force); virtual void UpdateToolbar(TabContents* contents, bool should_restore_state); diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc index 453a8f54..7c0685c 100644 --- a/chrome/browser/gtk/location_bar_view_gtk.cc +++ b/chrome/browser/gtk/location_bar_view_gtk.cc @@ -543,9 +543,10 @@ void LocationBarViewGtk::AcceptInputWithDisposition( location_entry_->model()->AcceptInput(disposition, false); } -void LocationBarViewGtk::FocusLocation() { +void LocationBarViewGtk::FocusLocation(bool select_all) { location_entry_->SetFocus(); - location_entry_->SelectAll(true); + if (select_all) + location_entry_->SelectAll(true); } void LocationBarViewGtk::FocusSearch() { diff --git a/chrome/browser/gtk/location_bar_view_gtk.h b/chrome/browser/gtk/location_bar_view_gtk.h index d31655b..97ac60c6 100644 --- a/chrome/browser/gtk/location_bar_view_gtk.h +++ b/chrome/browser/gtk/location_bar_view_gtk.h @@ -97,7 +97,7 @@ class LocationBarViewGtk : public AutocompleteEditController, virtual PageTransition::Type GetPageTransition() const; virtual void AcceptInput(); virtual void AcceptInputWithDisposition(WindowOpenDisposition); - virtual void FocusLocation(); + virtual void FocusLocation(bool select_all); virtual void FocusSearch(); virtual void UpdateContentSettingsIcons(); virtual void UpdatePageActions(); diff --git a/chrome/browser/location_bar.h b/chrome/browser/location_bar.h index 7919406..a1924fc 100644 --- a/chrome/browser/location_bar.h +++ b/chrome/browser/location_bar.h @@ -44,8 +44,8 @@ class LocationBar { // Accepts the current input, overriding the disposition. virtual void AcceptInputWithDisposition(WindowOpenDisposition) = 0; - // Focuses and selects the contents of the location bar. - virtual void FocusLocation() = 0; + // Focuses the location bar. Optionally also selects its contents. + virtual void FocusLocation(bool select_all) = 0; // Clears the location bar, inserts an annoying little "?" turd and sets // focus to it. diff --git a/chrome/browser/omnibox_search_hint.cc b/chrome/browser/omnibox_search_hint.cc index 7445306..9adf9b3 100644 --- a/chrome/browser/omnibox_search_hint.cc +++ b/chrome/browser/omnibox_search_hint.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -178,7 +178,7 @@ void OmniboxSearchHint::ShowEnteringQuery() { LocationBar* location_bar = BrowserList::GetLastActive()->window()-> GetLocationBar(); AutocompleteEditView* edit_view = location_bar->location_entry(); - location_bar->FocusLocation(); + location_bar->FocusLocation(true); edit_view->SetUserText( l10n_util::GetString(IDS_OMNIBOX_SEARCH_HINT_OMNIBOX_TEXT)); edit_view->SelectAll(false); diff --git a/chrome/browser/tab_contents/render_view_host_manager.cc b/chrome/browser/tab_contents/render_view_host_manager.cc index 9c555fb..73cf51f 100644 --- a/chrome/browser/tab_contents/render_view_host_manager.cc +++ b/chrome/browser/tab_contents/render_view_host_manager.cc @@ -492,7 +492,7 @@ void RenderViewHostManager::CommitPending() { // committing above and we're done. if (!pending_render_view_host_) { if (will_focus_location_bar) - delegate_->SetFocusToLocationBar(); + delegate_->SetFocusToLocationBar(false); return; } @@ -524,7 +524,7 @@ void RenderViewHostManager::CommitPending() { delegate_->UpdateRenderViewSizeForRenderManager(); if (will_focus_location_bar) - delegate_->SetFocusToLocationBar(); + delegate_->SetFocusToLocationBar(false); else if (focus_render_view && render_view_host_->view()) render_view_host_->view()->Focus(); diff --git a/chrome/browser/tab_contents/render_view_host_manager.h b/chrome/browser/tab_contents/render_view_host_manager.h index d0e88e3..e04235d 100644 --- a/chrome/browser/tab_contents/render_view_host_manager.h +++ b/chrome/browser/tab_contents/render_view_host_manager.h @@ -66,7 +66,7 @@ class RenderViewHostManager virtual bool FocusLocationBarByDefault() = 0; // Focuses the location bar. - virtual void SetFocusToLocationBar() = 0; + virtual void SetFocusToLocationBar(bool select_all) = 0; }; // Both delegate pointers must be non-NULL and are not owned by this class. diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 998eb50..d9e96b4 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -963,9 +963,9 @@ bool TabContents::FocusLocationBarByDefault() { return false; } -void TabContents::SetFocusToLocationBar() { +void TabContents::SetFocusToLocationBar(bool select_all) { if (delegate()) - delegate()->SetFocusToLocationBar(); + delegate()->SetFocusToLocationBar(select_all); } void TabContents::AddInfoBar(InfoBarDelegate* delegate) { diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h index 91519c8..732e0d4 100644 --- a/chrome/browser/tab_contents/tab_contents.h +++ b/chrome/browser/tab_contents/tab_contents.h @@ -448,7 +448,7 @@ class TabContents : public PageNavigator, virtual bool FocusLocationBarByDefault(); // Focuses the location bar. - virtual void SetFocusToLocationBar(); + virtual void SetFocusToLocationBar(bool select_all); // Infobars ------------------------------------------------------------------ diff --git a/chrome/browser/tab_contents/tab_contents_delegate.h b/chrome/browser/tab_contents/tab_contents_delegate.h index c219c72..eb26827 100644 --- a/chrome/browser/tab_contents/tab_contents_delegate.h +++ b/chrome/browser/tab_contents/tab_contents_delegate.h @@ -169,7 +169,7 @@ class TabContentsDelegate : public AutomationResourceRoutingDelegate { // Sets focus to the location bar or some other place that is appropriate. // This is called when the tab wants to encourage user input, like for the // new tab page. - virtual void SetFocusToLocationBar() {} + virtual void SetFocusToLocationBar(bool select_all) {} // Called when a popup select is about to be displayed. The delegate can use // this to disable inactive rendering for the frame in the window the select diff --git a/chrome/browser/tab_contents/tab_contents_view_gtk.cc b/chrome/browser/tab_contents/tab_contents_view_gtk.cc index c5db5c0..d6bcede 100644 --- a/chrome/browser/tab_contents/tab_contents_view_gtk.cc +++ b/chrome/browser/tab_contents/tab_contents_view_gtk.cc @@ -257,7 +257,7 @@ void TabContentsViewGtk::Focus() { void TabContentsViewGtk::SetInitialFocus() { if (tab_contents()->FocusLocationBarByDefault()) - tab_contents()->SetFocusToLocationBar(); + tab_contents()->SetFocusToLocationBar(false); else Focus(); } diff --git a/chrome/browser/tab_contents/tab_contents_view_mac.mm b/chrome/browser/tab_contents/tab_contents_view_mac.mm index 65b27f5..495ac24 100644 --- a/chrome/browser/tab_contents/tab_contents_view_mac.mm +++ b/chrome/browser/tab_contents/tab_contents_view_mac.mm @@ -191,7 +191,7 @@ void TabContentsViewMac::Focus() { void TabContentsViewMac::SetInitialFocus() { if (tab_contents()->FocusLocationBarByDefault()) - tab_contents()->SetFocusToLocationBar(); + tab_contents()->SetFocusToLocationBar(false); else [[cocoa_view_.get() window] makeFirstResponder:GetContentNativeView()]; } diff --git a/chrome/browser/views/accessible_toolbar_view.cc b/chrome/browser/views/accessible_toolbar_view.cc index a7e8f1b..fead6c0 100644 --- a/chrome/browser/views/accessible_toolbar_view.cc +++ b/chrome/browser/views/accessible_toolbar_view.cc @@ -258,6 +258,6 @@ void AccessibleToolbarView::SetFocusToLastFocusedView() { BrowserView* browser_view = static_cast<BrowserView*>(view); // Force the focus to be set on the location bar. - browser_view->SetFocusToLocationBar(); + browser_view->SetFocusToLocationBar(false); } } diff --git a/chrome/browser/views/dropdown_bar_host.cc b/chrome/browser/views/dropdown_bar_host.cc index 963a81e..e16074c 100644 --- a/chrome/browser/views/dropdown_bar_host.cc +++ b/chrome/browser/views/dropdown_bar_host.cc @@ -88,7 +88,7 @@ void DropdownBarHost::Show(bool animate) { } void DropdownBarHost::SetFocusAndSelection() { - view_->SetFocusAndSelection(); + view_->SetFocusAndSelection(true); } bool DropdownBarHost::IsAnimating() const { diff --git a/chrome/browser/views/dropdown_bar_view.h b/chrome/browser/views/dropdown_bar_view.h index 21bd64d..dbae978 100644 --- a/chrome/browser/views/dropdown_bar_view.h +++ b/chrome/browser/views/dropdown_bar_view.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -24,7 +24,7 @@ class DropdownBarView : public views::View { virtual ~DropdownBarView() {} // Claims focus for the text field and selects its contents. - virtual void SetFocusAndSelection() = 0; + virtual void SetFocusAndSelection(bool select_all) = 0; // Updates the view to let it know where the host is clipping the // dropdown widget (while animating the opening or closing of the widget). diff --git a/chrome/browser/views/find_bar_view.cc b/chrome/browser/views/find_bar_view.cc index 9f1700b..7e15345 100644 --- a/chrome/browser/views/find_bar_view.cc +++ b/chrome/browser/views/find_bar_view.cc @@ -210,9 +210,9 @@ void FindBarView::UpdateForResult(const FindNotificationDetails& result, SchedulePaint(); } -void FindBarView::SetFocusAndSelection() { +void FindBarView::SetFocusAndSelection(bool select_all) { find_text_->RequestFocus(); - if (!find_text_->text().empty()) + if (select_all && !find_text_->text().empty()) find_text_->SelectAll(); } diff --git a/chrome/browser/views/find_bar_view.h b/chrome/browser/views/find_bar_view.h index 74f23d0..fbfdc8a 100644 --- a/chrome/browser/views/find_bar_view.h +++ b/chrome/browser/views/find_bar_view.h @@ -52,7 +52,7 @@ class FindBarView : public DropdownBarView, const string16& find_text); // Claims focus for the text field and selects its contents. - virtual void SetFocusAndSelection(); + virtual void SetFocusAndSelection(bool select_all); // Overridden from views::View: virtual void Paint(gfx::Canvas* canvas); diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc index cc77bc6..732a1fb 100644 --- a/chrome/browser/views/frame/browser_view.cc +++ b/chrome/browser/views/frame/browser_view.cc @@ -835,11 +835,11 @@ LocationBar* BrowserView::GetLocationBar() const { return toolbar_->location_bar(); } -void BrowserView::SetFocusToLocationBar() { +void BrowserView::SetFocusToLocationBar(bool select_all) { LocationBarView* location_bar = toolbar_->location_bar(); if (location_bar->IsFocusable()) { // Location bar got focus. - location_bar->FocusLocation(); + location_bar->FocusLocation(select_all); } else { // If none of location bar/compact navigation bar got focus, // then clear focus. diff --git a/chrome/browser/views/frame/browser_view.h b/chrome/browser/views/frame/browser_view.h index 1e5b361..94ccafe 100644 --- a/chrome/browser/views/frame/browser_view.h +++ b/chrome/browser/views/frame/browser_view.h @@ -264,7 +264,7 @@ class BrowserView : public BrowserBubbleHost, virtual void SetFullscreen(bool fullscreen); virtual bool IsFullscreen() const; virtual LocationBar* GetLocationBar() const; - virtual void SetFocusToLocationBar(); + virtual void SetFocusToLocationBar(bool select_all); virtual void UpdateStopGoState(bool is_loading, bool force); virtual void UpdateToolbar(TabContents* contents, bool should_restore_state); virtual void FocusToolbar(); diff --git a/chrome/browser/views/location_bar_view.cc b/chrome/browser/views/location_bar_view.cc index b9e36d5..7a1e4d9 100644 --- a/chrome/browser/views/location_bar_view.cc +++ b/chrome/browser/views/location_bar_view.cc @@ -1659,9 +1659,10 @@ void LocationBarView::AcceptInputWithDisposition(WindowOpenDisposition disp) { location_entry_->model()->AcceptInput(disp, false); } -void LocationBarView::FocusLocation() { +void LocationBarView::FocusLocation(bool select_all) { location_entry_->SetFocus(); - location_entry_->SelectAll(true); + if (select_all) + location_entry_->SelectAll(true); } void LocationBarView::FocusSearch() { diff --git a/chrome/browser/views/location_bar_view.h b/chrome/browser/views/location_bar_view.h index faf2bfc..681a015 100644 --- a/chrome/browser/views/location_bar_view.h +++ b/chrome/browser/views/location_bar_view.h @@ -165,7 +165,7 @@ class LocationBarView : public LocationBar, virtual PageTransition::Type GetPageTransition() const; virtual void AcceptInput(); virtual void AcceptInputWithDisposition(WindowOpenDisposition); - virtual void FocusLocation(); + virtual void FocusLocation(bool select_all); virtual void FocusSearch(); virtual void UpdateContentSettingsIcons(); virtual void UpdatePageActions(); diff --git a/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc b/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc index b8d2907..2d83fa7 100644 --- a/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc +++ b/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc @@ -267,7 +267,7 @@ void TabContentsViewGtk::Focus() { void TabContentsViewGtk::SetInitialFocus() { if (tab_contents()->FocusLocationBarByDefault()) - tab_contents()->SetFocusToLocationBar(); + tab_contents()->SetFocusToLocationBar(false); else Focus(); } diff --git a/chrome/browser/views/tab_contents/tab_contents_view_win.cc b/chrome/browser/views/tab_contents/tab_contents_view_win.cc index 0592cc2..9086d49 100644 --- a/chrome/browser/views/tab_contents/tab_contents_view_win.cc +++ b/chrome/browser/views/tab_contents/tab_contents_view_win.cc @@ -202,7 +202,7 @@ void TabContentsViewWin::Focus() { void TabContentsViewWin::SetInitialFocus() { if (tab_contents()->FocusLocationBarByDefault()) - tab_contents()->SetFocusToLocationBar(); + tab_contents()->SetFocusToLocationBar(false); else Focus(); } diff --git a/chrome/browser/views/toolbar_view.cc b/chrome/browser/views/toolbar_view.cc index 52854e67..51c405d 100644 --- a/chrome/browser/views/toolbar_view.cc +++ b/chrome/browser/views/toolbar_view.cc @@ -929,7 +929,7 @@ void ToolbarView::RestoreLastFocusedView() { views::View* view = GetAncestorWithClassName(BrowserView::kViewClassName); if (view) { BrowserView* browser_view = static_cast<BrowserView*>(view); - browser_view->SetFocusToLocationBar(); + browser_view->SetFocusToLocationBar(false); } } } diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 964ff9c..c7ee70e 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -128,6 +128,7 @@ 'test/chrome_process_util_mac.cc', 'test/profile_mock.h', 'test/test_browser_window.h', + 'test/test_location_bar.h', 'test/testing_profile.cc', 'test/testing_profile.h', 'test/ui_test_utils.cc', diff --git a/chrome/test/test_browser_window.h b/chrome/test/test_browser_window.h index c81ff1c..9f384f6 100644 --- a/chrome/test/test_browser_window.h +++ b/chrome/test/test_browser_window.h @@ -43,7 +43,7 @@ class TestBrowserWindow : public BrowserWindow { virtual LocationBar* GetLocationBar() const { return const_cast<TestLocationBar*>(&location_bar_); } - virtual void SetFocusToLocationBar() {} + virtual void SetFocusToLocationBar(bool select_all) {} virtual void UpdateStopGoState(bool is_loading, bool force) {} virtual void UpdateToolbar(TabContents* contents, bool should_restore_state) {} diff --git a/chrome/test/test_location_bar.h b/chrome/test/test_location_bar.h index 7d4a114..2c06329 100644 --- a/chrome/test/test_location_bar.h +++ b/chrome/test/test_location_bar.h @@ -36,7 +36,7 @@ class TestLocationBar : public LocationBar { virtual PageTransition::Type GetPageTransition() const { return transition_; } virtual void AcceptInput() {} virtual void AcceptInputWithDisposition(WindowOpenDisposition) {} - virtual void FocusLocation() {} + virtual void FocusLocation(bool select_all) {} virtual void FocusSearch() {} virtual void UpdateContentSettingsIcons() {} virtual void UpdatePageActions() {} |