Bug 1153156 part.3 Don't allow to override system scroll speed if the wheel event causes too fast scroll r=smaug+jimm

This commit is contained in:
Masayuki Nakano 2016-01-27 15:09:13 +09:00
parent 6f56a7bd2c
commit 95c2b8dfcc
4 changed files with 44 additions and 53 deletions

View File

@ -638,14 +638,17 @@ public:
double OverriddenDeltaX() const;
double OverriddenDeltaY() const;
// Compute the overridden delta value. This may be useful for suppressing
// too fast scroll by system scroll speed overriding when widget sets
// mAllowToOverrideSystemScrollSpeed.
static double ComputeOverriddenDelta(double aDelta, bool aIsForVertical);
private:
static bool sInitialized;
static bool sIsSystemScrollSpeedOverrideEnabled;
static int32_t sOverrideFactorX;
static int32_t sOverrideFactorY;
static void Initialize();
static double ComputeOverriddenDelta(double aDelta, bool aIsForVertical);
};
/******************************************************************************

View File

@ -863,9 +863,36 @@ MouseScrollHandler::LastEventInfo::InitWheelEvent(
mAccumulatedDelta -=
lineOrPageDelta * orienter * RoundDelta(nativeDeltaPerUnit);
aWheelEvent.mAllowToOverrideSystemScrollSpeed =
MouseScrollHandler::sInstance->
mSystemSettings.IsOverridingSystemScrollSpeedAllowed();
if (aWheelEvent.deltaMode != nsIDOMWheelEvent::DOM_DELTA_LINE) {
// If the scroll delta mode isn't per line scroll, we shouldn't allow to
// override the system scroll speed setting.
aWheelEvent.mAllowToOverrideSystemScrollSpeed = false;
} else if (!MouseScrollHandler::sInstance->
mSystemSettings.IsOverridingSystemScrollSpeedAllowed()) {
// If the system settings are customized by either the user or
// the mouse utility, we shouldn't allow to override the system scroll
// speed setting.
aWheelEvent.mAllowToOverrideSystemScrollSpeed = false;
} else {
// For suppressing too fast scroll, we should ensure that the maximum
// overridden delta value should be less than overridden scroll speed
// with default scroll amount.
double defaultScrollAmount =
mIsVertical ? SystemSettings::DefaultScrollLines() :
SystemSettings::DefaultScrollChars();
double maxDelta =
WidgetWheelEvent::ComputeOverriddenDelta(defaultScrollAmount,
mIsVertical);
if (maxDelta != defaultScrollAmount) {
double overriddenDelta =
WidgetWheelEvent::ComputeOverriddenDelta(Abs(delta), mIsVertical);
if (overriddenDelta > maxDelta) {
// Suppress to fast scroll since overriding system scroll speed with
// current delta value causes too big delta value.
aWheelEvent.mAllowToOverrideSystemScrollSpeed = false;
}
}
}
MOZ_LOG(gMouseScrollLog, LogLevel::Info,
("MouseScroll::LastEventInfo::InitWheelEvent: aWidget=%p, "
@ -930,7 +957,7 @@ MouseScrollHandler::SystemSettings::InitScrollLines()
MOZ_LOG(gMouseScrollLog, LogLevel::Info,
("MouseScroll::SystemSettings::InitScrollLines(): ::SystemParametersInfo("
"SPI_GETWHEELSCROLLLINES) failed"));
mScrollLines = 3;
mScrollLines = DefaultScrollLines();
}
if (mScrollLines > WHEEL_DELTA) {
@ -972,6 +999,7 @@ MouseScrollHandler::SystemSettings::InitScrollChars()
IsVistaOrLater() ?
"this is unexpected on Vista or later" :
"but on XP or earlier, this is not a problem"));
// XXX Should we use DefaultScrollChars()?
mScrollChars = 1;
}
@ -1055,11 +1083,8 @@ MouseScrollHandler::SystemSettings::TrustedScrollSettingsDriver()
bool
MouseScrollHandler::SystemSettings::IsOverridingSystemScrollSpeedAllowed()
{
// The default vertical and horizontal scrolling speed is 3, this is defined
// on the document of SystemParametersInfo in MSDN.
const uint32_t kSystemDefaultScrollingSpeed = 3;
return mScrollLines == kSystemDefaultScrollingSpeed &&
(!IsVistaOrLater() || mScrollChars == kSystemDefaultScrollingSpeed);
return mScrollLines == DefaultScrollLines() &&
(!IsVistaOrLater() || mScrollChars == DefaultScrollChars());
}
/******************************************************************************

View File

@ -300,6 +300,11 @@ private:
(uint32_t(mScrollChars) == WHEEL_PAGESCROLL);
}
// The default vertical and horizontal scrolling speed is 3, this is defined
// on the document of SystemParametersInfo in MSDN.
static int32_t DefaultScrollLines() { return 3; }
static int32_t DefaultScrollChars() { return 3; }
private:
bool mInitialized;
// The result of SystemParametersInfo() may not be reliable since it may

View File

@ -3715,48 +3715,6 @@ nsWindow::OnDefaultButtonLoaded(const LayoutDeviceIntRect& aButtonRect)
return NS_OK;
}
#if 0
NS_IMETHODIMP
nsWindow::OverrideSystemMouseScrollSpeed(double aOriginalDeltaX,
double aOriginalDeltaY,
double& aOverriddenDeltaX,
double& aOverriddenDeltaY)
{
// The default vertical and horizontal scrolling speed is 3, this is defined
// on the document of SystemParametersInfo in MSDN.
const uint32_t kSystemDefaultScrollingSpeed = 3;
// Limit the overridden delta value from the system settings. The mouse
// driver might accelerate the scrolling speed already. If so, we shouldn't
// override the scrolling speed for preventing the unexpected high speed
// scrolling.
double absDeltaLimitX, absDeltaLimitY;
rv =
nsBaseWidget::OverrideSystemMouseScrollSpeed(kSystemDefaultScrollingSpeed,
kSystemDefaultScrollingSpeed,
absDeltaLimitX,
absDeltaLimitY);
NS_ENSURE_SUCCESS(rv, rv);
// If the given delta is larger than our computed limitation value, the delta
// was accelerated by the mouse driver. So, we should do nothing here.
if (absDeltaLimitX <= absOriginDeltaX || absDeltaLimitY <= absOriginDeltaY) {
return NS_OK;
}
aOverriddenDeltaX = std::min(absComputedOverriddenDeltaX, absDeltaLimitX);
aOverriddenDeltaY = std::min(absComputedOverriddenDeltaY, absDeltaLimitY);
if (aOriginalDeltaX < 0) {
aOverriddenDeltaX *= -1;
}
if (aOriginalDeltaY < 0) {
aOverriddenDeltaY *= -1;
}
return NS_OK;
}
#endif
already_AddRefed<mozilla::gfx::DrawTarget>
nsWindow::StartRemoteDrawing()
{