diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-11 02:20:21 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-11 02:20:21 +0000 |
commit | 87fae51359ae20a37a3f24f55bc715f8b3013761 (patch) | |
tree | 2061ea03ca659787099cc1a4ff83963fd6d76fbc /chrome | |
parent | 82aa72dfc7fb4aebea7857ce0c896434f18167bb (diff) | |
download | chromium_src-87fae51359ae20a37a3f24f55bc715f8b3013761.zip chromium_src-87fae51359ae20a37a3f24f55bc715f8b3013761.tar.gz chromium_src-87fae51359ae20a37a3f24f55bc715f8b3013761.tar.bz2 |
Find bar fixes:
- prefer previous find from same tab contents over overall most recent find when re-opening find bar
- GTK + Windows: always update find bar view text if it doesn't match the search results.
TEST=see bug for repro steps
BUG=30006
Review URL: http://codereview.chromium.org/482015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34322 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/gtk/find_bar_gtk.cc | 15 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.cc | 12 | ||||
-rw-r--r-- | chrome/browser/views/find_bar_host_browsertest.cc | 35 | ||||
-rw-r--r-- | chrome/browser/views/find_bar_view.cc | 10 |
4 files changed, 52 insertions, 20 deletions
diff --git a/chrome/browser/gtk/find_bar_gtk.cc b/chrome/browser/gtk/find_bar_gtk.cc index 6cfbc51..0ee2137 100644 --- a/chrome/browser/gtk/find_bar_gtk.cc +++ b/chrome/browser/gtk/find_bar_gtk.cc @@ -333,12 +333,12 @@ void FindBarGtk::MoveWindowIfNecessary(const gfx::Rect& selection_rect, } void FindBarGtk::SetFindText(const string16& find_text) { - std::string text_entry_utf8 = UTF16ToUTF8(find_text); + std::string find_text_utf8 = UTF16ToUTF8(find_text); // Ignore the "changed" signal handler because programatically setting the // text should not fire a "changed" event. ignore_changed_signal_ = true; - gtk_entry_set_text(GTK_ENTRY(text_entry_), text_entry_utf8.c_str()); + gtk_entry_set_text(GTK_ENTRY(text_entry_), find_text_utf8.c_str()); ignore_changed_signal_ = false; } @@ -356,20 +356,17 @@ void FindBarGtk::UpdateUIForFindResult(const FindNotificationDetails& result, if (result.number_of_matches() > 0) focus_store_.Store(NULL); - std::string text_entry_utf8 = UTF16ToUTF8(find_text); + std::string find_text_utf8 = UTF16ToUTF8(find_text); bool have_valid_range = result.number_of_matches() != -1 && result.active_match_ordinal() != -1; - // If we don't have any results and something was passed in, then that means - // someone pressed F3 while the Find box was closed. In that case we need to - // repopulate the Find box with what was passed in. - std::string search_string(gtk_entry_get_text(GTK_ENTRY(text_entry_))); - if (search_string.empty() && !text_entry_utf8.empty()) { + std::string entry_text(gtk_entry_get_text(GTK_ENTRY(text_entry_))); + if (entry_text != find_text_utf8) { SetFindText(find_text); gtk_entry_select_region(GTK_ENTRY(text_entry_), 0, -1); } - if (!search_string.empty() && have_valid_range) { + if (!find_text.empty() && have_valid_range) { gtk_label_set_text(GTK_LABEL(match_count_label_), l10n_util::GetStringFUTF8(IDS_FIND_IN_PAGE_COUNT, IntToString16(result.active_match_ordinal()), diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 30b393d..2d62549 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -246,7 +246,6 @@ TabContents::TabContents(Profile* profile, find_ui_active_(false), find_op_aborted_(false), current_find_request_id_(find_request_id_counter_++), - find_text_(), last_search_case_sensitive_(false), last_search_prepopulate_text_(NULL), last_search_result_(), @@ -1020,10 +1019,14 @@ void TabContents::StartFinding(string16 search_string, // If search_string is empty, it means FindNext was pressed with a keyboard // shortcut so unless we have something to search for we return early. if (search_string.empty() && find_text_.empty()) { - if (last_search_prepopulate_text_->empty()) + // Try the last thing we searched for on this tab, then the last thing + // searched for on any tab. + if (!previous_find_text_.empty()) + search_string = previous_find_text_; + else if (!last_search_prepopulate_text_->empty()) + search_string = *last_search_prepopulate_text_; + else return; - // Try whatever we searched for last in any tab. - search_string = *last_search_prepopulate_text_; } // Keep track of the previous search. @@ -1061,6 +1064,7 @@ void TabContents::StopFinding(bool clear_selection) { // by the user, but the UI has not been dismissed. if (!clear_selection) find_ui_active_ = false; + previous_find_text_ = find_text_; find_text_.clear(); find_op_aborted_ = true; last_search_result_ = FindNotificationDetails(); diff --git a/chrome/browser/views/find_bar_host_browsertest.cc b/chrome/browser/views/find_bar_host_browsertest.cc index f160da0..0cb112f 100644 --- a/chrome/browser/views/find_bar_host_browsertest.cc +++ b/chrome/browser/views/find_bar_host_browsertest.cc @@ -765,3 +765,38 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, RestartSearchFromF3) { EXPECT_EQ(1, FindInPageWchar(tab, L"", kFwd, kIgnoreCase, &ordinal)); EXPECT_EQ(1, ordinal); } + +// When re-opening the find bar with F3, the find bar should be re-populated +// with the last search from the same tab rather than the last overall search. +// http://crbug.com/30006 +IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PreferPreviousSearch) { + HTTPTestServer* server = StartHTTPServer(); + + DropdownBarHost::disable_animations_during_testing_ = true; + + // First we navigate to any page. + GURL url = server->TestServerPageW(kSimplePage); + ui_test_utils::NavigateToURL(browser(), url); + + // Find "Default". + int ordinal = 0; + TabContents* tab1 = browser()->GetSelectedTabContents(); + EXPECT_EQ(1, FindInPageWchar(tab1, L"Default", kFwd, kIgnoreCase, &ordinal)); + + // Create a second tab. + browser()->AddTabWithURL(url, GURL(), PageTransition::TYPED, true, -1, + false, NULL); + browser()->SelectTabContentsAt(1, false); + TabContents* tab2 = browser()->GetSelectedTabContents(); + EXPECT_NE(tab1, tab2); + + // Find "given". + FindInPageWchar(tab2, L"given", kFwd, kIgnoreCase, &ordinal); + + // Switch back to first tab. + browser()->SelectTabContentsAt(0, false); + browser()->GetFindBarController()->EndFindSession(); + // Simulate F3. + ui_test_utils::FindInPage(tab1, string16(), kFwd, kIgnoreCase, &ordinal); + EXPECT_EQ(tab1->find_text(), WideToUTF16(L"Default")); +} diff --git a/chrome/browser/views/find_bar_view.cc b/chrome/browser/views/find_bar_view.cc index 2cb2de7..0c57f32 100644 --- a/chrome/browser/views/find_bar_view.cc +++ b/chrome/browser/views/find_bar_view.cc @@ -172,16 +172,12 @@ void FindBarView::UpdateForResult(const FindNotificationDetails& result, bool have_valid_range = result.number_of_matches() != -1 && result.active_match_ordinal() != -1; - // If we don't have any results and something was passed in, then that means - // someone pressed F3 while the Find box was closed. In that case we need to - // repopulate the Find box with what was passed in. - string16 search_string = find_text_->text(); - if (search_string.empty() && !find_text.empty()) { + if (find_text_->text() != find_text) { find_text_->SetText(find_text); find_text_->SelectAll(); } - if (!search_string.empty() && have_valid_range) { + if (!find_text.empty() && have_valid_range) { match_count_text_->SetText( l10n_util::GetStringF(IDS_FIND_IN_PAGE_COUNT, IntToWString(result.active_match_ordinal()), @@ -192,7 +188,7 @@ void FindBarView::UpdateForResult(const FindNotificationDetails& result, match_count_text_->SetText(std::wstring()); } - if (search_string.empty() || result.number_of_matches() > 0 || + if (find_text.empty() || result.number_of_matches() > 0 || !have_valid_range) { // If there was no text entered or there were results, the match_count label // should have a normal background color. We also reset the background if |