Bug 1153156 part.2 Make WidgetWheelEvent store if overriding system scroll speed is allowed and it shouldn't be allowed if scroll speed isn't system default settings on Windows r=smaug+jimm

This commit is contained in:
Masayuki Nakano 2016-01-27 15:09:13 +09:00
parent 05401d4a7f
commit f9a85c2ca7
6 changed files with 53 additions and 60 deletions

View File

@ -462,6 +462,7 @@ private:
, overflowDeltaY(0.0)
, mViewPortIsOverscrolled(false)
, mCanTriggerSwipe(false)
, mAllowToOverrideSystemScrollSpeed(false)
{
}
@ -485,6 +486,7 @@ public:
, overflowDeltaY(0.0)
, mViewPortIsOverscrolled(false)
, mCanTriggerSwipe(false)
, mAllowToOverrideSystemScrollSpeed(true)
{
}
@ -599,6 +601,11 @@ public:
// viewport.
bool mCanTriggerSwipe;
// If mAllowToOverrideSystemScrollSpeed is true, the scroll speed may be
// overridden. Otherwise, the scroll speed won't be overridden even if
// it's enabled by the pref.
bool mAllowToOverrideSystemScrollSpeed;
void AssignWheelEventData(const WidgetWheelEvent& aEvent, bool aCopyTargets)
{
AssignMouseEventBaseData(aEvent, aCopyTargets);
@ -618,6 +625,8 @@ public:
overflowDeltaY = aEvent.overflowDeltaY;
mViewPortIsOverscrolled = aEvent.mViewPortIsOverscrolled;
mCanTriggerSwipe = aEvent.mCanTriggerSwipe;
mAllowToOverrideSystemScrollSpeed =
aEvent.mAllowToOverrideSystemScrollSpeed;
}
// System scroll speed settings may be too slow at using Gecko. In such

View File

@ -384,12 +384,18 @@ WidgetWheelEvent::ComputeOverriddenDelta(double aDelta, bool aIsForVertical)
double
WidgetWheelEvent::OverriddenDeltaX() const
{
if (!mAllowToOverrideSystemScrollSpeed) {
return deltaX;
}
return ComputeOverriddenDelta(deltaX, false);
}
double
WidgetWheelEvent::OverriddenDeltaY() const
{
if (!mAllowToOverrideSystemScrollSpeed) {
return deltaY;
}
return ComputeOverriddenDelta(deltaY, true);
}

View File

@ -175,6 +175,7 @@ struct ParamTraits<mozilla::WidgetWheelEvent>
WriteParam(aMsg, aParam.overflowDeltaY);
WriteParam(aMsg, aParam.mViewPortIsOverscrolled);
WriteParam(aMsg, aParam.mCanTriggerSwipe);
WriteParam(aMsg, aParam.mAllowToOverrideSystemScrollSpeed);
}
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
@ -197,7 +198,8 @@ struct ParamTraits<mozilla::WidgetWheelEvent>
ReadParam(aMsg, aIter, &aResult->overflowDeltaX) &&
ReadParam(aMsg, aIter, &aResult->overflowDeltaY) &&
ReadParam(aMsg, aIter, &aResult->mViewPortIsOverscrolled) &&
ReadParam(aMsg, aIter, &aResult->mCanTriggerSwipe);
ReadParam(aMsg, aIter, &aResult->mCanTriggerSwipe) &&
ReadParam(aMsg, aIter, &aResult->mAllowToOverrideSystemScrollSpeed);
aResult->scrollType =
static_cast<mozilla::WidgetWheelEvent::ScrollType>(scrollType);
return rv;

View File

@ -613,7 +613,7 @@ MouseScrollHandler::HandleMouseWheelMessage(nsWindowBase* aWidget,
// If it's not allowed to cache system settings, we need to reset the cache
// before handling the mouse wheel message.
mSystemSettings.TrustedScrollSettingsDriver(aMessage == MOZ_WM_MOUSEVWHEEL);
mSystemSettings.TrustedScrollSettingsDriver();
EventInfo eventInfo(aWidget, WinUtils::GetNativeMessage(aMessage),
aWParam, aLParam);
@ -863,11 +863,16 @@ MouseScrollHandler::LastEventInfo::InitWheelEvent(
mAccumulatedDelta -=
lineOrPageDelta * orienter * RoundDelta(nativeDeltaPerUnit);
aWheelEvent.mAllowToOverrideSystemScrollSpeed =
MouseScrollHandler::sInstance->
mSystemSettings.IsOverridingSystemScrollSpeedAllowed();
MOZ_LOG(gMouseScrollLog, LogLevel::Info,
("MouseScroll::LastEventInfo::InitWheelEvent: aWidget=%p, "
"aWheelEvent { refPoint: { x: %d, y: %d }, deltaX: %f, deltaY: %f, "
"lineOrPageDeltaX: %d, lineOrPageDeltaY: %d, "
"isShift: %s, isControl: %s, isAlt: %s, isMeta: %s }, "
"isShift: %s, isControl: %s, isAlt: %s, isMeta: %s, "
"mAllowToOverrideSystemScrollSpeed: %s }, "
"mAccumulatedDelta: %d",
aWidget, aWheelEvent.refPoint.x, aWheelEvent.refPoint.y,
aWheelEvent.deltaX, aWheelEvent.deltaY,
@ -875,7 +880,9 @@ MouseScrollHandler::LastEventInfo::InitWheelEvent(
GetBoolName(aWheelEvent.IsShift()),
GetBoolName(aWheelEvent.IsControl()),
GetBoolName(aWheelEvent.IsAlt()),
GetBoolName(aWheelEvent.IsMeta()), mAccumulatedDelta));
GetBoolName(aWheelEvent.IsMeta()),
GetBoolName(aWheelEvent.mAllowToOverrideSystemScrollSpeed),
mAccumulatedDelta));
return (delta != 0);
}
@ -994,9 +1001,10 @@ MouseScrollHandler::SystemSettings::MarkDirty()
}
void
MouseScrollHandler::SystemSettings::RefreshCache(bool aForVertical)
MouseScrollHandler::SystemSettings::RefreshCache()
{
bool isChanged = aForVertical ? InitScrollLines() : InitScrollChars();
bool isChanged = InitScrollLines();
isChanged = InitScrollChars() || isChanged;
if (!isChanged) {
return;
}
@ -1007,16 +1015,14 @@ MouseScrollHandler::SystemSettings::RefreshCache(bool aForVertical)
}
void
MouseScrollHandler::SystemSettings::TrustedScrollSettingsDriver(
bool aIsVertical)
MouseScrollHandler::SystemSettings::TrustedScrollSettingsDriver()
{
if (!mInitialized) {
return;
}
// if the cache is initialized with prefs, we don't need to refresh it.
if ((aIsVertical && mIsReliableScrollLines) ||
(!aIsVertical && mIsReliableScrollChars)) {
if (mIsReliableScrollLines && mIsReliableScrollChars) {
return;
}
@ -1025,7 +1031,7 @@ MouseScrollHandler::SystemSettings::TrustedScrollSettingsDriver(
// If system settings cache is disabled, we should always refresh them.
if (!userPrefs.IsSystemSettingCacheEnabled()) {
RefreshCache(aIsVertical);
RefreshCache();
return;
}
@ -1039,13 +1045,23 @@ MouseScrollHandler::SystemSettings::TrustedScrollSettingsDriver(
// ::SystemParametersInfo() and returns different value from system settings.
if (Device::SynTP::IsDriverInstalled() ||
Device::Apoint::IsDriverInstalled()) {
RefreshCache(aIsVertical);
RefreshCache();
return;
}
// XXX We're not sure about other touchpad drivers...
}
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);
}
/******************************************************************************
*
* UserPrefs

View File

@ -279,7 +279,13 @@ private:
// changed without WM_SETTINGCHANGE message. For avoiding this trouble,
// we need to modify cache of system settings at every wheel message
// handling if we meet known device whose utility may hook the API.
void TrustedScrollSettingsDriver(bool aIsVertical);
void TrustedScrollSettingsDriver();
// Returns true if the system scroll may be overridden for faster scroll.
// Otherwise, false. For example, if the user maybe uses an expensive
// mouse which supports acceleration of scroll speed, faster scroll makes
// the user inconvenient.
bool IsOverridingSystemScrollSpeedAllowed();
int32_t GetScrollAmount(bool aForVertical) const
{
@ -310,7 +316,7 @@ private:
bool InitScrollLines();
bool InitScrollChars();
void RefreshCache(bool aForVertical);
void RefreshCache();
};
SystemSettings mSystemSettings;

View File

@ -3726,52 +3726,6 @@ nsWindow::OverrideSystemMouseScrollSpeed(double aOriginalDeltaX,
// on the document of SystemParametersInfo in MSDN.
const uint32_t kSystemDefaultScrollingSpeed = 3;
double absOriginDeltaX = Abs(aOriginalDeltaX);
double absOriginDeltaY = Abs(aOriginalDeltaY);
// Compute the simple overridden speed.
double absComputedOverriddenDeltaX, absComputedOverriddenDeltaY;
nsresult rv =
nsBaseWidget::OverrideSystemMouseScrollSpeed(absOriginDeltaX,
absOriginDeltaY,
absComputedOverriddenDeltaX,
absComputedOverriddenDeltaY);
NS_ENSURE_SUCCESS(rv, rv);
aOverriddenDeltaX = aOriginalDeltaX;
aOverriddenDeltaY = aOriginalDeltaY;
if (absComputedOverriddenDeltaX == absOriginDeltaX &&
absComputedOverriddenDeltaY == absOriginDeltaY) {
// We don't override now.
return NS_OK;
}
// Otherwise, we should check whether the user customized the system settings
// or not. If the user did it, we should respect the will.
UINT systemSpeed;
if (!::SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &systemSpeed, 0)) {
return NS_ERROR_FAILURE;
}
// The default vertical scrolling speed is 3, this is defined on the document
// of SystemParametersInfo in MSDN.
if (systemSpeed != kSystemDefaultScrollingSpeed) {
return NS_OK;
}
// Only Vista and later, Windows has the system setting of horizontal
// scrolling by the mouse wheel.
if (IsVistaOrLater()) {
if (!::SystemParametersInfo(SPI_GETWHEELSCROLLCHARS, 0, &systemSpeed, 0)) {
return NS_ERROR_FAILURE;
}
// The default horizontal scrolling speed is 3, this is defined on the
// document of SystemParametersInfo in MSDN.
if (systemSpeed != kSystemDefaultScrollingSpeed) {
return NS_OK;
}
}
// 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