| 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 // If the user has selected something since the last Find operation we want | 130 // If the user has selected something since the last Find operation we want |
| 131 // to start from there. Otherwise, we start searching from where the last Fi
nd | 131 // to start from there. Otherwise, we start searching from where the last Fi
nd |
| 132 // operation left off (either a Find or a FindNext operation). | 132 // operation left off (either a Find or a FindNext operation). |
| 133 VisibleSelection selection(ownerFrame().frame()->selection().selection()); | 133 VisibleSelection selection(ownerFrame().frame()->selection().selection()); |
| 134 bool activeSelection = !selection.isNone(); | 134 bool activeSelection = !selection.isNone(); |
| 135 if (activeSelection) { | 135 if (activeSelection) { |
| 136 m_activeMatch = firstRangeOf(selection).get(); | 136 m_activeMatch = firstRangeOf(selection).get(); |
| 137 ownerFrame().frame()->selection().clear(); | 137 ownerFrame().frame()->selection().clear(); |
| 138 } | 138 } |
| 139 | 139 |
| 140 ASSERT(ownerFrame().frame() && ownerFrame().frame()->view()); | 140 DCHECK(ownerFrame().frame()); |
| 141 DCHECK(ownerFrame().frame()->view()); |
| 141 const FindOptions findOptions = (options.forward ? 0 : Backwards) | 142 const FindOptions findOptions = (options.forward ? 0 : Backwards) |
| 142 | (options.matchCase ? 0 : CaseInsensitive) | 143 | (options.matchCase ? 0 : CaseInsensitive) |
| 143 | (wrapWithinFrame ? WrapAround : 0) | 144 | (wrapWithinFrame ? WrapAround : 0) |
| 144 | (options.wordStart ? AtWordStarts : 0) | 145 | (options.wordStart ? AtWordStarts : 0) |
| 145 | (options.medialCapitalAsWordStart ? TreatMedialCapitalAsWordStart : 0) | 146 | (options.medialCapitalAsWordStart ? TreatMedialCapitalAsWordStart : 0) |
| 146 | (options.findNext ? 0 : StartInSelection); | 147 | (options.findNext ? 0 : StartInSelection); |
| 147 m_activeMatch = ownerFrame().frame()->editor().findStringAndScrollToVisible(
searchText, m_activeMatch.get(), findOptions); | 148 m_activeMatch = ownerFrame().frame()->editor().findStringAndScrollToVisible(
searchText, m_activeMatch.get(), findOptions); |
| 148 | 149 |
| 149 if (!m_activeMatch) { | 150 if (!m_activeMatch) { |
| 150 // If we're finding next the next active match might not be in the curre
nt frame. | 151 // If we're finding next the next active match might not be in the curre
nt frame. |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 // Note that we want to defer the final update when resetting even if sh
ouldScopeMatches returns false. | 277 // Note that we want to defer the final update when resetting even if sh
ouldScopeMatches returns false. |
| 277 // This is done in order to prevent sending a final message based only o
n the results of the first frame | 278 // This is done in order to prevent sending a final message based only o
n the results of the first frame |
| 278 // since m_framesScopingCount would be 0 as other frames have yet to res
et. | 279 // since m_framesScopingCount would be 0 as other frames have yet to res
et. |
| 279 finishCurrentScopingEffort(identifier); | 280 finishCurrentScopingEffort(identifier); |
| 280 return; | 281 return; |
| 281 } | 282 } |
| 282 | 283 |
| 283 WebLocalFrameImpl* mainFrameImpl = ownerFrame().viewImpl()->mainFrameImpl(); | 284 WebLocalFrameImpl* mainFrameImpl = ownerFrame().viewImpl()->mainFrameImpl(); |
| 284 PositionInFlatTree searchStart = PositionInFlatTree::firstPositionInNode(own
erFrame().frame()->document()); | 285 PositionInFlatTree searchStart = PositionInFlatTree::firstPositionInNode(own
erFrame().frame()->document()); |
| 285 PositionInFlatTree searchEnd = PositionInFlatTree::lastPositionInNode(ownerF
rame().frame()->document()); | 286 PositionInFlatTree searchEnd = PositionInFlatTree::lastPositionInNode(ownerF
rame().frame()->document()); |
| 286 ASSERT(searchStart.document() == searchEnd.document()); | 287 DCHECK_EQ(searchStart.document(), searchEnd.document()); |
| 287 | 288 |
| 288 if (m_resumeScopingFromRange) { | 289 if (m_resumeScopingFromRange) { |
| 289 // This is a continuation of a scoping operation that timed out and didn
't | 290 // This is a continuation of a scoping operation that timed out and didn
't |
| 290 // complete last time around, so we should start from where we left off. | 291 // complete last time around, so we should start from where we left off. |
| 291 ASSERT(m_resumeScopingFromRange->collapsed()); | 292 DCHECK(m_resumeScopingFromRange->collapsed()); |
| 292 searchStart = fromPositionInDOMTree<EditingInFlatTreeStrategy>(m_resumeS
copingFromRange->endPosition()); | 293 searchStart = fromPositionInDOMTree<EditingInFlatTreeStrategy>(m_resumeS
copingFromRange->endPosition()); |
| 293 if (searchStart.document() != searchEnd.document()) | 294 if (searchStart.document() != searchEnd.document()) |
| 294 return; | 295 return; |
| 295 } | 296 } |
| 296 | 297 |
| 297 // This timeout controls how long we scope before releasing control. This | 298 // This timeout controls how long we scope before releasing control. This |
| 298 // value does not prevent us from running for longer than this, but it is | 299 // value does not prevent us from running for longer than this, but it is |
| 299 // periodically checked to see if we have exceeded our allocated time. | 300 // periodically checked to see if we have exceeded our allocated time. |
| 300 const double maxScopingDuration = 0.1; // seconds | 301 const double maxScopingDuration = 0.1; // seconds |
| 301 | 302 |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 frame->ensureTextFinder().appendFindMatchRects(matchRects); | 545 frame->ensureTextFinder().appendFindMatchRects(matchRects); |
| 545 | 546 |
| 546 outputRects = matchRects; | 547 outputRects = matchRects; |
| 547 } | 548 } |
| 548 | 549 |
| 549 void TextFinder::appendFindMatchRects(Vector<WebFloatRect>& frameRects) | 550 void TextFinder::appendFindMatchRects(Vector<WebFloatRect>& frameRects) |
| 550 { | 551 { |
| 551 updateFindMatchRects(); | 552 updateFindMatchRects(); |
| 552 frameRects.reserveCapacity(frameRects.size() + m_findMatchesCache.size()); | 553 frameRects.reserveCapacity(frameRects.size() + m_findMatchesCache.size()); |
| 553 for (const FindMatch& match : m_findMatchesCache) { | 554 for (const FindMatch& match : m_findMatchesCache) { |
| 554 ASSERT(!match.m_rect.isEmpty()); | 555 DCHECK(!match.m_rect.isEmpty()); |
| 555 frameRects.append(match.m_rect); | 556 frameRects.append(match.m_rect); |
| 556 } | 557 } |
| 557 } | 558 } |
| 558 | 559 |
| 559 int TextFinder::selectNearestFindMatch(const WebFloatPoint& point, WebRect* sele
ctionRect) | 560 int TextFinder::selectNearestFindMatch(const WebFloatPoint& point, WebRect* sele
ctionRect) |
| 560 { | 561 { |
| 561 TextFinder* bestFinder = nullptr; | 562 TextFinder* bestFinder = nullptr; |
| 562 int indexInBestFrame = -1; | 563 int indexInBestFrame = -1; |
| 563 float distanceInBestFrame = FLT_MAX; | 564 float distanceInBestFrame = FLT_MAX; |
| 564 | 565 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 579 return -1; | 580 return -1; |
| 580 } | 581 } |
| 581 | 582 |
| 582 int TextFinder::nearestFindMatch(const FloatPoint& point, float& distanceSquared
) | 583 int TextFinder::nearestFindMatch(const FloatPoint& point, float& distanceSquared
) |
| 583 { | 584 { |
| 584 updateFindMatchRects(); | 585 updateFindMatchRects(); |
| 585 | 586 |
| 586 int nearest = -1; | 587 int nearest = -1; |
| 587 distanceSquared = FLT_MAX; | 588 distanceSquared = FLT_MAX; |
| 588 for (size_t i = 0; i < m_findMatchesCache.size(); ++i) { | 589 for (size_t i = 0; i < m_findMatchesCache.size(); ++i) { |
| 589 ASSERT(!m_findMatchesCache[i].m_rect.isEmpty()); | 590 DCHECK(!m_findMatchesCache[i].m_rect.isEmpty()); |
| 590 FloatSize offset = point - m_findMatchesCache[i].m_rect.center(); | 591 FloatSize offset = point - m_findMatchesCache[i].m_rect.center(); |
| 591 float width = offset.width(); | 592 float width = offset.width(); |
| 592 float height = offset.height(); | 593 float height = offset.height(); |
| 593 float currentDistanceSquared = width * width + height * height; | 594 float currentDistanceSquared = width * width + height * height; |
| 594 if (currentDistanceSquared < distanceSquared) { | 595 if (currentDistanceSquared < distanceSquared) { |
| 595 nearest = i; | 596 nearest = i; |
| 596 distanceSquared = currentDistanceSquared; | 597 distanceSquared = currentDistanceSquared; |
| 597 } | 598 } |
| 598 } | 599 } |
| 599 return nearest; | 600 return nearest; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 | 720 |
| 720 bool TextFinder::shouldScopeMatches(const String& searchText) | 721 bool TextFinder::shouldScopeMatches(const String& searchText) |
| 721 { | 722 { |
| 722 // Don't scope if we can't find a frame or a view. | 723 // Don't scope if we can't find a frame or a view. |
| 723 // The user may have closed the tab/application, so abort. | 724 // The user may have closed the tab/application, so abort. |
| 724 // Also ignore detached frames, as many find operations report to the main f
rame. | 725 // Also ignore detached frames, as many find operations report to the main f
rame. |
| 725 LocalFrame* frame = ownerFrame().frame(); | 726 LocalFrame* frame = ownerFrame().frame(); |
| 726 if (!frame || !frame->view() || !frame->page() || !ownerFrame().hasVisibleCo
ntent()) | 727 if (!frame || !frame->view() || !frame->page() || !ownerFrame().hasVisibleCo
ntent()) |
| 727 return false; | 728 return false; |
| 728 | 729 |
| 729 ASSERT(frame->document() && frame->view()); | 730 DCHECK(frame->document()); |
| 731 DCHECK(frame->view()); |
| 730 | 732 |
| 731 // If the frame completed the scoping operation and found 0 matches the last | 733 // If the frame completed the scoping operation and found 0 matches the last |
| 732 // time it was searched, then we don't have to search it again if the user i
s | 734 // time it was searched, then we don't have to search it again if the user i
s |
| 733 // just adding to the search string or sending the same search string again. | 735 // just adding to the search string or sending the same search string again. |
| 734 if (m_lastFindRequestCompletedWithNoMatches && !m_lastSearchString.isEmpty()
) { | 736 if (m_lastFindRequestCompletedWithNoMatches && !m_lastSearchString.isEmpty()
) { |
| 735 // Check to see if the search string prefixes match. | 737 // Check to see if the search string prefixes match. |
| 736 String previousSearchPrefix = | 738 String previousSearchPrefix = |
| 737 searchText.substring(0, m_lastSearchString.length()); | 739 searchText.substring(0, m_lastSearchString.length()); |
| 738 | 740 |
| 739 if (previousSearchPrefix == m_lastSearchString) | 741 if (previousSearchPrefix == m_lastSearchString) |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 visitor->trace(m_ownerFrame); | 815 visitor->trace(m_ownerFrame); |
| 814 visitor->trace(m_currentActiveMatchFrame); | 816 visitor->trace(m_currentActiveMatchFrame); |
| 815 visitor->trace(m_activeMatch); | 817 visitor->trace(m_activeMatch); |
| 816 visitor->trace(m_resumeScopingFromRange); | 818 visitor->trace(m_resumeScopingFromRange); |
| 817 visitor->trace(m_deferredScopingWork); | 819 visitor->trace(m_deferredScopingWork); |
| 818 visitor->trace(m_findMatchesCache); | 820 visitor->trace(m_findMatchesCache); |
| 819 #endif | 821 #endif |
| 820 } | 822 } |
| 821 | 823 |
| 822 } // namespace blink | 824 } // namespace blink |
| OLD | NEW |