Bug 1688354 [wpt PR 27298] - Treat 'rem' as an absolute unit for font size, a=testonly
[gecko.git] / dom / events / NotifyPaintEvent.cpp
blobdf2a0d8deef506867dc33c65fb39db59bf515e63
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/. */
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"
15 namespace mozilla::dom {
17 NotifyPaintEvent::NotifyPaintEvent(
18 EventTarget* aOwner, nsPresContext* aPresContext, WidgetEvent* aEvent,
19 EventMessage aEventMessage, nsTArray<nsRect>* aInvalidateRequests,
20 uint64_t aTransactionId, DOMHighResTimeStamp aTimeStamp)
21 : Event(aOwner, aPresContext, aEvent) {
22 if (mEvent) {
23 mEvent->mMessage = aEventMessage;
25 if (aInvalidateRequests) {
26 mInvalidateRequests.SwapElements(*aInvalidateRequests);
29 mTransactionId = aTransactionId;
30 mTimeStamp = aTimeStamp;
33 nsRegion NotifyPaintEvent::GetRegion(SystemCallerGuarantee) {
34 nsRegion r;
35 for (uint32_t i = 0; i < mInvalidateRequests.Length(); ++i) {
36 r.Or(r, mInvalidateRequests[i]);
37 r.SimplifyOutward(10);
39 return r;
42 already_AddRefed<DOMRect> NotifyPaintEvent::BoundingClientRect(
43 SystemCallerGuarantee aGuarantee) {
44 RefPtr<DOMRect> rect = new DOMRect(ToSupports(this));
46 if (mPresContext) {
47 rect->SetLayoutRect(GetRegion(aGuarantee).GetBounds());
50 return rect.forget();
53 already_AddRefed<DOMRectList> NotifyPaintEvent::ClientRects(
54 SystemCallerGuarantee aGuarantee) {
55 nsISupports* parent = ToSupports(this);
56 RefPtr<DOMRectList> rectList = new DOMRectList(parent);
58 nsRegion r = GetRegion(aGuarantee);
59 for (auto iter = r.RectIter(); !iter.Done(); iter.Next()) {
60 RefPtr<DOMRect> rect = new DOMRect(parent);
61 rect->SetLayoutRect(iter.Get());
62 rectList->Append(rect);
65 return rectList.forget();
68 already_AddRefed<PaintRequestList> NotifyPaintEvent::PaintRequests(
69 SystemCallerGuarantee) {
70 Event* parent = this;
71 RefPtr<PaintRequestList> requests = new PaintRequestList(parent);
73 for (uint32_t i = 0; i < mInvalidateRequests.Length(); ++i) {
74 RefPtr<PaintRequest> r = new PaintRequest(parent);
75 r->SetRequest(mInvalidateRequests[i]);
76 requests->Append(r);
79 return requests.forget();
82 void NotifyPaintEvent::Serialize(IPC::Message* aMsg,
83 bool aSerializeInterfaceType) {
84 if (aSerializeInterfaceType) {
85 IPC::WriteParam(aMsg, u"notifypaintevent"_ns);
88 Event::Serialize(aMsg, false);
90 uint32_t length = mInvalidateRequests.Length();
91 IPC::WriteParam(aMsg, length);
92 for (uint32_t i = 0; i < length; ++i) {
93 IPC::WriteParam(aMsg, mInvalidateRequests[i]);
97 bool NotifyPaintEvent::Deserialize(const IPC::Message* aMsg,
98 PickleIterator* aIter) {
99 NS_ENSURE_TRUE(Event::Deserialize(aMsg, aIter), false);
101 uint32_t length = 0;
102 NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &length), false);
103 mInvalidateRequests.SetCapacity(length);
104 for (uint32_t i = 0; i < length; ++i) {
105 nsRect req;
106 NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &req), false);
107 mInvalidateRequests.AppendElement(req);
110 return true;
113 uint64_t NotifyPaintEvent::TransactionId(SystemCallerGuarantee) {
114 return mTransactionId;
117 DOMHighResTimeStamp NotifyPaintEvent::PaintTimeStamp(SystemCallerGuarantee) {
118 return mTimeStamp;
121 } // namespace mozilla::dom
123 using namespace mozilla;
124 using namespace mozilla::dom;
126 already_AddRefed<NotifyPaintEvent> NS_NewDOMNotifyPaintEvent(
127 EventTarget* aOwner, nsPresContext* aPresContext, WidgetEvent* aEvent,
128 EventMessage aEventMessage, nsTArray<nsRect>* aInvalidateRequests,
129 uint64_t aTransactionId, DOMHighResTimeStamp aTimeStamp) {
130 RefPtr<NotifyPaintEvent> it =
131 new NotifyPaintEvent(aOwner, aPresContext, aEvent, aEventMessage,
132 aInvalidateRequests, aTransactionId, aTimeStamp);
133 return it.forget();