Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1171)

Side by Side Diff: third_party/WebKit/Source/web/TextFinder.h

Issue 1959183002: Multi-Process Find-in-Page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Disabled tests on Android Release because of crbug.com/615291. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 template <typename T> class WebVector; 53 template <typename T> class WebVector;
54 54
55 class WEB_EXPORT TextFinder final : public GarbageCollectedFinalized<TextFinder> { 55 class WEB_EXPORT TextFinder final : public GarbageCollectedFinalized<TextFinder> {
56 WTF_MAKE_NONCOPYABLE(TextFinder); 56 WTF_MAKE_NONCOPYABLE(TextFinder);
57 public: 57 public:
58 static TextFinder* create(WebLocalFrameImpl& ownerFrame); 58 static TextFinder* create(WebLocalFrameImpl& ownerFrame);
59 59
60 bool find( 60 bool find(
61 int identifier, const WebString& searchText, const WebFindOptions&, 61 int identifier, const WebString& searchText, const WebFindOptions&,
62 bool wrapWithinFrame, WebRect* selectionRect, bool* activeNow = nullptr) ; 62 bool wrapWithinFrame, WebRect* selectionRect, bool* activeNow = nullptr) ;
63 void clearActiveFindMatch();
63 void stopFindingAndClearSelection(); 64 void stopFindingAndClearSelection();
64 void scopeStringMatches( 65 void scopeStringMatches(
65 int identifier, const WebString& searchText, const WebFindOptions&, 66 int identifier, const WebString& searchText, const WebFindOptions&,
66 bool reset); 67 bool reset);
67 void cancelPendingScopingEffort(); 68 void cancelPendingScopingEffort();
68 void increaseMatchCount(int identifier, int count); 69 void increaseMatchCount(int identifier, int count);
69 void resetMatchCount(); 70 void resetMatchCount();
70 int findMatchMarkersVersion() const { return m_findMatchMarkersVersion; } 71 int findMatchMarkersVersion() const { return m_findMatchMarkersVersion; }
71 WebFloatRect activeFindMatchRect(); 72 WebFloatRect activeFindMatchRect();
72 void findMatchRects(WebVector<WebFloatRect>&); 73 void findMatchRects(WebVector<WebFloatRect>&);
73 int selectNearestFindMatch(const WebFloatPoint&, WebRect* selectionRect); 74 int selectNearestFindMatch(const WebFloatPoint&, WebRect* selectionRect);
74 75
75 // Returns which frame has an active match. This function should only be 76 // Return the index in the find-in-page cache of the match closest to the
76 // called on the main frame, as it is the only frame keeping track. Returned 77 // provided point in find-in-page coordinates, or -1 in case of error.
77 // value can be 0 if no frame has an active match. 78 // The squared distance to the closest match is returned in the |distanceSqu ared| parameter.
78 WebLocalFrameImpl* activeMatchFrame() const { return m_currentActiveMatchFra me; } 79 int nearestFindMatch(const FloatPoint&, float* distanceSquared);
80
81 // Returns whether this frame has the active match.
82 bool activeMatchFrame() const { return m_currentActiveMatchFrame; }
79 83
80 // Returns the active match in the current frame. Could be a null range if 84 // Returns the active match in the current frame. Could be a null range if
81 // the local frame has no active match. 85 // the local frame has no active match.
82 Range* activeMatch() const { return m_activeMatch.get(); } 86 Range* activeMatch() const { return m_activeMatch.get(); }
83 87
84 void flushCurrentScoping(); 88 void flushCurrentScoping();
85 89
86 void resetActiveMatch() { m_activeMatch = nullptr; } 90 void resetActiveMatch() { m_activeMatch = nullptr; }
87 91
88 int totalMatchCount() const { return m_totalMatchCount; } 92 int totalMatchCount() const { return m_totalMatchCount; }
(...skipping 30 matching lines...) Expand all
119 // Notifies the delegate about a new selection rect. 123 // Notifies the delegate about a new selection rect.
120 void reportFindInPageSelection( 124 void reportFindInPageSelection(
121 const WebRect& selectionRect, int activeMatchOrdinal, int identifier); 125 const WebRect& selectionRect, int activeMatchOrdinal, int identifier);
122 126
123 void reportFindInPageResultToAccessibility(int identifier); 127 void reportFindInPageResultToAccessibility(int identifier);
124 128
125 // Clear the find-in-page matches cache forcing rects to be fully 129 // Clear the find-in-page matches cache forcing rects to be fully
126 // calculated again next time updateFindMatchRects is called. 130 // calculated again next time updateFindMatchRects is called.
127 void clearFindMatchesCache(); 131 void clearFindMatchesCache();
128 132
129 // Check if the activeMatchFrame still exists in the frame tree.
130 bool isActiveMatchFrameValid() const;
131
132 // Return the index in the find-in-page cache of the match closest to the
133 // provided point in find-in-page coordinates, or -1 in case of error.
134 // The squared distance to the closest match is returned in the distanceSqua red parameter.
135 int nearestFindMatch(const FloatPoint&, float& distanceSquared);
136
137 // Select a find-in-page match marker in the current frame using a cache 133 // Select a find-in-page match marker in the current frame using a cache
138 // match index returned by nearestFindMatch. Returns the ordinal of the new 134 // match index returned by nearestFindMatch. Returns the ordinal of the new
139 // selected match or -1 in case of error. Also provides the bounding box of 135 // selected match or -1 in case of error. Also provides the bounding box of
140 // the marker in window coordinates if selectionRect is not null. 136 // the marker in window coordinates if selectionRect is not null.
141 int selectFindMatch(unsigned index, WebRect* selectionRect); 137 int selectFindMatch(unsigned index, WebRect* selectionRect);
142 138
143 // Compute and cache the rects for FindMatches if required. 139 // Compute and cache the rects for FindMatches if required.
144 // Rects are automatically invalidated in case of content size changes, 140 // Rects are automatically invalidated in case of content size changes,
145 // propagating the invalidation to child frames. 141 // propagating the invalidation to child frames.
146 void updateFindMatchRects(); 142 void updateFindMatchRects();
147 143
148 // Append the find-in-page match rects of the current frame to the provided vector.
149 void appendFindMatchRects(Vector<WebFloatRect>& frameRects);
150
151 // Add a WebKit TextMatch-highlight marker to nodes in a range. 144 // Add a WebKit TextMatch-highlight marker to nodes in a range.
152 void addMarker(Range*, bool activeMatch); 145 void addMarker(Range*, bool activeMatch);
153 146
154 // Sets the markers within a range as active or inactive. Returns true if at least 147 // Sets the markers within a range as active or inactive. Returns true if at least
155 // one such marker found. 148 // one such marker found.
156 bool setMarkerActive(Range*, bool active); 149 bool setMarkerActive(Range*, bool active);
157 150
158 // Removes all markers. 151 // Removes all markers.
159 void unmarkAllTextMatches(); 152 void unmarkAllTextMatches();
160 153
161 // Returns the ordinal of the first match in the frame specified. This
162 // function enumerates the frames, starting with the main frame and up to (b ut
163 // not including) the frame passed in as a parameter and counts how many
164 // matches have been found.
165 int ordinalOfFirstMatchForFrame(WebLocalFrameImpl*) const;
166
167 // Determines whether the scoping effort is required for a particular frame. 154 // Determines whether the scoping effort is required for a particular frame.
168 // It is not necessary if the frame is invisible, for example, or if this 155 // It is not necessary if the frame is invisible, for example, or if this
169 // is a repeat search that already returned nothing last time the same prefi x 156 // is a repeat search that already returned nothing last time the same prefi x
170 // was searched. 157 // was searched.
171 bool shouldScopeMatches(const WTF::String& searchText); 158 bool shouldScopeMatches(const WTF::String& searchText);
172 159
173 // Removes the current frame from the global scoping effort and triggers any 160 // Removes the current frame from the global scoping effort and triggers any
174 // updates if appropriate. This method does not mark the scoping operation 161 // updates if appropriate. This method does not mark the scoping operation
175 // as finished. 162 // as finished.
176 void flushCurrentScopingEffort(int identifier); 163 void flushCurrentScopingEffort(int identifier);
177 164
178 // Finishes the current scoping effort and triggers any updates if appropria te. 165 // Finishes the current scoping effort and triggers any updates if appropria te.
179 void finishCurrentScopingEffort(int identifier); 166 void finishCurrentScopingEffort(int identifier);
180 167
181 // Queue up a deferred call to scopeStringMatches. 168 // Queue up a deferred call to scopeStringMatches.
182 void scopeStringMatchesSoon( 169 void scopeStringMatchesSoon(
183 int identifier, const WebString& searchText, const WebFindOptions&, 170 int identifier, const WebString& searchText, const WebFindOptions&,
184 bool reset); 171 bool reset);
185 172
186 // Called by a DeferredScopeStringMatches instance. 173 // Called by a DeferredScopeStringMatches instance.
187 void callScopeStringMatches( 174 void callScopeStringMatches(
188 DeferredScopeStringMatches*, int identifier, const WebString& searchText , 175 DeferredScopeStringMatches*, int identifier, const WebString& searchText ,
189 const WebFindOptions&, bool reset); 176 const WebFindOptions&, bool reset);
190 177
191 // Determines whether to invalidate the content area and scrollbar. 178 // Determines whether to invalidate the content area and scrollbar.
192 void invalidateIfNecessary(); 179 void invalidateIfNecessary();
193 180
194 // Sets the markers within a current match range as active or inactive.
195 void setMatchMarkerActive(bool);
196
197 void decrementFramesScopingCount(int identifier);
198
199 WebLocalFrameImpl& ownerFrame() const 181 WebLocalFrameImpl& ownerFrame() const
200 { 182 {
201 DCHECK(m_ownerFrame); 183 DCHECK(m_ownerFrame);
202 return *m_ownerFrame; 184 return *m_ownerFrame;
203 } 185 }
204 186
205 // Returns the ordinal of the first match in the owner frame.
206 int ordinalOfFirstMatch() const;
207
208 Member<WebLocalFrameImpl> m_ownerFrame; 187 Member<WebLocalFrameImpl> m_ownerFrame;
209 188
210 // A way for the main frame to keep track of which frame has an active 189 // Indicates whether this frame currently has the active match.
211 // match. Should be 0 for all other frames. 190 bool m_currentActiveMatchFrame;
212 Member<WebLocalFrameImpl> m_currentActiveMatchFrame;
213 191
214 // The range of the active match for the current frame. 192 // The range of the active match for the current frame.
215 Member<Range> m_activeMatch; 193 Member<Range> m_activeMatch;
216 194
217 // The index of the active match for the current frame. 195 // The index of the active match for the current frame.
218 int m_activeMatchIndexInCurrentFrame; 196 int m_activeMatchIndex;
219 197
220 // The scoping effort can time out and we need to keep track of where we 198 // The scoping effort can time out and we need to keep track of where we
221 // ended our last search so we can continue from where we left of. 199 // ended our last search so we can continue from where we left of.
222 // 200 //
223 // This range is collapsed to the end position of the last successful 201 // This range is collapsed to the end position of the last successful
224 // search; the new search should start from this position. 202 // search; the new search should start from this position.
225 Member<Range> m_resumeScopingFromRange; 203 Member<Range> m_resumeScopingFromRange;
226 204
227 // Keeps track of the last string this frame searched for. This is used for 205 // Keeps track of the last string this frame searched for. This is used for
228 // short-circuiting searches in the following scenarios: When a frame has 206 // short-circuiting searches in the following scenarios: When a frame has
229 // been searched and returned 0 results, we don't need to search that frame 207 // been searched and returned 0 results, we don't need to search that frame
230 // again if the user is just adding to the search (making it more specific). 208 // again if the user is just adding to the search (making it more specific).
231 WTF::String m_lastSearchString; 209 WTF::String m_lastSearchString;
232 210
233 // Keeps track of how many matches this frame has found so far, so that we 211 // Keeps track of how many matches this frame has found so far, so that we
234 // don't lose count between scoping efforts, and is also used (in conjunctio n 212 // don't lose count between scoping efforts, and is also used (in conjunctio n
235 // with m_lastSearchString) to figure out if we need to search the frame aga in. 213 // with m_lastSearchString) to figure out if we need to search the frame aga in.
236 int m_lastMatchCount; 214 int m_lastMatchCount;
237 215
238 // This variable keeps a cumulative total of matches found so far for ALL th e 216 // This variable keeps a cumulative total of matches found so far in this
239 // frames on the page, and is only incremented by calling IncreaseMatchCount 217 // frame, and is only incremented by calling IncreaseMatchCount.
240 // (on the main frame only). It should be -1 for all other frames.
241 int m_totalMatchCount; 218 int m_totalMatchCount;
242 219
243 // This variable keeps a cumulative total of how many frames are currently 220 // Keeps track of whether the frame is currently scoping (being searched for matches).
244 // scoping, and is incremented/decremented on the main frame only. 221 bool m_frameScoping;
245 // It should be -1 for all other frames.
246 int m_framesScopingCount;
247 222
248 // Identifier of the latest find-in-page request. Required to be stored in 223 // Identifier of the latest find-in-page request. Required to be stored in
249 // the frame in order to reply if required in case the frame is detached. 224 // the frame in order to reply if required in case the frame is detached.
250 int m_findRequestIdentifier; 225 int m_findRequestIdentifier;
251 226
252 // Keeps track of when the scoping effort should next invalidate the scrollb ar 227 // Keeps track of when the scoping effort should next invalidate the scrollb ar
253 // and the frame area. 228 // and the frame area.
254 int m_nextInvalidateAfter; 229 int m_nextInvalidateAfter;
255 230
256 // A list of all of the pending calls to scopeStringMatches. 231 // A list of all of the pending calls to scopeStringMatches.
257 HeapVector<Member<DeferredScopeStringMatches>> m_deferredScopingWork; 232 HeapVector<Member<DeferredScopeStringMatches>> m_deferredScopingWork;
258 233
259 // Version number incremented on the main frame only whenever the document 234 // Version number incremented whenever this frame's find-in-page match
260 // find-in-page match markers change. It should be 0 for all other frames. 235 // markers change.
261 int m_findMatchMarkersVersion; 236 int m_findMatchMarkersVersion;
262 237
263 // Local cache of the find match markers currently displayed for this frame. 238 // Local cache of the find match markers currently displayed for this frame.
264 HeapVector<FindMatch> m_findMatchesCache; 239 HeapVector<FindMatch> m_findMatchesCache;
265 240
266 // Contents size when find-in-page match rects were last computed for this 241 // Contents size when find-in-page match rects were last computed for this
267 // frame's cache. 242 // frame's cache.
268 IntSize m_contentsSizeForCurrentFindMatchRects; 243 IntSize m_contentsSizeForCurrentFindMatchRects;
269 244
270 // This flag is used by the scoping effort to determine if we need to figure 245 // This flag is used by the scoping effort to determine if we need to figure
(...skipping 11 matching lines...) Expand all
282 // Determines if the rects in the find-in-page matches cache of this frame 257 // Determines if the rects in the find-in-page matches cache of this frame
283 // are invalid and should be recomputed. 258 // are invalid and should be recomputed.
284 bool m_findMatchRectsAreValid; 259 bool m_findMatchRectsAreValid;
285 }; 260 };
286 261
287 } // namespace blink 262 } // namespace blink
288 263
289 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::TextFinder::FindMatch); 264 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::TextFinder::FindMatch);
290 265
291 #endif // TextFinder_h 266 #endif // TextFinder_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/page/Page.cpp ('k') | third_party/WebKit/Source/web/TextFinder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698