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

Unified Diff: ios/chrome/browser/find_in_page/find_tab_helper.mm

Issue 2724683002: [ios] Moves the Find in Page APIs into FindTabHelper. (Closed)
Patch Set: Review Created 3 years, 9 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
Index: ios/chrome/browser/find_in_page/find_tab_helper.mm
diff --git a/ios/chrome/browser/find_in_page/find_tab_helper.mm b/ios/chrome/browser/find_in_page/find_tab_helper.mm
index 9892712a9bfd8e3ad43c91c8bd96df6d5ca0d5b8..fd68d43ca261c938c245065ec4fa8c886725e36d 100644
--- a/ios/chrome/browser/find_in_page/find_tab_helper.mm
+++ b/ios/chrome/browser/find_in_page/find_tab_helper.mm
@@ -5,6 +5,7 @@
#import "ios/chrome/browser/find_in_page/find_tab_helper.h"
#import "ios/chrome/browser/find_in_page/find_in_page_controller.h"
+#import "ios/chrome/browser/find_in_page/find_in_page_model.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
@@ -25,21 +26,75 @@ void FindTabHelper::CreateForWebState(
FindTabHelper::FindTabHelper(
web::WebState* web_state,
- id<FindInPageControllerDelegate> controller_delegate) {
- controller_ =
- [[FindInPageController alloc] initWithWebState:web_state
- delegate:controller_delegate];
+ id<FindInPageControllerDelegate> controller_delegate)
+ : web::WebStateObserver(web_state) {
+ controller_.reset([[FindInPageController alloc]
+ initWithWebState:web_state
+ delegate:controller_delegate]);
}
FindTabHelper::~FindTabHelper() {}
-FindInPageController* FindTabHelper::GetController() {
- return controller_;
+void FindTabHelper::StartFinding(NSString* search_term,
+ FindInPageCompletionBlock completion) {
+ [controller_ findStringInPage:search_term
+ completionHandler:^{
+ FindInPageModel* model = controller_.get().findInPageModel;
+ completion(model);
+ }];
+}
+
+void FindTabHelper::ContinueFinding(FindDirection direction,
+ FindInPageCompletionBlock completion) {
+ FindInPageModel* model = controller_.get().findInPageModel;
+
+ if (direction == FORWARD) {
+ [controller_ findNextStringInPageWithCompletionHandler:^{
+ completion(model);
+ }];
+
+ } else if (direction == REVERSE) {
+ [controller_ findPreviousStringInPageWithCompletionHandler:^{
+ completion(model);
+ }];
+
+ } else {
+ NOTREACHED();
+ }
+}
+
+void FindTabHelper::StopFinding(ProceduralBlock completion) {
+ [controller_ disableFindInPageWithCompletionHandler:completion];
+ SetFindUIActive(false);
+}
+
+FindInPageModel* FindTabHelper::GetFindResult() const {
+ return controller_.get().findInPageModel;
+}
+
+bool FindTabHelper::CurrentPageSupportsFindInPage() const {
+ return [controller_ canFindInPage];
+}
+
+bool FindTabHelper::IsFindUIActive() const {
+ return controller_.get().findInPageModel.enabled;
+}
+
+void FindTabHelper::SetFindUIActive(bool active) {
+ controller_.get().findInPageModel.enabled = active;
+}
+
+void FindTabHelper::PersistSearchTerm() {
+ [controller_ saveSearchTerm];
+}
+
+void FindTabHelper::RestoreSearchTerm() {
+ [controller_ restoreSearchTerm];
}
void FindTabHelper::NavigationItemCommitted(
const web::LoadCommittedDetails& load_details) {
- [controller_ disableFindInPageWithCompletionHandler:nil];
+ StopFinding(nil);
}
void FindTabHelper::WebStateDestroyed() {
« no previous file with comments | « ios/chrome/browser/find_in_page/find_tab_helper.h ('k') | ios/chrome/browser/find_in_page/find_tab_helper_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698