Bug 681192. Part 4: Make ScrollFrameRectIntoView compute a generous allowed scroll destination range. r=roc,matspal

--HG--
extra : rebase_source : 524add7c1080994dd1bc2345cbd6f54c15653d27
This commit is contained in:
Oleg Romashin 2012-02-07 12:22:53 -08:00
Родитель 02d53f3912
Коммит 4cf354e233
1 изменённых файлов: 29 добавлений и 5 удалений

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

@ -3051,8 +3051,12 @@ ComputeWhereToScroll(PRInt16 aWhereToScroll,
nscoord aRectMin,
nscoord aRectMax,
nscoord aViewMin,
nscoord aViewMax) {
nscoord aViewMax,
nscoord* aRangeMin,
nscoord* aRangeMax) {
nscoord resultCoord = aOriginalCoord;
// Allow the scroll operation to land anywhere that
// makes the whole rectangle visible.
if (nsIPresShell::SCROLL_MINIMUM == aWhereToScroll) {
if (aRectMin < aViewMin) {
// Scroll up so the frame's top edge is visible
@ -3071,6 +3075,10 @@ ComputeWhereToScroll(PRInt16 aWhereToScroll,
resultCoord = NSToCoordRound(frameAlignCoord - (aViewMax - aViewMin) * (
aWhereToScroll / 100.0f));
}
nscoord scrollPortLength = aViewMax - aViewMin;
// Force the scroll range to extend to include resultCoord.
*aRangeMin = NS_MIN(resultCoord, aRectMax - scrollPortLength);
*aRangeMax = NS_MAX(resultCoord, aRectMin);
return resultCoord;
}
@ -3090,8 +3098,18 @@ static void ScrollToShowRect(nsIScrollableFrame* aScrollFrame,
{
nsPoint scrollPt = aScrollFrame->GetScrollPosition();
nsRect visibleRect(scrollPt, aScrollFrame->GetScrollPortRect().Size());
nsSize lineSize = aScrollFrame->GetLineScrollAmount();
nsSize lineSize;
// Don't call GetLineScrollAmount unless we actually need it. Not only
// does this save time, but it's not safe to call GetLineScrollAmount
// during reflow (because it depends on font size inflation and doesn't
// use the in-reflow-safe font-size inflation path). If we did call it,
// it would assert and possible give the wrong result.
if (aVertical.mWhenToScroll == nsIPresShell::SCROLL_IF_NOT_VISIBLE ||
aHorizontal.mWhenToScroll == nsIPresShell::SCROLL_IF_NOT_VISIBLE) {
lineSize = aScrollFrame->GetLineScrollAmount();
}
nsPresContext::ScrollbarStyles ss = aScrollFrame->GetScrollbarStyles();
nsRect allowedRange(scrollPt, nsSize(0, 0));
if ((aFlags & nsIPresShell::SCROLL_OVERFLOW_HIDDEN) ||
ss.mVertical != NS_STYLE_OVERFLOW_HIDDEN) {
@ -3102,12 +3120,15 @@ static void ScrollToShowRect(nsIScrollableFrame* aScrollFrame,
aRect.YMost(),
visibleRect.y,
visibleRect.YMost())) {
nscoord maxHeight;
scrollPt.y = ComputeWhereToScroll(aVertical.mWhereToScroll,
scrollPt.y,
aRect.y,
aRect.YMost(),
visibleRect.y,
visibleRect.YMost());
visibleRect.YMost(),
&allowedRange.y, &maxHeight);
allowedRange.height = maxHeight - allowedRange.y;
}
}
@ -3120,16 +3141,19 @@ static void ScrollToShowRect(nsIScrollableFrame* aScrollFrame,
aRect.XMost(),
visibleRect.x,
visibleRect.XMost())) {
nscoord maxWidth;
scrollPt.x = ComputeWhereToScroll(aHorizontal.mWhereToScroll,
scrollPt.x,
aRect.x,
aRect.XMost(),
visibleRect.x,
visibleRect.XMost());
visibleRect.XMost(),
&allowedRange.x, &maxWidth);
allowedRange.width = maxWidth - allowedRange.x;
}
}
aScrollFrame->ScrollTo(scrollPt, nsIScrollableFrame::INSTANT);
aScrollFrame->ScrollTo(scrollPt, nsIScrollableFrame::INSTANT, &allowedRange);
}
nsresult