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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 #include "core/editing/VisibleSelection.h" | 47 #include "core/editing/VisibleSelection.h" |
48 #include "core/frame/FrameView.h" | 48 #include "core/frame/FrameView.h" |
49 #include "platform/Timer.h" | 49 #include "platform/Timer.h" |
50 #include "public/platform/WebVector.h" | 50 #include "public/platform/WebVector.h" |
51 #include "wtf/CurrentTime.h" | 51 #include "wtf/CurrentTime.h" |
52 | 52 |
53 using namespace WebCore; | 53 using namespace WebCore; |
54 | 54 |
55 namespace blink { | 55 namespace blink { |
56 | 56 |
57 TextFinder::FindMatch::FindMatch(PassRefPtr<Range> range, int ordinal) | 57 TextFinder::FindMatch::FindMatch(PassRefPtrWillBeRawPtr<Range> range, int ordina
l) |
58 : m_range(range) | 58 : m_range(range) |
59 , m_ordinal(ordinal) | 59 , m_ordinal(ordinal) |
60 { | 60 { |
61 } | 61 } |
62 | 62 |
| 63 void TextFinder::FindMatch::trace(WebCore::Visitor* visitor) |
| 64 { |
| 65 visitor->trace(m_range); |
| 66 } |
| 67 |
63 class TextFinder::DeferredScopeStringMatches { | 68 class TextFinder::DeferredScopeStringMatches { |
64 public: | 69 public: |
65 DeferredScopeStringMatches(TextFinder* textFinder, int identifier, const Web
String& searchText, const WebFindOptions& options, bool reset) | 70 DeferredScopeStringMatches(TextFinder* textFinder, int identifier, const Web
String& searchText, const WebFindOptions& options, bool reset) |
66 : m_timer(this, &DeferredScopeStringMatches::doTimeout) | 71 : m_timer(this, &DeferredScopeStringMatches::doTimeout) |
67 , m_textFinder(textFinder) | 72 , m_textFinder(textFinder) |
68 , m_identifier(identifier) | 73 , m_identifier(identifier) |
69 , m_searchText(searchText) | 74 , m_searchText(searchText) |
70 , m_options(options) | 75 , m_options(options) |
71 , m_reset(reset) | 76 , m_reset(reset) |
72 { | 77 { |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 | 226 |
222 if (!shouldScopeMatches(searchText)) { | 227 if (!shouldScopeMatches(searchText)) { |
223 // Note that we want to defer the final update when resetting even if sh
ouldScopeMatches returns false. | 228 // Note that we want to defer the final update when resetting even if sh
ouldScopeMatches returns false. |
224 // This is done in order to prevent sending a final message based only o
n the results of the first frame | 229 // This is done in order to prevent sending a final message based only o
n the results of the first frame |
225 // since m_framesScopingCount would be 0 as other frames have yet to res
et. | 230 // since m_framesScopingCount would be 0 as other frames have yet to res
et. |
226 finishCurrentScopingEffort(identifier); | 231 finishCurrentScopingEffort(identifier); |
227 return; | 232 return; |
228 } | 233 } |
229 | 234 |
230 WebFrameImpl* mainFrameImpl = m_ownerFrame.viewImpl()->mainFrameImpl(); | 235 WebFrameImpl* mainFrameImpl = m_ownerFrame.viewImpl()->mainFrameImpl(); |
231 RefPtr<Range> searchRange(rangeOfContents(m_ownerFrame.frame()->document()))
; | 236 RefPtrWillBeRawPtr<Range> searchRange(rangeOfContents(m_ownerFrame.frame()->
document())); |
232 | 237 |
233 Node* originalEndContainer = searchRange->endContainer(); | 238 Node* originalEndContainer = searchRange->endContainer(); |
234 int originalEndOffset = searchRange->endOffset(); | 239 int originalEndOffset = searchRange->endOffset(); |
235 | 240 |
236 TrackExceptionState exceptionState, exceptionState2; | 241 TrackExceptionState exceptionState, exceptionState2; |
237 if (m_resumeScopingFromRange) { | 242 if (m_resumeScopingFromRange) { |
238 // This is a continuation of a scoping operation that timed out and didn
't | 243 // This is a continuation of a scoping operation that timed out and didn
't |
239 // complete last time around, so we should start from where we left off. | 244 // complete last time around, so we should start from where we left off. |
240 searchRange->setStart(m_resumeScopingFromRange->startContainer(), m_resu
meScopingFromRange->startOffset(exceptionState2) + 1, exceptionState); | 245 searchRange->setStart(m_resumeScopingFromRange->startContainer(), m_resu
meScopingFromRange->startOffset(exceptionState2) + 1, exceptionState); |
241 if (exceptionState.hadException() || exceptionState2.hadException()) { | 246 if (exceptionState.hadException() || exceptionState2.hadException()) { |
(...skipping 10 matching lines...) Expand all Loading... |
252 | 257 |
253 int matchCount = 0; | 258 int matchCount = 0; |
254 bool timedOut = false; | 259 bool timedOut = false; |
255 double startTime = currentTime(); | 260 double startTime = currentTime(); |
256 do { | 261 do { |
257 // Find next occurrence of the search string. | 262 // Find next occurrence of the search string. |
258 // FIXME: (http://b/1088245) This WebKit operation may run for longer | 263 // FIXME: (http://b/1088245) This WebKit operation may run for longer |
259 // than the timeout value, and is not interruptible as it is currently | 264 // than the timeout value, and is not interruptible as it is currently |
260 // written. We may need to rewrite it with interruptibility in mind, or | 265 // written. We may need to rewrite it with interruptibility in mind, or |
261 // find an alternative. | 266 // find an alternative. |
262 RefPtr<Range> resultRange(findPlainText( | 267 RefPtrWillBeRawPtr<Range> resultRange(findPlainText( |
263 searchRange.get(), searchText, options.matchCase ? 0 : CaseInsensiti
ve)); | 268 searchRange.get(), searchText, options.matchCase ? 0 : CaseInsensiti
ve)); |
264 if (resultRange->collapsed(exceptionState)) { | 269 if (resultRange->collapsed(exceptionState)) { |
265 if (!resultRange->startContainer()->isInShadowTree()) | 270 if (!resultRange->startContainer()->isInShadowTree()) |
266 break; | 271 break; |
267 | 272 |
268 searchRange->setStartAfter( | 273 searchRange->setStartAfter( |
269 resultRange->startContainer()->deprecatedShadowAncestorNode(), e
xceptionState); | 274 resultRange->startContainer()->deprecatedShadowAncestorNode(), e
xceptionState); |
270 searchRange->setEnd(originalEndContainer, originalEndOffset, excepti
onState); | 275 searchRange->setEnd(originalEndContainer, originalEndOffset, excepti
onState); |
271 continue; | 276 continue; |
272 } | 277 } |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 it->m_rect = FloatRect(); | 451 it->m_rect = FloatRect(); |
447 else if (!m_findMatchRectsAreValid) | 452 else if (!m_findMatchRectsAreValid) |
448 it->m_rect = findInPageRectFromRange(it->m_range.get()); | 453 it->m_rect = findInPageRectFromRange(it->m_range.get()); |
449 | 454 |
450 if (it->m_rect.isEmpty()) | 455 if (it->m_rect.isEmpty()) |
451 ++deadMatches; | 456 ++deadMatches; |
452 } | 457 } |
453 | 458 |
454 // Remove any invalid matches from the cache. | 459 // Remove any invalid matches from the cache. |
455 if (deadMatches) { | 460 if (deadMatches) { |
456 Vector<FindMatch> filteredMatches; | 461 WillBeHeapVector<FindMatch> filteredMatches; |
457 filteredMatches.reserveCapacity(m_findMatchesCache.size() - deadMatches)
; | 462 filteredMatches.reserveCapacity(m_findMatchesCache.size() - deadMatches)
; |
458 | 463 |
459 for (Vector<FindMatch>::const_iterator it = m_findMatchesCache.begin();
it != m_findMatchesCache.end(); ++it) { | 464 for (Vector<FindMatch>::const_iterator it = m_findMatchesCache.begin();
it != m_findMatchesCache.end(); ++it) { |
460 if (!it->m_rect.isEmpty()) | 465 if (!it->m_rect.isEmpty()) |
461 filteredMatches.append(*it); | 466 filteredMatches.append(*it); |
462 } | 467 } |
463 | 468 |
464 m_findMatchesCache.swap(filteredMatches); | 469 m_findMatchesCache.swap(filteredMatches); |
465 } | 470 } |
466 | 471 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 distanceSquared = currentDistanceSquared; | 544 distanceSquared = currentDistanceSquared; |
540 } | 545 } |
541 } | 546 } |
542 return nearest; | 547 return nearest; |
543 } | 548 } |
544 | 549 |
545 int TextFinder::selectFindMatch(unsigned index, WebRect* selectionRect) | 550 int TextFinder::selectFindMatch(unsigned index, WebRect* selectionRect) |
546 { | 551 { |
547 ASSERT_WITH_SECURITY_IMPLICATION(index < m_findMatchesCache.size()); | 552 ASSERT_WITH_SECURITY_IMPLICATION(index < m_findMatchesCache.size()); |
548 | 553 |
549 RefPtr<Range> range = m_findMatchesCache[index].m_range; | 554 RefPtrWillBeRawPtr<Range> range = m_findMatchesCache[index].m_range; |
550 if (!range->boundaryPointsValid() || !range->startContainer()->inDocument()) | 555 if (!range->boundaryPointsValid() || !range->startContainer()->inDocument()) |
551 return -1; | 556 return -1; |
552 | 557 |
553 // Check if the match is already selected. | 558 // Check if the match is already selected. |
554 TextFinder& mainFrameTextFinder = m_ownerFrame.viewImpl()->mainFrameImpl()->
ensureTextFinder(); | 559 TextFinder& mainFrameTextFinder = m_ownerFrame.viewImpl()->mainFrameImpl()->
ensureTextFinder(); |
555 WebFrameImpl* activeMatchFrame = mainFrameTextFinder.m_currentActiveMatchFra
me; | 560 WebFrameImpl* activeMatchFrame = mainFrameTextFinder.m_currentActiveMatchFra
me; |
556 if (&m_ownerFrame != activeMatchFrame || !m_activeMatch || !areRangesEqual(m
_activeMatch.get(), range.get())) { | 561 if (&m_ownerFrame != activeMatchFrame || !m_activeMatch || !areRangesEqual(m
_activeMatch.get(), range.get())) { |
557 if (isActiveMatchFrameValid()) | 562 if (isActiveMatchFrameValid()) |
558 activeMatchFrame->ensureTextFinder().setMatchMarkerActive(false); | 563 activeMatchFrame->ensureTextFinder().setMatchMarkerActive(false); |
559 | 564 |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 if (!m_framesScopingCount) | 733 if (!m_framesScopingCount) |
729 m_ownerFrame.increaseMatchCount(0, identifier); | 734 m_ownerFrame.increaseMatchCount(0, identifier); |
730 } | 735 } |
731 | 736 |
732 int TextFinder::ordinalOfFirstMatch() const | 737 int TextFinder::ordinalOfFirstMatch() const |
733 { | 738 { |
734 return ordinalOfFirstMatchForFrame(&m_ownerFrame); | 739 return ordinalOfFirstMatchForFrame(&m_ownerFrame); |
735 } | 740 } |
736 | 741 |
737 } // namespace blink | 742 } // namespace blink |
OLD | NEW |