Bug 1355548 - Using cached perference values in WheelTransaction. r?masayuki
MozReview-Commit-ID: GpKgMpDwi3w
--- a/dom/events/EventStateManager.cpp
+++ b/dom/events/EventStateManager.cpp
@@ -326,16 +326,17 @@ EventStateManager::EventStateManager()
++sESMInstanceCount;
static bool sAddedPointerEventEnabled = false;
if (!sAddedPointerEventEnabled) {
Preferences::AddBoolVarCache(&sPointerEventEnabled,
"dom.w3c_pointer_events.enabled", false);
sAddedPointerEventEnabled = true;
}
+ WheelTransaction::InitializeStatics();
}
nsresult
EventStateManager::UpdateUserActivityTimer()
{
if (!gUserInteractionTimerCallback)
return NS_OK;
--- a/dom/events/WheelHandlingHelper.cpp
+++ b/dom/events/WheelHandlingHelper.cpp
@@ -274,17 +274,17 @@ WheelTransaction::Shutdown()
NS_IF_RELEASE(sTimer);
}
/* static */ void
WheelTransaction::OnFailToScrollTarget()
{
NS_PRECONDITION(sTargetFrame, "We don't have mouse scrolling transaction");
- if (Preferences::GetBool("test.mousescroll", false)) {
+ if (Prefs::sTestMouseScroll) {
// This event is used for automated tests, see bug 442774.
nsContentUtils::DispatchTrustedEvent(
sTargetFrame->GetContent()->OwnerDoc(),
sTargetFrame->GetContent(),
NS_LITERAL_STRING("MozMouseScrollFailed"),
true, true);
}
// The target frame might be destroyed in the event handler, at that time,
@@ -303,17 +303,17 @@ WheelTransaction::OnTimeout(nsITimer* aT
return;
}
// Store the sTargetFrame, the variable becomes null in EndTransaction.
nsIFrame* frame = sTargetFrame;
// We need to finish current transaction before DOM event firing. Because
// the next DOM event might create strange situation for us.
MayEndTransaction();
- if (Preferences::GetBool("test.mousescroll", false)) {
+ if (Prefs::sTestMouseScroll) {
// This event is used for automated tests, see bug 442774.
nsContentUtils::DispatchTrustedEvent(
frame->GetContent()->OwnerDoc(),
frame->GetContent(),
NS_LITERAL_STRING("MozMouseScrollTransactionTimeout"),
true, true);
}
}
@@ -340,28 +340,16 @@ WheelTransaction::SetTimeout()
WheelTransaction::GetScreenPoint(WidgetGUIEvent* aEvent)
{
NS_ASSERTION(aEvent, "aEvent is null");
NS_ASSERTION(aEvent->mWidget, "aEvent-mWidget is null");
return (aEvent->mRefPoint + aEvent->mWidget->WidgetToScreenOffset())
.ToUnknownPoint();
}
-/* static */ uint32_t
-WheelTransaction::GetTimeoutTime()
-{
- return Preferences::GetUint("mousewheel.transaction.timeout", 1500);
-}
-
-/* static */ uint32_t
-WheelTransaction::GetIgnoreMoveDelayTime()
-{
- return Preferences::GetUint("mousewheel.transaction.ignoremovedelay", 100);
-}
-
/* static */ DeltaValues
WheelTransaction::AccelerateWheelDelta(WidgetWheelEvent* aEvent,
bool aAllowScrollSpeedOverride)
{
DeltaValues result(aEvent);
// Don't accelerate the delta values if the event isn't line scrolling.
if (aEvent->mDeltaMode != nsIDOMWheelEvent::DOM_DELTA_LINE) {
@@ -386,28 +374,16 @@ WheelTransaction::AccelerateWheelDelta(W
}
/* static */ double
WheelTransaction::ComputeAcceleratedWheelDelta(double aDelta, int32_t aFactor)
{
return mozilla::ComputeAcceleratedWheelDelta(aDelta, sScrollSeriesCounter, aFactor);
}
-/* static */ int32_t
-WheelTransaction::GetAccelerationStart()
-{
- return Preferences::GetInt("mousewheel.acceleration.start", -1);
-}
-
-/* static */ int32_t
-WheelTransaction::GetAccelerationFactor()
-{
- return Preferences::GetInt("mousewheel.acceleration.factor", -1);
-}
-
/* static */ DeltaValues
WheelTransaction::OverrideSystemScrollSpeed(WidgetWheelEvent* aEvent)
{
MOZ_ASSERT(sTargetFrame, "We don't have mouse scrolling transaction");
MOZ_ASSERT(aEvent->mDeltaMode == nsIDOMWheelEvent::DOM_DELTA_LINE);
// If the event doesn't scroll to both X and Y, we don't need to do anything
// here.
@@ -544,9 +520,36 @@ ScrollbarsForWheel::DeactivateAllTempora
if (scrollbarMediator) {
scrollbarMediator->ScrollbarActivityStopped();
}
*scrollTarget = nullptr;
}
}
}
+/******************************************************************/
+/* mozilla::WheelTransaction */
+/******************************************************************/
+int32_t WheelTransaction::Prefs::sMouseWheelAccelerationStart = -1;
+int32_t WheelTransaction::Prefs::sMouseWheelAccelerationFactor = -1;
+uint32_t WheelTransaction::Prefs::sMouseWheelTransactionTimeout = 1500;
+uint32_t WheelTransaction::Prefs::sMouseWheelTransactionIgnoreMoveDelay = 100;
+bool WheelTransaction::Prefs::sTestMouseScroll = false;
+
+/* static */ void
+WheelTransaction::Prefs::InitializeStatics()
+{
+ static bool sIsInitialized = false;
+ if (sIsInitialized) {
+ Preferences::AddIntVarCache(&sMouseWheelAccelerationStart,
+ "mousewheel.acceleration.start", -1);
+ Preferences::AddIntVarCache(&sMouseWheelAccelerationFactor,
+ "mousewheel.acceleration.factor", -1);
+ Preferences::AddUintVarCache(&sMouseWheelTransactionTimeout,
+ "mousewheel.transaction.timeout", 1500);
+ Preferences::AddUintVarCache(&sMouseWheelTransactionIgnoreMoveDelay,
+ "mousewheel.transaction.ignoremovedelay", 100);
+ Preferences::AddBoolVarCache(&sTestMouseScroll, "test.mousescroll", false);
+ sIsInitialized = true;
+ }
+}
+
} // namespace mozilla
--- a/dom/events/WheelHandlingHelper.h
+++ b/dom/events/WheelHandlingHelper.h
@@ -138,45 +138,72 @@ public:
static bool WillHandleDefaultAction(WidgetWheelEvent* aWheelEvent,
nsIFrame* aTargetFrame)
{
AutoWeakFrame targetWeakFrame(aTargetFrame);
return WillHandleDefaultAction(aWheelEvent, targetWeakFrame);
}
static void OnEvent(WidgetEvent* aEvent);
static void Shutdown();
- static uint32_t GetTimeoutTime();
+ static uint32_t GetTimeoutTime()
+ {
+ return Prefs::sMouseWheelTransactionTimeout;
+ }
static void OwnScrollbars(bool aOwn);
static DeltaValues AccelerateWheelDelta(WidgetWheelEvent* aEvent,
bool aAllowScrollSpeedOverride);
+ static void InitializeStatics()
+ {
+ Prefs::InitializeStatics();
+ }
protected:
static void BeginTransaction(nsIFrame* aTargetFrame,
WidgetWheelEvent* aEvent);
// Be careful, UpdateTransaction may fire a DOM event, therefore, the target
// frame might be destroyed in the event handler.
static bool UpdateTransaction(WidgetWheelEvent* aEvent);
static void MayEndTransaction();
static nsIntPoint GetScreenPoint(WidgetGUIEvent* aEvent);
static void OnFailToScrollTarget();
static void OnTimeout(nsITimer* aTimer, void* aClosure);
static void SetTimeout();
- static uint32_t GetIgnoreMoveDelayTime();
- static int32_t GetAccelerationStart();
- static int32_t GetAccelerationFactor();
+ static uint32_t GetIgnoreMoveDelayTime()
+ {
+ return Prefs::sMouseWheelTransactionIgnoreMoveDelay;
+ }
+ static int32_t GetAccelerationStart()
+ {
+ return Prefs::sMouseWheelAccelerationStart;
+ }
+ static int32_t GetAccelerationFactor()
+ {
+ return Prefs::sMouseWheelAccelerationFactor;
+ }
static DeltaValues OverrideSystemScrollSpeed(WidgetWheelEvent* aEvent);
static double ComputeAcceleratedWheelDelta(double aDelta, int32_t aFactor);
static bool OutOfTime(uint32_t aBaseTime, uint32_t aThreshold);
static AutoWeakFrame sTargetFrame;
static uint32_t sTime; // in milliseconds
static uint32_t sMouseMoved; // in milliseconds
static nsITimer* sTimer;
static int32_t sScrollSeriesCounter;
+
+ class Prefs
+ {
+ public:
+ static void InitializeStatics();
+ static int32_t sMouseWheelAccelerationStart;
+ static int32_t sMouseWheelAccelerationFactor;
+ static uint32_t sMouseWheelTransactionTimeout;
+ static uint32_t sMouseWheelTransactionIgnoreMoveDelay;
+ static bool sTestMouseScroll;
+ };
static bool sOwnScrollbars;
};
} // namespace mozilla
#endif // mozilla_WheelHandlingHelper_h_