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
|
|
|
|
2013-12-08 07:51:16 -08:00
|
|
|
#include "AccessCheck.h"
|
2014-03-04 16:37:43 -08:00
|
|
|
#include "base/basictypes.h"
|
2012-08-28 05:41:04 -07:00
|
|
|
#include "ipc/IPCMessageUtils.h"
|
2014-03-04 16:37:43 -08:00
|
|
|
#include "mozilla/dom/Event.h"
|
2013-09-25 04:21:20 -07:00
|
|
|
#include "mozilla/ContentEvents.h"
|
2014-03-31 23:13:50 -07:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2014-03-31 21:09:23 -07:00
|
|
|
#include "mozilla/EventStateManager.h"
|
2014-02-27 02:51:15 -08:00
|
|
|
#include "mozilla/InternalMutationEvent.h"
|
2013-09-25 04:21:20 -07:00
|
|
|
#include "mozilla/MiscEvents.h"
|
2013-09-25 04:21:18 -07:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2014-03-04 16:37:43 -08:00
|
|
|
#include "mozilla/Preferences.h"
|
2013-09-25 04:21:19 -07:00
|
|
|
#include "mozilla/TextEvents.h"
|
2013-09-25 04:21:16 -07:00
|
|
|
#include "mozilla/TouchEvents.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsContentUtils.h"
|
2014-03-04 16:37:43 -08:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsDeviceContext.h"
|
|
|
|
#include "nsError.h"
|
|
|
|
#include "nsGlobalWindow.h"
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIScrollableFrame.h"
|
2013-03-07 10:53:19 -08:00
|
|
|
#include "nsJSEnvironment.h"
|
2011-12-16 16:24:11 -08:00
|
|
|
#include "nsLayoutUtils.h"
|
2014-06-05 22:29:49 -07:00
|
|
|
#include "nsPerformance.h"
|
2013-03-09 03:34:29 -08:00
|
|
|
#include "nsPIWindowRoot.h"
|
2014-06-05 22:29:49 -07:00
|
|
|
#include "WorkerPrivate.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-12-08 07:51:16 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2014-03-04 16:37:43 -08:00
|
|
|
|
2013-12-08 07:51:16 -08:00
|
|
|
namespace workers {
|
|
|
|
extern bool IsCurrentThreadRunningChromeWorker();
|
|
|
|
} // namespace workers
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static char *sPopupAllowedEvents;
|
|
|
|
|
2014-06-05 22:29:49 -07:00
|
|
|
static bool sReturnHighResTimeStamp = false;
|
|
|
|
static bool sReturnHighResTimeStampIsSet = false;
|
|
|
|
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::Event(EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetEvent* aEvent)
|
2013-05-07 17:55:21 -07:00
|
|
|
{
|
|
|
|
ConstructorInit(aOwner, aPresContext, aEvent);
|
|
|
|
}
|
|
|
|
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::Event(nsPIDOMWindow* aParent)
|
2013-05-07 17:55:21 -07:00
|
|
|
{
|
|
|
|
ConstructorInit(static_cast<nsGlobalWindow *>(aParent), nullptr, nullptr);
|
|
|
|
}
|
|
|
|
|
2013-06-20 07:13:52 -07:00
|
|
|
void
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::ConstructorInit(EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetEvent* aEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-06-20 07:13:52 -07:00
|
|
|
SetIsDOMBinding();
|
2013-03-09 03:34:29 -08:00
|
|
|
SetOwner(aOwner);
|
2013-08-16 03:06:24 -07:00
|
|
|
mIsMainThreadEvent = mOwner || NS_IsMainThread();
|
2013-11-18 08:58:02 -08:00
|
|
|
if (mIsMainThreadEvent) {
|
|
|
|
nsJSContext::LikelyShortLivingObjectCreated();
|
|
|
|
}
|
2013-03-09 03:34:29 -08:00
|
|
|
|
2014-06-05 22:29:49 -07:00
|
|
|
if (mIsMainThreadEvent && !sReturnHighResTimeStampIsSet) {
|
|
|
|
Preferences::AddBoolVarCache(&sReturnHighResTimeStamp,
|
|
|
|
"dom.event.highrestimestamp.enabled",
|
|
|
|
sReturnHighResTimeStamp);
|
|
|
|
sReturnHighResTimeStampIsSet = true;
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mPrivateDataDuplicated = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (aEvent) {
|
|
|
|
mEvent = aEvent;
|
2011-10-17 07:59:28 -07:00
|
|
|
mEventIsInternal = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
2011-10-17 07:59:28 -07:00
|
|
|
mEventIsInternal = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
|
|
|
A derived class might want to allocate its own type of aEvent
|
2013-10-01 20:46:04 -07:00
|
|
|
(derived from WidgetEvent). To do this, it should take care to pass
|
2013-04-02 18:14:24 -07:00
|
|
|
a non-nullptr aEvent to this ctor, e.g.:
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-03-04 16:37:43 -08:00
|
|
|
FooEvent::FooEvent(..., WidgetEvent* aEvent)
|
|
|
|
: Event(..., aEvent ? aEvent : new WidgetEvent())
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
Then, to override the mEventIsInternal assignments done by the
|
|
|
|
base ctor, it should do this in its own ctor:
|
|
|
|
|
2014-03-04 16:37:43 -08:00
|
|
|
FooEvent::FooEvent(..., WidgetEvent* aEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
...
|
|
|
|
{
|
|
|
|
...
|
|
|
|
if (aEvent) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mEventIsInternal = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
2011-10-17 07:59:28 -07:00
|
|
|
mEventIsInternal = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
...
|
|
|
|
}
|
|
|
|
*/
|
2013-10-01 20:46:04 -07:00
|
|
|
mEvent = new WidgetEvent(false, 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
mEvent->time = PR_Now();
|
|
|
|
}
|
|
|
|
|
2011-12-14 11:53:48 -08:00
|
|
|
InitPresContextData(aPresContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::InitPresContextData(nsPresContext* aPresContext)
|
2011-12-14 11:53:48 -08:00
|
|
|
{
|
|
|
|
mPresContext = aPresContext;
|
2007-03-22 10:30:00 -07:00
|
|
|
// Get the explicit original target (if it's anonymous make it null)
|
|
|
|
{
|
2010-06-11 04:10:51 -07:00
|
|
|
nsCOMPtr<nsIContent> content = GetTargetFromFrame();
|
2013-03-17 00:55:17 -07:00
|
|
|
mExplicitOriginalTarget = content;
|
2008-07-22 21:50:20 -07:00
|
|
|
if (content && content->IsInAnonymousSubtree()) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mExplicitOriginalTarget = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::~Event()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-03-04 16:37:43 -08:00
|
|
|
NS_ASSERT_OWNINGTHREAD(Event);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (mEventIsInternal && mEvent) {
|
|
|
|
delete mEvent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-04 16:37:43 -08:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Event)
|
2013-03-09 03:34:29 -08:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2013-06-20 07:13:52 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMEvent)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2014-03-04 16:37:43 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(Event)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(Event)
|
2007-06-26 01:21:42 -07:00
|
|
|
|
2014-03-04 16:37:43 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(Event)
|
2013-08-01 18:29:05 -07:00
|
|
|
|
2014-03-04 16:37:43 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(Event)
|
2013-03-09 03:34:29 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
2014-03-04 16:37:43 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Event)
|
2007-06-26 01:21:42 -07:00
|
|
|
if (tmp->mEventIsInternal) {
|
2012-07-30 07:20:58 -07:00
|
|
|
tmp->mEvent->target = nullptr;
|
|
|
|
tmp->mEvent->currentTarget = nullptr;
|
|
|
|
tmp->mEvent->originalTarget = nullptr;
|
2007-06-26 01:21:42 -07:00
|
|
|
switch (tmp->mEvent->eventStructType) {
|
|
|
|
case NS_MOUSE_EVENT:
|
|
|
|
case NS_MOUSE_SCROLL_EVENT:
|
2012-08-11 18:42:34 -07:00
|
|
|
case NS_WHEEL_EVENT:
|
2009-02-17 03:49:03 -08:00
|
|
|
case NS_SIMPLE_GESTURE_EVENT:
|
2013-11-20 21:44:31 -08:00
|
|
|
case NS_POINTER_EVENT:
|
2013-10-17 23:10:26 -07:00
|
|
|
tmp->mEvent->AsMouseEventBase()->relatedTarget = nullptr;
|
2007-06-26 01:21:42 -07:00
|
|
|
break;
|
2013-10-17 23:10:26 -07:00
|
|
|
case NS_DRAG_EVENT: {
|
|
|
|
WidgetDragEvent* dragEvent = tmp->mEvent->AsDragEvent();
|
|
|
|
dragEvent->dataTransfer = nullptr;
|
|
|
|
dragEvent->relatedTarget = nullptr;
|
2008-08-27 05:07:27 -07:00
|
|
|
break;
|
2013-10-17 23:10:26 -07:00
|
|
|
}
|
2013-03-11 08:49:48 -07:00
|
|
|
case NS_CLIPBOARD_EVENT:
|
2013-10-17 23:10:22 -07:00
|
|
|
tmp->mEvent->AsClipboardEvent()->clipboardData = nullptr;
|
2013-03-11 08:49:48 -07:00
|
|
|
break;
|
2007-06-26 01:21:42 -07:00
|
|
|
case NS_MUTATION_EVENT:
|
2013-10-17 23:10:22 -07:00
|
|
|
tmp->mEvent->AsMutationEvent()->mRelatedNode = nullptr;
|
2007-06-26 01:21:42 -07:00
|
|
|
break;
|
2013-06-05 05:02:51 -07:00
|
|
|
case NS_FOCUS_EVENT:
|
2013-10-17 23:10:22 -07:00
|
|
|
tmp->mEvent->AsFocusEvent()->relatedTarget = nullptr;
|
2013-06-05 05:02:51 -07:00
|
|
|
break;
|
2007-06-26 01:21:42 -07:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-14 23:32:40 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPresContext);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mExplicitOriginalTarget);
|
2013-03-09 03:34:29 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mOwner);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
2007-06-26 01:21:42 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2014-03-04 16:37:43 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Event)
|
2007-06-26 01:21:42 -07:00
|
|
|
if (tmp->mEventIsInternal) {
|
2012-11-14 23:32:40 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEvent->target)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEvent->currentTarget)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEvent->originalTarget)
|
2007-06-26 01:21:42 -07:00
|
|
|
switch (tmp->mEvent->eventStructType) {
|
|
|
|
case NS_MOUSE_EVENT:
|
|
|
|
case NS_MOUSE_SCROLL_EVENT:
|
2012-08-11 18:42:34 -07:00
|
|
|
case NS_WHEEL_EVENT:
|
2009-02-17 03:49:03 -08:00
|
|
|
case NS_SIMPLE_GESTURE_EVENT:
|
2013-11-20 21:44:31 -08:00
|
|
|
case NS_POINTER_EVENT:
|
2008-09-08 11:26:46 -07:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mEvent->relatedTarget");
|
2013-10-17 23:10:26 -07:00
|
|
|
cb.NoteXPCOMChild(tmp->mEvent->AsMouseEventBase()->relatedTarget);
|
2007-06-26 01:21:42 -07:00
|
|
|
break;
|
2013-10-17 23:10:26 -07:00
|
|
|
case NS_DRAG_EVENT: {
|
|
|
|
WidgetDragEvent* dragEvent = tmp->mEvent->AsDragEvent();
|
2008-09-08 11:26:46 -07:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mEvent->dataTransfer");
|
2013-10-17 23:10:26 -07:00
|
|
|
cb.NoteXPCOMChild(dragEvent->dataTransfer);
|
2009-02-17 03:49:03 -08:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mEvent->relatedTarget");
|
2013-10-17 23:10:26 -07:00
|
|
|
cb.NoteXPCOMChild(dragEvent->relatedTarget);
|
2008-08-27 05:07:27 -07:00
|
|
|
break;
|
2013-10-17 23:10:26 -07:00
|
|
|
}
|
2013-03-11 08:49:48 -07:00
|
|
|
case NS_CLIPBOARD_EVENT:
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mEvent->clipboardData");
|
2013-10-17 23:10:22 -07:00
|
|
|
cb.NoteXPCOMChild(tmp->mEvent->AsClipboardEvent()->clipboardData);
|
2013-03-11 08:49:48 -07:00
|
|
|
break;
|
2007-06-26 01:21:42 -07:00
|
|
|
case NS_MUTATION_EVENT:
|
2008-09-08 11:26:46 -07:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mEvent->mRelatedNode");
|
2013-10-17 23:10:22 -07:00
|
|
|
cb.NoteXPCOMChild(tmp->mEvent->AsMutationEvent()->mRelatedNode);
|
2007-06-26 01:21:42 -07:00
|
|
|
break;
|
2013-06-05 05:02:51 -07:00
|
|
|
case NS_FOCUS_EVENT:
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mEvent->relatedTarget");
|
2013-10-17 23:10:22 -07:00
|
|
|
cb.NoteXPCOMChild(tmp->mEvent->AsFocusEvent()->relatedTarget);
|
2013-06-05 05:02:51 -07:00
|
|
|
break;
|
2007-06-26 01:21:42 -07:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-14 23:32:39 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPresContext)
|
2012-11-14 23:32:40 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mExplicitOriginalTarget)
|
2013-03-09 03:34:29 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOwner)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
2007-06-26 01:21:42 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2013-12-08 07:51:16 -08:00
|
|
|
bool
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::IsChrome(JSContext* aCx) const
|
2013-12-08 07:51:16 -08:00
|
|
|
{
|
|
|
|
return mIsMainThreadEvent ?
|
|
|
|
xpc::AccessCheck::isChrome(js::GetContextCompartment(aCx)) :
|
|
|
|
mozilla::dom::workers::IsCurrentThreadRunningChromeWorker();
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsIDOMEventInterface
|
2014-03-04 16:37:43 -08:00
|
|
|
NS_METHOD
|
|
|
|
Event::GetType(nsAString& aType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-08-16 03:06:24 -07:00
|
|
|
if (!mIsMainThreadEvent || !mEvent->typeString.IsEmpty()) {
|
|
|
|
aType = mEvent->typeString;
|
2009-10-24 08:06:01 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
const char* name = GetEventName(mEvent->message);
|
|
|
|
|
|
|
|
if (name) {
|
|
|
|
CopyASCIItoUTF16(name, aType);
|
|
|
|
return NS_OK;
|
|
|
|
} else if (mEvent->message == NS_USER_DEFINED_EVENT && mEvent->userType) {
|
2010-03-08 07:45:00 -08:00
|
|
|
aType = Substring(nsDependentAtomString(mEvent->userType), 2); // Remove "on"
|
2013-08-16 03:06:24 -07:00
|
|
|
mEvent->typeString = aType;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-03-24 04:34:48 -07:00
|
|
|
|
|
|
|
aType.Truncate();
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-03-17 00:55:17 -07:00
|
|
|
static EventTarget*
|
|
|
|
GetDOMEventTarget(nsIDOMEventTarget* aTarget)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-03-17 00:55:17 -07:00
|
|
|
return aTarget ? aTarget->GetTargetForDOMEvent() : nullptr;
|
|
|
|
}
|
2011-06-23 19:18:01 -07:00
|
|
|
|
2013-03-17 00:55:17 -07:00
|
|
|
EventTarget*
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::GetTarget() const
|
2013-03-17 00:55:17 -07:00
|
|
|
{
|
|
|
|
return GetDOMEventTarget(mEvent->target);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-04-17 02:18:36 -07:00
|
|
|
NS_METHOD
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::GetTarget(nsIDOMEventTarget** aTarget)
|
2007-04-17 02:18:36 -07:00
|
|
|
{
|
2013-03-17 00:55:17 -07:00
|
|
|
NS_IF_ADDREF(*aTarget = GetTarget());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
EventTarget*
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::GetCurrentTarget() const
|
2013-03-17 00:55:17 -07:00
|
|
|
{
|
|
|
|
return GetDOMEventTarget(mEvent->currentTarget);
|
2007-04-17 02:18:36 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::GetCurrentTarget(nsIDOMEventTarget** aCurrentTarget)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-03-17 00:55:17 -07:00
|
|
|
NS_IF_ADDREF(*aCurrentTarget = GetCurrentTarget());
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get the actual event target node (may have been retargeted for mouse events)
|
|
|
|
//
|
2010-06-11 04:10:51 -07:00
|
|
|
already_AddRefed<nsIContent>
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::GetTargetFromFrame()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
if (!mPresContext) { return nullptr; }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Get the target frame (have to get the ESM first)
|
2011-04-21 10:35:52 -07:00
|
|
|
nsIFrame* targetFrame = mPresContext->EventStateManager()->GetEventTarget();
|
2012-07-30 07:20:58 -07:00
|
|
|
if (!targetFrame) { return nullptr; }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// get the real content
|
|
|
|
nsCOMPtr<nsIContent> realEventContent;
|
2011-09-26 13:55:04 -07:00
|
|
|
targetFrame->GetContentForEvent(mEvent, getter_AddRefs(realEventContent));
|
2010-06-11 04:10:51 -07:00
|
|
|
return realEventContent.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-03-17 00:55:17 -07:00
|
|
|
EventTarget*
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::GetExplicitOriginalTarget() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mExplicitOriginalTarget) {
|
2013-03-17 00:55:17 -07:00
|
|
|
return mExplicitOriginalTarget;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2013-03-17 00:55:17 -07:00
|
|
|
return GetTarget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::GetExplicitOriginalTarget(nsIDOMEventTarget** aRealEventTarget)
|
2013-03-17 00:55:17 -07:00
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aRealEventTarget = GetExplicitOriginalTarget());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
EventTarget*
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::GetOriginalTarget() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mEvent->originalTarget) {
|
2013-03-17 00:55:17 -07:00
|
|
|
return GetDOMEventTarget(mEvent->originalTarget);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-03-17 00:55:17 -07:00
|
|
|
return GetTarget();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::GetOriginalTarget(nsIDOMEventTarget** aOriginalTarget)
|
2013-03-17 00:55:17 -07:00
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aOriginalTarget = GetOriginalTarget());
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-12-22 00:18:08 -08:00
|
|
|
NS_IMETHODIMP_(void)
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::SetTrusted(bool aTrusted)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-12-15 17:26:03 -08:00
|
|
|
mEvent->mFlags.mIsTrusted = aTrusted;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-03-13 13:02:32 -07:00
|
|
|
bool
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::Init(mozilla::dom::EventTarget* aGlobal)
|
2013-03-09 03:34:29 -08:00
|
|
|
{
|
2013-08-30 02:47:19 -07:00
|
|
|
if (!mIsMainThreadEvent) {
|
|
|
|
return nsContentUtils::ThreadsafeIsCallerChrome();
|
|
|
|
}
|
2013-03-09 03:34:29 -08:00
|
|
|
bool trusted = false;
|
2013-03-13 13:02:32 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> w = do_QueryInterface(aGlobal);
|
2013-03-09 03:34:29 -08:00
|
|
|
if (w) {
|
2013-04-23 21:22:37 -07:00
|
|
|
nsCOMPtr<nsIDocument> d = w->GetExtantDoc();
|
2013-03-09 03:34:29 -08:00
|
|
|
if (d) {
|
|
|
|
trusted = nsContentUtils::IsChromeDoc(d);
|
|
|
|
nsIPresShell* s = d->GetShell();
|
|
|
|
if (s) {
|
2013-03-13 13:02:32 -07:00
|
|
|
InitPresContextData(s->GetPresContext());
|
2013-03-09 03:34:29 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-03-13 13:02:32 -07:00
|
|
|
return trusted;
|
|
|
|
}
|
|
|
|
|
2014-03-04 16:37:43 -08:00
|
|
|
// static
|
|
|
|
already_AddRefed<Event>
|
|
|
|
Event::Constructor(const GlobalObject& aGlobal,
|
|
|
|
const nsAString& aType,
|
|
|
|
const EventInit& aParam,
|
|
|
|
ErrorResult& aRv)
|
2013-03-13 13:02:32 -07:00
|
|
|
{
|
2013-08-22 22:17:08 -07:00
|
|
|
nsCOMPtr<mozilla::dom::EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports());
|
2014-03-04 16:37:43 -08:00
|
|
|
nsRefPtr<Event> e = new Event(t, nullptr, nullptr);
|
2013-03-13 13:02:32 -07:00
|
|
|
bool trusted = e->Init(t);
|
2013-03-09 03:34:29 -08:00
|
|
|
aRv = e->InitEvent(aType, aParam.mBubbles, aParam.mCancelable);
|
|
|
|
e->SetTrusted(trusted);
|
|
|
|
return e.forget();
|
|
|
|
}
|
|
|
|
|
2013-03-17 00:55:17 -07:00
|
|
|
uint16_t
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::EventPhase() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Note, remember to check that this works also
|
|
|
|
// if or when Bug 235441 is fixed.
|
2012-05-03 03:59:51 -07:00
|
|
|
if ((mEvent->currentTarget &&
|
|
|
|
mEvent->currentTarget == mEvent->target) ||
|
2012-12-15 17:26:03 -08:00
|
|
|
mEvent->mFlags.InTargetPhase()) {
|
2013-03-17 00:55:17 -07:00
|
|
|
return nsIDOMEvent::AT_TARGET;
|
|
|
|
}
|
|
|
|
if (mEvent->mFlags.mInCapturePhase) {
|
|
|
|
return nsIDOMEvent::CAPTURING_PHASE;
|
|
|
|
}
|
|
|
|
if (mEvent->mFlags.mInBubblingPhase) {
|
|
|
|
return nsIDOMEvent::BUBBLING_PHASE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2013-03-17 00:55:17 -07:00
|
|
|
return nsIDOMEvent::NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::GetEventPhase(uint16_t* aEventPhase)
|
2013-03-17 00:55:17 -07:00
|
|
|
{
|
|
|
|
*aEventPhase = EventPhase();
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::GetBubbles(bool* aBubbles)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-03-17 00:55:17 -07:00
|
|
|
*aBubbles = Bubbles();
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::GetCancelable(bool* aCancelable)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-03-17 00:55:17 -07:00
|
|
|
*aCancelable = Cancelable();
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::GetTimeStamp(uint64_t* aTimeStamp)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-06-05 22:29:49 -07:00
|
|
|
*aTimeStamp = mEvent->time;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::StopPropagation()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-12-15 17:26:03 -08:00
|
|
|
mEvent->mFlags.mPropagationStopped = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-11-04 10:17:19 -07:00
|
|
|
NS_IMETHODIMP
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::StopImmediatePropagation()
|
2011-11-04 10:17:19 -07:00
|
|
|
{
|
2012-12-15 17:26:03 -08:00
|
|
|
mEvent->mFlags.mPropagationStopped = true;
|
|
|
|
mEvent->mFlags.mImmediatePropagationStopped = true;
|
2011-11-04 10:17:19 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::GetIsTrusted(bool* aIsTrusted)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-03-17 00:55:17 -07:00
|
|
|
*aIsTrusted = IsTrusted();
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::PreventDefault()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-12-08 07:51:16 -08:00
|
|
|
// This method is called only from C++ code which must handle default action
|
|
|
|
// of this event. So, pass true always.
|
|
|
|
PreventDefaultInternal(true);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::PreventDefault(JSContext* aCx)
|
2013-12-08 07:51:16 -08:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aCx, "JS context must be specified");
|
|
|
|
|
|
|
|
// Note that at handling default action, another event may be dispatched.
|
|
|
|
// Then, JS in content mey be call preventDefault()
|
|
|
|
// even in the event is in system event group. Therefore, don't refer
|
|
|
|
// mInSystemGroup here.
|
|
|
|
PreventDefaultInternal(IsChrome(aCx));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::PreventDefaultInternal(bool aCalledByDefaultHandler)
|
2013-12-08 07:51:16 -08:00
|
|
|
{
|
|
|
|
if (!mEvent->mFlags.mCancelable) {
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-10-29 04:11:02 -07:00
|
|
|
|
2013-12-08 07:51:16 -08:00
|
|
|
mEvent->mFlags.mDefaultPrevented = true;
|
|
|
|
|
|
|
|
// Note that even if preventDefault() has already been called by chrome,
|
|
|
|
// a call of preventDefault() by content needs to overwrite
|
|
|
|
// mDefaultPreventedByContent to true because in such case, defaultPrevented
|
|
|
|
// must be true when web apps check it after they call preventDefault().
|
|
|
|
if (!aCalledByDefaultHandler) {
|
|
|
|
mEvent->mFlags.mDefaultPreventedByContent = true;
|
|
|
|
}
|
2013-12-12 01:39:04 -08:00
|
|
|
|
|
|
|
if (!IsTrusted()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
WidgetDragEvent* dragEvent = mEvent->AsDragEvent();
|
|
|
|
if (!dragEvent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(mEvent->currentTarget);
|
|
|
|
if (!node) {
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(mEvent->currentTarget);
|
|
|
|
if (!win) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
node = win->GetExtantDoc();
|
|
|
|
}
|
|
|
|
if (!nsContentUtils::IsChromeDoc(node->OwnerDoc())) {
|
|
|
|
dragEvent->mDefaultPreventedOnContent = true;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-07-18 03:36:08 -07:00
|
|
|
void
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::SetEventType(const nsAString& aEventTypeArg)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-08-16 03:06:24 -07:00
|
|
|
if (mIsMainThreadEvent) {
|
2014-06-16 02:08:29 -07:00
|
|
|
mEvent->typeString.Truncate();
|
2013-08-16 03:06:24 -07:00
|
|
|
mEvent->userType =
|
|
|
|
nsContentUtils::GetEventIdAndAtom(aEventTypeArg, mEvent->eventStructType,
|
|
|
|
&(mEvent->message));
|
|
|
|
} else {
|
|
|
|
mEvent->userType = nullptr;
|
|
|
|
mEvent->message = NS_USER_DEFINED_EVENT;
|
|
|
|
mEvent->typeString = aEventTypeArg;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::InitEvent(const nsAString& aEventTypeArg,
|
|
|
|
bool aCanBubbleArg,
|
|
|
|
bool aCancelableArg)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Make sure this event isn't already being dispatched.
|
2012-12-15 17:26:04 -08:00
|
|
|
NS_ENSURE_TRUE(!mEvent->mFlags.mIsBeingDispatched, NS_OK);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-03-17 00:55:17 -07:00
|
|
|
if (IsTrusted()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Ensure the caller is permitted to dispatch trusted DOM events.
|
2013-08-30 02:47:19 -07:00
|
|
|
if (!nsContentUtils::ThreadsafeIsCallerChrome()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
SetTrusted(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-18 03:36:08 -07:00
|
|
|
SetEventType(aEventTypeArg);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-12-15 17:26:03 -08:00
|
|
|
mEvent->mFlags.mBubbles = aCanBubbleArg;
|
|
|
|
mEvent->mFlags.mCancelable = aCancelableArg;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-03-20 07:15:58 -07:00
|
|
|
mEvent->mFlags.mDefaultPrevented = false;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Clearing the old targets, so that the event is targeted correctly when
|
|
|
|
// re-dispatching it.
|
2012-07-30 07:20:58 -07:00
|
|
|
mEvent->target = nullptr;
|
|
|
|
mEvent->originalTarget = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-06-10 11:14:30 -07:00
|
|
|
NS_IMETHODIMP
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::DuplicatePrivateData()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-03-04 16:37:43 -08:00
|
|
|
NS_ASSERTION(mEvent, "No WidgetEvent for Event duplication!");
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mEventIsInternal) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-01-26 22:10:44 -08:00
|
|
|
mEvent = mEvent->Duplicate();
|
2012-07-30 07:20:58 -07:00
|
|
|
mPresContext = nullptr;
|
2011-10-17 07:59:28 -07:00
|
|
|
mEventIsInternal = true;
|
|
|
|
mPrivateDataDuplicated = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-06-10 11:14:30 -07:00
|
|
|
NS_IMETHODIMP
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::SetTarget(nsIDOMEventTarget* aTarget)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(aTarget);
|
|
|
|
|
|
|
|
NS_ASSERTION(!win || !win->IsInnerWindow(),
|
|
|
|
"Uh, inner window set as event target!");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-03-31 05:44:18 -07:00
|
|
|
mEvent->target = do_QueryInterface(aTarget);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP_(bool)
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::IsDispatchStopped()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-12-15 17:26:03 -08:00
|
|
|
return mEvent->mFlags.mPropagationStopped;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-10-01 20:46:04 -07:00
|
|
|
NS_IMETHODIMP_(WidgetEvent*)
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::GetInternalNSEvent()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-10-09 16:23:07 -07:00
|
|
|
return mEvent;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-03-04 16:37:43 -08:00
|
|
|
NS_IMETHODIMP_(Event*)
|
|
|
|
Event::InternalDOMEvent()
|
2013-03-09 03:34:29 -08:00
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// return true if eventName is contained within events, delimited by
|
|
|
|
// spaces
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2007-03-22 10:30:00 -07:00
|
|
|
PopupAllowedForEvent(const char *eventName)
|
|
|
|
{
|
|
|
|
if (!sPopupAllowedEvents) {
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::PopupAllowedEventsChanged();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (!sPopupAllowedEvents) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDependentCString events(sPopupAllowedEvents);
|
|
|
|
|
|
|
|
nsAFlatCString::const_iterator start, end;
|
|
|
|
nsAFlatCString::const_iterator startiter(events.BeginReading(start));
|
|
|
|
events.EndReading(end);
|
|
|
|
|
|
|
|
while (startiter != end) {
|
|
|
|
nsAFlatCString::const_iterator enditer(end);
|
|
|
|
|
|
|
|
if (!FindInReadable(nsDependentCString(eventName), startiter, enditer))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// the match is surrounded by spaces, or at a string boundary
|
|
|
|
if ((startiter == start || *--startiter == ' ') &&
|
|
|
|
(enditer == end || *enditer == ' ')) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Move on and see if there are other matches. (The delimitation
|
|
|
|
// requirement makes it pointless to begin the next search before
|
|
|
|
// the end of the invalid match just found.)
|
|
|
|
startiter = enditer;
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
PopupControlState
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::GetEventPopupControlState(WidgetEvent* aEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// generally if an event handler is running, new windows are disallowed.
|
|
|
|
// check for exceptions:
|
|
|
|
PopupControlState abuse = openAbused;
|
|
|
|
|
|
|
|
switch(aEvent->eventStructType) {
|
|
|
|
case NS_EVENT :
|
|
|
|
// For these following events only allow popups if they're
|
|
|
|
// triggered while handling user input. See
|
|
|
|
// nsPresShell::HandleEventInternal() for details.
|
2014-03-31 21:09:23 -07:00
|
|
|
if (EventStateManager::IsHandlingUserInput()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
switch(aEvent->message) {
|
|
|
|
case NS_FORM_SELECTED :
|
2014-03-04 16:37:43 -08:00
|
|
|
if (PopupAllowedForEvent("select")) {
|
2007-03-22 10:30:00 -07:00
|
|
|
abuse = openControlled;
|
2014-03-04 16:37:43 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case NS_FORM_CHANGE :
|
2014-03-04 16:37:43 -08:00
|
|
|
if (PopupAllowedForEvent("change")) {
|
2007-03-22 10:30:00 -07:00
|
|
|
abuse = openControlled;
|
2014-03-04 16:37:43 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2014-04-10 00:11:37 -07:00
|
|
|
case NS_EDITOR_INPUT_EVENT :
|
2007-03-22 10:30:00 -07:00
|
|
|
// For this following event only allow popups if it's triggered
|
|
|
|
// while handling user input. See
|
|
|
|
// nsPresShell::HandleEventInternal() for details.
|
2014-03-31 21:09:23 -07:00
|
|
|
if (EventStateManager::IsHandlingUserInput()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
switch(aEvent->message) {
|
2014-04-10 00:11:37 -07:00
|
|
|
case NS_EDITOR_INPUT:
|
2014-03-04 16:37:43 -08:00
|
|
|
if (PopupAllowedForEvent("input")) {
|
2007-03-22 10:30:00 -07:00
|
|
|
abuse = openControlled;
|
2014-03-04 16:37:43 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_INPUT_EVENT :
|
|
|
|
// For this following event only allow popups if it's triggered
|
|
|
|
// while handling user input. See
|
|
|
|
// nsPresShell::HandleEventInternal() for details.
|
2014-03-31 21:09:23 -07:00
|
|
|
if (EventStateManager::IsHandlingUserInput()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
switch(aEvent->message) {
|
|
|
|
case NS_FORM_CHANGE :
|
2014-03-04 16:37:43 -08:00
|
|
|
if (PopupAllowedForEvent("change")) {
|
2007-03-22 10:30:00 -07:00
|
|
|
abuse = openControlled;
|
2014-03-04 16:37:43 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2011-10-31 16:39:32 -07:00
|
|
|
case NS_XUL_COMMAND:
|
|
|
|
abuse = openControlled;
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_KEY_EVENT :
|
2012-12-15 17:26:03 -08:00
|
|
|
if (aEvent->mFlags.mIsTrusted) {
|
2013-10-17 23:10:24 -07:00
|
|
|
uint32_t key = aEvent->AsKeyboardEvent()->keyCode;
|
2007-03-22 10:30:00 -07:00
|
|
|
switch(aEvent->message) {
|
|
|
|
case NS_KEY_PRESS :
|
|
|
|
// return key on focused button. see note at NS_MOUSE_CLICK.
|
2014-03-04 16:37:43 -08:00
|
|
|
if (key == nsIDOMKeyEvent::DOM_VK_RETURN) {
|
2007-03-22 10:30:00 -07:00
|
|
|
abuse = openAllowed;
|
2014-03-04 16:37:43 -08:00
|
|
|
} else if (PopupAllowedForEvent("keypress")) {
|
2007-03-22 10:30:00 -07:00
|
|
|
abuse = openControlled;
|
2014-03-04 16:37:43 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case NS_KEY_UP :
|
|
|
|
// space key on focused button. see note at NS_MOUSE_CLICK.
|
2014-03-04 16:37:43 -08:00
|
|
|
if (key == nsIDOMKeyEvent::DOM_VK_SPACE) {
|
2007-03-22 10:30:00 -07:00
|
|
|
abuse = openAllowed;
|
2014-03-04 16:37:43 -08:00
|
|
|
} else if (PopupAllowedForEvent("keyup")) {
|
2007-03-22 10:30:00 -07:00
|
|
|
abuse = openControlled;
|
2014-03-04 16:37:43 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case NS_KEY_DOWN :
|
2014-03-04 16:37:43 -08:00
|
|
|
if (PopupAllowedForEvent("keydown")) {
|
2007-03-22 10:30:00 -07:00
|
|
|
abuse = openControlled;
|
2014-03-04 16:37:43 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2013-05-16 16:29:23 -07:00
|
|
|
case NS_TOUCH_EVENT :
|
|
|
|
if (aEvent->mFlags.mIsTrusted) {
|
|
|
|
switch (aEvent->message) {
|
|
|
|
case NS_TOUCH_START :
|
|
|
|
if (PopupAllowedForEvent("touchstart")) {
|
|
|
|
abuse = openControlled;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_TOUCH_END :
|
|
|
|
if (PopupAllowedForEvent("touchend")) {
|
|
|
|
abuse = openControlled;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
case NS_MOUSE_EVENT :
|
2012-12-15 17:26:03 -08:00
|
|
|
if (aEvent->mFlags.mIsTrusted &&
|
2013-10-22 01:55:20 -07:00
|
|
|
aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton) {
|
2007-03-22 10:30:00 -07:00
|
|
|
switch(aEvent->message) {
|
|
|
|
case NS_MOUSE_BUTTON_UP :
|
2014-03-04 16:37:43 -08:00
|
|
|
if (PopupAllowedForEvent("mouseup")) {
|
2007-03-22 10:30:00 -07:00
|
|
|
abuse = openControlled;
|
2014-03-04 16:37:43 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case NS_MOUSE_BUTTON_DOWN :
|
2014-03-04 16:37:43 -08:00
|
|
|
if (PopupAllowedForEvent("mousedown")) {
|
2007-03-22 10:30:00 -07:00
|
|
|
abuse = openControlled;
|
2014-03-04 16:37:43 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case NS_MOUSE_CLICK :
|
|
|
|
/* Click events get special treatment because of their
|
|
|
|
historical status as a more legitimate event handler. If
|
|
|
|
click popups are enabled in the prefs, clear the popup
|
|
|
|
status completely. */
|
2014-03-04 16:37:43 -08:00
|
|
|
if (PopupAllowedForEvent("click")) {
|
2007-03-22 10:30:00 -07:00
|
|
|
abuse = openAllowed;
|
2014-03-04 16:37:43 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case NS_MOUSE_DOUBLECLICK :
|
2014-03-04 16:37:43 -08:00
|
|
|
if (PopupAllowedForEvent("dblclick")) {
|
2007-03-22 10:30:00 -07:00
|
|
|
abuse = openControlled;
|
2014-03-04 16:37:43 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_FORM_EVENT :
|
|
|
|
// For these following events only allow popups if they're
|
|
|
|
// triggered while handling user input. See
|
|
|
|
// nsPresShell::HandleEventInternal() for details.
|
2014-03-31 21:09:23 -07:00
|
|
|
if (EventStateManager::IsHandlingUserInput()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
switch(aEvent->message) {
|
|
|
|
case NS_FORM_SUBMIT :
|
2014-03-04 16:37:43 -08:00
|
|
|
if (PopupAllowedForEvent("submit")) {
|
2007-03-22 10:30:00 -07:00
|
|
|
abuse = openControlled;
|
2014-03-04 16:37:43 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case NS_FORM_RESET :
|
2014-03-04 16:37:43 -08:00
|
|
|
if (PopupAllowedForEvent("reset")) {
|
2007-03-22 10:30:00 -07:00
|
|
|
abuse = openControlled;
|
2014-03-04 16:37:43 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2012-11-19 22:05:56 -08:00
|
|
|
default:
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return abuse;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::PopupAllowedEventsChanged()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (sPopupAllowedEvents) {
|
|
|
|
nsMemory::Free(sPopupAllowedEvents);
|
|
|
|
}
|
|
|
|
|
2011-05-28 00:03:00 -07:00
|
|
|
nsAdoptingCString str = Preferences::GetCString("dom.popup_allowed_events");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// We'll want to do this even if str is empty to avoid looking up
|
|
|
|
// this pref all the time if it's not set.
|
|
|
|
sPopupAllowedEvents = ToNewCString(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::Shutdown()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (sPopupAllowedEvents) {
|
|
|
|
nsMemory::Free(sPopupAllowedEvents);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-16 16:24:11 -08:00
|
|
|
nsIntPoint
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::GetScreenCoords(nsPresContext* aPresContext,
|
|
|
|
WidgetEvent* aEvent,
|
|
|
|
LayoutDeviceIntPoint aPoint)
|
2011-12-16 16:24:11 -08:00
|
|
|
{
|
2014-03-31 21:09:23 -07:00
|
|
|
if (EventStateManager::sIsPointerLocked) {
|
|
|
|
return EventStateManager::sLastScreenPoint;
|
2012-04-11 14:55:21 -07:00
|
|
|
}
|
|
|
|
|
2011-12-16 16:24:11 -08:00
|
|
|
if (!aEvent ||
|
|
|
|
(aEvent->eventStructType != NS_MOUSE_EVENT &&
|
|
|
|
aEvent->eventStructType != NS_MOUSE_SCROLL_EVENT &&
|
2012-08-11 18:42:34 -07:00
|
|
|
aEvent->eventStructType != NS_WHEEL_EVENT &&
|
2013-11-20 21:44:31 -08:00
|
|
|
aEvent->eventStructType != NS_POINTER_EVENT &&
|
2011-12-16 16:24:11 -08:00
|
|
|
aEvent->eventStructType != NS_TOUCH_EVENT &&
|
|
|
|
aEvent->eventStructType != NS_DRAG_EVENT &&
|
|
|
|
aEvent->eventStructType != NS_SIMPLE_GESTURE_EVENT)) {
|
|
|
|
return nsIntPoint(0, 0);
|
|
|
|
}
|
|
|
|
|
2013-10-22 01:55:20 -07:00
|
|
|
WidgetGUIEvent* guiEvent = aEvent->AsGUIEvent();
|
2011-12-16 16:24:11 -08:00
|
|
|
if (!guiEvent->widget) {
|
2013-08-02 00:05:16 -07:00
|
|
|
return LayoutDeviceIntPoint::ToUntyped(aPoint);
|
2011-12-16 16:24:11 -08:00
|
|
|
}
|
|
|
|
|
2013-08-02 00:05:16 -07:00
|
|
|
LayoutDeviceIntPoint offset = aPoint +
|
|
|
|
LayoutDeviceIntPoint::FromUntyped(guiEvent->widget->WidgetToScreenOffset());
|
2011-12-16 16:24:11 -08:00
|
|
|
nscoord factor = aPresContext->DeviceContext()->UnscaledAppUnitsPerDevPixel();
|
|
|
|
return nsIntPoint(nsPresContext::AppUnitsToIntCSSPixels(offset.x * factor),
|
|
|
|
nsPresContext::AppUnitsToIntCSSPixels(offset.y * factor));
|
|
|
|
}
|
|
|
|
|
2014-03-04 16:37:43 -08:00
|
|
|
// static
|
2013-07-10 02:55:05 -07:00
|
|
|
CSSIntPoint
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::GetPageCoords(nsPresContext* aPresContext,
|
|
|
|
WidgetEvent* aEvent,
|
|
|
|
LayoutDeviceIntPoint aPoint,
|
|
|
|
CSSIntPoint aDefaultPoint)
|
2011-12-16 16:24:11 -08:00
|
|
|
{
|
2014-03-04 16:37:43 -08:00
|
|
|
CSSIntPoint pagePoint =
|
|
|
|
Event::GetClientCoords(aPresContext, aEvent, aPoint, aDefaultPoint);
|
2011-12-16 16:24:11 -08:00
|
|
|
|
|
|
|
// If there is some scrolling, add scroll info to client point.
|
|
|
|
if (aPresContext && aPresContext->GetPresShell()) {
|
|
|
|
nsIPresShell* shell = aPresContext->GetPresShell();
|
|
|
|
nsIScrollableFrame* scrollframe = shell->GetRootScrollFrameAsScrollable();
|
|
|
|
if (scrollframe) {
|
2013-07-10 02:55:05 -07:00
|
|
|
pagePoint += CSSIntPoint::FromAppUnitsRounded(scrollframe->GetScrollPosition());
|
2011-12-16 16:24:11 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pagePoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2013-07-10 02:55:05 -07:00
|
|
|
CSSIntPoint
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::GetClientCoords(nsPresContext* aPresContext,
|
|
|
|
WidgetEvent* aEvent,
|
|
|
|
LayoutDeviceIntPoint aPoint,
|
|
|
|
CSSIntPoint aDefaultPoint)
|
2011-12-16 16:24:11 -08:00
|
|
|
{
|
2014-03-31 21:09:23 -07:00
|
|
|
if (EventStateManager::sIsPointerLocked) {
|
|
|
|
return EventStateManager::sLastClientPoint;
|
2012-04-11 14:55:21 -07:00
|
|
|
}
|
|
|
|
|
2011-12-16 16:24:11 -08:00
|
|
|
if (!aEvent ||
|
|
|
|
(aEvent->eventStructType != NS_MOUSE_EVENT &&
|
|
|
|
aEvent->eventStructType != NS_MOUSE_SCROLL_EVENT &&
|
2012-08-11 18:42:34 -07:00
|
|
|
aEvent->eventStructType != NS_WHEEL_EVENT &&
|
2011-12-16 16:24:11 -08:00
|
|
|
aEvent->eventStructType != NS_TOUCH_EVENT &&
|
|
|
|
aEvent->eventStructType != NS_DRAG_EVENT &&
|
2013-11-20 21:44:31 -08:00
|
|
|
aEvent->eventStructType != NS_POINTER_EVENT &&
|
2011-12-16 16:24:11 -08:00
|
|
|
aEvent->eventStructType != NS_SIMPLE_GESTURE_EVENT) ||
|
|
|
|
!aPresContext ||
|
2013-10-22 01:55:20 -07:00
|
|
|
!aEvent->AsGUIEvent()->widget) {
|
2011-12-16 16:24:11 -08:00
|
|
|
return aDefaultPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIPresShell* shell = aPresContext->GetPresShell();
|
|
|
|
if (!shell) {
|
2013-07-10 02:55:05 -07:00
|
|
|
return CSSIntPoint(0, 0);
|
2011-12-16 16:24:11 -08:00
|
|
|
}
|
2013-07-10 02:55:05 -07:00
|
|
|
|
2011-12-16 16:24:11 -08:00
|
|
|
nsIFrame* rootFrame = shell->GetRootFrame();
|
2013-07-10 02:55:05 -07:00
|
|
|
if (!rootFrame) {
|
|
|
|
return CSSIntPoint(0, 0);
|
|
|
|
}
|
|
|
|
nsPoint pt =
|
2013-08-02 00:05:16 -07:00
|
|
|
nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent,
|
|
|
|
LayoutDeviceIntPoint::ToUntyped(aPoint), rootFrame);
|
2011-12-16 16:24:11 -08:00
|
|
|
|
2013-07-10 02:55:05 -07:00
|
|
|
return CSSIntPoint::FromAppUnitsRounded(pt);
|
2011-12-16 16:24:11 -08:00
|
|
|
}
|
|
|
|
|
2014-03-04 16:37:43 -08:00
|
|
|
// To be called ONLY by Event::GetType (which has the additional
|
2007-03-22 10:30:00 -07:00
|
|
|
// logic for handling user-defined events).
|
|
|
|
// static
|
2014-03-04 16:37:43 -08:00
|
|
|
const char*
|
|
|
|
Event::GetEventName(uint32_t aEventType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
switch(aEventType) {
|
2012-08-29 04:24:41 -07:00
|
|
|
#define ID_TO_EVENT(name_, _id, _type, _struct) \
|
|
|
|
case _id: return #name_;
|
2014-04-01 04:42:12 -07:00
|
|
|
#include "mozilla/EventNameList.h"
|
2012-08-29 04:24:41 -07:00
|
|
|
#undef ID_TO_EVENT
|
2007-03-22 10:30:00 -07:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-10-01 20:46:04 -07:00
|
|
|
// XXXldb We can hit this case for WidgetEvent objects that we didn't
|
2007-03-22 10:30:00 -07:00
|
|
|
// create and that are not user defined events since this function and
|
|
|
|
// SetEventType are incomplete. (But fixing that requires fixing the
|
|
|
|
// arrays in nsEventListenerManager too, since the events for which
|
2014-03-04 16:37:43 -08:00
|
|
|
// this is a problem generally *are* created by Event.)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-12-08 07:51:16 -08:00
|
|
|
bool
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::DefaultPrevented(JSContext* aCx) const
|
2013-12-08 07:51:16 -08:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aCx, "JS context must be specified");
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE(mEvent, false);
|
|
|
|
|
|
|
|
// If preventDefault() has never been called, just return false.
|
|
|
|
if (!mEvent->mFlags.mDefaultPrevented) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If preventDefault() has been called by content, return true. Otherwise,
|
|
|
|
// i.e., preventDefault() has been called by chrome, return true only when
|
|
|
|
// this is called by chrome.
|
|
|
|
return mEvent->mFlags.mDefaultPreventedByContent || IsChrome(aCx);
|
|
|
|
}
|
|
|
|
|
2014-06-05 22:29:49 -07:00
|
|
|
double
|
2014-06-05 22:29:49 -07:00
|
|
|
Event::TimeStamp() const
|
|
|
|
{
|
|
|
|
if (!sReturnHighResTimeStamp) {
|
2014-06-05 22:29:49 -07:00
|
|
|
return static_cast<double>(mEvent->time);
|
2014-06-05 22:29:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mEvent->timeStamp.IsNull()) {
|
2014-06-05 22:29:49 -07:00
|
|
|
return 0.0;
|
2014-06-05 22:29:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mIsMainThreadEvent) {
|
|
|
|
if (NS_WARN_IF(!mOwner)) {
|
2014-06-05 22:29:49 -07:00
|
|
|
return 0.0;
|
2014-06-05 22:29:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPerformance* perf = mOwner->GetPerformance();
|
|
|
|
if (NS_WARN_IF(!perf)) {
|
2014-06-05 22:29:49 -07:00
|
|
|
return 0.0;
|
2014-06-05 22:29:49 -07:00
|
|
|
}
|
|
|
|
|
2014-06-05 22:29:49 -07:00
|
|
|
return perf->GetDOMTiming()->TimeStampToDOMHighRes(mEvent->timeStamp);
|
2014-06-05 22:29:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// For dedicated workers, we should make times relative to the navigation
|
|
|
|
// start of the document that created the worker. We currently don't have
|
|
|
|
// that information handy so for now we treat shared workers and dedicated
|
|
|
|
// workers alike and make times relative to the worker creation time. We can
|
|
|
|
// fix this when we implement WorkerPerformance.
|
|
|
|
workers::WorkerPrivate* workerPrivate =
|
|
|
|
workers::GetCurrentThreadWorkerPrivate();
|
|
|
|
MOZ_ASSERT(workerPrivate);
|
|
|
|
|
|
|
|
TimeDuration duration =
|
|
|
|
mEvent->timeStamp - workerPrivate->CreationTimeStamp();
|
2014-06-05 22:29:49 -07:00
|
|
|
return duration.ToMilliseconds();
|
2014-06-05 22:29:49 -07:00
|
|
|
}
|
|
|
|
|
2013-05-27 07:43:51 -07:00
|
|
|
bool
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::GetPreventDefault() const
|
2013-05-27 07:43:51 -07:00
|
|
|
{
|
|
|
|
if (mOwner) {
|
|
|
|
if (nsIDocument* doc = mOwner->GetExtantDoc()) {
|
|
|
|
doc->WarnOnceAbout(nsIDocument::eGetPreventDefault);
|
|
|
|
}
|
|
|
|
}
|
2013-12-08 07:51:16 -08:00
|
|
|
// GetPreventDefault() is legacy and Gecko specific method. Although,
|
|
|
|
// the result should be same as defaultPrevented, we don't need to break
|
|
|
|
// backward compatibility of legacy method. Let's behave traditionally.
|
2013-05-27 07:43:51 -07:00
|
|
|
return DefaultPrevented();
|
|
|
|
}
|
|
|
|
|
2009-06-23 03:07:39 -07:00
|
|
|
NS_IMETHODIMP
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::GetPreventDefault(bool* aReturn)
|
2009-06-23 03:07:39 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aReturn);
|
2013-03-17 00:55:17 -07:00
|
|
|
*aReturn = GetPreventDefault();
|
2009-06-23 03:07:39 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-13 13:44:35 -07:00
|
|
|
NS_IMETHODIMP
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::GetDefaultPrevented(bool* aReturn)
|
2011-05-13 13:44:35 -07:00
|
|
|
{
|
2013-03-17 00:55:17 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aReturn);
|
2013-12-08 07:51:16 -08:00
|
|
|
// This method must be called by only event handlers implemented by C++.
|
|
|
|
// Then, the handlers must handle default action. So, this method don't need
|
|
|
|
// to check if preventDefault() has been called by content or chrome.
|
2013-03-17 00:55:17 -07:00
|
|
|
*aReturn = DefaultPrevented();
|
|
|
|
return NS_OK;
|
2011-05-13 13:44:35 -07:00
|
|
|
}
|
|
|
|
|
2012-06-10 11:14:30 -07:00
|
|
|
NS_IMETHODIMP_(void)
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::Serialize(IPC::Message* aMsg, bool aSerializeInterfaceType)
|
2009-11-17 06:22:23 -08:00
|
|
|
{
|
|
|
|
if (aSerializeInterfaceType) {
|
|
|
|
IPC::WriteParam(aMsg, NS_LITERAL_STRING("event"));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsString type;
|
|
|
|
GetType(type);
|
|
|
|
IPC::WriteParam(aMsg, type);
|
|
|
|
|
2013-03-17 00:55:17 -07:00
|
|
|
IPC::WriteParam(aMsg, Bubbles());
|
|
|
|
IPC::WriteParam(aMsg, Cancelable());
|
|
|
|
IPC::WriteParam(aMsg, IsTrusted());
|
2009-11-17 06:22:23 -08:00
|
|
|
|
|
|
|
// No timestamp serialization for now!
|
|
|
|
}
|
|
|
|
|
2012-06-10 11:14:30 -07:00
|
|
|
NS_IMETHODIMP_(bool)
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::Deserialize(const IPC::Message* aMsg, void** aIter)
|
2009-11-17 06:22:23 -08:00
|
|
|
{
|
|
|
|
nsString type;
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &type), false);
|
2009-11-17 06:22:23 -08:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool bubbles = false;
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &bubbles), false);
|
2009-11-17 06:22:23 -08:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool cancelable = false;
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &cancelable), false);
|
2009-11-17 06:22:23 -08:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool trusted = false;
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &trusted), false);
|
2009-11-17 06:22:23 -08:00
|
|
|
|
|
|
|
nsresult rv = InitEvent(type, bubbles, cancelable);
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
2009-11-17 06:22:23 -08:00
|
|
|
SetTrusted(trusted);
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2009-11-17 06:22:23 -08:00
|
|
|
}
|
|
|
|
|
2013-03-09 03:34:29 -08:00
|
|
|
NS_IMETHODIMP_(void)
|
2014-03-04 16:37:43 -08:00
|
|
|
Event::SetOwner(mozilla::dom::EventTarget* aOwner)
|
2013-03-09 03:34:29 -08:00
|
|
|
{
|
|
|
|
mOwner = nullptr;
|
|
|
|
|
|
|
|
if (!aOwner) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsINode> n = do_QueryInterface(aOwner);
|
|
|
|
if (n) {
|
|
|
|
mOwner = do_QueryInterface(n->OwnerDoc()->GetScopeObject());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsPIDOMWindow> w = do_QueryInterface(aOwner);
|
|
|
|
if (w) {
|
|
|
|
if (w->IsOuterWindow()) {
|
|
|
|
mOwner = w->GetCurrentInnerWindow();
|
|
|
|
} else {
|
|
|
|
mOwner.swap(w);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-31 23:13:50 -07:00
|
|
|
nsCOMPtr<DOMEventTargetHelper> eth = do_QueryInterface(aOwner);
|
2013-03-09 03:34:29 -08:00
|
|
|
if (eth) {
|
|
|
|
mOwner = eth->GetOwner();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsCOMPtr<nsPIWindowRoot> root = do_QueryInterface(aOwner);
|
|
|
|
MOZ_ASSERT(root, "Unexpected EventTarget!");
|
|
|
|
#endif
|
|
|
|
}
|
2009-11-17 06:22:23 -08:00
|
|
|
|
2014-03-04 16:37:43 -08:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewDOMEvent(nsIDOMEvent** aInstancePtrResult,
|
|
|
|
EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetEvent* aEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-03-04 16:37:43 -08:00
|
|
|
Event* it = new Event(aOwner, aPresContext, aEvent);
|
2014-03-17 13:00:11 -07:00
|
|
|
NS_ADDREF(it);
|
|
|
|
*aInstancePtrResult = static_cast<Event*>(it);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|