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
|
|
|
|
2009-11-17 06:22:23 -08:00
|
|
|
#include "base/basictypes.h"
|
2011-10-10 22:50:08 -07:00
|
|
|
|
2012-08-28 05:41:04 -07:00
|
|
|
#include "ipc/IPCMessageUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCOMPtr.h"
|
2012-07-27 07:03:27 -07:00
|
|
|
#include "nsError.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsDOMEvent.h"
|
|
|
|
#include "nsEventStateManager.h"
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIDocument.h"
|
2013-09-25 04:21:20 -07:00
|
|
|
#include "mozilla/ContentEvents.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"
|
2013-09-24 03:04:16 -07:00
|
|
|
#include "mozilla/MutationEvent.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"
|
2013-03-07 10:53:19 -08:00
|
|
|
#include "nsJSEnvironment.h"
|
2011-05-28 00:03:00 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2011-12-16 16:24:11 -08:00
|
|
|
#include "nsLayoutUtils.h"
|
|
|
|
#include "nsIScrollableFrame.h"
|
2013-03-09 03:34:29 -08:00
|
|
|
#include "nsDOMEventTargetHelper.h"
|
|
|
|
#include "nsPIWindowRoot.h"
|
2013-05-07 17:55:21 -07:00
|
|
|
#include "nsGlobalWindow.h"
|
2013-09-23 04:55:35 -07:00
|
|
|
#include "nsDeviceContext.h"
|
2011-05-28 00:03:00 -07:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2013-03-17 00:55:17 -07:00
|
|
|
using namespace mozilla::dom;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
static char *sPopupAllowedEvents;
|
|
|
|
|
|
|
|
|
2013-03-09 03:34:29 -08:00
|
|
|
nsDOMEvent::nsDOMEvent(mozilla::dom::EventTarget* aOwner,
|
2013-10-01 20:46:04 -07:00
|
|
|
nsPresContext* aPresContext, WidgetEvent* aEvent)
|
2013-05-07 17:55:21 -07:00
|
|
|
{
|
|
|
|
ConstructorInit(aOwner, aPresContext, aEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMEvent::nsDOMEvent(nsPIDOMWindow* aParent)
|
|
|
|
{
|
|
|
|
ConstructorInit(static_cast<nsGlobalWindow *>(aParent), nullptr, nullptr);
|
|
|
|
}
|
|
|
|
|
2013-06-20 07:13:52 -07:00
|
|
|
void
|
|
|
|
nsDOMEvent::ConstructorInit(mozilla::dom::EventTarget* aOwner,
|
2013-10-01 20:46:04 -07:00
|
|
|
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-03-09 03:34:29 -08:00
|
|
|
|
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
|
|
|
|
2013-10-01 20:46:04 -07:00
|
|
|
nsDOMFooEvent::nsDOMFooEvent(..., WidgetEvent* aEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
: nsDOMEvent(..., aEvent ? aEvent : new nsFooEvent())
|
|
|
|
|
|
|
|
Then, to override the mEventIsInternal assignments done by the
|
|
|
|
base ctor, it should do this in its own ctor:
|
|
|
|
|
2013-10-01 20:46:04 -07:00
|
|
|
nsDOMFooEvent::nsDOMFooEvent(..., 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);
|
2013-03-07 10:53:19 -08:00
|
|
|
nsJSContext::LikelyShortLivingObjectCreated();
|
2011-12-14 11:53:48 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMEvent::InitPresContextData(nsPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMEvent::~nsDOMEvent()
|
|
|
|
{
|
|
|
|
NS_ASSERT_OWNINGTHREAD(nsDOMEvent);
|
|
|
|
|
|
|
|
if (mEventIsInternal && mEvent) {
|
|
|
|
delete mEvent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-26 01:21:42 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMEvent)
|
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
|
|
|
|
|
2007-06-26 01:21:42 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMEvent)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMEvent)
|
|
|
|
|
2013-08-01 18:29:05 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMEvent)
|
|
|
|
|
2013-03-09 03:34:29 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsDOMEvent)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
2007-06-26 01:21:42 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDOMEvent)
|
|
|
|
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-10-01 00:23:02 -07:00
|
|
|
static_cast<WidgetMouseEventBase*>(tmp->mEvent)->relatedTarget =
|
|
|
|
nullptr;
|
2007-06-26 01:21:42 -07:00
|
|
|
break;
|
2008-08-27 05:07:27 -07:00
|
|
|
case NS_DRAG_EVENT:
|
2013-10-01 00:23:02 -07:00
|
|
|
static_cast<WidgetDragEvent*>(tmp->mEvent)->dataTransfer = nullptr;
|
2013-10-01 00:23:02 -07:00
|
|
|
static_cast<WidgetMouseEventBase*>(tmp->mEvent)->relatedTarget =
|
|
|
|
nullptr;
|
2008-08-27 05:07:27 -07:00
|
|
|
break;
|
2013-03-11 08:49:48 -07:00
|
|
|
case NS_CLIPBOARD_EVENT:
|
2013-09-26 23:20:55 -07:00
|
|
|
static_cast<InternalClipboardEvent*>(tmp->mEvent)->clipboardData =
|
|
|
|
nullptr;
|
2013-03-11 08:49:48 -07:00
|
|
|
break;
|
2007-06-26 01:21:42 -07:00
|
|
|
case NS_MUTATION_EVENT:
|
2013-09-26 23:20:53 -07:00
|
|
|
static_cast<InternalMutationEvent*>(tmp->mEvent)->mRelatedNode =
|
|
|
|
nullptr;
|
2007-06-26 01:21:42 -07:00
|
|
|
break;
|
2013-06-05 05:02:51 -07:00
|
|
|
case NS_FOCUS_EVENT:
|
2013-09-26 23:20:55 -07:00
|
|
|
static_cast<InternalFocusEvent*>(tmp->mEvent)->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
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDOMEvent)
|
|
|
|
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:
|
2008-09-08 11:26:46 -07:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mEvent->relatedTarget");
|
2007-06-26 01:21:42 -07:00
|
|
|
cb.NoteXPCOMChild(
|
2013-10-01 00:23:02 -07:00
|
|
|
static_cast<WidgetMouseEventBase*>(tmp->mEvent)->relatedTarget);
|
2007-06-26 01:21:42 -07:00
|
|
|
break;
|
2008-08-27 05:07:27 -07:00
|
|
|
case NS_DRAG_EVENT:
|
2008-09-08 11:26:46 -07:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mEvent->dataTransfer");
|
2008-08-27 05:07:27 -07:00
|
|
|
cb.NoteXPCOMChild(
|
2013-10-01 00:23:02 -07:00
|
|
|
static_cast<WidgetDragEvent*>(tmp->mEvent)->dataTransfer);
|
2009-02-17 03:49:03 -08:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mEvent->relatedTarget");
|
|
|
|
cb.NoteXPCOMChild(
|
2013-10-01 00:23:02 -07:00
|
|
|
static_cast<WidgetMouseEventBase*>(tmp->mEvent)->relatedTarget);
|
2008-08-27 05:07:27 -07:00
|
|
|
break;
|
2013-03-11 08:49:48 -07:00
|
|
|
case NS_CLIPBOARD_EVENT:
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mEvent->clipboardData");
|
|
|
|
cb.NoteXPCOMChild(
|
2013-09-26 23:20:55 -07:00
|
|
|
static_cast<InternalClipboardEvent*>(tmp->mEvent)->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");
|
2007-06-26 01:21:42 -07:00
|
|
|
cb.NoteXPCOMChild(
|
2013-09-26 23:20:53 -07:00
|
|
|
static_cast<InternalMutationEvent*>(tmp->mEvent)->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");
|
|
|
|
cb.NoteXPCOMChild(
|
2013-09-26 23:20:55 -07:00
|
|
|
static_cast<InternalFocusEvent*>(tmp->mEvent)->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
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsIDOMEventInterface
|
|
|
|
NS_METHOD nsDOMEvent::GetType(nsAString& aType)
|
|
|
|
{
|
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*
|
|
|
|
nsDOMEvent::GetTarget() const
|
|
|
|
{
|
|
|
|
return GetDOMEventTarget(mEvent->target);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-04-17 02:18:36 -07:00
|
|
|
NS_METHOD
|
|
|
|
nsDOMEvent::GetTarget(nsIDOMEventTarget** aTarget)
|
|
|
|
{
|
2013-03-17 00:55:17 -07:00
|
|
|
NS_IF_ADDREF(*aTarget = GetTarget());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
EventTarget*
|
|
|
|
nsDOMEvent::GetCurrentTarget() const
|
|
|
|
{
|
|
|
|
return GetDOMEventTarget(mEvent->currentTarget);
|
2007-04-17 02:18:36 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMEvent::GetCurrentTarget(nsIDOMEventTarget** aCurrentTarget)
|
|
|
|
{
|
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>
|
2007-03-22 10:30:00 -07:00
|
|
|
nsDOMEvent::GetTargetFromFrame()
|
|
|
|
{
|
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*
|
|
|
|
nsDOMEvent::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
|
2013-03-17 00:55:17 -07:00
|
|
|
nsDOMEvent::GetExplicitOriginalTarget(nsIDOMEventTarget** aRealEventTarget)
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aRealEventTarget = GetExplicitOriginalTarget());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
EventTarget*
|
|
|
|
nsDOMEvent::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
|
|
|
|
nsDOMEvent::GetOriginalTarget(nsIDOMEventTarget** aOriginalTarget)
|
|
|
|
{
|
|
|
|
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)
|
2011-09-28 23:19:26 -07:00
|
|
|
nsDOMEvent::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
|
|
|
|
nsDOMEvent::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;
|
|
|
|
}
|
|
|
|
|
|
|
|
//static
|
|
|
|
already_AddRefed<nsDOMEvent>
|
|
|
|
nsDOMEvent::Constructor(const mozilla::dom::GlobalObject& aGlobal,
|
|
|
|
const nsAString& aType,
|
|
|
|
const mozilla::dom::EventInit& aParam,
|
|
|
|
mozilla::ErrorResult& aRv)
|
|
|
|
{
|
2013-08-22 22:17:08 -07:00
|
|
|
nsCOMPtr<mozilla::dom::EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports());
|
2013-06-20 07:13:52 -07:00
|
|
|
nsRefPtr<nsDOMEvent> e = new nsDOMEvent(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
|
|
|
|
nsDOMEvent::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
|
|
|
|
nsDOMEvent::GetEventPhase(uint16_t* aEventPhase)
|
|
|
|
{
|
|
|
|
*aEventPhase = EventPhase();
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsDOMEvent::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
|
2011-09-28 23:19:26 -07:00
|
|
|
nsDOMEvent::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
|
2012-08-22 08:56:38 -07:00
|
|
|
nsDOMEvent::GetTimeStamp(uint64_t* aTimeStamp)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-03-17 00:55:17 -07:00
|
|
|
*aTimeStamp = TimeStamp();
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMEvent::StopPropagation()
|
|
|
|
{
|
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
|
|
|
|
nsDOMEvent::StopImmediatePropagation()
|
|
|
|
{
|
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
|
2011-09-28 23:19:26 -07:00
|
|
|
nsDOMEvent::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
|
|
|
|
nsDOMEvent::PreventDefault()
|
|
|
|
{
|
2012-12-15 17:26:03 -08:00
|
|
|
if (mEvent->mFlags.mCancelable) {
|
2012-12-15 17:26:04 -08:00
|
|
|
mEvent->mFlags.mDefaultPrevented = true;
|
2009-10-29 04:11:02 -07:00
|
|
|
|
|
|
|
// Need to set an extra flag for drag events.
|
2013-03-17 00:55:17 -07:00
|
|
|
if (mEvent->eventStructType == NS_DRAG_EVENT && IsTrusted()) {
|
2009-10-29 04:11:02 -07:00
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(mEvent->currentTarget);
|
|
|
|
if (!node) {
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(mEvent->currentTarget);
|
|
|
|
if (win) {
|
2013-04-23 21:22:37 -07:00
|
|
|
node = win->GetExtantDoc();
|
2009-10-29 04:11:02 -07:00
|
|
|
}
|
|
|
|
}
|
2011-10-18 03:53:36 -07:00
|
|
|
if (node && !nsContentUtils::IsChromeDoc(node->OwnerDoc())) {
|
2012-12-15 17:26:04 -08:00
|
|
|
mEvent->mFlags.mDefaultPreventedByContent = true;
|
2009-10-29 04:11:02 -07:00
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-10-29 04:11:02 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-18 03:36:08 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsDOMEvent::SetEventType(const nsAString& aEventTypeArg)
|
|
|
|
{
|
2013-08-16 03:06:24 -07:00
|
|
|
if (mIsMainThreadEvent) {
|
|
|
|
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
|
2011-09-28 23:19:26 -07:00
|
|
|
nsDOMEvent::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
|
|
|
|
nsDOMEvent::DuplicatePrivateData()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// FIXME! Simplify this method and make it somehow easily extendable,
|
|
|
|
// Bug 329127
|
|
|
|
|
2013-10-01 20:46:04 -07:00
|
|
|
NS_ASSERTION(mEvent, "No WidgetEvent for nsDOMEvent duplication!");
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mEventIsInternal) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-10-01 20:46:04 -07:00
|
|
|
WidgetEvent* newEvent = nullptr;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t msg = mEvent->message;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
switch (mEvent->eventStructType) {
|
|
|
|
case NS_EVENT:
|
|
|
|
{
|
2013-10-01 20:46:04 -07:00
|
|
|
newEvent = new WidgetEvent(false, msg);
|
2013-08-29 19:10:32 -07:00
|
|
|
newEvent->AssignEventData(*mEvent, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NS_GUI_EVENT:
|
|
|
|
{
|
2013-10-01 20:46:03 -07:00
|
|
|
WidgetGUIEvent* oldGUIEvent = static_cast<WidgetGUIEvent*>(mEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
// Not copying widget, it is a weak reference.
|
2013-10-01 20:46:03 -07:00
|
|
|
WidgetGUIEvent* guiEvent = new WidgetGUIEvent(false, msg, nullptr);
|
2013-08-29 19:10:32 -07:00
|
|
|
guiEvent->AssignGUIEventData(*oldGUIEvent, true);
|
|
|
|
newEvent = guiEvent;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NS_INPUT_EVENT:
|
|
|
|
{
|
2013-10-01 00:23:02 -07:00
|
|
|
WidgetInputEvent* oldInputEvent = static_cast<WidgetInputEvent*>(mEvent);
|
|
|
|
WidgetInputEvent* inputEvent = new WidgetInputEvent(false, msg, nullptr);
|
2013-08-29 19:10:32 -07:00
|
|
|
inputEvent->AssignInputEventData(*oldInputEvent, true);
|
|
|
|
newEvent = inputEvent;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NS_KEY_EVENT:
|
|
|
|
{
|
2013-10-01 00:22:58 -07:00
|
|
|
WidgetKeyboardEvent* oldKeyEvent =
|
|
|
|
static_cast<WidgetKeyboardEvent*>(mEvent);
|
|
|
|
WidgetKeyboardEvent* keyEvent =
|
|
|
|
new WidgetKeyboardEvent(false, msg, nullptr);
|
2013-08-29 19:10:32 -07:00
|
|
|
keyEvent->AssignKeyEventData(*oldKeyEvent, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
newEvent = keyEvent;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NS_MOUSE_EVENT:
|
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
nsMouseEvent* oldMouseEvent = static_cast<nsMouseEvent*>(mEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMouseEvent* mouseEvent =
|
2012-07-30 07:20:58 -07:00
|
|
|
new nsMouseEvent(false, msg, nullptr, oldMouseEvent->reason);
|
2013-08-29 19:10:32 -07:00
|
|
|
mouseEvent->AssignMouseEventData(*oldMouseEvent, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
newEvent = mouseEvent;
|
|
|
|
break;
|
|
|
|
}
|
2008-08-27 05:07:27 -07:00
|
|
|
case NS_DRAG_EVENT:
|
|
|
|
{
|
2013-10-01 00:23:02 -07:00
|
|
|
WidgetDragEvent* oldDragEvent = static_cast<WidgetDragEvent*>(mEvent);
|
|
|
|
WidgetDragEvent* dragEvent = new WidgetDragEvent(false, msg, nullptr);
|
2013-09-03 04:45:28 -07:00
|
|
|
dragEvent->AssignDragEventData(*oldDragEvent, true);
|
2008-08-27 05:07:27 -07:00
|
|
|
newEvent = dragEvent;
|
|
|
|
break;
|
|
|
|
}
|
2013-03-11 08:49:48 -07:00
|
|
|
case NS_CLIPBOARD_EVENT:
|
|
|
|
{
|
2013-09-26 23:20:55 -07:00
|
|
|
InternalClipboardEvent* oldClipboardEvent =
|
|
|
|
static_cast<InternalClipboardEvent*>(mEvent);
|
|
|
|
InternalClipboardEvent* clipboardEvent =
|
|
|
|
new InternalClipboardEvent(false, msg);
|
2013-09-03 04:45:29 -07:00
|
|
|
clipboardEvent->AssignClipboardEventData(*oldClipboardEvent, true);
|
2013-03-11 08:49:48 -07:00
|
|
|
newEvent = clipboardEvent;
|
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
case NS_SCRIPT_ERROR_EVENT:
|
|
|
|
{
|
2013-09-26 23:20:56 -07:00
|
|
|
InternalScriptErrorEvent* oldScriptErrorEvent =
|
|
|
|
static_cast<InternalScriptErrorEvent*>(mEvent);
|
|
|
|
InternalScriptErrorEvent* scriptErrorEvent =
|
|
|
|
new InternalScriptErrorEvent(false, msg);
|
2013-09-03 04:45:28 -07:00
|
|
|
scriptErrorEvent->AssignScriptErrorEventData(*oldScriptErrorEvent, true);
|
2013-08-29 19:10:32 -07:00
|
|
|
newEvent = scriptErrorEvent;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NS_TEXT_EVENT:
|
|
|
|
{
|
2013-10-01 00:22:59 -07:00
|
|
|
WidgetTextEvent* oldTextEvent = static_cast<WidgetTextEvent*>(mEvent);
|
|
|
|
WidgetTextEvent* textEvent = new WidgetTextEvent(false, msg, nullptr);
|
2013-09-03 04:45:29 -07:00
|
|
|
textEvent->AssignTextEventData(*oldTextEvent, true);
|
2013-08-29 19:10:32 -07:00
|
|
|
newEvent = textEvent;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NS_COMPOSITION_EVENT:
|
|
|
|
{
|
2013-10-01 00:23:00 -07:00
|
|
|
WidgetCompositionEvent* compositionEvent =
|
|
|
|
new WidgetCompositionEvent(false, msg, nullptr);
|
|
|
|
WidgetCompositionEvent* oldCompositionEvent =
|
|
|
|
static_cast<WidgetCompositionEvent*>(mEvent);
|
2013-09-03 04:45:29 -07:00
|
|
|
compositionEvent->AssignCompositionEventData(*oldCompositionEvent, true);
|
2011-09-22 02:17:40 -07:00
|
|
|
newEvent = compositionEvent;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NS_MOUSE_SCROLL_EVENT:
|
|
|
|
{
|
2013-10-01 00:23:02 -07:00
|
|
|
WidgetMouseScrollEvent* oldMouseScrollEvent =
|
|
|
|
static_cast<WidgetMouseScrollEvent*>(mEvent);
|
|
|
|
WidgetMouseScrollEvent* mouseScrollEvent =
|
|
|
|
new WidgetMouseScrollEvent(false, msg, nullptr);
|
2013-09-03 04:45:29 -07:00
|
|
|
mouseScrollEvent->AssignMouseScrollEventData(*oldMouseScrollEvent, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
newEvent = mouseScrollEvent;
|
|
|
|
break;
|
|
|
|
}
|
2012-08-11 18:42:34 -07:00
|
|
|
case NS_WHEEL_EVENT:
|
|
|
|
{
|
2013-09-13 19:39:41 -07:00
|
|
|
WheelEvent* oldWheelEvent = static_cast<WheelEvent*>(mEvent);
|
|
|
|
WheelEvent* wheelEvent = new WheelEvent(false, msg, nullptr);
|
2013-09-03 04:45:29 -07:00
|
|
|
wheelEvent->AssignWheelEventData(*oldWheelEvent, true);
|
2012-08-11 18:42:34 -07:00
|
|
|
newEvent = wheelEvent;
|
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
case NS_SCROLLPORT_EVENT:
|
|
|
|
{
|
2013-09-26 23:20:56 -07:00
|
|
|
InternalScrollPortEvent* oldScrollPortEvent =
|
|
|
|
static_cast<InternalScrollPortEvent*>(mEvent);
|
|
|
|
InternalScrollPortEvent* scrollPortEvent =
|
|
|
|
new InternalScrollPortEvent(false, msg, nullptr);
|
2013-09-03 04:45:28 -07:00
|
|
|
scrollPortEvent->AssignScrollPortEventData(*oldScrollPortEvent, true);
|
2013-08-29 19:10:32 -07:00
|
|
|
newEvent = scrollPortEvent;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
2009-09-11 16:13:56 -07:00
|
|
|
case NS_SCROLLAREA_EVENT:
|
|
|
|
{
|
2013-09-26 23:20:56 -07:00
|
|
|
InternalScrollAreaEvent* oldScrollAreaEvent =
|
|
|
|
static_cast<InternalScrollAreaEvent*>(mEvent);
|
|
|
|
InternalScrollAreaEvent* scrollAreaEvent =
|
|
|
|
new InternalScrollAreaEvent(false, msg, nullptr);
|
2013-09-03 04:45:28 -07:00
|
|
|
scrollAreaEvent->AssignScrollAreaEventData(*oldScrollAreaEvent, true);
|
2013-08-29 19:10:32 -07:00
|
|
|
newEvent = scrollAreaEvent;
|
2009-09-11 16:13:56 -07:00
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
case NS_MUTATION_EVENT:
|
|
|
|
{
|
2013-09-26 23:20:53 -07:00
|
|
|
InternalMutationEvent* mutationEvent =
|
|
|
|
new InternalMutationEvent(false, msg);
|
|
|
|
InternalMutationEvent* oldMutationEvent =
|
|
|
|
static_cast<InternalMutationEvent*>(mEvent);
|
2013-09-03 04:45:30 -07:00
|
|
|
mutationEvent->AssignMutationEventData(*oldMutationEvent, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
newEvent = mutationEvent;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NS_FORM_EVENT:
|
|
|
|
{
|
2013-09-26 23:20:55 -07:00
|
|
|
InternalFormEvent* oldFormEvent = static_cast<InternalFormEvent*>(mEvent);
|
|
|
|
InternalFormEvent* formEvent = new InternalFormEvent(false, msg);
|
2013-09-03 04:45:29 -07:00
|
|
|
formEvent->AssignFormEventData(*oldFormEvent, true);
|
2013-08-29 19:10:32 -07:00
|
|
|
newEvent = formEvent;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
2009-10-01 10:53:10 -07:00
|
|
|
case NS_FOCUS_EVENT:
|
|
|
|
{
|
2013-09-26 23:20:55 -07:00
|
|
|
InternalFocusEvent* newFocusEvent = new InternalFocusEvent(false, msg);
|
|
|
|
InternalFocusEvent* oldFocusEvent =
|
|
|
|
static_cast<InternalFocusEvent*>(mEvent);
|
2013-09-03 04:45:29 -07:00
|
|
|
newFocusEvent->AssignFocusEventData(*oldFocusEvent, true);
|
2010-10-18 11:12:18 -07:00
|
|
|
newEvent = newFocusEvent;
|
2009-10-01 10:53:10 -07:00
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
case NS_COMMAND_EVENT:
|
|
|
|
{
|
2013-09-26 23:20:54 -07:00
|
|
|
WidgetCommandEvent* oldCommandEvent =
|
|
|
|
static_cast<WidgetCommandEvent*>(mEvent);
|
|
|
|
WidgetCommandEvent* commandEvent =
|
|
|
|
new WidgetCommandEvent(false, mEvent->userType,
|
|
|
|
oldCommandEvent->command, nullptr);
|
2013-09-03 04:45:29 -07:00
|
|
|
commandEvent->AssignCommandEventData(*oldCommandEvent, true);
|
2013-08-29 19:10:32 -07:00
|
|
|
newEvent = commandEvent;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NS_UI_EVENT:
|
|
|
|
{
|
2013-10-01 00:23:01 -07:00
|
|
|
InternalUIEvent* oldUIEvent = static_cast<InternalUIEvent*>(mEvent);
|
|
|
|
InternalUIEvent* uiEvent =
|
|
|
|
new InternalUIEvent(false, msg, oldUIEvent->detail);
|
2013-09-03 04:45:29 -07:00
|
|
|
uiEvent->AssignUIEventData(*oldUIEvent, true);
|
2013-08-29 19:10:32 -07:00
|
|
|
newEvent = uiEvent;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NS_SVGZOOM_EVENT:
|
|
|
|
{
|
2013-10-01 20:46:03 -07:00
|
|
|
WidgetGUIEvent* oldGUIEvent = static_cast<WidgetGUIEvent*>(mEvent);
|
|
|
|
WidgetGUIEvent* guiEvent = new WidgetGUIEvent(false, msg, nullptr);
|
2013-08-29 19:10:32 -07:00
|
|
|
guiEvent->eventStructType = NS_SVGZOOM_EVENT;
|
|
|
|
guiEvent->AssignGUIEventData(*oldGUIEvent, true);
|
|
|
|
newEvent = guiEvent;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
2010-07-31 00:02:52 -07:00
|
|
|
case NS_SMIL_TIME_EVENT:
|
|
|
|
{
|
2013-10-01 00:23:01 -07:00
|
|
|
InternalUIEvent* oldUIEvent = static_cast<InternalUIEvent*>(mEvent);
|
|
|
|
InternalUIEvent* uiEvent = new InternalUIEvent(false, msg, 0);
|
2013-08-29 19:10:32 -07:00
|
|
|
uiEvent->eventStructType = NS_SMIL_TIME_EVENT;
|
2013-09-03 04:45:29 -07:00
|
|
|
uiEvent->AssignUIEventData(*oldUIEvent, true);
|
2013-08-29 19:10:32 -07:00
|
|
|
newEvent = uiEvent;
|
2010-07-31 00:02:52 -07:00
|
|
|
break;
|
|
|
|
}
|
2008-10-23 13:15:20 -07:00
|
|
|
case NS_SIMPLE_GESTURE_EVENT:
|
|
|
|
{
|
2013-09-26 23:20:57 -07:00
|
|
|
WidgetSimpleGestureEvent* oldSimpleGestureEvent =
|
|
|
|
static_cast<WidgetSimpleGestureEvent*>(mEvent);
|
|
|
|
WidgetSimpleGestureEvent* simpleGestureEvent =
|
|
|
|
new WidgetSimpleGestureEvent(false, msg, nullptr, 0, 0.0);
|
2013-09-03 04:45:30 -07:00
|
|
|
simpleGestureEvent->
|
|
|
|
AssignSimpleGestureEventData(*oldSimpleGestureEvent, true);
|
2008-10-23 13:15:20 -07:00
|
|
|
newEvent = simpleGestureEvent;
|
|
|
|
break;
|
|
|
|
}
|
2009-12-23 11:10:31 -08:00
|
|
|
case NS_TRANSITION_EVENT:
|
|
|
|
{
|
2013-09-26 23:20:55 -07:00
|
|
|
InternalTransitionEvent* oldTransitionEvent =
|
|
|
|
static_cast<InternalTransitionEvent*>(mEvent);
|
|
|
|
InternalTransitionEvent* transitionEvent =
|
|
|
|
new InternalTransitionEvent(false, msg,
|
|
|
|
oldTransitionEvent->propertyName,
|
|
|
|
oldTransitionEvent->elapsedTime,
|
|
|
|
oldTransitionEvent->pseudoElement);
|
2013-09-03 04:45:30 -07:00
|
|
|
transitionEvent->AssignTransitionEventData(*oldTransitionEvent, true);
|
2013-08-29 19:10:32 -07:00
|
|
|
newEvent = transitionEvent;
|
2009-12-23 11:10:31 -08:00
|
|
|
break;
|
|
|
|
}
|
2011-04-11 23:18:44 -07:00
|
|
|
case NS_ANIMATION_EVENT:
|
|
|
|
{
|
2013-09-26 23:20:54 -07:00
|
|
|
InternalAnimationEvent* oldAnimationEvent =
|
|
|
|
static_cast<InternalAnimationEvent*>(mEvent);
|
|
|
|
InternalAnimationEvent* animationEvent =
|
|
|
|
new InternalAnimationEvent(false, msg,
|
|
|
|
oldAnimationEvent->animationName,
|
|
|
|
oldAnimationEvent->elapsedTime,
|
|
|
|
oldAnimationEvent->pseudoElement);
|
2013-09-03 04:45:30 -07:00
|
|
|
animationEvent->AssignAnimationEventData(*oldAnimationEvent, true);
|
2013-08-29 19:10:32 -07:00
|
|
|
newEvent = animationEvent;
|
2011-04-11 23:18:44 -07:00
|
|
|
break;
|
|
|
|
}
|
2011-12-16 16:24:11 -08:00
|
|
|
case NS_TOUCH_EVENT:
|
|
|
|
{
|
2013-09-26 23:20:57 -07:00
|
|
|
WidgetTouchEvent* oldTouchEvent = static_cast<WidgetTouchEvent*>(mEvent);
|
|
|
|
WidgetTouchEvent* touchEvent = new WidgetTouchEvent(false, oldTouchEvent);
|
2013-09-03 04:45:29 -07:00
|
|
|
touchEvent->AssignTouchEventData(*oldTouchEvent, true);
|
2013-08-29 19:10:32 -07:00
|
|
|
newEvent = touchEvent;
|
2011-12-16 16:24:11 -08:00
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
NS_WARNING("Unknown event type!!!");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-29 19:10:32 -07:00
|
|
|
newEvent->mFlags = mEvent->mFlags;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mEvent = newEvent;
|
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
|
|
|
|
nsDOMEvent::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)
|
2008-10-09 16:23:07 -07:00
|
|
|
nsDOMEvent::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*)
|
2008-10-09 16:23:07 -07:00
|
|
|
nsDOMEvent::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
|
|
|
}
|
|
|
|
|
2013-03-09 03:34:29 -08:00
|
|
|
NS_IMETHODIMP_(nsDOMEvent*)
|
|
|
|
nsDOMEvent::InternalDOMEvent()
|
|
|
|
{
|
|
|
|
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) {
|
|
|
|
nsDOMEvent::PopupAllowedEventsChanged();
|
|
|
|
|
|
|
|
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
|
2013-10-01 20:46:04 -07:00
|
|
|
nsDOMEvent::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.
|
|
|
|
if (nsEventStateManager::IsHandlingUserInput()) {
|
|
|
|
switch(aEvent->message) {
|
|
|
|
case NS_FORM_SELECTED :
|
|
|
|
if (::PopupAllowedForEvent("select"))
|
|
|
|
abuse = openControlled;
|
|
|
|
break;
|
|
|
|
case NS_FORM_CHANGE :
|
|
|
|
if (::PopupAllowedForEvent("change"))
|
|
|
|
abuse = openControlled;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_GUI_EVENT :
|
|
|
|
// For this following event only allow popups if it's triggered
|
|
|
|
// while handling user input. See
|
|
|
|
// nsPresShell::HandleEventInternal() for details.
|
|
|
|
if (nsEventStateManager::IsHandlingUserInput()) {
|
|
|
|
switch(aEvent->message) {
|
|
|
|
case NS_FORM_INPUT :
|
|
|
|
if (::PopupAllowedForEvent("input"))
|
|
|
|
abuse = openControlled;
|
|
|
|
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.
|
|
|
|
if (nsEventStateManager::IsHandlingUserInput()) {
|
|
|
|
switch(aEvent->message) {
|
|
|
|
case NS_FORM_CHANGE :
|
|
|
|
if (::PopupAllowedForEvent("change"))
|
|
|
|
abuse = openControlled;
|
|
|
|
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-01 00:22:58 -07:00
|
|
|
uint32_t key = static_cast<WidgetKeyboardEvent*>(aEvent)->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.
|
|
|
|
if (key == nsIDOMKeyEvent::DOM_VK_RETURN)
|
|
|
|
abuse = openAllowed;
|
|
|
|
else if (::PopupAllowedForEvent("keypress"))
|
|
|
|
abuse = openControlled;
|
|
|
|
break;
|
|
|
|
case NS_KEY_UP :
|
|
|
|
// space key on focused button. see note at NS_MOUSE_CLICK.
|
|
|
|
if (key == nsIDOMKeyEvent::DOM_VK_SPACE)
|
|
|
|
abuse = openAllowed;
|
|
|
|
else if (::PopupAllowedForEvent("keyup"))
|
|
|
|
abuse = openControlled;
|
|
|
|
break;
|
|
|
|
case NS_KEY_DOWN :
|
|
|
|
if (::PopupAllowedForEvent("keydown"))
|
|
|
|
abuse = openControlled;
|
|
|
|
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 &&
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsMouseEvent*>(aEvent)->button == nsMouseEvent::eLeftButton) {
|
2007-03-22 10:30:00 -07:00
|
|
|
switch(aEvent->message) {
|
|
|
|
case NS_MOUSE_BUTTON_UP :
|
|
|
|
if (::PopupAllowedForEvent("mouseup"))
|
|
|
|
abuse = openControlled;
|
|
|
|
break;
|
|
|
|
case NS_MOUSE_BUTTON_DOWN :
|
|
|
|
if (::PopupAllowedForEvent("mousedown"))
|
|
|
|
abuse = openControlled;
|
|
|
|
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. */
|
|
|
|
if (::PopupAllowedForEvent("click"))
|
|
|
|
abuse = openAllowed;
|
|
|
|
break;
|
|
|
|
case NS_MOUSE_DOUBLECLICK :
|
|
|
|
if (::PopupAllowedForEvent("dblclick"))
|
|
|
|
abuse = openControlled;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_SCRIPT_ERROR_EVENT :
|
|
|
|
switch(aEvent->message) {
|
|
|
|
case NS_LOAD_ERROR :
|
|
|
|
// Any error event will allow popups, if enabled in the pref.
|
|
|
|
if (::PopupAllowedForEvent("error"))
|
|
|
|
abuse = openControlled;
|
|
|
|
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.
|
|
|
|
if (nsEventStateManager::IsHandlingUserInput()) {
|
|
|
|
switch(aEvent->message) {
|
|
|
|
case NS_FORM_SUBMIT :
|
|
|
|
if (::PopupAllowedForEvent("submit"))
|
|
|
|
abuse = openControlled;
|
|
|
|
break;
|
|
|
|
case NS_FORM_RESET :
|
|
|
|
if (::PopupAllowedForEvent("reset"))
|
|
|
|
abuse = openControlled;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2012-11-19 22:05:56 -08:00
|
|
|
default:
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return abuse;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
|
|
|
nsDOMEvent::PopupAllowedEventsChanged()
|
|
|
|
{
|
|
|
|
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
|
|
|
|
nsDOMEvent::Shutdown()
|
|
|
|
{
|
|
|
|
if (sPopupAllowedEvents) {
|
|
|
|
nsMemory::Free(sPopupAllowedEvents);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-16 16:24:11 -08:00
|
|
|
nsIntPoint
|
|
|
|
nsDOMEvent::GetScreenCoords(nsPresContext* aPresContext,
|
2013-10-01 20:46:04 -07:00
|
|
|
WidgetEvent* aEvent,
|
2013-08-02 00:05:16 -07:00
|
|
|
LayoutDeviceIntPoint aPoint)
|
2011-12-16 16:24:11 -08:00
|
|
|
{
|
2012-04-11 14:55:21 -07:00
|
|
|
if (nsEventStateManager::sIsPointerLocked) {
|
|
|
|
return nsEventStateManager::sLastScreenPoint;
|
|
|
|
}
|
|
|
|
|
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 &&
|
|
|
|
aEvent->eventStructType != NS_SIMPLE_GESTURE_EVENT)) {
|
|
|
|
return nsIntPoint(0, 0);
|
|
|
|
}
|
|
|
|
|
2013-10-01 20:46:03 -07:00
|
|
|
WidgetGUIEvent* guiEvent = static_cast<WidgetGUIEvent*>(aEvent);
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
//static
|
2013-07-10 02:55:05 -07:00
|
|
|
CSSIntPoint
|
2011-12-16 16:24:11 -08:00
|
|
|
nsDOMEvent::GetPageCoords(nsPresContext* aPresContext,
|
2013-10-01 20:46:04 -07:00
|
|
|
WidgetEvent* aEvent,
|
2013-08-02 00:05:16 -07:00
|
|
|
LayoutDeviceIntPoint aPoint,
|
2013-07-10 02:55:05 -07:00
|
|
|
CSSIntPoint aDefaultPoint)
|
2011-12-16 16:24:11 -08:00
|
|
|
{
|
2013-07-10 02:55:05 -07:00
|
|
|
CSSIntPoint pagePoint = nsDOMEvent::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
|
2011-12-16 16:24:11 -08:00
|
|
|
nsDOMEvent::GetClientCoords(nsPresContext* aPresContext,
|
2013-10-01 20:46:04 -07:00
|
|
|
WidgetEvent* aEvent,
|
2013-08-02 00:05:16 -07:00
|
|
|
LayoutDeviceIntPoint aPoint,
|
2013-07-10 02:55:05 -07:00
|
|
|
CSSIntPoint aDefaultPoint)
|
2011-12-16 16:24:11 -08:00
|
|
|
{
|
2012-04-11 14:55:21 -07:00
|
|
|
if (nsEventStateManager::sIsPointerLocked) {
|
|
|
|
return nsEventStateManager::sLastClientPoint;
|
|
|
|
}
|
|
|
|
|
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 &&
|
|
|
|
aEvent->eventStructType != NS_SIMPLE_GESTURE_EVENT) ||
|
|
|
|
!aPresContext ||
|
2013-10-01 20:46:03 -07:00
|
|
|
!static_cast<WidgetGUIEvent*>(aEvent)->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
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// To be called ONLY by nsDOMEvent::GetType (which has the additional
|
|
|
|
// logic for handling user-defined events).
|
|
|
|
// static
|
2012-08-22 08:56:38 -07:00
|
|
|
const char* nsDOMEvent::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_;
|
|
|
|
#include "nsEventNameList.h"
|
|
|
|
#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
|
|
|
|
// this is a problem generally *are* created by nsDOMEvent.)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-05-27 07:43:51 -07:00
|
|
|
bool
|
|
|
|
nsDOMEvent::GetPreventDefault() const
|
|
|
|
{
|
|
|
|
if (mOwner) {
|
|
|
|
if (nsIDocument* doc = mOwner->GetExtantDoc()) {
|
|
|
|
doc->WarnOnceAbout(nsIDocument::eGetPreventDefault);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return DefaultPrevented();
|
|
|
|
}
|
|
|
|
|
2009-06-23 03:07:39 -07:00
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsDOMEvent::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
|
2011-09-28 23:19:26 -07:00
|
|
|
nsDOMEvent::GetDefaultPrevented(bool* aReturn)
|
2011-05-13 13:44:35 -07:00
|
|
|
{
|
2013-03-17 00:55:17 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aReturn);
|
|
|
|
*aReturn = DefaultPrevented();
|
|
|
|
return NS_OK;
|
2011-05-13 13:44:35 -07:00
|
|
|
}
|
|
|
|
|
2012-06-10 11:14:30 -07:00
|
|
|
NS_IMETHODIMP_(void)
|
2011-09-28 23:19:26 -07:00
|
|
|
nsDOMEvent::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)
|
2009-11-17 06:22:23 -08:00
|
|
|
nsDOMEvent::Deserialize(const IPC::Message* aMsg, void** aIter)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
nsDOMEvent::SetOwner(mozilla::dom::EventTarget* aOwner)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsDOMEventTargetHelper> eth = do_QueryInterface(aOwner);
|
|
|
|
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
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult NS_NewDOMEvent(nsIDOMEvent** aInstancePtrResult,
|
2013-03-09 03:34:29 -08:00
|
|
|
mozilla::dom::EventTarget* aOwner,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsPresContext* aPresContext,
|
2013-10-01 20:46:04 -07:00
|
|
|
WidgetEvent* aEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-03-09 03:34:29 -08:00
|
|
|
nsRefPtr<nsDOMEvent> it =
|
2013-06-20 07:13:52 -07:00
|
|
|
new nsDOMEvent(aOwner, aPresContext, aEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
return CallQueryInterface(it, aInstancePtrResult);
|
|
|
|
}
|