Bug 1361067 Part1: Refactor coalescing mouse wheel events. r=smaug.
authorStone Shih <sshih@mozilla.com>
Sun, 13 Aug 2017 14:08:48 +0800
changeset 427937 1edccf6d5a8a2eb9a71be9365ce405b6065be587
parent 427936 aea34f7567218bf1c372dd18e0d04494dd165125
child 427938 64edaaccec973cd3b0d2aeea1f565d65e8614ea3
push id1567
push userjlorenzo@mozilla.com
push dateThu, 02 Nov 2017 12:36:05 +0000
treeherdermozilla-release@e512c14a0406 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1361067
milestone57.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 1361067 Part1: Refactor coalescing mouse wheel events. r=smaug. MozReview-Commit-ID: 3NJJ77zAxNJ
dom/ipc/CoalescedInputData.h
dom/ipc/CoalescedWheelData.cpp
dom/ipc/CoalescedWheelData.h
dom/ipc/TabChild.cpp
dom/ipc/moz.build
new file mode 100644
--- /dev/null
+++ b/dom/ipc/CoalescedInputData.h
@@ -0,0 +1,65 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_dom_CoalescedInputData_h
+#define mozilla_dom_CoalescedInputData_h
+
+#include "mozilla/UniquePtr.h"
+#include "FrameMetrics.h"
+
+namespace mozilla {
+namespace dom {
+
+template<class InputEventType>
+class CoalescedInputData
+{
+protected:
+  typedef mozilla::layers::ScrollableLayerGuid ScrollableLayerGuid;
+
+  UniquePtr<InputEventType> mCoalescedInputEvent;
+  ScrollableLayerGuid mGuid;
+  uint64_t mInputBlockId;
+
+public:
+  CoalescedInputData()
+    : mInputBlockId(0)
+  {
+  }
+
+  void Reset()
+  {
+    mCoalescedInputEvent = nullptr;
+  }
+
+  bool IsEmpty()
+  {
+    return !mCoalescedInputEvent;
+  }
+
+  bool CanCoalesce(const InputEventType& aEvent,
+                   const ScrollableLayerGuid& aGuid,
+                   const uint64_t& aInputBlockId);
+
+  const InputEventType* GetCoalescedEvent()
+  {
+    return mCoalescedInputEvent.get();
+  }
+
+  ScrollableLayerGuid GetScrollableLayerGuid()
+  {
+    return mGuid;
+  }
+
+  uint64_t GetInputBlockId()
+  {
+    return mInputBlockId;
+  }
+};
+
+} // namespace dom
+} // namespace mozilla
+
+#endif // mozilla_dom_CoalescedInputData_h
--- a/dom/ipc/CoalescedWheelData.cpp
+++ b/dom/ipc/CoalescedWheelData.cpp
@@ -1,52 +1,51 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 #include "base/basictypes.h"
 
 #include "CoalescedWheelData.h"
-#include "FrameMetrics.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 void
 CoalescedWheelData::Coalesce(const WidgetWheelEvent& aEvent,
                              const ScrollableLayerGuid& aGuid,
                              const uint64_t& aInputBlockId)
 {
   if (IsEmpty()) {
-    mCoalescedWheelEvent = MakeUnique<WidgetWheelEvent>(aEvent);
+    mCoalescedInputEvent = MakeUnique<WidgetWheelEvent>(aEvent);
     mGuid = aGuid;
     mInputBlockId = aInputBlockId;
   } else {
     MOZ_ASSERT(mGuid == aGuid);
     MOZ_ASSERT(mInputBlockId == aInputBlockId);
-    MOZ_ASSERT(mCoalescedWheelEvent->mModifiers == aEvent.mModifiers);
-    MOZ_ASSERT(mCoalescedWheelEvent->mDeltaMode == aEvent.mDeltaMode);
-    MOZ_ASSERT(mCoalescedWheelEvent->mCanTriggerSwipe ==
+    MOZ_ASSERT(mCoalescedInputEvent->mModifiers == aEvent.mModifiers);
+    MOZ_ASSERT(mCoalescedInputEvent->mDeltaMode == aEvent.mDeltaMode);
+    MOZ_ASSERT(mCoalescedInputEvent->mCanTriggerSwipe ==
                aEvent.mCanTriggerSwipe);
-    mCoalescedWheelEvent->mDeltaX += aEvent.mDeltaX;
-    mCoalescedWheelEvent->mDeltaY += aEvent.mDeltaY;
-    mCoalescedWheelEvent->mDeltaZ += aEvent.mDeltaZ;
-    mCoalescedWheelEvent->mLineOrPageDeltaX += aEvent.mLineOrPageDeltaX;
-    mCoalescedWheelEvent->mLineOrPageDeltaY += aEvent.mLineOrPageDeltaY;
-    mCoalescedWheelEvent->mTimeStamp = aEvent.mTimeStamp;
+    mCoalescedInputEvent->mDeltaX += aEvent.mDeltaX;
+    mCoalescedInputEvent->mDeltaY += aEvent.mDeltaY;
+    mCoalescedInputEvent->mDeltaZ += aEvent.mDeltaZ;
+    mCoalescedInputEvent->mLineOrPageDeltaX += aEvent.mLineOrPageDeltaX;
+    mCoalescedInputEvent->mLineOrPageDeltaY += aEvent.mLineOrPageDeltaY;
+    mCoalescedInputEvent->mTimeStamp = aEvent.mTimeStamp;
   }
 }
 
 bool
 CoalescedWheelData::CanCoalesce(const WidgetWheelEvent& aEvent,
                                 const ScrollableLayerGuid& aGuid,
                                 const uint64_t& aInputBlockId)
 {
   MOZ_ASSERT(!IsEmpty());
-  return !mCoalescedWheelEvent ||
-         (mCoalescedWheelEvent->mRefPoint == aEvent.mRefPoint &&
-          mCoalescedWheelEvent->mModifiers == aEvent.mModifiers &&
-          mCoalescedWheelEvent->mDeltaMode == aEvent.mDeltaMode &&
-          mCoalescedWheelEvent->mCanTriggerSwipe == aEvent.mCanTriggerSwipe &&
+  return !mCoalescedInputEvent ||
+         (mCoalescedInputEvent->mRefPoint == aEvent.mRefPoint &&
+          mCoalescedInputEvent->mModifiers == aEvent.mModifiers &&
+          mCoalescedInputEvent->mDeltaMode == aEvent.mDeltaMode &&
+          mCoalescedInputEvent->mCanTriggerSwipe == aEvent.mCanTriggerSwipe &&
           mGuid == aGuid &&
           mInputBlockId == aInputBlockId);
 }
--- a/dom/ipc/CoalescedWheelData.h
+++ b/dom/ipc/CoalescedWheelData.h
@@ -2,66 +2,30 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_CoalescedWheelData_h
 #define mozilla_dom_CoalescedWheelData_h
 
+#include "CoalescedInputData.h"
 #include "mozilla/MouseEvents.h"
-#include "mozilla/UniquePtr.h"
 
 namespace mozilla {
 namespace dom {
 
-class CoalescedWheelData final
+class CoalescedWheelData final : public CoalescedInputData<WidgetWheelEvent>
 {
-protected:
-  typedef mozilla::layers::ScrollableLayerGuid ScrollableLayerGuid;
-
 public:
-  UniquePtr<WidgetWheelEvent> mCoalescedWheelEvent;
-  ScrollableLayerGuid mGuid;
-  uint64_t mInputBlockId;
-
-  CoalescedWheelData()
-    : mInputBlockId(0)
-  {
-  }
-
   void Coalesce(const WidgetWheelEvent& aEvent,
                 const ScrollableLayerGuid& aGuid,
                 const uint64_t& aInputBlockId);
-  void Reset()
-  {
-    mCoalescedWheelEvent = nullptr;
-  }
-
-  bool IsEmpty()
-  {
-    return !mCoalescedWheelEvent;
-  }
 
   bool CanCoalesce(const WidgetWheelEvent& aEvent,
                    const ScrollableLayerGuid& aGuid,
                    const uint64_t& aInputBlockId);
-
-  const WidgetWheelEvent* GetCoalescedWheelEvent()
-  {
-    return mCoalescedWheelEvent.get();
-  }
-
-  ScrollableLayerGuid GetScrollableLayerGuid()
-  {
-    return mGuid;
-  }
-
-  uint64_t GetInputBlockId()
-  {
-    return mInputBlockId;
-  }
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_CoalescedWheelData_h
--- a/dom/ipc/TabChild.cpp
+++ b/dom/ipc/TabChild.cpp
@@ -1675,17 +1675,17 @@ TabChild::DispatchWidgetEventViaAPZ(Widg
 
 void
 TabChild::MaybeDispatchCoalescedWheelEvent()
 {
   if (mCoalescedWheelData.IsEmpty()) {
     return;
   }
   const WidgetWheelEvent* wheelEvent =
-    mCoalescedWheelData.GetCoalescedWheelEvent();
+    mCoalescedWheelData.GetCoalescedEvent();
   MOZ_ASSERT(wheelEvent);
   DispatchWheelEvent(*wheelEvent,
                      mCoalescedWheelData.GetScrollableLayerGuid(),
                      mCoalescedWheelData.GetInputBlockId());
   mCoalescedWheelData.Reset();
 }
 
 void
--- a/dom/ipc/moz.build
+++ b/dom/ipc/moz.build
@@ -14,16 +14,17 @@ XPIDL_SOURCES += [
 XPIDL_MODULE = 'dom'
 
 EXPORTS.mozilla.dom.ipc += [
     'IdType.h',
     'StructuredCloneData.h',
 ]
 
 EXPORTS.mozilla.dom += [
+    'CoalescedInputData.h',
     'CoalescedWheelData.h',
     'ContentBridgeChild.h',
     'ContentBridgeParent.h',
     'ContentChild.h',
     'ContentParent.h',
     'ContentPrefs.h',
     'ContentProcess.h',
     'ContentProcessManager.h',