Bug 481768 - mouse wheel scrolls too far when viewport is smallish, p=karlt+smaug, r=karlt+smaug, sr+roc

This commit is contained in:
mozbugz@karlt.net 2009-03-09 13:10:12 +02:00
parent 05ae092b34
commit 1cb05a3c55
2 changed files with 31 additions and 6 deletions

View File

@ -2817,6 +2817,28 @@ nsEventStateManager::DoScrollText(nsPresContext* aPresContext,
}
if (!passToParent && scrollView) {
if (aScrollQuantity == eScrollByLine) {
// Limit scrolling to be at most one page, but if possible, try to
// just adjust the number of scrolled lines.
nscoord lineHeight = 0;
scrollView->GetLineHeight(&lineHeight);
if (lineHeight) {
nsSize pageScrollDistances(0, 0);
scrollView->GetPageScrollDistances(&pageScrollDistances);
nscoord pageScroll = aScrollHorizontal ?
pageScrollDistances.width : pageScrollDistances.height;
if (PR_ABS(aNumLines) * lineHeight > pageScroll) {
nscoord maxLines = (pageScroll / lineHeight);
if (maxLines >= 1) {
aNumLines = ((aNumLines < 0) ? -1 : 1) * maxLines;
} else {
aScrollQuantity = eScrollByPage;
}
}
}
}
PRInt32 scrollX = 0;
PRInt32 scrollY = aNumLines;

View File

@ -129,14 +129,17 @@ function testRichListbox(id, andThen)
function helper()
{
var [aStart, aDelta, aExpected, aKind] = tests[0];
var [aStart, aDelta, aKind] = tests[0];
tests.shift();
listbox.scrollToIndex(aStart);
synthesizeMouseScroll(listbox, 10, 10,
{axis:"vertical", delta:aDelta, type:aKind.eventType,
hasPixels:aKind.hasPixels});
setTimeout(function() {
is(listbox.getIndexOfFirstVisibleRow(), aKind.shouldScrollNative ? aExpected : aStart,
var change = listbox.getIndexOfFirstVisibleRow() - aStart;
var direction = (change > 0) - (change < 0);
var expected = aKind.shouldScrollNative && (aDelta > 0) - (aDelta < 0);
is(direction, expected,
"mouse-scroll of '" + id + "' vertical starting " + aStart + " delta " + aDelta
+ " eventType " + aKind.eventType + " hasPixels " + aKind.hasPixels);
@ -159,10 +162,10 @@ function testRichListbox(id, andThen)
// richlistbox currently uses native XUL scrolling, so the "line"
// amounts don't necessarily correspond 1-to-1 with listbox items. So
// we just check that scrolling up/down a lot hits the first/last items
// we just check that scrolling up/down scrolls in the right direction.
kinds.forEach(function(aKind) {
tests.push([2, -100, 0, aKind]);
tests.push([2, 100, listbox.getRowCount() - listbox.getNumberOfVisibleRows(), aKind]);
tests.push([2, -100, aKind]);
tests.push([2, 100, aKind]);
});
helper();
}