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