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

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

Issue 2775663008: LayoutObject::absoluteBoundingBoxRectForRange() should take EphemeralRange (Closed)
Patch Set: Y Created 3 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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 } 158 }
159 159
160 // If the user is browsing a page with autosizing, adjust the zoom to the 160 // If the user is browsing a page with autosizing, adjust the zoom to the
161 // column where the next hit has been found. Doing this when autosizing is 161 // column where the next hit has been found. Doing this when autosizing is
162 // not set will result in a zoom reset on small devices. 162 // not set will result in a zoom reset on small devices.
163 if (ownerFrame() 163 if (ownerFrame()
164 .frame() 164 .frame()
165 ->document() 165 ->document()
166 ->textAutosizer() 166 ->textAutosizer()
167 ->pageNeedsAutosizing()) { 167 ->pageNeedsAutosizing()) {
168 const EphemeralRange range(m_activeMatch.get());
168 ownerFrame().viewImpl()->zoomToFindInPageRect( 169 ownerFrame().viewImpl()->zoomToFindInPageRect(
169 ownerFrame().frameView()->contentsToRootFrame( 170 ownerFrame().frameView()->contentsToRootFrame(enclosingIntRect(
170 enclosingIntRect(LayoutObject::absoluteBoundingBoxRectForRange( 171 LayoutObject::absoluteBoundingBoxRectForRange(range))));
171 m_activeMatch.get()))));
172 } 172 }
173 173
174 bool wasActiveFrame = m_currentActiveMatchFrame; 174 bool wasActiveFrame = m_currentActiveMatchFrame;
175 m_currentActiveMatchFrame = true; 175 m_currentActiveMatchFrame = true;
176 176
177 bool isActive = setMarkerActive(m_activeMatch.get(), true); 177 bool isActive = setMarkerActive(m_activeMatch.get(), true);
178 if (activeNow) 178 if (activeNow)
179 *activeNow = isActive; 179 *activeNow = isActive;
180 180
181 // Make sure no node is focused. See http://crbug.com/38700. 181 // Make sure no node is focused. See http://crbug.com/38700.
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 void TextFinder::updateFindMatchRects() { 522 void TextFinder::updateFindMatchRects() {
523 IntSize currentContentsSize = ownerFrame().contentsSize(); 523 IntSize currentContentsSize = ownerFrame().contentsSize();
524 if (m_contentsSizeForCurrentFindMatchRects != currentContentsSize) { 524 if (m_contentsSizeForCurrentFindMatchRects != currentContentsSize) {
525 m_contentsSizeForCurrentFindMatchRects = currentContentsSize; 525 m_contentsSizeForCurrentFindMatchRects = currentContentsSize;
526 m_findMatchRectsAreValid = false; 526 m_findMatchRectsAreValid = false;
527 } 527 }
528 528
529 size_t deadMatches = 0; 529 size_t deadMatches = 0;
530 for (FindMatch& match : m_findMatchesCache) { 530 for (FindMatch& match : m_findMatchesCache) {
531 if (!match.m_range->boundaryPointsValid() || 531 if (!match.m_range->boundaryPointsValid() ||
532 !match.m_range->startContainer()->isConnected()) 532 !match.m_range->startContainer()->isConnected()) {
533 match.m_rect = FloatRect(); 533 match.m_rect = FloatRect();
534 else if (!m_findMatchRectsAreValid) 534 } else if (!m_findMatchRectsAreValid) {
535 match.m_rect = findInPageRectFromRange(match.m_range.get()); 535 EphemeralRange range(match.m_range.get());
Xiaocheng 2017/03/28 21:29:34 nit: |const EphemeralRange|
tanvir 2017/03/30 19:11:06 Done.
536 match.m_rect = findInPageRectFromRange(range);
537 }
536 538
537 if (match.m_rect.isEmpty()) 539 if (match.m_rect.isEmpty())
538 ++deadMatches; 540 ++deadMatches;
539 } 541 }
540 542
541 // Remove any invalid matches from the cache. 543 // Remove any invalid matches from the cache.
542 if (deadMatches) { 544 if (deadMatches) {
543 HeapVector<FindMatch> filteredMatches; 545 HeapVector<FindMatch> filteredMatches;
544 filteredMatches.reserveCapacity(m_findMatchesCache.size() - deadMatches); 546 filteredMatches.reserveCapacity(m_findMatchesCache.size() - deadMatches);
545 547
(...skipping 13 matching lines...) Expand all
559 toWebLocalFrameImpl(child)->ensureTextFinder().m_findMatchRectsAreValid = 561 toWebLocalFrameImpl(child)->ensureTextFinder().m_findMatchRectsAreValid =
560 false; 562 false;
561 563
562 m_findMatchRectsAreValid = true; 564 m_findMatchRectsAreValid = true;
563 } 565 }
564 566
565 WebFloatRect TextFinder::activeFindMatchRect() { 567 WebFloatRect TextFinder::activeFindMatchRect() {
566 if (!m_currentActiveMatchFrame || !m_activeMatch) 568 if (!m_currentActiveMatchFrame || !m_activeMatch)
567 return WebFloatRect(); 569 return WebFloatRect();
568 570
569 return WebFloatRect(findInPageRectFromRange(activeMatch())); 571 EphemeralRange range(activeMatch());
Xiaocheng 2017/03/28 21:29:34 nit: |const EphemeralRange|
tanvir 2017/03/30 19:11:06 Done.
572 return WebFloatRect(findInPageRectFromRange(range));
570 } 573 }
571 574
572 void TextFinder::findMatchRects(WebVector<WebFloatRect>& outputRects) { 575 void TextFinder::findMatchRects(WebVector<WebFloatRect>& outputRects) {
573 updateFindMatchRects(); 576 updateFindMatchRects();
574 577
575 Vector<WebFloatRect> matchRects; 578 Vector<WebFloatRect> matchRects;
576 matchRects.reserveCapacity(matchRects.size() + m_findMatchesCache.size()); 579 matchRects.reserveCapacity(matchRects.size() + m_findMatchesCache.size());
577 for (const FindMatch& match : m_findMatchesCache) { 580 for (const FindMatch& match : m_findMatchesCache) {
578 DCHECK(!match.m_rect.isEmpty()); 581 DCHECK(!match.m_rect.isEmpty());
579 matchRects.push_back(match.m_rect); 582 matchRects.push_back(match.m_rect);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 641
639 // Clear any user selection, to make sure Find Next continues on from the 642 // Clear any user selection, to make sure Find Next continues on from the
640 // match we just activated. 643 // match we just activated.
641 ownerFrame().frame()->selection().clear(); 644 ownerFrame().frame()->selection().clear();
642 645
643 // Make sure no node is focused. See http://crbug.com/38700. 646 // Make sure no node is focused. See http://crbug.com/38700.
644 ownerFrame().frame()->document()->clearFocusedElement(); 647 ownerFrame().frame()->document()->clearFocusedElement();
645 } 648 }
646 649
647 IntRect activeMatchRect; 650 IntRect activeMatchRect;
648 IntRect activeMatchBoundingBox = enclosingIntRect( 651 IntRect activeMatchBoundingBox =
649 LayoutObject::absoluteBoundingBoxRectForRange(m_activeMatch.get())); 652 enclosingIntRect(LayoutObject::absoluteBoundingBoxRectForRange(
653 EphemeralRange(m_activeMatch.get())));
650 654
651 if (!activeMatchBoundingBox.isEmpty()) { 655 if (!activeMatchBoundingBox.isEmpty()) {
652 if (m_activeMatch->firstNode() && 656 if (m_activeMatch->firstNode() &&
653 m_activeMatch->firstNode()->layoutObject()) { 657 m_activeMatch->firstNode()->layoutObject()) {
654 m_activeMatch->firstNode()->layoutObject()->scrollRectToVisible( 658 m_activeMatch->firstNode()->layoutObject()->scrollRectToVisible(
655 LayoutRect(activeMatchBoundingBox), 659 LayoutRect(activeMatchBoundingBox),
656 ScrollAlignment::alignCenterIfNeeded, 660 ScrollAlignment::alignCenterIfNeeded,
657 ScrollAlignment::alignCenterIfNeeded, UserScroll); 661 ScrollAlignment::alignCenterIfNeeded, UserScroll);
658 } 662 }
659 663
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 783
780 DEFINE_TRACE(TextFinder) { 784 DEFINE_TRACE(TextFinder) {
781 visitor->trace(m_ownerFrame); 785 visitor->trace(m_ownerFrame);
782 visitor->trace(m_activeMatch); 786 visitor->trace(m_activeMatch);
783 visitor->trace(m_resumeScopingFromRange); 787 visitor->trace(m_resumeScopingFromRange);
784 visitor->trace(m_deferredScopingWork); 788 visitor->trace(m_deferredScopingWork);
785 visitor->trace(m_findMatchesCache); 789 visitor->trace(m_findMatchesCache);
786 } 790 }
787 791
788 } // namespace blink 792 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698