Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/ipc/CoalescedMouseData.cpp
Line
Count
Source (jump to first uncovered line)
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"
7
8
#include "CoalescedMouseData.h"
9
#include "TabChild.h"
10
11
using namespace mozilla;
12
using namespace mozilla::dom;
13
14
void
15
CoalescedMouseData::Coalesce(const WidgetMouseEvent& aEvent,
16
                             const ScrollableLayerGuid& aGuid,
17
                             const uint64_t& aInputBlockId)
18
0
{
19
0
  if (IsEmpty()) {
20
0
    mCoalescedInputEvent = MakeUnique<WidgetMouseEvent>(aEvent);
21
0
    mGuid = aGuid;
22
0
    mInputBlockId = aInputBlockId;
23
0
    MOZ_ASSERT(!mCoalescedInputEvent->mCoalescedWidgetEvents);
24
0
  } else {
25
0
    MOZ_ASSERT(mGuid == aGuid);
26
0
    MOZ_ASSERT(mInputBlockId == aInputBlockId);
27
0
    MOZ_ASSERT(mCoalescedInputEvent->mModifiers == aEvent.mModifiers);
28
0
    MOZ_ASSERT(mCoalescedInputEvent->mReason == aEvent.mReason);
29
0
    MOZ_ASSERT(mCoalescedInputEvent->inputSource == aEvent.inputSource);
30
0
    MOZ_ASSERT(mCoalescedInputEvent->button == aEvent.button);
31
0
    MOZ_ASSERT(mCoalescedInputEvent->buttons == aEvent.buttons);
32
0
    mCoalescedInputEvent->mTimeStamp = aEvent.mTimeStamp;
33
0
    mCoalescedInputEvent->mRefPoint = aEvent.mRefPoint;
34
0
    mCoalescedInputEvent->pressure = aEvent.pressure;
35
0
    mCoalescedInputEvent->AssignPointerHelperData(aEvent);
36
0
  }
37
0
38
0
  if (aEvent.mMessage == eMouseMove &&
39
0
      PointerEventHandler::IsPointerEventEnabled()) {
40
0
    // PointerEvent::getCoalescedEvents is only applied to pointermove events.
41
0
    if (!mCoalescedInputEvent->mCoalescedWidgetEvents) {
42
0
      mCoalescedInputEvent->mCoalescedWidgetEvents =
43
0
        new WidgetPointerEventHolder();
44
0
    }
45
0
    // Append current event in mCoalescedWidgetEvents. We use them to generate
46
0
    // DOM events when content calls PointerEvent::getCoalescedEvents.
47
0
    WidgetPointerEvent* event = mCoalescedInputEvent->mCoalescedWidgetEvents
48
0
                                  ->mEvents.AppendElement(aEvent);
49
0
50
0
    event->mFlags.mBubbles = false;
51
0
    event->mFlags.mCancelable = false;
52
0
  }
53
0
}
54
55
bool
56
CoalescedMouseData::CanCoalesce(const WidgetMouseEvent& aEvent,
57
                             const ScrollableLayerGuid& aGuid,
58
                             const uint64_t& aInputBlockId)
59
0
{
60
0
  MOZ_ASSERT(aEvent.mMessage == eMouseMove);
61
0
  return !mCoalescedInputEvent ||
62
0
         (mCoalescedInputEvent->mModifiers == aEvent.mModifiers &&
63
0
          mCoalescedInputEvent->inputSource == aEvent.inputSource &&
64
0
          mCoalescedInputEvent->pointerId == aEvent.pointerId &&
65
0
          mCoalescedInputEvent->button == aEvent.button &&
66
0
          mCoalescedInputEvent->buttons == aEvent.buttons &&
67
0
          mGuid == aGuid &&
68
0
          mInputBlockId == aInputBlockId);
69
0
}
70
71
72
void
73
CoalescedMouseMoveFlusher::WillRefresh(mozilla::TimeStamp aTime)
74
0
{
75
0
  MOZ_ASSERT(mRefreshDriver);
76
0
  mTabChild->FlushAllCoalescedMouseData();
77
0
  mTabChild->ProcessPendingCoalescedMouseDataAndDispatchEvents();
78
0
}
79
80
void
81
CoalescedMouseMoveFlusher::StartObserver()
82
0
{
83
0
  nsRefreshDriver* refreshDriver = GetRefreshDriver();
84
0
  if (mRefreshDriver && mRefreshDriver == refreshDriver) {
85
0
    // Nothing to do if we already added an observer and it's same refresh driver.
86
0
    return;
87
0
  }
88
0
  RemoveObserver();
89
0
  if (refreshDriver) {
90
0
    mRefreshDriver = refreshDriver;
91
0
    DebugOnly<bool> success =
92
0
      mRefreshDriver->AddRefreshObserver(this, FlushType::Event);
93
0
    MOZ_ASSERT(success);
94
0
  }
95
0
}
96
97
void
98
CoalescedMouseMoveFlusher::RemoveObserver()
99
0
{
100
0
  if (mRefreshDriver) {
101
0
    mRefreshDriver->RemoveRefreshObserver(this, FlushType::Event);
102
0
    mRefreshDriver = nullptr;
103
0
  }
104
0
}
105
106
nsRefreshDriver*
107
CoalescedMouseMoveFlusher::GetRefreshDriver()
108
0
{
109
0
  nsCOMPtr<nsIPresShell> presShell = mTabChild->GetPresShell();
110
0
  if (!presShell || !presShell->GetPresContext() ||
111
0
      !presShell->GetPresContext()->RefreshDriver()) {
112
0
    return nullptr;
113
0
  }
114
0
  return presShell->GetPresContext()->RefreshDriver();
115
0
}