Bug 1885602 - Part 5: Implement navigating to the SUMO help topic from the menu heade...
[gecko.git] / dom / events / NotifyPaintEvent.cpp
blob6bbcd736a4268659ec6dd20d6d9266261cf3e856
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::MessageWriter* aWriter,
83 bool aSerializeInterfaceType) {
84 if (aSerializeInterfaceType) {
85 IPC::WriteParam(aWriter, u"notifypaintevent"_ns);
88 Event::Serialize(aWriter, false);
90 uint32_t length = mInvalidateRequests.Length();
91 IPC::WriteParam(aWriter, length);
92 for (uint32_t i = 0; i < length; ++i) {
93 IPC::WriteParam(aWriter, mInvalidateRequests[i]);
97 bool NotifyPaintEvent::Deserialize(IPC::MessageReader* aReader) {
98 NS_ENSURE_TRUE(Event::Deserialize(aReader), false);
100 uint32_t length = 0;
101 NS_ENSURE_TRUE(IPC::ReadParam(aReader, &length), false);
102 mInvalidateRequests.SetCapacity(length);
103 for (uint32_t i = 0; i < length; ++i) {
104 nsRect req;
105 NS_ENSURE_TRUE(IPC::ReadParam(aReader, &req), false);
106 mInvalidateRequests.AppendElement(req);
109 return true;
112 uint64_t NotifyPaintEvent::TransactionId(SystemCallerGuarantee) {
113 return mTransactionId;
116 DOMHighResTimeStamp NotifyPaintEvent::PaintTimeStamp(SystemCallerGuarantee) {
117 return mTimeStamp;
120 } // namespace mozilla::dom
122 using namespace mozilla;
123 using namespace mozilla::dom;
125 already_AddRefed<NotifyPaintEvent> NS_NewDOMNotifyPaintEvent(
126 EventTarget* aOwner, nsPresContext* aPresContext, WidgetEvent* aEvent,
127 EventMessage aEventMessage, nsTArray<nsRect>* aInvalidateRequests,
128 uint64_t aTransactionId, DOMHighResTimeStamp aTimeStamp) {
129 RefPtr<NotifyPaintEvent> it =
130 new NotifyPaintEvent(aOwner, aPresContext, aEvent, aEventMessage,
131 aInvalidateRequests, aTransactionId, aTimeStamp);
132 return it.forget();