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"
|
2013-07-26 12:28:31 -07:00
|
|
|
#include "mozilla/GfxMessageUtils.h"
|
2008-09-18 02:47:21 -07:00
|
|
|
#include "nsDOMNotifyPaintEvent.h"
|
|
|
|
#include "nsContentUtils.h"
|
2009-09-03 21:49:18 -07:00
|
|
|
#include "nsPaintRequest.h"
|
2013-09-20 03:21:03 -07:00
|
|
|
#include "mozilla/dom/DOMRect.h"
|
|
|
|
|
2013-10-01 20:46:04 -07:00
|
|
|
using namespace mozilla;
|
2013-09-20 03:21:03 -07:00
|
|
|
using namespace mozilla::dom;
|
2008-09-18 02:47:21 -07:00
|
|
|
|
2013-03-09 03:34:29 -08:00
|
|
|
nsDOMNotifyPaintEvent::nsDOMNotifyPaintEvent(mozilla::dom::EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
2013-10-01 20:46:04 -07:00
|
|
|
WidgetEvent* 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsDOMNotifyPaintEvent)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMNotifyPaintEvent)
|
|
|
|
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)
|
2013-04-15 13:27:37 -07:00
|
|
|
{
|
|
|
|
*aResult = BoundingClientRect().get();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-09-20 03:21:03 -07:00
|
|
|
already_AddRefed<DOMRect>
|
2013-04-15 13:27:37 -07:00
|
|
|
nsDOMNotifyPaintEvent::BoundingClientRect()
|
2008-09-18 02:47:21 -07:00
|
|
|
{
|
2013-09-20 03:21:03 -07:00
|
|
|
nsRefPtr<DOMRect> rect = new DOMRect(ToSupports(this));
|
2008-09-18 02:47:21 -07:00
|
|
|
|
2013-03-17 00:55:17 -07:00
|
|
|
if (mPresContext) {
|
|
|
|
rect->SetLayoutRect(GetRegion().GetBounds());
|
|
|
|
}
|
2008-09-18 02:47:21 -07:00
|
|
|
|
2013-04-15 13:27:37 -07:00
|
|
|
return rect.forget();
|
2008-09-18 02:47:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMNotifyPaintEvent::GetClientRects(nsIDOMClientRectList** aResult)
|
2013-04-15 13:27:37 -07:00
|
|
|
{
|
|
|
|
*aResult = ClientRects().get();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-09-20 03:21:03 -07:00
|
|
|
already_AddRefed<DOMRectList>
|
2013-04-15 13:27:37 -07:00
|
|
|
nsDOMNotifyPaintEvent::ClientRects()
|
2008-09-18 02:47:21 -07:00
|
|
|
{
|
2013-03-17 00:55:17 -07:00
|
|
|
nsISupports* parent = ToSupports(this);
|
2013-09-20 03:21:03 -07:00
|
|
|
nsRefPtr<DOMRectList> rectList = new DOMRectList(parent);
|
2008-09-18 02:47:21 -07:00
|
|
|
|
|
|
|
nsRegion r = GetRegion();
|
|
|
|
nsRegionRectIterator iter(r);
|
|
|
|
for (const nsRect* rgnRect = iter.Next(); rgnRect; rgnRect = iter.Next()) {
|
2013-09-20 03:21:03 -07:00
|
|
|
nsRefPtr<DOMRect> rect = new DOMRect(parent);
|
2008-09-18 02:47:21 -07:00
|
|
|
|
2009-09-03 21:49:18 -07:00
|
|
|
rect->SetLayoutRect(*rgnRect);
|
2008-09-18 02:47:21 -07:00
|
|
|
rectList->Append(rect);
|
|
|
|
}
|
|
|
|
|
2013-04-15 13:27:37 -07:00
|
|
|
return rectList.forget();
|
2009-09-03 21:49:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-07-10 03:01:29 -07:00
|
|
|
nsDOMNotifyPaintEvent::GetPaintRequests(nsISupports** aResult)
|
2009-09-03 21:49:18 -07:00
|
|
|
{
|
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,
|
2013-10-01 20:46:04 -07:00
|
|
|
WidgetEvent* 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);
|
2008-09-18 02:47:21 -07:00
|
|
|
|
|
|
|
return CallQueryInterface(it, aInstancePtrResult);
|
|
|
|
}
|