Bug 1573968 - Remove WheelTransaction::Prefs. r=njn
authorKristen Wright <kwright@mozilla.com>
Wed, 14 Aug 2019 22:18:59 +0000
changeset 488134 77b5eec7b9e5b3f1fdf55bab886cc9391cd8a536
parent 488133 c60ee628dd0e2c7ff6d829c5536dc15332735286
child 488135 7710c9d9b6b0b2f8f51b0d3d4e9dea3753201b25
push id113900
push usercbrindusan@mozilla.com
push dateThu, 15 Aug 2019 09:53:50 +0000
treeherdermozilla-inbound@0db07ff50ab5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1573968
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1573968 - Remove WheelTransaction::Prefs. r=njn All of these prefs are already static prefs, so this removes the varcache pref definitions from WheelTransaction and replaces them with the existing static prefs. Differential Revision: https://phabricator.services.mozilla.com/D42040
dom/events/EventStateManager.cpp
dom/events/WheelHandlingHelper.cpp
dom/events/WheelHandlingHelper.h
modules/libpref/init/StaticPrefList.yaml
--- a/dom/events/EventStateManager.cpp
+++ b/dom/events/EventStateManager.cpp
@@ -26,16 +26,17 @@
 #include "mozilla/dom/MouseEventBinding.h"
 #include "mozilla/dom/BrowserChild.h"
 #include "mozilla/dom/BrowserParent.h"
 #include "mozilla/dom/UIEvent.h"
 #include "mozilla/dom/UIEventBinding.h"
 #include "mozilla/dom/WheelEventBinding.h"
 #include "mozilla/StaticPrefs_dom.h"
 #include "mozilla/StaticPrefs_layout.h"
+#include "mozilla/StaticPrefs_mousewheel.h"
 #include "mozilla/StaticPrefs_ui.h"
 #include "mozilla/StaticPrefs_zoom.h"
 
 #include "ContentEventHandler.h"
 #include "IMEContentObserver.h"
 #include "WheelHandlingHelper.h"
 #include "RemoteDragStartData.h"
 
@@ -246,17 +247,16 @@ EventStateManager::EventStateManager()
       mInTouchDrag(false),
       m_haveShutdown(false) {
   if (sESMInstanceCount == 0) {
     gUserInteractionTimerCallback = new UITimerCallback();
     if (gUserInteractionTimerCallback) NS_ADDREF(gUserInteractionTimerCallback);
     UpdateUserActivityTimer();
   }
   ++sESMInstanceCount;
-  WheelTransaction::InitializeStatics();
 }
 
 nsresult EventStateManager::UpdateUserActivityTimer() {
   if (!gUserInteractionTimerCallback) return NS_OK;
 
   if (!gUserInteractionTimer) {
     gUserInteractionTimer =
         NS_NewTimer(SystemGroup::EventTargetFor(TaskCategory::Other)).take();
@@ -5836,17 +5836,18 @@ void EventStateManager::ClearGlobalActiv
 void EventStateManager::DeltaAccumulator::InitLineOrPageDelta(
     nsIFrame* aTargetFrame, EventStateManager* aESM, WidgetWheelEvent* aEvent) {
   MOZ_ASSERT(aESM);
   MOZ_ASSERT(aEvent);
 
   // Reset if the previous wheel event is too old.
   if (!mLastTime.IsNull()) {
     TimeDuration duration = TimeStamp::Now() - mLastTime;
-    if (duration.ToMilliseconds() > WheelTransaction::GetTimeoutTime()) {
+    if (duration.ToMilliseconds() >
+        StaticPrefs::mousewheel_transaction_timeout()) {
       Reset();
     }
   }
   // If we have accumulated delta,  we may need to reset it.
   if (IsInTransaction()) {
     // If wheel event type is changed, reset the values.
     if (mHandlingDeltaMode != aEvent->mDeltaMode ||
         mIsNoLineOrPageDeltaDevice != aEvent->mIsNoLineOrPageDelta) {
--- a/dom/events/WheelHandlingHelper.cpp
+++ b/dom/events/WheelHandlingHelper.cpp
@@ -8,16 +8,18 @@
 
 #include <utility>  // for std::swap
 
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/EventStateManager.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/PresShell.h"
+#include "mozilla/StaticPrefs_mousewheel.h"
+#include "mozilla/StaticPrefs_test.h"
 #include "mozilla/dom/WheelEventBinding.h"
 #include "nsCOMPtr.h"
 #include "nsContentUtils.h"
 #include "nsIContent.h"
 #include "nsIContentInlines.h"
 #include "mozilla/dom/Document.h"
 #include "DocumentInlines.h"  // for Document and HTMLBodyElement
 #include "nsIScrollableFrame.h"
@@ -218,29 +220,30 @@ bool WheelTransaction::WillHandleDefault
 }
 
 /* static */
 void WheelTransaction::OnEvent(WidgetEvent* aEvent) {
   if (!sTargetFrame) {
     return;
   }
 
-  if (OutOfTime(sTime, GetTimeoutTime())) {
+  if (OutOfTime(sTime, StaticPrefs::mousewheel_transaction_timeout())) {
     // Even if the scroll event which is handled after timeout, but onTimeout
     // was not fired by timer, then the scroll event will scroll old frame,
     // therefore, we should call OnTimeout here and ensure to finish the old
     // transaction.
     OnTimeout(nullptr, nullptr);
     return;
   }
 
   switch (aEvent->mMessage) {
     case eWheel:
       if (sMouseMoved != 0 &&
-          OutOfTime(sMouseMoved, GetIgnoreMoveDelayTime())) {
+          OutOfTime(sMouseMoved,
+                    StaticPrefs::mousewheel_transaction_ignoremovedelay())) {
         // Terminate the current mousewheel transaction if the mouse moved more
         // than ignoremovedelay milliseconds ago
         EndTransaction();
       }
       return;
     case eMouseMove:
     case eDragOver: {
       WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent();
@@ -255,17 +258,19 @@ void WheelTransaction::OnEvent(WidgetEve
           EndTransaction();
           return;
         }
 
         // If the cursor is moving inside the frame, and it is less than
         // ignoremovedelay milliseconds since the last scroll operation, ignore
         // the mouse move; otherwise, record the current mouse move time to be
         // checked later
-        if (!sMouseMoved && OutOfTime(sTime, GetIgnoreMoveDelayTime())) {
+        if (!sMouseMoved &&
+            OutOfTime(sTime,
+                      StaticPrefs::mousewheel_transaction_ignoremovedelay())) {
           sMouseMoved = PR_IntervalToMilliseconds(PR_IntervalNow());
         }
       }
       return;
     }
     case eKeyPress:
     case eKeyUp:
     case eKeyDown:
@@ -285,17 +290,17 @@ void WheelTransaction::OnEvent(WidgetEve
 
 /* static */
 void WheelTransaction::Shutdown() { NS_IF_RELEASE(sTimer); }
 
 /* static */
 void WheelTransaction::OnFailToScrollTarget() {
   MOZ_ASSERT(sTargetFrame, "We don't have mouse scrolling transaction");
 
-  if (Prefs::sTestMouseScroll) {
+  if (StaticPrefs::test_mousescroll()) {
     // This event is used for automated tests, see bug 442774.
     nsContentUtils::DispatchTrustedEvent(
         sTargetFrame->GetContent()->OwnerDoc(), sTargetFrame->GetContent(),
         NS_LITERAL_STRING("MozMouseScrollFailed"), CanBubble::eYes,
         Cancelable::eYes);
   }
   // The target frame might be destroyed in the event handler, at that time,
   // we need to finish the current transaction
@@ -312,17 +317,17 @@ void WheelTransaction::OnTimeout(nsITime
     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 (Prefs::sTestMouseScroll) {
+  if (StaticPrefs::test_mousescroll()) {
     // This event is used for automated tests, see bug 442774.
     nsContentUtils::DispatchTrustedEvent(
         frame->GetContent()->OwnerDoc(), frame->GetContent(),
         NS_LITERAL_STRING("MozMouseScrollTransactionTimeout"), CanBubble::eYes,
         Cancelable::eYes);
   }
 }
 
@@ -331,18 +336,18 @@ void WheelTransaction::SetTimeout() {
   if (!sTimer) {
     sTimer = NS_NewTimer().take();
     if (!sTimer) {
       return;
     }
   }
   sTimer->Cancel();
   DebugOnly<nsresult> rv = sTimer->InitWithNamedFuncCallback(
-      OnTimeout, nullptr, GetTimeoutTime(), nsITimer::TYPE_ONE_SHOT,
-      "WheelTransaction::SetTimeout");
+      OnTimeout, nullptr, StaticPrefs::mousewheel_transaction_timeout(),
+      nsITimer::TYPE_ONE_SHOT, "WheelTransaction::SetTimeout");
   NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
                        "nsITimer::InitWithFuncCallback failed");
 }
 
 /* static */
 LayoutDeviceIntPoint WheelTransaction::GetScreenPoint(WidgetGUIEvent* aEvent) {
   NS_ASSERTION(aEvent, "aEvent is null");
   NS_ASSERTION(aEvent->mWidget, "aEvent-mWidget is null");
@@ -359,19 +364,19 @@ DeltaValues WheelTransaction::Accelerate
     return result;
   }
 
   if (aAllowScrollSpeedOverride) {
     result = OverrideSystemScrollSpeed(aEvent);
   }
 
   // Accelerate by the sScrollSeriesCounter
-  int32_t start = GetAccelerationStart();
+  int32_t start = StaticPrefs::mousewheel_acceleration_start();
   if (start >= 0 && sScrollSeriesCounter >= start) {
-    int32_t factor = GetAccelerationFactor();
+    int32_t factor = StaticPrefs::mousewheel_acceleration_factor();
     if (factor > 0) {
       result.deltaX = ComputeAcceleratedWheelDelta(result.deltaX, factor);
       result.deltaY = ComputeAcceleratedWheelDelta(result.deltaY, factor);
     }
   }
 
   return result;
 }
@@ -514,43 +519,16 @@ void ScrollbarsForWheel::DeactivateAllTe
         scrollbarMediator->ScrollbarActivityStopped();
       }
       *scrollTarget = nullptr;
     }
   }
 }
 
 /******************************************************************/
-/* mozilla::WheelTransaction::Prefs                               */
-/******************************************************************/
-
-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;
-  }
-}
-
-/******************************************************************/
 /* mozilla::WheelDeltaHorizontalizer                              */
 /******************************************************************/
 
 void WheelDeltaHorizontalizer::Horizontalize() {
   MOZ_ASSERT(!mWheelEvent.mDeltaValuesHorizontalizedForDefaultHandler,
              "Wheel delta values in one wheel scroll event are being adjusted "
              "a second time");
 
--- a/dom/events/WheelHandlingHelper.h
+++ b/dom/events/WheelHandlingHelper.h
@@ -130,67 +130,44 @@ class WheelTransaction {
                                       AutoWeakFrame& aTargetWeakFrame);
   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() {
-    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,
                                const WidgetWheelEvent* aEvent);
   // Be careful, UpdateTransaction may fire a DOM event, therefore, the target
   // frame might be destroyed in the event handler.
   static bool UpdateTransaction(const WidgetWheelEvent* aEvent);
   static void MayEndTransaction();
 
   static LayoutDeviceIntPoint GetScreenPoint(WidgetGUIEvent* aEvent);
   static void OnFailToScrollTarget();
   static void OnTimeout(nsITimer* aTimer, void* aClosure);
   static void SetTimeout();
-  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;
   static bool sOwnScrollbars;
-
-  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;
-  };
 };
 
 // For some kinds of scrollings, the delta values of WidgetWheelEvent are
 // possbile to be adjusted. For example, the user has configured the pref to let
 // [vertical wheel + Shift key] to perform horizontal scrolling instead of
 // vertical scrolling.
 // The values in this enumeration list all kinds of scrollings whose delta
 // values are possible to be adjusted.
--- a/modules/libpref/init/StaticPrefList.yaml
+++ b/modules/libpref/init/StaticPrefList.yaml
@@ -5682,22 +5682,22 @@
 
 - name: mousewheel.system_scroll_override_on_root_content.vertical.factor
   type: RelaxedAtomicInt32
   value: 0
   mirror: always
 
 - name: mousewheel.transaction.ignoremovedelay
   type: RelaxedAtomicInt32
-  value: (int32_t)100
+  value: 100
   mirror: always
 
 - name: mousewheel.transaction.timeout
   type: RelaxedAtomicInt32
-  value: (int32_t)1500
+  value: 1500
   mirror: always
 
 #---------------------------------------------------------------------------
 # Prefs starting with "network."
 #---------------------------------------------------------------------------
 
 # Sub-resources HTTP-authentication:
 #   0 - don't allow sub-resources to open HTTP authentication credentials