summaryrefslogtreecommitdiff
path: root/chromium/components/find_in_page
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-12 14:27:29 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-13 09:35:20 +0000
commitc30a6232df03e1efbd9f3b226777b07e087a1122 (patch)
treee992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/components/find_in_page
parent7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff)
downloadqtwebengine-chromium-85-based.tar.gz
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/components/find_in_page')
-rw-r--r--chromium/components/find_in_page/android/find_in_page_bridge.cc3
-rw-r--r--chromium/components/find_in_page/find_tab_helper.cc36
-rw-r--r--chromium/components/find_in_page/find_tab_helper.h12
3 files changed, 26 insertions, 25 deletions
diff --git a/chromium/components/find_in_page/android/find_in_page_bridge.cc b/chromium/components/find_in_page/android/find_in_page_bridge.cc
index fac7ff269e4..2346f0d29cd 100644
--- a/chromium/components/find_in_page/android/find_in_page_bridge.cc
+++ b/chromium/components/find_in_page/android/find_in_page_bridge.cc
@@ -36,7 +36,8 @@ void FindInPageBridge::StartFinding(JNIEnv* env,
find_in_page::FindTabHelper::FromWebContents(web_contents_)
->StartFinding(
base::android::ConvertJavaStringToUTF16(env, search_string),
- forward_direction, case_sensitive);
+ forward_direction, case_sensitive,
+ true /* find_next_if_selection_matches */);
}
void FindInPageBridge::StopFinding(JNIEnv* env,
diff --git a/chromium/components/find_in_page/find_tab_helper.cc b/chromium/components/find_in_page/find_tab_helper.cc
index b94f420dc1e..a3beda34257 100644
--- a/chromium/components/find_in_page/find_tab_helper.cc
+++ b/chromium/components/find_in_page/find_tab_helper.cc
@@ -11,9 +11,7 @@
#include "build/build_config.h"
#include "components/find_in_page/find_result_observer.h"
#include "components/find_in_page/find_types.h"
-#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_frame_host.h"
-#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/stop_find_action.h"
#include "third_party/blink/public/mojom/frame/find_in_page.mojom.h"
@@ -27,7 +25,7 @@ namespace find_in_page {
int FindTabHelper::find_request_id_counter_ = -1;
FindTabHelper::FindTabHelper(WebContents* web_contents)
- : content::WebContentsObserver(web_contents),
+ : web_contents_(web_contents),
current_find_request_id_(find_request_id_counter_++),
current_find_session_id_(current_find_request_id_) {}
@@ -47,6 +45,7 @@ void FindTabHelper::RemoveObserver(FindResultObserver* observer) {
void FindTabHelper::StartFinding(base::string16 search_string,
bool forward_direction,
bool case_sensitive,
+ bool find_next_if_selection_matches,
bool run_synchronously_for_testing) {
// Remove the carriage return character, which generally isn't in web content.
const base::char16 kInvalidChars[] = {'\r', 0};
@@ -64,18 +63,13 @@ void FindTabHelper::StartFinding(base::string16 search_string,
// Keep track of the previous search.
previous_find_text_ = find_text_;
- // This is a FindNext operation if we are searching for the same text again,
- // or if the passed in search text is empty (FindNext keyboard shortcut). The
- // exception to this is if the Find was aborted (then we don't want FindNext
- // because the highlighting has been cleared and we need it to reappear). We
- // therefore treat FindNext after an aborted Find operation as a full fledged
- // Find.
- bool find_next = (find_text_ == search_string || search_string.empty()) &&
- (last_search_case_sensitive_ == case_sensitive) &&
- !find_op_aborted_;
+ // NB: search_string will be empty when using the FindNext keyboard shortcut.
+ bool new_session = (find_text_ != search_string && !search_string.empty()) ||
+ (last_search_case_sensitive_ != case_sensitive) ||
+ find_op_aborted_;
current_find_request_id_ = find_request_id_counter_++;
- if (!find_next)
+ if (new_session)
current_find_session_id_ = current_find_request_id_;
if (!search_string.empty())
@@ -91,10 +85,10 @@ void FindTabHelper::StartFinding(base::string16 search_string,
auto options = blink::mojom::FindOptions::New();
options->forward = forward_direction;
options->match_case = case_sensitive;
- options->find_next = find_next;
+ options->new_session = new_session;
+ options->find_next_if_selection_matches = find_next_if_selection_matches;
options->run_synchronously_for_testing = run_synchronously_for_testing;
- web_contents()->Find(current_find_request_id_, find_text_,
- std::move(options));
+ web_contents_->Find(current_find_request_id_, find_text_, std::move(options));
}
void FindTabHelper::StopFinding(SelectionAction selection_action) {
@@ -128,11 +122,11 @@ void FindTabHelper::StopFinding(SelectionAction selection_action) {
NOTREACHED();
action = content::STOP_FIND_ACTION_KEEP_SELECTION;
}
- web_contents()->StopFinding(action);
+ web_contents_->StopFinding(action);
}
void FindTabHelper::ActivateFindInPageResultForAccessibility() {
- web_contents()->GetMainFrame()->ActivateFindInPageResultForAccessibility(
+ web_contents_->GetMainFrame()->ActivateFindInPageResultForAccessibility(
current_find_request_id_);
}
@@ -148,13 +142,13 @@ base::string16 FindTabHelper::GetInitialSearchText() {
#if defined(OS_ANDROID)
void FindTabHelper::ActivateNearestFindResult(float x, float y) {
if (!find_op_aborted_ && !find_text_.empty()) {
- web_contents()->ActivateNearestFindResult(x, y);
+ web_contents_->ActivateNearestFindResult(x, y);
}
}
void FindTabHelper::RequestFindMatchRects(int current_version) {
if (!find_op_aborted_ && !find_text_.empty())
- web_contents()->RequestFindMatchRects(current_version);
+ web_contents_->RequestFindMatchRects(current_version);
}
#endif
@@ -184,7 +178,7 @@ void FindTabHelper::HandleFindReply(int request_id,
FindNotificationDetails(request_id, number_of_matches, selection,
active_match_ordinal, final_update);
for (auto& observer : observers_)
- observer.OnFindResultAvailable(web_contents());
+ observer.OnFindResultAvailable(web_contents_);
}
}
diff --git a/chromium/components/find_in_page/find_tab_helper.h b/chromium/components/find_in_page/find_tab_helper.h
index f5f8fd09ae9..73586ea5499 100644
--- a/chromium/components/find_in_page/find_tab_helper.h
+++ b/chromium/components/find_in_page/find_tab_helper.h
@@ -8,7 +8,6 @@
#include "base/strings/string16.h"
#include "build/build_config.h"
#include "components/find_in_page/find_notification_details.h"
-#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
#include "ui/gfx/range/range.h"
@@ -18,8 +17,7 @@ class FindResultObserver;
enum class SelectionAction;
// Per-tab find manager. Handles dealing with the life cycle of find sessions.
-class FindTabHelper : public content::WebContentsObserver,
- public content::WebContentsUserData<FindTabHelper> {
+class FindTabHelper : public content::WebContentsUserData<FindTabHelper> {
public:
// The delegate tracks search text state.
class Delegate {
@@ -48,9 +46,14 @@ class FindTabHelper : public content::WebContentsObserver,
// function does not block while a search is in progress. The controller will
// receive the results through the notification mechanism. See Observe(...)
// for details.
+ //
+ // If |find_next_if_selection_matches| is true and the search results in an
+ // exact match of the selection, keep searching. It should generally be set to
+ // true unless you're starting a new find based on the selection.
void StartFinding(base::string16 search_string,
bool forward_direction,
bool case_sensitive,
+ bool find_next_if_selection_matches,
bool run_synchronously_for_testing = false);
// Stops the current Find operation.
@@ -126,6 +129,9 @@ class FindTabHelper : public content::WebContentsObserver,
// the user has issued a new search).
static int find_request_id_counter_;
+ // The WebContents which owns this helper.
+ content::WebContents* web_contents_ = nullptr;
+
// True if the Find UI is active for this Tab.
bool find_ui_active_ = false;