Bug 1430187 - Part 1: Allow find-in-page to unilaterally find text that's out of view in a scrollable container. r=mikedeboer, a=lizzard
authorBrad Werth <bwerth@mozilla.com>
Fri, 19 Jan 2018 15:58:03 -0800
changeset 454536 ad738f287aa1411eddcac4841cf929f63e5fb593
parent 454535 e4ed154c002a8fbfff664d70015631d83d9d21be
child 454537 130679feb369f7f3cc0f0893a85ed078bee4deba
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer, lizzard
bugs1430187
milestone59.0
Bug 1430187 - Part 1: Allow find-in-page to unilaterally find text that's out of view in a scrollable container. r=mikedeboer, a=lizzard MozReview-Commit-ID: KBh9PxuUWhT
toolkit/components/typeaheadfind/nsTypeAheadFind.cpp
--- a/toolkit/components/typeaheadfind/nsTypeAheadFind.cpp
+++ b/toolkit/components/typeaheadfind/nsTypeAheadFind.cpp
@@ -457,20 +457,30 @@ nsTypeAheadFind::FindItNow(nsIPresShell 
 
       if (aIsLinksOnly) {
         // Don't check if inside link when searching all text
         RangeStartsInsideLink(static_cast<nsRange*>(returnRange.get()),
                               presShell, &isInsideLink, &isStartingLink);
       }
 
       bool usesIndependentSelection;
-      if (!IsRangeVisible(presShell, presContext, returnRange,
-                          aIsFirstVisiblePreferred, false,
-                          getter_AddRefs(mStartPointRange),
-                          &usesIndependentSelection) ||
+      // Check actual visibility of the range, and generate some
+      // side effects (like updating mStartPointRange and
+      // setting usesIndependentSelection) that we'll need whether
+      // or not the range is visible.
+      bool canSeeRange = IsRangeVisible(presShell, presContext,
+                                        returnRange,
+                                        aIsFirstVisiblePreferred, false,
+                                        getter_AddRefs(mStartPointRange),
+                                        &usesIndependentSelection);
+
+      // If we can't see the range, we still might be able to scroll
+      // it into view if usesIndependentSelection is true. If both are
+      // false, then we treat it as a failure condition.
+      if ((!canSeeRange && !usesIndependentSelection) ||
           (aIsLinksOnly && !isInsideLink) ||
           (mStartLinksOnlyPref && aIsLinksOnly && !isStartingLink)) {
         // ------ Failure ------
         // At this point mStartPointRange got updated to the first
         // visible range in the viewport.  We _may_ be able to just
         // start there, if it's not taking us in the wrong direction.
         if (aFindPrev) {
           // We can continue at the end of mStartPointRange if its end is before
@@ -836,17 +846,17 @@ nsTypeAheadFind::GetSearchContainers(nsI
     aSelectionController->GetSelection(
       nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
     if (selection)
       selection->GetRangeAt(0, getter_AddRefs(currentSelectionRange));
   }
 
   if (!currentSelectionRange) {
     // Ensure visible range, move forward if necessary
-    // This uses ignores the return value, but usese the side effect of
+    // This ignores the return value, but uses the side effect of
     // IsRangeVisible. It returns the first visible range after searchRange
     IsRangeVisible(presShell, presContext, mSearchRange,
                    aIsFirstVisiblePreferred, true,
                    getter_AddRefs(mStartPointRange), nullptr);
   }
   else {
     uint32_t startOffset;
     nsCOMPtr<nsIDOMNode> startNode;