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