summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-28 20:04:07 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-28 20:04:07 +0000
commit8768b4555d2ce58da02a5a51894f455cc2dfb158 (patch)
treed966e1281feb75b88391945e200ec6851b144017 /chrome/browser
parent8c23a87bd4f1c7aa5b7426bc6e0ab4f959669cbf (diff)
downloadchromium_src-8768b4555d2ce58da02a5a51894f455cc2dfb158.zip
chromium_src-8768b4555d2ce58da02a5a51894f455cc2dfb158.tar.gz
chromium_src-8768b4555d2ce58da02a5a51894f455cc2dfb158.tar.bz2
Makes instant suggest commit immediately. If folks like this, I can
rip out some more code. BUG=none TEST=none Review URL: http://codereview.chromium.org/6360022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@73006 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/about_flags.cc7
-rw-r--r--chrome/browser/instant/instant_browsertest.cc47
-rw-r--r--chrome/browser/instant/instant_loader.cc30
-rw-r--r--chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm10
-rw-r--r--chrome/browser/ui/gtk/location_bar_view_gtk.cc19
-rw-r--r--chrome/browser/ui/views/location_bar/location_bar_view.cc49
6 files changed, 48 insertions, 114 deletions
diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
index 83c9ee4..8386677 100644
--- a/chrome/browser/about_flags.cc
+++ b/chrome/browser/about_flags.cc
@@ -242,13 +242,6 @@ const Experiment kExperiments[] = {
SINGLE_VALUE_TYPE(switches::kExperimentalLocationFeatures)
},
{
- "instant-autocomplete-immediately", // FLAGS:RECORD_UMA
- IDS_FLAGS_INSTANT_AUTOCOMPLETE_IMMEDIATELY_NAME,
- IDS_FLAGS_INSTANT_AUTOCOMPLETE_IMMEDIATELY_DESCRIPTION,
- kOsWin | kOsLinux,
- SINGLE_VALUE_TYPE(switches::kInstantAutocompleteImmediately)
- },
- {
"block-reading-third-party-cookies",
IDS_FLAGS_BLOCK_ALL_THIRD_PARTY_COOKIES_NAME,
IDS_FLAGS_BLOCK_ALL_THIRD_PARTY_COOKIES_DESCRIPTION,
diff --git a/chrome/browser/instant/instant_browsertest.cc b/chrome/browser/instant/instant_browsertest.cc
index 231109e..8b3ad93 100644
--- a/chrome/browser/instant/instant_browsertest.cc
+++ b/chrome/browser/instant/instant_browsertest.cc
@@ -292,9 +292,11 @@ IN_PROC_BROWSER_TEST_F(InstantTest, OnChangeEvent) {
ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc"));
+ ASSERT_EQ(ASCIIToUTF16("abcdef"), location_bar_->location_entry()->GetText());
+
// Check that the value is reflected and onchange is called.
- EXPECT_EQ("true 0 0 1 1 a false abc false 3 3",
- GetSearchStateAsString(preview_));
+ EXPECT_EQ("true 0 0 1 2 a false abc false 3 3",
+ GetSearchStateAsString(preview_));
}
IN_PROC_BROWSER_TEST_F(InstantTest, SetSuggestionsArrayOfStrings) {
@@ -634,8 +636,8 @@ IN_PROC_BROWSER_TEST_F(InstantTest, OnSubmitEvent) {
ASSERT_TRUE(contents);
// Check that the value is reflected and onsubmit is called.
- EXPECT_EQ("true 1 0 1 1 a false abc true 3 3",
- GetSearchStateAsString(preview_));
+ EXPECT_EQ("true 1 0 1 2 a false abcdef true 3 3",
+ GetSearchStateAsString(preview_));
}
// Verify that the oncancel event is dispatched upon losing focus.
@@ -659,39 +661,6 @@ IN_PROC_BROWSER_TEST_F(InstantTest, OnCancelEvent) {
ASSERT_TRUE(contents);
// Check that the value is reflected and oncancel is called.
- EXPECT_EQ("true 0 1 1 1 a false abc false 3 3",
- GetSearchStateAsString(preview_));
-}
-
-IN_PROC_BROWSER_TEST_F(InstantTest, TabKey) {
- ASSERT_TRUE(test_server()->Start());
- EnableInstant();
- ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
-
- ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
- ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
- ASSERT_NO_FATAL_FAILURE(SetupPreview());
-
- ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc"));
-
- // Pressing tab to convert instant suggest into inline autocomplete.
- ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB));
-
- ASSERT_EQ(ASCIIToUTF16("abcdef"), location_bar_->location_entry()->GetText());
-
- EXPECT_EQ("true 0 0 2 1 a false abcdef false 6 6",
- GetSearchStateAsString(preview_));
-
- // Pressing tab again to accept the current instant preview.
- ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB));
-
- // Check that the preview contents have been committed.
- ASSERT_FALSE(browser()->instant()->GetPreviewContents());
- ASSERT_FALSE(browser()->instant()->is_active());
- TabContents* contents = browser()->GetSelectedTabContents();
- ASSERT_TRUE(contents);
-
- // Check that the value is reflected and onsubmit is called.
- EXPECT_EQ("true 1 0 2 1 a false abcdef true 6 6",
- GetSearchStateAsString(preview_));
+ EXPECT_EQ("true 0 1 1 2 a false abc false 3 3",
+ GetSearchStateAsString(preview_));
}
diff --git a/chrome/browser/instant/instant_loader.cc b/chrome/browser/instant/instant_loader.cc
index b674921..e4ee07d 100644
--- a/chrome/browser/instant/instant_loader.cc
+++ b/chrome/browser/instant/instant_loader.cc
@@ -445,16 +445,17 @@ void InstantLoader::Update(TabContentsWrapper* tab_contents,
// showing the url.
last_transition_type_ = transition_type;
- // If state hasn't changed, just reuse the last suggestion. If the user
- // modifies the text of the omnibox in anyway the URL changes. We also need to
- // update if verbatim changes and we're showing instant results. We have to be
- // careful in checking user_text as in some situations InstantController
- // passes in an empty string (when it knows the user_text won't matter). In
- // these cases, we don't worry about whether the new user text matches the old
- // user text.
- if ((url_ == url) &&
- (new_user_text.empty() || user_text_ == new_user_text) &&
- (!template_url || verbatim == verbatim_)) {
+ // If state hasn't changed, reuse the last suggestion. There are two cases:
+ // 1. If no template url (not using instant API), then we only care if the url
+ // changes.
+ // 2. Template url (using instant API) then the important part is if the
+ // user_text changes.
+ // We have to be careful in checking user_text as in some situations
+ // InstantController passes in an empty string (when it knows the user_text
+ // won't matter).
+ if ((!template_url_id_ && url_ == url) ||
+ (template_url_id_ &&
+ (new_user_text.empty() || user_text_ == new_user_text))) {
suggested_text->assign(last_suggestion_);
return;
}
@@ -640,8 +641,13 @@ void InstantLoader::SetCompleteSuggestedText(
}
complete_suggested_text_ = complete_suggested_text;
- last_suggestion_ = complete_suggested_text_.substr(user_text_.size());
- delegate_->SetSuggestedTextFor(this, last_suggestion_);
+ // 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);
}
void InstantLoader::PreviewPainted() {
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 ba43a7c..3a1746b 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
@@ -139,8 +139,14 @@ std::wstring LocationBarViewMac::GetInputString() const {
}
void LocationBarViewMac::SetSuggestedText(const string16& text) {
- edit_view_->SetInstantSuggestion(
- edit_view_->model()->UseVerbatimInstant() ? 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()) {
+ edit_view_->model()->FinalizeInstantQuery(edit_view_->GetText(), text,
+ false);
+ }
}
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 b7a5c72..cddb57e 100644
--- a/chrome/browser/ui/gtk/location_bar_view_gtk.cc
+++ b/chrome/browser/ui/gtk/location_bar_view_gtk.cc
@@ -627,18 +627,13 @@ void LocationBarViewGtk::ShowFirstRunBubble(FirstRun::BubbleType bubble_type) {
}
void LocationBarViewGtk::SetSuggestedText(const string16& text) {
- if (CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kInstantAutocompleteImmediately)) {
- // 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()) {
- location_entry_->model()->FinalizeInstantQuery(
- location_entry_->GetText(), text, false);
- }
- } else {
- location_entry_->SetInstantSuggestion(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()) {
+ location_entry_->model()->FinalizeInstantQuery(
+ location_entry_->GetText(), text, false);
}
}
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 8dc3a25..fd84c69 100644
--- a/chrome/browser/ui/views/location_bar/location_bar_view.cc
+++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc
@@ -1123,49 +1123,14 @@ void LocationBarView::ShowFirstRunBubble(FirstRun::BubbleType bubble_type) {
}
void LocationBarView::SetSuggestedText(const string16& input) {
- if (CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kInstantAutocompleteImmediately)) {
- // 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 (!input.empty()) {
- location_entry_->model()->FinalizeInstantQuery(
- location_entry_->GetText(), input, false);
- }
- return;
+ // 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 (!input.empty()) {
+ location_entry_->model()->FinalizeInstantQuery(location_entry_->GetText(),
+ input, false);
}
-#if defined(OS_WIN)
- // Don't show the suggested text if inline autocomplete is prevented.
- string16 text = location_entry_->model()->UseVerbatimInstant() ?
- string16() : input;
- if (!text.empty()) {
- if (!suggested_text_view_) {
- suggested_text_view_ = new SuggestedTextView(this);
- 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 (!location_entry_->IsImeComposing())
- suggested_text_view_->StartAnimation();
- } else if (suggested_text_view_) {
- delete suggested_text_view_;
- suggested_text_view_ = NULL;
- } else {
- return;
- }
-
- Layout();
- SchedulePaint();
-#else
- location_entry_->SetInstantSuggestion(input);
-#endif
}
std::wstring LocationBarView::GetInputString() const {