Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #ifndef IOS_CHROME_BROWSER_FIND_IN_PAGE_FIND_TAB_HELPER_H_ | 5 #ifndef IOS_CHROME_BROWSER_FIND_IN_PAGE_FIND_TAB_HELPER_H_ |
| 6 #define IOS_CHROME_BROWSER_FIND_IN_PAGE_FIND_TAB_HELPER_H_ | 6 #define IOS_CHROME_BROWSER_FIND_IN_PAGE_FIND_TAB_HELPER_H_ |
| 7 | 7 |
| 8 #include <Foundation/Foundation.h> | |
| 9 | |
| 10 #include "base/ios/block_types.h" | |
| 11 #import "base/mac/scoped_nsobject.h" | |
| 8 #include "base/macros.h" | 12 #include "base/macros.h" |
| 9 #include "ios/web/public/web_state/web_state_observer.h" | 13 #include "ios/web/public/web_state/web_state_observer.h" |
| 10 #import "ios/web/public/web_state/web_state_user_data.h" | 14 #import "ios/web/public/web_state/web_state_user_data.h" |
| 11 | 15 |
| 12 @class FindInPageController; | 16 @class FindInPageController; |
| 13 @protocol FindInPageControllerDelegate; | 17 @protocol FindInPageControllerDelegate; |
| 18 @class FindInPageModel; | |
| 19 | |
| 20 typedef void (^FindInPageCompletionBlock)(FindInPageModel*); | |
| 14 | 21 |
| 15 // Adds support for the "Find in page" feature. | 22 // Adds support for the "Find in page" feature. |
| 16 class FindTabHelper : public web::WebStateObserver, | 23 class FindTabHelper : public web::WebStateObserver, |
| 17 public web::WebStateUserData<FindTabHelper> { | 24 public web::WebStateUserData<FindTabHelper> { |
| 18 public: | 25 public: |
| 26 enum FindDirection { | |
| 27 FORWARD, | |
| 28 REVERSE, | |
| 29 }; | |
| 30 | |
| 19 // Creates a FindTabHelper and attaches it to the given |web_state|. | 31 // Creates a FindTabHelper and attaches it to the given |web_state|. |
| 20 // |controller_delegate| can be nil. | 32 // |controller_delegate| can be nil. |
| 21 static void CreateForWebState( | 33 static void CreateForWebState( |
| 22 web::WebState* web_state, | 34 web::WebState* web_state, |
| 23 id<FindInPageControllerDelegate> controller_delegate); | 35 id<FindInPageControllerDelegate> controller_delegate); |
| 24 | 36 |
| 25 // Returns the find in page controller. | 37 // Starts an asynchronous Find operation that will call the given completion |
| 26 FindInPageController* GetController(); | 38 // handler with results. Always searches in the FORWARD direction. |
| 39 void StartFinding(NSString* search_string, | |
| 40 FindInPageCompletionBlock completion); | |
| 41 | |
| 42 // Runs an asynchronous Find operation that will call the given completion | |
| 43 // handler with results. Uses the previously remembered search string and | |
| 44 // searches in the given |direction|. | |
|
stkhapugin
2017/03/14 14:06:15
Specify how this and other methods can be called w
rohitrao (ping after 24h)
2017/03/14 14:50:53
Added a note about highlighting to the method comm
| |
| 45 void ContinueFinding(FindDirection direction, | |
| 46 FindInPageCompletionBlock completion); | |
| 47 | |
| 48 // Stops any running find operations and runs the given completion block. | |
| 49 void StopFinding(ProceduralBlock completion); | |
| 50 | |
| 51 // Returns the FindInPageModel that contains the latest find results. | |
| 52 FindInPageModel* GetFindResult() const; | |
| 53 | |
| 54 // Returns true if the currently loaded page supports Find in Page. | |
| 55 bool CurrentPageSupportsFindInPage() const; | |
| 56 | |
| 57 // Returns true if the Find in Page UI is currently visible. | |
| 58 bool IsFindUIActive() const; | |
| 59 | |
| 60 // Marks the Find in Page UI as visible or not. This method does not directly | |
| 61 // show or hide the UI. It simply acts as a marker for whether or not the UI | |
| 62 // is visible. | |
| 63 void SetFindUIActive(bool active); | |
| 64 | |
| 65 // Saves the current find text to persistent storage. | |
| 66 void PersistSearchTerm(); | |
| 67 | |
| 68 // Restores the current find text from persistent storage. | |
| 69 void RestoreSearchTerm(); | |
| 27 | 70 |
| 28 private: | 71 private: |
| 72 friend class FindTabHelperTest; | |
| 73 | |
| 29 FindTabHelper(web::WebState* web_state, | 74 FindTabHelper(web::WebState* web_state, |
| 30 id<FindInPageControllerDelegate> controller_delegate); | 75 id<FindInPageControllerDelegate> controller_delegate); |
| 31 ~FindTabHelper() override; | 76 ~FindTabHelper() override; |
| 32 | 77 |
| 33 // web::WebStateObserver. | 78 // web::WebStateObserver. |
| 34 void NavigationItemCommitted( | 79 void NavigationItemCommitted( |
| 35 const web::LoadCommittedDetails& load_details) override; | 80 const web::LoadCommittedDetails& load_details) override; |
| 36 void WebStateDestroyed() override; | 81 void WebStateDestroyed() override; |
| 37 | 82 |
| 38 // The ObjC find in page controller. | 83 // The ObjC find in page controller. |
| 39 FindInPageController* controller_; | 84 base::scoped_nsobject<FindInPageController> controller_; |
| 40 | 85 |
| 41 DISALLOW_COPY_AND_ASSIGN(FindTabHelper); | 86 DISALLOW_COPY_AND_ASSIGN(FindTabHelper); |
| 42 }; | 87 }; |
| 43 | 88 |
| 44 #endif // IOS_CHROME_BROWSER_FIND_IN_PAGE_FIND_TAB_HELPER_H_ | 89 #endif // IOS_CHROME_BROWSER_FIND_IN_PAGE_FIND_TAB_HELPER_H_ |
| OLD | NEW |