OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 26 matching lines...) Expand all Loading... |
37 #include "public/platform/WebFloatPoint.h" | 37 #include "public/platform/WebFloatPoint.h" |
38 #include "public/platform/WebFloatRect.h" | 38 #include "public/platform/WebFloatRect.h" |
39 #include "public/platform/WebRect.h" | 39 #include "public/platform/WebRect.h" |
40 #include "public/web/WebFindOptions.h" | 40 #include "public/web/WebFindOptions.h" |
41 #include "wtf/PassOwnPtr.h" | 41 #include "wtf/PassOwnPtr.h" |
42 #include "wtf/PassRefPtr.h" | 42 #include "wtf/PassRefPtr.h" |
43 #include "wtf/Vector.h" | 43 #include "wtf/Vector.h" |
44 #include "wtf/text/WTFString.h" | 44 #include "wtf/text/WTFString.h" |
45 | 45 |
46 namespace blink { | 46 namespace blink { |
| 47 |
47 class Range; | 48 class Range; |
48 } | |
49 | |
50 namespace blink { | |
51 class WebLocalFrameImpl; | 49 class WebLocalFrameImpl; |
52 | 50 |
53 template <typename T> class WebVector; | 51 template <typename T> class WebVector; |
54 | 52 |
55 class TextFinder { | 53 class TextFinder { |
56 public: | 54 public: |
57 static PassOwnPtr<TextFinder> create(WebLocalFrameImpl& ownerFrame); | 55 static PassOwnPtr<TextFinder> create(WebLocalFrameImpl& ownerFrame); |
58 | 56 |
59 bool find( | 57 bool find( |
60 int identifier, const WebString& searchText, const WebFindOptions&, | 58 int identifier, const WebString& searchText, const WebFindOptions&, |
(...skipping 10 matching lines...) Expand all Loading... |
71 void findMatchRects(WebVector<WebFloatRect>&); | 69 void findMatchRects(WebVector<WebFloatRect>&); |
72 int selectNearestFindMatch(const WebFloatPoint&, WebRect* selectionRect); | 70 int selectNearestFindMatch(const WebFloatPoint&, WebRect* selectionRect); |
73 | 71 |
74 // Returns which frame has an active match. This function should only be | 72 // Returns which frame has an active match. This function should only be |
75 // called on the main frame, as it is the only frame keeping track. Returned | 73 // called on the main frame, as it is the only frame keeping track. Returned |
76 // value can be 0 if no frame has an active match. | 74 // value can be 0 if no frame has an active match. |
77 WebLocalFrameImpl* activeMatchFrame() const { return m_currentActiveMatchFra
me; } | 75 WebLocalFrameImpl* activeMatchFrame() const { return m_currentActiveMatchFra
me; } |
78 | 76 |
79 // Returns the active match in the current frame. Could be a null range if | 77 // Returns the active match in the current frame. Could be a null range if |
80 // the local frame has no active match. | 78 // the local frame has no active match. |
81 blink::Range* activeMatch() const { return m_activeMatch.get(); } | 79 Range* activeMatch() const { return m_activeMatch.get(); } |
82 | 80 |
83 void flushCurrentScoping(); | 81 void flushCurrentScoping(); |
84 | 82 |
85 void resetActiveMatch() { m_activeMatch = nullptr; } | 83 void resetActiveMatch() { m_activeMatch = nullptr; } |
86 | 84 |
87 int totalMatchCount() const { return m_totalMatchCount; } | 85 int totalMatchCount() const { return m_totalMatchCount; } |
88 bool scopingInProgress() const { return m_scopingInProgress; } | 86 bool scopingInProgress() const { return m_scopingInProgress; } |
89 void increaseMarkerVersion() { ++m_findMatchMarkersVersion; } | 87 void increaseMarkerVersion() { ++m_findMatchMarkersVersion; } |
90 | 88 |
91 ~TextFinder(); | 89 ~TextFinder(); |
92 | 90 |
93 class FindMatch { | 91 class FindMatch { |
94 ALLOW_ONLY_INLINE_ALLOCATION(); | 92 ALLOW_ONLY_INLINE_ALLOCATION(); |
95 public: | 93 public: |
96 RefPtrWillBeMember<blink::Range> m_range; | 94 RefPtrWillBeMember<Range> m_range; |
97 | 95 |
98 // 1-based index within this frame. | 96 // 1-based index within this frame. |
99 int m_ordinal; | 97 int m_ordinal; |
100 | 98 |
101 // In find-in-page coordinates. | 99 // In find-in-page coordinates. |
102 // Lazily calculated by updateFindMatchRects. | 100 // Lazily calculated by updateFindMatchRects. |
103 blink::FloatRect m_rect; | 101 FloatRect m_rect; |
104 | 102 |
105 FindMatch(PassRefPtrWillBeRawPtr<blink::Range>, int ordinal); | 103 FindMatch(PassRefPtrWillBeRawPtr<Range>, int ordinal); |
106 | 104 |
107 void trace(blink::Visitor*); | 105 void trace(Visitor*); |
108 }; | 106 }; |
109 | 107 |
110 private: | 108 private: |
111 class DeferredScopeStringMatches; | 109 class DeferredScopeStringMatches; |
112 friend class DeferredScopeStringMatches; | 110 friend class DeferredScopeStringMatches; |
113 | 111 |
114 explicit TextFinder(WebLocalFrameImpl& ownerFrame); | 112 explicit TextFinder(WebLocalFrameImpl& ownerFrame); |
115 | 113 |
116 // Notifies the delegate about a new selection rect. | 114 // Notifies the delegate about a new selection rect. |
117 void reportFindInPageSelection( | 115 void reportFindInPageSelection( |
118 const WebRect& selectionRect, int activeMatchOrdinal, int identifier); | 116 const WebRect& selectionRect, int activeMatchOrdinal, int identifier); |
119 | 117 |
120 // Clear the find-in-page matches cache forcing rects to be fully | 118 // Clear the find-in-page matches cache forcing rects to be fully |
121 // calculated again next time updateFindMatchRects is called. | 119 // calculated again next time updateFindMatchRects is called. |
122 void clearFindMatchesCache(); | 120 void clearFindMatchesCache(); |
123 | 121 |
124 // Check if the activeMatchFrame still exists in the frame tree. | 122 // Check if the activeMatchFrame still exists in the frame tree. |
125 bool isActiveMatchFrameValid() const; | 123 bool isActiveMatchFrameValid() const; |
126 | 124 |
127 // Return the index in the find-in-page cache of the match closest to the | 125 // Return the index in the find-in-page cache of the match closest to the |
128 // provided point in find-in-page coordinates, or -1 in case of error. | 126 // provided point in find-in-page coordinates, or -1 in case of error. |
129 // The squared distance to the closest match is returned in the distanceSqua
red parameter. | 127 // The squared distance to the closest match is returned in the distanceSqua
red parameter. |
130 int nearestFindMatch(const blink::FloatPoint&, float& distanceSquared); | 128 int nearestFindMatch(const FloatPoint&, float& distanceSquared); |
131 | 129 |
132 // Select a find-in-page match marker in the current frame using a cache | 130 // Select a find-in-page match marker in the current frame using a cache |
133 // match index returned by nearestFindMatch. Returns the ordinal of the new | 131 // match index returned by nearestFindMatch. Returns the ordinal of the new |
134 // selected match or -1 in case of error. Also provides the bounding box of | 132 // selected match or -1 in case of error. Also provides the bounding box of |
135 // the marker in window coordinates if selectionRect is not null. | 133 // the marker in window coordinates if selectionRect is not null. |
136 int selectFindMatch(unsigned index, WebRect* selectionRect); | 134 int selectFindMatch(unsigned index, WebRect* selectionRect); |
137 | 135 |
138 // Compute and cache the rects for FindMatches if required. | 136 // Compute and cache the rects for FindMatches if required. |
139 // Rects are automatically invalidated in case of content size changes, | 137 // Rects are automatically invalidated in case of content size changes, |
140 // propagating the invalidation to child frames. | 138 // propagating the invalidation to child frames. |
141 void updateFindMatchRects(); | 139 void updateFindMatchRects(); |
142 | 140 |
143 // Append the find-in-page match rects of the current frame to the provided
vector. | 141 // Append the find-in-page match rects of the current frame to the provided
vector. |
144 void appendFindMatchRects(Vector<WebFloatRect>& frameRects); | 142 void appendFindMatchRects(Vector<WebFloatRect>& frameRects); |
145 | 143 |
146 // Add a WebKit TextMatch-highlight marker to nodes in a range. | 144 // Add a WebKit TextMatch-highlight marker to nodes in a range. |
147 void addMarker(blink::Range*, bool activeMatch); | 145 void addMarker(Range*, bool activeMatch); |
148 | 146 |
149 // Sets the markers within a range as active or inactive. | 147 // Sets the markers within a range as active or inactive. |
150 void setMarkerActive(blink::Range*, bool active); | 148 void setMarkerActive(Range*, bool active); |
151 | 149 |
152 // Returns the ordinal of the first match in the frame specified. This | 150 // Returns the ordinal of the first match in the frame specified. This |
153 // function enumerates the frames, starting with the main frame and up to (b
ut | 151 // function enumerates the frames, starting with the main frame and up to (b
ut |
154 // not including) the frame passed in as a parameter and counts how many | 152 // not including) the frame passed in as a parameter and counts how many |
155 // matches have been found. | 153 // matches have been found. |
156 int ordinalOfFirstMatchForFrame(WebLocalFrameImpl*) const; | 154 int ordinalOfFirstMatchForFrame(WebLocalFrameImpl*) const; |
157 | 155 |
158 // Determines whether the scoping effort is required for a particular frame. | 156 // Determines whether the scoping effort is required for a particular frame. |
159 // It is not necessary if the frame is invisible, for example, or if this | 157 // It is not necessary if the frame is invisible, for example, or if this |
160 // is a repeat search that already returned nothing last time the same prefi
x | 158 // is a repeat search that already returned nothing last time the same prefi
x |
(...skipping 29 matching lines...) Expand all Loading... |
190 // Returns the ordinal of the first match in the owner frame. | 188 // Returns the ordinal of the first match in the owner frame. |
191 int ordinalOfFirstMatch() const; | 189 int ordinalOfFirstMatch() const; |
192 | 190 |
193 WebLocalFrameImpl& m_ownerFrame; | 191 WebLocalFrameImpl& m_ownerFrame; |
194 | 192 |
195 // A way for the main frame to keep track of which frame has an active | 193 // A way for the main frame to keep track of which frame has an active |
196 // match. Should be 0 for all other frames. | 194 // match. Should be 0 for all other frames. |
197 WebLocalFrameImpl* m_currentActiveMatchFrame; | 195 WebLocalFrameImpl* m_currentActiveMatchFrame; |
198 | 196 |
199 // The range of the active match for the current frame. | 197 // The range of the active match for the current frame. |
200 RefPtrWillBePersistent<blink::Range> m_activeMatch; | 198 RefPtrWillBePersistent<Range> m_activeMatch; |
201 | 199 |
202 // The index of the active match for the current frame. | 200 // The index of the active match for the current frame. |
203 int m_activeMatchIndexInCurrentFrame; | 201 int m_activeMatchIndexInCurrentFrame; |
204 | 202 |
205 // The scoping effort can time out and we need to keep track of where we | 203 // The scoping effort can time out and we need to keep track of where we |
206 // ended our last search so we can continue from where we left of. | 204 // ended our last search so we can continue from where we left of. |
207 // | 205 // |
208 // This range is collapsed to the start position of the last successful | 206 // This range is collapsed to the start position of the last successful |
209 // search; the new search should start from the next adjacent position. | 207 // search; the new search should start from the next adjacent position. |
210 RefPtrWillBePersistent<blink::Range> m_resumeScopingFromRange; | 208 RefPtrWillBePersistent<Range> m_resumeScopingFromRange; |
211 | 209 |
212 // Keeps track of the last string this frame searched for. This is used for | 210 // Keeps track of the last string this frame searched for. This is used for |
213 // short-circuiting searches in the following scenarios: When a frame has | 211 // short-circuiting searches in the following scenarios: When a frame has |
214 // been searched and returned 0 results, we don't need to search that frame | 212 // been searched and returned 0 results, we don't need to search that frame |
215 // again if the user is just adding to the search (making it more specific). | 213 // again if the user is just adding to the search (making it more specific). |
216 WTF::String m_lastSearchString; | 214 WTF::String m_lastSearchString; |
217 | 215 |
218 // Keeps track of how many matches this frame has found so far, so that we | 216 // Keeps track of how many matches this frame has found so far, so that we |
219 // don't loose count between scoping efforts, and is also used (in conjuncti
on | 217 // don't loose count between scoping efforts, and is also used (in conjuncti
on |
220 // with m_lastSearchString) to figure out if we need to search the frame aga
in. | 218 // with m_lastSearchString) to figure out if we need to search the frame aga
in. |
(...skipping 22 matching lines...) Expand all Loading... |
243 | 241 |
244 // Version number incremented on the main frame only whenever the document | 242 // Version number incremented on the main frame only whenever the document |
245 // find-in-page match markers change. It should be 0 for all other frames. | 243 // find-in-page match markers change. It should be 0 for all other frames. |
246 int m_findMatchMarkersVersion; | 244 int m_findMatchMarkersVersion; |
247 | 245 |
248 // Local cache of the find match markers currently displayed for this frame. | 246 // Local cache of the find match markers currently displayed for this frame. |
249 WillBePersistentHeapVector<FindMatch> m_findMatchesCache; | 247 WillBePersistentHeapVector<FindMatch> m_findMatchesCache; |
250 | 248 |
251 // Contents size when find-in-page match rects were last computed for this | 249 // Contents size when find-in-page match rects were last computed for this |
252 // frame's cache. | 250 // frame's cache. |
253 blink::IntSize m_contentsSizeForCurrentFindMatchRects; | 251 IntSize m_contentsSizeForCurrentFindMatchRects; |
254 | 252 |
255 // This flag is used by the scoping effort to determine if we need to figure | 253 // This flag is used by the scoping effort to determine if we need to figure |
256 // out which rectangle is the active match. Once we find the active | 254 // out which rectangle is the active match. Once we find the active |
257 // rectangle we clear this flag. | 255 // rectangle we clear this flag. |
258 bool m_locatingActiveRect; | 256 bool m_locatingActiveRect; |
259 | 257 |
260 // Keeps track of whether there is an scoping effort ongoing in the frame. | 258 // Keeps track of whether there is an scoping effort ongoing in the frame. |
261 bool m_scopingInProgress; | 259 bool m_scopingInProgress; |
262 | 260 |
263 // Keeps track of whether the last find request completed its scoping effort | 261 // Keeps track of whether the last find request completed its scoping effort |
264 // without finding any matches in this frame. | 262 // without finding any matches in this frame. |
265 bool m_lastFindRequestCompletedWithNoMatches; | 263 bool m_lastFindRequestCompletedWithNoMatches; |
266 | 264 |
267 // Determines if the rects in the find-in-page matches cache of this frame | 265 // Determines if the rects in the find-in-page matches cache of this frame |
268 // are invalid and should be recomputed. | 266 // are invalid and should be recomputed. |
269 bool m_findMatchRectsAreValid; | 267 bool m_findMatchRectsAreValid; |
270 }; | 268 }; |
271 | 269 |
272 } // namespace blink | 270 } // namespace blink |
273 | 271 |
274 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::TextFinder::FindMatch); | 272 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::TextFinder::FindMatch); |
275 | 273 |
276 #endif | 274 #endif |
OLD | NEW |