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