2001-09-25 01:32:19 +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/. */
|
1998-06-07 07:55:55 +00:00
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
#ifndef mozilla_dom_Event_h_
|
|
|
|
#define mozilla_dom_Event_h_
|
1998-06-07 07:55:55 +00:00
|
|
|
|
2013-05-29 20:43:41 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-09-25 11:21:22 +00:00
|
|
|
#include "mozilla/BasicEvents.h"
|
2004-08-20 18:09:19 +00:00
|
|
|
#include "nsIDOMEvent.h"
|
1998-06-07 07:55:55 +00:00
|
|
|
#include "nsISupports.h"
|
2003-03-04 01:51:16 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2004-09-04 19:28:46 +00:00
|
|
|
#include "nsPIDOMWindow.h"
|
1998-06-07 07:55:55 +00:00
|
|
|
#include "nsPoint.h"
|
2007-06-26 08:21:42 +00:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2010-04-10 20:10:12 +00:00
|
|
|
#include "nsAutoPtr.h"
|
2013-03-09 11:34:29 +00:00
|
|
|
#include "mozilla/dom/EventBinding.h"
|
|
|
|
#include "nsIScriptGlobalObject.h"
|
2013-07-10 09:55:05 +00:00
|
|
|
#include "Units.h"
|
2013-08-28 02:59:14 +00:00
|
|
|
#include "js/TypeDecls.h"
|
2003-03-04 01:51:16 +00:00
|
|
|
|
1998-06-23 21:53:02 +00:00
|
|
|
class nsIContent;
|
2013-08-19 10:15:55 +00:00
|
|
|
class nsIDOMEventTarget;
|
2010-04-10 20:10:12 +00:00
|
|
|
class nsPresContext;
|
2013-03-09 11:34:29 +00:00
|
|
|
|
2013-08-19 10:15:55 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2014-03-05 00:37:43 +00:00
|
|
|
|
2013-08-19 10:15:55 +00:00
|
|
|
class EventTarget;
|
2014-02-23 05:01:12 +00:00
|
|
|
class ErrorEvent;
|
2014-06-03 22:52:36 +00:00
|
|
|
class ProgressEvent;
|
2014-10-15 14:48:04 +00:00
|
|
|
class WantsPopupControlCheck;
|
2013-08-19 10:15:55 +00:00
|
|
|
|
2013-04-12 14:51:25 +00:00
|
|
|
// Dummy class so we can cast through it to get from nsISupports to
|
2014-03-05 00:37:43 +00:00
|
|
|
// Event subclasses with only two non-ambiguous static casts.
|
|
|
|
class EventBase : public nsIDOMEvent
|
2013-04-12 14:51:25 +00:00
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
class Event : public EventBase,
|
|
|
|
public nsWrapperCache
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
{
|
2013-06-20 14:13:52 +00:00
|
|
|
public:
|
2014-03-05 00:37:43 +00:00
|
|
|
Event(EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetEvent* aEvent);
|
2014-08-05 13:19:51 +00:00
|
|
|
explicit Event(nsPIDOMWindow* aWindow);
|
2014-06-23 19:56:07 +00:00
|
|
|
|
|
|
|
protected:
|
2014-03-05 00:37:43 +00:00
|
|
|
virtual ~Event();
|
|
|
|
|
2013-05-08 00:55:21 +00:00
|
|
|
private:
|
2014-03-05 00:37:43 +00:00
|
|
|
void ConstructorInit(EventTarget* aOwner,
|
2013-10-02 03:46:04 +00:00
|
|
|
nsPresContext* aPresContext,
|
2014-03-05 00:37:43 +00:00
|
|
|
WidgetEvent* aEvent);
|
|
|
|
|
1998-07-23 02:55:33 +00:00
|
|
|
public:
|
2013-03-09 11:34:29 +00:00
|
|
|
void GetParentObject(nsIScriptGlobalObject** aParentObject)
|
|
|
|
{
|
|
|
|
if (mOwner) {
|
|
|
|
CallQueryInterface(mOwner, aParentObject);
|
|
|
|
} else {
|
|
|
|
*aParentObject = nullptr;
|
|
|
|
}
|
|
|
|
}
|
2001-12-06 06:57:03 +00:00
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
static Event* FromSupports(nsISupports* aSupports)
|
2013-03-09 11:34:29 +00:00
|
|
|
{
|
|
|
|
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
|
2014-03-05 00:37:43 +00:00
|
|
|
return static_cast<Event*>(event);
|
2013-03-09 11:34:29 +00:00
|
|
|
}
|
|
|
|
|
2007-06-26 08:21:42 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2014-03-05 00:37:43 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Event)
|
2013-03-09 11:34:29 +00:00
|
|
|
|
|
|
|
nsISupports* GetParentObject()
|
|
|
|
{
|
|
|
|
return mOwner;
|
|
|
|
}
|
|
|
|
|
2014-10-17 23:16:58 +00:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE MOZ_FINAL;
|
|
|
|
|
|
|
|
virtual JSObject* WrapObjectInternal(JSContext* aCx);
|
1998-06-07 07:55:55 +00:00
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
virtual ErrorEvent* AsErrorEvent()
|
2014-02-23 05:01:12 +00:00
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-06-03 22:52:36 +00:00
|
|
|
virtual ProgressEvent* AsProgressEvent()
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
1999-11-03 07:11:45 +00:00
|
|
|
// nsIDOMEvent Interface
|
2001-12-06 06:57:03 +00:00
|
|
|
NS_DECL_NSIDOMEVENT
|
|
|
|
|
2011-12-14 19:53:48 +00:00
|
|
|
void InitPresContextData(nsPresContext* aPresContext);
|
|
|
|
|
2013-03-13 20:02:32 +00:00
|
|
|
// Returns true if the event should be trusted.
|
2014-03-05 00:37:43 +00:00
|
|
|
bool Init(EventTarget* aGlobal);
|
2013-03-13 20:02:32 +00:00
|
|
|
|
2014-10-15 14:48:04 +00:00
|
|
|
static PopupControlState GetEventPopupControlState(WidgetEvent* aEvent,
|
|
|
|
nsIDOMEvent* aDOMEvent = nullptr);
|
2004-09-04 19:28:46 +00:00
|
|
|
|
|
|
|
static void PopupAllowedEventsChanged();
|
|
|
|
|
|
|
|
static void Shutdown();
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
static const char* GetEventName(uint32_t aEventType);
|
2014-03-05 00:37:43 +00:00
|
|
|
static CSSIntPoint GetClientCoords(nsPresContext* aPresContext,
|
|
|
|
WidgetEvent* aEvent,
|
|
|
|
LayoutDeviceIntPoint aPoint,
|
|
|
|
CSSIntPoint aDefaultPoint);
|
|
|
|
static CSSIntPoint GetPageCoords(nsPresContext* aPresContext,
|
|
|
|
WidgetEvent* aEvent,
|
|
|
|
LayoutDeviceIntPoint aPoint,
|
|
|
|
CSSIntPoint aDefaultPoint);
|
|
|
|
static nsIntPoint GetScreenCoords(nsPresContext* aPresContext,
|
|
|
|
WidgetEvent* aEvent,
|
|
|
|
LayoutDeviceIntPoint aPoint);
|
|
|
|
|
|
|
|
static already_AddRefed<Event> Constructor(const GlobalObject& aGlobal,
|
|
|
|
const nsAString& aType,
|
|
|
|
const EventInit& aParam,
|
|
|
|
ErrorResult& aRv);
|
2013-03-09 11:34:29 +00:00
|
|
|
|
|
|
|
// Implemented as xpidl method
|
|
|
|
// void GetType(nsString& aRetval) {}
|
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
EventTarget* GetTarget() const;
|
|
|
|
EventTarget* GetCurrentTarget() const;
|
2013-03-09 11:34:29 +00:00
|
|
|
|
2013-03-17 07:55:17 +00:00
|
|
|
uint16_t EventPhase() const;
|
2013-03-09 11:34:29 +00:00
|
|
|
|
|
|
|
// xpidl implementation
|
|
|
|
// void StopPropagation();
|
|
|
|
|
|
|
|
// xpidl implementation
|
|
|
|
// void StopImmediatePropagation();
|
|
|
|
|
2013-03-17 07:55:17 +00:00
|
|
|
bool Bubbles() const
|
2013-03-09 11:34:29 +00:00
|
|
|
{
|
2013-03-17 07:55:17 +00:00
|
|
|
return mEvent->mFlags.mBubbles;
|
2013-03-09 11:34:29 +00:00
|
|
|
}
|
|
|
|
|
2013-03-17 07:55:17 +00:00
|
|
|
bool Cancelable() const
|
2013-03-09 11:34:29 +00:00
|
|
|
{
|
2013-03-17 07:55:17 +00:00
|
|
|
return mEvent->mFlags.mCancelable;
|
2013-03-09 11:34:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// xpidl implementation
|
|
|
|
// void PreventDefault();
|
|
|
|
|
2013-12-08 15:51:16 +00:00
|
|
|
// You MUST NOT call PreventDefaultJ(JSContext*) from C++ code. A call of
|
|
|
|
// this method always sets Event.defaultPrevented true for web contents.
|
|
|
|
// If default action handler calls this, web applications meet wrong
|
|
|
|
// defaultPrevented value.
|
|
|
|
void PreventDefault(JSContext* aCx);
|
|
|
|
|
|
|
|
// You MUST NOT call DefaultPrevented(JSContext*) from C++ code. This may
|
|
|
|
// return false even if PreventDefault() has been called.
|
|
|
|
// See comments in its implementation for the detail.
|
|
|
|
bool DefaultPrevented(JSContext* aCx) const;
|
|
|
|
|
2013-03-17 07:55:17 +00:00
|
|
|
bool DefaultPrevented() const
|
2013-03-09 11:34:29 +00:00
|
|
|
{
|
2013-12-08 15:51:16 +00:00
|
|
|
return mEvent->mFlags.mDefaultPrevented;
|
2013-03-09 11:34:29 +00:00
|
|
|
}
|
|
|
|
|
2013-03-17 07:55:17 +00:00
|
|
|
bool MultipleActionsPrevented() const
|
2013-03-12 11:28:17 +00:00
|
|
|
{
|
|
|
|
return mEvent->mFlags.mMultipleActionsPrevented;
|
|
|
|
}
|
|
|
|
|
2013-03-17 07:55:17 +00:00
|
|
|
bool IsTrusted() const
|
2013-03-09 11:34:29 +00:00
|
|
|
{
|
2013-03-17 07:55:17 +00:00
|
|
|
return mEvent->mFlags.mIsTrusted;
|
2013-03-09 11:34:29 +00:00
|
|
|
}
|
|
|
|
|
2014-01-15 14:28:04 +00:00
|
|
|
bool IsSynthesized() const
|
|
|
|
{
|
|
|
|
return mEvent->mFlags.mIsSynthesizedForTests;
|
|
|
|
}
|
|
|
|
|
2014-06-06 05:29:49 +00:00
|
|
|
double TimeStamp() const;
|
2013-03-09 11:34:29 +00:00
|
|
|
|
|
|
|
void InitEvent(const nsAString& aType, bool aBubbles, bool aCancelable,
|
2014-03-05 00:37:43 +00:00
|
|
|
ErrorResult& aRv)
|
2013-03-09 11:34:29 +00:00
|
|
|
{
|
|
|
|
aRv = InitEvent(aType, aBubbles, aCancelable);
|
|
|
|
}
|
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
EventTarget* GetOriginalTarget() const;
|
|
|
|
EventTarget* GetExplicitOriginalTarget() const;
|
2013-03-09 11:34:29 +00:00
|
|
|
|
2013-05-27 14:43:51 +00:00
|
|
|
bool GetPreventDefault() const;
|
2013-03-09 11:34:29 +00:00
|
|
|
|
2014-03-21 17:46:15 +00:00
|
|
|
/**
|
|
|
|
* @param aCalledByDefaultHandler Should be true when this is called by
|
|
|
|
* C++ or Chrome. Otherwise, e.g., called
|
|
|
|
* by a call of Event.preventDefault() in
|
|
|
|
* content script, false.
|
|
|
|
*/
|
|
|
|
void PreventDefaultInternal(bool aCalledByDefaultHandler);
|
|
|
|
|
|
|
|
bool IsMainThreadEvent()
|
|
|
|
{
|
|
|
|
return mIsMainThreadEvent;
|
|
|
|
}
|
|
|
|
|
2014-08-27 03:19:56 +00:00
|
|
|
/**
|
|
|
|
* For a given current target, returns the related target adjusted with
|
|
|
|
* shadow DOM retargeting rules. Returns nullptr if related target
|
|
|
|
* is not adjusted.
|
|
|
|
*/
|
|
|
|
static nsIContent* GetShadowRelatedTarget(nsIContent* aCurrentTarget,
|
|
|
|
nsIContent* aRelatedTarget);
|
|
|
|
|
1998-06-07 07:55:55 +00:00
|
|
|
protected:
|
|
|
|
|
2004-08-20 18:09:19 +00:00
|
|
|
// Internal helper functions
|
2012-07-18 10:36:08 +00:00
|
|
|
void SetEventType(const nsAString& aEventTypeArg);
|
2010-06-11 11:10:51 +00:00
|
|
|
already_AddRefed<nsIContent> GetTargetFromFrame();
|
2000-05-05 14:47:37 +00:00
|
|
|
|
2014-10-15 14:48:04 +00:00
|
|
|
friend class WantsPopupControlCheck;
|
|
|
|
void SetWantsPopupControlCheck(bool aCheck)
|
|
|
|
{
|
|
|
|
mWantsPopupControlCheck = aCheck;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GetWantsPopupControlCheck()
|
|
|
|
{
|
|
|
|
return IsTrusted() && mWantsPopupControlCheck;
|
|
|
|
}
|
|
|
|
|
2013-12-08 15:51:16 +00:00
|
|
|
/**
|
|
|
|
* IsChrome() returns true if aCx is chrome context or the event is created
|
|
|
|
* in chrome's thread. Otherwise, false.
|
|
|
|
*/
|
|
|
|
bool IsChrome(JSContext* aCx) const;
|
|
|
|
|
2013-10-02 03:46:04 +00:00
|
|
|
mozilla::WidgetEvent* mEvent;
|
2010-03-25 13:17:11 +00:00
|
|
|
nsRefPtr<nsPresContext> mPresContext;
|
2014-03-05 00:37:43 +00:00
|
|
|
nsCOMPtr<EventTarget> mExplicitOriginalTarget;
|
2013-03-09 11:34:29 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> mOwner; // nsPIDOMWindow for now.
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mEventIsInternal;
|
|
|
|
bool mPrivateDataDuplicated;
|
2013-08-16 10:06:24 +00:00
|
|
|
bool mIsMainThreadEvent;
|
2014-10-15 14:48:04 +00:00
|
|
|
// True when popup control check should rely on event.type, not
|
|
|
|
// WidgetEvent.message.
|
|
|
|
bool mWantsPopupControlCheck;
|
|
|
|
};
|
|
|
|
|
|
|
|
class MOZ_STACK_CLASS WantsPopupControlCheck
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
WantsPopupControlCheck(nsIDOMEvent* aEvent) : mEvent(aEvent->InternalDOMEvent())
|
|
|
|
{
|
|
|
|
mOriginalWantsPopupControlCheck = mEvent->GetWantsPopupControlCheck();
|
|
|
|
mEvent->SetWantsPopupControlCheck(mEvent->IsTrusted());
|
|
|
|
}
|
|
|
|
|
|
|
|
~WantsPopupControlCheck()
|
|
|
|
{
|
|
|
|
mEvent->SetWantsPopupControlCheck(mOriginalWantsPopupControlCheck);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Event* mEvent;
|
|
|
|
bool mOriginalWantsPopupControlCheck;
|
1998-06-07 07:55:55 +00:00
|
|
|
};
|
1998-07-23 02:55:33 +00:00
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#define NS_FORWARD_TO_EVENT \
|
|
|
|
NS_FORWARD_NSIDOMEVENT(Event::)
|
2004-08-20 18:09:19 +00:00
|
|
|
|
2012-06-10 18:14:30 +00: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 15:56:38 +00:00
|
|
|
NS_IMETHOD GetEventPhase(uint16_t *aEventPhase) { return _to GetEventPhase(aEventPhase); } \
|
2012-06-10 18:14:30 +00: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 07:44:00 +00: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 18:14:30 +00:00
|
|
|
NS_IMETHOD SetTarget(nsIDOMEventTarget *aTarget) { return _to SetTarget(aTarget); } \
|
|
|
|
NS_IMETHOD_(bool) IsDispatchStopped(void) { return _to IsDispatchStopped(); } \
|
2014-03-05 00:37:43 +00:00
|
|
|
NS_IMETHOD_(WidgetEvent*) GetInternalNSEvent(void) { return _to GetInternalNSEvent(); } \
|
2013-03-09 11:34:29 +00:00
|
|
|
NS_IMETHOD_(void) SetTrusted(bool aTrusted) { _to SetTrusted(aTrusted); } \
|
2014-03-05 00:37:43 +00:00
|
|
|
NS_IMETHOD_(void) SetOwner(EventTarget* aOwner) { _to SetOwner(aOwner); } \
|
|
|
|
NS_IMETHOD_(Event*) InternalDOMEvent() { return _to InternalDOMEvent(); }
|
2012-06-10 18:14:30 +00:00
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
#define NS_FORWARD_TO_EVENT_NO_SERIALIZATION_NO_DUPLICATION \
|
|
|
|
NS_FORWARD_NSIDOMEVENT_NO_SERIALIZATION_NO_DUPLICATION(Event::)
|
2012-06-10 18:14:30 +00:00
|
|
|
|
2013-03-09 11:34:29 +00:00
|
|
|
inline nsISupports*
|
2014-03-05 00:37:43 +00:00
|
|
|
ToSupports(mozilla::dom::Event* e)
|
2013-03-09 11:34:29 +00:00
|
|
|
{
|
|
|
|
return static_cast<nsIDOMEvent*>(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline nsISupports*
|
2014-03-05 00:37:43 +00:00
|
|
|
ToCanonicalSupports(mozilla::dom::Event* e)
|
2013-03-09 11:34:29 +00:00
|
|
|
{
|
|
|
|
return static_cast<nsIDOMEvent*>(e);
|
|
|
|
}
|
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
#endif // mozilla_dom_Event_h_
|