summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.cc40
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.h13
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_unittest.cc3
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view.h6
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc5
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.h3
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_mac.h3
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_mac.mm7
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_views.cc3
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_views.h3
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_win.cc6
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_win.h3
-rw-r--r--chrome/browser/instant/instant_browsertest.cc35
-rw-r--r--chrome/browser/instant/instant_controller.cc8
-rw-r--r--chrome/browser/instant/instant_controller.h4
-rw-r--r--chrome/browser/instant/instant_delegate.h4
-rw-r--r--chrome/browser/instant/instant_loader.cc31
-rw-r--r--chrome/browser/instant/instant_loader.h4
-rw-r--r--chrome/browser/instant/instant_loader_delegate.h7
-rw-r--r--chrome/browser/instant/instant_loader_manager_unittest.cc17
-rw-r--r--chrome/browser/ui/browser.cc5
-rw-r--r--chrome/browser/ui/browser.h13
-rw-r--r--chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h3
-rw-r--r--chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm5
-rw-r--r--chrome/browser/ui/gtk/location_bar_view_gtk.cc5
-rw-r--r--chrome/browser/ui/gtk/location_bar_view_gtk.h3
-rw-r--r--chrome/browser/ui/omnibox/location_bar.h4
-rw-r--r--chrome/browser/ui/views/location_bar/location_bar_view.cc42
-rw-r--r--chrome/browser/ui/views/location_bar/location_bar_view.h9
-rw-r--r--chrome/test/test_location_bar.h33
30 files changed, 231 insertions, 96 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;
diff --git a/chrome/browser/instant/instant_browsertest.cc b/chrome/browser/instant/instant_browsertest.cc
index c175eb6..1ecce31 100644
--- a/chrome/browser/instant/instant_browsertest.cc
+++ b/chrome/browser/instant/instant_browsertest.cc
@@ -5,6 +5,7 @@
#include "base/command_line.h"
#include "base/stringprintf.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/autocomplete/autocomplete_edit.h"
#include "chrome/browser/autocomplete/autocomplete_edit_view.h"
#include "chrome/browser/browser_list.h"
#include "chrome/browser/browser_window.h"
@@ -690,3 +691,37 @@ IN_PROC_BROWSER_TEST_F(InstantTest, ShowAboutCrash) {
// If we get here it means the preview was shown. If we time out, it means the
// preview was never shown.
}
+
+IN_PROC_BROWSER_TEST_F(InstantTest, InstantCompleteNever) {
+ ASSERT_TRUE(test_server()->Start());
+ EnableInstant();
+ ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
+ ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
+ ASSERT_NO_FATAL_FAILURE(SetupPreview());
+
+ SetSuggestionsJavascriptArgument(
+ preview_,
+ "{suggestions:[{value:'defghij'}],complete_behavior:'never'}");
+ ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def"));
+ EXPECT_STR_EQ("defghij", GetSuggestion());
+ AutocompleteEditModel* edit_model = location_bar_->location_entry()->model();
+ EXPECT_EQ(INSTANT_COMPLETE_NEVER, edit_model->instant_complete_behavior());
+ ASSERT_EQ(ASCIIToUTF16("def"), location_bar_->location_entry()->GetText());
+}
+
+IN_PROC_BROWSER_TEST_F(InstantTest, InstantCompleteDelayed) {
+ ASSERT_TRUE(test_server()->Start());
+ EnableInstant();
+ ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
+ ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
+ ASSERT_NO_FATAL_FAILURE(SetupPreview());
+
+ SetSuggestionsJavascriptArgument(
+ preview_,
+ "{suggestions:[{value:'defghij'}],complete_behavior:'delayed'}");
+ ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def"));
+ EXPECT_STR_EQ("defghij", GetSuggestion());
+ AutocompleteEditModel* edit_model = location_bar_->location_entry()->model();
+ EXPECT_EQ(INSTANT_COMPLETE_DELAYED, edit_model->instant_complete_behavior());
+ ASSERT_EQ(ASCIIToUTF16("def"), location_bar_->location_entry()->GetText());
+}
diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc
index c556dff..50f833b 100644
--- a/chrome/browser/instant/instant_controller.cc
+++ b/chrome/browser/instant/instant_controller.cc
@@ -388,10 +388,12 @@ void InstantController::ShowInstantLoader(InstantLoader* loader) {
NotificationService::NoDetails());
}
-void InstantController::SetSuggestedTextFor(InstantLoader* loader,
- const string16& text) {
+void InstantController::SetSuggestedTextFor(
+ InstantLoader* loader,
+ const string16& text,
+ InstantCompleteBehavior behavior) {
if (loader_manager_->current_loader() == loader)
- delegate_->SetSuggestedText(text);
+ delegate_->SetSuggestedText(text, behavior);
}
gfx::Rect InstantController::GetInstantBounds() {
diff --git a/chrome/browser/instant/instant_controller.h b/chrome/browser/instant/instant_controller.h
index bc535f8..6e1d619 100644
--- a/chrome/browser/instant/instant_controller.h
+++ b/chrome/browser/instant/instant_controller.h
@@ -18,6 +18,7 @@
#include "chrome/browser/instant/instant_commit_type.h"
#include "chrome/browser/instant/instant_loader_delegate.h"
#include "chrome/browser/search_engines/template_url_id.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"
@@ -174,7 +175,8 @@ class InstantController : public InstantLoaderDelegate {
// InstantLoaderDelegate
virtual void ShowInstantLoader(InstantLoader* loader) OVERRIDE;
virtual void SetSuggestedTextFor(InstantLoader* loader,
- const string16& text) OVERRIDE;
+ const string16& text,
+ InstantCompleteBehavior behavior) OVERRIDE;
virtual gfx::Rect GetInstantBounds() OVERRIDE;
virtual bool ShouldCommitInstantOnMouseUp() OVERRIDE;
virtual void CommitInstantLoader(InstantLoader* loader) OVERRIDE;
diff --git a/chrome/browser/instant/instant_delegate.h b/chrome/browser/instant/instant_delegate.h
index a908981..b459d61 100644
--- a/chrome/browser/instant/instant_delegate.h
+++ b/chrome/browser/instant/instant_delegate.h
@@ -7,6 +7,7 @@
#pragma once
#include "base/string16.h"
+#include "chrome/common/instant_types.h"
class TabContentsWrapper;
@@ -37,7 +38,8 @@ class InstantDelegate {
virtual void CommitInstant(TabContentsWrapper* preview_contents) = 0;
// Invoked when the suggested text is to change to |text|.
- virtual void SetSuggestedText(const string16& text) = 0;
+ virtual void SetSuggestedText(const string16& text,
+ InstantCompleteBehavior behavior) = 0;
// Returns the bounds instant will be placed at in screen coordinates.
virtual gfx::Rect GetInstantBounds() = 0;
diff --git a/chrome/browser/instant/instant_loader.cc b/chrome/browser/instant/instant_loader.cc
index 7a058a5..a22e1c4 100644
--- a/chrome/browser/instant/instant_loader.cc
+++ b/chrome/browser/instant/instant_loader.cc
@@ -530,11 +530,10 @@ void InstantLoader::TabContentsDelegateImpl::OnSetSuggestions(
page_id != source->controller().GetActiveEntry()->page_id())
return;
- // TODO: pass in behavior to SetCompleteSuggestedText.
if (suggestions.empty())
- loader_->SetCompleteSuggestedText(string16());
+ loader_->SetCompleteSuggestedText(string16(), behavior);
else
- loader_->SetCompleteSuggestedText(UTF8ToUTF16(suggestions[0]));
+ loader_->SetCompleteSuggestedText(UTF8ToUTF16(suggestions[0]), behavior);
}
void InstantLoader::TabContentsDelegateImpl::OnInstantSupportDetermined(
@@ -779,7 +778,8 @@ void InstantLoader::CommitInstantLoader() {
}
void InstantLoader::SetCompleteSuggestedText(
- const string16& complete_suggested_text) {
+ const string16& complete_suggested_text,
+ InstantCompleteBehavior behavior) {
if (!is_showing_instant()) {
// We're not trying to use the instant API with this page. Ignore it.
return;
@@ -804,18 +804,25 @@ void InstantLoader::SetCompleteSuggestedText(
0, user_text_lower.size())) {
// The user text no longer contains the suggested text, ignore it.
complete_suggested_text_.clear();
- delegate_->SetSuggestedTextFor(this, string16());
+ delegate_->SetSuggestedTextFor(this, string16(), behavior);
return;
}
complete_suggested_text_ = complete_suggested_text;
- // We are effectively showing complete_suggested_text_ now. Update user_text_
- // so we don't notify the page again if Update happens to be invoked (which is
- // more than likely if this callback completes before the omnibox is done).
- string16 suggestion = complete_suggested_text_.substr(user_text_.size());
- user_text_ = complete_suggested_text_;
- last_suggestion_.clear();
- delegate_->SetSuggestedTextFor(this, suggestion);
+ if (behavior == INSTANT_COMPLETE_NOW) {
+ // We are effectively showing complete_suggested_text_ now. Update
+ // user_text_ so we don't notify the page again if Update happens to be
+ // invoked (which is more than likely if this callback completes before the
+ // omnibox is done).
+ string16 suggestion = complete_suggested_text_.substr(user_text_.size());
+ user_text_ = complete_suggested_text_;
+ delegate_->SetSuggestedTextFor(this, suggestion, behavior);
+ } else {
+ DCHECK((behavior == INSTANT_COMPLETE_DELAYED) ||
+ (behavior == INSTANT_COMPLETE_NEVER));
+ last_suggestion_ = complete_suggested_text_.substr(user_text_.size());
+ delegate_->SetSuggestedTextFor(this, last_suggestion_, behavior);
+ }
}
void InstantLoader::PreviewPainted() {
diff --git a/chrome/browser/instant/instant_loader.h b/chrome/browser/instant/instant_loader.h
index aaae7bf..f18d454 100644
--- a/chrome/browser/instant/instant_loader.h
+++ b/chrome/browser/instant/instant_loader.h
@@ -12,6 +12,7 @@
#include "base/timer.h"
#include "chrome/browser/instant/instant_commit_type.h"
#include "chrome/browser/search_engines/template_url_id.h"
+#include "chrome/common/instant_types.h"
#include "chrome/common/page_transition_types.h"
#include "content/common/notification_observer.h"
#include "content/common/notification_registrar.h"
@@ -103,7 +104,8 @@ class InstantLoader : public NotificationObserver {
// Invoked when the page wants to update the suggested text. If |user_text_|
// starts with |suggested_text|, then the delegate is notified of the change,
// which results in updating the omnibox.
- void SetCompleteSuggestedText(const string16& suggested_text);
+ void SetCompleteSuggestedText(const string16& suggested_text,
+ InstantCompleteBehavior behavior);
// Invoked when the page paints.
void PreviewPainted();
diff --git a/chrome/browser/instant/instant_loader_delegate.h b/chrome/browser/instant/instant_loader_delegate.h
index bfe1518..6e3232a 100644
--- a/chrome/browser/instant/instant_loader_delegate.h
+++ b/chrome/browser/instant/instant_loader_delegate.h
@@ -7,6 +7,7 @@
#pragma once
#include "base/string16.h"
+#include "chrome/common/instant_types.h"
class GURL;
@@ -23,8 +24,10 @@ class InstantLoaderDelegate {
virtual void ShowInstantLoader(InstantLoader* loader) = 0;
// Invoked when the loader has suggested text.
- virtual void SetSuggestedTextFor(InstantLoader* loader,
- const string16& text) = 0;
+ virtual void SetSuggestedTextFor(
+ InstantLoader* loader,
+ const string16& text,
+ InstantCompleteBehavior behavior) = 0;
// Returns the bounds of instant.
virtual gfx::Rect GetInstantBounds() = 0;
diff --git a/chrome/browser/instant/instant_loader_manager_unittest.cc b/chrome/browser/instant/instant_loader_manager_unittest.cc
index 98af6da..ec3e2a2 100644
--- a/chrome/browser/instant/instant_loader_manager_unittest.cc
+++ b/chrome/browser/instant/instant_loader_manager_unittest.cc
@@ -14,26 +14,29 @@ class InstantLoaderDelegateImpl : public InstantLoaderDelegate {
public:
InstantLoaderDelegateImpl() {}
- virtual void ShowInstantLoader(InstantLoader* loader) {}
+ virtual void ShowInstantLoader(InstantLoader* loader) OVERRIDE {}
virtual void SetSuggestedTextFor(InstantLoader* loader,
- const string16& text) {}
+ const string16& text,
+ InstantCompleteBehavior behavior) OVERRIDE {}
- virtual gfx::Rect GetInstantBounds() {
+ virtual gfx::Rect GetInstantBounds() OVERRIDE {
return gfx::Rect();
}
- virtual bool ShouldCommitInstantOnMouseUp() {
+ virtual bool ShouldCommitInstantOnMouseUp() OVERRIDE {
return false;
}
- virtual void CommitInstantLoader(InstantLoader* loader) {
+ virtual void CommitInstantLoader(InstantLoader* loader) OVERRIDE {
}
- virtual void InstantLoaderDoesntSupportInstant(InstantLoader* loader) {
+ virtual void InstantLoaderDoesntSupportInstant(
+ InstantLoader* loader) OVERRIDE {
}
- virtual void AddToBlacklist(InstantLoader* loader, const GURL& url) {
+ virtual void AddToBlacklist(InstantLoader* loader,
+ const GURL& url) OVERRIDE {
}
private:
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc
index 5011f72..9670d6b 100644
--- a/chrome/browser/ui/browser.cc
+++ b/chrome/browser/ui/browser.cc
@@ -3527,8 +3527,9 @@ void Browser::CommitInstant(TabContentsWrapper* preview_contents) {
}
}
-void Browser::SetSuggestedText(const string16& text) {
- window()->GetLocationBar()->SetSuggestedText(text);
+void Browser::SetSuggestedText(const string16& text,
+ InstantCompleteBehavior behavior) {
+ window()->GetLocationBar()->SetSuggestedText(text, behavior);
}
gfx::Rect Browser::GetInstantBounds() {
diff --git a/chrome/browser/ui/browser.h b/chrome/browser/ui/browser.h
index 88bf2ac..b57bf05 100644
--- a/chrome/browser/ui/browser.h
+++ b/chrome/browser/ui/browser.h
@@ -840,12 +840,13 @@ class Browser : public TabHandlerDelegate,
virtual void OnStateChanged();
// Overriden from InstantDelegate:
- virtual void PrepareForInstant();
- virtual void ShowInstant(TabContentsWrapper* preview_contents);
- virtual void HideInstant();
- virtual void CommitInstant(TabContentsWrapper* preview_contents);
- virtual void SetSuggestedText(const string16& text);
- virtual gfx::Rect GetInstantBounds();
+ virtual void PrepareForInstant() OVERRIDE;
+ virtual void ShowInstant(TabContentsWrapper* preview_contents) OVERRIDE;
+ virtual void HideInstant() OVERRIDE;
+ virtual void CommitInstant(TabContentsWrapper* preview_contents) OVERRIDE;
+ virtual void SetSuggestedText(const string16& text,
+ InstantCompleteBehavior behavior) OVERRIDE;
+ virtual gfx::Rect GetInstantBounds() OVERRIDE;
// Command and state updating ///////////////////////////////////////////////
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 aa56b6c..14cf022 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
@@ -54,7 +54,8 @@ class LocationBarViewMac : public AutocompleteEditController,
// Overridden from LocationBar:
virtual void ShowFirstRunBubble(FirstRun::BubbleType bubble_type);
- virtual void SetSuggestedText(const string16& text);
+ virtual void SetSuggestedText(const string16& text,
+ InstantCompleteBehavior behavior);
virtual std::wstring GetInputString() const;
virtual WindowOpenDisposition GetWindowOpenDisposition() const;
virtual PageTransition::Type GetPageTransition() const;
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 61b12fd..2c246a6 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
@@ -137,8 +137,9 @@ std::wstring LocationBarViewMac::GetInputString() const {
return location_input_;
}
-void LocationBarViewMac::SetSuggestedText(const string16& text) {
- edit_view_->model()->SetSuggestedText(text);
+void LocationBarViewMac::SetSuggestedText(const string16& text,
+ InstantCompleteBehavior behavior) {
+ edit_view_->model()->SetSuggestedText(text, behavior);
}
WindowOpenDisposition LocationBarViewMac::GetWindowOpenDisposition() const {
diff --git a/chrome/browser/ui/gtk/location_bar_view_gtk.cc b/chrome/browser/ui/gtk/location_bar_view_gtk.cc
index a9fbd9b..76e3ad6 100644
--- a/chrome/browser/ui/gtk/location_bar_view_gtk.cc
+++ b/chrome/browser/ui/gtk/location_bar_view_gtk.cc
@@ -583,8 +583,9 @@ void LocationBarViewGtk::ShowFirstRunBubble(FirstRun::BubbleType bubble_type) {
MessageLoop::current()->PostTask(FROM_HERE, task);
}
-void LocationBarViewGtk::SetSuggestedText(const string16& text) {
- location_entry_->model()->SetSuggestedText(text);
+void LocationBarViewGtk::SetSuggestedText(const string16& text,
+ InstantCompleteBehavior behavior) {
+ location_entry_->model()->SetSuggestedText(text, behavior);
}
std::wstring LocationBarViewGtk::GetInputString() const {
diff --git a/chrome/browser/ui/gtk/location_bar_view_gtk.h b/chrome/browser/ui/gtk/location_bar_view_gtk.h
index a888524..8bc3b91 100644
--- a/chrome/browser/ui/gtk/location_bar_view_gtk.h
+++ b/chrome/browser/ui/gtk/location_bar_view_gtk.h
@@ -108,7 +108,8 @@ class LocationBarViewGtk : public AutocompleteEditController,
// Implement the LocationBar interface.
virtual void ShowFirstRunBubble(FirstRun::BubbleType bubble_type);
- virtual void SetSuggestedText(const string16& text);
+ virtual void SetSuggestedText(const string16& text,
+ InstantCompleteBehavior behavior);
virtual std::wstring GetInputString() const;
virtual WindowOpenDisposition GetWindowOpenDisposition() const;
virtual PageTransition::Type GetPageTransition() const;
diff --git a/chrome/browser/ui/omnibox/location_bar.h b/chrome/browser/ui/omnibox/location_bar.h
index f88f4a6..0183745 100644
--- a/chrome/browser/ui/omnibox/location_bar.h
+++ b/chrome/browser/ui/omnibox/location_bar.h
@@ -16,6 +16,7 @@
#include "base/string16.h"
#include "chrome/browser/first_run/first_run.h"
+#include "chrome/browser/instant/instant_delegate.h"
#include "chrome/common/page_transition_types.h"
#include "webkit/glue/window_open_disposition.h"
@@ -33,7 +34,8 @@ class LocationBar {
// Sets the suggested text to show in the omnibox. This is shown in addition
// to the current text of the omnibox.
- virtual void SetSuggestedText(const string16& text) = 0;
+ virtual void SetSuggestedText(const string16& text,
+ InstantCompleteBehavior behavior) = 0;
// Returns the string of text entered in the location bar.
virtual std::wstring GetInputString() const = 0;
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 68b535e..72a0034 100644
--- a/chrome/browser/ui/views/location_bar/location_bar_view.cc
+++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc
@@ -389,15 +389,40 @@ gfx::Point LocationBarView::GetLocationEntryOrigin() const {
return origin;
}
-string16 LocationBarView::GetInstantSuggestion() const {
#if defined(OS_WIN)
+void LocationBarView::SetInstantSuggestion(const string16& text,
+ bool animate_to_complete) {
+ // Don't show the suggested text if inline autocomplete is prevented.
+ if (!text.empty()) {
+ if (!suggested_text_view_) {
+ suggested_text_view_ = new SuggestedTextView(location_entry_->model());
+ suggested_text_view_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
+ suggested_text_view_->SetColor(
+ GetColor(ToolbarModel::NONE,
+ LocationBarView::DEEMPHASIZED_TEXT));
+ suggested_text_view_->SetText(UTF16ToWide(text));
+ suggested_text_view_->SetFont(location_entry_->GetFont());
+ AddChildView(suggested_text_view_);
+ } else if (suggested_text_view_->GetText() != UTF16ToWide(text)) {
+ suggested_text_view_->SetText(UTF16ToWide(text));
+ }
+ if (animate_to_complete && !location_entry_->IsImeComposing())
+ suggested_text_view_->StartAnimation();
+ } else if (suggested_text_view_) {
+ delete suggested_text_view_;
+ suggested_text_view_ = NULL;
+ } else {
+ return;
+ }
+
+ Layout();
+ SchedulePaint();
+}
+
+string16 LocationBarView::GetInstantSuggestion() const {
return HasValidSuggestText() ? suggested_text_view_->GetText() : string16();
-#else
- // On linux the edit shows the suggested text.
- NOTREACHED();
- return string16();
-#endif
}
+#endif
gfx::Size LocationBarView::GetPreferredSize() {
return gfx::Size(0, GetThemeProvider()->GetBitmapNamed(mode_ == POPUP ?
@@ -1057,8 +1082,9 @@ void LocationBarView::ShowFirstRunBubble(FirstRun::BubbleType bubble_type) {
ShowFirstRunBubbleInternal(bubble_type);
}
-void LocationBarView::SetSuggestedText(const string16& text) {
- location_entry_->model()->SetSuggestedText(text);
+void LocationBarView::SetSuggestedText(const string16& text,
+ InstantCompleteBehavior behavior) {
+ location_entry_->model()->SetSuggestedText(text, behavior);
}
std::wstring LocationBarView::GetInputString() const {
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 373e6f9..bb41bad 100644
--- a/chrome/browser/ui/views/location_bar/location_bar_view.h
+++ b/chrome/browser/ui/views/location_bar/location_bar_view.h
@@ -152,8 +152,14 @@ class LocationBarView : public LocationBar,
// appears, not where the icons are shown).
gfx::Point GetLocationEntryOrigin() const;
+#if defined(OS_WIN)
+ // Invoked from AutocompleteEditViewWin to show the instant suggestion.
+ void SetInstantSuggestion(const string16& text,
+ bool animate_to_complete);
+
// Returns the current instant suggestion text.
string16 GetInstantSuggestion() const;
+#endif
// Sizing functions
virtual gfx::Size GetPreferredSize() OVERRIDE;
@@ -218,7 +224,8 @@ class LocationBarView : public LocationBar,
// Overridden from LocationBar:
virtual void ShowFirstRunBubble(FirstRun::BubbleType bubble_type) OVERRIDE;
- virtual void SetSuggestedText(const string16& text) OVERRIDE;
+ virtual void SetSuggestedText(const string16& text,
+ InstantCompleteBehavior behavior) OVERRIDE;
virtual std::wstring GetInputString() const OVERRIDE;
virtual WindowOpenDisposition GetWindowOpenDisposition() const OVERRIDE;
virtual PageTransition::Type GetPageTransition() const OVERRIDE;
diff --git a/chrome/test/test_location_bar.h b/chrome/test/test_location_bar.h
index a74c2ad..f3dc099 100644
--- a/chrome/test/test_location_bar.h
+++ b/chrome/test/test_location_bar.h
@@ -27,22 +27,23 @@ class TestLocationBar : public LocationBar {
}
// Overridden from LocationBar:
- virtual void ShowFirstRunBubble(FirstRun::BubbleType bubble_type) {}
- virtual void SetSuggestedText(const string16& text) {}
- virtual std::wstring GetInputString() const;
- virtual WindowOpenDisposition GetWindowOpenDisposition() const;
- virtual PageTransition::Type GetPageTransition() const;
- virtual void AcceptInput() {}
- virtual void FocusLocation(bool select_all) {}
- virtual void FocusSearch() {}
- virtual void UpdateContentSettingsIcons() {}
- virtual void UpdatePageActions() {}
- virtual void InvalidatePageActions() {}
- virtual void SaveStateToContents(TabContents* contents) {}
- virtual void Revert() {}
- virtual const AutocompleteEditView* location_entry() const;
- virtual AutocompleteEditView* location_entry();
- virtual LocationBarTesting* GetLocationBarForTesting();
+ virtual void ShowFirstRunBubble(FirstRun::BubbleType bubble_type) OVERRIDE {}
+ virtual void SetSuggestedText(const string16& text,
+ InstantCompleteBehavior behavior) OVERRIDE {}
+ virtual std::wstring GetInputString() const OVERRIDE;
+ virtual WindowOpenDisposition GetWindowOpenDisposition() const OVERRIDE;
+ virtual PageTransition::Type GetPageTransition() const OVERRIDE;
+ virtual void AcceptInput() OVERRIDE {}
+ virtual void FocusLocation(bool select_all) OVERRIDE {}
+ virtual void FocusSearch() OVERRIDE {}
+ virtual void UpdateContentSettingsIcons() OVERRIDE {}
+ virtual void UpdatePageActions() OVERRIDE {}
+ virtual void InvalidatePageActions() OVERRIDE {}
+ virtual void SaveStateToContents(TabContents* contents) OVERRIDE {}
+ virtual void Revert() OVERRIDE {}
+ virtual const AutocompleteEditView* location_entry() const OVERRIDE;
+ virtual AutocompleteEditView* location_entry() OVERRIDE;
+ virtual LocationBarTesting* GetLocationBarForTesting() OVERRIDE;
private: