Browse files

Bug 829952 Reimplement system scroll speed override stuff for D3E Whe…

…elEvent feedback=avih, r=smaug+roc, sr=roc
  • Loading branch information...
1 parent 0fa494d commit b15ae9db9f610412547120d89509ea7d0c2a1d9e @masayuki-nakano masayuki-nakano committed Mar 15, 2013
View
39 content/events/src/nsEventStateManager.cpp
@@ -646,47 +646,30 @@ nsMouseWheelTransaction::OverrideSystemScrollSpeed(widget::WheelEvent* aEvent)
MOZ_ASSERT(sTargetFrame, "We don't have mouse scrolling transaction");
MOZ_ASSERT(aEvent->deltaMode == nsIDOMWheelEvent::DOM_DELTA_LINE);
- DeltaValues result(aEvent);
-
// If the event doesn't scroll to both X and Y, we don't need to do anything
- // here. And also, if the event indicates the device supports high
- // resolution scroll, we shouldn't need to override it.
- if ((!aEvent->lineOrPageDeltaX && !aEvent->lineOrPageDeltaY) ||
- (static_cast<double>(aEvent->lineOrPageDeltaX) != aEvent->deltaX) ||
- (static_cast<double>(aEvent->lineOrPageDeltaY) != aEvent->deltaY)) {
- return result;
+ // here.
+ if (!aEvent->deltaX && !aEvent->deltaY) {
+ return DeltaValues(aEvent);
}
// We shouldn't override the scrolling speed on non root scroll frame.
if (sTargetFrame !=
sTargetFrame->PresContext()->PresShell()->GetRootScrollFrame()) {
- return result;
+ return DeltaValues(aEvent);
}
// Compute the overridden speed to nsIWidget. The widget can check the
// conditions (e.g., checking the prefs, and also whether the user customized
// the system settings of the mouse wheel scrolling or not), and can limit
// the speed for preventing the unexpected high speed scrolling.
nsCOMPtr<nsIWidget> widget(sTargetFrame->GetNearestWidget());
- NS_ENSURE_TRUE(widget, result);
- int32_t overriddenDeltaX = 0, overriddenDeltaY = 0;
- if (aEvent->lineOrPageDeltaX) {
- nsresult rv =
- widget->OverrideSystemMouseScrollSpeed(aEvent->lineOrPageDeltaX,
- true, overriddenDeltaX);
- if (NS_FAILED(rv)) {
- return result;
- }
- }
- if (aEvent->lineOrPageDeltaY) {
- nsresult rv =
- widget->OverrideSystemMouseScrollSpeed(aEvent->lineOrPageDeltaY,
- false, overriddenDeltaY);
- if (NS_FAILED(rv)) {
- return result;
- }
- }
- return DeltaValues(overriddenDeltaX, overriddenDeltaY);
+ NS_ENSURE_TRUE(widget, DeltaValues(aEvent));
+ DeltaValues overriddenDeltaValues(0.0, 0.0);
+ nsresult rv =
+ widget->OverrideSystemMouseScrollSpeed(aEvent->deltaX, aEvent->deltaY,
+ overriddenDeltaValues.deltaX,
+ overriddenDeltaValues.deltaY);
+ return NS_FAILED(rv) ? DeltaValues(aEvent) : overriddenDeltaValues;
}
/******************************************************************/
View
27 widget/nsIWidget.h
@@ -92,8 +92,8 @@ typedef nsEventStatus (* EVENT_CALLBACK)(nsGUIEvent *event);
#endif
#define NS_IWIDGET_IID \
- { 0x48568C1E, 0xAF56, 0x4F73, \
- { 0x94, 0x6D, 0xAA, 0x43, 0xD8, 0x96, 0x78, 0x6B } }
+ { 0xdaac8d94, 0x14f3, 0x4bc4, \
+ { 0xa8, 0xc, 0xf0, 0xe6, 0x46, 0x1e, 0xad, 0x40 } }
/*
* Window shadow styles
@@ -1553,16 +1553,19 @@ class nsIWidget : public nsISupports {
* actions. And also this isn't called when the user doesn't use the
* system wheel speed settings.
*
- * @param aOriginalDelta The delta value of the current mouse wheel
- * scrolling event.
- * @param aIsHorizontal If TRUE, the scrolling direction is horizontal.
- * Otherwise, it's vertical.
- * @param aOverriddenDelta The overridden mouse scrolling speed. This value
- * may be same as aOriginalDelta.
- */
- NS_IMETHOD OverrideSystemMouseScrollSpeed(int32_t aOriginalDelta,
- bool aIsHorizontal,
- int32_t &aOverriddenDelta) = 0;
+ * @param aOriginalDeltaX The X delta value of the current mouse wheel
+ * scrolling event.
+ * @param aOriginalDeltaX The Y delta value of the current mouse wheel
+ * scrolling event.
+ * @param aOverriddenDeltaX The overridden mouse scrolling speed along X
+ * axis. This value may be same as aOriginalDeltaX.
+ * @param aOverriddenDeltaY The overridden mouse scrolling speed along Y
+ * axis. This value may be same as aOriginalDeltaY.
+ */
+ NS_IMETHOD OverrideSystemMouseScrollSpeed(double aOriginalDeltaX,
+ double aOriginalDeltaY,
+ double& aOverriddenDeltaX,
+ double& aOverriddenDeltaY) = 0;
/**
* Return true if this process shouldn't use platform widgets, and
View
44 widget/windows/nsWindow.cpp
@@ -3426,26 +3426,32 @@ nsWindow::OnDefaultButtonLoaded(const nsIntRect &aButtonRect)
}
NS_IMETHODIMP
-nsWindow::OverrideSystemMouseScrollSpeed(int32_t aOriginalDelta,
- bool aIsHorizontal,
- int32_t &aOverriddenDelta)
+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;
- int32_t absOriginDelta = DeprecatedAbs(aOriginalDelta);
+ double absOriginDeltaX = Abs(aOriginalDeltaX);
+ double absOriginDeltaY = Abs(aOriginalDeltaY);
// Compute the simple overridden speed.
- int32_t absComputedOverriddenDelta;
+ double absComputedOverriddenDeltaX, absComputedOverriddenDeltaY;
nsresult rv =
- nsBaseWidget::OverrideSystemMouseScrollSpeed(absOriginDelta, aIsHorizontal,
- absComputedOverriddenDelta);
+ nsBaseWidget::OverrideSystemMouseScrollSpeed(absOriginDeltaX,
+ absOriginDeltaY,
+ absComputedOverriddenDeltaX,
+ absComputedOverriddenDeltaY);
NS_ENSURE_SUCCESS(rv, rv);
- aOverriddenDelta = aOriginalDelta;
+ aOverriddenDeltaX = aOriginalDeltaX;
+ aOverriddenDeltaY = aOriginalDeltaY;
- if (absComputedOverriddenDelta == absOriginDelta) {
+ if (absComputedOverriddenDeltaX == absOriginDeltaX &&
+ absComputedOverriddenDeltaY == absOriginDeltaY) {
// We don't override now.
return NS_OK;
}
@@ -3479,23 +3485,29 @@ nsWindow::OverrideSystemMouseScrollSpeed(int32_t aOriginalDelta,
// driver might accelerate the scrolling speed already. If so, we shouldn't
// override the scrolling speed for preventing the unexpected high speed
// scrolling.
- int32_t absDeltaLimit;
+ double absDeltaLimitX, absDeltaLimitY;
rv =
nsBaseWidget::OverrideSystemMouseScrollSpeed(kSystemDefaultScrollingSpeed,
- aIsHorizontal, absDeltaLimit);
+ 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 (absDeltaLimit <= absOriginDelta) {
+ if (absDeltaLimitX <= absOriginDeltaX || absDeltaLimitY <= absOriginDeltaY) {
return NS_OK;
}
- absComputedOverriddenDelta =
- std::min(absComputedOverriddenDelta, absDeltaLimit);
+ aOverriddenDeltaX = std::min(absComputedOverriddenDeltaX, absDeltaLimitX);
+ aOverriddenDeltaY = std::min(absComputedOverriddenDeltaY, absDeltaLimitY);
- aOverriddenDelta = (aOriginalDelta > 0) ? absComputedOverriddenDelta :
- -absComputedOverriddenDelta;
+ if (aOriginalDeltaX < 0) {
+ aOverriddenDeltaX *= -1;
+ }
+ if (aOriginalDeltaY < 0) {
+ aOverriddenDeltaY *= -1;
+ }
return NS_OK;
}
View
5 widget/windows/nsWindow.h
@@ -142,7 +142,10 @@ class nsWindow : public nsWindowBase
bool* aAllowRetaining = nullptr);
gfxASurface *GetThebesSurface();
NS_IMETHOD OnDefaultButtonLoaded(const nsIntRect &aButtonRect);
- NS_IMETHOD OverrideSystemMouseScrollSpeed(int32_t aOriginalDelta, bool aIsHorizontal, int32_t &aOverriddenDelta);
+ NS_IMETHOD OverrideSystemMouseScrollSpeed(double aOriginalDeltaX,
+ double aOriginalDeltaY,
+ double& aOverriddenDeltaX,
+ double& aOverriddenDeltaY);
virtual nsresult SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout,
int32_t aNativeKeyCode,
View
55 widget/xpwidgets/nsBaseWidget.cpp
@@ -1198,36 +1198,45 @@ NS_METHOD nsBaseWidget::UnregisterTouchWindow()
}
NS_IMETHODIMP
-nsBaseWidget::OverrideSystemMouseScrollSpeed(int32_t aOriginalDelta,
- bool aIsHorizontal,
- int32_t &aOverriddenDelta)
-{
- aOverriddenDelta = aOriginalDelta;
+nsBaseWidget::OverrideSystemMouseScrollSpeed(double aOriginalDeltaX,
+ double aOriginalDeltaY,
+ double& aOverriddenDeltaX,
+ double& aOverriddenDeltaY)
+{
+ aOverriddenDeltaX = aOriginalDeltaX;
+ aOverriddenDeltaY = aOriginalDeltaY;
+
+ static bool sInitialized = false;
+ static bool sIsOverrideEnabled = false;
+ static int32_t sIntFactorX = 0;
+ static int32_t sIntFactorY = 0;
+
+ if (!sInitialized) {
+ Preferences::AddBoolVarCache(&sIsOverrideEnabled,
+ "mousewheel.system_scroll_override_on_root_content.enabled", false);
+ Preferences::AddIntVarCache(&sIntFactorX,
+ "mousewheel.system_scroll_override_on_root_content.horizontal.factor", 0);
+ Preferences::AddIntVarCache(&sIntFactorY,
+ "mousewheel.system_scroll_override_on_root_content.vertical.factor", 0);
+ sIntFactorX = std::max(sIntFactorX, 0);
+ sIntFactorY = std::max(sIntFactorY, 0);
+ sInitialized = true;
+ }
- const char* kPrefNameOverrideEnabled =
- "mousewheel.system_scroll_override_on_root_content.enabled";
- bool isOverrideEnabled =
- Preferences::GetBool(kPrefNameOverrideEnabled, false);
- if (!isOverrideEnabled) {
+ if (!sIsOverrideEnabled) {
return NS_OK;
}
- nsAutoCString factorPrefName(
- "mousewheel.system_scroll_override_on_root_content.");
- if (aIsHorizontal) {
- factorPrefName.AppendLiteral("horizontal.");
- } else {
- factorPrefName.AppendLiteral("vertical.");
- }
- factorPrefName.AppendLiteral("factor");
- int32_t iFactor = Preferences::GetInt(factorPrefName.get(), 0);
// The pref value must be larger than 100, otherwise, we don't override the
// delta value.
- if (iFactor <= 100) {
- return NS_OK;
+ if (sIntFactorX > 100) {
+ double factor = static_cast<double>(sIntFactorX) / 100;
+ aOverriddenDeltaX *= factor;
+ }
+ if (sIntFactorY > 100) {
+ double factor = static_cast<double>(sIntFactorY) / 100;
+ aOverriddenDeltaY *= factor;
}
- double factor = (double)iFactor / 100;
- aOverriddenDelta = int32_t(NS_round((double)aOriginalDelta * factor));
return NS_OK;
}
View
5 widget/xpwidgets/nsBaseWidget.h
@@ -148,7 +148,10 @@ class nsBaseWidget : public nsIWidget
NS_IMETHOD NotifyIMEOfTextChange(uint32_t aStart, uint32_t aOldEnd, uint32_t aNewEnd) MOZ_OVERRIDE { return NS_ERROR_NOT_IMPLEMENTED; }
virtual nsIMEUpdatePreference GetIMEUpdatePreference() { return nsIMEUpdatePreference(false, false); }
NS_IMETHOD OnDefaultButtonLoaded(const nsIntRect &aButtonRect) { return NS_ERROR_NOT_IMPLEMENTED; }
- NS_IMETHOD OverrideSystemMouseScrollSpeed(int32_t aOriginalDelta, bool aIsHorizontal, int32_t &aOverriddenDelta);
+ NS_IMETHOD OverrideSystemMouseScrollSpeed(double aOriginalDeltaX,
+ double aOriginalDeltaY,
+ double& aOverriddenDeltaX,
+ double& aOverriddenDeltaY);
virtual already_AddRefed<nsIWidget>
CreateChild(const nsIntRect &aRect,
nsDeviceContext *aContext,

0 comments on commit b15ae9d

Please sign in to comment.