Bug 818263. Make the EventTarget binding work for nodes. r=smaug,peterv

This commit is contained in:
Boris Zbarsky 2012-12-06 20:39:51 -05:00
Родитель 0900957c01
Коммит 66a25e5fa2
7 изменённых файлов: 78 добавлений и 33 удалений

Просмотреть файл

@ -19,7 +19,7 @@
#include "nsPropertyTable.h" // for typedefs
#include "nsTObserverArray.h" // for member
#include "nsWindowMemoryReporter.h" // for NS_DECL_SIZEOF_EXCLUDING_THIS
#include "nsWrapperCache.h" // for base class
#include "mozilla/dom/EventTarget.h" // for base class
// Including 'windows.h' will #define GetClassInfo to something else.
#ifdef XP_WIN
@ -267,8 +267,7 @@ private:
* nsIContent and nsIDocument share. An instance of this interface has a list
* of nsIContent children and provides access to them.
*/
class nsINode : public nsIDOMEventTarget,
public nsWrapperCache
class nsINode : public mozilla::dom::EventTarget
{
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_INODE_IID)

Просмотреть файл

@ -0,0 +1,62 @@
/* -*- 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/. */
#ifndef mozilla_dom_EventTarget_h_
#define mozilla_dom_EventTarget_h_
#include "nsIDOMEventTarget.h"
#include "nsWrapperCache.h"
#include "nsIDOMEventListener.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/Nullable.h"
#include "nsIDOMEvent.h"
namespace mozilla {
namespace dom {
// IID for the dom::Element interface
#define NS_EVENTTARGET_IID \
{ 0x0a5aed21, 0x0bab, 0x48b3, \
{ 0xbe, 0x4b, 0xd4, 0xf9, 0xd4, 0xea, 0xc7, 0xdb } }
class EventTarget : public nsIDOMEventTarget,
public nsWrapperCache
{
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_EVENTTARGET_IID)
// WebIDL API
using nsIDOMEventTarget::AddEventListener;
using nsIDOMEventTarget::RemoveEventListener;
using nsIDOMEventTarget::DispatchEvent;
void AddEventListener(const nsAString& aType,
nsIDOMEventListener* aCallback, // XXX nullable
bool aCapture, const Nullable<bool>& aWantsUntrusted,
mozilla::ErrorResult& aRv)
{
aRv = AddEventListener(aType, aCallback, aCapture,
!aWantsUntrusted.IsNull() && aWantsUntrusted.Value(),
aWantsUntrusted.IsNull() ? 1 : 2);
}
void RemoveEventListener(const nsAString& aType,
nsIDOMEventListener* aCallback,
bool aCapture, mozilla::ErrorResult& aRv)
{
aRv = RemoveEventListener(aType, aCallback, aCapture);
}
bool DispatchEvent(nsIDOMEvent* aEvent, mozilla::ErrorResult& aRv)
{
bool result = false;
aRv = DispatchEvent(aEvent, &result);
return result;
}
};
NS_DEFINE_STATIC_IID_ACCESSOR(EventTarget, NS_EVENTTARGET_IID)
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_EventTarget_h_

Просмотреть файл

@ -24,6 +24,12 @@ EXPORTS = \
nsVKList.h \
$(NULL)
EXPORTS_NAMESPACES = mozilla/dom
EXPORTS_mozilla/dom = \
EventTarget.h \
$(NULL)
XPIDLSRCS = \
nsIEventListenerService.idl \
$(NULL)

Просмотреть файл

@ -8,21 +8,17 @@
#include "nsCOMPtr.h"
#include "nsGkAtoms.h"
#include "nsIDOMEventTarget.h"
#include "nsIDOMEventListener.h"
#include "nsCycleCollectionParticipant.h"
#include "nsPIDOMWindow.h"
#include "nsIScriptGlobalObject.h"
#include "nsEventListenerManager.h"
#include "nsIScriptContext.h"
#include "nsWrapperCache.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/Attributes.h"
#include "mozilla/dom/EventTarget.h"
class nsDOMEvent;
class nsDOMEventTargetHelper : public nsIDOMEventTarget,
public nsWrapperCache
class nsDOMEventTargetHelper : public mozilla::dom::EventTarget
{
public:
nsDOMEventTargetHelper() : mOwner(nullptr), mHasOrHasHadOwner(false) {}
@ -31,27 +27,6 @@ public:
NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS(nsDOMEventTargetHelper)
NS_DECL_NSIDOMEVENTTARGET
void AddEventListener(const nsAString& aType,
nsIDOMEventListener* aCallback, // XXX nullable
bool aCapture, const Nullable<bool>& aWantsUntrusted,
mozilla::ErrorResult& aRv)
{
aRv = AddEventListener(aType, aCallback, aCapture,
!aWantsUntrusted.IsNull() && aWantsUntrusted.Value(),
aWantsUntrusted.IsNull() ? 1 : 2);
}
void RemoveEventListener(const nsAString& aType,
nsIDOMEventListener* aCallback,
bool aCapture, mozilla::ErrorResult& aRv)
{
aRv = RemoveEventListener(aType, aCallback, aCapture);
}
bool DispatchEvent(nsIDOMEvent* aEvent, mozilla::ErrorResult& aRv)
{
bool result = false;
aRv = DispatchEvent(aEvent, &result);
return result;
}
void GetParentObject(nsIScriptGlobalObject **aParentObject)
{

Просмотреть файл

@ -51,6 +51,9 @@ enum nsDOMClassInfoID {
DOMCI_CASTABLE_INTERFACE(nsINode, nsINode, 0, _extra) \
DOMCI_CASTABLE_NODECL_INTERFACE(mozilla::dom::Element, mozilla::dom::Element,\
1, _extra) \
/* If this is ever removed, the IID for EventTarget can go away */ \
DOMCI_CASTABLE_NODECL_INTERFACE(mozilla::dom::EventTarget, \
mozilla::dom::EventTarget, 2, _extra) \
DOMCI_CASTABLE_INTERFACE(nsDocument, nsIDocument, 5, _extra) \
DOMCI_CASTABLE_INTERFACE(nsGenericHTMLElement, nsGenericHTMLElement, 6, \
_extra) \
@ -68,6 +71,7 @@ DOMCI_CASTABLE_INTERFACES(unused)
namespace mozilla {
namespace dom {
class Element;
class EventTarget;
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -221,10 +221,9 @@ DOMInterfaces = {
'EventTarget': [
{
'nativeType': 'nsDOMEventTargetHelper',
'hasInstanceInterface': 'nsIDOMEventTarget',
'hasXPConnectImpls': True,
'concrete': False,
'prefable': True,
},
{
'workers': True,

Просмотреть файл

@ -53,7 +53,7 @@ USING_WORKERS_NAMESPACE
namespace {
class WorkerGlobalScope : public EventTarget
class WorkerGlobalScope : public workers::EventTarget
{
static JSClass sClass;
static JSPropertySpec sProperties[];