Bug 657634 Don't use high resolution scrolling when scrolling speed is customized by prefs r=smaug

This commit is contained in:
Masayuki Nakano 2011-05-22 14:39:16 +09:00
Родитель bd356c84e9
Коммит cddb7705f5
3 изменённых файлов: 163 добавлений и 91 удалений

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

@ -1225,20 +1225,8 @@ nsEventStateManager::PreHandleEvent(nsPresContext* aPresContext,
nsMouseScrollEvent* msEvent = static_cast<nsMouseScrollEvent*>(aEvent); nsMouseScrollEvent* msEvent = static_cast<nsMouseScrollEvent*>(aEvent);
NS_NAMED_LITERAL_CSTRING(actionslot, ".action"); PRBool useSysNumLines = UseSystemScrollSettingFor(msEvent);
NS_NAMED_LITERAL_CSTRING(numlinesslot, ".numlines"); PRInt32 action = GetWheelActionFor(msEvent);
NS_NAMED_LITERAL_CSTRING(sysnumlinesslot, ".sysnumlines");
nsCAutoString baseKey;
GetBasePrefKeyForMouseWheel(msEvent, baseKey);
nsCAutoString sysNumLinesKey(baseKey);
sysNumLinesKey.Append(sysnumlinesslot);
PRBool useSysNumLines = nsContentUtils::GetBoolPref(sysNumLinesKey.get());
nsCAutoString actionKey(baseKey);
actionKey.Append(actionslot);
PRInt32 action = nsContentUtils::GetIntPref(actionKey.get());
if (!useSysNumLines) { if (!useSysNumLines) {
// If the scroll event's delta isn't to our liking, we can // If the scroll event's delta isn't to our liking, we can
@ -1254,9 +1242,7 @@ nsEventStateManager::PreHandleEvent(nsPresContext* aPresContext,
// second item, if the parameter is negative we swap // second item, if the parameter is negative we swap
// directions. // directions.
nsCAutoString numLinesKey(baseKey); PRInt32 numLines = GetScrollLinesFor(msEvent);
numLinesKey.Append(numlinesslot);
PRInt32 numLines = nsContentUtils::GetIntPref(numLinesKey.get());
PRBool swapDirs = (numLines < 0); PRBool swapDirs = (numLines < 0);
PRInt32 userSize = swapDirs ? -numLines : numLines; PRInt32 userSize = swapDirs ? -numLines : numLines;
@ -2573,6 +2559,66 @@ nsEventStateManager::SendPixelScrollEvent(nsIFrame* aTargetFrame,
nsEventDispatcher::Dispatch(targetContent, aPresContext, &event, nsnull, aStatus); nsEventDispatcher::Dispatch(targetContent, aPresContext, &event, nsnull, aStatus);
} }
PRInt32
nsEventStateManager::ComputeWheelActionFor(nsMouseScrollEvent* aMouseEvent,
PRBool aUseSystemSettings)
{
PRInt32 action = GetWheelActionFor(aMouseEvent);
if (aUseSystemSettings &&
(aMouseEvent->scrollFlags & nsMouseScrollEvent::kIsFullPage)) {
action = MOUSE_SCROLL_PAGE;
}
if (aMouseEvent->message == NS_MOUSE_PIXEL_SCROLL) {
if (action == MOUSE_SCROLL_N_LINES || action == MOUSE_SCROLL_PAGE ||
(aMouseEvent->scrollFlags & nsMouseScrollEvent::kIsMomentum)) {
action = MOUSE_SCROLL_PIXELS;
} else {
// Do not scroll pixels when zooming
action = -1;
}
} else if (aMouseEvent->scrollFlags & nsMouseScrollEvent::kHasPixels) {
if (aUseSystemSettings ||
action == MOUSE_SCROLL_N_LINES || action == MOUSE_SCROLL_PAGE ||
(aMouseEvent->scrollFlags & nsMouseScrollEvent::kIsMomentum)) {
// Don't scroll lines when a pixel scroll event will follow.
// Also, don't do history scrolling or zooming for momentum scrolls.
action = -1;
}
}
return action;
}
PRInt32
nsEventStateManager::GetWheelActionFor(nsMouseScrollEvent* aMouseEvent)
{
nsCAutoString prefName;
GetBasePrefKeyForMouseWheel(aMouseEvent, prefName);
prefName.Append(".action");
return nsContentUtils::GetIntPref(prefName.get());
}
PRInt32
nsEventStateManager::GetScrollLinesFor(nsMouseScrollEvent* aMouseEvent)
{
NS_ASSERTION(!UseSystemScrollSettingFor(aMouseEvent),
"GetScrollLinesFor() called when should use system settings");
nsCAutoString prefName;
GetBasePrefKeyForMouseWheel(aMouseEvent, prefName);
prefName.Append(".numlines");
return nsContentUtils::GetIntPref(prefName.get());
}
PRBool
nsEventStateManager::UseSystemScrollSettingFor(nsMouseScrollEvent* aMouseEvent)
{
nsCAutoString prefName;
GetBasePrefKeyForMouseWheel(aMouseEvent, prefName);
prefName.Append(".sysnumlines");
return nsContentUtils::GetBoolPref(prefName.get());
}
nsresult nsresult
nsEventStateManager::DoScrollText(nsIFrame* aTargetFrame, nsEventStateManager::DoScrollText(nsIFrame* aTargetFrame,
nsMouseScrollEvent* aMouseEvent, nsMouseScrollEvent* aMouseEvent,
@ -3062,45 +3108,8 @@ nsEventStateManager::PostHandleEvent(nsPresContext* aPresContext,
} }
if (*aStatus != nsEventStatus_eConsumeNoDefault) { if (*aStatus != nsEventStatus_eConsumeNoDefault) {
// Build the preference keys, based on the event properties. PRBool useSysNumLines = UseSystemScrollSettingFor(msEvent);
NS_NAMED_LITERAL_CSTRING(actionslot, ".action"); PRInt32 action = ComputeWheelActionFor(msEvent, useSysNumLines);
NS_NAMED_LITERAL_CSTRING(sysnumlinesslot, ".sysnumlines");
nsCAutoString baseKey;
GetBasePrefKeyForMouseWheel(msEvent, baseKey);
// Extract the preferences
nsCAutoString actionKey(baseKey);
actionKey.Append(actionslot);
nsCAutoString sysNumLinesKey(baseKey);
sysNumLinesKey.Append(sysnumlinesslot);
PRInt32 action = nsContentUtils::GetIntPref(actionKey.get());
PRBool useSysNumLines =
nsContentUtils::GetBoolPref(sysNumLinesKey.get());
if (useSysNumLines) {
if (msEvent->scrollFlags & nsMouseScrollEvent::kIsFullPage)
action = MOUSE_SCROLL_PAGE;
}
if (aEvent->message == NS_MOUSE_PIXEL_SCROLL) {
if (action == MOUSE_SCROLL_N_LINES || action == MOUSE_SCROLL_PAGE ||
(msEvent->scrollFlags & nsMouseScrollEvent::kIsMomentum)) {
action = MOUSE_SCROLL_PIXELS;
} else {
// Do not scroll pixels when zooming
action = -1;
}
} else if (msEvent->scrollFlags & nsMouseScrollEvent::kHasPixels) {
if (useSysNumLines || action == MOUSE_SCROLL_N_LINES ||
(msEvent->scrollFlags & nsMouseScrollEvent::kIsMomentum)) {
// Don't scroll lines when a pixel scroll event will follow.
// Also, don't do history scrolling or zooming for momentum scrolls.
action = -1;
}
}
switch (action) { switch (action) {
case MOUSE_SCROLL_N_LINES: case MOUSE_SCROLL_N_LINES:
@ -4686,13 +4695,35 @@ nsEventStateManager::DoQueryScrollTargetInfo(nsQueryContentEvent* aEvent,
nsIFrame* aTargetFrame) nsIFrame* aTargetFrame)
{ {
nsMouseScrollEvent* msEvent = aEvent->mInput.mMouseScrollEvent; nsMouseScrollEvent* msEvent = aEvent->mInput.mMouseScrollEvent;
nsIScrollableFrame::ScrollUnit unit;
if (msEvent->scrollFlags & nsMouseScrollEvent::kIsFullPage) { // Don't use high resolution scrolling when user customize the scrolling
unit = nsIScrollableFrame::PAGES; // speed.
} else { if (!UseSystemScrollSettingFor(msEvent)) {
unit = nsIScrollableFrame::LINES; return;
} }
DoScrollText(aTargetFrame, msEvent, unit, PR_FALSE, aEvent);
nsIScrollableFrame::ScrollUnit unit;
PRBool allowOverrideSystemSettings;
switch (ComputeWheelActionFor(msEvent, PR_TRUE)) {
case MOUSE_SCROLL_N_LINES:
unit = nsIScrollableFrame::LINES;
allowOverrideSystemSettings = PR_TRUE;
break;
case MOUSE_SCROLL_PAGE:
unit = nsIScrollableFrame::PAGES;
allowOverrideSystemSettings = PR_FALSE;
break;
case MOUSE_SCROLL_PIXELS:
unit = nsIScrollableFrame::DEVICE_PIXELS;
allowOverrideSystemSettings = PR_FALSE;
default:
// Don't use high resolution scrolling when the action doesn't scroll
// contents.
return;
}
DoScrollText(aTargetFrame, msEvent, unit,
allowOverrideSystemSettings, aEvent);
} }
void void

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

@ -342,6 +342,33 @@ protected:
nsresult GetMarkupDocumentViewer(nsIMarkupDocumentViewer** aMv); nsresult GetMarkupDocumentViewer(nsIMarkupDocumentViewer** aMv);
nsresult ChangeTextSize(PRInt32 change); nsresult ChangeTextSize(PRInt32 change);
nsresult ChangeFullZoom(PRInt32 change); nsresult ChangeFullZoom(PRInt32 change);
/**
* Computes the action for the aMouseEvent with prefs. The result is
* MOUSE_SCROLL_N_LINES, MOUSE_SCROLL_PAGE, MOUSE_SCROLL_HISTORY,
* MOUSE_SCROLL_ZOOM, MOUSE_SCROLL_PIXELS or -1.
* When the result is -1, nothing happens for the event.
*
* @param aUseSystemSettings Set the result of UseSystemScrollSettingFor().
*/
PRInt32 ComputeWheelActionFor(nsMouseScrollEvent* aMouseEvent,
PRBool aUseSystemSettings);
/**
* Gets the wheel action for the aMouseEvent ONLY with the pref.
* When you actually do something for the event, probably you should use
* ComputeWheelActionFor().
*/
PRInt32 GetWheelActionFor(nsMouseScrollEvent* aMouseEvent);
/**
* Gets the pref value for line scroll amount for the aMouseEvent.
* Note that this method doesn't check whether the aMouseEvent is line scroll
* event and doesn't use system settings.
*/
PRInt32 GetScrollLinesFor(nsMouseScrollEvent* aMouseEvent);
/**
* Whether use system scroll settings or settings in our prefs for the event.
* TRUE, if use system scroll settings. Otherwise, FALSE.
*/
PRBool UseSystemScrollSettingFor(nsMouseScrollEvent* aMouseEvent);
// end mousewheel functions // end mousewheel functions
/* /*

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

@ -6417,6 +6417,38 @@ nsWindow::OnMouseWheel(UINT aMessage, WPARAM aWParam, LPARAM aLParam,
sLastMouseWheelUnitIsPage = isPageScroll; sLastMouseWheelUnitIsPage = isPageScroll;
sLastMouseWheelTime = now; sLastMouseWheelTime = now;
*aRetValue = isVertical ? FALSE : TRUE; // means we process this message
nsModifierKeyState modKeyState;
// 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.
PRInt32 orienter = isVertical ? -1 : 1;
// Assume the Control key is down if the Elantech touchpad has sent the
// mis-ordered WM_KEYDOWN/WM_MOUSEWHEEL messages. (See the comment in
// OnKeyUp.)
PRBool isControl;
if (mAssumeWheelIsZoomUntil &&
static_cast<DWORD>(::GetMessageTime()) < mAssumeWheelIsZoomUntil) {
isControl = PR_TRUE;
} else {
isControl = modKeyState.mIsControlDown;
}
// Create line (or page) scroll event.
nsMouseScrollEvent scrollEvent(PR_TRUE, NS_MOUSE_SCROLL, this);
// Initialize common members on line scroll event, pixel scroll event and
// test event.
InitEvent(scrollEvent);
scrollEvent.isShift = modKeyState.mIsShiftDown;
scrollEvent.isControl = isControl;
scrollEvent.isMeta = PR_FALSE;
scrollEvent.isAlt = modKeyState.mIsAltDown;
// Before dispatching line scroll event, we should get the current scroll
// event target information for pixel scroll.
PRBool dispatchPixelScrollEvent = PR_FALSE; PRBool dispatchPixelScrollEvent = PR_FALSE;
PRInt32 pixelsPerUnit = 0; PRInt32 pixelsPerUnit = 0;
@ -6426,6 +6458,10 @@ nsWindow::OnMouseWheel(UINT aMessage, WPARAM aWParam, LPARAM aLParam,
testEvent.scrollFlags = isPageScroll ? nsMouseScrollEvent::kIsFullPage : 0; testEvent.scrollFlags = isPageScroll ? nsMouseScrollEvent::kIsFullPage : 0;
testEvent.scrollFlags |= isVertical ? nsMouseScrollEvent::kIsVertical : testEvent.scrollFlags |= isVertical ? nsMouseScrollEvent::kIsVertical :
nsMouseScrollEvent::kIsHorizontal; nsMouseScrollEvent::kIsHorizontal;
testEvent.isShift = scrollEvent.isShift;
testEvent.isControl = scrollEvent.isControl;
testEvent.isMeta = scrollEvent.isMeta;
testEvent.isAlt = scrollEvent.isAlt;
testEvent.delta = sLastMouseWheelDeltaIsPositive ? -1 : 1; testEvent.delta = sLastMouseWheelDeltaIsPositive ? -1 : 1;
nsQueryContentEvent queryEvent(PR_TRUE, NS_QUERY_SCROLL_TARGET_INFO, this); nsQueryContentEvent queryEvent(PR_TRUE, NS_QUERY_SCROLL_TARGET_INFO, this);
InitEvent(queryEvent); InitEvent(queryEvent);
@ -6447,33 +6483,10 @@ nsWindow::OnMouseWheel(UINT aMessage, WPARAM aWParam, LPARAM aLParam,
} }
} }
*aRetValue = isVertical ? FALSE : TRUE; // means we process this message // If we dispatch pixel scroll event after the line scroll event,
nsModifierKeyState modKeyState; // we should set kHasPixels flag to the line scroll event.
// 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.
PRInt32 orienter = isVertical ? -1 : 1;
// Assume the Control key is down if the Elantech touchpad has sent the
// mis-ordered WM_KEYDOWN/WM_MOUSEWHEEL messages. (See the comment in
// OnKeyUp.)
PRBool isControl;
if (mAssumeWheelIsZoomUntil &&
static_cast<DWORD>(::GetMessageTime()) < mAssumeWheelIsZoomUntil) {
isControl = PR_TRUE;
} else {
isControl = modKeyState.mIsControlDown;
}
nsMouseScrollEvent scrollEvent(PR_TRUE, NS_MOUSE_SCROLL, this);
InitEvent(scrollEvent);
scrollEvent.scrollFlags = scrollEvent.scrollFlags =
dispatchPixelScrollEvent ? nsMouseScrollEvent::kHasPixels : 0; dispatchPixelScrollEvent ? nsMouseScrollEvent::kHasPixels : 0;
scrollEvent.isShift = modKeyState.mIsShiftDown;
scrollEvent.isControl = isControl;
scrollEvent.isMeta = PR_FALSE;
scrollEvent.isAlt = modKeyState.mIsAltDown;
PRInt32 nativeDeltaForScroll = nativeDelta + sRemainingDeltaForScroll; PRInt32 nativeDeltaForScroll = nativeDelta + sRemainingDeltaForScroll;
@ -6521,10 +6534,11 @@ nsWindow::OnMouseWheel(UINT aMessage, WPARAM aWParam, LPARAM aLParam,
InitEvent(pixelEvent); InitEvent(pixelEvent);
pixelEvent.scrollFlags = nsMouseScrollEvent::kAllowSmoothScroll | pixelEvent.scrollFlags = nsMouseScrollEvent::kAllowSmoothScroll |
(scrollEvent.scrollFlags & ~nsMouseScrollEvent::kHasPixels); (scrollEvent.scrollFlags & ~nsMouseScrollEvent::kHasPixels);
pixelEvent.isShift = modKeyState.mIsShiftDown; // Use same modifier state for pixel scroll event.
pixelEvent.isControl = modKeyState.mIsControlDown; pixelEvent.isShift = scrollEvent.isShift;
pixelEvent.isMeta = PR_FALSE; pixelEvent.isControl = scrollEvent.isControl;
pixelEvent.isAlt = modKeyState.mIsAltDown; pixelEvent.isMeta = scrollEvent.isMeta;
pixelEvent.isAlt = scrollEvent.isAlt;
PRInt32 nativeDeltaForPixel = nativeDelta + sRemainingDeltaForPixel; PRInt32 nativeDeltaForPixel = nativeDelta + sRemainingDeltaForPixel;