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

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

Issue 1865813002: Remove RawPtr from Source/web/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 8 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #include "public/web/WebFindOptions.h" 51 #include "public/web/WebFindOptions.h"
52 #include "public/web/WebFrameClient.h" 52 #include "public/web/WebFrameClient.h"
53 #include "public/web/WebViewClient.h" 53 #include "public/web/WebViewClient.h"
54 #include "web/FindInPageCoordinates.h" 54 #include "web/FindInPageCoordinates.h"
55 #include "web/WebLocalFrameImpl.h" 55 #include "web/WebLocalFrameImpl.h"
56 #include "web/WebViewImpl.h" 56 #include "web/WebViewImpl.h"
57 #include "wtf/CurrentTime.h" 57 #include "wtf/CurrentTime.h"
58 58
59 namespace blink { 59 namespace blink {
60 60
61 TextFinder::FindMatch::FindMatch(RawPtr<Range> range, int ordinal) 61 TextFinder::FindMatch::FindMatch(Range* range, int ordinal)
62 : m_range(range) 62 : m_range(range)
63 , m_ordinal(ordinal) 63 , m_ordinal(ordinal)
64 { 64 {
65 } 65 }
66 66
67 DEFINE_TRACE(TextFinder::FindMatch) 67 DEFINE_TRACE(TextFinder::FindMatch)
68 { 68 {
69 visitor->trace(m_range); 69 visitor->trace(m_range);
70 } 70 }
71 71
72 class TextFinder::DeferredScopeStringMatches : public GarbageCollectedFinalized< TextFinder::DeferredScopeStringMatches> { 72 class TextFinder::DeferredScopeStringMatches : public GarbageCollectedFinalized< TextFinder::DeferredScopeStringMatches> {
73 public: 73 public:
74 static RawPtr<DeferredScopeStringMatches> create(TextFinder* textFinder, int identifier, const WebString& searchText, const WebFindOptions& options, bool re set) 74 static DeferredScopeStringMatches* create(TextFinder* textFinder, int identi fier, const WebString& searchText, const WebFindOptions& options, bool reset)
75 { 75 {
76 return new DeferredScopeStringMatches(textFinder, identifier, searchText , options, reset); 76 return new DeferredScopeStringMatches(textFinder, identifier, searchText , options, reset);
77 } 77 }
78 78
79 DEFINE_INLINE_TRACE() 79 DEFINE_INLINE_TRACE()
80 { 80 {
81 visitor->trace(m_textFinder); 81 visitor->trace(m_textFinder);
82 } 82 }
83 83
84 void dispose() 84 void dispose()
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 // Find next occurrence of the search string. 307 // Find next occurrence of the search string.
308 // FIXME: (http://crbug.com/6818) This WebKit operation may run for long er 308 // FIXME: (http://crbug.com/6818) This WebKit operation may run for long er
309 // than the timeout value, and is not interruptible as it is currently 309 // than the timeout value, and is not interruptible as it is currently
310 // written. We may need to rewrite it with interruptibility in mind, or 310 // written. We may need to rewrite it with interruptibility in mind, or
311 // find an alternative. 311 // find an alternative.
312 const EphemeralRangeInFlatTree result = findPlainText(EphemeralRangeInFl atTree(searchStart, searchEnd), searchText, options.matchCase ? 0 : CaseInsensit ive); 312 const EphemeralRangeInFlatTree result = findPlainText(EphemeralRangeInFl atTree(searchStart, searchEnd), searchText, options.matchCase ? 0 : CaseInsensit ive);
313 if (result.isCollapsed()) { 313 if (result.isCollapsed()) {
314 // Not found. 314 // Not found.
315 break; 315 break;
316 } 316 }
317 RawPtr<Range> resultRange = Range::create(result.document(), toPositionI nDOMTree(result.startPosition()), toPositionInDOMTree(result.endPosition())); 317 Range* resultRange = Range::create(result.document(), toPositionInDOMTre e(result.startPosition()), toPositionInDOMTree(result.endPosition()));
318 if (resultRange->collapsed()) { 318 if (resultRange->collapsed()) {
319 // resultRange will be collapsed if the matched text spans over mult iple TreeScopes. 319 // resultRange will be collapsed if the matched text spans over mult iple TreeScopes.
320 // FIXME: Show such matches to users. 320 // FIXME: Show such matches to users.
321 searchStart = result.endPosition(); 321 searchStart = result.endPosition();
322 continue; 322 continue;
323 } 323 }
324 324
325 ++matchCount; 325 ++matchCount;
326 326
327 // Catch a special case where Find found something but doesn't know what 327 // Catch a special case where Find found something but doesn't know what
(...skipping 20 matching lines...) Expand all
348 // To stop looking for the active tickmark, we set this flag. 348 // To stop looking for the active tickmark, we set this flag.
349 m_locatingActiveRect = false; 349 m_locatingActiveRect = false;
350 350
351 // Notify browser of new location for the selected rectangle. 351 // Notify browser of new location for the selected rectangle.
352 reportFindInPageSelection( 352 reportFindInPageSelection(
353 ownerFrame().frameView()->contentsToRootFrame(resultBounds), 353 ownerFrame().frameView()->contentsToRootFrame(resultBounds),
354 m_activeMatchIndexInCurrentFrame + 1, 354 m_activeMatchIndexInCurrentFrame + 1,
355 identifier); 355 identifier);
356 } 356 }
357 357
358 addMarker(resultRange.get(), foundActiveMatch); 358 addMarker(resultRange, foundActiveMatch);
359 359
360 m_findMatchesCache.append(FindMatch(resultRange.get(), m_lastMatchCount + matchCount)); 360 m_findMatchesCache.append(FindMatch(resultRange, m_lastMatchCount + matc hCount));
361 361
362 // Set the new start for the search range to be the end of the previous 362 // Set the new start for the search range to be the end of the previous
363 // result range. There is no need to use a VisiblePosition here, 363 // result range. There is no need to use a VisiblePosition here,
364 // since findPlainText will use a TextIterator to go over the visible 364 // since findPlainText will use a TextIterator to go over the visible
365 // text nodes. 365 // text nodes.
366 searchStart = result.endPosition(); 366 searchStart = result.endPosition();
367 367
368 m_resumeScopingFromRange = Range::create(result.document(), toPositionIn DOMTree(result.endPosition()), toPositionInDOMTree(result.endPosition())); 368 m_resumeScopingFromRange = Range::create(result.document(), toPositionIn DOMTree(result.endPosition()), toPositionInDOMTree(result.endPosition()));
369 timedOut = (currentTime() - startTime) >= maxScopingDuration; 369 timedOut = (currentTime() - startTime) >= maxScopingDuration;
370 } while (!timedOut); 370 } while (!timedOut);
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 distanceSquared = currentDistanceSquared; 597 distanceSquared = currentDistanceSquared;
598 } 598 }
599 } 599 }
600 return nearest; 600 return nearest;
601 } 601 }
602 602
603 int TextFinder::selectFindMatch(unsigned index, WebRect* selectionRect) 603 int TextFinder::selectFindMatch(unsigned index, WebRect* selectionRect)
604 { 604 {
605 ASSERT_WITH_SECURITY_IMPLICATION(index < m_findMatchesCache.size()); 605 ASSERT_WITH_SECURITY_IMPLICATION(index < m_findMatchesCache.size());
606 606
607 RawPtr<Range> range = m_findMatchesCache[index].m_range; 607 Range* range = m_findMatchesCache[index].m_range;
608 if (!range->boundaryPointsValid() || !range->startContainer()->inShadowInclu dingDocument()) 608 if (!range->boundaryPointsValid() || !range->startContainer()->inShadowInclu dingDocument())
609 return -1; 609 return -1;
610 610
611 // Check if the match is already selected. 611 // Check if the match is already selected.
612 TextFinder& mainFrameTextFinder = ownerFrame().viewImpl()->mainFrameImpl()-> ensureTextFinder(); 612 TextFinder& mainFrameTextFinder = ownerFrame().viewImpl()->mainFrameImpl()-> ensureTextFinder();
613 WebLocalFrameImpl* activeMatchFrame = mainFrameTextFinder.m_currentActiveMat chFrame; 613 WebLocalFrameImpl* activeMatchFrame = mainFrameTextFinder.m_currentActiveMat chFrame;
614 if (&ownerFrame() != activeMatchFrame || !m_activeMatch || !areRangesEqual(m _activeMatch.get(), range.get())) { 614 if (&ownerFrame() != activeMatchFrame || !m_activeMatch || !areRangesEqual(m _activeMatch.get(), range)) {
615 if (isActiveMatchFrameValid()) 615 if (isActiveMatchFrameValid())
616 activeMatchFrame->ensureTextFinder().setMatchMarkerActive(false); 616 activeMatchFrame->ensureTextFinder().setMatchMarkerActive(false);
617 617
618 m_activeMatchIndexInCurrentFrame = m_findMatchesCache[index].m_ordinal - 1; 618 m_activeMatchIndexInCurrentFrame = m_findMatchesCache[index].m_ordinal - 1;
619 619
620 // Set this frame as the active frame (the one with the active highlight ). 620 // Set this frame as the active frame (the one with the active highlight ).
621 mainFrameTextFinder.m_currentActiveMatchFrame = &ownerFrame(); 621 mainFrameTextFinder.m_currentActiveMatchFrame = &ownerFrame();
622 ownerFrame().viewImpl()->setFocusedFrame(&ownerFrame()); 622 ownerFrame().viewImpl()->setFocusedFrame(&ownerFrame());
623 623
624 m_activeMatch = range.release(); 624 m_activeMatch = range;
625 setMarkerActive(m_activeMatch.get(), true); 625 setMarkerActive(m_activeMatch.get(), true);
626 626
627 // Clear any user selection, to make sure Find Next continues on from th e match we just activated. 627 // Clear any user selection, to make sure Find Next continues on from th e match we just activated.
628 ownerFrame().frame()->selection().clear(); 628 ownerFrame().frame()->selection().clear();
629 629
630 // Make sure no node is focused. See http://crbug.com/38700. 630 // Make sure no node is focused. See http://crbug.com/38700.
631 ownerFrame().frame()->document()->clearFocusedElement(); 631 ownerFrame().frame()->document()->clearFocusedElement();
632 } 632 }
633 633
634 IntRect activeMatchRect; 634 IntRect activeMatchRect;
635 IntRect activeMatchBoundingBox = enclosingIntRect(LayoutObject::absoluteBoun dingBoxRectForRange(m_activeMatch.get())); 635 IntRect activeMatchBoundingBox = enclosingIntRect(LayoutObject::absoluteBoun dingBoxRectForRange(m_activeMatch.get()));
636 636
637 if (!activeMatchBoundingBox.isEmpty()) { 637 if (!activeMatchBoundingBox.isEmpty()) {
638 if (m_activeMatch->firstNode() && m_activeMatch->firstNode()->layoutObje ct()) { 638 if (m_activeMatch->firstNode() && m_activeMatch->firstNode()->layoutObje ct()) {
639 m_activeMatch->firstNode()->layoutObject()->scrollRectToVisible( 639 m_activeMatch->firstNode()->layoutObject()->scrollRectToVisible(
640 LayoutRect(activeMatchBoundingBox), ScrollAlignment::alignCenter IfNeeded, ScrollAlignment::alignCenterIfNeeded, UserScroll); 640 LayoutRect(activeMatchBoundingBox), ScrollAlignment::alignCenter IfNeeded, ScrollAlignment::alignCenterIfNeeded, UserScroll);
641 } 641 }
642 642
643 // Zoom to the active match. 643 // Zoom to the active match.
644 activeMatchRect = ownerFrame().frameView()->contentsToRootFrame(activeMa tchBoundingBox); 644 activeMatchRect = ownerFrame().frameView()->contentsToRootFrame(activeMa tchBoundingBox);
645 ownerFrame().viewImpl()->zoomToFindInPageRect(activeMatchRect); 645 ownerFrame().viewImpl()->zoomToFindInPageRect(activeMatchRect);
646 } 646 }
647 647
648 if (selectionRect) 648 if (selectionRect)
649 *selectionRect = activeMatchRect; 649 *selectionRect = activeMatchRect;
650 650
651 return ordinalOfFirstMatch() + m_activeMatchIndexInCurrentFrame + 1; 651 return ordinalOfFirstMatch() + m_activeMatchIndexInCurrentFrame + 1;
652 } 652 }
653 653
654 RawPtr<TextFinder> TextFinder::create(WebLocalFrameImpl& ownerFrame) 654 TextFinder* TextFinder::create(WebLocalFrameImpl& ownerFrame)
655 { 655 {
656 return new TextFinder(ownerFrame); 656 return new TextFinder(ownerFrame);
657 } 657 }
658 658
659 TextFinder::TextFinder(WebLocalFrameImpl& ownerFrame) 659 TextFinder::TextFinder(WebLocalFrameImpl& ownerFrame)
660 : m_ownerFrame(&ownerFrame) 660 : m_ownerFrame(&ownerFrame)
661 , m_currentActiveMatchFrame(nullptr) 661 , m_currentActiveMatchFrame(nullptr)
662 , m_activeMatchIndexInCurrentFrame(-1) 662 , m_activeMatchIndexInCurrentFrame(-1)
663 , m_resumeScopingFromRange(nullptr) 663 , m_resumeScopingFromRange(nullptr)
664 , m_lastMatchCount(-1) 664 , m_lastMatchCount(-1)
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 { 813 {
814 visitor->trace(m_ownerFrame); 814 visitor->trace(m_ownerFrame);
815 visitor->trace(m_currentActiveMatchFrame); 815 visitor->trace(m_currentActiveMatchFrame);
816 visitor->trace(m_activeMatch); 816 visitor->trace(m_activeMatch);
817 visitor->trace(m_resumeScopingFromRange); 817 visitor->trace(m_resumeScopingFromRange);
818 visitor->trace(m_deferredScopingWork); 818 visitor->trace(m_deferredScopingWork);
819 visitor->trace(m_findMatchesCache); 819 visitor->trace(m_findMatchesCache);
820 } 820 }
821 821
822 } // namespace blink 822 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/TextFinder.h ('k') | third_party/WebKit/Source/web/ValidationMessageClientImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698