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

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

Issue 1839643009: RELEASE_ASSERT -> CHECK and ASSERT -> DCHECK in web. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compilation. 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 // If the user has selected something since the last Find operation we want 130 // If the user has selected something since the last Find operation we want
131 // to start from there. Otherwise, we start searching from where the last Fi nd 131 // to start from there. Otherwise, we start searching from where the last Fi nd
132 // operation left off (either a Find or a FindNext operation). 132 // operation left off (either a Find or a FindNext operation).
133 VisibleSelection selection(ownerFrame().frame()->selection().selection()); 133 VisibleSelection selection(ownerFrame().frame()->selection().selection());
134 bool activeSelection = !selection.isNone(); 134 bool activeSelection = !selection.isNone();
135 if (activeSelection) { 135 if (activeSelection) {
136 m_activeMatch = firstRangeOf(selection).get(); 136 m_activeMatch = firstRangeOf(selection).get();
137 ownerFrame().frame()->selection().clear(); 137 ownerFrame().frame()->selection().clear();
138 } 138 }
139 139
140 ASSERT(ownerFrame().frame() && ownerFrame().frame()->view()); 140 DCHECK(ownerFrame().frame() && ownerFrame().frame()->view());
tkent 2016/03/31 23:05:21 Please split this into two. DCHECK(ownerFrame(
141 const FindOptions findOptions = (options.forward ? 0 : Backwards) 141 const FindOptions findOptions = (options.forward ? 0 : Backwards)
142 | (options.matchCase ? 0 : CaseInsensitive) 142 | (options.matchCase ? 0 : CaseInsensitive)
143 | (wrapWithinFrame ? WrapAround : 0) 143 | (wrapWithinFrame ? WrapAround : 0)
144 | (options.wordStart ? AtWordStarts : 0) 144 | (options.wordStart ? AtWordStarts : 0)
145 | (options.medialCapitalAsWordStart ? TreatMedialCapitalAsWordStart : 0) 145 | (options.medialCapitalAsWordStart ? TreatMedialCapitalAsWordStart : 0)
146 | (options.findNext ? 0 : StartInSelection); 146 | (options.findNext ? 0 : StartInSelection);
147 m_activeMatch = ownerFrame().frame()->editor().findStringAndScrollToVisible( searchText, m_activeMatch.get(), findOptions); 147 m_activeMatch = ownerFrame().frame()->editor().findStringAndScrollToVisible( searchText, m_activeMatch.get(), findOptions);
148 148
149 if (!m_activeMatch) { 149 if (!m_activeMatch) {
150 // If we're finding next the next active match might not be in the curre nt frame. 150 // If we're finding next the next active match might not be in the curre nt frame.
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 // Note that we want to defer the final update when resetting even if sh ouldScopeMatches returns false. 276 // Note that we want to defer the final update when resetting even if sh ouldScopeMatches returns false.
277 // This is done in order to prevent sending a final message based only o n the results of the first frame 277 // This is done in order to prevent sending a final message based only o n the results of the first frame
278 // since m_framesScopingCount would be 0 as other frames have yet to res et. 278 // since m_framesScopingCount would be 0 as other frames have yet to res et.
279 finishCurrentScopingEffort(identifier); 279 finishCurrentScopingEffort(identifier);
280 return; 280 return;
281 } 281 }
282 282
283 WebLocalFrameImpl* mainFrameImpl = ownerFrame().viewImpl()->mainFrameImpl(); 283 WebLocalFrameImpl* mainFrameImpl = ownerFrame().viewImpl()->mainFrameImpl();
284 PositionInFlatTree searchStart = PositionInFlatTree::firstPositionInNode(own erFrame().frame()->document()); 284 PositionInFlatTree searchStart = PositionInFlatTree::firstPositionInNode(own erFrame().frame()->document());
285 PositionInFlatTree searchEnd = PositionInFlatTree::lastPositionInNode(ownerF rame().frame()->document()); 285 PositionInFlatTree searchEnd = PositionInFlatTree::lastPositionInNode(ownerF rame().frame()->document());
286 ASSERT(searchStart.document() == searchEnd.document()); 286 DCHECK_EQ(searchStart.document(), searchEnd.document());
287 287
288 if (m_resumeScopingFromRange) { 288 if (m_resumeScopingFromRange) {
289 // This is a continuation of a scoping operation that timed out and didn 't 289 // This is a continuation of a scoping operation that timed out and didn 't
290 // complete last time around, so we should start from where we left off. 290 // complete last time around, so we should start from where we left off.
291 ASSERT(m_resumeScopingFromRange->collapsed()); 291 DCHECK(m_resumeScopingFromRange->collapsed());
292 searchStart = fromPositionInDOMTree<EditingInFlatTreeStrategy>(m_resumeS copingFromRange->endPosition()); 292 searchStart = fromPositionInDOMTree<EditingInFlatTreeStrategy>(m_resumeS copingFromRange->endPosition());
293 if (searchStart.document() != searchEnd.document()) 293 if (searchStart.document() != searchEnd.document())
294 return; 294 return;
295 } 295 }
296 296
297 // This timeout controls how long we scope before releasing control. This 297 // This timeout controls how long we scope before releasing control. This
298 // value does not prevent us from running for longer than this, but it is 298 // value does not prevent us from running for longer than this, but it is
299 // periodically checked to see if we have exceeded our allocated time. 299 // periodically checked to see if we have exceeded our allocated time.
300 const double maxScopingDuration = 0.1; // seconds 300 const double maxScopingDuration = 0.1; // seconds
301 301
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 frame->ensureTextFinder().appendFindMatchRects(matchRects); 544 frame->ensureTextFinder().appendFindMatchRects(matchRects);
545 545
546 outputRects = matchRects; 546 outputRects = matchRects;
547 } 547 }
548 548
549 void TextFinder::appendFindMatchRects(Vector<WebFloatRect>& frameRects) 549 void TextFinder::appendFindMatchRects(Vector<WebFloatRect>& frameRects)
550 { 550 {
551 updateFindMatchRects(); 551 updateFindMatchRects();
552 frameRects.reserveCapacity(frameRects.size() + m_findMatchesCache.size()); 552 frameRects.reserveCapacity(frameRects.size() + m_findMatchesCache.size());
553 for (const FindMatch& match : m_findMatchesCache) { 553 for (const FindMatch& match : m_findMatchesCache) {
554 ASSERT(!match.m_rect.isEmpty()); 554 DCHECK(!match.m_rect.isEmpty());
555 frameRects.append(match.m_rect); 555 frameRects.append(match.m_rect);
556 } 556 }
557 } 557 }
558 558
559 int TextFinder::selectNearestFindMatch(const WebFloatPoint& point, WebRect* sele ctionRect) 559 int TextFinder::selectNearestFindMatch(const WebFloatPoint& point, WebRect* sele ctionRect)
560 { 560 {
561 TextFinder* bestFinder = nullptr; 561 TextFinder* bestFinder = nullptr;
562 int indexInBestFrame = -1; 562 int indexInBestFrame = -1;
563 float distanceInBestFrame = FLT_MAX; 563 float distanceInBestFrame = FLT_MAX;
564 564
(...skipping 14 matching lines...) Expand all
579 return -1; 579 return -1;
580 } 580 }
581 581
582 int TextFinder::nearestFindMatch(const FloatPoint& point, float& distanceSquared ) 582 int TextFinder::nearestFindMatch(const FloatPoint& point, float& distanceSquared )
583 { 583 {
584 updateFindMatchRects(); 584 updateFindMatchRects();
585 585
586 int nearest = -1; 586 int nearest = -1;
587 distanceSquared = FLT_MAX; 587 distanceSquared = FLT_MAX;
588 for (size_t i = 0; i < m_findMatchesCache.size(); ++i) { 588 for (size_t i = 0; i < m_findMatchesCache.size(); ++i) {
589 ASSERT(!m_findMatchesCache[i].m_rect.isEmpty()); 589 DCHECK(!m_findMatchesCache[i].m_rect.isEmpty());
590 FloatSize offset = point - m_findMatchesCache[i].m_rect.center(); 590 FloatSize offset = point - m_findMatchesCache[i].m_rect.center();
591 float width = offset.width(); 591 float width = offset.width();
592 float height = offset.height(); 592 float height = offset.height();
593 float currentDistanceSquared = width * width + height * height; 593 float currentDistanceSquared = width * width + height * height;
594 if (currentDistanceSquared < distanceSquared) { 594 if (currentDistanceSquared < distanceSquared) {
595 nearest = i; 595 nearest = i;
596 distanceSquared = currentDistanceSquared; 596 distanceSquared = currentDistanceSquared;
597 } 597 }
598 } 598 }
599 return nearest; 599 return nearest;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 719
720 bool TextFinder::shouldScopeMatches(const String& searchText) 720 bool TextFinder::shouldScopeMatches(const String& searchText)
721 { 721 {
722 // Don't scope if we can't find a frame or a view. 722 // Don't scope if we can't find a frame or a view.
723 // The user may have closed the tab/application, so abort. 723 // The user may have closed the tab/application, so abort.
724 // Also ignore detached frames, as many find operations report to the main f rame. 724 // Also ignore detached frames, as many find operations report to the main f rame.
725 LocalFrame* frame = ownerFrame().frame(); 725 LocalFrame* frame = ownerFrame().frame();
726 if (!frame || !frame->view() || !frame->page() || !ownerFrame().hasVisibleCo ntent()) 726 if (!frame || !frame->view() || !frame->page() || !ownerFrame().hasVisibleCo ntent())
727 return false; 727 return false;
728 728
729 ASSERT(frame->document() && frame->view()); 729 DCHECK(frame->document() && frame->view());
tkent 2016/03/31 23:05:21 Please split this into two. DCHECK(frame->docu
730 730
731 // If the frame completed the scoping operation and found 0 matches the last 731 // If the frame completed the scoping operation and found 0 matches the last
732 // time it was searched, then we don't have to search it again if the user i s 732 // time it was searched, then we don't have to search it again if the user i s
733 // just adding to the search string or sending the same search string again. 733 // just adding to the search string or sending the same search string again.
734 if (m_lastFindRequestCompletedWithNoMatches && !m_lastSearchString.isEmpty() ) { 734 if (m_lastFindRequestCompletedWithNoMatches && !m_lastSearchString.isEmpty() ) {
735 // Check to see if the search string prefixes match. 735 // Check to see if the search string prefixes match.
736 String previousSearchPrefix = 736 String previousSearchPrefix =
737 searchText.substring(0, m_lastSearchString.length()); 737 searchText.substring(0, m_lastSearchString.length());
738 738
739 if (previousSearchPrefix == m_lastSearchString) 739 if (previousSearchPrefix == m_lastSearchString)
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 visitor->trace(m_ownerFrame); 813 visitor->trace(m_ownerFrame);
814 visitor->trace(m_currentActiveMatchFrame); 814 visitor->trace(m_currentActiveMatchFrame);
815 visitor->trace(m_activeMatch); 815 visitor->trace(m_activeMatch);
816 visitor->trace(m_resumeScopingFromRange); 816 visitor->trace(m_resumeScopingFromRange);
817 visitor->trace(m_deferredScopingWork); 817 visitor->trace(m_deferredScopingWork);
818 visitor->trace(m_findMatchesCache); 818 visitor->trace(m_findMatchesCache);
819 #endif 819 #endif
820 } 820 }
821 821
822 } // namespace blink 822 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698