1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/events/NotifyPaintEvent.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,177 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "base/basictypes.h" 1.10 +#include "ipc/IPCMessageUtils.h" 1.11 +#include "mozilla/dom/DOMRect.h" 1.12 +#include "mozilla/dom/NotifyPaintEvent.h" 1.13 +#include "mozilla/dom/PaintRequest.h" 1.14 +#include "mozilla/GfxMessageUtils.h" 1.15 +#include "nsContentUtils.h" 1.16 + 1.17 +namespace mozilla { 1.18 +namespace dom { 1.19 + 1.20 +NotifyPaintEvent::NotifyPaintEvent(EventTarget* aOwner, 1.21 + nsPresContext* aPresContext, 1.22 + WidgetEvent* aEvent, 1.23 + uint32_t aEventType, 1.24 + nsInvalidateRequestList* aInvalidateRequests) 1.25 + : Event(aOwner, aPresContext, aEvent) 1.26 +{ 1.27 + if (mEvent) { 1.28 + mEvent->message = aEventType; 1.29 + } 1.30 + if (aInvalidateRequests) { 1.31 + mInvalidateRequests.MoveElementsFrom(aInvalidateRequests->mRequests); 1.32 + } 1.33 +} 1.34 + 1.35 +NS_INTERFACE_MAP_BEGIN(NotifyPaintEvent) 1.36 + NS_INTERFACE_MAP_ENTRY(nsIDOMNotifyPaintEvent) 1.37 +NS_INTERFACE_MAP_END_INHERITING(Event) 1.38 + 1.39 +NS_IMPL_ADDREF_INHERITED(NotifyPaintEvent, Event) 1.40 +NS_IMPL_RELEASE_INHERITED(NotifyPaintEvent, Event) 1.41 + 1.42 +nsRegion 1.43 +NotifyPaintEvent::GetRegion() 1.44 +{ 1.45 + nsRegion r; 1.46 + if (!nsContentUtils::IsCallerChrome()) { 1.47 + return r; 1.48 + } 1.49 + for (uint32_t i = 0; i < mInvalidateRequests.Length(); ++i) { 1.50 + r.Or(r, mInvalidateRequests[i].mRect); 1.51 + r.SimplifyOutward(10); 1.52 + } 1.53 + return r; 1.54 +} 1.55 + 1.56 +NS_IMETHODIMP 1.57 +NotifyPaintEvent::GetBoundingClientRect(nsIDOMClientRect** aResult) 1.58 +{ 1.59 + *aResult = BoundingClientRect().take(); 1.60 + return NS_OK; 1.61 +} 1.62 + 1.63 +already_AddRefed<DOMRect> 1.64 +NotifyPaintEvent::BoundingClientRect() 1.65 +{ 1.66 + nsRefPtr<DOMRect> rect = new DOMRect(ToSupports(this)); 1.67 + 1.68 + if (mPresContext) { 1.69 + rect->SetLayoutRect(GetRegion().GetBounds()); 1.70 + } 1.71 + 1.72 + return rect.forget(); 1.73 +} 1.74 + 1.75 +NS_IMETHODIMP 1.76 +NotifyPaintEvent::GetClientRects(nsIDOMClientRectList** aResult) 1.77 +{ 1.78 + *aResult = ClientRects().take(); 1.79 + return NS_OK; 1.80 +} 1.81 + 1.82 +already_AddRefed<DOMRectList> 1.83 +NotifyPaintEvent::ClientRects() 1.84 +{ 1.85 + nsISupports* parent = ToSupports(this); 1.86 + nsRefPtr<DOMRectList> rectList = new DOMRectList(parent); 1.87 + 1.88 + nsRegion r = GetRegion(); 1.89 + nsRegionRectIterator iter(r); 1.90 + for (const nsRect* rgnRect = iter.Next(); rgnRect; rgnRect = iter.Next()) { 1.91 + nsRefPtr<DOMRect> rect = new DOMRect(parent); 1.92 + 1.93 + rect->SetLayoutRect(*rgnRect); 1.94 + rectList->Append(rect); 1.95 + } 1.96 + 1.97 + return rectList.forget(); 1.98 +} 1.99 + 1.100 +NS_IMETHODIMP 1.101 +NotifyPaintEvent::GetPaintRequests(nsISupports** aResult) 1.102 +{ 1.103 + nsRefPtr<PaintRequestList> requests = PaintRequests(); 1.104 + requests.forget(aResult); 1.105 + return NS_OK; 1.106 +} 1.107 + 1.108 +already_AddRefed<PaintRequestList> 1.109 +NotifyPaintEvent::PaintRequests() 1.110 +{ 1.111 + Event* parent = this; 1.112 + nsRefPtr<PaintRequestList> requests = new PaintRequestList(parent); 1.113 + 1.114 + if (nsContentUtils::IsCallerChrome()) { 1.115 + for (uint32_t i = 0; i < mInvalidateRequests.Length(); ++i) { 1.116 + nsRefPtr<PaintRequest> r = new PaintRequest(parent); 1.117 + r->SetRequest(mInvalidateRequests[i]); 1.118 + requests->Append(r); 1.119 + } 1.120 + } 1.121 + 1.122 + return requests.forget(); 1.123 +} 1.124 + 1.125 +NS_IMETHODIMP_(void) 1.126 +NotifyPaintEvent::Serialize(IPC::Message* aMsg, 1.127 + bool aSerializeInterfaceType) 1.128 +{ 1.129 + if (aSerializeInterfaceType) { 1.130 + IPC::WriteParam(aMsg, NS_LITERAL_STRING("notifypaintevent")); 1.131 + } 1.132 + 1.133 + Event::Serialize(aMsg, false); 1.134 + 1.135 + uint32_t length = mInvalidateRequests.Length(); 1.136 + IPC::WriteParam(aMsg, length); 1.137 + for (uint32_t i = 0; i < length; ++i) { 1.138 + IPC::WriteParam(aMsg, mInvalidateRequests[i].mRect); 1.139 + IPC::WriteParam(aMsg, mInvalidateRequests[i].mFlags); 1.140 + } 1.141 +} 1.142 + 1.143 +NS_IMETHODIMP_(bool) 1.144 +NotifyPaintEvent::Deserialize(const IPC::Message* aMsg, void** aIter) 1.145 +{ 1.146 + NS_ENSURE_TRUE(Event::Deserialize(aMsg, aIter), false); 1.147 + 1.148 + uint32_t length = 0; 1.149 + NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &length), false); 1.150 + mInvalidateRequests.SetCapacity(length); 1.151 + for (uint32_t i = 0; i < length; ++i) { 1.152 + nsInvalidateRequestList::Request req; 1.153 + NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &req.mRect), false); 1.154 + NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &req.mFlags), false); 1.155 + mInvalidateRequests.AppendElement(req); 1.156 + } 1.157 + 1.158 + return true; 1.159 +} 1.160 + 1.161 +} // namespace dom 1.162 +} // namespace mozilla 1.163 + 1.164 +using namespace mozilla; 1.165 +using namespace mozilla::dom; 1.166 + 1.167 +nsresult 1.168 +NS_NewDOMNotifyPaintEvent(nsIDOMEvent** aInstancePtrResult, 1.169 + EventTarget* aOwner, 1.170 + nsPresContext* aPresContext, 1.171 + WidgetEvent* aEvent, 1.172 + uint32_t aEventType, 1.173 + nsInvalidateRequestList* aInvalidateRequests) 1.174 +{ 1.175 + NotifyPaintEvent* it = new NotifyPaintEvent(aOwner, aPresContext, aEvent, 1.176 + aEventType, aInvalidateRequests); 1.177 + NS_ADDREF(it); 1.178 + *aInstancePtrResult = static_cast<Event*>(it); 1.179 + return NS_OK; 1.180 +}