Bug 1936278 - Prevent search mode chiclet from being dismissed when clicking in page...
[gecko.git] / dom / ipc / CoalescedMouseData.cpp
blob5aa445d2e0a6169e57c44569974d557b3baf7064
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) {
21 if (IsEmpty()) {
22 mCoalescedInputEvent = MakeUnique<WidgetMouseEvent>(aEvent);
23 mGuid = aGuid;
24 mInputBlockId = aInputBlockId;
25 MOZ_ASSERT(!mCoalescedInputEvent->mCoalescedWidgetEvents);
26 } else {
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(
50 aEvent);
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(); }