|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #include "base/basictypes.h" |
|
7 #include "ipc/IPCMessageUtils.h" |
|
8 #include "mozilla/dom/DOMRect.h" |
|
9 #include "mozilla/dom/NotifyPaintEvent.h" |
|
10 #include "mozilla/dom/PaintRequest.h" |
|
11 #include "mozilla/GfxMessageUtils.h" |
|
12 #include "nsContentUtils.h" |
|
13 |
|
14 namespace mozilla { |
|
15 namespace dom { |
|
16 |
|
17 NotifyPaintEvent::NotifyPaintEvent(EventTarget* aOwner, |
|
18 nsPresContext* aPresContext, |
|
19 WidgetEvent* aEvent, |
|
20 uint32_t aEventType, |
|
21 nsInvalidateRequestList* aInvalidateRequests) |
|
22 : Event(aOwner, aPresContext, aEvent) |
|
23 { |
|
24 if (mEvent) { |
|
25 mEvent->message = aEventType; |
|
26 } |
|
27 if (aInvalidateRequests) { |
|
28 mInvalidateRequests.MoveElementsFrom(aInvalidateRequests->mRequests); |
|
29 } |
|
30 } |
|
31 |
|
32 NS_INTERFACE_MAP_BEGIN(NotifyPaintEvent) |
|
33 NS_INTERFACE_MAP_ENTRY(nsIDOMNotifyPaintEvent) |
|
34 NS_INTERFACE_MAP_END_INHERITING(Event) |
|
35 |
|
36 NS_IMPL_ADDREF_INHERITED(NotifyPaintEvent, Event) |
|
37 NS_IMPL_RELEASE_INHERITED(NotifyPaintEvent, Event) |
|
38 |
|
39 nsRegion |
|
40 NotifyPaintEvent::GetRegion() |
|
41 { |
|
42 nsRegion r; |
|
43 if (!nsContentUtils::IsCallerChrome()) { |
|
44 return r; |
|
45 } |
|
46 for (uint32_t i = 0; i < mInvalidateRequests.Length(); ++i) { |
|
47 r.Or(r, mInvalidateRequests[i].mRect); |
|
48 r.SimplifyOutward(10); |
|
49 } |
|
50 return r; |
|
51 } |
|
52 |
|
53 NS_IMETHODIMP |
|
54 NotifyPaintEvent::GetBoundingClientRect(nsIDOMClientRect** aResult) |
|
55 { |
|
56 *aResult = BoundingClientRect().take(); |
|
57 return NS_OK; |
|
58 } |
|
59 |
|
60 already_AddRefed<DOMRect> |
|
61 NotifyPaintEvent::BoundingClientRect() |
|
62 { |
|
63 nsRefPtr<DOMRect> rect = new DOMRect(ToSupports(this)); |
|
64 |
|
65 if (mPresContext) { |
|
66 rect->SetLayoutRect(GetRegion().GetBounds()); |
|
67 } |
|
68 |
|
69 return rect.forget(); |
|
70 } |
|
71 |
|
72 NS_IMETHODIMP |
|
73 NotifyPaintEvent::GetClientRects(nsIDOMClientRectList** aResult) |
|
74 { |
|
75 *aResult = ClientRects().take(); |
|
76 return NS_OK; |
|
77 } |
|
78 |
|
79 already_AddRefed<DOMRectList> |
|
80 NotifyPaintEvent::ClientRects() |
|
81 { |
|
82 nsISupports* parent = ToSupports(this); |
|
83 nsRefPtr<DOMRectList> rectList = new DOMRectList(parent); |
|
84 |
|
85 nsRegion r = GetRegion(); |
|
86 nsRegionRectIterator iter(r); |
|
87 for (const nsRect* rgnRect = iter.Next(); rgnRect; rgnRect = iter.Next()) { |
|
88 nsRefPtr<DOMRect> rect = new DOMRect(parent); |
|
89 |
|
90 rect->SetLayoutRect(*rgnRect); |
|
91 rectList->Append(rect); |
|
92 } |
|
93 |
|
94 return rectList.forget(); |
|
95 } |
|
96 |
|
97 NS_IMETHODIMP |
|
98 NotifyPaintEvent::GetPaintRequests(nsISupports** aResult) |
|
99 { |
|
100 nsRefPtr<PaintRequestList> requests = PaintRequests(); |
|
101 requests.forget(aResult); |
|
102 return NS_OK; |
|
103 } |
|
104 |
|
105 already_AddRefed<PaintRequestList> |
|
106 NotifyPaintEvent::PaintRequests() |
|
107 { |
|
108 Event* parent = this; |
|
109 nsRefPtr<PaintRequestList> requests = new PaintRequestList(parent); |
|
110 |
|
111 if (nsContentUtils::IsCallerChrome()) { |
|
112 for (uint32_t i = 0; i < mInvalidateRequests.Length(); ++i) { |
|
113 nsRefPtr<PaintRequest> r = new PaintRequest(parent); |
|
114 r->SetRequest(mInvalidateRequests[i]); |
|
115 requests->Append(r); |
|
116 } |
|
117 } |
|
118 |
|
119 return requests.forget(); |
|
120 } |
|
121 |
|
122 NS_IMETHODIMP_(void) |
|
123 NotifyPaintEvent::Serialize(IPC::Message* aMsg, |
|
124 bool aSerializeInterfaceType) |
|
125 { |
|
126 if (aSerializeInterfaceType) { |
|
127 IPC::WriteParam(aMsg, NS_LITERAL_STRING("notifypaintevent")); |
|
128 } |
|
129 |
|
130 Event::Serialize(aMsg, false); |
|
131 |
|
132 uint32_t length = mInvalidateRequests.Length(); |
|
133 IPC::WriteParam(aMsg, length); |
|
134 for (uint32_t i = 0; i < length; ++i) { |
|
135 IPC::WriteParam(aMsg, mInvalidateRequests[i].mRect); |
|
136 IPC::WriteParam(aMsg, mInvalidateRequests[i].mFlags); |
|
137 } |
|
138 } |
|
139 |
|
140 NS_IMETHODIMP_(bool) |
|
141 NotifyPaintEvent::Deserialize(const IPC::Message* aMsg, void** aIter) |
|
142 { |
|
143 NS_ENSURE_TRUE(Event::Deserialize(aMsg, aIter), false); |
|
144 |
|
145 uint32_t length = 0; |
|
146 NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &length), false); |
|
147 mInvalidateRequests.SetCapacity(length); |
|
148 for (uint32_t i = 0; i < length; ++i) { |
|
149 nsInvalidateRequestList::Request req; |
|
150 NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &req.mRect), false); |
|
151 NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &req.mFlags), false); |
|
152 mInvalidateRequests.AppendElement(req); |
|
153 } |
|
154 |
|
155 return true; |
|
156 } |
|
157 |
|
158 } // namespace dom |
|
159 } // namespace mozilla |
|
160 |
|
161 using namespace mozilla; |
|
162 using namespace mozilla::dom; |
|
163 |
|
164 nsresult |
|
165 NS_NewDOMNotifyPaintEvent(nsIDOMEvent** aInstancePtrResult, |
|
166 EventTarget* aOwner, |
|
167 nsPresContext* aPresContext, |
|
168 WidgetEvent* aEvent, |
|
169 uint32_t aEventType, |
|
170 nsInvalidateRequestList* aInvalidateRequests) |
|
171 { |
|
172 NotifyPaintEvent* it = new NotifyPaintEvent(aOwner, aPresContext, aEvent, |
|
173 aEventType, aInvalidateRequests); |
|
174 NS_ADDREF(it); |
|
175 *aInstancePtrResult = static_cast<Event*>(it); |
|
176 return NS_OK; |
|
177 } |