Bug 796902 - Part c: Implement Paris bindings for PaintRequest; r=bent

This commit is contained in:
Ms2ger 2012-12-22 09:16:55 +01:00
parent af323be25f
commit b12f9b6da2
9 changed files with 86 additions and 26 deletions

View File

@ -92,24 +92,26 @@ nsDOMNotifyPaintEvent::GetClientRects(nsIDOMClientRectList** aResult)
NS_IMETHODIMP
nsDOMNotifyPaintEvent::GetPaintRequests(nsIDOMPaintRequestList** aResult)
{
nsRefPtr<nsPaintRequestList> requests =
new nsPaintRequestList(static_cast<nsDOMEvent*>(this));
if (!requests)
return NS_ERROR_OUT_OF_MEMORY;
nsRefPtr<nsPaintRequestList> requests = PaintRequests();
requests.forget(aResult);
return NS_OK;
}
already_AddRefed<nsPaintRequestList>
nsDOMNotifyPaintEvent::PaintRequests()
{
nsDOMEvent* parent = this;
nsRefPtr<nsPaintRequestList> requests = new nsPaintRequestList(parent);
if (nsContentUtils::IsCallerChrome()) {
for (uint32_t i = 0; i < mInvalidateRequests.Length(); ++i) {
nsRefPtr<nsPaintRequest> r = new nsPaintRequest();
if (!r)
return NS_ERROR_OUT_OF_MEMORY;
nsRefPtr<nsPaintRequest> r = new nsPaintRequest(parent);
r->SetRequest(mInvalidateRequests[i]);
requests->Append(r);
}
}
requests.forget(aResult);
return NS_OK;
return requests.forget();
}
NS_IMETHODIMP_(void)

View File

@ -33,6 +33,9 @@ public:
}
NS_IMETHOD_(void) Serialize(IPC::Message* aMsg, bool aSerializeInterfaceType);
NS_IMETHOD_(bool) Deserialize(const IPC::Message* aMsg, void** aIter);
already_AddRefed<nsPaintRequestList> PaintRequests();
private:
nsRegion GetRegion();

View File

@ -1,4 +1,4 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
@ -6,11 +6,14 @@
#include "nsPaintRequest.h"
#include "nsDOMClassInfoID.h"
#include "nsClientRect.h"
#include "nsIFrame.h"
#include "nsContentUtils.h"
#include "mozilla/dom/PaintRequestBinding.h"
#include "mozilla/dom/PaintRequestListBinding.h"
using namespace mozilla;
using namespace mozilla::dom;
DOMCI_DATA(PaintRequest, nsPaintRequest)
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(nsPaintRequest, mParent)
@ -28,25 +31,29 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(nsPaintRequest)
/* virtual */ JSObject*
nsPaintRequest::WrapObject(JSContext* aCx, JSObject* aScope, bool* aTriedToWrap)
{
*aTriedToWrap = false;
return nullptr;
return PaintRequestBinding::Wrap(aCx, aScope, this, aTriedToWrap);
}
already_AddRefed<nsClientRect>
nsPaintRequest::ClientRect()
{
nsRefPtr<nsClientRect> clientRect = new nsClientRect();
clientRect->SetLayoutRect(mRequest.mRect);
return clientRect.forget();
}
NS_IMETHODIMP
nsPaintRequest::GetClientRect(nsIDOMClientRect** aResult)
{
nsRefPtr<nsClientRect> clientRect = new nsClientRect();
if (!clientRect)
return NS_ERROR_OUT_OF_MEMORY;
clientRect->SetLayoutRect(mRequest.mRect);
nsRefPtr<nsClientRect> clientRect = ClientRect();
clientRect.forget(aResult);
return NS_OK;
}
NS_IMETHODIMP
nsPaintRequest::GetReason(nsAString& aResult)
nsPaintRequest::GetXPCOMReason(nsAString& aResult)
{
aResult.AssignLiteral("repaint");
GetReason(aResult);
return NS_OK;
}

View File

@ -1,4 +1,4 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
@ -11,12 +11,20 @@
#include "nsPresContext.h"
#include "nsIDOMEvent.h"
#include "mozilla/Attributes.h"
#include "nsClientRect.h"
#include "nsWrapperCache.h"
class nsPaintRequest MOZ_FINAL : public nsIDOMPaintRequest
, public nsWrapperCache
{
public:
nsPaintRequest(nsIDOMEvent* aParent)
: mParent(aParent)
{
mRequest.mFlags = 0;
SetIsDOMBinding();
}
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsPaintRequest)
NS_DECL_NSIDOMPAINTREQUEST
@ -24,7 +32,16 @@ public:
virtual JSObject* WrapObject(JSContext* aCx, JSObject* aScope,
bool* aTriedToWrap) MOZ_OVERRIDE;
nsPaintRequest() { mRequest.mFlags = 0; }
nsIDOMEvent* GetParentObject() const
{
return mParent;
}
already_AddRefed<nsClientRect> ClientRect();
void GetReason(nsAString& aResult) const
{
aResult.AssignLiteral("repaint");
}
void SetRequest(const nsInvalidateRequestList::Request& aRequest)
{ mRequest = aRequest; }
@ -32,6 +49,7 @@ public:
private:
~nsPaintRequest() {}
nsCOMPtr<nsIDOMEvent> mParent;
nsInvalidateRequestList::Request mRequest;
};

View File

@ -375,6 +375,11 @@ DOMInterfaces = {
'resultNotAddRefed': [ 'item' ]
},
'PaintRequest': {
'nativeType': 'nsPaintRequest',
'prefable': True
},
'PaintRequestList': {
'nativeType': 'nsPaintRequestList',
'headerFile': 'nsPaintRequest.h',
@ -812,7 +817,6 @@ addExternalIface('MediaStream')
addExternalIface('NamedNodeMap')
addExternalIface('OutputStream', nativeType='nsIOutputStream',
notflattened=True)
addExternalIface('PaintRequest')
addExternalIface('Principal', nativeType='nsIPrincipal',
headerFile='nsIPrincipal.h', notflattened=True)
addExternalIface('SVGLength')

View File

@ -11,7 +11,7 @@ interface nsIDOMClientRect;
* These objects are exposed by the MozDOMAfterPaint event. Each one represents
* a request to repaint a rectangle that was generated by the browser.
*/
[scriptable, uuid(4802360b-f1c0-4d84-bb9e-9d2ccb9de461)]
[scriptable, uuid(9eb5268f-73a4-41da-9790-d21fcefd5ffa)]
interface nsIDOMPaintRequest : nsISupports
{
/**
@ -25,5 +25,6 @@ interface nsIDOMPaintRequest : nsISupports
* that we updated the rectangle due to scrolling but instead of painting
* manually, we were able to do a copy from another area of the screen.
*/
[binaryname(XPCOMReason)]
readonly attribute DOMString reason;
};

View File

@ -0,0 +1,26 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
interface ClientRect;
/**
* These objects are exposed by the MozDOMAfterPaint event. Each one represents
* a request to repaint a rectangle that was generated by the browser.
*/
interface PaintRequest {
/**
* The client rect where invalidation was triggered.
*/
readonly attribute ClientRect clientRect;
/**
* The reason for the request, as a string. If an empty string, then we don't know
* the reason (this is common). Reasons include "scroll repaint", meaning that we
* needed to repaint the rectangle due to scrolling, and "scroll copy", meaning
* that we updated the rectangle due to scrolling but instead of painting
* manually, we were able to do a copy from another area of the screen.
*/
readonly attribute DOMString reason;
};

View File

@ -4,8 +4,6 @@
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
interface PaintRequest;
interface PaintRequestList {
readonly attribute unsigned long length;
getter PaintRequest? item(unsigned long index);

View File

@ -52,6 +52,7 @@ webidl_files = \
Node.webidl \
NodeFilter.webidl \
NodeList.webidl \
PaintRequest.webidl \
PaintRequestList.webidl \
PannerNode.webidl \
Performance.webidl \