| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 }; | 109 }; |
| 110 | 110 |
| 111 bool TextFinder::find(int identifier, | 111 bool TextFinder::find(int identifier, |
| 112 const WebString& searchText, | 112 const WebString& searchText, |
| 113 const WebFindOptions& options, | 113 const WebFindOptions& options, |
| 114 bool wrapWithinFrame, | 114 bool wrapWithinFrame, |
| 115 bool* activeNow) { | 115 bool* activeNow) { |
| 116 if (!options.findNext) | 116 if (!options.findNext) |
| 117 unmarkAllTextMatches(); | 117 unmarkAllTextMatches(); |
| 118 else | 118 else |
| 119 setMarkerActive(m_activeMatch.get(), false); | 119 setMarkerActive(m_activeMatch.get(), DocumentMarker::MatchStatus::Inactive); |
| 120 | 120 |
| 121 if (m_activeMatch && | 121 if (m_activeMatch && |
| 122 &m_activeMatch->ownerDocument() != ownerFrame().frame()->document()) | 122 &m_activeMatch->ownerDocument() != ownerFrame().frame()->document()) |
| 123 m_activeMatch = nullptr; | 123 m_activeMatch = nullptr; |
| 124 | 124 |
| 125 // If the user has selected something since the last Find operation we want | 125 // If the user has selected something since the last Find operation we want |
| 126 // to start from there. Otherwise, we start searching from where the last Find | 126 // to start from there. Otherwise, we start searching from where the last Find |
| 127 // operation left off (either a Find or a FindNext operation). | 127 // operation left off (either a Find or a FindNext operation). |
| 128 VisibleSelection selection(ownerFrame() | 128 VisibleSelection selection(ownerFrame() |
| 129 .frame() | 129 .frame() |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 ->pageNeedsAutosizing()) { | 167 ->pageNeedsAutosizing()) { |
| 168 ownerFrame().viewImpl()->zoomToFindInPageRect( | 168 ownerFrame().viewImpl()->zoomToFindInPageRect( |
| 169 ownerFrame().frameView()->contentsToRootFrame( | 169 ownerFrame().frameView()->contentsToRootFrame( |
| 170 enclosingIntRect(LayoutObject::absoluteBoundingBoxRectForRange( | 170 enclosingIntRect(LayoutObject::absoluteBoundingBoxRectForRange( |
| 171 m_activeMatch.get())))); | 171 m_activeMatch.get())))); |
| 172 } | 172 } |
| 173 | 173 |
| 174 bool wasActiveFrame = m_currentActiveMatchFrame; | 174 bool wasActiveFrame = m_currentActiveMatchFrame; |
| 175 m_currentActiveMatchFrame = true; | 175 m_currentActiveMatchFrame = true; |
| 176 | 176 |
| 177 bool isActive = setMarkerActive(m_activeMatch.get(), true); | 177 bool isActive = |
| 178 setMarkerActive(m_activeMatch.get(), DocumentMarker::MatchStatus::Active); |
| 178 if (activeNow) | 179 if (activeNow) |
| 179 *activeNow = isActive; | 180 *activeNow = isActive; |
| 180 | 181 |
| 181 // Make sure no node is focused. See http://crbug.com/38700. | 182 // Make sure no node is focused. See http://crbug.com/38700. |
| 182 ownerFrame().frame()->document()->clearFocusedElement(); | 183 ownerFrame().frame()->document()->clearFocusedElement(); |
| 183 | 184 |
| 184 // Set this frame as focused. | 185 // Set this frame as focused. |
| 185 ownerFrame().viewImpl()->setFocusedFrame(&ownerFrame()); | 186 ownerFrame().viewImpl()->setFocusedFrame(&ownerFrame()); |
| 186 | 187 |
| 187 if (!options.findNext || activeSelection || !isActive) { | 188 if (!options.findNext || activeSelection || !isActive) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 215 } | 216 } |
| 216 | 217 |
| 217 // We found something, so the result of the previous scoping may be outdated. | 218 // We found something, so the result of the previous scoping may be outdated. |
| 218 m_lastFindRequestCompletedWithNoMatches = false; | 219 m_lastFindRequestCompletedWithNoMatches = false; |
| 219 | 220 |
| 220 return true; | 221 return true; |
| 221 } | 222 } |
| 222 | 223 |
| 223 void TextFinder::clearActiveFindMatch() { | 224 void TextFinder::clearActiveFindMatch() { |
| 224 m_currentActiveMatchFrame = false; | 225 m_currentActiveMatchFrame = false; |
| 225 setMarkerActive(m_activeMatch.get(), false); | 226 setMarkerActive(m_activeMatch.get(), DocumentMarker::MatchStatus::Inactive); |
| 226 resetActiveMatch(); | 227 resetActiveMatch(); |
| 227 } | 228 } |
| 228 | 229 |
| 229 void TextFinder::stopFindingAndClearSelection() { | 230 void TextFinder::stopFindingAndClearSelection() { |
| 230 cancelPendingScopingEffort(); | 231 cancelPendingScopingEffort(); |
| 231 | 232 |
| 232 // Remove all markers for matches found and turn off the highlighting. | 233 // Remove all markers for matches found and turn off the highlighting. |
| 233 ownerFrame().frame()->document()->markers().removeMarkers( | 234 ownerFrame().frame()->document()->markers().removeMarkers( |
| 234 DocumentMarker::TextMatch); | 235 DocumentMarker::TextMatch); |
| 235 ownerFrame().frame()->editor().setMarkedTextMatchesAreHighlighted(false); | 236 ownerFrame().frame()->editor().setMarkedTextMatchesAreHighlighted(false); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 // To stop looking for the active tickmark, we set this flag. | 391 // To stop looking for the active tickmark, we set this flag. |
| 391 m_locatingActiveRect = false; | 392 m_locatingActiveRect = false; |
| 392 | 393 |
| 393 // Notify browser of new location for the selected rectangle. | 394 // Notify browser of new location for the selected rectangle. |
| 394 reportFindInPageSelection( | 395 reportFindInPageSelection( |
| 395 ownerFrame().frameView()->contentsToRootFrame(resultBounds), | 396 ownerFrame().frameView()->contentsToRootFrame(resultBounds), |
| 396 m_activeMatchIndex + 1, identifier); | 397 m_activeMatchIndex + 1, identifier); |
| 397 } | 398 } |
| 398 | 399 |
| 399 ownerFrame().frame()->document()->markers().addTextMatchMarker( | 400 ownerFrame().frame()->document()->markers().addTextMatchMarker( |
| 400 EphemeralRange(resultRange), foundActiveMatch); | 401 EphemeralRange(resultRange), |
| 402 foundActiveMatch ? DocumentMarker::MatchStatus::Active |
| 403 : DocumentMarker::MatchStatus::Inactive); |
| 401 | 404 |
| 402 m_findMatchesCache.push_back( | 405 m_findMatchesCache.push_back( |
| 403 FindMatch(resultRange, m_lastMatchCount + matchCount)); | 406 FindMatch(resultRange, m_lastMatchCount + matchCount)); |
| 404 | 407 |
| 405 // Set the new start for the search range to be the end of the previous | 408 // Set the new start for the search range to be the end of the previous |
| 406 // result range. There is no need to use a VisiblePosition here, | 409 // result range. There is no need to use a VisiblePosition here, |
| 407 // since findPlainText will use a TextIterator to go over the visible | 410 // since findPlainText will use a TextIterator to go over the visible |
| 408 // text nodes. | 411 // text nodes. |
| 409 searchStart = result.endPosition(); | 412 searchStart = result.endPosition(); |
| 410 | 413 |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 | 627 |
| 625 // Check if the match is already selected. | 628 // Check if the match is already selected. |
| 626 if (!m_currentActiveMatchFrame || !m_activeMatch || | 629 if (!m_currentActiveMatchFrame || !m_activeMatch || |
| 627 !areRangesEqual(m_activeMatch.get(), range)) { | 630 !areRangesEqual(m_activeMatch.get(), range)) { |
| 628 m_activeMatchIndex = m_findMatchesCache[index].m_ordinal - 1; | 631 m_activeMatchIndex = m_findMatchesCache[index].m_ordinal - 1; |
| 629 | 632 |
| 630 // Set this frame as the active frame (the one with the active highlight). | 633 // Set this frame as the active frame (the one with the active highlight). |
| 631 m_currentActiveMatchFrame = true; | 634 m_currentActiveMatchFrame = true; |
| 632 ownerFrame().viewImpl()->setFocusedFrame(&ownerFrame()); | 635 ownerFrame().viewImpl()->setFocusedFrame(&ownerFrame()); |
| 633 | 636 |
| 634 if (m_activeMatch) | 637 if (m_activeMatch) { |
| 635 setMarkerActive(m_activeMatch.get(), false); | 638 setMarkerActive(m_activeMatch.get(), |
| 639 DocumentMarker::MatchStatus::Inactive); |
| 640 } |
| 636 m_activeMatch = range; | 641 m_activeMatch = range; |
| 637 setMarkerActive(m_activeMatch.get(), true); | 642 setMarkerActive(m_activeMatch.get(), DocumentMarker::MatchStatus::Active); |
| 638 | 643 |
| 639 // Clear any user selection, to make sure Find Next continues on from the | 644 // Clear any user selection, to make sure Find Next continues on from the |
| 640 // match we just activated. | 645 // match we just activated. |
| 641 ownerFrame().frame()->selection().clear(); | 646 ownerFrame().frame()->selection().clear(); |
| 642 | 647 |
| 643 // Make sure no node is focused. See http://crbug.com/38700. | 648 // Make sure no node is focused. See http://crbug.com/38700. |
| 644 ownerFrame().frame()->document()->clearFocusedElement(); | 649 ownerFrame().frame()->document()->clearFocusedElement(); |
| 645 } | 650 } |
| 646 | 651 |
| 647 IntRect activeMatchRect; | 652 IntRect activeMatchRect; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 m_findRequestIdentifier(-1), | 689 m_findRequestIdentifier(-1), |
| 685 m_nextInvalidateAfter(0), | 690 m_nextInvalidateAfter(0), |
| 686 m_findMatchMarkersVersion(0), | 691 m_findMatchMarkersVersion(0), |
| 687 m_locatingActiveRect(false), | 692 m_locatingActiveRect(false), |
| 688 m_scopingInProgress(false), | 693 m_scopingInProgress(false), |
| 689 m_lastFindRequestCompletedWithNoMatches(false), | 694 m_lastFindRequestCompletedWithNoMatches(false), |
| 690 m_findMatchRectsAreValid(false) {} | 695 m_findMatchRectsAreValid(false) {} |
| 691 | 696 |
| 692 TextFinder::~TextFinder() {} | 697 TextFinder::~TextFinder() {} |
| 693 | 698 |
| 694 bool TextFinder::setMarkerActive(Range* range, bool active) { | 699 bool TextFinder::setMarkerActive(Range* range, |
| 700 DocumentMarker::MatchStatus matchStatus) { |
| 695 if (!range || range->collapsed()) | 701 if (!range || range->collapsed()) |
| 696 return false; | 702 return false; |
| 697 return ownerFrame().frame()->document()->markers().setMarkersActive( | 703 return ownerFrame().frame()->document()->markers().setMarkersActive( |
| 698 EphemeralRange(range), active); | 704 EphemeralRange(range), matchStatus); |
| 699 } | 705 } |
| 700 | 706 |
| 701 void TextFinder::unmarkAllTextMatches() { | 707 void TextFinder::unmarkAllTextMatches() { |
| 702 LocalFrame* frame = ownerFrame().frame(); | 708 LocalFrame* frame = ownerFrame().frame(); |
| 703 if (frame && frame->page() && | 709 if (frame && frame->page() && |
| 704 frame->editor().markedTextMatchesAreHighlighted()) | 710 frame->editor().markedTextMatchesAreHighlighted()) |
| 705 frame->document()->markers().removeMarkers(DocumentMarker::TextMatch); | 711 frame->document()->markers().removeMarkers(DocumentMarker::TextMatch); |
| 706 } | 712 } |
| 707 | 713 |
| 708 bool TextFinder::shouldScopeMatches(const String& searchText, | 714 bool TextFinder::shouldScopeMatches(const String& searchText, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 | 785 |
| 780 DEFINE_TRACE(TextFinder) { | 786 DEFINE_TRACE(TextFinder) { |
| 781 visitor->trace(m_ownerFrame); | 787 visitor->trace(m_ownerFrame); |
| 782 visitor->trace(m_activeMatch); | 788 visitor->trace(m_activeMatch); |
| 783 visitor->trace(m_resumeScopingFromRange); | 789 visitor->trace(m_resumeScopingFromRange); |
| 784 visitor->trace(m_deferredScopingWork); | 790 visitor->trace(m_deferredScopingWork); |
| 785 visitor->trace(m_findMatchesCache); | 791 visitor->trace(m_findMatchesCache); |
| 786 } | 792 } |
| 787 | 793 |
| 788 } // namespace blink | 794 } // namespace blink |
| OLD | NEW |