From 748e4225adf5049f8f9f62d4fb56e28a1b59d466 Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Tue, 6 Mar 2012 12:20:28 +0900 Subject: [PATCH] Bug 672175 part.3 MouseScrollHandler should manage user prefs r=jimm --- widget/windows/WinMouseScrollHandler.cpp | 61 ++++++++++++++++++++++++ widget/windows/WinMouseScrollHandler.h | 42 ++++++++++++++++ widget/windows/nsWindow.cpp | 18 ++----- widget/windows/nsWindow.h | 1 - 4 files changed, 108 insertions(+), 14 deletions(-) diff --git a/widget/windows/WinMouseScrollHandler.cpp b/widget/windows/WinMouseScrollHandler.cpp index a5f2f7772e04..9265ae2a5084 100644 --- a/widget/windows/WinMouseScrollHandler.cpp +++ b/widget/windows/WinMouseScrollHandler.cpp @@ -13,11 +13,18 @@ #include "nsWindow.h" #include "WinUtils.h" +#include "mozilla/Preferences.h" + namespace mozilla { namespace widget { #ifdef PR_LOGGING PRLogModuleInfo* gMouseScrollLog = nsnull; + +static const char* GetBoolName(bool aBool) +{ + return aBool ? "TRUE" : "FALSE"; +} #endif MouseScrollHandler* MouseScrollHandler::sInstance = nsnull; @@ -159,5 +166,59 @@ MouseScrollHandler::SystemSettings::MarkDirty() mInitialized = false; } +/****************************************************************************** + * + * UserPrefs + * + ******************************************************************************/ + +MouseScrollHandler::UserPrefs::UserPrefs() : + mInitialized(false) +{ + // We need to reset mouse wheel transaction when all of mousewheel related + // prefs are changed. + DebugOnly rv = + Preferences::RegisterCallback(OnChange, "mousewheel.", this); + MOZ_ASSERT(NS_SUCCEEDED(rv), + "Failed to register callback for mousewheel."); +} + +MouseScrollHandler::UserPrefs::~UserPrefs() +{ + DebugOnly rv = + Preferences::UnregisterCallback(OnChange, "mousewheel.", this); + MOZ_ASSERT(NS_SUCCEEDED(rv), + "Failed to unregister callback for mousewheel."); +} + +void +MouseScrollHandler::UserPrefs::Init() +{ + if (mInitialized) { + return; + } + + mInitialized = true; + + mPixelScrollingEnabled = + Preferences::GetBool("mousewheel.enable_pixel_scrolling", true); + mScrollMessageHandledAsWheelMessage = + Preferences::GetBool("mousewheel.emulate_at_wm_scroll", false); + + PR_LOG(gMouseScrollLog, PR_LOG_ALWAYS, + ("MouseScroll::UserPrefs::Init(): initialized, " + "mPixelScrollingEnabled=%s, mScrollMessageHandledAsWheelMessage=%s", + GetBoolName(mPixelScrollingEnabled), + GetBoolName(mScrollMessageHandledAsWheelMessage))); +} + +void +MouseScrollHandler::UserPrefs::MarkDirty() +{ + PR_LOG(gMouseScrollLog, PR_LOG_ALWAYS, + ("MouseScrollHandler::UserPrefs::MarkDirty(): Marking UserPrefs dirty")); + mInitialized = false; +} + } // namespace widget } // namespace mozilla diff --git a/widget/windows/WinMouseScrollHandler.h b/widget/windows/WinMouseScrollHandler.h index 940cf8bdedce..9ba4192bacf9 100644 --- a/widget/windows/WinMouseScrollHandler.h +++ b/widget/windows/WinMouseScrollHandler.h @@ -71,6 +71,48 @@ public: private: SystemSettings mSystemSettings; + +public: + class UserPrefs { + public: + UserPrefs(); + ~UserPrefs(); + + void MarkDirty(); + + bool IsPixelScrollingEnabled() + { + Init(); + return mPixelScrollingEnabled; + } + + bool IsScrollMessageHandledAsWheelMessage() + { + Init(); + return mScrollMessageHandledAsWheelMessage; + } + + private: + void Init(); + + static int OnChange(const char* aPrefName, void* aClosure) + { + static_cast(aClosure)->MarkDirty(); + return 0; + } + + bool mInitialized; + bool mPixelScrollingEnabled; + bool mScrollMessageHandledAsWheelMessage; + }; + + UserPrefs& GetUserPrefs() + { + return mUserPrefs; + } + +private: + UserPrefs mUserPrefs; }; } // namespace widget diff --git a/widget/windows/nsWindow.cpp b/widget/windows/nsWindow.cpp index 8015ad686168..967795f3c033 100644 --- a/widget/windows/nsWindow.cpp +++ b/widget/windows/nsWindow.cpp @@ -292,7 +292,6 @@ PRUint32 nsWindow::sOOPPPluginFocusEvent = MSG nsWindow::sRedirectedKeyDown; -bool nsWindow::sEnablePixelScrolling = true; bool nsWindow::sNeedsToInitMouseWheelSettings = true; HWND nsWindow::sLastMouseWheelWnd = NULL; @@ -6312,9 +6311,6 @@ nsWindow::InitMouseWheelScrollData() } sNeedsToInitMouseWheelSettings = false; ResetRemainingWheelDelta(); - - sEnablePixelScrolling = - Preferences::GetBool("mousewheel.enable_pixel_scrolling", true); } /* static */ @@ -6422,7 +6418,8 @@ nsWindow::OnMouseWheelInternal(UINT aMessage, WPARAM aWParam, LPARAM aLParam, PRInt32 computedScrollAmount = isPageScroll ? 1 : systemSettings.GetScrollAmount(isVertical); - if (sEnablePixelScrolling) { + if (MouseScrollHandler::GetInstance()-> + GetUserPrefs().IsPixelScrollingEnabled()) { nsMouseScrollEvent testEvent(true, NS_MOUSE_SCROLL, this); InitEvent(testEvent); testEvent.scrollFlags = isPageScroll ? nsMouseScrollEvent::kIsFullPage : 0; @@ -7567,14 +7564,9 @@ nsWindow::OnMouseWheel(UINT aMsg, WPARAM aWParam, LPARAM aLParam, bool nsWindow::OnScroll(UINT aMsg, WPARAM aWParam, LPARAM aLParam) { - static PRInt8 sMouseWheelEmulation = -1; - if (sMouseWheelEmulation < 0) { - bool emulate = - Preferences::GetBool("mousewheel.emulate_at_wm_scroll", false); - sMouseWheelEmulation = PRInt8(emulate); - } - - if (aLParam || sMouseWheelEmulation) { + if (aLParam || + MouseScrollHandler::GetInstance()-> + GetUserPrefs().IsScrollMessageHandledAsWheelMessage()) { // Scroll message generated by Thinkpad Trackpoint Driver or similar // Treat as a mousewheel message and scroll appropriately LRESULT retVal; diff --git a/widget/windows/nsWindow.h b/widget/windows/nsWindow.h index ef0afe97879b..3d1ac1e7a24c 100644 --- a/widget/windows/nsWindow.h +++ b/widget/windows/nsWindow.h @@ -608,7 +608,6 @@ protected: // was reirected to SendInput() API by OnKeyDown(). static MSG sRedirectedKeyDown; - static bool sEnablePixelScrolling; static bool sNeedsToInitMouseWheelSettings; static void InitMouseWheelScrollData();