diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-15 14:51:55 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-15 14:51:55 +0000 |
commit | 33b8b8e68843131c6f81c47a0d0c0c616a01b355 (patch) | |
tree | 37a3722b10fa9cfdaa5cb24eaa124f1943446fbf /chrome/browser/autocomplete | |
parent | 5976255eccb8c585c4e5ed0fefe4144d62bd1f74 (diff) | |
download | chromium_src-33b8b8e68843131c6f81c47a0d0c0c616a01b355.zip chromium_src-33b8b8e68843131c6f81c47a0d0c0c616a01b355.tar.gz chromium_src-33b8b8e68843131c6f81c47a0d0c0c616a01b355.tar.bz2 |
Wires up ability for page to specify instant auto complete
behavior. The choices are:
. immediately (current behavior and is the default).
. delayed (transitions to autocompleted after a delay).
. never (only show the suggestion, but never autocomplete it).
I'm doing this so we can collect some data to help understand which is
the less error prone of the 3. The data collection is all done on the
server side.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6685002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78211 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete')
12 files changed, 66 insertions, 29 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc index b52a0af..b172152 100644 --- a/chrome/browser/autocomplete/autocomplete_edit.cc +++ b/chrome/browser/autocomplete/autocomplete_edit.cc @@ -79,7 +79,8 @@ AutocompleteEditModel::AutocompleteEditModel( is_keyword_hint_(false), paste_and_go_transition_(PageTransition::TYPED), profile_(profile), - update_instant_(true) { + update_instant_(true), + instant_complete_behavior_(INSTANT_COMPLETE_DELAYED) { } AutocompleteEditModel::~AutocompleteEditModel() { @@ -172,13 +173,20 @@ void AutocompleteEditModel::FinalizeInstantQuery( } } -void AutocompleteEditModel::SetSuggestedText(const string16& text) { - // This method is internally invoked to reset suggest text, so we only do - // anything if the text isn't empty. - // TODO: if we keep autocomplete, make it so this isn't invoked with empty - // text. - if (!text.empty()) - FinalizeInstantQuery(view_->GetText(), text, false); +void AutocompleteEditModel::SetSuggestedText( + const string16& text, + InstantCompleteBehavior behavior) { + instant_complete_behavior_ = behavior; + if (instant_complete_behavior_ == INSTANT_COMPLETE_NOW) { + if (!text.empty()) + FinalizeInstantQuery(view_->GetText(), text, false); + else + view_->SetInstantSuggestion(text, false); + } else { + DCHECK((behavior == INSTANT_COMPLETE_DELAYED) || + (behavior == INSTANT_COMPLETE_NEVER)); + view_->SetInstantSuggestion(text, behavior == INSTANT_COMPLETE_DELAYED); + } } bool AutocompleteEditModel::CommitSuggestedText(bool skip_inline_autocomplete) { @@ -201,6 +209,7 @@ void AutocompleteEditModel::OnChanged() { InstantController* instant = controller_->GetInstant(); string16 suggested_text; TabContentsWrapper* tab = controller_->GetTabContentsWrapper(); + bool might_support_instant = false; if (update_instant_ && instant && tab) { if (user_input_in_progress() && popup_->IsOpen()) { AutocompleteMatch current_match = CurrentMatch(); @@ -216,11 +225,18 @@ void AutocompleteEditModel::OnChanged() { } else { instant->DestroyPreviewContents(); } - if (!instant->MightSupportInstant()) - FinalizeInstantQuery(string16(), string16(), false); + might_support_instant = instant->MightSupportInstant(); } - SetSuggestedText(suggested_text); + if (!might_support_instant) { + // Hide any suggestions we might be showing. + view_->SetInstantSuggestion(string16(), false); + + // No need to wait any longer for instant. + FinalizeInstantQuery(string16(), string16(), false); + } else { + SetSuggestedText(suggested_text, instant_complete_behavior_); + } controller_->OnChanged(); } @@ -568,7 +584,7 @@ void AutocompleteEditModel::OnSetFocus(bool control_down) { void AutocompleteEditModel::OnWillKillFocus( gfx::NativeView view_gaining_focus) { - SetSuggestedText(string16()); + SetSuggestedText(string16(), INSTANT_COMPLETE_NOW); InstantController* instant = controller_->GetInstant(); if (instant) diff --git a/chrome/browser/autocomplete/autocomplete_edit.h b/chrome/browser/autocomplete/autocomplete_edit.h index 41e05e9..7bb0dc0 100644 --- a/chrome/browser/autocomplete/autocomplete_edit.h +++ b/chrome/browser/autocomplete/autocomplete_edit.h @@ -10,6 +10,7 @@ #include "base/string16.h" #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h" #include "chrome/browser/autocomplete/autocomplete_match.h" +#include "chrome/common/instant_types.h" #include "chrome/common/page_transition_types.h" #include "googleurl/src/gurl.h" #include "ui/gfx/native_widget_types.h" @@ -191,7 +192,8 @@ class AutocompleteEditModel : public AutocompleteControllerDelegate { bool skip_inline_autocomplete); // Sets the suggestion text. - void SetSuggestedText(const string16& text); + void SetSuggestedText(const string16& text, + InstantCompleteBehavior behavior); // Commits the suggested text. If |skip_inline_autocomplete| is true then the // suggested text will be committed as final text as if it's inputted by the @@ -333,6 +335,12 @@ class AutocompleteEditModel : public AutocompleteControllerDelegate { // Invoked when the popup is going to change its bounds to |bounds|. void PopupBoundsChangedTo(const gfx::Rect& bounds); +#if defined(UNIT_TEST) + InstantCompleteBehavior instant_complete_behavior() const { + return instant_complete_behavior_; + } +#endif + private: enum PasteState { NONE, // Most recent edit was not a paste. @@ -523,6 +531,9 @@ class AutocompleteEditModel : public AutocompleteControllerDelegate { // happening. bool update_instant_; + // Last value of InstantCompleteBehavior supplied to |SetSuggestedText|. + InstantCompleteBehavior instant_complete_behavior_; + DISALLOW_COPY_AND_ASSIGN(AutocompleteEditModel); }; diff --git a/chrome/browser/autocomplete/autocomplete_edit_unittest.cc b/chrome/browser/autocomplete/autocomplete_edit_unittest.cc index 2a51f91..12e04df 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_unittest.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_unittest.cc @@ -56,7 +56,8 @@ class TestingAutocompleteEditView : public AutocompleteEditView { virtual bool OnAfterPossibleChange() { return false; } virtual gfx::NativeView GetNativeView() const { return 0; } virtual CommandUpdater* GetCommandUpdater() { return NULL; } - virtual void SetInstantSuggestion(const string16& input) {} + virtual void SetInstantSuggestion(const string16& input, + bool animate_to_complete) {} virtual string16 GetInstantSuggestion() const { return string16(); } virtual int TextWidth() const { return 0; } virtual bool IsImeComposing() const { return false; } diff --git a/chrome/browser/autocomplete/autocomplete_edit_view.h b/chrome/browser/autocomplete/autocomplete_edit_view.h index 1925983..99951f8 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view.h +++ b/chrome/browser/autocomplete/autocomplete_edit_view.h @@ -159,8 +159,10 @@ class AutocompleteEditView { // Returns the command updater for this view. virtual CommandUpdater* GetCommandUpdater() = 0; - // Shows the instant suggestion text. - virtual void SetInstantSuggestion(const string16& input) = 0; + // Shows the instant suggestion text. If |animate_to_complete| is true the + // view should start an animation that when done commits the text. + virtual void SetInstantSuggestion(const string16& input, + bool animate_to_complete) = 0; // Returns the current instant suggestion text. virtual string16 GetInstantSuggestion() const = 0; diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc index b7a6c0b..390276e 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc @@ -761,7 +761,8 @@ CommandUpdater* AutocompleteEditViewGtk::GetCommandUpdater() { return command_updater_; } -void AutocompleteEditViewGtk::SetInstantSuggestion(const string16& suggestion) { +void AutocompleteEditViewGtk::SetInstantSuggestion(const string16& suggestion, + bool animate_to_complete) { std::string suggestion_utf8 = UTF16ToUTF8(suggestion); gtk_label_set_text(GTK_LABEL(instant_view_), suggestion_utf8.c_str()); @@ -772,7 +773,7 @@ void AutocompleteEditViewGtk::SetInstantSuggestion(const string16& suggestion) { gtk_widget_hide(instant_view_); return; } - if (InstantController::IsEnabled(model_->profile()) + if (animate_to_complete #if GTK_CHECK_VERSION(2, 20, 0) && preedit_.empty() #endif diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h index fcd2e1e..cc8bbd6 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h +++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h @@ -139,7 +139,8 @@ class AutocompleteEditViewGtk : public AutocompleteEditView, virtual bool OnAfterPossibleChange(); virtual gfx::NativeView GetNativeView() const; virtual CommandUpdater* GetCommandUpdater(); - virtual void SetInstantSuggestion(const string16& suggestion); + virtual void SetInstantSuggestion(const string16& suggestion, + bool animate_to_complete); virtual string16 GetInstantSuggestion() const; virtual int TextWidth() const; virtual bool IsImeComposing() const; diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.h b/chrome/browser/autocomplete/autocomplete_edit_view_mac.h index 318e4b5..3a00aeb 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.h +++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.h @@ -83,7 +83,8 @@ class AutocompleteEditViewMac : public AutocompleteEditView, virtual bool OnAfterPossibleChange(); virtual gfx::NativeView GetNativeView() const; virtual CommandUpdater* GetCommandUpdater(); - virtual void SetInstantSuggestion(const string16& input); + virtual void SetInstantSuggestion(const string16& input, + bool animate_to_complete); virtual string16 GetInstantSuggestion() const; virtual int TextWidth() const; virtual bool IsImeComposing() const; diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm index 8904667..e86823e 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm +++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm @@ -604,7 +604,7 @@ void AutocompleteEditViewMac::OnStartingIME() { // Reset the suggest text just before starting an IME composition session, // otherwise the IME composition may be interrupted when the suggest text // gets reset by the IME composition change. - SetInstantSuggestion(string16()); + SetInstantSuggestion(string16(), false); } bool AutocompleteEditViewMac::OnInlineAutocompleteTextMaybeChanged( @@ -703,7 +703,8 @@ CommandUpdater* AutocompleteEditViewMac::GetCommandUpdater() { } void AutocompleteEditViewMac::SetInstantSuggestion( - const string16& suggest_text) { + const string16& suggest_text, + bool animate_to_complete) { NSString* text = GetNonSuggestTextSubstring(); bool needs_update = (suggest_text_length_ > 0); @@ -769,7 +770,7 @@ bool AutocompleteEditViewMac::OnDoCommandBySelector(SEL cmd) { // Reset the suggest text for any change other than key right or tab. // TODO(rohitrao): This is here to prevent complications when editing text. // See if this can be removed. - SetInstantSuggestion(string16()); + SetInstantSuggestion(string16(), false); } if (cmd == @selector(deleteForward:)) diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_views.cc b/chrome/browser/autocomplete/autocomplete_edit_view_views.cc index 922908a..0d1bdc3 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_views.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_view_views.cc @@ -541,7 +541,8 @@ CommandUpdater* AutocompleteEditViewViews::GetCommandUpdater() { return command_updater_; } -void AutocompleteEditViewViews::SetInstantSuggestion(const string16& input) { +void AutocompleteEditViewViews::SetInstantSuggestion(const string16& input, + bool animate_to_complete) { NOTIMPLEMENTED(); } diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_views.h b/chrome/browser/autocomplete/autocomplete_edit_view_views.h index e01ed05..1dd1316 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_views.h +++ b/chrome/browser/autocomplete/autocomplete_edit_view_views.h @@ -114,7 +114,8 @@ class AutocompleteEditViewViews : public views::View, virtual bool OnAfterPossibleChange(); virtual gfx::NativeView GetNativeView() const; virtual CommandUpdater* GetCommandUpdater(); - virtual void SetInstantSuggestion(const string16& input); + virtual void SetInstantSuggestion(const string16& input, + bool animate_to_complete); virtual string16 GetInstantSuggestion() const; virtual int TextWidth() const; virtual bool IsImeComposing() const; diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc index 6adb0be..c9520fc 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc @@ -930,9 +930,9 @@ CommandUpdater* AutocompleteEditViewWin::GetCommandUpdater() { return command_updater_; } -void AutocompleteEditViewWin::SetInstantSuggestion(const string16& suggestion) { - // On Windows, we shows the suggestion in LocationBarView. - NOTREACHED(); +void AutocompleteEditViewWin::SetInstantSuggestion(const string16& suggestion, + bool animate_to_complete) { + parent_view_->SetInstantSuggestion(suggestion, animate_to_complete); } int AutocompleteEditViewWin::TextWidth() const { diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.h b/chrome/browser/autocomplete/autocomplete_edit_view_win.h index e0b57f9..8a29b84 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_win.h +++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.h @@ -134,7 +134,8 @@ class AutocompleteEditViewWin virtual bool OnAfterPossibleChange(); virtual gfx::NativeView GetNativeView() const; virtual CommandUpdater* GetCommandUpdater(); - virtual void SetInstantSuggestion(const string16& suggestion); + virtual void SetInstantSuggestion(const string16& suggestion, + bool animate_to_complete); virtual int TextWidth() const; virtual string16 GetInstantSuggestion() const; virtual bool IsImeComposing() const; |