Bug 657935 Should refer computed delta value at dispatching pixel scroll event r=smaug+jimm

This commit is contained in:
Masayuki Nakano 2011-05-23 23:56:59 +09:00
parent 6bf777f61d
commit dd5ac61fdd
4 changed files with 67 additions and 35 deletions

View File

@ -390,7 +390,8 @@ public:
static PRUint32 GetTimeoutTime();
static PRInt32 AccelerateWheelDelta(PRInt32 aScrollLines,
PRBool aIsHorizontal, PRBool aAllowScrollSpeedOverride,
nsIScrollableFrame::ScrollUnit *aScrollQuantity);
nsIScrollableFrame::ScrollUnit *aScrollQuantity,
PRBool aLimitToMaxOnePageScroll = PR_TRUE);
static PRBool IsAccelerationEnabled();
enum {
@ -662,7 +663,8 @@ PRInt32
nsMouseWheelTransaction::AccelerateWheelDelta(PRInt32 aScrollLines,
PRBool aIsHorizontal,
PRBool aAllowScrollSpeedOverride,
nsIScrollableFrame::ScrollUnit *aScrollQuantity)
nsIScrollableFrame::ScrollUnit *aScrollQuantity,
PRBool aLimitToMaxOnePageScroll)
{
if (aAllowScrollSpeedOverride) {
aScrollLines = OverrideSystemScrollSpeed(aScrollLines, aIsHorizontal);
@ -679,7 +681,8 @@ nsMouseWheelTransaction::AccelerateWheelDelta(PRInt32 aScrollLines,
// If the computed delta is larger than the page, we should limit
// the delta value to the one page size.
return LimitToOnePageScroll(aScrollLines, aIsHorizontal, aScrollQuantity);
return !aLimitToMaxOnePageScroll ? aScrollLines :
LimitToOnePageScroll(aScrollLines, aIsHorizontal, aScrollQuantity);
}
PRInt32
@ -2703,6 +2706,27 @@ nsEventStateManager::DoScrollText(nsIFrame* aTargetFrame,
}
if (!passToParent && frameToScroll) {
if (aScrollQuantity == nsIScrollableFrame::LINES) {
// When this is called for querying the scroll target information,
// we shouldn't limit the scrolling amount to less one page.
// Otherwise, we shouldn't scroll more one page at once.
numLines =
nsMouseWheelTransaction::AccelerateWheelDelta(numLines, isHorizontal,
aAllowScrollSpeedOverride,
&aScrollQuantity,
!aQueryEvent);
}
#ifdef DEBUG
else {
NS_ASSERTION(!aAllowScrollSpeedOverride,
"aAllowScrollSpeedOverride is true but the quantity isn't by-line scrolling.");
}
#endif
if (aScrollQuantity == nsIScrollableFrame::PAGES) {
numLines = (numLines > 0) ? 1 : -1;
}
if (aQueryEvent) {
// If acceleration is enabled, pixel scroll shouldn't be used for
// high resolution scrolling.
@ -2718,34 +2742,23 @@ nsEventStateManager::DoScrollText(nsIFrame* aTargetFrame,
frameToScroll->GetPageScrollAmount().height / appUnitsPerDevPixel;
aQueryEvent->mReply.mPageWidth =
frameToScroll->GetPageScrollAmount().width / appUnitsPerDevPixel;
// Returns computed numLines to widget which is needed to compute the
// pixel scrolling amout for high resolution scrolling.
aQueryEvent->mReply.mComputedScrollAmount = numLines;
aQueryEvent->mSucceeded = PR_TRUE;
return NS_OK;
}
if (aScrollQuantity == nsIScrollableFrame::LINES) {
numLines =
nsMouseWheelTransaction::AccelerateWheelDelta(numLines, isHorizontal,
aAllowScrollSpeedOverride,
&aScrollQuantity);
}
#ifdef DEBUG
else {
NS_ASSERTION(!aAllowScrollSpeedOverride,
"aAllowScrollSpeedOverride is true but the quantity isn't by-line scrolling.");
}
#endif
PRInt32 scrollX = 0;
PRInt32 scrollY = numLines;
if (aScrollQuantity == nsIScrollableFrame::PAGES)
scrollY = (scrollY > 0) ? 1 : -1;
if (isHorizontal) {
scrollX = scrollY;
scrollY = 0;
}
nsIScrollableFrame::ScrollMode mode;
if (aMouseEvent->scrollFlags & nsMouseScrollEvent::kNoDefer) {
mode = nsIScrollableFrame::INSTANT;
@ -2757,6 +2770,8 @@ nsEventStateManager::DoScrollText(nsIFrame* aTargetFrame,
mode = nsIScrollableFrame::NORMAL;
}
// XXX Why don't we limit the pixel scroll amount to less one page??
nsIntPoint overflow;
frameToScroll->ScrollBy(nsIntPoint(scrollX, scrollY), aScrollQuantity,
mode, &overflow);

View File

@ -1346,6 +1346,13 @@ public:
PRInt32 mLineHeight;
PRInt32 mPageWidth;
PRInt32 mPageHeight;
// used by NS_QUERY_SCROLL_TARGET_INFO
// the mouse wheel scrolling amount may be overridden by prefs or
// overriding system scrolling speed mechanism.
// If mMouseScrollEvent is a line scroll event, the unit of this value is
// line. If mMouseScrollEvent is a page scroll event, the unit of this
// value is page.
PRInt32 mComputedScrollAmount;
} mReply;
enum {

View File

@ -289,6 +289,7 @@ struct ParamTraits<nsQueryContentEvent>
WriteParam(aMsg, aParam.mReply.mLineHeight);
WriteParam(aMsg, aParam.mReply.mPageHeight);
WriteParam(aMsg, aParam.mReply.mPageWidth);
WriteParam(aMsg, aParam.mReply.mComputedScrollAmount);
}
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
@ -307,7 +308,8 @@ struct ParamTraits<nsQueryContentEvent>
ReadParam(aMsg, aIter, &aResult->mReply.mWidgetIsHit) &&
ReadParam(aMsg, aIter, &aResult->mReply.mLineHeight) &&
ReadParam(aMsg, aIter, &aResult->mReply.mPageHeight) &&
ReadParam(aMsg, aIter, &aResult->mReply.mPageWidth);
ReadParam(aMsg, aIter, &aResult->mReply.mPageWidth) &&
ReadParam(aMsg, aIter, &aResult->mReply.mComputedScrollAmount);
}
};

View File

@ -6422,7 +6422,7 @@ nsWindow::OnMouseWheel(UINT aMessage, WPARAM aWParam, LPARAM aLParam,
// Our positive delta value means to bottom or right.
// But positive nativeDelta value means to top or right.
// Use orienter for computing our delta value.
// Use orienter for computing our delta value with native delta value.
PRInt32 orienter = isVertical ? -1 : 1;
// Assume the Control key is down if the Elantech touchpad has sent the
@ -6451,6 +6451,9 @@ nsWindow::OnMouseWheel(UINT aMessage, WPARAM aWParam, LPARAM aLParam,
// event target information for pixel scroll.
PRBool dispatchPixelScrollEvent = PR_FALSE;
PRInt32 pixelsPerUnit = 0;
// the amount is the number of lines (or pages) per WHEEL_DELTA
PRInt32 computedScrollAmount = isPageScroll ? 1 :
(isVertical ? sMouseWheelScrollLines : sMouseWheelScrollChars);
if (sEnablePixelScrolling) {
nsMouseScrollEvent testEvent(PR_TRUE, NS_MOUSE_SCROLL, this);
@ -6462,7 +6465,12 @@ nsWindow::OnMouseWheel(UINT aMessage, WPARAM aWParam, LPARAM aLParam,
testEvent.isControl = scrollEvent.isControl;
testEvent.isMeta = scrollEvent.isMeta;
testEvent.isAlt = scrollEvent.isAlt;
testEvent.delta = sLastMouseWheelDeltaIsPositive ? -1 : 1;
testEvent.delta = computedScrollAmount;
if ((isVertical && sLastMouseWheelDeltaIsPositive) ||
(!isVertical && !sLastMouseWheelDeltaIsPositive)) {
testEvent.delta *= -1;
}
nsQueryContentEvent queryEvent(PR_TRUE, NS_QUERY_SCROLL_TARGET_INFO, this);
InitEvent(queryEvent);
queryEvent.InitForQueryScrollTargetInfo(&testEvent);
@ -6479,7 +6487,14 @@ nsWindow::OnMouseWheel(UINT aMessage, WPARAM aWParam, LPARAM aLParam,
} else {
pixelsPerUnit = queryEvent.mReply.mLineHeight;
}
dispatchPixelScrollEvent = (pixelsPerUnit > 0);
// XXX Currently, we don't support the case that the computed delta has
// different sign.
computedScrollAmount = queryEvent.mReply.mComputedScrollAmount;
if (testEvent.delta < 0) {
computedScrollAmount *= -1;
}
dispatchPixelScrollEvent =
(pixelsPerUnit > 0) && (computedScrollAmount > 0);
}
}
@ -6490,6 +6505,8 @@ nsWindow::OnMouseWheel(UINT aMessage, WPARAM aWParam, LPARAM aLParam,
PRInt32 nativeDeltaForScroll = nativeDelta + sRemainingDeltaForScroll;
// NOTE: Don't use computedScrollAmount for computing the delta value of
// line/page scroll event. The value will be recomputed in ESM.
if (isPageScroll) {
scrollEvent.scrollFlags |= nsMouseScrollEvent::kIsFullPage;
if (isVertical) {
@ -6542,17 +6559,8 @@ nsWindow::OnMouseWheel(UINT aMessage, WPARAM aWParam, LPARAM aLParam,
PRInt32 nativeDeltaForPixel = nativeDelta + sRemainingDeltaForPixel;
double deltaPerPixel;
if (isPageScroll) {
deltaPerPixel = (double)WHEEL_DELTA / pixelsPerUnit;
} else {
if (isVertical) {
deltaPerPixel = (double)WHEEL_DELTA / sMouseWheelScrollLines;
} else {
deltaPerPixel = (double)WHEEL_DELTA / sMouseWheelScrollChars;
}
deltaPerPixel /= pixelsPerUnit;
}
double deltaPerPixel =
(double)WHEEL_DELTA / computedScrollAmount / pixelsPerUnit;
pixelEvent.delta =
RoundDelta((double)nativeDeltaForPixel * orienter / deltaPerPixel);
PRInt32 recomputedNativeDelta =