diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-14 15:53:13 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-14 15:53:13 +0000 |
commit | c07cfb808dbd642bb3385f974be296797bd34524 (patch) | |
tree | 2834f7923f749d5fdc1246888ca7caf5b0cf507f /chrome/browser/find_bar_controller.cc | |
parent | a68b966e94845efaa30dae71f4ca7c324eba57b9 (diff) | |
download | chromium_src-c07cfb808dbd642bb3385f974be296797bd34524.zip chromium_src-c07cfb808dbd642bb3385f974be296797bd34524.tar.gz chromium_src-c07cfb808dbd642bb3385f974be296797bd34524.tar.bz2 |
Add match count text to the GTK find bar. This also makes the bar wider.
The match count text doesn't currently show up realiably because the data in
the find reply is bad. I believe this is bug 11761.
The clicker checking code has been moved to the cross-platform
FindBarController so it doesn't have to be duplicated for each platform.
This also add IntToString16. I didnt add all the variants now. The *Wstring
versions should all eventually be changed to string16.
http://crbug.com/11750
Review URL: http://codereview.chromium.org/114023
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16058 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/find_bar_controller.cc')
-rw-r--r-- | chrome/browser/find_bar_controller.cc | 104 |
1 files changed, 63 insertions, 41 deletions
diff --git a/chrome/browser/find_bar_controller.cc b/chrome/browser/find_bar_controller.cc index 087cb5a..2d1a457 100644 --- a/chrome/browser/find_bar_controller.cc +++ b/chrome/browser/find_bar_controller.cc @@ -11,7 +11,9 @@ #include "chrome/browser/tab_contents/tab_contents.h" FindBarController::FindBarController(FindBar* find_bar) - : find_bar_(find_bar), tab_contents_(NULL) { + : find_bar_(find_bar), + tab_contents_(NULL), + last_reported_matchcount_(0) { } FindBarController::~FindBarController() { @@ -68,45 +70,45 @@ void FindBarController::ChangeTabContents(TabContents* contents) { find_bar_->Hide(false); } - if (tab_contents_) { - NotificationService::current()->AddObserver( - this, NotificationType::FIND_RESULT_AVAILABLE, - Source<TabContents>(tab_contents_)); - NotificationService::current()->AddObserver( - this, NotificationType::NAV_ENTRY_COMMITTED, - Source<NavigationController>(&tab_contents_->controller())); - - // 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); - - if (tab_contents_->find_ui_active()) { - // A tab with a visible find bar just got selected and we need to show the - // find bar but without animation since it was already animated into its - // visible state. We also want to reset the window location so that - // we don't surprise the user by popping up to the left for no apparent - // reason. - gfx::Rect new_pos = find_bar_->GetDialogPosition(gfx::Rect()); - find_bar_->SetDialogPosition(new_pos, false); - - // Only modify focus and selection if Find is active, otherwise the Find - // Bar will interfere with user input. - find_bar_->SetFocusAndSelection(); - } - - find_bar_->UpdateUIForFindResult(tab_contents_->find_result(), - tab_contents_->find_text()); + if (!tab_contents_) + return; + + NotificationService::current()->AddObserver( + this, NotificationType::FIND_RESULT_AVAILABLE, + Source<TabContents>(tab_contents_)); + NotificationService::current()->AddObserver( + this, NotificationType::NAV_ENTRY_COMMITTED, + Source<NavigationController>(&tab_contents_->controller())); + + // 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); + + if (tab_contents_->find_ui_active()) { + // A tab with a visible find bar just got selected and we need to show the + // find bar but without animation since it was already animated into its + // visible state. We also want to reset the window location so that + // we don't surprise the user by popping up to the left for no apparent + // reason. + gfx::Rect new_pos = find_bar_->GetDialogPosition(gfx::Rect()); + find_bar_->SetDialogPosition(new_pos, false); + + // Only modify focus and selection if Find is active, otherwise the Find + // Bar will interfere with user input. + find_bar_->SetFocusAndSelection(); } + + UpdateFindBarForCurrentResult(); } //////////////////////////////////////////////////////////////////////////////// @@ -119,8 +121,7 @@ void FindBarController::Observe(NotificationType type, // Don't update for notifications from TabContentses other than the one we // are actively tracking. if (Source<TabContents>(source).ptr() == tab_contents_) { - find_bar_->UpdateUIForFindResult(tab_contents_->find_result(), - tab_contents_->find_text()); + UpdateFindBarForCurrentResult(); if (tab_contents_->find_result().final_update() && tab_contents_->find_result().number_of_matches() == 0) { find_bar_->AudibleAlert(); @@ -149,3 +150,24 @@ void FindBarController::Observe(NotificationType type, } } } + +void FindBarController::UpdateFindBarForCurrentResult() { + const FindNotificationDetails& find_result = tab_contents_->find_result(); + + // Avoid bug 894389: When a new search starts (and finds something) it reports + // an interim match count result of 1 before the scoping effort starts. This + // is to provide feedback as early as possible that we will find something. + // As you add letters to the search term, this creates a flashing effect when + // we briefly show "1 of 1" matches because there is a slight delay until + // the scoping effort starts updating the match count. We avoid this flash by + // ignoring interim results of 1 if we already have a positive number. + if (find_result.number_of_matches() > -1) { + if (last_reported_matchcount_ > 0 && + find_result.number_of_matches() == 1 && + !find_result.final_update()) + return; // Don't let interim result override match count. + last_reported_matchcount_ = find_result.number_of_matches(); + } + + find_bar_->UpdateUIForFindResult(find_result, tab_contents_->find_text()); +} |