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"
|
2014-02-28 06:58:43 -08:00
|
|
|
#include "mozilla/dom/DOMRect.h"
|
|
|
|
#include "mozilla/dom/NotifyPaintEvent.h"
|
2013-07-26 12:28:31 -07:00
|
|
|
#include "mozilla/GfxMessageUtils.h"
|
2008-09-18 02:47:21 -07:00
|
|
|
#include "nsContentUtils.h"
|
2009-09-03 21:49:18 -07:00
|
|
|
#include "nsPaintRequest.h"
|
2013-09-20 03:21:03 -07:00
|
|
|
|
2014-02-28 06:58:43 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2008-09-18 02:47:21 -07:00
|
|
|
|
2014-02-28 06:58:43 -08:00
|
|
|
NotifyPaintEvent::NotifyPaintEvent(EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetEvent* aEvent,
|
|
|
|
uint32_t aEventType,
|
|
|
|
nsInvalidateRequestList* aInvalidateRequests)
|
2014-03-04 16:37:43 -08:00
|
|
|
: Event(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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-28 06:58:43 -08:00
|
|
|
NS_INTERFACE_MAP_BEGIN(NotifyPaintEvent)
|
2008-09-18 02:47:21 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMNotifyPaintEvent)
|
2014-03-04 16:37:43 -08:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(Event)
|
2008-09-18 02:47:21 -07:00
|
|
|
|
2014-03-04 16:37:43 -08:00
|
|
|
NS_IMPL_ADDREF_INHERITED(NotifyPaintEvent, Event)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(NotifyPaintEvent, Event)
|
2008-09-18 02:47:21 -07:00
|
|
|
|
|
|
|
nsRegion
|
2014-02-28 06:58:43 -08:00
|
|
|
NotifyPaintEvent::GetRegion()
|
2008-09-18 02:47:21 -07:00
|
|
|
{
|
|
|
|
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
|
2014-02-28 06:58:43 -08:00
|
|
|
NotifyPaintEvent::GetBoundingClientRect(nsIDOMClientRect** aResult)
|
2013-04-15 13:27:37 -07:00
|
|
|
{
|
2014-03-15 12:00:15 -07:00
|
|
|
*aResult = BoundingClientRect().take();
|
2013-04-15 13:27:37 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-09-20 03:21:03 -07:00
|
|
|
already_AddRefed<DOMRect>
|
2014-02-28 06:58:43 -08:00
|
|
|
NotifyPaintEvent::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
|
2014-02-28 06:58:43 -08:00
|
|
|
NotifyPaintEvent::GetClientRects(nsIDOMClientRectList** aResult)
|
2013-04-15 13:27:37 -07:00
|
|
|
{
|
2014-03-15 12:00:15 -07:00
|
|
|
*aResult = ClientRects().take();
|
2013-04-15 13:27:37 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-09-20 03:21:03 -07:00
|
|
|
already_AddRefed<DOMRectList>
|
2014-02-28 06:58:43 -08:00
|
|
|
NotifyPaintEvent::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
|
2014-02-28 06:58:43 -08:00
|
|
|
NotifyPaintEvent::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>
|
2014-02-28 06:58:43 -08:00
|
|
|
NotifyPaintEvent::PaintRequests()
|
2012-12-22 00:16:55 -08:00
|
|
|
{
|
2014-03-04 16:37:43 -08:00
|
|
|
Event* parent = this;
|
2012-12-22 00:16:55 -08:00
|
|
|
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)
|
2014-02-28 06:58:43 -08:00
|
|
|
NotifyPaintEvent::Serialize(IPC::Message* aMsg,
|
|
|
|
bool aSerializeInterfaceType)
|
2009-11-17 06:22:23 -08:00
|
|
|
{
|
|
|
|
if (aSerializeInterfaceType) {
|
|
|
|
IPC::WriteParam(aMsg, NS_LITERAL_STRING("notifypaintevent"));
|
|
|
|
}
|
|
|
|
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::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)
|
2014-02-28 06:58:43 -08:00
|
|
|
NotifyPaintEvent::Deserialize(const IPC::Message* aMsg, void** aIter)
|
2009-11-17 06:22:23 -08:00
|
|
|
{
|
2014-03-04 16:37:43 -08:00
|
|
|
NS_ENSURE_TRUE(Event::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
|
|
|
}
|
|
|
|
|
2014-02-28 06:58:43 -08:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2008-09-18 02:47:21 -07:00
|
|
|
|
2014-02-28 06:58:43 -08:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewDOMNotifyPaintEvent(nsIDOMEvent** aInstancePtrResult,
|
|
|
|
EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetEvent* aEvent,
|
|
|
|
uint32_t aEventType,
|
|
|
|
nsInvalidateRequestList* aInvalidateRequests)
|
|
|
|
{
|
|
|
|
NotifyPaintEvent* it = new NotifyPaintEvent(aOwner, aPresContext, aEvent,
|
|
|
|
aEventType, aInvalidateRequests);
|
2014-03-17 13:00:11 -07:00
|
|
|
NS_ADDREF(it);
|
|
|
|
*aInstancePtrResult = static_cast<Event*>(it);
|
|
|
|
return NS_OK;
|
2008-09-18 02:47:21 -07:00
|
|
|
}
|