OLD | NEW |
| (Empty) |
1 // Copyright 2015 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 COMPONENTS_WEB_VIEW_FIND_CONTROLLER_H_ | |
6 #define COMPONENTS_WEB_VIEW_FIND_CONTROLLER_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include <vector> | |
11 | |
12 #include "base/macros.h" | |
13 #include "base/memory/weak_ptr.h" | |
14 #include "components/web_view/local_find_options.h" | |
15 #include "components/web_view/public/interfaces/web_view.mojom.h" | |
16 | |
17 namespace web_view { | |
18 | |
19 class FindControllerDelegate; | |
20 class Frame; | |
21 | |
22 // Contains all the find code used by WebViewImpl. | |
23 class FindController { | |
24 public: | |
25 FindController(FindControllerDelegate* delegate); | |
26 ~FindController(); | |
27 | |
28 // Starts a find session looking for |search_text|. This method will first | |
29 // scan through frames one by one to look for the first instance of | |
30 // |search_text|, and return the data through | |
31 // OnFindInPageSelectionUpdated(). If found, it will highlight all instances | |
32 // of the text and report the final total count through | |
33 // FindInPageMatchCountUpdated(). | |
34 void Find(const std::string& search_text, bool forward_direction); | |
35 | |
36 // Unhighlights all find instances on the page. | |
37 void StopFinding(); | |
38 | |
39 void OnFindInFrameCountUpdated(int32_t request_id, | |
40 Frame* frame, | |
41 int32_t count, | |
42 bool final_update); | |
43 void OnFindInPageSelectionUpdated(int32_t request_id, | |
44 Frame* frame, | |
45 int32_t active_match_ordinal); | |
46 | |
47 void DidDestroyFrame(Frame* frame); | |
48 | |
49 private: | |
50 struct MatchData { | |
51 int count; | |
52 bool final_update; | |
53 }; | |
54 | |
55 // Callback method invoked by Find(). | |
56 void OnContinueFinding(int32_t request_id, | |
57 const std::string& search_string, | |
58 LocalFindOptions options, | |
59 uint32_t starting_frame, | |
60 uint32_t current_frame, | |
61 bool found); | |
62 | |
63 // Returns the next Frame that we want to Find() on. This method will start | |
64 // iterating, forward or backwards, from current_frame, and will return | |
65 // nullptr once it has gone entirely around the framelist and has returned to | |
66 // starting_frame. If |current_frame| doesn't exist, returns nullptr to | |
67 // terminate the search process. | |
68 Frame* GetNextFrameToSearch(uint32_t starting_frame, | |
69 uint32_t current_frame, | |
70 bool forward); | |
71 | |
72 // Returns an iterator into |find_frames_in_order_|. Implementation detail of | |
73 // GetNextFrameToSearch(). | |
74 std::vector<Frame*>::iterator GetFrameIteratorById(uint32_t frame_id); | |
75 | |
76 // Our owner. | |
77 FindControllerDelegate* delegate_; | |
78 | |
79 // A list of Frames in traversal order to be searched. | |
80 std::vector<Frame*> find_frames_in_order_; | |
81 | |
82 // Monotonically increasing find id. | |
83 int find_request_id_counter_; | |
84 | |
85 // Current find session number. We keep track of this to prevent recording | |
86 // stale callbacks. | |
87 int current_find_request_id_; | |
88 | |
89 // The current string we are/just finished searching for. This is used to | |
90 // figure out if this is a Find or a FindNext operation (FindNext should not | |
91 // increase the request id). | |
92 std::string find_text_; | |
93 | |
94 // The string we searched for before |find_text_|. | |
95 std::string previous_find_text_; | |
96 | |
97 // The current callback data from various frames. | |
98 std::map<Frame*, MatchData> returned_find_data_; | |
99 | |
100 // We keep track of the current frame with the selection. | |
101 uint32_t frame_with_selection_; | |
102 | |
103 base::WeakPtrFactory<FindController> weak_ptr_factory_; | |
104 | |
105 DISALLOW_COPY_AND_ASSIGN(FindController); | |
106 }; | |
107 | |
108 } // namespace web_view | |
109 | |
110 #endif // COMPONENTS_WEB_VIEW_FIND_CONTROLLER_H_ | |
OLD | NEW |