2007-03-22 10:30:00 -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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef nsDOMEvent_h__
|
|
|
|
#define nsDOMEvent_h__
|
|
|
|
|
|
|
|
#include "nsIDOMEvent.h"
|
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIDOMEventTarget.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsPoint.h"
|
|
|
|
#include "nsGUIEvent.h"
|
2007-06-26 01:21:42 -07:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2010-04-10 13:10:12 -07:00
|
|
|
#include "nsAutoPtr.h"
|
2011-12-14 11:53:48 -08:00
|
|
|
#include "nsIJSNativeInitializer.h"
|
2013-03-09 03:34:29 -08:00
|
|
|
#include "mozilla/dom/EventTarget.h"
|
|
|
|
#include "mozilla/dom/EventBinding.h"
|
|
|
|
#include "nsIScriptGlobalObject.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class nsIContent;
|
2010-04-10 13:10:12 -07:00
|
|
|
class nsPresContext;
|
2011-12-15 00:48:09 -08:00
|
|
|
struct JSContext;
|
2012-12-31 12:40:21 -08:00
|
|
|
class JSObject;
|
2013-03-09 03:34:29 -08:00
|
|
|
|
2013-04-12 07:51:25 -07:00
|
|
|
// Dummy class so we can cast through it to get from nsISupports to
|
|
|
|
// nsDOMEvent subclasses with only two non-ambiguous static casts.
|
|
|
|
class nsDOMEventBase : public nsIDOMEvent
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
class nsDOMEvent : public nsDOMEventBase,
|
2013-03-09 03:34:29 -08:00
|
|
|
public nsIJSNativeInitializer,
|
|
|
|
public nsWrapperCache
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-03-09 03:34:29 -08:00
|
|
|
protected:
|
|
|
|
nsDOMEvent(mozilla::dom::EventTarget* aOwner, nsPresContext* aPresContext,
|
|
|
|
nsEvent* aEvent);
|
2013-05-07 17:55:21 -07:00
|
|
|
nsDOMEvent(nsPIDOMWindow* aWindow);
|
2013-03-09 03:34:29 -08:00
|
|
|
virtual ~nsDOMEvent();
|
2013-05-07 17:55:21 -07:00
|
|
|
private:
|
|
|
|
void ConstructorInit(mozilla::dom::EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext, nsEvent* aEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
2013-03-09 03:34:29 -08:00
|
|
|
void GetParentObject(nsIScriptGlobalObject** aParentObject)
|
|
|
|
{
|
|
|
|
if (mOwner) {
|
|
|
|
CallQueryInterface(mOwner, aParentObject);
|
|
|
|
} else {
|
|
|
|
*aParentObject = nullptr;
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-03-09 03:34:29 -08:00
|
|
|
static nsDOMEvent* FromSupports(nsISupports* aSupports)
|
|
|
|
{
|
|
|
|
nsIDOMEvent* event =
|
|
|
|
static_cast<nsIDOMEvent*>(aSupports);
|
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMEvent> target_qi =
|
|
|
|
do_QueryInterface(aSupports);
|
|
|
|
|
|
|
|
// If this assertion fires the QI implementation for the object in
|
|
|
|
// question doesn't use the nsIDOMEvent pointer as the
|
|
|
|
// nsISupports pointer. That must be fixed, or we'll crash...
|
|
|
|
MOZ_ASSERT(target_qi == event, "Uh, fix QI!");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return static_cast<nsDOMEvent*>(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
static already_AddRefed<nsDOMEvent> CreateEvent(mozilla::dom::EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
nsEvent* aEvent)
|
|
|
|
{
|
|
|
|
nsRefPtr<nsDOMEvent> e = new nsDOMEvent(aOwner, aPresContext, aEvent);
|
|
|
|
e->SetIsDOMBinding();
|
|
|
|
return e.forget();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-06-26 01:21:42 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2013-03-09 03:34:29 -08:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsDOMEvent, nsIDOMEvent)
|
|
|
|
|
|
|
|
nsISupports* GetParentObject()
|
|
|
|
{
|
|
|
|
return mOwner;
|
|
|
|
}
|
|
|
|
|
2013-04-25 09:29:54 -07:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aScope) MOZ_OVERRIDE
|
2013-03-09 03:34:29 -08:00
|
|
|
{
|
2013-03-11 16:03:47 -07:00
|
|
|
return mozilla::dom::EventBinding::Wrap(aCx, aScope, this);
|
2013-03-09 03:34:29 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// nsIDOMEvent Interface
|
|
|
|
NS_DECL_NSIDOMEVENT
|
|
|
|
|
2011-12-14 11:53:48 -08:00
|
|
|
// nsIJSNativeInitializer
|
|
|
|
NS_IMETHOD Initialize(nsISupports* aOwner, JSContext* aCx, JSObject* aObj,
|
2013-05-29 14:56:10 -07:00
|
|
|
const JS::CallArgs& aArgs);
|
2011-12-14 11:53:48 -08:00
|
|
|
|
2011-12-23 14:13:46 -08:00
|
|
|
virtual nsresult InitFromCtor(const nsAString& aType,
|
2013-03-16 16:39:51 -07:00
|
|
|
JSContext* aCx, JS::Value* aVal);
|
2011-12-14 11:53:48 -08:00
|
|
|
|
|
|
|
void InitPresContextData(nsPresContext* aPresContext);
|
|
|
|
|
2013-03-13 13:02:32 -07:00
|
|
|
// Returns true if the event should be trusted.
|
|
|
|
bool Init(mozilla::dom::EventTarget* aGlobal);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static PopupControlState GetEventPopupControlState(nsEvent *aEvent);
|
|
|
|
|
|
|
|
static void PopupAllowedEventsChanged();
|
|
|
|
|
|
|
|
static void Shutdown();
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static const char* GetEventName(uint32_t aEventType);
|
2011-12-16 16:24:11 -08:00
|
|
|
static nsIntPoint GetClientCoords(nsPresContext* aPresContext,
|
|
|
|
nsEvent* aEvent,
|
|
|
|
nsIntPoint aPoint,
|
|
|
|
nsIntPoint aDefaultPoint);
|
|
|
|
static nsIntPoint GetPageCoords(nsPresContext* aPresContext,
|
|
|
|
nsEvent* aEvent,
|
|
|
|
nsIntPoint aPoint,
|
|
|
|
nsIntPoint aDefaultPoint);
|
|
|
|
static nsIntPoint GetScreenCoords(nsPresContext* aPresContext,
|
|
|
|
nsEvent* aEvent,
|
|
|
|
nsIntPoint aPoint);
|
2013-03-09 03:34:29 -08:00
|
|
|
|
|
|
|
static already_AddRefed<nsDOMEvent> Constructor(const mozilla::dom::GlobalObject& aGlobal,
|
|
|
|
const nsAString& aType,
|
|
|
|
const mozilla::dom::EventInit& aParam,
|
|
|
|
mozilla::ErrorResult& aRv);
|
|
|
|
|
|
|
|
// Implemented as xpidl method
|
|
|
|
// void GetType(nsString& aRetval) {}
|
|
|
|
|
2013-03-17 00:55:17 -07:00
|
|
|
mozilla::dom::EventTarget* GetTarget() const;
|
|
|
|
mozilla::dom::EventTarget* GetCurrentTarget() const;
|
2013-03-09 03:34:29 -08:00
|
|
|
|
2013-03-17 00:55:17 -07:00
|
|
|
uint16_t EventPhase() const;
|
2013-03-09 03:34:29 -08:00
|
|
|
|
|
|
|
// xpidl implementation
|
|
|
|
// void StopPropagation();
|
|
|
|
|
|
|
|
// xpidl implementation
|
|
|
|
// void StopImmediatePropagation();
|
|
|
|
|
2013-03-17 00:55:17 -07:00
|
|
|
bool Bubbles() const
|
2013-03-09 03:34:29 -08:00
|
|
|
{
|
2013-03-17 00:55:17 -07:00
|
|
|
return mEvent->mFlags.mBubbles;
|
2013-03-09 03:34:29 -08:00
|
|
|
}
|
|
|
|
|
2013-03-17 00:55:17 -07:00
|
|
|
bool Cancelable() const
|
2013-03-09 03:34:29 -08:00
|
|
|
{
|
2013-03-17 00:55:17 -07:00
|
|
|
return mEvent->mFlags.mCancelable;
|
2013-03-09 03:34:29 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// xpidl implementation
|
|
|
|
// void PreventDefault();
|
|
|
|
|
2013-03-17 00:55:17 -07:00
|
|
|
bool DefaultPrevented() const
|
2013-03-09 03:34:29 -08:00
|
|
|
{
|
2013-03-17 00:55:17 -07:00
|
|
|
return mEvent && mEvent->mFlags.mDefaultPrevented;
|
2013-03-09 03:34:29 -08:00
|
|
|
}
|
|
|
|
|
2013-03-17 00:55:17 -07:00
|
|
|
bool MultipleActionsPrevented() const
|
2013-03-12 04:28:17 -07:00
|
|
|
{
|
|
|
|
return mEvent->mFlags.mMultipleActionsPrevented;
|
|
|
|
}
|
|
|
|
|
2013-03-17 00:55:17 -07:00
|
|
|
bool IsTrusted() const
|
2013-03-09 03:34:29 -08:00
|
|
|
{
|
2013-03-17 00:55:17 -07:00
|
|
|
return mEvent->mFlags.mIsTrusted;
|
2013-03-09 03:34:29 -08:00
|
|
|
}
|
|
|
|
|
2013-03-17 00:55:17 -07:00
|
|
|
uint64_t TimeStamp() const
|
2013-03-09 03:34:29 -08:00
|
|
|
{
|
2013-03-17 00:55:17 -07:00
|
|
|
return mEvent->time;
|
2013-03-09 03:34:29 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void InitEvent(const nsAString& aType, bool aBubbles, bool aCancelable,
|
|
|
|
mozilla::ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
aRv = InitEvent(aType, aBubbles, aCancelable);
|
|
|
|
}
|
|
|
|
|
2013-03-17 00:55:17 -07:00
|
|
|
mozilla::dom::EventTarget* GetOriginalTarget() const;
|
|
|
|
mozilla::dom::EventTarget* GetExplicitOriginalTarget() const;
|
2013-03-09 03:34:29 -08:00
|
|
|
|
2013-05-27 07:43:51 -07:00
|
|
|
bool GetPreventDefault() const;
|
2013-03-09 03:34:29 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
|
|
|
|
|
|
|
// Internal helper functions
|
2012-07-18 03:36:08 -07:00
|
|
|
void SetEventType(const nsAString& aEventTypeArg);
|
2010-06-11 04:10:51 -07:00
|
|
|
already_AddRefed<nsIContent> GetTargetFromFrame();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsEvent* mEvent;
|
2010-03-25 06:17:11 -07:00
|
|
|
nsRefPtr<nsPresContext> mPresContext;
|
2013-03-17 00:55:17 -07:00
|
|
|
nsCOMPtr<mozilla::dom::EventTarget> mExplicitOriginalTarget;
|
2013-03-09 03:34:29 -08:00
|
|
|
nsCOMPtr<nsPIDOMWindow> mOwner; // nsPIDOMWindow for now.
|
2009-10-24 08:06:01 -07:00
|
|
|
nsString mCachedType;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mEventIsInternal;
|
|
|
|
bool mPrivateDataDuplicated;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#define NS_FORWARD_TO_NSDOMEVENT \
|
|
|
|
NS_FORWARD_NSIDOMEVENT(nsDOMEvent::)
|
|
|
|
|
2012-06-10 11:14:30 -07:00
|
|
|
#define NS_FORWARD_NSIDOMEVENT_NO_SERIALIZATION_NO_DUPLICATION(_to) \
|
|
|
|
NS_IMETHOD GetType(nsAString& aType){ return _to GetType(aType); } \
|
|
|
|
NS_IMETHOD GetTarget(nsIDOMEventTarget * *aTarget) { return _to GetTarget(aTarget); } \
|
|
|
|
NS_IMETHOD GetCurrentTarget(nsIDOMEventTarget * *aCurrentTarget) { return _to GetCurrentTarget(aCurrentTarget); } \
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD GetEventPhase(uint16_t *aEventPhase) { return _to GetEventPhase(aEventPhase); } \
|
2012-06-10 11:14:30 -07:00
|
|
|
NS_IMETHOD GetBubbles(bool *aBubbles) { return _to GetBubbles(aBubbles); } \
|
|
|
|
NS_IMETHOD GetCancelable(bool *aCancelable) { return _to GetCancelable(aCancelable); } \
|
|
|
|
NS_IMETHOD GetTimeStamp(DOMTimeStamp *aTimeStamp) { return _to GetTimeStamp(aTimeStamp); } \
|
|
|
|
NS_IMETHOD StopPropagation(void) { return _to StopPropagation(); } \
|
|
|
|
NS_IMETHOD PreventDefault(void) { return _to PreventDefault(); } \
|
|
|
|
NS_IMETHOD InitEvent(const nsAString & eventTypeArg, bool canBubbleArg, bool cancelableArg) { return _to InitEvent(eventTypeArg, canBubbleArg, cancelableArg); } \
|
|
|
|
NS_IMETHOD GetDefaultPrevented(bool *aDefaultPrevented) { return _to GetDefaultPrevented(aDefaultPrevented); } \
|
|
|
|
NS_IMETHOD StopImmediatePropagation(void) { return _to StopImmediatePropagation(); } \
|
2012-08-04 00:44:00 -07:00
|
|
|
NS_IMETHOD GetOriginalTarget(nsIDOMEventTarget** aOriginalTarget) { return _to GetOriginalTarget(aOriginalTarget); } \
|
|
|
|
NS_IMETHOD GetExplicitOriginalTarget(nsIDOMEventTarget** aExplicitOriginalTarget) { return _to GetExplicitOriginalTarget(aExplicitOriginalTarget); } \
|
|
|
|
NS_IMETHOD GetPreventDefault(bool* aRetval) { return _to GetPreventDefault(aRetval); } \
|
|
|
|
NS_IMETHOD GetIsTrusted(bool* aIsTrusted) { return _to GetIsTrusted(aIsTrusted); } \
|
2012-06-10 11:14:30 -07:00
|
|
|
NS_IMETHOD SetTarget(nsIDOMEventTarget *aTarget) { return _to SetTarget(aTarget); } \
|
|
|
|
NS_IMETHOD_(bool) IsDispatchStopped(void) { return _to IsDispatchStopped(); } \
|
|
|
|
NS_IMETHOD_(nsEvent *) GetInternalNSEvent(void) { return _to GetInternalNSEvent(); } \
|
2013-03-09 03:34:29 -08:00
|
|
|
NS_IMETHOD_(void) SetTrusted(bool aTrusted) { _to SetTrusted(aTrusted); } \
|
|
|
|
NS_IMETHOD_(void) SetOwner(mozilla::dom::EventTarget* aOwner) { _to SetOwner(aOwner); } \
|
|
|
|
NS_IMETHOD_(nsDOMEvent *) InternalDOMEvent(void) { return _to InternalDOMEvent(); }
|
2012-06-10 11:14:30 -07:00
|
|
|
|
|
|
|
#define NS_FORWARD_TO_NSDOMEVENT_NO_SERIALIZATION_NO_DUPLICATION \
|
|
|
|
NS_FORWARD_NSIDOMEVENT_NO_SERIALIZATION_NO_DUPLICATION(nsDOMEvent::)
|
|
|
|
|
2013-03-09 03:34:29 -08:00
|
|
|
inline nsISupports*
|
|
|
|
ToSupports(nsDOMEvent* e)
|
|
|
|
{
|
|
|
|
return static_cast<nsIDOMEvent*>(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline nsISupports*
|
|
|
|
ToCanonicalSupports(nsDOMEvent* e)
|
|
|
|
{
|
|
|
|
return static_cast<nsIDOMEvent*>(e);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif // nsDOMEvent_h__
|