| 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 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 // since findPlainText will use a TextIterator to go over the visible | 401 // since findPlainText will use a TextIterator to go over the visible |
| 402 // text nodes. | 402 // text nodes. |
| 403 searchStart = result.endPosition(); | 403 searchStart = result.endPosition(); |
| 404 | 404 |
| 405 m_resumeScopingFromRange = Range::create( | 405 m_resumeScopingFromRange = Range::create( |
| 406 result.document(), toPositionInDOMTree(result.endPosition()), | 406 result.document(), toPositionInDOMTree(result.endPosition()), |
| 407 toPositionInDOMTree(result.endPosition())); | 407 toPositionInDOMTree(result.endPosition())); |
| 408 timedOut = (currentTime() - startTime) >= maxScopingDuration; | 408 timedOut = (currentTime() - startTime) >= maxScopingDuration; |
| 409 } while (!timedOut); | 409 } while (!timedOut); |
| 410 | 410 |
| 411 // Remember what we search for last time, so we can skip searching if more | |
| 412 // letters are added to the search string (and last outcome was 0). | |
| 413 m_lastSearchString = searchText; | |
| 414 | |
| 415 if (matchCount > 0) { | 411 if (matchCount > 0) { |
| 416 ownerFrame().frame()->editor().setMarkedTextMatchesAreHighlighted(true); | 412 ownerFrame().frame()->editor().setMarkedTextMatchesAreHighlighted(true); |
| 417 | 413 |
| 418 m_lastMatchCount += matchCount; | 414 m_lastMatchCount += matchCount; |
| 419 | 415 |
| 420 // Let the frame know how many matches we found during this pass. | 416 // Let the frame know how many matches we found during this pass. |
| 421 ownerFrame().increaseMatchCount(matchCount, identifier); | 417 ownerFrame().increaseMatchCount(matchCount, identifier); |
| 422 } | 418 } |
| 423 | 419 |
| 424 if (timedOut) { | 420 if (timedOut) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 442 return; | 438 return; |
| 443 | 439 |
| 444 m_frameScoping = false; | 440 m_frameScoping = false; |
| 445 ownerFrame().increaseMatchCount(0, identifier); | 441 ownerFrame().increaseMatchCount(0, identifier); |
| 446 } | 442 } |
| 447 | 443 |
| 448 void TextFinder::finishCurrentScopingEffort(int identifier) { | 444 void TextFinder::finishCurrentScopingEffort(int identifier) { |
| 449 flushCurrentScopingEffort(identifier); | 445 flushCurrentScopingEffort(identifier); |
| 450 | 446 |
| 451 m_scopingInProgress = false; | 447 m_scopingInProgress = false; |
| 452 m_lastFindRequestCompletedWithNoMatches = !m_lastMatchCount; | |
| 453 | 448 |
| 454 // This frame is done, so show any scrollbar tickmarks we haven't drawn yet. | 449 // This frame is done, so show any scrollbar tickmarks we haven't drawn yet. |
| 455 ownerFrame().frameView()->invalidatePaintForTickmarks(); | 450 ownerFrame().frameView()->invalidatePaintForTickmarks(); |
| 456 } | 451 } |
| 457 | 452 |
| 458 void TextFinder::cancelPendingScopingEffort() { | 453 void TextFinder::cancelPendingScopingEffort() { |
| 459 for (DeferredScopeStringMatches* deferredWork : m_deferredScopingWork) | 454 for (DeferredScopeStringMatches* deferredWork : m_deferredScopingWork) |
| 460 deferredWork->dispose(); | 455 deferredWork->dispose(); |
| 461 m_deferredScopingWork.clear(); | 456 m_deferredScopingWork.clear(); |
| 462 | 457 |
| 463 m_activeMatchIndex = -1; | 458 m_activeMatchIndex = -1; |
| 464 | 459 |
| 465 // Last request didn't complete. | |
| 466 if (m_scopingInProgress) | |
| 467 m_lastFindRequestCompletedWithNoMatches = false; | |
| 468 | |
| 469 m_scopingInProgress = false; | 460 m_scopingInProgress = false; |
| 470 } | 461 } |
| 471 | 462 |
| 472 void TextFinder::increaseMatchCount(int identifier, int count) { | 463 void TextFinder::increaseMatchCount(int identifier, int count) { |
| 473 if (count) | 464 if (count) |
| 474 ++m_findMatchMarkersVersion; | 465 ++m_findMatchMarkersVersion; |
| 475 | 466 |
| 476 m_totalMatchCount += count; | 467 m_totalMatchCount += count; |
| 477 | 468 |
| 478 // Update the UI with the latest findings. | 469 // Update the UI with the latest findings. |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 m_activeMatchIndex(-1), | 661 m_activeMatchIndex(-1), |
| 671 m_resumeScopingFromRange(nullptr), | 662 m_resumeScopingFromRange(nullptr), |
| 672 m_lastMatchCount(-1), | 663 m_lastMatchCount(-1), |
| 673 m_totalMatchCount(-1), | 664 m_totalMatchCount(-1), |
| 674 m_frameScoping(false), | 665 m_frameScoping(false), |
| 675 m_findRequestIdentifier(-1), | 666 m_findRequestIdentifier(-1), |
| 676 m_nextInvalidateAfter(0), | 667 m_nextInvalidateAfter(0), |
| 677 m_findMatchMarkersVersion(0), | 668 m_findMatchMarkersVersion(0), |
| 678 m_locatingActiveRect(false), | 669 m_locatingActiveRect(false), |
| 679 m_scopingInProgress(false), | 670 m_scopingInProgress(false), |
| 680 m_lastFindRequestCompletedWithNoMatches(false), | |
| 681 m_findMatchRectsAreValid(false) {} | 671 m_findMatchRectsAreValid(false) {} |
| 682 | 672 |
| 683 TextFinder::~TextFinder() {} | 673 TextFinder::~TextFinder() {} |
| 684 | 674 |
| 685 bool TextFinder::setMarkerActive(Range* range, bool active) { | 675 bool TextFinder::setMarkerActive(Range* range, bool active) { |
| 686 if (!range || range->collapsed()) | 676 if (!range || range->collapsed()) |
| 687 return false; | 677 return false; |
| 688 return ownerFrame().frame()->document()->markers().setMarkersActive( | 678 return ownerFrame().frame()->document()->markers().setMarkersActive( |
| 689 EphemeralRange(range), active); | 679 EphemeralRange(range), active); |
| 690 } | 680 } |
| 691 | 681 |
| 692 void TextFinder::unmarkAllTextMatches() { | 682 void TextFinder::unmarkAllTextMatches() { |
| 693 LocalFrame* frame = ownerFrame().frame(); | 683 LocalFrame* frame = ownerFrame().frame(); |
| 694 if (frame && frame->page() && | 684 if (frame && frame->page() && |
| 695 frame->editor().markedTextMatchesAreHighlighted()) | 685 frame->editor().markedTextMatchesAreHighlighted()) |
| 696 frame->document()->markers().removeMarkers(DocumentMarker::TextMatch); | 686 frame->document()->markers().removeMarkers(DocumentMarker::TextMatch); |
| 697 } | 687 } |
| 698 | 688 |
| 699 bool TextFinder::shouldScopeMatches(const String& searchText, | 689 bool TextFinder::shouldScopeMatches(const String& searchText, |
| 700 const WebFindOptions& options) { | 690 const WebFindOptions& options) { |
| 701 // Don't scope if we can't find a frame or a view. | 691 // Don't scope if we can't find a frame or a view. |
| 702 // The user may have closed the tab/application, so abort. | 692 // The user may have closed the tab/application, so abort. |
| 703 LocalFrame* frame = ownerFrame().frame(); | 693 LocalFrame* frame = ownerFrame().frame(); |
| 704 if (!frame || !frame->view() || !frame->page()) | 694 if (!frame || !frame->view() || !frame->page()) |
| 705 return false; | 695 return false; |
| 706 | 696 |
| 707 DCHECK(frame->document()); | 697 DCHECK(frame->document()); |
| 708 DCHECK(frame->view()); | 698 DCHECK(frame->view()); |
| 709 | 699 |
| 710 if (options.force) | 700 return options.force || ownerFrame().hasVisibleContent(); |
| 711 return true; | |
| 712 | |
| 713 if (!ownerFrame().hasVisibleContent()) | |
| 714 return false; | |
| 715 | |
| 716 // If the frame completed the scoping operation and found 0 matches the last | |
| 717 // time it was searched, then we don't have to search it again if the user is | |
| 718 // just adding to the search string or sending the same search string again. | |
| 719 if (m_lastFindRequestCompletedWithNoMatches && | |
| 720 !m_lastSearchString.isEmpty()) { | |
| 721 // Check to see if the search string prefixes match. | |
| 722 String previousSearchPrefix = | |
| 723 searchText.substring(0, m_lastSearchString.length()); | |
| 724 | |
| 725 if (previousSearchPrefix == m_lastSearchString) | |
| 726 return false; // Don't search this frame, it will be fruitless. | |
| 727 } | |
| 728 | |
| 729 return true; | |
| 730 } | 701 } |
| 731 | 702 |
| 732 void TextFinder::scopeStringMatchesSoon(int identifier, | 703 void TextFinder::scopeStringMatchesSoon(int identifier, |
| 733 const WebString& searchText, | 704 const WebString& searchText, |
| 734 const WebFindOptions& options, | 705 const WebFindOptions& options, |
| 735 bool reset) { | 706 bool reset) { |
| 736 m_deferredScopingWork.append(DeferredScopeStringMatches::create( | 707 m_deferredScopingWork.append(DeferredScopeStringMatches::create( |
| 737 this, identifier, searchText, options, reset)); | 708 this, identifier, searchText, options, reset)); |
| 738 } | 709 } |
| 739 | 710 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 | 744 |
| 774 DEFINE_TRACE(TextFinder) { | 745 DEFINE_TRACE(TextFinder) { |
| 775 visitor->trace(m_ownerFrame); | 746 visitor->trace(m_ownerFrame); |
| 776 visitor->trace(m_activeMatch); | 747 visitor->trace(m_activeMatch); |
| 777 visitor->trace(m_resumeScopingFromRange); | 748 visitor->trace(m_resumeScopingFromRange); |
| 778 visitor->trace(m_deferredScopingWork); | 749 visitor->trace(m_deferredScopingWork); |
| 779 visitor->trace(m_findMatchesCache); | 750 visitor->trace(m_findMatchesCache); |
| 780 } | 751 } |
| 781 | 752 |
| 782 } // namespace blink | 753 } // namespace blink |
| OLD | NEW |