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