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

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

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

Powered by Google App Engine
This is Rietveld 408576698