Bug 1235686 part.1 MouseScrollHandler should refresh the cache of system settings at handling wheel messages if the pref doesn't allow to cache system settings r=jimm

This commit is contained in:
Masayuki Nakano 2016-01-13 10:49:38 +09:00
Родитель cb77a8b5fe
Коммит c218da049b
3 изменённых файлов: 126 добавлений и 20 удалений

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

@ -3261,6 +3261,16 @@ pref("ui.panel.default_level_parent", false);
pref("mousewheel.system_scroll_override_on_root_content.enabled", true); pref("mousewheel.system_scroll_override_on_root_content.enabled", true);
// Enable system settings cache for mouse wheel message handling.
// Note that even if this pref is set to true, Gecko may not cache the system
// settings if Gecko detects that the cache won't be refreshed properly when
// the settings are changed.
pref("mousewheel.system_settings_cache.enabled", true);
// This is a pref to test system settings cache for mouse wheel message
// handling. If this is set to true, Gecko forcibly use the cache.
pref("mousewheel.system_settings_cache.force_enabled", false);
// High resolution scrolling with supported mouse drivers on Vista or later. // High resolution scrolling with supported mouse drivers on Vista or later.
pref("mousewheel.enable_pixel_scrolling", true); pref("mousewheel.enable_pixel_scrolling", true);

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

@ -603,6 +603,10 @@ MouseScrollHandler::HandleMouseWheelMessage(nsWindowBase* aWidget,
mIsWaitingInternalMessage = false; mIsWaitingInternalMessage = false;
// 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);
EventInfo eventInfo(aWidget, WinUtils::GetNativeMessage(aMessage), EventInfo eventInfo(aWidget, WinUtils::GetNativeMessage(aMessage),
aWParam, aLParam); aWParam, aLParam);
if (!eventInfo.CanDispatchWheelEvent()) { if (!eventInfo.CanDispatchWheelEvent()) {
@ -881,30 +885,41 @@ MouseScrollHandler::SystemSettings::Init()
return; return;
} }
InitScrollLines();
InitScrollChars();
mInitialized = true; mInitialized = true;
MouseScrollHandler::UserPrefs& userPrefs = MOZ_LOG(gMouseScrollLog, LogLevel::Info,
MouseScrollHandler::sInstance->mUserPrefs; ("MouseScroll::SystemSettings::Init(): initialized, "
"mScrollLines=%d, mScrollChars=%d",
mScrollLines, mScrollChars));
}
mScrollLines = userPrefs.GetOverriddenVerticalScrollAmout(); bool
MouseScrollHandler::SystemSettings::InitScrollLines()
{
int32_t oldValue = mInitialized ? mScrollLines : 0;
mScrollLines = MouseScrollHandler::sInstance->
mUserPrefs.GetOverriddenVerticalScrollAmout();
if (mScrollLines >= 0) { if (mScrollLines >= 0) {
// overridden by the pref. // overridden by the pref.
MOZ_LOG(gMouseScrollLog, LogLevel::Info, MOZ_LOG(gMouseScrollLog, LogLevel::Info,
("MouseScroll::SystemSettings::Init(): mScrollLines is overridden by " ("MouseScroll::SystemSettings::InitScrollLines(): mScrollLines is "
"the pref: %d", "overridden by the pref: %d",
mScrollLines)); mScrollLines));
} else if (!::SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, } else if (!::SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0,
&mScrollLines, 0)) { &mScrollLines, 0)) {
MOZ_LOG(gMouseScrollLog, LogLevel::Info, MOZ_LOG(gMouseScrollLog, LogLevel::Info,
("MouseScroll::SystemSettings::Init(): ::SystemParametersInfo(" ("MouseScroll::SystemSettings::InitScrollLines(): ::SystemParametersInfo("
"SPI_GETWHEELSCROLLLINES) failed")); "SPI_GETWHEELSCROLLLINES) failed"));
mScrollLines = 3; mScrollLines = 3;
} }
if (mScrollLines > WHEEL_DELTA) { if (mScrollLines > WHEEL_DELTA) {
MOZ_LOG(gMouseScrollLog, LogLevel::Info, MOZ_LOG(gMouseScrollLog, LogLevel::Info,
("MouseScroll::SystemSettings::Init(): the result of " ("MouseScroll::SystemSettings::InitScrollLines(): the result of "
"::SystemParametersInfo(SPI_GETWHEELSCROLLLINES) is too large: %d", "::SystemParametersInfo(SPI_GETWHEELSCROLLLINES) is too large: %d",
mScrollLines)); mScrollLines));
// sScrollLines usually equals 3 or 0 (for no scrolling) // sScrollLines usually equals 3 or 0 (for no scrolling)
// However, if sScrollLines > WHEEL_DELTA, we assume that // However, if sScrollLines > WHEEL_DELTA, we assume that
@ -915,18 +930,26 @@ MouseScrollHandler::SystemSettings::Init()
mScrollLines = WHEEL_PAGESCROLL; mScrollLines = WHEEL_PAGESCROLL;
} }
mScrollChars = userPrefs.GetOverriddenHorizontalScrollAmout(); return oldValue != mScrollLines;
}
bool
MouseScrollHandler::SystemSettings::InitScrollChars()
{
int32_t oldValue = mInitialized ? mScrollChars : 0;
mScrollChars = MouseScrollHandler::sInstance->
mUserPrefs.GetOverriddenHorizontalScrollAmout();
if (mScrollChars >= 0) { if (mScrollChars >= 0) {
// overridden by the pref. // overridden by the pref.
MOZ_LOG(gMouseScrollLog, LogLevel::Info, MOZ_LOG(gMouseScrollLog, LogLevel::Info,
("MouseScroll::SystemSettings::Init(): mScrollChars is overridden by " ("MouseScroll::SystemSettings::InitScrollChars(): mScrollChars is "
"the pref: %d", "overridden by the pref: %d",
mScrollChars)); mScrollChars));
} else if (!::SystemParametersInfo(SPI_GETWHEELSCROLLCHARS, 0, } else if (!::SystemParametersInfo(SPI_GETWHEELSCROLLCHARS, 0,
&mScrollChars, 0)) { &mScrollChars, 0)) {
MOZ_LOG(gMouseScrollLog, LogLevel::Info, MOZ_LOG(gMouseScrollLog, LogLevel::Info,
("MouseScroll::SystemSettings::Init(): ::SystemParametersInfo(" ("MouseScroll::SystemSettings::InitScrollChars(): ::SystemParametersInfo("
"SPI_GETWHEELSCROLLCHARS) failed, %s", "SPI_GETWHEELSCROLLCHARS) failed, %s",
IsVistaOrLater() ? IsVistaOrLater() ?
"this is unexpected on Vista or later" : "this is unexpected on Vista or later" :
"but on XP or earlier, this is not a problem")); "but on XP or earlier, this is not a problem"));
@ -935,17 +958,14 @@ MouseScrollHandler::SystemSettings::Init()
if (mScrollChars > WHEEL_DELTA) { if (mScrollChars > WHEEL_DELTA) {
MOZ_LOG(gMouseScrollLog, LogLevel::Info, MOZ_LOG(gMouseScrollLog, LogLevel::Info,
("MouseScroll::SystemSettings::Init(): the result of " ("MouseScroll::SystemSettings::InitScrollChars(): the result of "
"::SystemParametersInfo(SPI_GETWHEELSCROLLCHARS) is too large: %d", "::SystemParametersInfo(SPI_GETWHEELSCROLLCHARS) is too large: %d",
mScrollChars)); mScrollChars));
// See the comments for the case mScrollLines > WHEEL_DELTA. // See the comments for the case mScrollLines > WHEEL_DELTA.
mScrollChars = WHEEL_PAGESCROLL; mScrollChars = WHEEL_PAGESCROLL;
} }
MOZ_LOG(gMouseScrollLog, LogLevel::Info, return oldValue != mScrollChars;
("MouseScroll::SystemSettings::Init(): initialized, "
"mScrollLines=%d, mScrollChars=%d",
mScrollLines, mScrollChars));
} }
void void
@ -961,6 +981,45 @@ MouseScrollHandler::SystemSettings::MarkDirty()
MouseScrollHandler::sInstance->mLastEventInfo.ResetTransaction(); MouseScrollHandler::sInstance->mLastEventInfo.ResetTransaction();
} }
void
MouseScrollHandler::SystemSettings::RefreshCache(bool aForVertical)
{
bool isChanged = aForVertical ? InitScrollLines() : InitScrollChars();
if (!isChanged) {
return;
}
// If the scroll amount is changed, we should reset current transaction.
MOZ_ASSERT(sInstance,
"Must not be called at initializing MouseScrollHandler");
MouseScrollHandler::sInstance->mLastEventInfo.ResetTransaction();
}
void
MouseScrollHandler::SystemSettings::TrustedScrollSettingsDriver(
bool aIsVertical)
{
if (!mInitialized) {
return;
}
MouseScrollHandler::UserPrefs& userPrefs =
MouseScrollHandler::sInstance->mUserPrefs;
// If system settings cache is disabled, we should always refresh them.
if (!userPrefs.IsSystemSettingCacheEnabled()) {
RefreshCache(aIsVertical);
return;
}
// If pref is set to as "always trust the cache", we shouldn't refresh them
// in any environments.
if (userPrefs.IsSystemSettingCacheForciblyEnabled()) {
return;
}
// TODO: Implement to check if we can trust the cache in the environment.
}
/****************************************************************************** /******************************************************************************
* *
* UserPrefs * UserPrefs
@ -997,6 +1056,11 @@ MouseScrollHandler::UserPrefs::Init()
mScrollMessageHandledAsWheelMessage = mScrollMessageHandledAsWheelMessage =
Preferences::GetBool("mousewheel.emulate_at_wm_scroll", false); Preferences::GetBool("mousewheel.emulate_at_wm_scroll", false);
mEnableSystemSettingCache =
Preferences::GetBool("mousewheel.system_settings_cache.enabled", true);
mForceEnableSystemSettingCache =
Preferences::GetBool("mousewheel.system_settings_cache.force_enabled",
false);
mOverriddenVerticalScrollAmount = mOverriddenVerticalScrollAmount =
Preferences::GetInt("mousewheel.windows.vertical_amount_override", -1); Preferences::GetInt("mousewheel.windows.vertical_amount_override", -1);
mOverriddenHorizontalScrollAmount = mOverriddenHorizontalScrollAmount =
@ -1008,10 +1072,14 @@ MouseScrollHandler::UserPrefs::Init()
MOZ_LOG(gMouseScrollLog, LogLevel::Info, MOZ_LOG(gMouseScrollLog, LogLevel::Info,
("MouseScroll::UserPrefs::Init(): initialized, " ("MouseScroll::UserPrefs::Init(): initialized, "
"mScrollMessageHandledAsWheelMessage=%s, " "mScrollMessageHandledAsWheelMessage=%s, "
"mEnableSystemSettingCache=%s, "
"mForceEnableSystemSettingCache=%s, "
"mOverriddenVerticalScrollAmount=%d, " "mOverriddenVerticalScrollAmount=%d, "
"mOverriddenHorizontalScrollAmount=%d, " "mOverriddenHorizontalScrollAmount=%d, "
"mMouseScrollTransactionTimeout=%d", "mMouseScrollTransactionTimeout=%d",
GetBoolName(mScrollMessageHandledAsWheelMessage), GetBoolName(mScrollMessageHandledAsWheelMessage),
GetBoolName(mEnableSystemSettingCache),
GetBoolName(mForceEnableSystemSettingCache),
mOverriddenVerticalScrollAmount, mOverriddenHorizontalScrollAmount, mOverriddenVerticalScrollAmount, mOverriddenHorizontalScrollAmount,
mMouseScrollTransactionTimeout)); mMouseScrollTransactionTimeout));
} }

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

@ -273,6 +273,14 @@ private:
void MarkDirty(); void MarkDirty();
void NotifyUserPrefsMayOverrideSystemSettings(); void NotifyUserPrefsMayOverrideSystemSettings();
// On some environments, SystemParametersInfo() may be hooked by touchpad
// utility or something. In such case, when user changes active pointing
// device to another one, the result of SystemParametersInfo() may be
// 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);
int32_t GetScrollAmount(bool aForVertical) const int32_t GetScrollAmount(bool aForVertical) const
{ {
MOZ_ASSERT(mInitialized, "SystemSettings must be initialized"); MOZ_ASSERT(mInitialized, "SystemSettings must be initialized");
@ -290,6 +298,12 @@ private:
bool mInitialized; bool mInitialized;
int32_t mScrollLines; int32_t mScrollLines;
int32_t mScrollChars; int32_t mScrollChars;
// Returns true if cached value is changed.
bool InitScrollLines();
bool InitScrollChars();
void RefreshCache(bool aForVertical);
}; };
SystemSettings mSystemSettings; SystemSettings mSystemSettings;
@ -307,6 +321,18 @@ private:
return mScrollMessageHandledAsWheelMessage; return mScrollMessageHandledAsWheelMessage;
} }
bool IsSystemSettingCacheEnabled()
{
Init();
return mEnableSystemSettingCache;
}
bool IsSystemSettingCacheForciblyEnabled()
{
Init();
return mForceEnableSystemSettingCache;
}
int32_t GetOverriddenVerticalScrollAmout() int32_t GetOverriddenVerticalScrollAmout()
{ {
Init(); Init();
@ -335,6 +361,8 @@ private:
bool mInitialized; bool mInitialized;
bool mScrollMessageHandledAsWheelMessage; bool mScrollMessageHandledAsWheelMessage;
bool mEnableSystemSettingCache;
bool mForceEnableSystemSettingCache;
int32_t mOverriddenVerticalScrollAmount; int32_t mOverriddenVerticalScrollAmount;
int32_t mOverriddenHorizontalScrollAmount; int32_t mOverriddenHorizontalScrollAmount;
int32_t mMouseScrollTransactionTimeout; int32_t mMouseScrollTransactionTimeout;