diff options
author | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-05 17:08:07 +0000 |
---|---|---|
committer | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-05 17:08:07 +0000 |
commit | 726bdbd79ab870b8f2d1b37ba72895cb68447a14 (patch) | |
tree | 0d7504dc32dff8f2cd48c9973a1bc9f41518787d /chrome/browser/find_bar_controller.cc | |
parent | 1456dad368c8998eaee08a30965c41ae55a32274 (diff) | |
download | chromium_src-726bdbd79ab870b8f2d1b37ba72895cb68447a14.zip chromium_src-726bdbd79ab870b8f2d1b37ba72895cb68447a14.tar.gz chromium_src-726bdbd79ab870b8f2d1b37ba72895cb68447a14.tar.bz2 |
Fix prepopulate value for Find and add browser tests for it.
Notable changes:
FindBarController now sets the prepopulate text during Show for the Find dialog, to fix regression 40121. It also checks not just the current find string (find_text()) but the previous one also (previous_find_text()) in MaybeSetPrepopulateText() because the current find string is blanked out when closing the Find window. And TabContents now makes sure previous_find_text() is never overwritten with an empty find_text value (to prevent the last search from being cleared if you open Find, close it without searching and open it again).
This changelist also adds automated tests for the codepaths above, which results in adding a GetFindText method to the FindBarTesting interface, to allow the tests to check what string is being shown to the user when the Find box opens.
BUG=40121
TEST=FindInPageControllerTest.Prepopulate* (three tests)
Review URL: http://codereview.chromium.org/1560012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43620 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/find_bar_controller.cc')
-rw-r--r-- | chrome/browser/find_bar_controller.cc | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/chrome/browser/find_bar_controller.cc b/chrome/browser/find_bar_controller.cc index b56b929..643e777 100644 --- a/chrome/browser/find_bar_controller.cc +++ b/chrome/browser/find_bar_controller.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -28,6 +28,8 @@ void FindBarController::Show() { // Only show the animation if we're not already showing a find bar for the // selected TabContents. if (!tab_contents_->find_ui_active()) { + MaybeSetPrepopulateText(); + tab_contents_->set_find_ui_active(true); find_bar_->Show(true); } @@ -74,25 +76,7 @@ void FindBarController::ChangeTabContents(TabContents* contents) { registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, Source<NavigationController>(&tab_contents_->controller())); -#if !defined(OS_MACOSX) - // Find out what we should show in the find text box. Usually, this will be - // the last search in this tab, but if no search has been issued in this tab - // we use the last search string (from any tab). - string16 find_string = tab_contents_->find_text(); - if (find_string.empty()) - find_string = tab_contents_->find_prepopulate_text(); - - // Update the find bar with existing results and search text, regardless of - // whether or not the find bar is visible, so that if it's subsequently - // shown it is showing the right state for this tab. We update the find text - // _first_ since the FindBarView checks its emptiness to see if it should - // clear the result count display when there's nothing in the box. - find_bar_->SetFindText(find_string); -#else - // Having a per-tab find_string is not compatible with OS X's find pasteboard, - // so we always have the same find text in all find bars. This is done through - // the find pasteboard mechanism, so don't set the text here. -#endif + MaybeSetPrepopulateText(); if (tab_contents_->find_ui_active()) { // A tab with a visible find bar just got selected and we need to show the @@ -209,3 +193,27 @@ void FindBarController::UpdateFindBarForCurrentResult() { find_bar_->UpdateUIForFindResult(find_result, tab_contents_->find_text()); } + +void FindBarController::MaybeSetPrepopulateText() { +#if !defined(OS_MACOSX) + // Find out what we should show in the find text box. Usually, this will be + // the last search in this tab, but if no search has been issued in this tab + // we use the last search string (from any tab). + string16 find_string = tab_contents_->find_text(); + if (find_string.empty()) + find_string = tab_contents_->previous_find_text(); + if (find_string.empty()) + find_string = tab_contents_->find_prepopulate_text(); + + // Update the find bar with existing results and search text, regardless of + // whether or not the find bar is visible, so that if it's subsequently + // shown it is showing the right state for this tab. We update the find text + // _first_ since the FindBarView checks its emptiness to see if it should + // clear the result count display when there's nothing in the box. + find_bar_->SetFindText(find_string); +#else + // Having a per-tab find_string is not compatible with OS X's find pasteboard, + // so we always have the same find text in all find bars. This is done through + // the find pasteboard mechanism, so don't set the text here. +#endif +} |