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
|
|
|
|
2014-03-04 16:37:43 -08:00
|
|
|
#ifndef mozilla_dom_Event_h_
|
|
|
|
#define mozilla_dom_Event_h_
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-05-29 13:43:41 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-09-25 04:21:22 -07:00
|
|
|
#include "mozilla/BasicEvents.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMEvent.h"
|
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsPoint.h"
|
2007-06-26 01:21:42 -07:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2010-04-10 13:10:12 -07:00
|
|
|
#include "nsAutoPtr.h"
|
2013-03-09 03:34:29 -08:00
|
|
|
#include "mozilla/dom/EventBinding.h"
|
|
|
|
#include "nsIScriptGlobalObject.h"
|
2013-07-10 02:55:05 -07:00
|
|
|
#include "Units.h"
|
2013-08-27 19:59:14 -07:00
|
|
|
#include "js/TypeDecls.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class nsIContent;
|
2013-08-19 03:15:55 -07:00
|
|
|
class nsIDOMEventTarget;
|
2010-04-10 13:10:12 -07:00
|
|
|
class nsPresContext;
|
2013-03-09 03:34:29 -08:00
|
|
|
|
2013-08-19 03:15:55 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2014-03-04 16:37:43 -08:00
|
|
|
|
2013-08-19 03:15:55 -07:00
|
|
|
class EventTarget;
|
2014-02-22 21:01:12 -08:00
|
|
|
class ErrorEvent;
|
2014-06-03 15:52:36 -07:00
|
|
|
class ProgressEvent;
|
2013-08-19 03:15:55 -07:00
|
|
|
|
2013-04-12 07:51:25 -07:00
|
|
|
// Dummy class so we can cast through it to get from nsISupports to
|
2014-03-04 16:37:43 -08:00
|
|
|
// Event subclasses with only two non-ambiguous static casts.
|
|
|
|
class EventBase : public nsIDOMEvent
|
2013-04-12 07:51:25 -07:00
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2014-03-04 16:37:43 -08:00
|
|
|
class Event : public EventBase,
|
|
|
|
public nsWrapperCache
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-06-20 07:13:52 -07:00
|
|
|
public:
|
2014-03-04 16:37:43 -08:00
|
|
|
Event(EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetEvent* aEvent);
|
2014-08-05 06:19:51 -07:00
|
|
|
explicit Event(nsPIDOMWindow* aWindow);
|
2014-06-23 12:56:07 -07:00
|
|
|
|
|
|
|
protected:
|
2014-03-04 16:37:43 -08:00
|
|
|
virtual ~Event();
|
|
|
|
|
2013-05-07 17:55:21 -07:00
|
|
|
private:
|
2014-03-04 16:37:43 -08:00
|
|
|
void ConstructorInit(EventTarget* aOwner,
|
2013-10-01 20:46:04 -07:00
|
|
|
nsPresContext* aPresContext,
|
2014-03-04 16:37:43 -08:00
|
|
|
WidgetEvent* 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
|
|
|
|
2014-03-04 16:37:43 -08:00
|
|
|
static Event* FromSupports(nsISupports* aSupports)
|
2013-03-09 03:34:29 -08: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-04 16:37:43 -08:00
|
|
|
return static_cast<Event*>(event);
|
2013-03-09 03:34:29 -08:00
|
|
|
}
|
|
|
|
|
2007-06-26 01:21:42 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2014-03-04 16:37:43 -08:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Event)
|
2013-03-09 03:34:29 -08:00
|
|
|
|
|
|
|
nsISupports* GetParentObject()
|
|
|
|
{
|
|
|
|
return mOwner;
|
|
|
|
}
|
|
|
|
|
2014-04-08 15:27:18 -07:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE
|
2013-03-09 03:34:29 -08:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 15:27:17 -07:00
|
|
|
return EventBinding::Wrap(aCx, this);
|
2013-03-09 03:34:29 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-03-04 16:37:43 -08:00
|
|
|
virtual ErrorEvent* AsErrorEvent()
|
2014-02-22 21:01:12 -08:00
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-06-03 15:52:36 -07:00
|
|
|
virtual ProgressEvent* AsProgressEvent()
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsIDOMEvent Interface
|
|
|
|
NS_DECL_NSIDOMEVENT
|
|
|
|
|
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.
|
2014-03-04 16:37:43 -08:00
|
|
|
bool Init(EventTarget* aGlobal);
|
2013-03-13 13:02:32 -07:00
|
|
|
|
2014-03-04 16:37:43 -08:00
|
|
|
static PopupControlState GetEventPopupControlState(WidgetEvent* aEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
static void PopupAllowedEventsChanged();
|
|
|
|
|
|
|
|
static void Shutdown();
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static const char* GetEventName(uint32_t aEventType);
|
2014-03-04 16:37:43 -08: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 03:34:29 -08:00
|
|
|
|
|
|
|
// Implemented as xpidl method
|
|
|
|
// void GetType(nsString& aRetval) {}
|
|
|
|
|
2014-03-04 16:37:43 -08:00
|
|
|
EventTarget* GetTarget() const;
|
|
|
|
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-12-08 07:51:16 -08: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 00:55:17 -07:00
|
|
|
bool DefaultPrevented() const
|
2013-03-09 03:34:29 -08:00
|
|
|
{
|
2013-12-08 07:51:16 -08:00
|
|
|
return 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
|
|
|
}
|
|
|
|
|
2014-01-15 06:28:04 -08:00
|
|
|
bool IsSynthesized() const
|
|
|
|
{
|
|
|
|
return mEvent->mFlags.mIsSynthesizedForTests;
|
|
|
|
}
|
|
|
|
|
2014-06-05 22:29:49 -07:00
|
|
|
double TimeStamp() const;
|
2013-03-09 03:34:29 -08:00
|
|
|
|
|
|
|
void InitEvent(const nsAString& aType, bool aBubbles, bool aCancelable,
|
2014-03-04 16:37:43 -08:00
|
|
|
ErrorResult& aRv)
|
2013-03-09 03:34:29 -08:00
|
|
|
{
|
|
|
|
aRv = InitEvent(aType, aBubbles, aCancelable);
|
|
|
|
}
|
|
|
|
|
2014-03-04 16:37:43 -08:00
|
|
|
EventTarget* GetOriginalTarget() const;
|
|
|
|
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
|
|
|
|
2014-03-21 10:46:15 -07: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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2013-12-08 07:51:16 -08: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-01 20:46:04 -07:00
|
|
|
mozilla::WidgetEvent* mEvent;
|
2010-03-25 06:17:11 -07:00
|
|
|
nsRefPtr<nsPresContext> mPresContext;
|
2014-03-04 16:37:43 -08:00
|
|
|
nsCOMPtr<EventTarget> mExplicitOriginalTarget;
|
2013-03-09 03:34:29 -08:00
|
|
|
nsCOMPtr<nsPIDOMWindow> mOwner; // nsPIDOMWindow for now.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mEventIsInternal;
|
|
|
|
bool mPrivateDataDuplicated;
|
2013-08-16 03:06:24 -07:00
|
|
|
bool mIsMainThreadEvent;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2014-03-04 16:37:43 -08:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#define NS_FORWARD_TO_EVENT \
|
|
|
|
NS_FORWARD_NSIDOMEVENT(Event::)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
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(); } \
|
2014-03-04 16:37:43 -08:00
|
|
|
NS_IMETHOD_(WidgetEvent*) GetInternalNSEvent(void) { return _to GetInternalNSEvent(); } \
|
2013-03-09 03:34:29 -08:00
|
|
|
NS_IMETHOD_(void) SetTrusted(bool aTrusted) { _to SetTrusted(aTrusted); } \
|
2014-03-04 16:37:43 -08:00
|
|
|
NS_IMETHOD_(void) SetOwner(EventTarget* aOwner) { _to SetOwner(aOwner); } \
|
|
|
|
NS_IMETHOD_(Event*) InternalDOMEvent() { return _to InternalDOMEvent(); }
|
2012-06-10 11:14:30 -07:00
|
|
|
|
2014-03-04 16:37:43 -08:00
|
|
|
#define NS_FORWARD_TO_EVENT_NO_SERIALIZATION_NO_DUPLICATION \
|
|
|
|
NS_FORWARD_NSIDOMEVENT_NO_SERIALIZATION_NO_DUPLICATION(Event::)
|
2012-06-10 11:14:30 -07:00
|
|
|
|
2013-03-09 03:34:29 -08:00
|
|
|
inline nsISupports*
|
2014-03-04 16:37:43 -08:00
|
|
|
ToSupports(mozilla::dom::Event* e)
|
2013-03-09 03:34:29 -08:00
|
|
|
{
|
|
|
|
return static_cast<nsIDOMEvent*>(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline nsISupports*
|
2014-03-04 16:37:43 -08:00
|
|
|
ToCanonicalSupports(mozilla::dom::Event* e)
|
2013-03-09 03:34:29 -08:00
|
|
|
{
|
|
|
|
return static_cast<nsIDOMEvent*>(e);
|
|
|
|
}
|
|
|
|
|
2014-03-04 16:37:43 -08:00
|
|
|
#endif // mozilla_dom_Event_h_
|