Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: third_party/WebKit/Source/web/TextFinder.cpp

Issue 2428613002: Removed limitation on searching frames for the same string prefix.
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 return; 442 return;
443 443
444 m_frameScoping = false; 444 m_frameScoping = false;
445 ownerFrame().increaseMatchCount(0, identifier); 445 ownerFrame().increaseMatchCount(0, identifier);
446 } 446 }
447 447
448 void TextFinder::finishCurrentScopingEffort(int identifier) { 448 void TextFinder::finishCurrentScopingEffort(int identifier) {
449 flushCurrentScopingEffort(identifier); 449 flushCurrentScopingEffort(identifier);
450 450
451 m_scopingInProgress = false; 451 m_scopingInProgress = false;
452 m_lastFindRequestCompletedWithNoMatches = !m_lastMatchCount;
453 452
454 // This frame is done, so show any scrollbar tickmarks we haven't drawn yet. 453 // This frame is done, so show any scrollbar tickmarks we haven't drawn yet.
455 ownerFrame().frameView()->invalidatePaintForTickmarks(); 454 ownerFrame().frameView()->invalidatePaintForTickmarks();
456 } 455 }
457 456
458 void TextFinder::cancelPendingScopingEffort() { 457 void TextFinder::cancelPendingScopingEffort() {
459 for (DeferredScopeStringMatches* deferredWork : m_deferredScopingWork) 458 for (DeferredScopeStringMatches* deferredWork : m_deferredScopingWork)
460 deferredWork->dispose(); 459 deferredWork->dispose();
461 m_deferredScopingWork.clear(); 460 m_deferredScopingWork.clear();
462 461
463 m_activeMatchIndex = -1; 462 m_activeMatchIndex = -1;
464 463
465 // Last request didn't complete.
466 if (m_scopingInProgress)
467 m_lastFindRequestCompletedWithNoMatches = false;
468
469 m_scopingInProgress = false; 464 m_scopingInProgress = false;
470 } 465 }
471 466
472 void TextFinder::increaseMatchCount(int identifier, int count) { 467 void TextFinder::increaseMatchCount(int identifier, int count) {
473 if (count) 468 if (count)
474 ++m_findMatchMarkersVersion; 469 ++m_findMatchMarkersVersion;
475 470
476 m_totalMatchCount += count; 471 m_totalMatchCount += count;
477 472
478 // Update the UI with the latest findings. 473 // Update the UI with the latest findings.
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 m_activeMatchIndex(-1), 665 m_activeMatchIndex(-1),
671 m_resumeScopingFromRange(nullptr), 666 m_resumeScopingFromRange(nullptr),
672 m_lastMatchCount(-1), 667 m_lastMatchCount(-1),
673 m_totalMatchCount(-1), 668 m_totalMatchCount(-1),
674 m_frameScoping(false), 669 m_frameScoping(false),
675 m_findRequestIdentifier(-1), 670 m_findRequestIdentifier(-1),
676 m_nextInvalidateAfter(0), 671 m_nextInvalidateAfter(0),
677 m_findMatchMarkersVersion(0), 672 m_findMatchMarkersVersion(0),
678 m_locatingActiveRect(false), 673 m_locatingActiveRect(false),
679 m_scopingInProgress(false), 674 m_scopingInProgress(false),
680 m_lastFindRequestCompletedWithNoMatches(false),
681 m_findMatchRectsAreValid(false) {} 675 m_findMatchRectsAreValid(false) {}
682 676
683 TextFinder::~TextFinder() {} 677 TextFinder::~TextFinder() {}
684 678
685 bool TextFinder::setMarkerActive(Range* range, bool active) { 679 bool TextFinder::setMarkerActive(Range* range, bool active) {
686 if (!range || range->collapsed()) 680 if (!range || range->collapsed())
687 return false; 681 return false;
688 return ownerFrame().frame()->document()->markers().setMarkersActive( 682 return ownerFrame().frame()->document()->markers().setMarkersActive(
689 EphemeralRange(range), active); 683 EphemeralRange(range), active);
690 } 684 }
691 685
692 void TextFinder::unmarkAllTextMatches() { 686 void TextFinder::unmarkAllTextMatches() {
693 LocalFrame* frame = ownerFrame().frame(); 687 LocalFrame* frame = ownerFrame().frame();
694 if (frame && frame->page() && 688 if (frame && frame->page() &&
695 frame->editor().markedTextMatchesAreHighlighted()) 689 frame->editor().markedTextMatchesAreHighlighted())
696 frame->document()->markers().removeMarkers(DocumentMarker::TextMatch); 690 frame->document()->markers().removeMarkers(DocumentMarker::TextMatch);
697 } 691 }
698 692
699 bool TextFinder::shouldScopeMatches(const String& searchText, 693 bool TextFinder::shouldScopeMatches(const String& searchText,
700 const WebFindOptions& options) { 694 const WebFindOptions& options) {
701 // Don't scope if we can't find a frame or a view. 695 // Don't scope if we can't find a frame or a view.
702 // The user may have closed the tab/application, so abort. 696 // The user may have closed the tab/application, so abort.
703 LocalFrame* frame = ownerFrame().frame(); 697 LocalFrame* frame = ownerFrame().frame();
704 if (!frame || !frame->view() || !frame->page()) 698 if (!frame || !frame->view() || !frame->page())
705 return false; 699 return false;
706 700
707 DCHECK(frame->document()); 701 DCHECK(frame->document());
708 DCHECK(frame->view()); 702 DCHECK(frame->view());
709 703
710 if (options.force) 704 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 } 705 }
731 706
732 void TextFinder::scopeStringMatchesSoon(int identifier, 707 void TextFinder::scopeStringMatchesSoon(int identifier,
733 const WebString& searchText, 708 const WebString& searchText,
734 const WebFindOptions& options, 709 const WebFindOptions& options,
735 bool reset) { 710 bool reset) {
736 m_deferredScopingWork.append(DeferredScopeStringMatches::create( 711 m_deferredScopingWork.append(DeferredScopeStringMatches::create(
737 this, identifier, searchText, options, reset)); 712 this, identifier, searchText, options, reset));
738 } 713 }
739 714
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 748
774 DEFINE_TRACE(TextFinder) { 749 DEFINE_TRACE(TextFinder) {
775 visitor->trace(m_ownerFrame); 750 visitor->trace(m_ownerFrame);
776 visitor->trace(m_activeMatch); 751 visitor->trace(m_activeMatch);
777 visitor->trace(m_resumeScopingFromRange); 752 visitor->trace(m_resumeScopingFromRange);
778 visitor->trace(m_deferredScopingWork); 753 visitor->trace(m_deferredScopingWork);
779 visitor->trace(m_findMatchesCache); 754 visitor->trace(m_findMatchesCache);
780 } 755 }
781 756
782 } // namespace blink 757 } // namespace blink
OLDNEW
« third_party/WebKit/Source/web/TextFinder.h ('K') | « third_party/WebKit/Source/web/TextFinder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698