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

Side by Side Diff: Source/web/WebFrameImpl.h

Issue 181013007: Introduce TextFinder class for decoupling WebFrameImpl and text finder. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@introduce-textfinder-class-new
Patch Set: Rebase Created 6 years, 9 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 class Node; 52 class Node;
53 class Range; 53 class Range;
54 class SubstituteData; 54 class SubstituteData;
55 struct FrameLoadRequest; 55 struct FrameLoadRequest;
56 struct WindowFeatures; 56 struct WindowFeatures;
57 } 57 }
58 58
59 namespace blink { 59 namespace blink {
60 class ChromePrintContext; 60 class ChromePrintContext;
61 class SharedWorkerRepositoryClientImpl; 61 class SharedWorkerRepositoryClientImpl;
62 class TextFinder;
62 class WebDataSourceImpl; 63 class WebDataSourceImpl;
63 class WebInputElement; 64 class WebInputElement;
64 class WebFrameClient; 65 class WebFrameClient;
65 class WebPerformance; 66 class WebPerformance;
66 class WebPluginContainerImpl; 67 class WebPluginContainerImpl;
67 class WebView; 68 class WebView;
68 class WebViewImpl; 69 class WebViewImpl;
69 struct WebPrintParams; 70 struct WebPrintParams;
70 71
71 template <typename T> class WebVector; 72 template <typename T> class WebVector;
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 WebCore::FrameView* frameView() const { return frame() ? frame()->view() : 0 ; } 260 WebCore::FrameView* frameView() const { return frame() ? frame()->view() : 0 ; }
260 261
261 // Getters for the impls corresponding to Get(Provisional)DataSource. They 262 // Getters for the impls corresponding to Get(Provisional)DataSource. They
262 // may return 0 if there is no corresponding data source. 263 // may return 0 if there is no corresponding data source.
263 WebDataSourceImpl* dataSourceImpl() const; 264 WebDataSourceImpl* dataSourceImpl() const;
264 WebDataSourceImpl* provisionalDataSourceImpl() const; 265 WebDataSourceImpl* provisionalDataSourceImpl() const;
265 266
266 // Returns which frame has an active match. This function should only be 267 // Returns which frame has an active match. This function should only be
267 // called on the main frame, as it is the only frame keeping track. Returned 268 // called on the main frame, as it is the only frame keeping track. Returned
268 // value can be 0 if no frame has an active match. 269 // value can be 0 if no frame has an active match.
269 WebFrameImpl* activeMatchFrame() const { return m_currentActiveMatchFrame; } 270 WebFrameImpl* activeMatchFrame() const;
270 271
271 // Returns the active match in the current frame. Could be a null range if 272 // Returns the active match in the current frame. Could be a null range if
272 // the local frame has no active match. 273 // the local frame has no active match.
273 WebCore::Range* activeMatch() const { return m_activeMatch.get(); } 274 WebCore::Range* activeMatch() const;
274 275
275 // When a Find operation ends, we want to set the selection to what was acti ve 276 // When a Find operation ends, we want to set the selection to what was acti ve
276 // and set focus to the first focusable node we find (starting with the firs t 277 // and set focus to the first focusable node we find (starting with the firs t
277 // node in the matched range and going up the inheritance chain). If we find 278 // node in the matched range and going up the inheritance chain). If we find
278 // nothing to focus we focus the first focusable node in the range. This 279 // nothing to focus we focus the first focusable node in the range. This
279 // allows us to set focus to a link (when we find text inside a link), which 280 // allows us to set focus to a link (when we find text inside a link), which
280 // allows us to navigate by pressing Enter after closing the Find box. 281 // allows us to navigate by pressing Enter after closing the Find box.
281 void setFindEndstateFocusAndSelection(); 282 void setFindEndstateFocusAndSelection();
282 283
283 void didFail(const WebCore::ResourceError&, bool wasProvisional); 284 void didFail(const WebCore::ResourceError&, bool wasProvisional);
284 285
285 // Sets whether the WebFrameImpl allows its document to be scrolled. 286 // Sets whether the WebFrameImpl allows its document to be scrolled.
286 // If the parameter is true, allow the document to be scrolled. 287 // If the parameter is true, allow the document to be scrolled.
287 // Otherwise, disallow scrolling. 288 // Otherwise, disallow scrolling.
288 virtual void setCanHaveScrollbars(bool) OVERRIDE; 289 virtual void setCanHaveScrollbars(bool) OVERRIDE;
289 290
290 WebCore::LocalFrame* frame() const { return m_frame.get(); } 291 WebCore::LocalFrame* frame() const { return m_frame.get(); }
291 WebFrameClient* client() const { return m_client; } 292 WebFrameClient* client() const { return m_client; }
292 void setClient(WebFrameClient* client) { m_client = client; } 293 void setClient(WebFrameClient* client) { m_client = client; }
293 294
294 WebPermissionClient* permissionClient() { return m_permissionClient; } 295 WebPermissionClient* permissionClient() { return m_permissionClient; }
295 SharedWorkerRepositoryClientImpl* sharedWorkerRepositoryClient() const { ret urn m_sharedWorkerRepositoryClient.get(); } 296 SharedWorkerRepositoryClientImpl* sharedWorkerRepositoryClient() const { ret urn m_sharedWorkerRepositoryClient.get(); }
296 297
297 void setInputEventsTransformForEmulation(const WebCore::IntSize&, float); 298 void setInputEventsTransformForEmulation(const WebCore::IntSize&, float);
298 299
299 static void selectWordAroundPosition(WebCore::LocalFrame*, WebCore::VisibleP osition); 300 static void selectWordAroundPosition(WebCore::LocalFrame*, WebCore::VisibleP osition);
300 301
302 // Returns the text finder object if it already exists.
303 // Otherwise creates it and then returns.
304 TextFinder& getOrCreateTextFinder();
tkent 2014/03/14 00:20:36 We usually name such function "ensureTextFinder().
Andrey Kraynov 2014/03/17 17:56:26 Thanks for the tip. I've renamed this function.
305
301 private: 306 private:
302 class DeferredScopeStringMatches;
303 friend class DeferredScopeStringMatches;
304 friend class FrameLoaderClientImpl; 307 friend class FrameLoaderClientImpl;
305 308
306 struct FindMatch {
307 RefPtr<WebCore::Range> m_range;
308
309 // 1-based index within this frame.
310 int m_ordinal;
311
312 // In find-in-page coordinates.
313 // Lazily calculated by updateFindMatchRects.
314 WebCore::FloatRect m_rect;
315
316 FindMatch(PassRefPtr<WebCore::Range>, int ordinal);
317 };
318
319 // A bit mask specifying area of the frame to invalidate.
320 enum AreaToInvalidate {
321 InvalidateNothing,
322 InvalidateContentArea,
323 InvalidateScrollbar, // Vertical scrollbar only.
324 InvalidateAll // Both content area and the scrollbar.
325 };
326
327 explicit WebFrameImpl(WebFrameClient*); 309 explicit WebFrameImpl(WebFrameClient*);
328 310
329 // Sets the local WebCore frame and registers destruction observers. 311 // Sets the local WebCore frame and registers destruction observers.
330 void setWebCoreFrame(PassRefPtr<WebCore::LocalFrame>); 312 void setWebCoreFrame(PassRefPtr<WebCore::LocalFrame>);
331 313
332 // Notifies the delegate about a new selection rect.
333 void reportFindInPageSelection(
334 const WebRect& selectionRect, int activeMatchOrdinal, int identifier);
335
336 // Clear the find-in-page matches cache forcing rects to be fully
337 // calculated again next time updateFindMatchRects is called.
338 void clearFindMatchesCache();
339
340 // Check if the activeMatchFrame still exists in the frame tree.
341 bool isActiveMatchFrameValid() const;
342
343 // Return the index in the find-in-page cache of the match closest to the
344 // provided point in find-in-page coordinates, or -1 in case of error.
345 // The squared distance to the closest match is returned in the distanceSqua red parameter.
346 int nearestFindMatch(const WebCore::FloatPoint&, float& distanceSquared);
347
348 // Select a find-in-page match marker in the current frame using a cache
349 // match index returned by nearestFindMatch. Returns the ordinal of the new
350 // selected match or -1 in case of error. Also provides the bounding box of
351 // the marker in window coordinates if selectionRect is not null.
352 int selectFindMatch(unsigned index, WebRect* selectionRect);
353
354 // Compute and cache the rects for FindMatches if required.
355 // Rects are automatically invalidated in case of content size changes,
356 // propagating the invalidation to child frames.
357 void updateFindMatchRects();
358
359 // Append the find-in-page match rects of the current frame to the provided vector.
360 void appendFindMatchRects(Vector<WebFloatRect>& frameRects);
361
362 // Invalidates a certain area within the frame.
363 void invalidateArea(AreaToInvalidate);
364
365 // Add a WebKit TextMatch-highlight marker to nodes in a range.
366 void addMarker(WebCore::Range*, bool activeMatch);
367
368 // Sets the markers within a range as active or inactive.
369 void setMarkerActive(WebCore::Range*, bool active);
370
371 // Returns the ordinal of the first match in the frame specified. This
372 // function enumerates the frames, starting with the main frame and up to (b ut
373 // not including) the frame passed in as a parameter and counts how many
374 // matches have been found.
375 int ordinalOfFirstMatchForFrame(WebFrameImpl*) const;
376
377 // Determines whether the scoping effort is required for a particular frame.
378 // It is not necessary if the frame is invisible, for example, or if this
379 // is a repeat search that already returned nothing last time the same prefi x
380 // was searched.
381 bool shouldScopeMatches(const WTF::String& searchText);
382
383 // Removes the current frame from the global scoping effort and triggers any
384 // updates if appropriate. This method does not mark the scoping operation
385 // as finished.
386 void flushCurrentScopingEffort(int identifier);
387
388 // Finishes the current scoping effort and triggers any updates if appropria te.
389 void finishCurrentScopingEffort(int identifier);
390
391 // Queue up a deferred call to scopeStringMatches.
392 void scopeStringMatchesSoon(
393 int identifier, const WebString& searchText, const WebFindOptions&,
394 bool reset);
395
396 // Called by a DeferredScopeStringMatches instance.
397 void callScopeStringMatches(
398 DeferredScopeStringMatches*, int identifier, const WebString& searchText ,
399 const WebFindOptions&, bool reset);
400
401 // Determines whether to invalidate the content area and scrollbar.
402 void invalidateIfNecessary();
403
404 void loadJavaScriptURL(const WebCore::KURL&); 314 void loadJavaScriptURL(const WebCore::KURL&);
405 315
406 // Returns a hit-tested VisiblePosition for the given point 316 // Returns a hit-tested VisiblePosition for the given point
407 WebCore::VisiblePosition visiblePositionForWindowPoint(const WebPoint&); 317 WebCore::VisiblePosition visiblePositionForWindowPoint(const WebPoint&);
408 318
409 FrameLoaderClientImpl m_frameLoaderClientImpl; 319 FrameLoaderClientImpl m_frameLoaderClientImpl;
410 320
411 // The embedder retains a reference to the WebCore LocalFrame while it is ac tive in the DOM. This 321 // The embedder retains a reference to the WebCore LocalFrame while it is ac tive in the DOM. This
412 // reference is released when the frame is removed from the DOM or the entir e page is closed. 322 // reference is released when the frame is removed from the DOM or the entir e page is closed.
413 // FIXME: These will need to change to WebFrame when we introduce WebFramePr oxy. 323 // FIXME: These will need to change to WebFrame when we introduce WebFramePr oxy.
414 RefPtr<WebCore::LocalFrame> m_frame; 324 RefPtr<WebCore::LocalFrame> m_frame;
415 WebFrameImpl* m_parent; 325 WebFrameImpl* m_parent;
416 WebFrameImpl* m_previousSibling; 326 WebFrameImpl* m_previousSibling;
417 WebFrameImpl* m_nextSibling; 327 WebFrameImpl* m_nextSibling;
418 WebFrameImpl* m_firstChild; 328 WebFrameImpl* m_firstChild;
419 WebFrameImpl* m_lastChild; 329 WebFrameImpl* m_lastChild;
420 330
421 WebFrameImpl* m_opener; 331 WebFrameImpl* m_opener;
422 WTF::HashSet<WebFrameImpl*> m_openedFrames; 332 WTF::HashSet<WebFrameImpl*> m_openedFrames;
423 333
424 // Indicate whether the current LocalFrame is local or remote. Remote frames are 334 // Indicate whether the current LocalFrame is local or remote. Remote frames are
425 // rendered in a different process from their parent frames. 335 // rendered in a different process from their parent frames.
426 bool m_isRemote; 336 bool m_isRemote;
427 337
428 WebFrameClient* m_client; 338 WebFrameClient* m_client;
429 WebPermissionClient* m_permissionClient; 339 WebPermissionClient* m_permissionClient;
430 OwnPtr<SharedWorkerRepositoryClientImpl> m_sharedWorkerRepositoryClient; 340 OwnPtr<SharedWorkerRepositoryClientImpl> m_sharedWorkerRepositoryClient;
431 341
432 // A way for the main frame to keep track of which frame has an active 342 // Will be initialized after first call to find() or scopeStringMatches().
433 // match. Should be 0 for all other frames. 343 OwnPtr<TextFinder> m_textFinder;
434 WebFrameImpl* m_currentActiveMatchFrame;
435
436 // The range of the active match for the current frame.
437 RefPtr<WebCore::Range> m_activeMatch;
438
439 // The index of the active match for the current frame.
440 int m_activeMatchIndexInCurrentFrame;
441
442 // This flag is used by the scoping effort to determine if we need to figure
443 // out which rectangle is the active match. Once we find the active
444 // rectangle we clear this flag.
445 bool m_locatingActiveRect;
446
447 // The scoping effort can time out and we need to keep track of where we
448 // ended our last search so we can continue from where we left of.
449 RefPtr<WebCore::Range> m_resumeScopingFromRange;
450
451 // Keeps track of the last string this frame searched for. This is used for
452 // short-circuiting searches in the following scenarios: When a frame has
453 // been searched and returned 0 results, we don't need to search that frame
454 // again if the user is just adding to the search (making it more specific).
455 WTF::String m_lastSearchString;
456
457 // Keeps track of how many matches this frame has found so far, so that we
458 // don't loose count between scoping efforts, and is also used (in conjuncti on
459 // with m_lastSearchString) to figure out if we need to search the frame aga in.
460 int m_lastMatchCount;
461
462 // This variable keeps a cumulative total of matches found so far for ALL th e
463 // frames on the page, and is only incremented by calling IncreaseMatchCount
464 // (on the main frame only). It should be -1 for all other frames.
465 int m_totalMatchCount;
466
467 // This variable keeps a cumulative total of how many frames are currently
468 // scoping, and is incremented/decremented on the main frame only.
469 // It should be -1 for all other frames.
470 int m_framesScopingCount;
471
472 // Identifier of the latest find-in-page request. Required to be stored in
473 // the frame in order to reply if required in case the frame is detached.
474 int m_findRequestIdentifier;
475
476 // Keeps track of whether there is an scoping effort ongoing in the frame.
477 bool m_scopingInProgress;
478
479 // Keeps track of whether the last find request completed its scoping effort
480 // without finding any matches in this frame.
481 bool m_lastFindRequestCompletedWithNoMatches;
482
483 // Keeps track of when the scoping effort should next invalidate the scrollb ar
484 // and the frame area.
485 int m_nextInvalidateAfter;
486
487 // A list of all of the pending calls to scopeStringMatches.
488 Vector<DeferredScopeStringMatches*> m_deferredScopingWork;
489
490 // Version number incremented on the main frame only whenever the document
491 // find-in-page match markers change. It should be 0 for all other frames.
492 int m_findMatchMarkersVersion;
493
494 // Local cache of the find match markers currently displayed for this frame.
495 Vector<FindMatch> m_findMatchesCache;
496
497 // Determines if the rects in the find-in-page matches cache of this frame
498 // are invalid and should be recomputed.
499 bool m_findMatchRectsAreValid;
500
501 // Contents size when find-in-page match rects were last computed for this
502 // frame's cache.
503 WebCore::IntSize m_contentsSizeForCurrentFindMatchRects;
504 344
505 // Valid between calls to BeginPrint() and EndPrint(). Containts the print 345 // Valid between calls to BeginPrint() and EndPrint(). Containts the print
506 // information. Is used by PrintPage(). 346 // information. Is used by PrintPage().
507 OwnPtr<ChromePrintContext> m_printContext; 347 OwnPtr<ChromePrintContext> m_printContext;
508 348
509 // Stores the additional input events offset and scale when device metrics e mulation is enabled. 349 // Stores the additional input events offset and scale when device metrics e mulation is enabled.
510 WebCore::IntSize m_inputEventsOffsetForEmulation; 350 WebCore::IntSize m_inputEventsOffsetForEmulation;
511 float m_inputEventsScaleFactorForEmulation; 351 float m_inputEventsScaleFactorForEmulation;
512 }; 352 };
513 353
514 DEFINE_TYPE_CASTS(WebFrameImpl, WebFrame, frame, true, true); 354 DEFINE_TYPE_CASTS(WebFrameImpl, WebFrame, frame, true, true);
515 355
516 } // namespace blink 356 } // namespace blink
517 357
518 #endif 358 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698