| 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 193 |
| 194 if (m_activeMatchIndex + 1 > m_lastMatchCount) | 194 if (m_activeMatchIndex + 1 > m_lastMatchCount) |
| 195 m_activeMatchIndex = 0; | 195 m_activeMatchIndex = 0; |
| 196 else if (m_activeMatchIndex < 0) | 196 else if (m_activeMatchIndex < 0) |
| 197 m_activeMatchIndex = m_lastMatchCount - 1; | 197 m_activeMatchIndex = m_lastMatchCount - 1; |
| 198 } | 198 } |
| 199 WebRect selectionRect = ownerFrame().frameView()->contentsToRootFrame(m_
activeMatch->boundingBox()); | 199 WebRect selectionRect = ownerFrame().frameView()->contentsToRootFrame(m_
activeMatch->boundingBox()); |
| 200 reportFindInPageSelection(selectionRect, m_activeMatchIndex + 1, identif
ier); | 200 reportFindInPageSelection(selectionRect, m_activeMatchIndex + 1, identif
ier); |
| 201 } | 201 } |
| 202 | 202 |
| 203 m_lastFindRequestCompletedWithNoMatches = false; | |
| 204 return true; | 203 return true; |
| 205 } | 204 } |
| 206 | 205 |
| 207 void TextFinder::clearActiveFindMatch() | 206 void TextFinder::clearActiveFindMatch() |
| 208 { | 207 { |
| 209 m_currentActiveMatchFrame = false; | 208 m_currentActiveMatchFrame = false; |
| 210 setMarkerActive(m_activeMatch.get(), false); | 209 setMarkerActive(m_activeMatch.get(), false); |
| 210 resetActiveMatch(); |
| 211 } | 211 } |
| 212 | 212 |
| 213 void TextFinder::stopFindingAndClearSelection() | 213 void TextFinder::stopFindingAndClearSelection() |
| 214 { | 214 { |
| 215 cancelPendingScopingEffort(); | 215 cancelPendingScopingEffort(); |
| 216 | 216 |
| 217 // Remove all markers for matches found and turn off the highlighting. | 217 // Remove all markers for matches found and turn off the highlighting. |
| 218 ownerFrame().frame()->document()->markers().removeMarkers(DocumentMarker::Te
xtMatch); | 218 ownerFrame().frame()->document()->markers().removeMarkers(DocumentMarker::Te
xtMatch); |
| 219 ownerFrame().frame()->editor().setMarkedTextMatchesAreHighlighted(false); | 219 ownerFrame().frame()->editor().setMarkedTextMatchesAreHighlighted(false); |
| 220 clearFindMatchesCache(); | 220 clearFindMatchesCache(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 // The view might be null on detached frames. | 278 // The view might be null on detached frames. |
| 279 LocalFrame* frame = ownerFrame().frame(); | 279 LocalFrame* frame = ownerFrame().frame(); |
| 280 if (frame && frame->page()) | 280 if (frame && frame->page()) |
| 281 m_frameScoping = true; | 281 m_frameScoping = true; |
| 282 | 282 |
| 283 // Now, defer scoping until later to allow find operation to finish quic
kly. | 283 // Now, defer scoping until later to allow find operation to finish quic
kly. |
| 284 scopeStringMatchesSoon(identifier, searchText, options, false); // false
means just reset, so don't do it again. | 284 scopeStringMatchesSoon(identifier, searchText, options, false); // false
means just reset, so don't do it again. |
| 285 return; | 285 return; |
| 286 } | 286 } |
| 287 | 287 |
| 288 if (!shouldScopeMatches(searchText)) { | 288 if (!shouldScopeMatches(searchText, options)) { |
| 289 finishCurrentScopingEffort(identifier); | 289 finishCurrentScopingEffort(identifier); |
| 290 return; | 290 return; |
| 291 } | 291 } |
| 292 | 292 |
| 293 PositionInFlatTree searchStart = PositionInFlatTree::firstPositionInNode(own
erFrame().frame()->document()); | 293 PositionInFlatTree searchStart = PositionInFlatTree::firstPositionInNode(own
erFrame().frame()->document()); |
| 294 PositionInFlatTree searchEnd = PositionInFlatTree::lastPositionInNode(ownerF
rame().frame()->document()); | 294 PositionInFlatTree searchEnd = PositionInFlatTree::lastPositionInNode(ownerF
rame().frame()->document()); |
| 295 DCHECK_EQ(searchStart.document(), searchEnd.document()); | 295 DCHECK_EQ(searchStart.document(), searchEnd.document()); |
| 296 | 296 |
| 297 if (m_resumeScopingFromRange) { | 297 if (m_resumeScopingFromRange) { |
| 298 // This is a continuation of a scoping operation that timed out and didn
't | 298 // This is a continuation of a scoping operation that timed out and didn
't |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 | 450 |
| 451 void TextFinder::increaseMatchCount(int identifier, int count) | 451 void TextFinder::increaseMatchCount(int identifier, int count) |
| 452 { | 452 { |
| 453 if (count) | 453 if (count) |
| 454 ++m_findMatchMarkersVersion; | 454 ++m_findMatchMarkersVersion; |
| 455 | 455 |
| 456 m_totalMatchCount += count; | 456 m_totalMatchCount += count; |
| 457 | 457 |
| 458 // Update the UI with the latest findings. | 458 // Update the UI with the latest findings. |
| 459 if (ownerFrame().client()) | 459 if (ownerFrame().client()) |
| 460 ownerFrame().client()->reportFindInPageMatchCount(identifier, m_totalMat
chCount, !m_frameScoping); | 460 ownerFrame().client()->reportFindInPageMatchCount(identifier, m_totalMat
chCount, !m_frameScoping || !m_totalMatchCount); |
| 461 } | 461 } |
| 462 | 462 |
| 463 void TextFinder::reportFindInPageSelection(const WebRect& selectionRect, int act
iveMatchOrdinal, int identifier) | 463 void TextFinder::reportFindInPageSelection(const WebRect& selectionRect, int act
iveMatchOrdinal, int identifier) |
| 464 { | 464 { |
| 465 // Update the UI with the latest selection rect. | 465 // Update the UI with the latest selection rect. |
| 466 if (ownerFrame().client()) | 466 if (ownerFrame().client()) |
| 467 ownerFrame().client()->reportFindInPageSelection(identifier, activeMatch
Ordinal, selectionRect); | 467 ownerFrame().client()->reportFindInPageSelection(identifier, activeMatch
Ordinal, selectionRect); |
| 468 | 468 |
| 469 // Update accessibility too, so if the user commits to this query | 469 // Update accessibility too, so if the user commits to this query |
| 470 // we can move accessibility focus to this result. | 470 // we can move accessibility focus to this result. |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 return ownerFrame().frame()->document()->markers().setMarkersActive(Ephemera
lRange(range), active); | 666 return ownerFrame().frame()->document()->markers().setMarkersActive(Ephemera
lRange(range), active); |
| 667 } | 667 } |
| 668 | 668 |
| 669 void TextFinder::unmarkAllTextMatches() | 669 void TextFinder::unmarkAllTextMatches() |
| 670 { | 670 { |
| 671 LocalFrame* frame = ownerFrame().frame(); | 671 LocalFrame* frame = ownerFrame().frame(); |
| 672 if (frame && frame->page() && frame->editor().markedTextMatchesAreHighlighte
d()) | 672 if (frame && frame->page() && frame->editor().markedTextMatchesAreHighlighte
d()) |
| 673 frame->document()->markers().removeMarkers(DocumentMarker::TextMatch); | 673 frame->document()->markers().removeMarkers(DocumentMarker::TextMatch); |
| 674 } | 674 } |
| 675 | 675 |
| 676 bool TextFinder::shouldScopeMatches(const String& searchText) | 676 bool TextFinder::shouldScopeMatches(const String& searchText, const WebFindOptio
ns& options) |
| 677 { | 677 { |
| 678 // Don't scope if we can't find a frame or a view. | 678 // Don't scope if we can't find a frame or a view. |
| 679 // The user may have closed the tab/application, so abort. | 679 // The user may have closed the tab/application, so abort. |
| 680 LocalFrame* frame = ownerFrame().frame(); | 680 LocalFrame* frame = ownerFrame().frame(); |
| 681 if (!frame || !frame->view() || !frame->page() || !ownerFrame().hasVisibleCo
ntent()) | 681 if (!frame || !frame->view() || !frame->page()) |
| 682 return false; | 682 return false; |
| 683 | 683 |
| 684 DCHECK(frame->document()); | 684 DCHECK(frame->document()); |
| 685 DCHECK(frame->view()); | 685 DCHECK(frame->view()); |
| 686 | 686 |
| 687 if (options.force) |
| 688 return true; |
| 689 |
| 690 if (!ownerFrame().hasVisibleContent()) |
| 691 return false; |
| 692 |
| 687 // If the frame completed the scoping operation and found 0 matches the last | 693 // If the frame completed the scoping operation and found 0 matches the last |
| 688 // time it was searched, then we don't have to search it again if the user i
s | 694 // time it was searched, then we don't have to search it again if the user i
s |
| 689 // just adding to the search string or sending the same search string again. | 695 // just adding to the search string or sending the same search string again. |
| 690 if (m_lastFindRequestCompletedWithNoMatches && !m_lastSearchString.isEmpty()
) { | 696 if (m_lastFindRequestCompletedWithNoMatches && !m_lastSearchString.isEmpty()
) { |
| 691 // Check to see if the search string prefixes match. | 697 // Check to see if the search string prefixes match. |
| 692 String previousSearchPrefix = | 698 String previousSearchPrefix = |
| 693 searchText.substring(0, m_lastSearchString.length()); | 699 searchText.substring(0, m_lastSearchString.length()); |
| 694 | 700 |
| 695 if (previousSearchPrefix == m_lastSearchString) | 701 if (previousSearchPrefix == m_lastSearchString) |
| 696 return false; // Don't search this frame, it will be fruitless. | 702 return false; // Don't search this frame, it will be fruitless. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 DEFINE_TRACE(TextFinder) | 746 DEFINE_TRACE(TextFinder) |
| 741 { | 747 { |
| 742 visitor->trace(m_ownerFrame); | 748 visitor->trace(m_ownerFrame); |
| 743 visitor->trace(m_activeMatch); | 749 visitor->trace(m_activeMatch); |
| 744 visitor->trace(m_resumeScopingFromRange); | 750 visitor->trace(m_resumeScopingFromRange); |
| 745 visitor->trace(m_deferredScopingWork); | 751 visitor->trace(m_deferredScopingWork); |
| 746 visitor->trace(m_findMatchesCache); | 752 visitor->trace(m_findMatchesCache); |
| 747 } | 753 } |
| 748 | 754 |
| 749 } // namespace blink | 755 } // namespace blink |
| OLD | NEW |