OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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. | |
4 | |
5 #ifndef CONTENT_BROWSER_FIND_REQUEST_MANAGER_H_ | |
6 #define CONTENT_BROWSER_FIND_REQUEST_MANAGER_H_ | |
7 | |
8 #include <set> | |
9 #include <vector> | |
10 | |
11 #include "content/public/common/stop_find_action.h" | |
12 #include "third_party/WebKit/public/web/WebFindOptions.h" | |
13 #include "ui/gfx/geometry/rect.h" | |
14 #include "ui/gfx/geometry/rect_f.h" | |
15 | |
16 namespace content { | |
17 | |
18 class RenderFrameHost; | |
19 class WebContentsImpl; | |
20 | |
21 // FindRequestManager manages all of the find-in-page requests/replies | |
22 // initiated/received through a WebContents. It coordinates searching across | |
23 // multiple (potentially out-of-process) frames, handles the aggregation of find | |
24 // results from each frame, and facilitates active match traversal. It is | |
25 // instantiated once per WebContents, and is owned by that WebContents. | |
26 // | |
27 // TODO(paulmeyer): FindRequestManager is currently incomplete and does not do | |
28 // all of these things yet, but will soon. | |
29 class FindRequestManager { | |
30 public: | |
31 explicit FindRequestManager(WebContentsImpl* web_contents); | |
32 ~FindRequestManager(); | |
33 | |
34 // Initiates a find operation for |search_text| with the options specified in | |
35 // |options|. |request_id| uniquely identifies the find request. | |
36 void Find(int request_id, | |
37 const base::string16& search_text, | |
38 const blink::WebFindOptions& options); | |
39 | |
40 // Stops the active find session and clears the general highlighting of the | |
41 // matches. |action| determines whether the last active match (if any) will be | |
42 // activated, cleared, or remain highlighted. | |
43 void StopFinding(StopFindAction action); | |
44 | |
45 // Called when a reply is received from a frame with the results from a | |
46 // find request. | |
47 void OnFindReply(RenderFrameHost* rfh, | |
48 int request_id, | |
49 int number_of_matches, | |
50 const gfx::Rect& selection_rect, | |
51 int active_match_ordinal, | |
52 bool final_update); | |
53 | |
54 #if defined(OS_ANDROID) | |
55 // Selects and zooms to the find result nearest to the point (x,y) defined in | |
56 // find-in-page coordinates. | |
57 void ActivateNearestFindResult(float x, float y); | |
58 | |
59 // Requests the rects of the current find matches from the renderer process. | |
60 void RequestFindMatchRects(int current_version); | |
61 | |
62 // Called when a reply is received in response to a request for find match | |
63 // rects. | |
64 void OnFindMatchRectsReply(RenderFrameHost* rfh, | |
65 int version, | |
66 const std::vector<gfx::RectF>& rects, | |
67 const gfx::RectF& active_rect); | |
68 #endif | |
69 | |
70 private: | |
71 // The request data for a single find request. | |
72 struct FindRequest { | |
73 // The find request ID that uniquely identifies this find request. | |
74 int id; | |
75 | |
76 // The text that is being searched for in this find request. | |
77 base::string16 search_text; | |
78 | |
79 // The set of find options in effect for this find request. | |
80 blink::WebFindOptions options; | |
81 }; | |
82 | |
83 // Send a find IPC containing the find request |request| to the RenderFrame | |
84 // associated with |rfh|. | |
85 void SendFindIPC(FindRequest request, RenderFrameHost* rfh); | |
ncarter (slow)
2016/04/11 21:27:35
Usually a struct like this would be passed by cons
paulmeyer
2016/04/12 17:54:25
Right, I didn't do that because this function will
| |
86 | |
87 // Send a stop finding IPC to the RenderFrame associated with |rfh|. | |
88 void SendStopFindingIPC(StopFindAction action, RenderFrameHost* rfh) const; | |
89 | |
90 // Reset all of the per-session state for a new find-in-page session. | |
91 void Reset(const FindRequest& initial_request); | |
92 | |
93 // Send the find results (as they currently are) to the WebContents. | |
94 void NotifyFindReply(int request_id, bool final_update) const; | |
95 | |
96 #if defined(OS_ANDROID) | |
97 // Request the latest find match rects from a frame. | |
98 void SendFindMatchRectsIPC(RenderFrameHost* rfh); | |
99 | |
100 // State related to FindMatchRects requests. | |
101 struct FindMatchRectsState { | |
102 // The latest find match rects version known by the requester. | |
103 int request_version; | |
104 } match_rects_; | |
105 #endif | |
106 | |
107 // The WebContents that owns this FindRequestManager. | |
108 WebContentsImpl* const contents_; | |
109 | |
110 // The request ID of the initial find request in the current find-in-page | |
111 // session, which uniquely identifies this session. Request IDs are included | |
112 // in all find-related IPCs, which allows reply IPCs containing results from | |
113 // previous sessions (with |request_id| < |current_session_id_|) to be easily | |
114 // identified and ignored. | |
115 int current_session_id_; | |
116 | |
117 // The current find request. | |
118 FindRequest current_request_; | |
119 | |
120 // The total number of matches found in the current find-in-page session. | |
121 int number_of_matches_; | |
122 | |
123 // The overall active match ordinal for the current find-in-page session. | |
124 int active_match_ordinal_; | |
125 | |
126 // The rectangle around the active match, in screen coordinates. | |
127 gfx::Rect selection_rect_; | |
128 }; | |
129 | |
130 } // namespace content | |
131 | |
132 #endif // CONTENT_BROWSER_FIND_REQUEST_MANAGER_H_ | |
OLD | NEW |