1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "base/basictypes.h"
8 #include "CoalescedMouseData.h"
9 #include "BrowserChild.h"
11 #include "mozilla/PresShell.h"
12 #include "mozilla/StaticPrefs_dom.h"
13 #include "nsRefreshDriver.h"
15 using namespace mozilla
;
16 using namespace mozilla::dom
;
18 void CoalescedMouseData::Coalesce(const WidgetMouseEvent
& aEvent
,
19 const ScrollableLayerGuid
& aGuid
,
20 const uint64_t& aInputBlockId
) {
22 mCoalescedInputEvent
= MakeUnique
<WidgetMouseEvent
>(aEvent
);
24 mInputBlockId
= aInputBlockId
;
25 MOZ_ASSERT(!mCoalescedInputEvent
->mCoalescedWidgetEvents
);
27 MOZ_ASSERT(mGuid
== aGuid
);
28 MOZ_ASSERT(mInputBlockId
== aInputBlockId
);
29 MOZ_ASSERT(mCoalescedInputEvent
->mModifiers
== aEvent
.mModifiers
);
30 MOZ_ASSERT(mCoalescedInputEvent
->mReason
== aEvent
.mReason
);
31 MOZ_ASSERT(mCoalescedInputEvent
->mInputSource
== aEvent
.mInputSource
);
32 MOZ_ASSERT(mCoalescedInputEvent
->mButton
== aEvent
.mButton
);
33 MOZ_ASSERT(mCoalescedInputEvent
->mButtons
== aEvent
.mButtons
);
34 mCoalescedInputEvent
->mTimeStamp
= aEvent
.mTimeStamp
;
35 mCoalescedInputEvent
->mRefPoint
= aEvent
.mRefPoint
;
36 mCoalescedInputEvent
->mPressure
= aEvent
.mPressure
;
37 mCoalescedInputEvent
->AssignPointerHelperData(aEvent
);
40 if (aEvent
.mMessage
== eMouseMove
) {
41 // PointerEvent::getCoalescedEvents is only applied to pointermove events.
42 if (!mCoalescedInputEvent
->mCoalescedWidgetEvents
) {
43 mCoalescedInputEvent
->mCoalescedWidgetEvents
=
44 new WidgetPointerEventHolder();
46 // Append current event in mCoalescedWidgetEvents. We use them to generate
47 // DOM events when content calls PointerEvent::getCoalescedEvents.
48 WidgetPointerEvent
* event
=
49 mCoalescedInputEvent
->mCoalescedWidgetEvents
->mEvents
.AppendElement(
52 event
->mMessage
= ePointerMove
;
53 event
->mFlags
.mBubbles
= false;
54 event
->mFlags
.mCancelable
= false;
58 bool CoalescedMouseData::CanCoalesce(const WidgetMouseEvent
& aEvent
,
59 const ScrollableLayerGuid
& aGuid
,
60 const uint64_t& aInputBlockId
) {
61 MOZ_ASSERT(aEvent
.mMessage
== eMouseMove
);
62 return !mCoalescedInputEvent
||
63 (!mCoalescedInputEvent
->mFlags
.mIsSynthesizedForTests
&&
64 !aEvent
.mFlags
.mIsSynthesizedForTests
&&
65 mCoalescedInputEvent
->mModifiers
== aEvent
.mModifiers
&&
66 mCoalescedInputEvent
->mInputSource
== aEvent
.mInputSource
&&
67 mCoalescedInputEvent
->pointerId
== aEvent
.pointerId
&&
68 mCoalescedInputEvent
->mButton
== aEvent
.mButton
&&
69 mCoalescedInputEvent
->mButtons
== aEvent
.mButtons
&& mGuid
== aGuid
&&
70 mInputBlockId
== aInputBlockId
);
73 CoalescedMouseMoveFlusher::CoalescedMouseMoveFlusher(
74 BrowserChild
* aBrowserChild
)
75 : CoalescedInputFlusher(aBrowserChild
) {}
77 void CoalescedMouseMoveFlusher::WillRefresh(mozilla::TimeStamp aTime
) {
78 MOZ_ASSERT(mRefreshDriver
);
79 mBrowserChild
->FlushAllCoalescedMouseData();
80 mBrowserChild
->ProcessPendingCoalescedMouseDataAndDispatchEvents();
83 CoalescedMouseMoveFlusher::~CoalescedMouseMoveFlusher() { RemoveObserver(); }