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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/find_bar/find_bar_controller.h" 5 #include "chrome/browser/ui/find_bar/find_bar_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 find_tab_helper->set_find_ui_active(true); 51 find_tab_helper->set_find_ui_active(true);
52 find_bar_->Show(true); 52 find_bar_->Show(true);
53 } 53 }
54 find_bar_->SetFocusAndSelection(); 54 find_bar_->SetFocusAndSelection();
55 } 55 }
56 56
57 void FindBarController::EndFindSession(SelectionAction selection_action, 57 void FindBarController::EndFindSession(SelectionAction selection_action,
58 ResultAction result_action) { 58 ResultAction result_action) {
59 find_bar_->Hide(true); 59 find_bar_->Hide(true);
60 60
61 // If the user searches again for this string, it should notify if the result
62 // comes back empty again.
63 last_reported_empty_search_.clear();
64
61 // |web_contents_| can be NULL for a number of reasons, for example when the 65 // |web_contents_| can be NULL for a number of reasons, for example when the
62 // tab is closing. We must guard against that case. See issue 8030. 66 // tab is closing. We must guard against that case. See issue 8030.
63 if (web_contents_) { 67 if (web_contents_) {
64 FindTabHelper* find_tab_helper = 68 FindTabHelper* find_tab_helper =
65 FindTabHelper::FromWebContents(web_contents_); 69 FindTabHelper::FromWebContents(web_contents_);
66 70
67 // When we hide the window, we need to notify the renderer that we are done 71 // When we hide the window, we need to notify the renderer that we are done
68 // for now, so that we can abort the scoping effort and clear all the 72 // for now, so that we can abort the scoping effort and clear all the
69 // tickmarks and highlighting. 73 // tickmarks and highlighting.
70 find_tab_helper->StopFinding(selection_action); 74 find_tab_helper->StopFinding(selection_action);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 void FindBarController::Observe(int type, 136 void FindBarController::Observe(int type,
133 const content::NotificationSource& source, 137 const content::NotificationSource& source,
134 const content::NotificationDetails& details) { 138 const content::NotificationDetails& details) {
135 FindTabHelper* find_tab_helper = 139 FindTabHelper* find_tab_helper =
136 FindTabHelper::FromWebContents(web_contents_); 140 FindTabHelper::FromWebContents(web_contents_);
137 if (type == chrome::NOTIFICATION_FIND_RESULT_AVAILABLE) { 141 if (type == chrome::NOTIFICATION_FIND_RESULT_AVAILABLE) {
138 // Don't update for notifications from WebContentses other than the one we 142 // Don't update for notifications from WebContentses other than the one we
139 // are actively tracking. 143 // are actively tracking.
140 if (content::Source<WebContents>(source).ptr() == web_contents_) { 144 if (content::Source<WebContents>(source).ptr() == web_contents_) {
141 UpdateFindBarForCurrentResult(); 145 UpdateFindBarForCurrentResult();
146
147 // A final update can occur multiple times if the document changes.
142 if (find_tab_helper->find_result().final_update() && 148 if (find_tab_helper->find_result().final_update() &&
143 find_tab_helper->find_result().number_of_matches() == 0) { 149 find_tab_helper->find_result().number_of_matches() == 0) {
144 const base::string16& last_search = 150 const base::string16& last_search =
145 find_tab_helper->previous_find_text(); 151 find_tab_helper->previous_find_text();
146 const base::string16& current_search = find_tab_helper->find_text(); 152 const base::string16& current_search = find_tab_helper->find_text();
147 if (!base::StartsWith(last_search, current_search, 153
148 base::CompareCase::SENSITIVE)) { 154 // Make sure only the first "final update" of any search results in a
149 find_bar_->AudibleAlert(); 155 // notification.
156 if (current_search != last_reported_empty_search_) {
157 // True if the current search is a substring of the previous one, such
158 // as if the user has backspaced.
159 const bool is_contracted_search = base::StartsWith(
160 last_search, current_search, base::CompareCase::SENSITIVE);
161
162 // Keep track of the last notified search string, even if the
163 // notification itself is elided.
164 last_reported_empty_search_ = current_search;
165 if (!is_contracted_search)
166 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
150 } 167 }
151 } 168 }
152 } 169 }
153 } else if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) { 170 } else if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) {
154 NavigationController* source_controller = 171 NavigationController* source_controller =
155 content::Source<NavigationController>(source).ptr(); 172 content::Source<NavigationController>(source).ptr();
156 if (source_controller == &web_contents_->GetController()) { 173 if (source_controller == &web_contents_->GetController()) {
157 content::LoadCommittedDetails* commit_details = 174 content::LoadCommittedDetails* commit_details =
158 content::Details<content::LoadCommittedDetails>(details).ptr(); 175 content::Details<content::LoadCommittedDetails>(details).ptr();
159 ui::PageTransition transition_type = 176 ui::PageTransition transition_type =
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 } 270 }
254 271
255 // Update the find bar with existing results and search text, regardless of 272 // Update the find bar with existing results and search text, regardless of
256 // whether or not the find bar is visible, so that if it's subsequently 273 // whether or not the find bar is visible, so that if it's subsequently
257 // shown it is showing the right state for this tab. We update the find text 274 // shown it is showing the right state for this tab. We update the find text
258 // _first_ since the FindBarView checks its emptiness to see if it should 275 // _first_ since the FindBarView checks its emptiness to see if it should
259 // clear the result count display when there's nothing in the box. 276 // clear the result count display when there's nothing in the box.
260 find_bar_->SetFindTextAndSelectedRange(find_string, 277 find_bar_->SetFindTextAndSelectedRange(find_string,
261 find_tab_helper->selected_range()); 278 find_tab_helper->selected_range());
262 } 279 }
OLDNEW
« 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