diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-01 20:58:19 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-01 20:58:19 +0000 |
commit | fdf773c534a49d14665928b957bbee60d00d0014 (patch) | |
tree | b43d1e352572dc81a5cbd232417438952f9762ff /chrome/browser/autocomplete | |
parent | e11de7254efb71fbe5b26b113a8e2e5bdd8da15f (diff) | |
download | chromium_src-fdf773c534a49d14665928b957bbee60d00d0014.zip chromium_src-fdf773c534a49d14665928b957bbee60d00d0014.tar.gz chromium_src-fdf773c534a49d14665928b957bbee60d00d0014.tar.bz2 |
Adds the ability to show verbatim instant results rather than
predictive results. More work is needed if we decide this is the direction to go, but it's good enough for us to play with.
BUG=61378
TEST=none
Review URL: http://codereview.chromium.org/4196009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64662 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete')
5 files changed, 54 insertions, 1 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc index 6505e6d..c86c8b0 100644 --- a/chrome/browser/autocomplete/autocomplete_edit.cc +++ b/chrome/browser/autocomplete/autocomplete_edit.cc @@ -20,6 +20,7 @@ #include "chrome/browser/command_updater.h" #include "chrome/browser/extensions/extension_omnibox_api.h" #include "chrome/browser/google/google_url_tracker.h" +#include "chrome/browser/instant/instant_controller.h" #include "chrome/browser/metrics/user_metrics.h" #include "chrome/browser/net/predictor_api.h" #include "chrome/browser/net/url_fixer_upper.h" @@ -680,6 +681,10 @@ void AutocompleteEditModel::PopupBoundsChangedTo(const gfx::Rect& bounds) { controller_->OnPopupBoundsChanged(bounds); } +void AutocompleteEditModel::ResultsUpdated() { + UpdateSuggestedSearchText(); +} + // Return true if the suggestion type warrants a TCP/IP preconnection. // i.e., it is now highly likely that the user will select the related domain. static bool IsPreconnectable(AutocompleteMatch::Type type) { @@ -767,3 +772,38 @@ void AutocompleteEditModel::GetInfoForCurrentText( alternate_nav_url); } } + +// Returns true if suggested search text should be shown for the specified match +// type. +static bool ShouldShowSuggestSearchTextFor(AutocompleteMatch::Type type) { + // TODO: add support for other engines when in keyword mode. + return ((type == AutocompleteMatch::SEARCH_HISTORY) || + (type == AutocompleteMatch::SEARCH_SUGGEST)); +} + +void AutocompleteEditModel::UpdateSuggestedSearchText() { + if (!InstantController::IsEnabled(profile_, InstantController::VERBATIM_TYPE)) + return; + + string16 suggested_text; + // The suggested text comes from the first search result. + if (popup_->IsOpen()) { + const AutocompleteResult& result = popup_->result(); + if ((result.size() > 1) && (popup_->selected_line() == 0) && + ((result.begin()->inline_autocomplete_offset == std::wstring::npos) || + (result.begin()->inline_autocomplete_offset == + result.begin()->fill_into_edit.size()))) { + for (AutocompleteResult::const_iterator i = result.begin() + 1; + i != result.end(); ++i) { + // TODO: add support for other engines when in keyword mode. + if (ShouldShowSuggestSearchTextFor(i->type) && + i->inline_autocomplete_offset != std::wstring::npos) { + suggested_text = WideToUTF16(i->fill_into_edit.substr( + i->inline_autocomplete_offset)); + break; + } + } + } + } + controller_->OnSetSuggestedSearchText(suggested_text); +} diff --git a/chrome/browser/autocomplete/autocomplete_edit.h b/chrome/browser/autocomplete/autocomplete_edit.h index 99f5e80..9e94172 100644 --- a/chrome/browser/autocomplete/autocomplete_edit.h +++ b/chrome/browser/autocomplete/autocomplete_edit.h @@ -6,6 +6,7 @@ #define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_EDIT_H_ #pragma once +#include "base/string16.h" #include "chrome/browser/autocomplete/autocomplete_match.h" #include "chrome/common/notification_observer.h" #include "chrome/common/notification_registrar.h" @@ -49,6 +50,9 @@ class AutocompleteEditController { // autocomplete. Returns true if the text was committed. virtual bool OnCommitSuggestedText(const std::wstring& typed_text) = 0; + // Sets the suggested search text to |suggested_text|. + virtual void OnSetSuggestedSearchText(const string16& suggested_text) = 0; + // Invoked when the popup is going to change its bounds to |bounds|. virtual void OnPopupBoundsChanged(const gfx::Rect& bounds) = 0; @@ -319,6 +323,9 @@ class AutocompleteEditModel : public NotificationObserver { // Invoked when the popup is going to change its bounds to |bounds|. void PopupBoundsChangedTo(const gfx::Rect& bounds); + // Invoked when the autocomplete results may have changed in some way. + void ResultsUpdated(); + private: enum PasteState { NONE, // Most recent edit was not a paste that replaced all text. @@ -368,6 +375,10 @@ class AutocompleteEditModel : public NotificationObserver { void GetInfoForCurrentText(AutocompleteMatch* match, GURL* alternate_nav_url) const; + // Determines the suggested search text and invokes OnSetSuggestedSearchText + // on the controller. + void UpdateSuggestedSearchText(); + AutocompleteEditView* view_; AutocompletePopupModel* popup_; diff --git a/chrome/browser/autocomplete/autocomplete_edit_unittest.cc b/chrome/browser/autocomplete/autocomplete_edit_unittest.cc index 6451fa6..b0941ad 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_unittest.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_unittest.cc @@ -67,6 +67,7 @@ class TestingAutocompleteEditController : public AutocompleteEditController { virtual bool OnCommitSuggestedText(const std::wstring& typed_text) { return false; } + virtual void OnSetSuggestedSearchText(const string16& suggested_text) {} virtual void OnPopupBoundsChanged(const gfx::Rect& bounds) {} virtual void OnAutocompleteAccept(const GURL& url, WindowOpenDisposition disposition, diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc index 422aadd6..cf7103e 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc @@ -1026,7 +1026,7 @@ void AutocompleteEditViewGtk::HandleViewMoveCursor( g_object_get(G_OBJECT(text_buffer_), "cursor-position", &cursor_pos, NULL); if (cursor_pos == gtk_text_buffer_get_char_count(text_buffer_)) - controller_->OnCommitSuggestedText(std::wstring()); + controller_->OnCommitSuggestedText(GetText()); else handled = false; } else { diff --git a/chrome/browser/autocomplete/autocomplete_popup_model.cc b/chrome/browser/autocomplete/autocomplete_popup_model.cc index 5b8f814..774acd0 100644 --- a/chrome/browser/autocomplete/autocomplete_popup_model.cc +++ b/chrome/browser/autocomplete/autocomplete_popup_model.cc @@ -293,6 +293,7 @@ void AutocompletePopupModel::Observe(NotificationType type, SetHoveredLine(kNoMatch); view_->UpdatePopupAppearance(); + edit_model_->ResultsUpdated(); edit_model_->PopupBoundsChangedTo(view_->GetTargetBounds()); } |