diff options
author | suzhe@google.com <suzhe@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-28 02:36:49 +0000 |
---|---|---|
committer | suzhe@google.com <suzhe@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-28 02:36:49 +0000 |
commit | 911696b92b1b5a666e59433b8b64303a2f4eae62 (patch) | |
tree | a47bab7021b5a34a532b1dae4140b8651558efd5 /chrome/browser/ui | |
parent | b7d6c22f8092a652d6b4572d4800e8a6aac6ccbe (diff) | |
download | chromium_src-911696b92b1b5a666e59433b8b64303a2f4eae62.zip chromium_src-911696b92b1b5a666e59433b8b64303a2f4eae62.tar.gz chromium_src-911696b92b1b5a666e59433b8b64303a2f4eae62.tar.bz2 |
Hitting Tab should always move cursor to end of omnibox text.
BUG=66850
TEST=AutocompleteEditViewTest.TabMoveCursorToEnd and InstantTest.TabKey
Review URL: http://codereview.chromium.org/5966006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72920 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui')
7 files changed, 59 insertions, 45 deletions
diff --git a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h index 0f87f44..7b06b91 100644 --- a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h +++ b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h @@ -132,7 +132,7 @@ class LocationBarViewMac : public AutocompleteEditController, virtual void OnAutocompleteWillClosePopup(); virtual void OnAutocompleteLosingFocus(gfx::NativeView unused); virtual void OnAutocompleteWillAccept(); - virtual bool OnCommitSuggestedText(const string16& typed_text); + virtual bool OnCommitSuggestedText(bool skip_inline_autocomplete); virtual bool AcceptCurrentInstantPreview(); virtual void OnPopupBoundsChanged(const gfx::Rect& bounds); virtual void OnAutocompleteAccept(const GURL& url, diff --git a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm index 213cc53..ba43a7c 100644 --- a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm +++ b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm @@ -248,8 +248,17 @@ void LocationBarViewMac::OnAutocompleteWillAccept() { update_instant_ = false; } -bool LocationBarViewMac::OnCommitSuggestedText(const string16& typed_text) { - return edit_view_->CommitSuggestText(); +bool LocationBarViewMac::OnCommitSuggestedText(bool skip_inline_autocomplete) { + if (!browser_->instant()) + return false; + + const string16 suggestion = edit_view_->GetInstantSuggestion(); + if (suggestion.empty()) + return false; + + edit_view_->model()->FinalizeInstantQuery( + edit_view_->GetText(), suggestion, skip_inline_autocomplete); + return true; } bool LocationBarViewMac::AcceptCurrentInstantPreview() { @@ -321,13 +330,13 @@ void LocationBarViewMac::OnChanged() { edit_view_->model()->UseVerbatimInstant(), &suggested_text); if (!instant->MightSupportInstant()) { - edit_view_->model()->FinalizeInstantQuery(string16(), - string16()); + edit_view_->model()->FinalizeInstantQuery( + string16(), string16(), false); } } else { instant->DestroyPreviewContents(); - edit_view_->model()->FinalizeInstantQuery(string16(), - string16()); + edit_view_->model()->FinalizeInstantQuery( + string16(), string16(), false); } } diff --git a/chrome/browser/ui/gtk/location_bar_view_gtk.cc b/chrome/browser/ui/gtk/location_bar_view_gtk.cc index 6b600d4..b7a5c72 100644 --- a/chrome/browser/ui/gtk/location_bar_view_gtk.cc +++ b/chrome/browser/ui/gtk/location_bar_view_gtk.cc @@ -458,9 +458,17 @@ void LocationBarViewGtk::OnAutocompleteWillAccept() { update_instant_ = false; } -bool LocationBarViewGtk::OnCommitSuggestedText( - const string16& typed_text) { - return browser_->instant() && location_entry_->CommitInstantSuggestion(); +bool LocationBarViewGtk::OnCommitSuggestedText(bool skip_inline_autocomplete) { + if (!browser_->instant()) + return false; + + const string16 suggestion = location_entry_->GetInstantSuggestion(); + if (suggestion.empty()) + return false; + + location_entry_->model()->FinalizeInstantQuery( + location_entry_->GetText(), suggestion, skip_inline_autocomplete); + return true; } bool LocationBarViewGtk::AcceptCurrentInstantPreview() { @@ -538,13 +546,13 @@ void LocationBarViewGtk::OnChanged() { location_entry_->model()->UseVerbatimInstant(), &suggested_text); if (!instant->MightSupportInstant()) { - location_entry_->model()->FinalizeInstantQuery(string16(), - string16()); + location_entry_->model()->FinalizeInstantQuery( + string16(), string16(), false); } } else { instant->DestroyPreviewContents(); - location_entry_->model()->FinalizeInstantQuery(string16(), - string16()); + location_entry_->model()->FinalizeInstantQuery( + string16(), string16(), false); } } @@ -627,7 +635,7 @@ void LocationBarViewGtk::SetSuggestedText(const string16& text) { // text. if (!text.empty()) { location_entry_->model()->FinalizeInstantQuery( - location_entry_->GetText(), text); + location_entry_->GetText(), text, false); } } else { location_entry_->SetInstantSuggestion(text); diff --git a/chrome/browser/ui/gtk/location_bar_view_gtk.h b/chrome/browser/ui/gtk/location_bar_view_gtk.h index 374d8fc..2bc9ba5 100644 --- a/chrome/browser/ui/gtk/location_bar_view_gtk.h +++ b/chrome/browser/ui/gtk/location_bar_view_gtk.h @@ -95,7 +95,7 @@ class LocationBarViewGtk : public AutocompleteEditController, virtual void OnAutocompleteLosingFocus(gfx::NativeView view_gaining_focus); virtual void OnAutocompleteWillAccept(); // For this implementation, the parameter is ignored. - virtual bool OnCommitSuggestedText(const string16& typed_text); + virtual bool OnCommitSuggestedText(bool skip_inline_autocomplete); virtual bool AcceptCurrentInstantPreview(); virtual void OnPopupBoundsChanged(const gfx::Rect& bounds); virtual void OnAutocompleteAccept(const GURL& url, diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chrome/browser/ui/views/location_bar/location_bar_view.cc index d66b51a..8dc3a25 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.cc +++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc @@ -399,15 +399,6 @@ gfx::Point LocationBarView::GetLocationEntryOrigin() const { return origin; } -#if defined(OS_WIN) -void LocationBarView::OnCommitSuggestedText() { - InstantController* instant = delegate_->GetInstant(); - DCHECK(instant); - DCHECK(suggested_text_view_); - OnCommitSuggestedText(location_entry_->GetText()); -} -#endif - gfx::Size LocationBarView::GetPreferredSize() { return gfx::Size(0, GetThemeProvider()->GetBitmapNamed(mode_ == POPUP ? IDR_LOCATIONBG_POPUPMODE_CENTER : IDR_LOCATIONBG_C)->height()); @@ -768,17 +759,24 @@ void LocationBarView::OnAutocompleteWillAccept() { update_instant_ = false; } -bool LocationBarView::OnCommitSuggestedText(const string16& typed_text) { - InstantController* instant = delegate_->GetInstant(); - if (!instant) +bool LocationBarView::OnCommitSuggestedText(bool skip_inline_autocomplete) { + if (!delegate_->GetInstant()) return false; + string16 suggestion; #if defined(OS_WIN) - if (!HasValidSuggestText()) - return false; - suggestion = suggested_text_view_->GetText(); + if (HasValidSuggestText()) + suggestion = suggested_text_view_->GetText(); +#else + suggestion = location_entry_->GetInstantSuggestion(); #endif - return location_entry_->CommitInstantSuggestion(typed_text, suggestion); + + if (suggestion.empty()) + return false; + + location_entry_->model()->FinalizeInstantQuery( + location_entry_->GetText(), suggestion, skip_inline_autocomplete); + return true; } bool LocationBarView::AcceptCurrentInstantPreview() { @@ -852,13 +850,13 @@ void LocationBarView::OnChanged() { location_entry_->model()->UseVerbatimInstant(), &suggested_text); if (!instant->MightSupportInstant()) { - location_entry_->model()->FinalizeInstantQuery(string16(), - string16()); + location_entry_->model()->FinalizeInstantQuery( + string16(), string16(), false); } } else { instant->DestroyPreviewContents(); - location_entry_->model()->FinalizeInstantQuery(string16(), - string16()); + location_entry_->model()->FinalizeInstantQuery( + string16(), string16(), false); } } @@ -1058,6 +1056,10 @@ bool LocationBarView::SkipDefaultKeyEventProcessing(const views::KeyEvent& e) { return true; } + // If the caret is not at the end, then tab moves the caret to the end. + if (!location_entry_->IsCaretAtEnd()) + return true; + // Tab while showing instant commits instant immediately. // Return true so that focus traversal isn't attempted. The edit ends // up doing nothing in this case. @@ -1128,8 +1130,8 @@ void LocationBarView::SetSuggestedText(const string16& input) { // TODO: if we keep autocomplete, make it so this isn't invoked with empty // text. if (!input.empty()) { - location_entry_->model()->FinalizeInstantQuery(location_entry_->GetText(), - input); + location_entry_->model()->FinalizeInstantQuery( + location_entry_->GetText(), input, false); } return; } diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.h b/chrome/browser/ui/views/location_bar/location_bar_view.h index 90273e9..d149aba 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.h +++ b/chrome/browser/ui/views/location_bar/location_bar_view.h @@ -155,11 +155,6 @@ class LocationBarView : public LocationBar, // appears, not where the icons are shown). gfx::Point GetLocationEntryOrigin() const; -#if defined(OS_WIN) - // Invoked from SuggestedTextView when the suggested text should be committed. - void OnCommitSuggestedText(); -#endif - // Sizing functions virtual gfx::Size GetPreferredSize(); @@ -194,7 +189,7 @@ class LocationBarView : public LocationBar, virtual void OnAutocompleteWillClosePopup(); virtual void OnAutocompleteLosingFocus(gfx::NativeView view_gaining_focus); virtual void OnAutocompleteWillAccept(); - virtual bool OnCommitSuggestedText(const string16& typed_text); + virtual bool OnCommitSuggestedText(bool skip_inline_autocomplete); virtual bool AcceptCurrentInstantPreview(); virtual void OnPopupBoundsChanged(const gfx::Rect& bounds); virtual void OnAutocompleteAccept(const GURL& url, diff --git a/chrome/browser/ui/views/location_bar/suggested_text_view.cc b/chrome/browser/ui/views/location_bar/suggested_text_view.cc index 22b9e9f..6fa19c0 100644 --- a/chrome/browser/ui/views/location_bar/suggested_text_view.cc +++ b/chrome/browser/ui/views/location_bar/suggested_text_view.cc @@ -46,7 +46,7 @@ void SuggestedTextView::PaintBackground(gfx::Canvas* canvas) { } void SuggestedTextView::AnimationEnded(const ui::Animation* animation) { - location_bar_->OnCommitSuggestedText(); + location_bar_->OnCommitSuggestedText(false); } void SuggestedTextView::AnimationProgressed(const ui::Animation* animation) { |