| 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 #include "public/web/WebFindOptions.h" | 51 #include "public/web/WebFindOptions.h" |
| 52 #include "public/web/WebFrameClient.h" | 52 #include "public/web/WebFrameClient.h" |
| 53 #include "public/web/WebViewClient.h" | 53 #include "public/web/WebViewClient.h" |
| 54 #include "web/FindInPageCoordinates.h" | 54 #include "web/FindInPageCoordinates.h" |
| 55 #include "web/WebLocalFrameImpl.h" | 55 #include "web/WebLocalFrameImpl.h" |
| 56 #include "web/WebViewImpl.h" | 56 #include "web/WebViewImpl.h" |
| 57 #include "wtf/CurrentTime.h" | 57 #include "wtf/CurrentTime.h" |
| 58 | 58 |
| 59 namespace blink { | 59 namespace blink { |
| 60 | 60 |
| 61 TextFinder::FindMatch::FindMatch(PassRefPtrWillBeRawPtr<Range> range, int ordina
l) | 61 TextFinder::FindMatch::FindMatch(RawPtr<Range> range, int ordinal) |
| 62 : m_range(range) | 62 : m_range(range) |
| 63 , m_ordinal(ordinal) | 63 , m_ordinal(ordinal) |
| 64 { | 64 { |
| 65 } | 65 } |
| 66 | 66 |
| 67 DEFINE_TRACE(TextFinder::FindMatch) | 67 DEFINE_TRACE(TextFinder::FindMatch) |
| 68 { | 68 { |
| 69 visitor->trace(m_range); | 69 visitor->trace(m_range); |
| 70 } | 70 } |
| 71 | 71 |
| 72 class TextFinder::DeferredScopeStringMatches : public NoBaseWillBeGarbageCollect
edFinalized<TextFinder::DeferredScopeStringMatches> { | 72 class TextFinder::DeferredScopeStringMatches : public GarbageCollectedFinalized<
TextFinder::DeferredScopeStringMatches> { |
| 73 public: | 73 public: |
| 74 static PassOwnPtrWillBeRawPtr<DeferredScopeStringMatches> create(TextFinder*
textFinder, int identifier, const WebString& searchText, const WebFindOptions&
options, bool reset) | 74 static RawPtr<DeferredScopeStringMatches> create(TextFinder* textFinder, int
identifier, const WebString& searchText, const WebFindOptions& options, bool re
set) |
| 75 { | 75 { |
| 76 return adoptPtrWillBeNoop(new DeferredScopeStringMatches(textFinder, ide
ntifier, searchText, options, reset)); | 76 return (new DeferredScopeStringMatches(textFinder, identifier, searchTex
t, options, reset)); |
| 77 } | 77 } |
| 78 | 78 |
| 79 DEFINE_INLINE_TRACE() | 79 DEFINE_INLINE_TRACE() |
| 80 { | 80 { |
| 81 visitor->trace(m_textFinder); | 81 visitor->trace(m_textFinder); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void dispose() | 84 void dispose() |
| 85 { | 85 { |
| 86 if (m_timer.isActive()) | 86 if (m_timer.isActive()) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 98 { | 98 { |
| 99 m_timer.startOneShot(0.0, BLINK_FROM_HERE); | 99 m_timer.startOneShot(0.0, BLINK_FROM_HERE); |
| 100 } | 100 } |
| 101 | 101 |
| 102 void doTimeout(Timer<DeferredScopeStringMatches>*) | 102 void doTimeout(Timer<DeferredScopeStringMatches>*) |
| 103 { | 103 { |
| 104 m_textFinder->callScopeStringMatches(this, m_identifier, m_searchText, m
_options, m_reset); | 104 m_textFinder->callScopeStringMatches(this, m_identifier, m_searchText, m
_options, m_reset); |
| 105 } | 105 } |
| 106 | 106 |
| 107 Timer<DeferredScopeStringMatches> m_timer; | 107 Timer<DeferredScopeStringMatches> m_timer; |
| 108 RawPtrWillBeMember<TextFinder> m_textFinder; | 108 Member<TextFinder> m_textFinder; |
| 109 const int m_identifier; | 109 const int m_identifier; |
| 110 const WebString m_searchText; | 110 const WebString m_searchText; |
| 111 const WebFindOptions m_options; | 111 const WebFindOptions m_options; |
| 112 const bool m_reset; | 112 const bool m_reset; |
| 113 }; | 113 }; |
| 114 | 114 |
| 115 bool TextFinder::find(int identifier, const WebString& searchText, const WebFind
Options& options, bool wrapWithinFrame, WebRect* selectionRect) | 115 bool TextFinder::find(int identifier, const WebString& searchText, const WebFind
Options& options, bool wrapWithinFrame, WebRect* selectionRect) |
| 116 { | 116 { |
| 117 if (!ownerFrame().frame() || !ownerFrame().frame()->page()) | 117 if (!ownerFrame().frame() || !ownerFrame().frame()->page()) |
| 118 return false; | 118 return false; |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 // Find next occurrence of the search string. | 301 // Find next occurrence of the search string. |
| 302 // FIXME: (http://crbug.com/6818) This WebKit operation may run for long
er | 302 // FIXME: (http://crbug.com/6818) This WebKit operation may run for long
er |
| 303 // than the timeout value, and is not interruptible as it is currently | 303 // than the timeout value, and is not interruptible as it is currently |
| 304 // written. We may need to rewrite it with interruptibility in mind, or | 304 // written. We may need to rewrite it with interruptibility in mind, or |
| 305 // find an alternative. | 305 // find an alternative. |
| 306 EphemeralRangeTemplate<Strategy> result = findPlainText(EphemeralRangeTe
mplate<Strategy>(searchStart, searchEnd), searchText, options.matchCase ? 0 : Ca
seInsensitive); | 306 EphemeralRangeTemplate<Strategy> result = findPlainText(EphemeralRangeTe
mplate<Strategy>(searchStart, searchEnd), searchText, options.matchCase ? 0 : Ca
seInsensitive); |
| 307 if (result.isCollapsed()) { | 307 if (result.isCollapsed()) { |
| 308 // Not found. | 308 // Not found. |
| 309 break; | 309 break; |
| 310 } | 310 } |
| 311 RefPtrWillBeRawPtr<Range> resultRange = Range::create(result.document(),
toPositionInDOMTree(result.startPosition()), toPositionInDOMTree(result.endPosi
tion())); | 311 RawPtr<Range> resultRange = Range::create(result.document(), toPositionI
nDOMTree(result.startPosition()), toPositionInDOMTree(result.endPosition())); |
| 312 if (resultRange->collapsed()) { | 312 if (resultRange->collapsed()) { |
| 313 // resultRange will be collapsed if the matched text spans over mult
iple TreeScopes. | 313 // resultRange will be collapsed if the matched text spans over mult
iple TreeScopes. |
| 314 // FIXME: Show such matches to users. | 314 // FIXME: Show such matches to users. |
| 315 searchStart = result.endPosition(); | 315 searchStart = result.endPosition(); |
| 316 continue; | 316 continue; |
| 317 } | 317 } |
| 318 | 318 |
| 319 ++matchCount; | 319 ++matchCount; |
| 320 | 320 |
| 321 // Catch a special case where Find found something but doesn't know what | 321 // Catch a special case where Find found something but doesn't know what |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 match.m_rect = FloatRect(); | 505 match.m_rect = FloatRect(); |
| 506 else if (!m_findMatchRectsAreValid) | 506 else if (!m_findMatchRectsAreValid) |
| 507 match.m_rect = findInPageRectFromRange(match.m_range.get()); | 507 match.m_rect = findInPageRectFromRange(match.m_range.get()); |
| 508 | 508 |
| 509 if (match.m_rect.isEmpty()) | 509 if (match.m_rect.isEmpty()) |
| 510 ++deadMatches; | 510 ++deadMatches; |
| 511 } | 511 } |
| 512 | 512 |
| 513 // Remove any invalid matches from the cache. | 513 // Remove any invalid matches from the cache. |
| 514 if (deadMatches) { | 514 if (deadMatches) { |
| 515 WillBeHeapVector<FindMatch> filteredMatches; | 515 HeapVector<FindMatch> filteredMatches; |
| 516 filteredMatches.reserveCapacity(m_findMatchesCache.size() - deadMatches)
; | 516 filteredMatches.reserveCapacity(m_findMatchesCache.size() - deadMatches)
; |
| 517 | 517 |
| 518 for (const FindMatch& match : m_findMatchesCache) { | 518 for (const FindMatch& match : m_findMatchesCache) { |
| 519 if (!match.m_rect.isEmpty()) | 519 if (!match.m_rect.isEmpty()) |
| 520 filteredMatches.append(match); | 520 filteredMatches.append(match); |
| 521 } | 521 } |
| 522 | 522 |
| 523 m_findMatchesCache.swap(filteredMatches); | 523 m_findMatchesCache.swap(filteredMatches); |
| 524 } | 524 } |
| 525 | 525 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 distanceSquared = currentDistanceSquared; | 598 distanceSquared = currentDistanceSquared; |
| 599 } | 599 } |
| 600 } | 600 } |
| 601 return nearest; | 601 return nearest; |
| 602 } | 602 } |
| 603 | 603 |
| 604 int TextFinder::selectFindMatch(unsigned index, WebRect* selectionRect) | 604 int TextFinder::selectFindMatch(unsigned index, WebRect* selectionRect) |
| 605 { | 605 { |
| 606 ASSERT_WITH_SECURITY_IMPLICATION(index < m_findMatchesCache.size()); | 606 ASSERT_WITH_SECURITY_IMPLICATION(index < m_findMatchesCache.size()); |
| 607 | 607 |
| 608 RefPtrWillBeRawPtr<Range> range = m_findMatchesCache[index].m_range; | 608 RawPtr<Range> range = m_findMatchesCache[index].m_range; |
| 609 if (!range->boundaryPointsValid() || !range->startContainer()->inDocument()) | 609 if (!range->boundaryPointsValid() || !range->startContainer()->inDocument()) |
| 610 return -1; | 610 return -1; |
| 611 | 611 |
| 612 // Check if the match is already selected. | 612 // Check if the match is already selected. |
| 613 TextFinder& mainFrameTextFinder = ownerFrame().viewImpl()->mainFrameImpl()->
ensureTextFinder(); | 613 TextFinder& mainFrameTextFinder = ownerFrame().viewImpl()->mainFrameImpl()->
ensureTextFinder(); |
| 614 WebLocalFrameImpl* activeMatchFrame = mainFrameTextFinder.m_currentActiveMat
chFrame; | 614 WebLocalFrameImpl* activeMatchFrame = mainFrameTextFinder.m_currentActiveMat
chFrame; |
| 615 if (&ownerFrame() != activeMatchFrame || !m_activeMatch || !areRangesEqual(m
_activeMatch.get(), range.get())) { | 615 if (&ownerFrame() != activeMatchFrame || !m_activeMatch || !areRangesEqual(m
_activeMatch.get(), range.get())) { |
| 616 if (isActiveMatchFrameValid()) | 616 if (isActiveMatchFrameValid()) |
| 617 activeMatchFrame->ensureTextFinder().setMatchMarkerActive(false); | 617 activeMatchFrame->ensureTextFinder().setMatchMarkerActive(false); |
| 618 | 618 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 645 activeMatchRect = ownerFrame().frameView()->contentsToRootFrame(activeMa
tchBoundingBox); | 645 activeMatchRect = ownerFrame().frameView()->contentsToRootFrame(activeMa
tchBoundingBox); |
| 646 ownerFrame().viewImpl()->zoomToFindInPageRect(activeMatchRect); | 646 ownerFrame().viewImpl()->zoomToFindInPageRect(activeMatchRect); |
| 647 } | 647 } |
| 648 | 648 |
| 649 if (selectionRect) | 649 if (selectionRect) |
| 650 *selectionRect = activeMatchRect; | 650 *selectionRect = activeMatchRect; |
| 651 | 651 |
| 652 return ordinalOfFirstMatch() + m_activeMatchIndexInCurrentFrame + 1; | 652 return ordinalOfFirstMatch() + m_activeMatchIndexInCurrentFrame + 1; |
| 653 } | 653 } |
| 654 | 654 |
| 655 PassOwnPtrWillBeRawPtr<TextFinder> TextFinder::create(WebLocalFrameImpl& ownerFr
ame) | 655 RawPtr<TextFinder> TextFinder::create(WebLocalFrameImpl& ownerFrame) |
| 656 { | 656 { |
| 657 return adoptPtrWillBeNoop(new TextFinder(ownerFrame)); | 657 return (new TextFinder(ownerFrame)); |
| 658 } | 658 } |
| 659 | 659 |
| 660 TextFinder::TextFinder(WebLocalFrameImpl& ownerFrame) | 660 TextFinder::TextFinder(WebLocalFrameImpl& ownerFrame) |
| 661 : m_ownerFrame(&ownerFrame) | 661 : m_ownerFrame(&ownerFrame) |
| 662 , m_currentActiveMatchFrame(nullptr) | 662 , m_currentActiveMatchFrame(nullptr) |
| 663 , m_activeMatchIndexInCurrentFrame(-1) | 663 , m_activeMatchIndexInCurrentFrame(-1) |
| 664 , m_resumeScopingFromRange(nullptr) | 664 , m_resumeScopingFromRange(nullptr) |
| 665 , m_lastMatchCount(-1) | 665 , m_lastMatchCount(-1) |
| 666 , m_totalMatchCount(-1) | 666 , m_totalMatchCount(-1) |
| 667 , m_framesScopingCount(-1) | 667 , m_framesScopingCount(-1) |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 visitor->trace(m_ownerFrame); | 815 visitor->trace(m_ownerFrame); |
| 816 visitor->trace(m_currentActiveMatchFrame); | 816 visitor->trace(m_currentActiveMatchFrame); |
| 817 visitor->trace(m_activeMatch); | 817 visitor->trace(m_activeMatch); |
| 818 visitor->trace(m_resumeScopingFromRange); | 818 visitor->trace(m_resumeScopingFromRange); |
| 819 visitor->trace(m_deferredScopingWork); | 819 visitor->trace(m_deferredScopingWork); |
| 820 visitor->trace(m_findMatchesCache); | 820 visitor->trace(m_findMatchesCache); |
| 821 #endif | 821 #endif |
| 822 } | 822 } |
| 823 | 823 |
| 824 } // namespace blink | 824 } // namespace blink |
| OLD | NEW |