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
|
|
|
|
|
|
|
/* This must occur *after* base/basictypes.h to avoid typedefs conflicts. */
|
|
|
|
#include "mozilla/Util.h"
|
|
|
|
|
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"
|
|
|
|
#include "nsIInterfaceRequestor.h"
|
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsMutationEvent.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsIScriptSecurityManager.h"
|
|
|
|
#include "nsIScriptError.h"
|
2011-05-28 00:03:00 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2011-12-14 11:54:46 -08:00
|
|
|
#include "nsJSUtils.h"
|
2011-12-23 14:13:46 -08:00
|
|
|
#include "DictionaryHelpers.h"
|
2011-12-16 16:24:11 -08:00
|
|
|
#include "nsLayoutUtils.h"
|
|
|
|
#include "nsIScrollableFrame.h"
|
2012-07-20 09:42:08 -07:00
|
|
|
#include "nsDOMClassInfoID.h"
|
2011-05-28 00:03:00 -07:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
static char *sPopupAllowedEvents;
|
|
|
|
|
|
|
|
|
|
|
|
nsDOMEvent::nsDOMEvent(nsPresContext* aPresContext, nsEvent* aEvent)
|
|
|
|
{
|
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
|
|
|
|
(derived from nsEvent). To do this, it should take care to pass
|
|
|
|
a non-NULL aEvent to this ctor, e.g.:
|
|
|
|
|
|
|
|
nsDOMFooEvent::nsDOMFooEvent(..., nsEvent* aEvent)
|
|
|
|
: nsDOMEvent(..., aEvent ? aEvent : new nsFooEvent())
|
|
|
|
|
|
|
|
Then, to override the mEventIsInternal assignments done by the
|
|
|
|
base ctor, it should do this in its own ctor:
|
|
|
|
|
|
|
|
nsDOMFooEvent::nsDOMFooEvent(..., nsEvent* aEvent)
|
|
|
|
...
|
|
|
|
{
|
|
|
|
...
|
|
|
|
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
|
|
|
}
|
|
|
|
...
|
|
|
|
}
|
|
|
|
*/
|
2011-10-17 07:59:28 -07:00
|
|
|
mEvent = new nsEvent(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
|
|
|
|
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();
|
2012-02-17 06:16:59 -08:00
|
|
|
mExplicitOriginalTarget = do_QueryInterface(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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-12 05:08:43 -08:00
|
|
|
DOMCI_DATA(Event, nsDOMEvent)
|
|
|
|
|
2007-06-26 01:21:42 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMEvent)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMEvent)
|
2011-12-14 11:53:48 -08:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIJSNativeInitializer)
|
2010-03-17 08:09:05 -07:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Event)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2007-06-26 01:21:42 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMEvent)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMEvent)
|
|
|
|
|
|
|
|
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:
|
2012-07-30 07:20:58 -07:00
|
|
|
static_cast<nsMouseEvent_base*>(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:
|
2012-07-30 07:20:58 -07:00
|
|
|
static_cast<nsDragEvent*>(tmp->mEvent)->dataTransfer = nullptr;
|
|
|
|
static_cast<nsMouseEvent_base*>(tmp->mEvent)->relatedTarget = nullptr;
|
2008-08-27 05:07:27 -07:00
|
|
|
break;
|
2007-06-26 01:21:42 -07:00
|
|
|
case NS_MUTATION_EVENT:
|
2012-07-30 07:20:58 -07:00
|
|
|
static_cast<nsMutationEvent*>(tmp->mEvent)->mRelatedNode = nullptr;
|
2007-06-26 01:21:42 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-14 23:32:40 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPresContext);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mExplicitOriginalTarget);
|
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(
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsMouseEvent_base*>(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(
|
|
|
|
static_cast<nsDragEvent*>(tmp->mEvent)->dataTransfer);
|
2009-02-17 03:49:03 -08:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mEvent->relatedTarget");
|
|
|
|
cb.NoteXPCOMChild(
|
|
|
|
static_cast<nsMouseEvent_base*>(tmp->mEvent)->relatedTarget);
|
2008-08-27 05:07:27 -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(
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsMutationEvent*>(tmp->mEvent)->mRelatedNode);
|
2007-06-26 01:21:42 -07:00
|
|
|
break;
|
|
|
|
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)
|
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)
|
|
|
|
{
|
2009-10-24 08:06:01 -07:00
|
|
|
if (!mCachedType.IsEmpty()) {
|
|
|
|
aType = mCachedType;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
const char* name = GetEventName(mEvent->message);
|
|
|
|
|
|
|
|
if (name) {
|
|
|
|
CopyASCIItoUTF16(name, aType);
|
2009-10-24 08:06:01 -07:00
|
|
|
mCachedType = aType;
|
2007-03-22 10:30:00 -07:00
|
|
|
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"
|
2009-10-24 08:06:01 -07:00
|
|
|
mCachedType = 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
|
|
|
}
|
|
|
|
|
2007-04-17 02:18:36 -07:00
|
|
|
static nsresult
|
2011-06-23 19:18:00 -07:00
|
|
|
GetDOMEventTarget(nsIDOMEventTarget* aTarget,
|
2007-04-17 02:18:36 -07:00
|
|
|
nsIDOMEventTarget** aDOMTarget)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-06-23 19:18:00 -07:00
|
|
|
nsIDOMEventTarget* realTarget =
|
2010-03-31 05:44:18 -07:00
|
|
|
aTarget ? aTarget->GetTargetForDOMEvent() : aTarget;
|
2007-04-17 02:18:36 -07:00
|
|
|
|
2011-06-23 19:18:01 -07:00
|
|
|
NS_IF_ADDREF(*aDOMTarget = realTarget);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-04-17 02:18:36 -07:00
|
|
|
NS_METHOD
|
|
|
|
nsDOMEvent::GetTarget(nsIDOMEventTarget** aTarget)
|
|
|
|
{
|
|
|
|
return GetDOMEventTarget(mEvent->target, aTarget);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMEvent::GetCurrentTarget(nsIDOMEventTarget** aCurrentTarget)
|
|
|
|
{
|
2007-04-17 02:18:36 -07:00
|
|
|
return GetDOMEventTarget(mEvent->currentTarget, aCurrentTarget);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMEvent::GetExplicitOriginalTarget(nsIDOMEventTarget** aRealEventTarget)
|
|
|
|
{
|
|
|
|
if (mExplicitOriginalTarget) {
|
|
|
|
*aRealEventTarget = mExplicitOriginalTarget;
|
|
|
|
NS_ADDREF(*aRealEventTarget);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetTarget(aRealEventTarget);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMEvent::GetOriginalTarget(nsIDOMEventTarget** aOriginalTarget)
|
|
|
|
{
|
|
|
|
if (mEvent->originalTarget) {
|
2007-04-17 02:18:36 -07:00
|
|
|
return GetDOMEventTarget(mEvent->originalTarget, aOriginalTarget);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return GetTarget(aOriginalTarget);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-12-14 11:53:48 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMEvent::Initialize(nsISupports* aOwner, JSContext* aCx, JSObject* aObj,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aArgc, jsval* aArgv)
|
2011-12-14 11:53:48 -08:00
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(aArgc >= 1, NS_ERROR_XPC_NOT_ENOUGH_ARGS);
|
|
|
|
|
|
|
|
bool trusted = false;
|
|
|
|
nsCOMPtr<nsPIDOMWindow> w = do_QueryInterface(aOwner);
|
|
|
|
if (w) {
|
|
|
|
nsCOMPtr<nsIDocument> d = do_QueryInterface(w->GetExtantDocument());
|
|
|
|
if (d) {
|
|
|
|
trusted = nsContentUtils::IsChromeDoc(d);
|
|
|
|
nsIPresShell* s = d->GetShell();
|
|
|
|
if (s) {
|
|
|
|
InitPresContextData(s->GetPresContext());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
JSAutoRequest ar(aCx);
|
|
|
|
JSString* jsstr = JS_ValueToString(aCx, aArgv[0]);
|
|
|
|
if (!jsstr) {
|
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::Anchor<JSString*> deleteProtector(jsstr);
|
|
|
|
|
2011-12-14 11:54:46 -08:00
|
|
|
nsDependentJSString type;
|
|
|
|
NS_ENSURE_STATE(type.init(aCx, jsstr));
|
2011-12-23 14:13:46 -08:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
nsresult rv = InitFromCtor(type, aCx, aArgc >= 2 ? &(aArgv[1]) : nullptr);
|
2011-12-14 11:53:48 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
SetTrusted(trusted);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-12-23 14:13:46 -08:00
|
|
|
nsDOMEvent::InitFromCtor(const nsAString& aType,
|
|
|
|
JSContext* aCx, jsval* aVal)
|
2011-12-14 11:53:48 -08:00
|
|
|
{
|
2013-02-11 11:37:50 -08:00
|
|
|
mozilla::idl::EventInit d;
|
2011-12-23 14:13:46 -08:00
|
|
|
nsresult rv = d.Init(aCx, aVal);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return InitEvent(aType, d.bubbles, d.cancelable);
|
2011-12-14 11:53:48 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsDOMEvent::GetEventPhase(uint16_t* aEventPhase)
|
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()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
*aEventPhase = nsIDOMEvent::AT_TARGET;
|
2012-12-15 17:26:03 -08:00
|
|
|
} else if (mEvent->mFlags.mInCapturePhase) {
|
2007-03-22 10:30:00 -07:00
|
|
|
*aEventPhase = nsIDOMEvent::CAPTURING_PHASE;
|
2012-12-15 17:26:03 -08:00
|
|
|
} else if (mEvent->mFlags.mInBubblingPhase) {
|
2007-03-22 10:30:00 -07:00
|
|
|
*aEventPhase = nsIDOMEvent::BUBBLING_PHASE;
|
|
|
|
} else {
|
2012-05-03 03:59:51 -07:00
|
|
|
*aEventPhase = nsIDOMEvent::NONE;
|
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
|
|
|
{
|
2012-12-15 17:26:03 -08:00
|
|
|
*aBubbles = mEvent->mFlags.mBubbles;
|
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
|
|
|
{
|
2012-12-15 17:26:03 -08:00
|
|
|
*aCancelable = mEvent->mFlags.mCancelable;
|
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
|
|
|
{
|
2010-08-11 14:05:27 -07:00
|
|
|
*aTimeStamp = mEvent->time;
|
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;
|
|
|
|
}
|
|
|
|
|
2008-12-06 01:30:01 -08:00
|
|
|
static nsIDocument* GetDocumentForReport(nsEvent* aEvent)
|
|
|
|
{
|
2012-12-02 00:59:29 -08:00
|
|
|
nsIDOMEventTarget* target = aEvent->currentTarget;
|
|
|
|
if (nsCOMPtr<nsINode> node = do_QueryInterface(target)) {
|
2011-10-18 03:53:36 -07:00
|
|
|
return node->OwnerDoc();
|
2012-12-02 00:59:29 -08:00
|
|
|
}
|
2008-12-06 01:30:01 -08:00
|
|
|
|
2012-12-02 00:59:29 -08:00
|
|
|
if (nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(target)) {
|
|
|
|
return window->GetExtantDoc();
|
|
|
|
}
|
2008-12-06 01:30:01 -08:00
|
|
|
|
2012-12-02 00:59:29 -08:00
|
|
|
return nullptr;
|
2008-12-06 01:30:01 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static void
|
|
|
|
ReportUseOfDeprecatedMethod(nsEvent* aEvent, nsIDOMEvent* aDOMEvent,
|
|
|
|
const char* aWarning)
|
|
|
|
{
|
2008-12-06 01:30:01 -08:00
|
|
|
nsCOMPtr<nsIDocument> doc(GetDocumentForReport(aEvent));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsAutoString type;
|
|
|
|
aDOMEvent->GetType(type);
|
|
|
|
const PRUnichar *strings[] = { type.get() };
|
2011-12-15 06:47:03 -08:00
|
|
|
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
|
|
|
|
"DOM Events", doc,
|
|
|
|
nsContentUtils::eDOM_PROPERTIES,
|
2007-03-22 10:30:00 -07:00
|
|
|
aWarning,
|
2011-12-15 06:47:03 -08:00
|
|
|
strings, ArrayLength(strings));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMEvent::PreventBubble()
|
|
|
|
{
|
|
|
|
ReportUseOfDeprecatedMethod(mEvent, this, "UseOfPreventBubbleWarning");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMEvent::PreventCapture()
|
|
|
|
{
|
|
|
|
ReportUseOfDeprecatedMethod(mEvent, this, "UseOfPreventCaptureWarning");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsDOMEvent::GetIsTrusted(bool *aIsTrusted)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-12-15 17:26:03 -08:00
|
|
|
*aIsTrusted = mEvent->mFlags.mIsTrusted;
|
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.
|
2012-12-15 17:26:03 -08:00
|
|
|
if (mEvent->eventStructType == NS_DRAG_EVENT && mEvent->mFlags.mIsTrusted) {
|
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) {
|
|
|
|
node = do_QueryInterface(win->GetExtantDocument());
|
|
|
|
}
|
|
|
|
}
|
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)
|
|
|
|
{
|
2010-06-22 11:12:12 -07:00
|
|
|
mEvent->userType =
|
|
|
|
nsContentUtils::GetEventIdAndAtom(aEventTypeArg, mEvent->eventStructType,
|
|
|
|
&(mEvent->message));
|
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
|
|
|
|
2012-12-15 17:26:03 -08:00
|
|
|
if (mEvent->mFlags.mIsTrusted) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Ensure the caller is permitted to dispatch trusted DOM events.
|
2012-10-21 23:29:55 -07:00
|
|
|
if (!nsContentUtils::IsCallerChrome()) {
|
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
|
|
|
|
|
|
|
// 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;
|
2009-10-24 08:06:01 -07:00
|
|
|
mCachedType = aEventTypeArg;
|
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
|
|
|
|
|
|
|
|
NS_ASSERTION(mEvent, "No nsEvent for nsDOMEvent duplication!");
|
|
|
|
if (mEventIsInternal) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
nsEvent* newEvent = nullptr;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t msg = mEvent->message;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isInputEvent = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
switch (mEvent->eventStructType) {
|
|
|
|
case NS_EVENT:
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
newEvent = new nsEvent(false, msg);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NS_GUI_EVENT:
|
|
|
|
{
|
|
|
|
// Not copying widget, it is a weak reference.
|
2012-07-30 07:20:58 -07:00
|
|
|
newEvent = new nsGUIEvent(false, msg, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NS_SCROLLBAR_EVENT:
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
newEvent = new nsScrollbarEvent(false, msg, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_TRUE(newEvent, NS_ERROR_OUT_OF_MEMORY);
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsScrollbarEvent*>(newEvent)->position =
|
|
|
|
static_cast<nsScrollbarEvent*>(mEvent)->position;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NS_INPUT_EVENT:
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
newEvent = new nsInputEvent(false, msg, nullptr);
|
2011-10-17 07:59:28 -07:00
|
|
|
isInputEvent = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NS_KEY_EVENT:
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
nsKeyEvent* keyEvent = new nsKeyEvent(false, msg, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_TRUE(keyEvent, NS_ERROR_OUT_OF_MEMORY);
|
2007-07-08 00:08:04 -07:00
|
|
|
nsKeyEvent* oldKeyEvent = static_cast<nsKeyEvent*>(mEvent);
|
2011-10-17 07:59:28 -07:00
|
|
|
isInputEvent = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
keyEvent->keyCode = oldKeyEvent->keyCode;
|
|
|
|
keyEvent->charCode = oldKeyEvent->charCode;
|
2012-05-03 01:35:01 -07:00
|
|
|
keyEvent->location = oldKeyEvent->location;
|
2007-03-22 10:30:00 -07:00
|
|
|
keyEvent->isChar = oldKeyEvent->isChar;
|
|
|
|
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);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_TRUE(mouseEvent, NS_ERROR_OUT_OF_MEMORY);
|
2011-10-17 07:59:28 -07:00
|
|
|
isInputEvent = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
mouseEvent->clickCount = oldMouseEvent->clickCount;
|
|
|
|
mouseEvent->acceptActivation = oldMouseEvent->acceptActivation;
|
2007-09-18 00:25:49 -07:00
|
|
|
mouseEvent->context = oldMouseEvent->context;
|
2007-03-22 10:30:00 -07:00
|
|
|
mouseEvent->relatedTarget = oldMouseEvent->relatedTarget;
|
|
|
|
mouseEvent->button = oldMouseEvent->button;
|
2012-04-24 20:00:01 -07:00
|
|
|
mouseEvent->buttons = oldMouseEvent->buttons;
|
2008-12-11 15:55:15 -08:00
|
|
|
mouseEvent->pressure = oldMouseEvent->pressure;
|
2010-04-06 05:59:24 -07:00
|
|
|
mouseEvent->inputSource = oldMouseEvent->inputSource;
|
2007-03-22 10:30:00 -07:00
|
|
|
newEvent = mouseEvent;
|
|
|
|
break;
|
|
|
|
}
|
2008-08-27 05:07:27 -07:00
|
|
|
case NS_DRAG_EVENT:
|
|
|
|
{
|
|
|
|
nsDragEvent* oldDragEvent = static_cast<nsDragEvent*>(mEvent);
|
|
|
|
nsDragEvent* dragEvent =
|
2012-07-30 07:20:58 -07:00
|
|
|
new nsDragEvent(false, msg, nullptr);
|
2008-08-27 05:07:27 -07:00
|
|
|
NS_ENSURE_TRUE(dragEvent, NS_ERROR_OUT_OF_MEMORY);
|
2011-10-17 07:59:28 -07:00
|
|
|
isInputEvent = true;
|
2008-08-27 05:07:27 -07:00
|
|
|
dragEvent->dataTransfer = oldDragEvent->dataTransfer;
|
|
|
|
dragEvent->clickCount = oldDragEvent->clickCount;
|
|
|
|
dragEvent->acceptActivation = oldDragEvent->acceptActivation;
|
|
|
|
dragEvent->relatedTarget = oldDragEvent->relatedTarget;
|
|
|
|
dragEvent->button = oldDragEvent->button;
|
2012-04-24 20:00:01 -07:00
|
|
|
dragEvent->buttons = oldDragEvent->buttons;
|
2010-04-06 05:59:24 -07:00
|
|
|
static_cast<nsMouseEvent*>(dragEvent)->inputSource =
|
|
|
|
static_cast<nsMouseEvent*>(oldDragEvent)->inputSource;
|
2008-08-27 05:07:27 -07:00
|
|
|
newEvent = dragEvent;
|
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
case NS_SCRIPT_ERROR_EVENT:
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
newEvent = new nsScriptErrorEvent(false, msg);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_TRUE(newEvent, NS_ERROR_OUT_OF_MEMORY);
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsScriptErrorEvent*>(newEvent)->lineNr =
|
|
|
|
static_cast<nsScriptErrorEvent*>(mEvent)->lineNr;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NS_TEXT_EVENT:
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
newEvent = new nsTextEvent(false, msg, nullptr);
|
2011-10-17 07:59:28 -07:00
|
|
|
isInputEvent = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NS_COMPOSITION_EVENT:
|
|
|
|
{
|
2011-09-22 02:17:40 -07:00
|
|
|
nsCompositionEvent* compositionEvent =
|
2012-07-30 07:20:58 -07:00
|
|
|
new nsCompositionEvent(false, msg, nullptr);
|
2011-09-22 02:17:40 -07:00
|
|
|
nsCompositionEvent* oldCompositionEvent =
|
|
|
|
static_cast<nsCompositionEvent*>(mEvent);
|
|
|
|
compositionEvent->data = oldCompositionEvent->data;
|
|
|
|
newEvent = compositionEvent;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NS_MOUSE_SCROLL_EVENT:
|
|
|
|
{
|
|
|
|
nsMouseScrollEvent* mouseScrollEvent =
|
2012-07-30 07:20:58 -07:00
|
|
|
new nsMouseScrollEvent(false, msg, nullptr);
|
2011-10-17 07:59:28 -07:00
|
|
|
isInputEvent = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMouseScrollEvent* oldMouseScrollEvent =
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsMouseScrollEvent*>(mEvent);
|
2012-08-11 18:42:37 -07:00
|
|
|
mouseScrollEvent->isHorizontal = oldMouseScrollEvent->isHorizontal;
|
2007-03-22 10:30:00 -07:00
|
|
|
mouseScrollEvent->delta = oldMouseScrollEvent->delta;
|
|
|
|
mouseScrollEvent->relatedTarget = oldMouseScrollEvent->relatedTarget;
|
|
|
|
mouseScrollEvent->button = oldMouseScrollEvent->button;
|
2012-04-24 20:00:01 -07:00
|
|
|
mouseScrollEvent->buttons = oldMouseScrollEvent->buttons;
|
2010-04-06 05:59:24 -07:00
|
|
|
static_cast<nsMouseEvent_base*>(mouseScrollEvent)->inputSource =
|
|
|
|
static_cast<nsMouseEvent_base*>(oldMouseScrollEvent)->inputSource;
|
2007-03-22 10:30:00 -07:00
|
|
|
newEvent = mouseScrollEvent;
|
|
|
|
break;
|
|
|
|
}
|
2012-08-11 18:42:34 -07:00
|
|
|
case NS_WHEEL_EVENT:
|
|
|
|
{
|
|
|
|
widget::WheelEvent* wheelEvent =
|
|
|
|
new widget::WheelEvent(false, msg, nullptr);
|
|
|
|
isInputEvent = true;
|
|
|
|
widget::WheelEvent* oldWheelEvent =
|
|
|
|
static_cast<widget::WheelEvent*>(mEvent);
|
|
|
|
wheelEvent->deltaX = oldWheelEvent->deltaX;
|
|
|
|
wheelEvent->deltaY = oldWheelEvent->deltaY;
|
|
|
|
wheelEvent->deltaZ = oldWheelEvent->deltaZ;
|
|
|
|
wheelEvent->deltaMode = oldWheelEvent->deltaMode;
|
|
|
|
wheelEvent->relatedTarget = oldWheelEvent->relatedTarget;
|
|
|
|
wheelEvent->button = oldWheelEvent->button;
|
|
|
|
wheelEvent->buttons = oldWheelEvent->buttons;
|
|
|
|
wheelEvent->modifiers = oldWheelEvent->modifiers;
|
|
|
|
wheelEvent->inputSource = oldWheelEvent->inputSource;
|
2012-08-11 18:42:35 -07:00
|
|
|
wheelEvent->customizedByUserPrefs = oldWheelEvent->customizedByUserPrefs;
|
2012-08-11 18:42:36 -07:00
|
|
|
wheelEvent->isMomentum = oldWheelEvent->isMomentum;
|
2012-08-11 18:42:36 -07:00
|
|
|
wheelEvent->isPixelOnlyDevice = oldWheelEvent->isPixelOnlyDevice;
|
2012-08-11 18:42:35 -07:00
|
|
|
wheelEvent->lineOrPageDeltaX = oldWheelEvent->lineOrPageDeltaX;
|
|
|
|
wheelEvent->lineOrPageDeltaY = oldWheelEvent->lineOrPageDeltaY;
|
2012-08-11 18:42:36 -07:00
|
|
|
wheelEvent->scrollType = oldWheelEvent->scrollType;
|
2012-08-11 18:42:35 -07:00
|
|
|
wheelEvent->overflowDeltaX = oldWheelEvent->overflowDeltaX;
|
|
|
|
wheelEvent->overflowDeltaY = oldWheelEvent->overflowDeltaY;
|
2012-08-11 18:42:34 -07:00
|
|
|
newEvent = wheelEvent;
|
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
case NS_SCROLLPORT_EVENT:
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
newEvent = new nsScrollPortEvent(false, msg, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_TRUE(newEvent, NS_ERROR_OUT_OF_MEMORY);
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsScrollPortEvent*>(newEvent)->orient =
|
|
|
|
static_cast<nsScrollPortEvent*>(mEvent)->orient;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
2009-09-11 16:13:56 -07:00
|
|
|
case NS_SCROLLAREA_EVENT:
|
|
|
|
{
|
|
|
|
nsScrollAreaEvent *newScrollAreaEvent =
|
2012-07-30 07:20:58 -07:00
|
|
|
new nsScrollAreaEvent(false, msg, nullptr);
|
2009-09-11 16:13:56 -07:00
|
|
|
NS_ENSURE_TRUE(newScrollAreaEvent, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
newScrollAreaEvent->mArea =
|
|
|
|
static_cast<nsScrollAreaEvent *>(mEvent)->mArea;
|
|
|
|
newEvent = newScrollAreaEvent;
|
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
case NS_MUTATION_EVENT:
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
nsMutationEvent* mutationEvent = new nsMutationEvent(false, msg);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_TRUE(mutationEvent, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
nsMutationEvent* oldMutationEvent =
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsMutationEvent*>(mEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
mutationEvent->mRelatedNode = oldMutationEvent->mRelatedNode;
|
|
|
|
mutationEvent->mAttrName = oldMutationEvent->mAttrName;
|
|
|
|
mutationEvent->mPrevAttrValue = oldMutationEvent->mPrevAttrValue;
|
|
|
|
mutationEvent->mNewAttrValue = oldMutationEvent->mNewAttrValue;
|
|
|
|
mutationEvent->mAttrChange = oldMutationEvent->mAttrChange;
|
|
|
|
newEvent = mutationEvent;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NS_FORM_EVENT:
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
newEvent = new nsFormEvent(false, msg);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
2009-10-01 10:53:10 -07:00
|
|
|
case NS_FOCUS_EVENT:
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
nsFocusEvent* newFocusEvent = new nsFocusEvent(false, msg);
|
2010-10-18 11:12:18 -07:00
|
|
|
NS_ENSURE_TRUE(newFocusEvent, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
nsFocusEvent* oldFocusEvent = static_cast<nsFocusEvent*>(mEvent);
|
|
|
|
newFocusEvent->fromRaise = oldFocusEvent->fromRaise;
|
|
|
|
newFocusEvent->isRefocus = oldFocusEvent->isRefocus;
|
|
|
|
newEvent = newFocusEvent;
|
2009-10-01 10:53:10 -07:00
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
case NS_COMMAND_EVENT:
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
newEvent = new nsCommandEvent(false, mEvent->userType,
|
2012-07-30 07:20:58 -07:00
|
|
|
static_cast<nsCommandEvent*>(mEvent)->command, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_TRUE(newEvent, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NS_UI_EVENT:
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
newEvent = new nsUIEvent(false, msg,
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsUIEvent*>(mEvent)->detail);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NS_SVG_EVENT:
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
newEvent = new nsEvent(false, msg);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_TRUE(newEvent, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
newEvent->eventStructType = NS_SVG_EVENT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NS_SVGZOOM_EVENT:
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
newEvent = new nsGUIEvent(false, msg, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_TRUE(newEvent, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
newEvent->eventStructType = NS_SVGZOOM_EVENT;
|
|
|
|
break;
|
|
|
|
}
|
2010-07-31 00:02:52 -07:00
|
|
|
case NS_SMIL_TIME_EVENT:
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
newEvent = new nsUIEvent(false, msg, 0);
|
2010-07-31 00:02:52 -07:00
|
|
|
NS_ENSURE_TRUE(newEvent, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
newEvent->eventStructType = NS_SMIL_TIME_EVENT;
|
|
|
|
break;
|
|
|
|
}
|
2008-10-23 13:15:20 -07:00
|
|
|
case NS_SIMPLE_GESTURE_EVENT:
|
|
|
|
{
|
|
|
|
nsSimpleGestureEvent* oldSimpleGestureEvent = static_cast<nsSimpleGestureEvent*>(mEvent);
|
|
|
|
nsSimpleGestureEvent* simpleGestureEvent =
|
2012-07-30 07:20:58 -07:00
|
|
|
new nsSimpleGestureEvent(false, msg, nullptr, 0, 0.0);
|
2008-10-23 13:15:20 -07:00
|
|
|
NS_ENSURE_TRUE(simpleGestureEvent, NS_ERROR_OUT_OF_MEMORY);
|
2011-10-17 07:59:28 -07:00
|
|
|
isInputEvent = true;
|
2008-10-23 13:15:20 -07:00
|
|
|
simpleGestureEvent->direction = oldSimpleGestureEvent->direction;
|
|
|
|
simpleGestureEvent->delta = oldSimpleGestureEvent->delta;
|
2012-06-14 10:40:12 -07:00
|
|
|
simpleGestureEvent->clickCount = oldSimpleGestureEvent->clickCount;
|
2008-10-23 13:15:20 -07:00
|
|
|
newEvent = simpleGestureEvent;
|
|
|
|
break;
|
|
|
|
}
|
2009-12-23 11:10:31 -08:00
|
|
|
case NS_TRANSITION_EVENT:
|
|
|
|
{
|
|
|
|
nsTransitionEvent* oldTransitionEvent =
|
|
|
|
static_cast<nsTransitionEvent*>(mEvent);
|
2011-10-17 07:59:28 -07:00
|
|
|
newEvent = new nsTransitionEvent(false, msg,
|
2009-12-23 11:10:31 -08:00
|
|
|
oldTransitionEvent->propertyName,
|
|
|
|
oldTransitionEvent->elapsedTime);
|
|
|
|
NS_ENSURE_TRUE(newEvent, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
break;
|
|
|
|
}
|
2011-04-11 23:18:44 -07:00
|
|
|
case NS_ANIMATION_EVENT:
|
|
|
|
{
|
|
|
|
nsAnimationEvent* oldAnimationEvent =
|
|
|
|
static_cast<nsAnimationEvent*>(mEvent);
|
2011-10-17 07:59:28 -07:00
|
|
|
newEvent = new nsAnimationEvent(false, msg,
|
2011-04-11 23:18:44 -07:00
|
|
|
oldAnimationEvent->animationName,
|
|
|
|
oldAnimationEvent->elapsedTime);
|
|
|
|
NS_ENSURE_TRUE(newEvent, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
break;
|
|
|
|
}
|
2011-12-16 16:24:11 -08:00
|
|
|
case NS_TOUCH_EVENT:
|
|
|
|
{
|
2012-04-04 10:08:53 -07:00
|
|
|
nsTouchEvent *oldTouchEvent = static_cast<nsTouchEvent*>(mEvent);
|
|
|
|
newEvent = new nsTouchEvent(false, oldTouchEvent);
|
2011-12-16 16:24:11 -08:00
|
|
|
NS_ENSURE_TRUE(newEvent, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
isInputEvent = true;
|
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
NS_WARNING("Unknown event type!!!");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE(newEvent, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
if (isInputEvent) {
|
2007-07-08 00:08:04 -07:00
|
|
|
nsInputEvent* oldInputEvent = static_cast<nsInputEvent*>(mEvent);
|
|
|
|
nsInputEvent* newInputEvent = static_cast<nsInputEvent*>(newEvent);
|
2012-04-24 20:00:02 -07:00
|
|
|
newInputEvent->modifiers = oldInputEvent->modifiers;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
newEvent->target = mEvent->target;
|
|
|
|
newEvent->currentTarget = mEvent->currentTarget;
|
|
|
|
newEvent->originalTarget = mEvent->originalTarget;
|
2012-12-15 17:26:03 -08:00
|
|
|
newEvent->mFlags = mEvent->mFlags;
|
2007-03-22 10:30:00 -07:00
|
|
|
newEvent->time = mEvent->time;
|
|
|
|
newEvent->refPoint = mEvent->refPoint;
|
|
|
|
newEvent->userType = mEvent->userType;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-10-09 16:23:07 -07:00
|
|
|
NS_IMETHODIMP_(nsEvent*)
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
nsDOMEvent::GetEventPopupControlState(nsEvent *aEvent)
|
|
|
|
{
|
|
|
|
// 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) {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t key = static_cast<nsKeyEvent *>(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;
|
|
|
|
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,
|
|
|
|
nsEvent* aEvent,
|
|
|
|
nsIntPoint aPoint)
|
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsGUIEvent* guiEvent = static_cast<nsGUIEvent*>(aEvent);
|
|
|
|
if (!guiEvent->widget) {
|
|
|
|
return aPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIntPoint offset = aPoint + guiEvent->widget->WidgetToScreenOffset();
|
|
|
|
nscoord factor = aPresContext->DeviceContext()->UnscaledAppUnitsPerDevPixel();
|
|
|
|
return nsIntPoint(nsPresContext::AppUnitsToIntCSSPixels(offset.x * factor),
|
|
|
|
nsPresContext::AppUnitsToIntCSSPixels(offset.y * factor));
|
|
|
|
}
|
|
|
|
|
|
|
|
//static
|
|
|
|
nsIntPoint
|
|
|
|
nsDOMEvent::GetPageCoords(nsPresContext* aPresContext,
|
|
|
|
nsEvent* aEvent,
|
|
|
|
nsIntPoint aPoint,
|
|
|
|
nsIntPoint aDefaultPoint)
|
|
|
|
{
|
|
|
|
nsIntPoint pagePoint = nsDOMEvent::GetClientCoords(aPresContext,
|
|
|
|
aEvent,
|
|
|
|
aPoint,
|
|
|
|
aDefaultPoint);
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
nsPoint pt = scrollframe->GetScrollPosition();
|
|
|
|
pagePoint += nsIntPoint(nsPresContext::AppUnitsToIntCSSPixels(pt.x),
|
|
|
|
nsPresContext::AppUnitsToIntCSSPixels(pt.y));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pagePoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
nsIntPoint
|
|
|
|
nsDOMEvent::GetClientCoords(nsPresContext* aPresContext,
|
|
|
|
nsEvent* aEvent,
|
|
|
|
nsIntPoint aPoint,
|
|
|
|
nsIntPoint aDefaultPoint)
|
|
|
|
{
|
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 ||
|
|
|
|
!((nsGUIEvent*)aEvent)->widget) {
|
|
|
|
return aDefaultPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPoint pt(0, 0);
|
|
|
|
nsIPresShell* shell = aPresContext->GetPresShell();
|
|
|
|
if (!shell) {
|
|
|
|
return nsIntPoint(0, 0);
|
|
|
|
}
|
|
|
|
nsIFrame* rootFrame = shell->GetRootFrame();
|
|
|
|
if (rootFrame)
|
|
|
|
pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, aPoint, rootFrame);
|
|
|
|
|
|
|
|
return nsIntPoint(nsPresContext::AppUnitsToIntCSSPixels(pt.x),
|
|
|
|
nsPresContext::AppUnitsToIntCSSPixels(pt.y));
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
// XXXldb We can hit this case for nsEvent objects that we didn't
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
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);
|
2012-12-15 17:26:04 -08:00
|
|
|
*aReturn = mEvent && mEvent->mFlags.mDefaultPrevented;
|
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
|
|
|
{
|
|
|
|
return GetPreventDefault(aReturn);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool bubbles = false;
|
2009-11-17 06:22:23 -08:00
|
|
|
GetBubbles(&bubbles);
|
|
|
|
IPC::WriteParam(aMsg, bubbles);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool cancelable = false;
|
2009-11-17 06:22:23 -08:00
|
|
|
GetCancelable(&cancelable);
|
|
|
|
IPC::WriteParam(aMsg, cancelable);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool trusted = false;
|
2009-11-17 06:22:23 -08:00
|
|
|
GetIsTrusted(&trusted);
|
|
|
|
IPC::WriteParam(aMsg, trusted);
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult NS_NewDOMEvent(nsIDOMEvent** aInstancePtrResult,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
nsEvent *aEvent)
|
|
|
|
{
|
|
|
|
nsDOMEvent* it = new nsDOMEvent(aPresContext, aEvent);
|
2012-07-30 07:20:58 -07:00
|
|
|
if (nullptr == it) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CallQueryInterface(it, aInstancePtrResult);
|
|
|
|
}
|