Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / find_bar / find_tab_helper.h
blobdfe18662335c87f7e59a4c36346f3351f4b831c5
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_FIND_BAR_FIND_TAB_HELPER_H_
6 #define CHROME_BROWSER_UI_FIND_BAR_FIND_TAB_HELPER_H_
8 #include "chrome/browser/ui/find_bar/find_bar_controller.h"
9 #include "chrome/browser/ui/find_bar/find_notification_details.h"
10 #include "content/public/browser/web_contents_observer.h"
11 #include "content/public/browser/web_contents_user_data.h"
12 #include "ui/gfx/range/range.h"
14 namespace gfx {
15 class RectF;
18 // Per-tab find manager. Handles dealing with the life cycle of find sessions.
19 class FindTabHelper : public content::WebContentsObserver,
20 public content::WebContentsUserData<FindTabHelper> {
21 public:
22 ~FindTabHelper() override;
24 // Starts the Find operation by calling StartFinding on the Tab. This function
25 // can be called from the outside as a result of hot-keys, so it uses the
26 // last remembered search string as specified with set_find_string(). This
27 // function does not block while a search is in progress. The controller will
28 // receive the results through the notification mechanism. See Observe(...)
29 // for details.
30 void StartFinding(base::string16 search_string,
31 bool forward_direction,
32 bool case_sensitive);
34 // Stops the current Find operation.
35 void StopFinding(FindBarController::SelectionAction selection_action);
37 // When the user commits to a search query or jumps from one result
38 // to the next, move accessibility focus to the next find result.
39 void ActivateFindInPageResultForAccessibility();
41 // Accessors/Setters for find_ui_active_.
42 bool find_ui_active() const { return find_ui_active_; }
43 void set_find_ui_active(bool find_ui_active) {
44 find_ui_active_ = find_ui_active;
47 // Setter for find_op_aborted_.
48 void set_find_op_aborted(bool find_op_aborted) {
49 find_op_aborted_ = find_op_aborted;
52 // Used _only_ by testing to get or set the current request ID.
53 int current_find_request_id() { return current_find_request_id_; }
54 void set_current_find_request_id(int current_find_request_id) {
55 current_find_request_id_ = current_find_request_id;
58 // Accessor for find_text_. Used to determine if this WebContents has any
59 // active searches.
60 base::string16 find_text() const { return find_text_; }
62 // Accessor for the previous search we issued.
63 base::string16 previous_find_text() const { return previous_find_text_; }
65 gfx::Range selected_range() const { return selected_range_; }
66 void set_selected_range(const gfx::Range& selected_range) {
67 selected_range_ = selected_range;
70 // Accessor for find_result_.
71 const FindNotificationDetails& find_result() const {
72 return last_search_result_;
75 #if defined(OS_ANDROID)
76 // Selects and zooms to the find result nearest to the point (x,y)
77 // defined in find-in-page coordinates.
78 void ActivateNearestFindResult(float x, float y);
80 // Asks the renderer to send the rects of the current find matches.
81 void RequestFindMatchRects(int current_version);
82 #endif
84 void HandleFindReply(int request_id,
85 int number_of_matches,
86 const gfx::Rect& selection_rect,
87 int active_match_ordinal,
88 bool final_update);
90 private:
91 explicit FindTabHelper(content::WebContents* web_contents);
92 friend class content::WebContentsUserData<FindTabHelper>;
94 // Each time a search request comes in we assign it an id before passing it
95 // over the IPC so that when the results come in we can evaluate whether we
96 // still care about the results of the search (in some cases we don't because
97 // the user has issued a new search).
98 static int find_request_id_counter_;
100 // True if the Find UI is active for this Tab.
101 bool find_ui_active_;
103 // True if a Find operation was aborted. This can happen if the Find box is
104 // closed or if the search term inside the Find box is erased while a search
105 // is in progress. This can also be set if a page has been reloaded, and will
106 // on FindNext result in a full Find operation so that the highlighting for
107 // inactive matches can be repainted.
108 bool find_op_aborted_;
110 // This variable keeps track of what the most recent request id is.
111 int current_find_request_id_;
113 // The current string we are/just finished searching for. This is used to
114 // figure out if this is a Find or a FindNext operation (FindNext should not
115 // increase the request id).
116 base::string16 find_text_;
118 // The string we searched for before |find_text_|.
119 base::string16 previous_find_text_;
121 // The selection within the text.
122 gfx::Range selected_range_;
124 // Whether the last search was case sensitive or not.
125 bool last_search_case_sensitive_;
127 // The last find result. This object contains details about the number of
128 // matches, the find selection rectangle, etc. The UI can access this
129 // information to build its presentation.
130 FindNotificationDetails last_search_result_;
132 DISALLOW_COPY_AND_ASSIGN(FindTabHelper);
135 #endif // CHROME_BROWSER_UI_FIND_BAR_FIND_TAB_HELPER_H_