зеркало из https://github.com/mozilla/pjs.git
Bug 672175 part.2 MouseScrollHandler should manage system settings r=jimm
This commit is contained in:
Родитель
bca7d8e5f4
Коммит
f00be25d7f
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include "WinMouseScrollHandler.h"
|
||||
#include "nsWindow.h"
|
||||
#include "WinUtils.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace widget {
|
||||
|
@ -77,9 +78,86 @@ MouseScrollHandler::ProcessMessage(nsWindow* aWindow, UINT msg,
|
|||
WPARAM wParam, LPARAM lParam,
|
||||
LRESULT *aRetValue, bool &aEatMessage)
|
||||
{
|
||||
return false;
|
||||
switch (msg) {
|
||||
case WM_SETTINGCHANGE:
|
||||
if (!sInstance) {
|
||||
return false;
|
||||
}
|
||||
if (wParam == SPI_SETWHEELSCROLLLINES ||
|
||||
wParam == SPI_SETWHEELSCROLLCHARS) {
|
||||
sInstance->mSystemSettings.MarkDirty();
|
||||
}
|
||||
return false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* SystemSettings
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
void
|
||||
MouseScrollHandler::SystemSettings::Init()
|
||||
{
|
||||
if (mInitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
mInitialized = true;
|
||||
|
||||
if (!::SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &mScrollLines, 0)) {
|
||||
PR_LOG(gMouseScrollLog, PR_LOG_ALWAYS,
|
||||
("MouseScroll::SystemSettings::Init(): ::SystemParametersInfo("
|
||||
"SPI_GETWHEELSCROLLLINES) failed"));
|
||||
mScrollLines = 3;
|
||||
} else if (mScrollLines > WHEEL_DELTA) {
|
||||
PR_LOG(gMouseScrollLog, PR_LOG_ALWAYS,
|
||||
("MouseScroll::SystemSettings::Init(): the result of "
|
||||
"::SystemParametersInfo(SPI_GETWHEELSCROLLLINES) is too large: %d",
|
||||
mScrollLines));
|
||||
// sScrollLines usually equals 3 or 0 (for no scrolling)
|
||||
// However, if sScrollLines > WHEEL_DELTA, we assume that
|
||||
// the mouse driver wants a page scroll. The docs state that
|
||||
// sScrollLines should explicitly equal WHEEL_PAGESCROLL, but
|
||||
// since some mouse drivers use an arbitrary large number instead,
|
||||
// we have to handle that as well.
|
||||
mScrollLines = WHEEL_PAGESCROLL;
|
||||
}
|
||||
|
||||
if (!::SystemParametersInfo(SPI_GETWHEELSCROLLCHARS, 0, &mScrollChars, 0)) {
|
||||
PR_LOG(gMouseScrollLog, PR_LOG_ALWAYS,
|
||||
("MouseScroll::SystemSettings::Init(): ::SystemParametersInfo("
|
||||
"SPI_GETWHEELSCROLLCHARS) failed, %s",
|
||||
WinUtils::GetWindowsVersion() >= WinUtils::VISTA_VERSION ?
|
||||
"this is unexpected on Vista or later" :
|
||||
"but on XP or earlier, this is not a problem"));
|
||||
mScrollChars = 1;
|
||||
} else if (mScrollChars > WHEEL_DELTA) {
|
||||
PR_LOG(gMouseScrollLog, PR_LOG_ALWAYS,
|
||||
("MouseScroll::SystemSettings::Init(): the result of "
|
||||
"::SystemParametersInfo(SPI_GETWHEELSCROLLCHARS) is too large: %d",
|
||||
mScrollChars));
|
||||
// See the comments for the case mScrollLines > WHEEL_DELTA.
|
||||
mScrollChars = WHEEL_PAGESCROLL;
|
||||
}
|
||||
|
||||
PR_LOG(gMouseScrollLog, PR_LOG_ALWAYS,
|
||||
("MouseScroll::SystemSettings::Init(): initialized, "
|
||||
"mScrollLines=%d, mScrollChars=%d",
|
||||
mScrollLines, mScrollChars));
|
||||
}
|
||||
|
||||
void
|
||||
MouseScrollHandler::SystemSettings::MarkDirty()
|
||||
{
|
||||
PR_LOG(gMouseScrollLog, PR_LOG_ALWAYS,
|
||||
("MouseScrollHandler::SystemSettings::MarkDirty(): "
|
||||
"Marking SystemSettings dirty"));
|
||||
mInitialized = false;
|
||||
}
|
||||
|
||||
} // namespace widget
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -36,6 +36,41 @@ private:
|
|||
~MouseScrollHandler();
|
||||
|
||||
static MouseScrollHandler* sInstance;
|
||||
|
||||
public:
|
||||
class SystemSettings {
|
||||
public:
|
||||
SystemSettings() : mInitialized(false) {}
|
||||
|
||||
void Init();
|
||||
void MarkDirty();
|
||||
|
||||
PRInt32 GetScrollAmount(bool aForVertical) const
|
||||
{
|
||||
MOZ_ASSERT(mInitialized, "SystemSettings must be initialized");
|
||||
return aForVertical ? mScrollLines : mScrollChars;
|
||||
}
|
||||
|
||||
bool IsPageScroll(bool aForVertical) const
|
||||
{
|
||||
MOZ_ASSERT(mInitialized, "SystemSettings must be initialized");
|
||||
return aForVertical ? (mScrollLines == WHEEL_PAGESCROLL) :
|
||||
(mScrollChars == WHEEL_PAGESCROLL);
|
||||
}
|
||||
|
||||
private:
|
||||
bool mInitialized;
|
||||
PRInt32 mScrollLines;
|
||||
PRInt32 mScrollChars;
|
||||
};
|
||||
|
||||
SystemSettings& GetSystemSettings()
|
||||
{
|
||||
return mSystemSettings;
|
||||
}
|
||||
|
||||
private:
|
||||
SystemSettings mSystemSettings;
|
||||
};
|
||||
|
||||
} // namespace widget
|
||||
|
|
|
@ -294,8 +294,6 @@ MSG nsWindow::sRedirectedKeyDown;
|
|||
|
||||
bool nsWindow::sEnablePixelScrolling = true;
|
||||
bool nsWindow::sNeedsToInitMouseWheelSettings = true;
|
||||
ULONG nsWindow::sMouseWheelScrollLines = 0;
|
||||
ULONG nsWindow::sMouseWheelScrollChars = 0;
|
||||
|
||||
HWND nsWindow::sLastMouseWheelWnd = NULL;
|
||||
PRInt32 nsWindow::sRemainingDeltaForScroll = 0;
|
||||
|
@ -6315,30 +6313,6 @@ nsWindow::InitMouseWheelScrollData()
|
|||
sNeedsToInitMouseWheelSettings = false;
|
||||
ResetRemainingWheelDelta();
|
||||
|
||||
if (!::SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0,
|
||||
&sMouseWheelScrollLines, 0)) {
|
||||
NS_WARNING("Failed to get SPI_GETWHEELSCROLLLINES");
|
||||
sMouseWheelScrollLines = 3;
|
||||
} else if (sMouseWheelScrollLines > WHEEL_DELTA) {
|
||||
// sMouseWheelScrollLines usually equals 3 or 0 (for no scrolling)
|
||||
// However, if sMouseWheelScrollLines > WHEEL_DELTA, we assume that
|
||||
// the mouse driver wants a page scroll. The docs state that
|
||||
// sMouseWheelScrollLines should explicitly equal WHEEL_PAGESCROLL, but
|
||||
// since some mouse drivers use an arbitrary large number instead,
|
||||
// we have to handle that as well.
|
||||
sMouseWheelScrollLines = WHEEL_PAGESCROLL;
|
||||
}
|
||||
|
||||
if (!::SystemParametersInfo(SPI_GETWHEELSCROLLCHARS, 0,
|
||||
&sMouseWheelScrollChars, 0)) {
|
||||
NS_ASSERTION(WinUtils::GetWindowsVersion() < WinUtils::VISTA_VERSION,
|
||||
"Failed to get SPI_GETWHEELSCROLLCHARS");
|
||||
sMouseWheelScrollChars = 1;
|
||||
} else if (sMouseWheelScrollChars > WHEEL_DELTA) {
|
||||
// See the comments for the case sMouseWheelScrollLines > WHEEL_DELTA.
|
||||
sMouseWheelScrollChars = WHEEL_PAGESCROLL;
|
||||
}
|
||||
|
||||
sEnablePixelScrolling =
|
||||
Preferences::GetBool("mousewheel.enable_pixel_scrolling", true);
|
||||
}
|
||||
|
@ -6367,10 +6341,12 @@ nsWindow::OnMouseWheelInternal(UINT aMessage, WPARAM aWParam, LPARAM aLParam,
|
|||
LRESULT *aRetValue)
|
||||
{
|
||||
InitMouseWheelScrollData();
|
||||
MouseScrollHandler::SystemSettings& systemSettings =
|
||||
MouseScrollHandler::GetInstance()->GetSystemSettings();
|
||||
systemSettings.Init();
|
||||
|
||||
bool isVertical = (aMessage == WM_MOUSEWHEEL);
|
||||
if ((isVertical && sMouseWheelScrollLines == 0) ||
|
||||
(!isVertical && sMouseWheelScrollChars == 0)) {
|
||||
if (systemSettings.GetScrollAmount(isVertical) == 0) {
|
||||
// XXX I think that we should dispatch mouse wheel events even if the
|
||||
// operation will not scroll because the wheel operation really happened
|
||||
// and web application may want to handle the event for non-scroll action.
|
||||
|
@ -6386,9 +6362,7 @@ nsWindow::OnMouseWheelInternal(UINT aMessage, WPARAM aWParam, LPARAM aLParam,
|
|||
return; // We cannot process this message
|
||||
}
|
||||
|
||||
bool isPageScroll =
|
||||
((isVertical && sMouseWheelScrollLines == WHEEL_PAGESCROLL) ||
|
||||
(!isVertical && sMouseWheelScrollChars == WHEEL_PAGESCROLL));
|
||||
bool isPageScroll = systemSettings.IsPageScroll(isVertical);
|
||||
|
||||
// Discard the remaining delta if current wheel message and last one are
|
||||
// received by different window or to scroll different direction or
|
||||
|
@ -6445,8 +6419,8 @@ nsWindow::OnMouseWheelInternal(UINT aMessage, WPARAM aWParam, LPARAM aLParam,
|
|||
PRInt32 actualScrollAction = nsQueryContentEvent::SCROLL_ACTION_NONE;
|
||||
PRInt32 pixelsPerUnit = 0;
|
||||
// the amount is the number of lines (or pages) per WHEEL_DELTA
|
||||
PRInt32 computedScrollAmount = isPageScroll ? 1 :
|
||||
(isVertical ? sMouseWheelScrollLines : sMouseWheelScrollChars);
|
||||
PRInt32 computedScrollAmount =
|
||||
isPageScroll ? 1 : systemSettings.GetScrollAmount(isVertical);
|
||||
|
||||
if (sEnablePixelScrolling) {
|
||||
nsMouseScrollEvent testEvent(true, NS_MOUSE_SCROLL, this);
|
||||
|
@ -6519,11 +6493,11 @@ nsWindow::OnMouseWheelInternal(UINT aMessage, WPARAM aWParam, LPARAM aLParam,
|
|||
double deltaPerUnit;
|
||||
if (isVertical) {
|
||||
scrollEvent.scrollFlags |= nsMouseScrollEvent::kIsVertical;
|
||||
deltaPerUnit = (double)WHEEL_DELTA / sMouseWheelScrollLines;
|
||||
} else {
|
||||
scrollEvent.scrollFlags |= nsMouseScrollEvent::kIsHorizontal;
|
||||
deltaPerUnit = (double)WHEEL_DELTA / sMouseWheelScrollChars;
|
||||
}
|
||||
deltaPerUnit =
|
||||
(double)WHEEL_DELTA / systemSettings.GetScrollAmount(isVertical);
|
||||
scrollEvent.delta =
|
||||
RoundDelta((double)nativeDeltaForScroll * orienter / deltaPerUnit);
|
||||
PRInt32 recomputedNativeDelta =
|
||||
|
|
|
@ -610,8 +610,6 @@ protected:
|
|||
|
||||
static bool sEnablePixelScrolling;
|
||||
static bool sNeedsToInitMouseWheelSettings;
|
||||
static ULONG sMouseWheelScrollLines;
|
||||
static ULONG sMouseWheelScrollChars;
|
||||
static void InitMouseWheelScrollData();
|
||||
|
||||
static HWND sLastMouseWheelWnd;
|
||||
|
|
Загрузка…
Ссылка в новой задаче