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