NotifyPaintEvent.cpp 5.1 KB

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