Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5574)

Unified Diff: chrome/browser/ui/find_bar/find_bar_controller.cc

Issue 2839713002: Fix extraneous beeps on empty page search. (Closed)
Patch Set: Clear notification state when find session ends. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/find_bar/find_bar_controller.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/find_bar/find_bar_controller.cc
diff --git a/chrome/browser/ui/find_bar/find_bar_controller.cc b/chrome/browser/ui/find_bar/find_bar_controller.cc
index db9cfcefd123182f20140dccf9165747410969e3..b5a089d5b759ffcd8775e66bbb8c5994c438aea7 100644
--- a/chrome/browser/ui/find_bar/find_bar_controller.cc
+++ b/chrome/browser/ui/find_bar/find_bar_controller.cc
@@ -58,6 +58,10 @@ void FindBarController::EndFindSession(SelectionAction selection_action,
ResultAction result_action) {
find_bar_->Hide(true);
+ // If the user searches again for this string, it should notify if the result
+ // comes back empty again.
+ last_reported_empty_search_.clear();
+
// |web_contents_| can be NULL for a number of reasons, for example when the
// tab is closing. We must guard against that case. See issue 8030.
if (web_contents_) {
@@ -139,14 +143,27 @@ void FindBarController::Observe(int type,
// are actively tracking.
if (content::Source<WebContents>(source).ptr() == web_contents_) {
UpdateFindBarForCurrentResult();
+
+ // A final update can occur multiple times if the document changes.
if (find_tab_helper->find_result().final_update() &&
find_tab_helper->find_result().number_of_matches() == 0) {
const base::string16& last_search =
find_tab_helper->previous_find_text();
const base::string16& current_search = find_tab_helper->find_text();
- if (!base::StartsWith(last_search, current_search,
- base::CompareCase::SENSITIVE)) {
- find_bar_->AudibleAlert();
+
+ // Make sure only the first "final update" of any search results in a
+ // notification.
+ if (current_search != last_reported_empty_search_) {
+ // True if the current search is a substring of the previous one, such
+ // as if the user has backspaced.
+ const bool is_contracted_search = base::StartsWith(
+ last_search, current_search, base::CompareCase::SENSITIVE);
+
+ // Keep track of the last notified search string, even if the
+ // notification itself is elided.
+ last_reported_empty_search_ = current_search;
+ if (!is_contracted_search)
+ find_bar_->AudibleAlert();
Peter Kasting 2017/04/24 22:25:46 Nit: It's simpler, and I would find it clearer, to
Sigurður Ásgeirsson 2017/04/26 16:53:36 I like "alerted_search_", much better - thanks! N
Peter Kasting 2017/04/26 17:22:12 I actually found "is contracted search" a really c
}
}
}
« no previous file with comments | « chrome/browser/ui/find_bar/find_bar_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698