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

Side by Side Diff: chrome/browser/ui/find_bar/find_tab_helper.cc

Issue 1913543002: Fix for problem with activating find-in-page match via find tickbar. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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_tab_helper.h ('k') | content/browser/find_request_manager.cc » ('j') | 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_tab_helper.h" 5 #include "chrome/browser/ui/find_bar/find_tab_helper.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 15 matching lines...) Expand all
26 DEFINE_WEB_CONTENTS_USER_DATA_KEY(FindTabHelper); 26 DEFINE_WEB_CONTENTS_USER_DATA_KEY(FindTabHelper);
27 27
28 // static 28 // static
29 int FindTabHelper::find_request_id_counter_ = -1; 29 int FindTabHelper::find_request_id_counter_ = -1;
30 30
31 FindTabHelper::FindTabHelper(WebContents* web_contents) 31 FindTabHelper::FindTabHelper(WebContents* web_contents)
32 : content::WebContentsObserver(web_contents), 32 : content::WebContentsObserver(web_contents),
33 find_ui_active_(false), 33 find_ui_active_(false),
34 find_op_aborted_(false), 34 find_op_aborted_(false),
35 current_find_request_id_(find_request_id_counter_++), 35 current_find_request_id_(find_request_id_counter_++),
36 current_find_session_id_(current_find_request_id_),
36 last_search_case_sensitive_(false), 37 last_search_case_sensitive_(false),
37 last_search_result_() { 38 last_search_result_() {
38 } 39 }
39 40
40 FindTabHelper::~FindTabHelper() { 41 FindTabHelper::~FindTabHelper() {
41 } 42 }
42 43
43 void FindTabHelper::StartFinding(base::string16 search_string, 44 void FindTabHelper::StartFinding(base::string16 search_string,
44 bool forward_direction, 45 bool forward_direction,
45 bool case_sensitive) { 46 bool case_sensitive) {
(...skipping 26 matching lines...) Expand all
72 // or if the passed in search text is empty (FindNext keyboard shortcut). The 73 // or if the passed in search text is empty (FindNext keyboard shortcut). The
73 // exception to this is if the Find was aborted (then we don't want FindNext 74 // exception to this is if the Find was aborted (then we don't want FindNext
74 // because the highlighting has been cleared and we need it to reappear). We 75 // because the highlighting has been cleared and we need it to reappear). We
75 // therefore treat FindNext after an aborted Find operation as a full fledged 76 // therefore treat FindNext after an aborted Find operation as a full fledged
76 // Find. 77 // Find.
77 bool find_next = (find_text_ == search_string || search_string.empty()) && 78 bool find_next = (find_text_ == search_string || search_string.empty()) &&
78 (last_search_case_sensitive_ == case_sensitive) && 79 (last_search_case_sensitive_ == case_sensitive) &&
79 !find_op_aborted_; 80 !find_op_aborted_;
80 81
81 current_find_request_id_ = find_request_id_counter_++; 82 current_find_request_id_ = find_request_id_counter_++;
83 if (!find_next)
84 current_find_session_id_ = current_find_request_id_;
82 85
83 if (!search_string.empty()) 86 if (!search_string.empty())
84 find_text_ = search_string; 87 find_text_ = search_string;
85 last_search_case_sensitive_ = case_sensitive; 88 last_search_case_sensitive_ = case_sensitive;
86 89
87 find_op_aborted_ = false; 90 find_op_aborted_ = false;
88 91
89 // Keep track of what the last search was across the tabs. 92 // Keep track of what the last search was across the tabs.
90 Profile* profile = 93 Profile* profile =
91 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 94 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 if (!find_op_aborted_ && !find_text_.empty()) 152 if (!find_op_aborted_ && !find_text_.empty())
150 web_contents()->RequestFindMatchRects(current_version); 153 web_contents()->RequestFindMatchRects(current_version);
151 } 154 }
152 #endif 155 #endif
153 156
154 void FindTabHelper::HandleFindReply(int request_id, 157 void FindTabHelper::HandleFindReply(int request_id,
155 int number_of_matches, 158 int number_of_matches,
156 const gfx::Rect& selection_rect, 159 const gfx::Rect& selection_rect,
157 int active_match_ordinal, 160 int active_match_ordinal,
158 bool final_update) { 161 bool final_update) {
159 // Ignore responses for requests that have been aborted. 162 // Ignore responses for requests that have been aborted. Ignore responses for
160 // Ignore responses for requests other than the one we have most recently 163 // requests from previous sessiona. That way we won't act on stale results
ncarter (slow) 2016/04/25 18:02:38 "sessiona"
161 // issued. That way we won't act on stale results when the user has 164 // when the user has already typed in another query.
162 // already typed in another query. 165 if (!find_op_aborted_ && request_id >= current_find_session_id_) {
163 if (!find_op_aborted_ && request_id == current_find_request_id_) {
164 if (number_of_matches == -1) 166 if (number_of_matches == -1)
165 number_of_matches = last_search_result_.number_of_matches(); 167 number_of_matches = last_search_result_.number_of_matches();
166 if (active_match_ordinal == -1) 168 if (active_match_ordinal == -1)
167 active_match_ordinal = last_search_result_.active_match_ordinal(); 169 active_match_ordinal = last_search_result_.active_match_ordinal();
168 170
169 gfx::Rect selection = selection_rect; 171 gfx::Rect selection = selection_rect;
170 if (final_update && active_match_ordinal == 0) 172 if (final_update && active_match_ordinal == 0)
171 selection = gfx::Rect(); 173 selection = gfx::Rect();
172 else if (selection_rect.IsEmpty()) 174 else if (selection_rect.IsEmpty())
173 selection = last_search_result_.selection_rect(); 175 selection = last_search_result_.selection_rect();
174 176
175 // Notify the UI, automation and any other observers that a find result was 177 // Notify the UI, automation and any other observers that a find result was
176 // found. 178 // found.
177 last_search_result_ = FindNotificationDetails( 179 last_search_result_ = FindNotificationDetails(
178 request_id, number_of_matches, selection, active_match_ordinal, 180 request_id, number_of_matches, selection, active_match_ordinal,
179 final_update); 181 final_update);
180 content::NotificationService::current()->Notify( 182 content::NotificationService::current()->Notify(
181 chrome::NOTIFICATION_FIND_RESULT_AVAILABLE, 183 chrome::NOTIFICATION_FIND_RESULT_AVAILABLE,
182 content::Source<WebContents>(web_contents()), 184 content::Source<WebContents>(web_contents()),
183 content::Details<FindNotificationDetails>(&last_search_result_)); 185 content::Details<FindNotificationDetails>(&last_search_result_));
184 } 186 }
185 } 187 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/find_bar/find_tab_helper.h ('k') | content/browser/find_request_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698