2008-09-18 09:47:21 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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 09:47:21 +00:00
|
|
|
|
2009-11-17 14:22:23 +00:00
|
|
|
#include "base/basictypes.h"
|
2012-08-28 12:41:04 +00:00
|
|
|
#include "ipc/IPCMessageUtils.h"
|
2014-02-28 14:58:43 +00:00
|
|
|
#include "mozilla/dom/DOMRect.h"
|
|
|
|
#include "mozilla/dom/NotifyPaintEvent.h"
|
2014-04-03 04:18:37 +00:00
|
|
|
#include "mozilla/dom/PaintRequest.h"
|
2013-07-26 19:28:31 +00:00
|
|
|
#include "mozilla/GfxMessageUtils.h"
|
2008-09-18 09:47:21 +00:00
|
|
|
#include "nsContentUtils.h"
|
2013-09-20 10:21:03 +00:00
|
|
|
|
2014-02-28 14:58:43 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2008-09-18 09:47:21 +00:00
|
|
|
|
2014-02-28 14:58:43 +00:00
|
|
|
NotifyPaintEvent::NotifyPaintEvent(EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetEvent* aEvent,
|
|
|
|
uint32_t aEventType,
|
|
|
|
nsInvalidateRequestList* aInvalidateRequests)
|
2014-03-05 00:37:43 +00:00
|
|
|
: Event(aOwner, aPresContext, aEvent)
|
2009-06-23 09:09:05 +00:00
|
|
|
{
|
|
|
|
if (mEvent) {
|
|
|
|
mEvent->message = aEventType;
|
2008-09-18 09:47:21 +00:00
|
|
|
}
|
2009-09-04 04:49:18 +00:00
|
|
|
if (aInvalidateRequests) {
|
2012-10-19 04:50:34 +00:00
|
|
|
mInvalidateRequests.MoveElementsFrom(aInvalidateRequests->mRequests);
|
2008-09-18 09:47:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-28 14:58:43 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN(NotifyPaintEvent)
|
2008-09-18 09:47:21 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMNotifyPaintEvent)
|
2014-03-05 00:37:43 +00:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(Event)
|
2008-09-18 09:47:21 +00:00
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
NS_IMPL_ADDREF_INHERITED(NotifyPaintEvent, Event)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(NotifyPaintEvent, Event)
|
2008-09-18 09:47:21 +00:00
|
|
|
|
|
|
|
nsRegion
|
2014-02-28 14:58:43 +00:00
|
|
|
NotifyPaintEvent::GetRegion()
|
2008-09-18 09:47:21 +00:00
|
|
|
{
|
|
|
|
nsRegion r;
|
2012-10-25 23:10:53 +00:00
|
|
|
if (!nsContentUtils::IsCallerChrome()) {
|
2012-08-29 05:47:18 +00:00
|
|
|
return r;
|
|
|
|
}
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < mInvalidateRequests.Length(); ++i) {
|
2009-09-04 04:49:18 +00:00
|
|
|
r.Or(r, mInvalidateRequests[i].mRect);
|
|
|
|
r.SimplifyOutward(10);
|
2008-09-18 09:47:21 +00:00
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-28 14:58:43 +00:00
|
|
|
NotifyPaintEvent::GetBoundingClientRect(nsIDOMClientRect** aResult)
|
2013-04-15 20:27:37 +00:00
|
|
|
{
|
2014-03-15 19:00:15 +00:00
|
|
|
*aResult = BoundingClientRect().take();
|
2013-04-15 20:27:37 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-09-20 10:21:03 +00:00
|
|
|
already_AddRefed<DOMRect>
|
2014-02-28 14:58:43 +00:00
|
|
|
NotifyPaintEvent::BoundingClientRect()
|
2008-09-18 09:47:21 +00:00
|
|
|
{
|
2013-09-20 10:21:03 +00:00
|
|
|
nsRefPtr<DOMRect> rect = new DOMRect(ToSupports(this));
|
2008-09-18 09:47:21 +00:00
|
|
|
|
2013-03-17 07:55:17 +00:00
|
|
|
if (mPresContext) {
|
|
|
|
rect->SetLayoutRect(GetRegion().GetBounds());
|
|
|
|
}
|
2008-09-18 09:47:21 +00:00
|
|
|
|
2013-04-15 20:27:37 +00:00
|
|
|
return rect.forget();
|
2008-09-18 09:47:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-28 14:58:43 +00:00
|
|
|
NotifyPaintEvent::GetClientRects(nsIDOMClientRectList** aResult)
|
2013-04-15 20:27:37 +00:00
|
|
|
{
|
2014-03-15 19:00:15 +00:00
|
|
|
*aResult = ClientRects().take();
|
2013-04-15 20:27:37 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-09-20 10:21:03 +00:00
|
|
|
already_AddRefed<DOMRectList>
|
2014-02-28 14:58:43 +00:00
|
|
|
NotifyPaintEvent::ClientRects()
|
2008-09-18 09:47:21 +00:00
|
|
|
{
|
2013-03-17 07:55:17 +00:00
|
|
|
nsISupports* parent = ToSupports(this);
|
2013-09-20 10:21:03 +00:00
|
|
|
nsRefPtr<DOMRectList> rectList = new DOMRectList(parent);
|
2008-09-18 09:47:21 +00:00
|
|
|
|
|
|
|
nsRegion r = GetRegion();
|
|
|
|
nsRegionRectIterator iter(r);
|
|
|
|
for (const nsRect* rgnRect = iter.Next(); rgnRect; rgnRect = iter.Next()) {
|
2013-09-20 10:21:03 +00:00
|
|
|
nsRefPtr<DOMRect> rect = new DOMRect(parent);
|
2008-09-18 09:47:21 +00:00
|
|
|
|
2009-09-04 04:49:18 +00:00
|
|
|
rect->SetLayoutRect(*rgnRect);
|
2008-09-18 09:47:21 +00:00
|
|
|
rectList->Append(rect);
|
|
|
|
}
|
|
|
|
|
2013-04-15 20:27:37 +00:00
|
|
|
return rectList.forget();
|
2009-09-04 04:49:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-28 14:58:43 +00:00
|
|
|
NotifyPaintEvent::GetPaintRequests(nsISupports** aResult)
|
2009-09-04 04:49:18 +00:00
|
|
|
{
|
2014-04-03 04:18:37 +00:00
|
|
|
nsRefPtr<PaintRequestList> requests = PaintRequests();
|
2012-12-22 08:16:55 +00:00
|
|
|
requests.forget(aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-04-03 04:18:37 +00:00
|
|
|
already_AddRefed<PaintRequestList>
|
2014-02-28 14:58:43 +00:00
|
|
|
NotifyPaintEvent::PaintRequests()
|
2012-12-22 08:16:55 +00:00
|
|
|
{
|
2014-03-05 00:37:43 +00:00
|
|
|
Event* parent = this;
|
2014-04-03 04:18:37 +00:00
|
|
|
nsRefPtr<PaintRequestList> requests = new PaintRequestList(parent);
|
2009-09-04 04:49:18 +00:00
|
|
|
|
2012-10-25 23:10:53 +00:00
|
|
|
if (nsContentUtils::IsCallerChrome()) {
|
2012-08-29 05:47:18 +00:00
|
|
|
for (uint32_t i = 0; i < mInvalidateRequests.Length(); ++i) {
|
2014-04-03 04:18:37 +00:00
|
|
|
nsRefPtr<PaintRequest> r = new PaintRequest(parent);
|
2012-08-29 05:47:18 +00:00
|
|
|
r->SetRequest(mInvalidateRequests[i]);
|
|
|
|
requests->Append(r);
|
|
|
|
}
|
2009-09-04 04:49:18 +00:00
|
|
|
}
|
|
|
|
|
2012-12-22 08:16:55 +00:00
|
|
|
return requests.forget();
|
2008-09-18 09:47:21 +00:00
|
|
|
}
|
|
|
|
|
2012-06-10 23:44:50 +00:00
|
|
|
NS_IMETHODIMP_(void)
|
2014-02-28 14:58:43 +00:00
|
|
|
NotifyPaintEvent::Serialize(IPC::Message* aMsg,
|
|
|
|
bool aSerializeInterfaceType)
|
2009-11-17 14:22:23 +00:00
|
|
|
{
|
|
|
|
if (aSerializeInterfaceType) {
|
|
|
|
IPC::WriteParam(aMsg, NS_LITERAL_STRING("notifypaintevent"));
|
|
|
|
}
|
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
Event::Serialize(aMsg, false);
|
2009-11-17 14:22:23 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t length = mInvalidateRequests.Length();
|
2009-11-17 14:22:23 +00:00
|
|
|
IPC::WriteParam(aMsg, length);
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
2013-03-12 17:26:48 +00:00
|
|
|
IPC::WriteParam(aMsg, mInvalidateRequests[i].mRect);
|
2009-11-17 14:22:23 +00:00
|
|
|
IPC::WriteParam(aMsg, mInvalidateRequests[i].mFlags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-10 23:44:50 +00:00
|
|
|
NS_IMETHODIMP_(bool)
|
2014-02-28 14:58:43 +00:00
|
|
|
NotifyPaintEvent::Deserialize(const IPC::Message* aMsg, void** aIter)
|
2009-11-17 14:22:23 +00:00
|
|
|
{
|
2014-03-05 00:37:43 +00:00
|
|
|
NS_ENSURE_TRUE(Event::Deserialize(aMsg, aIter), false);
|
2009-11-17 14:22:23 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t length = 0;
|
2011-10-17 14:59:28 +00:00
|
|
|
NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &length), false);
|
2009-11-17 14:22:23 +00:00
|
|
|
mInvalidateRequests.SetCapacity(length);
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
2009-11-17 14:22:23 +00:00
|
|
|
nsInvalidateRequestList::Request req;
|
2013-03-12 17:26:48 +00:00
|
|
|
NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &req.mRect), false);
|
2011-10-17 14:59:28 +00:00
|
|
|
NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &req.mFlags), false);
|
2009-11-17 14:22:23 +00:00
|
|
|
mInvalidateRequests.AppendElement(req);
|
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2009-11-17 14:22:23 +00:00
|
|
|
}
|
|
|
|
|
2014-02-28 14:58:43 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2008-09-18 09:47:21 +00:00
|
|
|
|
2014-02-28 14:58:43 +00: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 20:00:11 +00:00
|
|
|
NS_ADDREF(it);
|
|
|
|
*aInstancePtrResult = static_cast<Event*>(it);
|
|
|
|
return NS_OK;
|
2008-09-18 09:47:21 +00:00
|
|
|
}
|