Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/events/NotifyPaintEvent.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
7
#include "base/basictypes.h"
8
#include "ipc/IPCMessageUtils.h"
9
#include "mozilla/dom/DOMRect.h"
10
#include "mozilla/dom/NotifyPaintEvent.h"
11
#include "mozilla/dom/PaintRequest.h"
12
#include "mozilla/GfxMessageUtils.h"
13
#include "nsContentUtils.h"
14
15
namespace mozilla {
16
namespace dom {
17
18
NotifyPaintEvent::NotifyPaintEvent(EventTarget* aOwner,
19
                                   nsPresContext* aPresContext,
20
                                   WidgetEvent* aEvent,
21
                                   EventMessage aEventMessage,
22
                                   nsTArray<nsRect>* aInvalidateRequests,
23
                                   uint64_t aTransactionId,
24
                                   DOMHighResTimeStamp aTimeStamp)
25
  : Event(aOwner, aPresContext, aEvent)
26
0
{
27
0
  if (mEvent) {
28
0
    mEvent->mMessage = aEventMessage;
29
0
  }
30
0
  if (aInvalidateRequests) {
31
0
    mInvalidateRequests.SwapElements(*aInvalidateRequests);
32
0
  }
33
0
34
0
  mTransactionId = aTransactionId;
35
0
  mTimeStamp = aTimeStamp;
36
0
}
37
38
nsRegion
39
NotifyPaintEvent::GetRegion(SystemCallerGuarantee)
40
0
{
41
0
  nsRegion r;
42
0
  for (uint32_t i = 0; i < mInvalidateRequests.Length(); ++i) {
43
0
    r.Or(r, mInvalidateRequests[i]);
44
0
    r.SimplifyOutward(10);
45
0
  }
46
0
  return r;
47
0
}
48
49
already_AddRefed<DOMRect>
50
NotifyPaintEvent::BoundingClientRect(SystemCallerGuarantee aGuarantee)
51
0
{
52
0
  RefPtr<DOMRect> rect = new DOMRect(ToSupports(this));
53
0
54
0
  if (mPresContext) {
55
0
    rect->SetLayoutRect(GetRegion(aGuarantee).GetBounds());
56
0
  }
57
0
58
0
  return rect.forget();
59
0
}
60
61
already_AddRefed<DOMRectList>
62
NotifyPaintEvent::ClientRects(SystemCallerGuarantee aGuarantee)
63
0
{
64
0
  nsISupports* parent = ToSupports(this);
65
0
  RefPtr<DOMRectList> rectList = new DOMRectList(parent);
66
0
67
0
  nsRegion r = GetRegion(aGuarantee);
68
0
  for (auto iter = r.RectIter(); !iter.Done(); iter.Next()) {
69
0
    RefPtr<DOMRect> rect = new DOMRect(parent);
70
0
    rect->SetLayoutRect(iter.Get());
71
0
    rectList->Append(rect);
72
0
  }
73
0
74
0
  return rectList.forget();
75
0
}
76
77
already_AddRefed<PaintRequestList>
78
NotifyPaintEvent::PaintRequests(SystemCallerGuarantee)
79
0
{
80
0
  Event* parent = this;
81
0
  RefPtr<PaintRequestList> requests = new PaintRequestList(parent);
82
0
83
0
  for (uint32_t i = 0; i < mInvalidateRequests.Length(); ++i) {
84
0
    RefPtr<PaintRequest> r = new PaintRequest(parent);
85
0
    r->SetRequest(mInvalidateRequests[i]);
86
0
    requests->Append(r);
87
0
  }
88
0
89
0
  return requests.forget();
90
0
}
91
92
void
93
NotifyPaintEvent::Serialize(IPC::Message* aMsg,
94
                            bool aSerializeInterfaceType)
95
0
{
96
0
  if (aSerializeInterfaceType) {
97
0
    IPC::WriteParam(aMsg, NS_LITERAL_STRING("notifypaintevent"));
98
0
  }
99
0
100
0
  Event::Serialize(aMsg, false);
101
0
102
0
  uint32_t length = mInvalidateRequests.Length();
103
0
  IPC::WriteParam(aMsg, length);
104
0
  for (uint32_t i = 0; i < length; ++i) {
105
0
    IPC::WriteParam(aMsg, mInvalidateRequests[i]);
106
0
  }
107
0
}
108
109
bool
110
NotifyPaintEvent::Deserialize(const IPC::Message* aMsg, PickleIterator* aIter)
111
0
{
112
0
  NS_ENSURE_TRUE(Event::Deserialize(aMsg, aIter), false);
113
0
114
0
  uint32_t length = 0;
115
0
  NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &length), false);
116
0
  mInvalidateRequests.SetCapacity(length);
117
0
  for (uint32_t i = 0; i < length; ++i) {
118
0
    nsRect req;
119
0
    NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &req), false);
120
0
    mInvalidateRequests.AppendElement(req);
121
0
  }
122
0
123
0
  return true;
124
0
}
125
126
uint64_t
127
NotifyPaintEvent::TransactionId(SystemCallerGuarantee)
128
0
{
129
0
  return mTransactionId;
130
0
}
131
132
DOMHighResTimeStamp
133
NotifyPaintEvent::PaintTimeStamp(SystemCallerGuarantee)
134
0
{
135
0
  return mTimeStamp;
136
0
}
137
138
} // namespace dom
139
} // namespace mozilla
140
141
using namespace mozilla;
142
using namespace mozilla::dom;
143
144
already_AddRefed<NotifyPaintEvent>
145
NS_NewDOMNotifyPaintEvent(EventTarget* aOwner,
146
                          nsPresContext* aPresContext,
147
                          WidgetEvent* aEvent,
148
                          EventMessage aEventMessage,
149
                          nsTArray<nsRect>* aInvalidateRequests,
150
                          uint64_t aTransactionId,
151
                          DOMHighResTimeStamp aTimeStamp)
152
0
{
153
0
  RefPtr<NotifyPaintEvent> it =
154
0
    new NotifyPaintEvent(aOwner, aPresContext, aEvent, aEventMessage,
155
0
                         aInvalidateRequests, aTransactionId, aTimeStamp);
156
0
  return it.forget();
157
0
}