Bug 463042 - Smooth scrolling isn't working with the scrollbar or the keyboard arrows, r+sr=roc

This commit is contained in:
Markus Stange 2008-12-02 14:18:08 +01:00
parent 847fd40c16
commit 76daa5a7da
6 changed files with 56 additions and 29 deletions

View File

@ -2684,12 +2684,11 @@ nsEventStateManager::DoScrollText(nsPresContext* aPresContext,
}
if (aScrollQuantity == eScrollByPage)
scrollView->ScrollByPages(scrollX, scrollY, NS_VMREFRESH_DEFERRED);
scrollView->ScrollByPages(scrollX, scrollY, NS_VMREFRESH_SMOOTHSCROLL);
else if (aScrollQuantity == eScrollByPixel)
scrollView->ScrollByPixels(scrollX, scrollY, NS_VMREFRESH_DEFERRED);
else
scrollView->ScrollByLines(scrollX, scrollY,
NS_VMREFRESH_SMOOTHSCROLL | NS_VMREFRESH_DEFERRED);
scrollView->ScrollByLines(scrollX, scrollY, NS_VMREFRESH_SMOOTHSCROLL);
}
if (passToParent) {
nsresult rv;
@ -3158,7 +3157,8 @@ nsEventStateManager::PostHandleEvent(nsPresContext* aPresContext,
nsIScrollableView* sv = nsLayoutUtils::GetNearestScrollingView(aView, nsLayoutUtils::eVertical);
if (sv) {
nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent;
sv->ScrollByPages(0, (keyEvent->keyCode != NS_VK_PAGE_UP) ? 1 : -1);
sv->ScrollByPages(0, (keyEvent->keyCode != NS_VK_PAGE_UP) ? 1 : -1,
NS_VMREFRESH_SMOOTHSCROLL);
}
}
break;
@ -3178,7 +3178,8 @@ nsEventStateManager::PostHandleEvent(nsPresContext* aPresContext,
nsIScrollableView* sv = nsLayoutUtils::GetNearestScrollingView(aView, nsLayoutUtils::eVertical);
if (sv) {
nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent;
sv->ScrollByLines(0, (keyEvent->keyCode == NS_VK_DOWN) ? 1 : -1);
sv->ScrollByLines(0, (keyEvent->keyCode == NS_VK_DOWN) ? 1 : -1,
NS_VMREFRESH_SMOOTHSCROLL);
// force the update to happen now, otherwise multiple scrolls can
// occur before the update is processed. (bug #7354)
@ -3197,7 +3198,8 @@ nsEventStateManager::PostHandleEvent(nsPresContext* aPresContext,
nsIScrollableView* sv = nsLayoutUtils::GetNearestScrollingView(aView, nsLayoutUtils::eHorizontal);
if (sv) {
nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent;
sv->ScrollByLines((keyEvent->keyCode == NS_VK_RIGHT) ? 1 : -1, 0);
sv->ScrollByLines((keyEvent->keyCode == NS_VK_RIGHT) ? 1 : -1, 0,
NS_VMREFRESH_SMOOTHSCROLL);
// force the update to happen now, otherwise multiple scrolls can
// occur before the update is processed. (bug #7354)
@ -3218,7 +3220,7 @@ nsEventStateManager::PostHandleEvent(nsPresContext* aPresContext,
if (!mCurrentFocus) {
nsIScrollableView* sv = nsLayoutUtils::GetNearestScrollingView(aView, nsLayoutUtils::eVertical);
if (sv) {
sv->ScrollByPages(0, 1);
sv->ScrollByPages(0, 1, NS_VMREFRESH_SMOOTHSCROLL);
}
}
}

View File

@ -65,11 +65,13 @@ var step1 =function() {
"Page1: Ensure we scrollpane is at the top before we start scrolling.");
sendKey('DOWN', testWindow);
sendKey('UP', testWindow);
is(testWindow.document.body.scrollTop, 0,
"Page1: Ensure we can scroll down and up, back to the top.");
// Nav to blue box page. This should fire step2.
testWindow.location = gTallBlueBoxURI;
setTimeout(function() {
is(testWindow.document.body.scrollTop, 0,
"Page1: Ensure we can scroll down and up, back to the top.");
// Nav to blue box page. This should fire step2.
testWindow.location = gTallBlueBoxURI;
}, 0);
}
@ -82,11 +84,13 @@ var step2 =function() {
sendKey('DOWN', testWindow);
sendKey('DOWN', testWindow);
sendKey('DOWN', testWindow);
isnot(testWindow.document.body.scrollTop, 0,
"Page2: Ensure we could scrol.");
// Navigate backwards. This should fire step3.
testWindow.history.back();
setTimeout(function() {
isnot(testWindow.document.body.scrollTop, 0,
"Page2: Ensure we could scrol.");
// Navigate backwards. This should fire step3.
testWindow.history.back();
}, 0);
}
var step3 =function() {
@ -97,11 +101,13 @@ var step3 =function() {
is(testWindow.document.body.scrollTop, 0,
"Page1Again: Ensure scroll pane at top before we scroll.");
sendKey('DOWN', testWindow);
isnot(testWindow.document.body.scrollTop, 0,
"Page2Again: Ensure we can still scroll.");
testWindow.close();
window.SimpleTest.finish();
setTimeout(function() {
isnot(testWindow.document.body.scrollTop, 0,
"Page2Again: Ensure we can still scroll.");
testWindow.close();
window.SimpleTest.finish();
}, 0);
}
SimpleTest.waitForExplicitFinish();

View File

@ -11,6 +11,17 @@
<![CDATA[
function runTest() {
var tests = execTests();
function execNext() {
try {
tests.next();
setTimeout(execNext, 0);
} catch (e) {}
}
execNext();
}
function execTests() {
var e = document.getElementById("edit");
var doc = e.contentDocument;
var win = e.contentWindow;
@ -39,7 +50,6 @@ function runTest() {
}
function testScrollCommand(cmd, expectTop) {
doCommand(cmd);
is(root.getBoundingClientRect().top, -expectTop, cmd);
}
@ -100,21 +110,29 @@ function runTest() {
return n;
}
doCommand("cmd_scrollBottom");
testScrollCommand("cmd_scrollBottom", root.scrollHeight - 100);
doCommand("cmd_scrollTop");
testScrollCommand("cmd_scrollTop", 0);
doCommand("cmd_scrollPageDown");
yield;
var pageHeight = -root.getBoundingClientRect().top;
ok(pageHeight > 0, "cmd_scrollPageDown works");
ok(pageHeight <= 100, "cmd_scrollPageDown doesn't scroll too much");
doCommand("cmd_scrollBottom");
doCommand("cmd_scrollPageUp");
yield;
testScrollCommand("cmd_scrollPageUp", root.scrollHeight - 100 - pageHeight);
doCommand("cmd_scrollTop");
doCommand("cmd_scrollLineDown");
yield;
var lineHeight = -root.getBoundingClientRect().top;
ok(lineHeight > 0, "Can scroll by lines");
doCommand("cmd_scrollBottom");
doCommand("cmd_scrollLineUp");
yield;
testScrollCommand("cmd_scrollLineUp", root.scrollHeight - 100 - lineHeight);
var runSelectionTests = function(selectWordNextNode, selectWordNextOffset) {

View File

@ -2835,7 +2835,7 @@ PresShell::ScrollPage(PRBool aForward)
{
nsIScrollableView* scrollView = GetViewToScroll(nsLayoutUtils::eVertical);
if (scrollView) {
scrollView->ScrollByPages(0, aForward ? 1 : -1);
scrollView->ScrollByPages(0, aForward ? 1 : -1, NS_VMREFRESH_SMOOTHSCROLL);
}
return NS_OK;
}
@ -2848,9 +2848,9 @@ PresShell::ScrollLine(PRBool aForward)
#ifdef MOZ_WIDGET_COCOA
// Emulate the Mac IE behavior of scrolling a minimum of 2 lines
// rather than 1. This vastly improves scrolling speed.
scrollView->ScrollByLines(0, aForward ? 2 : -2);
scrollView->ScrollByLines(0, aForward ? 2 : -2, NS_VMREFRESH_SMOOTHSCROLL);
#else
scrollView->ScrollByLines(0, aForward ? 1 : -1);
scrollView->ScrollByLines(0, aForward ? 1 : -1, NS_VMREFRESH_SMOOTHSCROLL);
#endif
//NEW FOR LINES
@ -2872,7 +2872,7 @@ PresShell::ScrollHorizontal(PRBool aLeft)
{
nsIScrollableView* scrollView = GetViewToScroll(nsLayoutUtils::eHorizontal);
if (scrollView) {
scrollView->ScrollByLines(aLeft ? -1 : 1, 0);
scrollView->ScrollByLines(aLeft ? -1 : 1, 0, NS_VMREFRESH_SMOOTHSCROLL);
//NEW FOR LINES
// force the update to happen now, otherwise multiple scrolls can
// occur before the update is processed. (bug #7354)

View File

@ -1910,7 +1910,8 @@ void nsGfxScrollFrameInner::CurPosAttributeChanged(nsIContent* aContent)
InternalScrollPositionDidChange(curPosX, curPosY);
mFrameInitiatedScroll = PR_FALSE;
}
ScrollbarChanged(mOuter->PresContext(), x, y, isSmooth ? NS_VMREFRESH_SMOOTHSCROLL : 0);
ScrollbarChanged(mOuter->PresContext(), x, y,
isSmooth ? NS_VMREFRESH_SMOOTHSCROLL : NS_VMREFRESH_DEFERRED);
}
}

View File

@ -255,7 +255,7 @@ NS_IMETHODIMP nsScrollPortView::ScrollTo(nscoord aDestinationX, nscoord aDestina
mDestinationY = aDestinationY;
ClampScrollValues(mDestinationX, mDestinationY, this);
if (!(aUpdateFlags & NS_VMREFRESH_DEFERRED)) {
if (!(aUpdateFlags & (NS_VMREFRESH_DEFERRED | NS_VMREFRESH_SMOOTHSCROLL))) {
// Asynchronous scrolling is not allowed, so we'll kill any existing
// async-scrolling process and do an instant scroll
delete mAsyncScroll;