Bug 804799. Make sure we keep advancing our current find point through the document even in cases when we optimize by moving it to the first visible range, so we don't get stuck in an infinite loop. r=masayuki

This commit is contained in:
Boris Zbarsky 2012-10-24 16:10:49 -04:00
Родитель b129ae95fc
Коммит dc9e635bf3
1 изменённых файлов: 37 добавлений и 5 удалений

Просмотреть файл

@ -390,10 +390,42 @@ nsTypeAheadFind::FindItNow(nsIPresShell *aPresShell, bool aIsLinksOnly,
(aIsLinksOnly && !isInsideLink) ||
(mStartLinksOnlyPref && aIsLinksOnly && !isStartingLink)) {
// ------ Failure ------
// mStartPointRange got updated to the right thing already,
// but we stil need to collapse it to the right end.
mStartPointRange->Collapse(aFindPrev);
// 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
// the start of returnRange or coincides with it. Otherwise, we need
// to continue at the start of returnRange.
int16_t compareResult;
nsresult rv =
mStartPointRange->CompareBoundaryPoints(nsIDOMRange::START_TO_END,
returnRange, &compareResult);
if (NS_SUCCEEDED(rv) && compareResult <= 0) {
// OK to start at the end of mStartPointRange
mStartPointRange->Collapse(false);
} else {
// Start at the beginning of returnRange
returnRange->CloneRange(getter_AddRefs(mStartPointRange));
mStartPointRange->Collapse(true);
}
} else {
// We can continue at the start of mStartPointRange if its start is
// after the end of returnRange or coincides with it. Otherwise, we
// need to continue at the end of returnRange.
int16_t compareResult;
nsresult rv =
mStartPointRange->CompareBoundaryPoints(nsIDOMRange::END_TO_START,
returnRange, &compareResult);
if (NS_SUCCEEDED(rv) && compareResult >= 0) {
// OK to start at the start of mStartPointRange
mStartPointRange->Collapse(true);
} else {
// Start at the end of returnRange
returnRange->CloneRange(getter_AddRefs(mStartPointRange));
mStartPointRange->Collapse(false);
}
}
continue;
}
@ -1146,9 +1178,9 @@ nsTypeAheadFind::IsRangeVisible(nsIPresShell *aPresShell,
nsCOMPtr<nsIDOMNode> firstVisibleNode = do_QueryInterface(frame->GetContent());
if (firstVisibleNode) {
(*aFirstVisibleRange)->SelectNode(firstVisibleNode);
frame->GetOffsets(startFrameOffset, endFrameOffset);
(*aFirstVisibleRange)->SetStart(firstVisibleNode, startFrameOffset);
(*aFirstVisibleRange)->SetEnd(firstVisibleNode, endFrameOffset);
}
}