2008-09-18 02:47:21 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2008-09-18 02:47:21 -07:00
|
|
|
|
2009-11-17 06:22:23 -08:00
|
|
|
#include "base/basictypes.h"
|
2012-08-28 05:41:04 -07:00
|
|
|
#include "ipc/IPCMessageUtils.h"
|
2008-09-18 02:47:21 -07:00
|
|
|
#include "nsDOMNotifyPaintEvent.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsClientRect.h"
|
2009-09-03 21:49:18 -07:00
|
|
|
#include "nsPaintRequest.h"
|
|
|
|
#include "nsIFrame.h"
|
2012-07-20 09:42:08 -07:00
|
|
|
#include "nsDOMClassInfoID.h"
|
2008-09-18 02:47:21 -07:00
|
|
|
|
2013-03-09 03:34:29 -08:00
|
|
|
nsDOMNotifyPaintEvent::nsDOMNotifyPaintEvent(mozilla::dom::EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
2009-06-23 02:09:05 -07:00
|
|
|
nsEvent* aEvent,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aEventType,
|
2009-09-03 21:49:18 -07:00
|
|
|
nsInvalidateRequestList* aInvalidateRequests)
|
2013-03-09 03:34:29 -08:00
|
|
|
: nsDOMEvent(aOwner, aPresContext, aEvent)
|
2009-06-23 02:09:05 -07:00
|
|
|
{
|
|
|
|
if (mEvent) {
|
|
|
|
mEvent->message = aEventType;
|
2008-09-18 02:47:21 -07:00
|
|
|
}
|
2009-09-03 21:49:18 -07:00
|
|
|
if (aInvalidateRequests) {
|
2012-10-18 21:50:34 -07:00
|
|
|
mInvalidateRequests.MoveElementsFrom(aInvalidateRequests->mRequests);
|
2008-09-18 02:47:21 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-12 05:08:43 -08:00
|
|
|
DOMCI_DATA(NotifyPaintEvent, nsDOMNotifyPaintEvent)
|
|
|
|
|
2008-09-18 02:47:21 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN(nsDOMNotifyPaintEvent)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMNotifyPaintEvent)
|
2010-03-17 08:09:05 -07:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(NotifyPaintEvent)
|
2008-09-18 02:47:21 -07:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(nsDOMNotifyPaintEvent, nsDOMEvent)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsDOMNotifyPaintEvent, nsDOMEvent)
|
|
|
|
|
|
|
|
nsRegion
|
|
|
|
nsDOMNotifyPaintEvent::GetRegion()
|
|
|
|
{
|
|
|
|
nsRegion r;
|
2012-10-25 16:10:53 -07:00
|
|
|
if (!nsContentUtils::IsCallerChrome()) {
|
2012-08-28 22:47:18 -07:00
|
|
|
return r;
|
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < mInvalidateRequests.Length(); ++i) {
|
2009-09-03 21:49:18 -07:00
|
|
|
r.Or(r, mInvalidateRequests[i].mRect);
|
|
|
|
r.SimplifyOutward(10);
|
2008-09-18 02:47:21 -07:00
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMNotifyPaintEvent::GetBoundingClientRect(nsIDOMClientRect** aResult)
|
|
|
|
{
|
|
|
|
// Weak ref, since we addref it below
|
|
|
|
nsClientRect* rect = new nsClientRect();
|
|
|
|
if (!rect)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
NS_ADDREF(*aResult = rect);
|
|
|
|
if (!mPresContext)
|
|
|
|
return NS_OK;
|
|
|
|
|
2009-09-03 21:49:18 -07:00
|
|
|
rect->SetLayoutRect(GetRegion().GetBounds());
|
2008-09-18 02:47:21 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMNotifyPaintEvent::GetClientRects(nsIDOMClientRectList** aResult)
|
|
|
|
{
|
2011-08-22 02:14:13 -07:00
|
|
|
nsRefPtr<nsClientRectList> rectList =
|
|
|
|
new nsClientRectList(static_cast<nsIDOMEvent*>(static_cast<nsDOMEvent*>(this)));
|
2008-09-18 02:47:21 -07:00
|
|
|
if (!rectList)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
nsRegion r = GetRegion();
|
|
|
|
nsRegionRectIterator iter(r);
|
|
|
|
for (const nsRect* rgnRect = iter.Next(); rgnRect; rgnRect = iter.Next()) {
|
|
|
|
nsRefPtr<nsClientRect> rect = new nsClientRect();
|
|
|
|
if (!rect)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2009-09-03 21:49:18 -07:00
|
|
|
rect->SetLayoutRect(*rgnRect);
|
2008-09-18 02:47:21 -07:00
|
|
|
rectList->Append(rect);
|
|
|
|
}
|
|
|
|
|
2009-09-03 21:49:18 -07:00
|
|
|
rectList.forget(aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMNotifyPaintEvent::GetPaintRequests(nsIDOMPaintRequestList** aResult)
|
|
|
|
{
|
2012-12-22 00:16:55 -08:00
|
|
|
nsRefPtr<nsPaintRequestList> requests = PaintRequests();
|
|
|
|
requests.forget(aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsPaintRequestList>
|
|
|
|
nsDOMNotifyPaintEvent::PaintRequests()
|
|
|
|
{
|
|
|
|
nsDOMEvent* parent = this;
|
|
|
|
nsRefPtr<nsPaintRequestList> requests = new nsPaintRequestList(parent);
|
2009-09-03 21:49:18 -07:00
|
|
|
|
2012-10-25 16:10:53 -07:00
|
|
|
if (nsContentUtils::IsCallerChrome()) {
|
2012-08-28 22:47:18 -07:00
|
|
|
for (uint32_t i = 0; i < mInvalidateRequests.Length(); ++i) {
|
2012-12-22 00:16:55 -08:00
|
|
|
nsRefPtr<nsPaintRequest> r = new nsPaintRequest(parent);
|
2012-08-28 22:47:18 -07:00
|
|
|
r->SetRequest(mInvalidateRequests[i]);
|
|
|
|
requests->Append(r);
|
|
|
|
}
|
2009-09-03 21:49:18 -07:00
|
|
|
}
|
|
|
|
|
2012-12-22 00:16:55 -08:00
|
|
|
return requests.forget();
|
2008-09-18 02:47:21 -07:00
|
|
|
}
|
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
NS_IMETHODIMP_(void)
|
2009-11-17 06:22:23 -08:00
|
|
|
nsDOMNotifyPaintEvent::Serialize(IPC::Message* aMsg,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aSerializeInterfaceType)
|
2009-11-17 06:22:23 -08:00
|
|
|
{
|
|
|
|
if (aSerializeInterfaceType) {
|
|
|
|
IPC::WriteParam(aMsg, NS_LITERAL_STRING("notifypaintevent"));
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
nsDOMEvent::Serialize(aMsg, false);
|
2009-11-17 06:22:23 -08:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t length = mInvalidateRequests.Length();
|
2009-11-17 06:22:23 -08:00
|
|
|
IPC::WriteParam(aMsg, length);
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
2013-03-12 10:26:48 -07:00
|
|
|
IPC::WriteParam(aMsg, mInvalidateRequests[i].mRect);
|
2009-11-17 06:22:23 -08:00
|
|
|
IPC::WriteParam(aMsg, mInvalidateRequests[i].mFlags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
NS_IMETHODIMP_(bool)
|
2009-11-17 06:22:23 -08:00
|
|
|
nsDOMNotifyPaintEvent::Deserialize(const IPC::Message* aMsg, void** aIter)
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ENSURE_TRUE(nsDOMEvent::Deserialize(aMsg, aIter), false);
|
2009-11-17 06:22:23 -08:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t length = 0;
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &length), false);
|
2009-11-17 06:22:23 -08:00
|
|
|
mInvalidateRequests.SetCapacity(length);
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
2009-11-17 06:22:23 -08:00
|
|
|
nsInvalidateRequestList::Request req;
|
2013-03-12 10:26:48 -07:00
|
|
|
NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &req.mRect), false);
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &req.mFlags), false);
|
2009-11-17 06:22:23 -08:00
|
|
|
mInvalidateRequests.AppendElement(req);
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2009-11-17 06:22:23 -08:00
|
|
|
}
|
|
|
|
|
2008-09-18 02:47:21 -07:00
|
|
|
nsresult NS_NewDOMNotifyPaintEvent(nsIDOMEvent** aInstancePtrResult,
|
2013-03-09 03:34:29 -08:00
|
|
|
mozilla::dom::EventTarget* aOwner,
|
2008-09-18 02:47:21 -07:00
|
|
|
nsPresContext* aPresContext,
|
2009-06-23 02:09:05 -07:00
|
|
|
nsEvent *aEvent,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aEventType,
|
2009-09-03 21:49:18 -07:00
|
|
|
nsInvalidateRequestList* aInvalidateRequests)
|
2008-09-18 02:47:21 -07:00
|
|
|
{
|
|
|
|
nsDOMNotifyPaintEvent* it =
|
2013-03-09 03:34:29 -08:00
|
|
|
new nsDOMNotifyPaintEvent(aOwner, aPresContext, aEvent, aEventType,
|
2009-09-03 21:49:18 -07:00
|
|
|
aInvalidateRequests);
|
2012-07-30 07:20:58 -07:00
|
|
|
if (nullptr == it) {
|
2008-09-18 02:47:21 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CallQueryInterface(it, aInstancePtrResult);
|
|
|
|
}
|