2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1998-06-07 11:55:55 +04:00
|
|
|
|
2013-12-08 19:51:16 +04:00
|
|
|
#include "AccessCheck.h"
|
2014-03-05 04:37:43 +04:00
|
|
|
#include "base/basictypes.h"
|
2012-08-28 16:41:04 +04:00
|
|
|
#include "ipc/IPCMessageUtils.h"
|
2014-03-05 04:37:43 +04:00
|
|
|
#include "mozilla/dom/Event.h"
|
2014-08-27 07:19:56 +04:00
|
|
|
#include "mozilla/dom/ShadowRoot.h"
|
2013-09-25 15:21:20 +04:00
|
|
|
#include "mozilla/ContentEvents.h"
|
2014-04-01 10:13:50 +04:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2014-04-01 08:09:23 +04:00
|
|
|
#include "mozilla/EventStateManager.h"
|
2014-02-27 14:51:15 +04:00
|
|
|
#include "mozilla/InternalMutationEvent.h"
|
2013-09-25 15:21:20 +04:00
|
|
|
#include "mozilla/MiscEvents.h"
|
2013-09-25 15:21:18 +04:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2014-03-05 04:37:43 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2013-09-25 15:21:19 +04:00
|
|
|
#include "mozilla/TextEvents.h"
|
2013-09-25 15:21:16 +04:00
|
|
|
#include "mozilla/TouchEvents.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
#include "nsContentUtils.h"
|
2014-03-05 04:37:43 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsDeviceContext.h"
|
|
|
|
#include "nsError.h"
|
|
|
|
#include "nsGlobalWindow.h"
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIScrollableFrame.h"
|
2013-03-07 22:53:19 +04:00
|
|
|
#include "nsJSEnvironment.h"
|
2011-12-17 04:24:11 +04:00
|
|
|
#include "nsLayoutUtils.h"
|
2014-06-06 09:29:49 +04:00
|
|
|
#include "nsPerformance.h"
|
2013-03-09 15:34:29 +04:00
|
|
|
#include "nsPIWindowRoot.h"
|
2014-06-06 09:29:49 +04:00
|
|
|
#include "WorkerPrivate.h"
|
1998-07-17 08:52:12 +04:00
|
|
|
|
2013-12-08 19:51:16 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2014-03-05 04:37:43 +04:00
|
|
|
|
2013-12-08 19:51:16 +04:00
|
|
|
namespace workers {
|
|
|
|
extern bool IsCurrentThreadRunningChromeWorker();
|
|
|
|
} // namespace workers
|
|
|
|
|
2004-09-04 23:28:46 +04:00
|
|
|
static char *sPopupAllowedEvents;
|
|
|
|
|
2014-06-06 09:29:49 +04:00
|
|
|
static bool sReturnHighResTimeStamp = false;
|
|
|
|
static bool sReturnHighResTimeStampIsSet = false;
|
|
|
|
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::Event(EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetEvent* aEvent)
|
2013-05-08 04:55:21 +04:00
|
|
|
{
|
|
|
|
ConstructorInit(aOwner, aPresContext, aEvent);
|
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
Event::Event(nsPIDOMWindowInner* aParent)
|
2013-05-08 04:55:21 +04:00
|
|
|
{
|
2016-01-30 20:05:36 +03:00
|
|
|
ConstructorInit(nsGlobalWindow::Cast(aParent), nullptr, nullptr);
|
2013-05-08 04:55:21 +04:00
|
|
|
}
|
|
|
|
|
2013-06-20 18:13:52 +04:00
|
|
|
void
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::ConstructorInit(EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetEvent* aEvent)
|
2001-02-12 09:54:31 +03:00
|
|
|
{
|
2013-03-09 15:34:29 +04:00
|
|
|
SetOwner(aOwner);
|
2015-06-25 19:26:09 +03:00
|
|
|
mIsMainThreadEvent = NS_IsMainThread();
|
2013-03-09 15:34:29 +04:00
|
|
|
|
2014-06-06 09:29:49 +04:00
|
|
|
if (mIsMainThreadEvent && !sReturnHighResTimeStampIsSet) {
|
|
|
|
Preferences::AddBoolVarCache(&sReturnHighResTimeStamp,
|
|
|
|
"dom.event.highrestimestamp.enabled",
|
|
|
|
sReturnHighResTimeStamp);
|
|
|
|
sReturnHighResTimeStampIsSet = true;
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mPrivateDataDuplicated = false;
|
2014-10-15 18:48:04 +04:00
|
|
|
mWantsPopupControlCheck = false;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
|
2000-05-16 15:35:12 +04:00
|
|
|
if (aEvent) {
|
|
|
|
mEvent = aEvent;
|
2011-10-17 18:59:28 +04:00
|
|
|
mEventIsInternal = false;
|
2000-05-16 15:35:12 +04:00
|
|
|
}
|
|
|
|
else {
|
2011-10-17 18:59:28 +04:00
|
|
|
mEventIsInternal = true;
|
2004-08-20 22:09:19 +04:00
|
|
|
/*
|
|
|
|
A derived class might want to allocate its own type of aEvent
|
2013-10-02 07:46:04 +04:00
|
|
|
(derived from WidgetEvent). To do this, it should take care to pass
|
2013-04-03 05:14:24 +04:00
|
|
|
a non-nullptr aEvent to this ctor, e.g.:
|
2004-08-20 22:09:19 +04:00
|
|
|
|
2014-03-05 04:37:43 +04:00
|
|
|
FooEvent::FooEvent(..., WidgetEvent* aEvent)
|
|
|
|
: Event(..., aEvent ? aEvent : new WidgetEvent())
|
2004-08-20 22:09:19 +04:00
|
|
|
|
2004-09-04 23:28:46 +04:00
|
|
|
Then, to override the mEventIsInternal assignments done by the
|
|
|
|
base ctor, it should do this in its own ctor:
|
2004-08-20 22:09:19 +04:00
|
|
|
|
2014-03-05 04:37:43 +04:00
|
|
|
FooEvent::FooEvent(..., WidgetEvent* aEvent)
|
2004-08-20 22:09:19 +04:00
|
|
|
...
|
|
|
|
{
|
|
|
|
...
|
|
|
|
if (aEvent) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mEventIsInternal = false;
|
2004-08-20 22:09:19 +04:00
|
|
|
}
|
|
|
|
else {
|
2011-10-17 18:59:28 +04:00
|
|
|
mEventIsInternal = true;
|
2004-08-20 22:09:19 +04:00
|
|
|
}
|
|
|
|
...
|
|
|
|
}
|
|
|
|
*/
|
2015-08-29 02:58:26 +03:00
|
|
|
mEvent = new WidgetEvent(false, eVoidEvent);
|
2004-08-20 22:09:19 +04:00
|
|
|
mEvent->time = PR_Now();
|
2000-05-16 15:35:12 +04:00
|
|
|
}
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
|
2011-12-14 23:53:48 +04:00
|
|
|
InitPresContextData(aPresContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::InitPresContextData(nsPresContext* aPresContext)
|
2011-12-14 23:53:48 +04:00
|
|
|
{
|
|
|
|
mPresContext = aPresContext;
|
2003-02-22 11:10:46 +03:00
|
|
|
// Get the explicit original target (if it's anonymous make it null)
|
|
|
|
{
|
2010-06-11 15:10:51 +04:00
|
|
|
nsCOMPtr<nsIContent> content = GetTargetFromFrame();
|
2013-03-17 11:55:17 +04:00
|
|
|
mExplicitOriginalTarget = content;
|
2008-07-23 08:50:20 +04:00
|
|
|
if (content && content->IsInAnonymousSubtree()) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mExplicitOriginalTarget = nullptr;
|
2003-02-22 11:10:46 +03:00
|
|
|
}
|
|
|
|
}
|
1998-06-07 11:55:55 +04:00
|
|
|
}
|
|
|
|
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::~Event()
|
2001-02-12 09:54:31 +03:00
|
|
|
{
|
2014-03-05 04:37:43 +04:00
|
|
|
NS_ASSERT_OWNINGTHREAD(Event);
|
2001-02-12 09:54:31 +03:00
|
|
|
|
2006-06-05 22:38:54 +04:00
|
|
|
if (mEventIsInternal && mEvent) {
|
2004-01-12 11:25:18 +03:00
|
|
|
delete mEvent;
|
2000-05-16 15:35:12 +04:00
|
|
|
}
|
1998-06-07 11:55:55 +04:00
|
|
|
}
|
|
|
|
|
2014-03-05 04:37:43 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Event)
|
2013-03-09 15:34:29 +04:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2013-06-20 18:13:52 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2004-08-20 22:09:19 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMEvent)
|
1999-12-21 22:28:15 +03:00
|
|
|
NS_INTERFACE_MAP_END
|
1998-06-07 11:55:55 +04:00
|
|
|
|
2014-03-05 04:37:43 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(Event)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(Event)
|
2007-06-26 12:21:42 +04:00
|
|
|
|
2014-03-05 04:37:43 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(Event)
|
2013-08-02 05:29:05 +04:00
|
|
|
|
2014-03-05 04:37:43 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(Event)
|
2013-03-09 15:34:29 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
2014-03-05 04:37:43 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Event)
|
2007-06-26 12:21:42 +04:00
|
|
|
if (tmp->mEventIsInternal) {
|
2012-07-30 18:20:58 +04:00
|
|
|
tmp->mEvent->target = nullptr;
|
|
|
|
tmp->mEvent->currentTarget = nullptr;
|
|
|
|
tmp->mEvent->originalTarget = nullptr;
|
2014-08-04 09:28:46 +04:00
|
|
|
switch (tmp->mEvent->mClass) {
|
2014-08-04 09:28:50 +04:00
|
|
|
case eMouseEventClass:
|
2014-08-04 09:28:51 +04:00
|
|
|
case eMouseScrollEventClass:
|
2014-08-04 09:28:51 +04:00
|
|
|
case eWheelEventClass:
|
2014-08-04 09:28:53 +04:00
|
|
|
case eSimpleGestureEventClass:
|
2014-08-04 09:28:52 +04:00
|
|
|
case ePointerEventClass:
|
2013-10-18 10:10:26 +04:00
|
|
|
tmp->mEvent->AsMouseEventBase()->relatedTarget = nullptr;
|
2007-06-26 12:21:42 +04:00
|
|
|
break;
|
2014-08-04 09:28:50 +04:00
|
|
|
case eDragEventClass: {
|
2013-10-18 10:10:26 +04:00
|
|
|
WidgetDragEvent* dragEvent = tmp->mEvent->AsDragEvent();
|
|
|
|
dragEvent->dataTransfer = nullptr;
|
|
|
|
dragEvent->relatedTarget = nullptr;
|
2008-08-27 16:07:27 +04:00
|
|
|
break;
|
2013-10-18 10:10:26 +04:00
|
|
|
}
|
2014-08-04 09:28:55 +04:00
|
|
|
case eClipboardEventClass:
|
2013-10-18 10:10:22 +04:00
|
|
|
tmp->mEvent->AsClipboardEvent()->clipboardData = nullptr;
|
2013-03-11 19:49:48 +04:00
|
|
|
break;
|
2014-08-04 09:28:57 +04:00
|
|
|
case eMutationEventClass:
|
2013-10-18 10:10:22 +04:00
|
|
|
tmp->mEvent->AsMutationEvent()->mRelatedNode = nullptr;
|
2007-06-26 12:21:42 +04:00
|
|
|
break;
|
2014-08-04 09:28:54 +04:00
|
|
|
case eFocusEventClass:
|
2013-10-18 10:10:22 +04:00
|
|
|
tmp->mEvent->AsFocusEvent()->relatedTarget = nullptr;
|
2013-06-05 16:02:51 +04:00
|
|
|
break;
|
2007-06-26 12:21:42 +04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPresContext);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mExplicitOriginalTarget);
|
2013-03-09 15:34:29 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mOwner);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
2007-06-26 12:21:42 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2014-03-05 04:37:43 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Event)
|
2007-06-26 12:21:42 +04:00
|
|
|
if (tmp->mEventIsInternal) {
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEvent->target)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEvent->currentTarget)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEvent->originalTarget)
|
2014-08-04 09:28:46 +04:00
|
|
|
switch (tmp->mEvent->mClass) {
|
2014-08-04 09:28:50 +04:00
|
|
|
case eMouseEventClass:
|
2014-08-04 09:28:51 +04:00
|
|
|
case eMouseScrollEventClass:
|
2014-08-04 09:28:51 +04:00
|
|
|
case eWheelEventClass:
|
2014-08-04 09:28:53 +04:00
|
|
|
case eSimpleGestureEventClass:
|
2014-08-04 09:28:52 +04:00
|
|
|
case ePointerEventClass:
|
2008-09-08 22:26:46 +04:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mEvent->relatedTarget");
|
2013-10-18 10:10:26 +04:00
|
|
|
cb.NoteXPCOMChild(tmp->mEvent->AsMouseEventBase()->relatedTarget);
|
2007-06-26 12:21:42 +04:00
|
|
|
break;
|
2014-08-04 09:28:50 +04:00
|
|
|
case eDragEventClass: {
|
2013-10-18 10:10:26 +04:00
|
|
|
WidgetDragEvent* dragEvent = tmp->mEvent->AsDragEvent();
|
2008-09-08 22:26:46 +04:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mEvent->dataTransfer");
|
2013-10-18 10:10:26 +04:00
|
|
|
cb.NoteXPCOMChild(dragEvent->dataTransfer);
|
2009-02-17 14:49:03 +03:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mEvent->relatedTarget");
|
2013-10-18 10:10:26 +04:00
|
|
|
cb.NoteXPCOMChild(dragEvent->relatedTarget);
|
2008-08-27 16:07:27 +04:00
|
|
|
break;
|
2013-10-18 10:10:26 +04:00
|
|
|
}
|
2014-08-04 09:28:55 +04:00
|
|
|
case eClipboardEventClass:
|
2013-03-11 19:49:48 +04:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mEvent->clipboardData");
|
2013-10-18 10:10:22 +04:00
|
|
|
cb.NoteXPCOMChild(tmp->mEvent->AsClipboardEvent()->clipboardData);
|
2013-03-11 19:49:48 +04:00
|
|
|
break;
|
2014-08-04 09:28:57 +04:00
|
|
|
case eMutationEventClass:
|
2008-09-08 22:26:46 +04:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mEvent->mRelatedNode");
|
2013-10-18 10:10:22 +04:00
|
|
|
cb.NoteXPCOMChild(tmp->mEvent->AsMutationEvent()->mRelatedNode);
|
2007-06-26 12:21:42 +04:00
|
|
|
break;
|
2014-08-04 09:28:54 +04:00
|
|
|
case eFocusEventClass:
|
2013-06-05 16:02:51 +04:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mEvent->relatedTarget");
|
2013-10-18 10:10:22 +04:00
|
|
|
cb.NoteXPCOMChild(tmp->mEvent->AsFocusEvent()->relatedTarget);
|
2013-06-05 16:02:51 +04:00
|
|
|
break;
|
2007-06-26 12:21:42 +04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-15 11:32:39 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPresContext)
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mExplicitOriginalTarget)
|
2013-03-09 15:34:29 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOwner)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
2007-06-26 12:21:42 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2014-10-18 03:16:58 +04:00
|
|
|
|
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
Event::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2014-10-18 03:16:58 +04:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
return WrapObjectInternal(aCx, aGivenProto);
|
2014-10-18 03:16:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
Event::WrapObjectInternal(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2014-10-18 03:16:58 +04:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
return EventBinding::Wrap(aCx, this, aGivenProto);
|
2014-10-18 03:16:58 +04:00
|
|
|
}
|
|
|
|
|
2013-12-08 19:51:16 +04:00
|
|
|
bool
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::IsChrome(JSContext* aCx) const
|
2013-12-08 19:51:16 +04:00
|
|
|
{
|
|
|
|
return mIsMainThreadEvent ?
|
|
|
|
xpc::AccessCheck::isChrome(js::GetContextCompartment(aCx)) :
|
|
|
|
mozilla::dom::workers::IsCurrentThreadRunningChromeWorker();
|
|
|
|
}
|
|
|
|
|
1998-06-07 11:55:55 +04:00
|
|
|
// nsIDOMEventInterface
|
2014-03-05 04:37:43 +04:00
|
|
|
NS_METHOD
|
|
|
|
Event::GetType(nsAString& aType)
|
1998-07-17 08:52:12 +04:00
|
|
|
{
|
2013-08-16 14:06:24 +04:00
|
|
|
if (!mIsMainThreadEvent || !mEvent->typeString.IsEmpty()) {
|
|
|
|
aType = mEvent->typeString;
|
2009-10-24 19:06:01 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2015-08-22 04:34:51 +03:00
|
|
|
const char* name = GetEventName(mEvent->mMessage);
|
1998-07-17 08:52:12 +04:00
|
|
|
|
2003-12-23 18:41:10 +03:00
|
|
|
if (name) {
|
|
|
|
CopyASCIItoUTF16(name, aType);
|
1998-07-17 08:52:12 +04:00
|
|
|
return NS_OK;
|
2015-09-10 04:40:04 +03:00
|
|
|
} else if (mEvent->mMessage == eUnidentifiedEvent && mEvent->userType) {
|
2010-03-08 18:45:00 +03:00
|
|
|
aType = Substring(nsDependentAtomString(mEvent->userType), 2); // Remove "on"
|
2013-08-16 14:06:24 +04:00
|
|
|
mEvent->typeString = aType;
|
2006-10-06 09:24:02 +04:00
|
|
|
return NS_OK;
|
2001-04-17 09:52:11 +04:00
|
|
|
}
|
2011-03-24 14:34:48 +03:00
|
|
|
|
|
|
|
aType.Truncate();
|
|
|
|
return NS_OK;
|
1998-07-17 08:52:12 +04:00
|
|
|
}
|
|
|
|
|
2013-03-17 11:55:17 +04:00
|
|
|
static EventTarget*
|
|
|
|
GetDOMEventTarget(nsIDOMEventTarget* aTarget)
|
1998-06-07 11:55:55 +04:00
|
|
|
{
|
2013-03-17 11:55:17 +04:00
|
|
|
return aTarget ? aTarget->GetTargetForDOMEvent() : nullptr;
|
|
|
|
}
|
2011-06-24 06:18:01 +04:00
|
|
|
|
2013-03-17 11:55:17 +04:00
|
|
|
EventTarget*
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::GetTarget() const
|
2013-03-17 11:55:17 +04:00
|
|
|
{
|
|
|
|
return GetDOMEventTarget(mEvent->target);
|
1998-06-07 11:55:55 +04:00
|
|
|
}
|
|
|
|
|
2007-04-17 13:18:36 +04:00
|
|
|
NS_METHOD
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::GetTarget(nsIDOMEventTarget** aTarget)
|
2007-04-17 13:18:36 +04:00
|
|
|
{
|
2013-03-17 11:55:17 +04:00
|
|
|
NS_IF_ADDREF(*aTarget = GetTarget());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
EventTarget*
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::GetCurrentTarget() const
|
2013-03-17 11:55:17 +04:00
|
|
|
{
|
|
|
|
return GetDOMEventTarget(mEvent->currentTarget);
|
2007-04-17 13:18:36 +04:00
|
|
|
}
|
|
|
|
|
1999-05-19 03:51:04 +04:00
|
|
|
NS_IMETHODIMP
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::GetCurrentTarget(nsIDOMEventTarget** aCurrentTarget)
|
1998-07-17 08:52:12 +04:00
|
|
|
{
|
2013-03-17 11:55:17 +04:00
|
|
|
NS_IF_ADDREF(*aCurrentTarget = GetCurrentTarget());
|
|
|
|
return NS_OK;
|
1998-07-17 08:52:12 +04:00
|
|
|
}
|
|
|
|
|
2003-02-22 11:10:46 +03:00
|
|
|
//
|
|
|
|
// Get the actual event target node (may have been retargeted for mouse events)
|
|
|
|
//
|
2010-06-11 15:10:51 +04:00
|
|
|
already_AddRefed<nsIContent>
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::GetTargetFromFrame()
|
2003-02-22 11:10:46 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
if (!mPresContext) { return nullptr; }
|
2003-02-22 11:10:46 +03:00
|
|
|
|
|
|
|
// Get the target frame (have to get the ESM first)
|
2011-04-21 21:35:52 +04:00
|
|
|
nsIFrame* targetFrame = mPresContext->EventStateManager()->GetEventTarget();
|
2012-07-30 18:20:58 +04:00
|
|
|
if (!targetFrame) { return nullptr; }
|
2003-02-22 11:10:46 +03:00
|
|
|
|
|
|
|
// get the real content
|
|
|
|
nsCOMPtr<nsIContent> realEventContent;
|
2011-09-27 00:55:04 +04:00
|
|
|
targetFrame->GetContentForEvent(mEvent, getter_AddRefs(realEventContent));
|
2010-06-11 15:10:51 +04:00
|
|
|
return realEventContent.forget();
|
2003-02-22 11:10:46 +03:00
|
|
|
}
|
|
|
|
|
2013-03-17 11:55:17 +04:00
|
|
|
EventTarget*
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::GetExplicitOriginalTarget() const
|
2003-02-22 11:10:46 +03:00
|
|
|
{
|
|
|
|
if (mExplicitOriginalTarget) {
|
2013-03-17 11:55:17 +04:00
|
|
|
return mExplicitOriginalTarget;
|
2003-02-22 11:10:46 +03:00
|
|
|
}
|
2013-03-17 11:55:17 +04:00
|
|
|
return GetTarget();
|
2003-02-22 11:10:46 +03:00
|
|
|
}
|
|
|
|
|
2000-09-07 05:07:29 +04:00
|
|
|
NS_IMETHODIMP
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::GetExplicitOriginalTarget(nsIDOMEventTarget** aRealEventTarget)
|
2013-03-17 11:55:17 +04:00
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aRealEventTarget = GetExplicitOriginalTarget());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
EventTarget*
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::GetOriginalTarget() const
|
2000-09-07 05:07:29 +04:00
|
|
|
{
|
2006-03-07 20:08:51 +03:00
|
|
|
if (mEvent->originalTarget) {
|
2013-03-17 11:55:17 +04:00
|
|
|
return GetDOMEventTarget(mEvent->originalTarget);
|
2006-03-07 20:08:51 +03:00
|
|
|
}
|
2000-09-07 13:20:56 +04:00
|
|
|
|
2013-03-17 11:55:17 +04:00
|
|
|
return GetTarget();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::GetOriginalTarget(nsIDOMEventTarget** aOriginalTarget)
|
2013-03-17 11:55:17 +04:00
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aOriginalTarget = GetOriginalTarget());
|
|
|
|
return NS_OK;
|
2000-09-07 05:07:29 +04:00
|
|
|
}
|
|
|
|
|
2015-01-23 14:55:46 +03:00
|
|
|
EventTarget*
|
|
|
|
Event::GetComposedTarget() const
|
|
|
|
{
|
|
|
|
EventTarget* et = GetOriginalTarget();
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(et);
|
|
|
|
if (!content) {
|
|
|
|
return et;
|
|
|
|
}
|
|
|
|
nsIContent* nonChrome = content->FindFirstNonChromeOnlyAccessContent();
|
|
|
|
return nonChrome ?
|
|
|
|
static_cast<EventTarget*>(nonChrome) :
|
|
|
|
static_cast<EventTarget*>(content->GetComposedDoc());
|
|
|
|
}
|
|
|
|
|
2012-12-22 12:18:08 +04:00
|
|
|
NS_IMETHODIMP_(void)
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::SetTrusted(bool aTrusted)
|
2001-11-20 11:40:54 +03:00
|
|
|
{
|
2012-12-16 05:26:03 +04:00
|
|
|
mEvent->mFlags.mIsTrusted = aTrusted;
|
2001-11-20 11:40:54 +03:00
|
|
|
}
|
|
|
|
|
2013-03-14 00:02:32 +04:00
|
|
|
bool
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::Init(mozilla::dom::EventTarget* aGlobal)
|
2013-03-09 15:34:29 +04:00
|
|
|
{
|
2013-08-30 13:47:19 +04:00
|
|
|
if (!mIsMainThreadEvent) {
|
|
|
|
return nsContentUtils::ThreadsafeIsCallerChrome();
|
|
|
|
}
|
2013-03-09 15:34:29 +04:00
|
|
|
bool trusted = false;
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> w = do_QueryInterface(aGlobal);
|
2013-03-09 15:34:29 +04:00
|
|
|
if (w) {
|
2013-04-24 08:22:37 +04:00
|
|
|
nsCOMPtr<nsIDocument> d = w->GetExtantDoc();
|
2013-03-09 15:34:29 +04:00
|
|
|
if (d) {
|
|
|
|
trusted = nsContentUtils::IsChromeDoc(d);
|
|
|
|
nsIPresShell* s = d->GetShell();
|
|
|
|
if (s) {
|
2013-03-14 00:02:32 +04:00
|
|
|
InitPresContextData(s->GetPresContext());
|
2013-03-09 15:34:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-03-14 00:02:32 +04:00
|
|
|
return trusted;
|
|
|
|
}
|
|
|
|
|
2014-03-05 04:37:43 +04:00
|
|
|
// static
|
|
|
|
already_AddRefed<Event>
|
|
|
|
Event::Constructor(const GlobalObject& aGlobal,
|
|
|
|
const nsAString& aType,
|
|
|
|
const EventInit& aParam,
|
|
|
|
ErrorResult& aRv)
|
2013-03-14 00:02:32 +04:00
|
|
|
{
|
2013-08-23 09:17:08 +04:00
|
|
|
nsCOMPtr<mozilla::dom::EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports());
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Event> e = new Event(t, nullptr, nullptr);
|
2013-03-14 00:02:32 +04:00
|
|
|
bool trusted = e->Init(t);
|
2015-11-13 03:09:42 +03:00
|
|
|
e->InitEvent(aType, aParam.mBubbles, aParam.mCancelable);
|
2013-03-09 15:34:29 +04:00
|
|
|
e->SetTrusted(trusted);
|
|
|
|
return e.forget();
|
|
|
|
}
|
|
|
|
|
2013-03-17 11:55:17 +04:00
|
|
|
uint16_t
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::EventPhase() const
|
1998-07-17 08:52:12 +04:00
|
|
|
{
|
2006-06-22 11:51:57 +04:00
|
|
|
// Note, remember to check that this works also
|
|
|
|
// if or when Bug 235441 is fixed.
|
2012-05-03 14:59:51 +04:00
|
|
|
if ((mEvent->currentTarget &&
|
|
|
|
mEvent->currentTarget == mEvent->target) ||
|
2012-12-16 05:26:03 +04:00
|
|
|
mEvent->mFlags.InTargetPhase()) {
|
2013-03-17 11:55:17 +04:00
|
|
|
return nsIDOMEvent::AT_TARGET;
|
|
|
|
}
|
|
|
|
if (mEvent->mFlags.mInCapturePhase) {
|
|
|
|
return nsIDOMEvent::CAPTURING_PHASE;
|
|
|
|
}
|
|
|
|
if (mEvent->mFlags.mInBubblingPhase) {
|
|
|
|
return nsIDOMEvent::BUBBLING_PHASE;
|
1999-07-19 23:54:34 +04:00
|
|
|
}
|
2013-03-17 11:55:17 +04:00
|
|
|
return nsIDOMEvent::NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::GetEventPhase(uint16_t* aEventPhase)
|
2013-03-17 11:55:17 +04:00
|
|
|
{
|
|
|
|
*aEventPhase = EventPhase();
|
1999-05-19 03:51:04 +04:00
|
|
|
return NS_OK;
|
1998-07-17 08:52:12 +04:00
|
|
|
}
|
|
|
|
|
1999-11-03 10:11:45 +03:00
|
|
|
NS_IMETHODIMP
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::GetBubbles(bool* aBubbles)
|
1999-11-03 10:11:45 +03:00
|
|
|
{
|
2013-03-17 11:55:17 +04:00
|
|
|
*aBubbles = Bubbles();
|
2000-05-16 15:35:12 +04:00
|
|
|
return NS_OK;
|
1999-11-03 10:11:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::GetCancelable(bool* aCancelable)
|
1999-11-03 10:11:45 +03:00
|
|
|
{
|
2013-03-17 11:55:17 +04:00
|
|
|
*aCancelable = Cancelable();
|
2000-05-16 15:35:12 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::GetTimeStamp(uint64_t* aTimeStamp)
|
2000-05-16 15:35:12 +04:00
|
|
|
{
|
2014-06-06 09:29:49 +04:00
|
|
|
*aTimeStamp = mEvent->time;
|
2000-05-16 15:35:12 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::StopPropagation()
|
2000-05-16 15:35:12 +04:00
|
|
|
{
|
2012-12-16 05:26:03 +04:00
|
|
|
mEvent->mFlags.mPropagationStopped = true;
|
2000-05-16 15:35:12 +04:00
|
|
|
return NS_OK;
|
1999-11-03 10:11:45 +03:00
|
|
|
}
|
|
|
|
|
2011-11-04 21:17:19 +04:00
|
|
|
NS_IMETHODIMP
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::StopImmediatePropagation()
|
2011-11-04 21:17:19 +04:00
|
|
|
{
|
2012-12-16 05:26:03 +04:00
|
|
|
mEvent->mFlags.mPropagationStopped = true;
|
|
|
|
mEvent->mFlags.mImmediatePropagationStopped = true;
|
2011-11-04 21:17:19 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-05-25 23:54:13 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Event::StopCrossProcessForwarding()
|
|
|
|
{
|
|
|
|
mEvent->mFlags.mNoCrossProcessBoundaryForwarding = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-09-02 19:25:39 +04:00
|
|
|
NS_IMETHODIMP
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::GetIsTrusted(bool* aIsTrusted)
|
2004-09-02 19:25:39 +04:00
|
|
|
{
|
2013-03-17 11:55:17 +04:00
|
|
|
*aIsTrusted = IsTrusted();
|
2004-09-02 19:25:39 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-05-19 03:51:04 +04:00
|
|
|
NS_IMETHODIMP
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::PreventDefault()
|
1998-06-07 11:55:55 +04:00
|
|
|
{
|
2013-12-08 19:51:16 +04:00
|
|
|
// This method is called only from C++ code which must handle default action
|
|
|
|
// of this event. So, pass true always.
|
|
|
|
PreventDefaultInternal(true);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::PreventDefault(JSContext* aCx)
|
2013-12-08 19:51:16 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aCx, "JS context must be specified");
|
|
|
|
|
|
|
|
// Note that at handling default action, another event may be dispatched.
|
|
|
|
// Then, JS in content mey be call preventDefault()
|
|
|
|
// even in the event is in system event group. Therefore, don't refer
|
|
|
|
// mInSystemGroup here.
|
|
|
|
PreventDefaultInternal(IsChrome(aCx));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::PreventDefaultInternal(bool aCalledByDefaultHandler)
|
2013-12-08 19:51:16 +04:00
|
|
|
{
|
|
|
|
if (!mEvent->mFlags.mCancelable) {
|
|
|
|
return;
|
2000-05-16 15:35:12 +04:00
|
|
|
}
|
2009-10-29 14:11:02 +03:00
|
|
|
|
2013-12-08 19:51:16 +04:00
|
|
|
mEvent->mFlags.mDefaultPrevented = true;
|
|
|
|
|
|
|
|
// Note that even if preventDefault() has already been called by chrome,
|
|
|
|
// a call of preventDefault() by content needs to overwrite
|
|
|
|
// mDefaultPreventedByContent to true because in such case, defaultPrevented
|
|
|
|
// must be true when web apps check it after they call preventDefault().
|
|
|
|
if (!aCalledByDefaultHandler) {
|
|
|
|
mEvent->mFlags.mDefaultPreventedByContent = true;
|
2015-01-21 04:16:04 +03:00
|
|
|
} else {
|
|
|
|
mEvent->mFlags.mDefaultPreventedByChrome = true;
|
2013-12-08 19:51:16 +04:00
|
|
|
}
|
2013-12-12 13:39:04 +04:00
|
|
|
|
|
|
|
if (!IsTrusted()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
WidgetDragEvent* dragEvent = mEvent->AsDragEvent();
|
|
|
|
if (!dragEvent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(mEvent->currentTarget);
|
|
|
|
if (!node) {
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> win = do_QueryInterface(mEvent->currentTarget);
|
2013-12-12 13:39:04 +04:00
|
|
|
if (!win) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
node = win->GetExtantDoc();
|
|
|
|
}
|
|
|
|
if (!nsContentUtils::IsChromeDoc(node->OwnerDoc())) {
|
|
|
|
dragEvent->mDefaultPreventedOnContent = true;
|
|
|
|
}
|
1998-07-17 08:52:12 +04:00
|
|
|
}
|
|
|
|
|
2012-07-18 14:36:08 +04:00
|
|
|
void
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::SetEventType(const nsAString& aEventTypeArg)
|
2000-05-16 15:35:12 +04:00
|
|
|
{
|
2013-08-16 14:06:24 +04:00
|
|
|
if (mIsMainThreadEvent) {
|
2014-06-17 02:59:54 +04:00
|
|
|
mEvent->typeString.Truncate();
|
2013-08-16 14:06:24 +04:00
|
|
|
mEvent->userType =
|
2015-08-26 15:56:59 +03:00
|
|
|
nsContentUtils::GetEventMessageAndAtom(aEventTypeArg, mEvent->mClass,
|
|
|
|
&(mEvent->mMessage));
|
2013-08-16 14:06:24 +04:00
|
|
|
} else {
|
|
|
|
mEvent->userType = nullptr;
|
2015-09-10 04:40:04 +03:00
|
|
|
mEvent->mMessage = eUnidentifiedEvent;
|
2013-08-16 14:06:24 +04:00
|
|
|
mEvent->typeString = aEventTypeArg;
|
|
|
|
}
|
2000-05-16 15:35:12 +04:00
|
|
|
}
|
|
|
|
|
2015-11-13 03:09:42 +03:00
|
|
|
void
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::InitEvent(const nsAString& aEventTypeArg,
|
|
|
|
bool aCanBubbleArg,
|
|
|
|
bool aCancelableArg)
|
1999-11-03 10:11:45 +03:00
|
|
|
{
|
2005-06-22 05:53:58 +04:00
|
|
|
// Make sure this event isn't already being dispatched.
|
2015-11-13 03:09:42 +03:00
|
|
|
NS_ENSURE_TRUE_VOID(!mEvent->mFlags.mIsBeingDispatched);
|
2005-06-22 05:53:58 +04:00
|
|
|
|
2013-03-17 11:55:17 +04:00
|
|
|
if (IsTrusted()) {
|
2005-06-22 05:53:58 +04:00
|
|
|
// Ensure the caller is permitted to dispatch trusted DOM events.
|
2013-08-30 13:47:19 +04:00
|
|
|
if (!nsContentUtils::ThreadsafeIsCallerChrome()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
SetTrusted(false);
|
2005-06-22 05:53:58 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-18 14:36:08 +04:00
|
|
|
SetEventType(aEventTypeArg);
|
2005-06-22 05:53:58 +04:00
|
|
|
|
2012-12-16 05:26:03 +04:00
|
|
|
mEvent->mFlags.mBubbles = aCanBubbleArg;
|
|
|
|
mEvent->mFlags.mCancelable = aCancelableArg;
|
2005-06-22 05:53:58 +04:00
|
|
|
|
2013-03-20 18:15:58 +04:00
|
|
|
mEvent->mFlags.mDefaultPrevented = false;
|
2015-01-21 04:16:04 +03:00
|
|
|
mEvent->mFlags.mDefaultPreventedByContent = false;
|
|
|
|
mEvent->mFlags.mDefaultPreventedByChrome = false;
|
2013-03-20 18:15:58 +04:00
|
|
|
|
2006-03-15 00:51:56 +03:00
|
|
|
// Clearing the old targets, so that the event is targeted correctly when
|
|
|
|
// re-dispatching it.
|
2012-07-30 18:20:58 +04:00
|
|
|
mEvent->target = nullptr;
|
|
|
|
mEvent->originalTarget = nullptr;
|
1999-11-03 10:11:45 +03:00
|
|
|
}
|
|
|
|
|
2012-06-10 22:14:30 +04:00
|
|
|
NS_IMETHODIMP
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::DuplicatePrivateData()
|
1998-06-24 01:53:02 +04:00
|
|
|
{
|
2014-03-05 04:37:43 +04:00
|
|
|
NS_ASSERTION(mEvent, "No WidgetEvent for Event duplication!");
|
2006-03-07 20:08:51 +03:00
|
|
|
if (mEventIsInternal) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-01-27 10:10:44 +04:00
|
|
|
mEvent = mEvent->Duplicate();
|
2012-07-30 18:20:58 +04:00
|
|
|
mPresContext = nullptr;
|
2011-10-17 18:59:28 +04:00
|
|
|
mEventIsInternal = true;
|
|
|
|
mPrivateDataDuplicated = true;
|
1998-11-18 08:25:26 +03:00
|
|
|
|
1998-06-24 01:53:02 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-07-17 08:52:12 +04:00
|
|
|
|
2012-06-10 22:14:30 +04:00
|
|
|
NS_IMETHODIMP
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::SetTarget(nsIDOMEventTarget* aTarget)
|
1999-05-21 23:27:02 +04:00
|
|
|
{
|
2010-03-31 16:44:18 +04:00
|
|
|
mEvent->target = do_QueryInterface(aTarget);
|
1999-05-21 23:27:02 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP_(bool)
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::IsDispatchStopped()
|
1999-12-16 01:04:43 +03:00
|
|
|
{
|
2012-12-16 05:26:03 +04:00
|
|
|
return mEvent->mFlags.mPropagationStopped;
|
1999-12-16 01:04:43 +03:00
|
|
|
}
|
|
|
|
|
2013-10-02 07:46:04 +04:00
|
|
|
NS_IMETHODIMP_(WidgetEvent*)
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::GetInternalNSEvent()
|
2000-05-17 09:27:22 +04:00
|
|
|
{
|
2008-10-10 03:23:07 +04:00
|
|
|
return mEvent;
|
2000-05-17 09:27:22 +04:00
|
|
|
}
|
|
|
|
|
2014-03-05 04:37:43 +04:00
|
|
|
NS_IMETHODIMP_(Event*)
|
|
|
|
Event::InternalDOMEvent()
|
2013-03-09 15:34:29 +04:00
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2004-09-04 23:28:46 +04:00
|
|
|
// return true if eventName is contained within events, delimited by
|
|
|
|
// spaces
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2004-09-04 23:28:46 +04:00
|
|
|
PopupAllowedForEvent(const char *eventName)
|
|
|
|
{
|
|
|
|
if (!sPopupAllowedEvents) {
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::PopupAllowedEventsChanged();
|
2004-09-04 23:28:46 +04:00
|
|
|
|
|
|
|
if (!sPopupAllowedEvents) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2004-09-04 23:28:46 +04: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 18:59:28 +04:00
|
|
|
return false;
|
2004-09-04 23:28:46 +04:00
|
|
|
|
|
|
|
// the match is surrounded by spaces, or at a string boundary
|
|
|
|
if ((startiter == start || *--startiter == ' ') &&
|
|
|
|
(enditer == end || *enditer == ' ')) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2004-09-04 23:28:46 +04: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 18:59:28 +04:00
|
|
|
return false;
|
2004-09-04 23:28:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
PopupControlState
|
2014-10-15 18:48:04 +04:00
|
|
|
Event::GetEventPopupControlState(WidgetEvent* aEvent, nsIDOMEvent* aDOMEvent)
|
2004-09-04 23:28:46 +04:00
|
|
|
{
|
|
|
|
// generally if an event handler is running, new windows are disallowed.
|
|
|
|
// check for exceptions:
|
|
|
|
PopupControlState abuse = openAbused;
|
|
|
|
|
2014-10-15 18:48:04 +04:00
|
|
|
if (aDOMEvent && aDOMEvent->InternalDOMEvent()->GetWantsPopupControlCheck()) {
|
|
|
|
nsAutoString type;
|
|
|
|
aDOMEvent->GetType(type);
|
|
|
|
if (PopupAllowedForEvent(NS_ConvertUTF16toUTF8(type).get())) {
|
|
|
|
return openAllowed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-04 09:28:46 +04:00
|
|
|
switch(aEvent->mClass) {
|
2014-08-04 09:28:58 +04:00
|
|
|
case eBasicEventClass:
|
2004-09-04 23:28:46 +04:00
|
|
|
// For these following events only allow popups if they're
|
|
|
|
// triggered while handling user input. See
|
|
|
|
// nsPresShell::HandleEventInternal() for details.
|
2014-04-01 08:09:23 +04:00
|
|
|
if (EventStateManager::IsHandlingUserInput()) {
|
2015-08-22 04:34:51 +03:00
|
|
|
switch(aEvent->mMessage) {
|
2015-09-02 09:08:00 +03:00
|
|
|
case eFormSelect:
|
2014-03-05 04:37:43 +04:00
|
|
|
if (PopupAllowedForEvent("select")) {
|
2004-09-04 23:28:46 +04:00
|
|
|
abuse = openControlled;
|
2014-03-05 04:37:43 +04:00
|
|
|
}
|
2005-03-04 05:01:54 +03:00
|
|
|
break;
|
2015-09-02 09:08:00 +03:00
|
|
|
case eFormChange:
|
2014-03-05 04:37:43 +04:00
|
|
|
if (PopupAllowedForEvent("change")) {
|
2004-09-04 23:28:46 +04:00
|
|
|
abuse = openControlled;
|
2014-03-05 04:37:43 +04:00
|
|
|
}
|
2005-03-04 05:01:54 +03:00
|
|
|
break;
|
2015-08-26 15:56:59 +03:00
|
|
|
default:
|
|
|
|
break;
|
2004-09-04 23:28:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2014-08-04 09:28:49 +04:00
|
|
|
case eEditorInputEventClass:
|
2004-09-04 23:28:46 +04:00
|
|
|
// For this following event only allow popups if it's triggered
|
|
|
|
// while handling user input. See
|
|
|
|
// nsPresShell::HandleEventInternal() for details.
|
2014-04-01 08:09:23 +04:00
|
|
|
if (EventStateManager::IsHandlingUserInput()) {
|
2015-08-22 04:34:51 +03:00
|
|
|
switch(aEvent->mMessage) {
|
2015-09-14 18:14:33 +03:00
|
|
|
case eEditorInput:
|
2014-03-05 04:37:43 +04:00
|
|
|
if (PopupAllowedForEvent("input")) {
|
2004-09-04 23:28:46 +04:00
|
|
|
abuse = openControlled;
|
2014-03-05 04:37:43 +04:00
|
|
|
}
|
2004-09-04 23:28:46 +04:00
|
|
|
break;
|
2015-08-26 15:56:59 +03:00
|
|
|
default:
|
|
|
|
break;
|
2004-09-04 23:28:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2014-08-04 09:28:47 +04:00
|
|
|
case eInputEventClass:
|
2004-09-04 23:28:46 +04:00
|
|
|
// For this following event only allow popups if it's triggered
|
|
|
|
// while handling user input. See
|
|
|
|
// nsPresShell::HandleEventInternal() for details.
|
2014-04-01 08:09:23 +04:00
|
|
|
if (EventStateManager::IsHandlingUserInput()) {
|
2015-08-22 04:34:51 +03:00
|
|
|
switch(aEvent->mMessage) {
|
2015-09-02 09:08:00 +03:00
|
|
|
case eFormChange:
|
2014-03-05 04:37:43 +04:00
|
|
|
if (PopupAllowedForEvent("change")) {
|
2004-09-04 23:28:46 +04:00
|
|
|
abuse = openControlled;
|
2014-03-05 04:37:43 +04:00
|
|
|
}
|
2004-09-04 23:28:46 +04:00
|
|
|
break;
|
2015-09-04 13:54:12 +03:00
|
|
|
case eXULCommand:
|
2011-11-01 03:39:32 +04:00
|
|
|
abuse = openControlled;
|
|
|
|
break;
|
2015-08-26 15:56:59 +03:00
|
|
|
default:
|
|
|
|
break;
|
2004-09-04 23:28:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2014-08-04 09:28:48 +04:00
|
|
|
case eKeyboardEventClass:
|
2012-12-16 05:26:03 +04:00
|
|
|
if (aEvent->mFlags.mIsTrusted) {
|
2013-10-18 10:10:24 +04:00
|
|
|
uint32_t key = aEvent->AsKeyboardEvent()->keyCode;
|
2015-08-22 04:34:51 +03:00
|
|
|
switch(aEvent->mMessage) {
|
2015-08-29 02:58:27 +03:00
|
|
|
case eKeyPress:
|
2015-08-29 02:58:32 +03:00
|
|
|
// return key on focused button. see note at eMouseClick.
|
2014-03-05 04:37:43 +04:00
|
|
|
if (key == nsIDOMKeyEvent::DOM_VK_RETURN) {
|
2004-09-04 23:28:46 +04:00
|
|
|
abuse = openAllowed;
|
2014-03-05 04:37:43 +04:00
|
|
|
} else if (PopupAllowedForEvent("keypress")) {
|
2004-09-04 23:28:46 +04:00
|
|
|
abuse = openControlled;
|
2014-03-05 04:37:43 +04:00
|
|
|
}
|
2004-09-04 23:28:46 +04:00
|
|
|
break;
|
2015-08-29 02:58:27 +03:00
|
|
|
case eKeyUp:
|
2015-08-29 02:58:32 +03:00
|
|
|
// space key on focused button. see note at eMouseClick.
|
2014-03-05 04:37:43 +04:00
|
|
|
if (key == nsIDOMKeyEvent::DOM_VK_SPACE) {
|
2004-09-04 23:28:46 +04:00
|
|
|
abuse = openAllowed;
|
2014-03-05 04:37:43 +04:00
|
|
|
} else if (PopupAllowedForEvent("keyup")) {
|
2004-09-04 23:28:46 +04:00
|
|
|
abuse = openControlled;
|
2014-03-05 04:37:43 +04:00
|
|
|
}
|
2004-09-04 23:28:46 +04:00
|
|
|
break;
|
2015-08-29 02:58:27 +03:00
|
|
|
case eKeyDown:
|
2014-03-05 04:37:43 +04:00
|
|
|
if (PopupAllowedForEvent("keydown")) {
|
2004-09-04 23:28:46 +04:00
|
|
|
abuse = openControlled;
|
2014-03-05 04:37:43 +04:00
|
|
|
}
|
2004-09-04 23:28:46 +04:00
|
|
|
break;
|
2015-08-26 15:56:59 +03:00
|
|
|
default:
|
|
|
|
break;
|
2004-09-04 23:28:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2014-08-04 09:28:53 +04:00
|
|
|
case eTouchEventClass:
|
2013-05-17 03:29:23 +04:00
|
|
|
if (aEvent->mFlags.mIsTrusted) {
|
2015-08-22 04:34:51 +03:00
|
|
|
switch (aEvent->mMessage) {
|
2015-09-14 18:14:34 +03:00
|
|
|
case eTouchStart:
|
2013-05-17 03:29:23 +04:00
|
|
|
if (PopupAllowedForEvent("touchstart")) {
|
|
|
|
abuse = openControlled;
|
|
|
|
}
|
|
|
|
break;
|
2015-09-14 18:14:35 +03:00
|
|
|
case eTouchEnd:
|
2013-05-17 03:29:23 +04:00
|
|
|
if (PopupAllowedForEvent("touchend")) {
|
|
|
|
abuse = openControlled;
|
|
|
|
}
|
|
|
|
break;
|
2015-08-26 15:56:59 +03:00
|
|
|
default:
|
|
|
|
break;
|
2013-05-17 03:29:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2014-08-04 09:28:50 +04:00
|
|
|
case eMouseEventClass:
|
2012-12-16 05:26:03 +04:00
|
|
|
if (aEvent->mFlags.mIsTrusted &&
|
2013-10-22 12:55:20 +04:00
|
|
|
aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton) {
|
2015-08-22 04:34:51 +03:00
|
|
|
switch(aEvent->mMessage) {
|
2015-08-29 02:58:30 +03:00
|
|
|
case eMouseUp:
|
2014-03-05 04:37:43 +04:00
|
|
|
if (PopupAllowedForEvent("mouseup")) {
|
2004-09-04 23:28:46 +04:00
|
|
|
abuse = openControlled;
|
2014-03-05 04:37:43 +04:00
|
|
|
}
|
2004-09-04 23:28:46 +04:00
|
|
|
break;
|
2015-08-29 02:58:30 +03:00
|
|
|
case eMouseDown:
|
2014-03-05 04:37:43 +04:00
|
|
|
if (PopupAllowedForEvent("mousedown")) {
|
2004-09-04 23:28:46 +04:00
|
|
|
abuse = openControlled;
|
2014-03-05 04:37:43 +04:00
|
|
|
}
|
2004-09-04 23:28:46 +04:00
|
|
|
break;
|
2015-08-29 02:58:32 +03:00
|
|
|
case eMouseClick:
|
2004-09-04 23:28:46 +04:00
|
|
|
/* Click events get special treatment because of their
|
|
|
|
historical status as a more legitimate event handler. If
|
|
|
|
click popups are enabled in the prefs, clear the popup
|
|
|
|
status completely. */
|
2014-03-05 04:37:43 +04:00
|
|
|
if (PopupAllowedForEvent("click")) {
|
2004-09-04 23:28:46 +04:00
|
|
|
abuse = openAllowed;
|
2014-03-05 04:37:43 +04:00
|
|
|
}
|
2004-09-04 23:28:46 +04:00
|
|
|
break;
|
2015-08-29 02:58:31 +03:00
|
|
|
case eMouseDoubleClick:
|
2014-03-05 04:37:43 +04:00
|
|
|
if (PopupAllowedForEvent("dblclick")) {
|
2004-09-04 23:28:46 +04:00
|
|
|
abuse = openControlled;
|
2014-03-05 04:37:43 +04:00
|
|
|
}
|
2004-09-04 23:28:46 +04:00
|
|
|
break;
|
2015-08-26 15:56:59 +03:00
|
|
|
default:
|
|
|
|
break;
|
2004-09-04 23:28:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2014-08-04 09:28:54 +04:00
|
|
|
case eFormEventClass:
|
2004-09-04 23:28:46 +04:00
|
|
|
// For these following events only allow popups if they're
|
|
|
|
// triggered while handling user input. See
|
|
|
|
// nsPresShell::HandleEventInternal() for details.
|
2014-04-01 08:09:23 +04:00
|
|
|
if (EventStateManager::IsHandlingUserInput()) {
|
2015-08-22 04:34:51 +03:00
|
|
|
switch(aEvent->mMessage) {
|
2015-09-02 09:08:00 +03:00
|
|
|
case eFormSubmit:
|
2014-03-05 04:37:43 +04:00
|
|
|
if (PopupAllowedForEvent("submit")) {
|
2004-09-04 23:28:46 +04:00
|
|
|
abuse = openControlled;
|
2014-03-05 04:37:43 +04:00
|
|
|
}
|
2004-09-04 23:28:46 +04:00
|
|
|
break;
|
2015-09-02 09:08:00 +03:00
|
|
|
case eFormReset:
|
2014-03-05 04:37:43 +04:00
|
|
|
if (PopupAllowedForEvent("reset")) {
|
2004-09-04 23:28:46 +04:00
|
|
|
abuse = openControlled;
|
2014-03-05 04:37:43 +04:00
|
|
|
}
|
2004-09-04 23:28:46 +04:00
|
|
|
break;
|
2015-08-26 15:56:59 +03:00
|
|
|
default:
|
|
|
|
break;
|
2004-09-04 23:28:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2012-11-20 10:05:56 +04:00
|
|
|
default:
|
|
|
|
break;
|
2004-09-04 23:28:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return abuse;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::PopupAllowedEventsChanged()
|
2004-09-04 23:28:46 +04:00
|
|
|
{
|
|
|
|
if (sPopupAllowedEvents) {
|
2015-03-27 03:01:12 +03:00
|
|
|
free(sPopupAllowedEvents);
|
2004-09-04 23:28:46 +04:00
|
|
|
}
|
|
|
|
|
2011-05-28 11:03:00 +04:00
|
|
|
nsAdoptingCString str = Preferences::GetCString("dom.popup_allowed_events");
|
2004-09-04 23:28:46 +04:00
|
|
|
|
|
|
|
// We'll want to do this even if str is empty to avoid looking up
|
|
|
|
// this pref all the time if it's not set.
|
|
|
|
sPopupAllowedEvents = ToNewCString(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::Shutdown()
|
2004-09-04 23:28:46 +04:00
|
|
|
{
|
|
|
|
if (sPopupAllowedEvents) {
|
2015-03-27 03:01:12 +03:00
|
|
|
free(sPopupAllowedEvents);
|
2004-09-04 23:28:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-10 19:32:40 +03:00
|
|
|
// static
|
|
|
|
CSSIntPoint
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::GetScreenCoords(nsPresContext* aPresContext,
|
|
|
|
WidgetEvent* aEvent,
|
|
|
|
LayoutDeviceIntPoint aPoint)
|
2011-12-17 04:24:11 +04:00
|
|
|
{
|
2014-09-25 13:04:45 +04:00
|
|
|
if (!nsContentUtils::LegacyIsCallerChromeOrNativeCode() &&
|
2015-06-07 16:02:00 +03:00
|
|
|
nsContentUtils::ResistFingerprinting()) {
|
|
|
|
// When resisting fingerprinting, return client coordinates instead.
|
2015-11-10 19:32:40 +03:00
|
|
|
return GetClientCoords(aPresContext, aEvent, aPoint, CSSIntPoint(0, 0));
|
2015-06-07 16:02:00 +03:00
|
|
|
}
|
|
|
|
|
2014-04-01 08:09:23 +04:00
|
|
|
if (EventStateManager::sIsPointerLocked) {
|
|
|
|
return EventStateManager::sLastScreenPoint;
|
2012-04-12 01:55:21 +04:00
|
|
|
}
|
|
|
|
|
2015-02-15 21:52:28 +03:00
|
|
|
if (!aEvent ||
|
2014-08-04 09:28:50 +04:00
|
|
|
(aEvent->mClass != eMouseEventClass &&
|
2014-08-04 09:28:51 +04:00
|
|
|
aEvent->mClass != eMouseScrollEventClass &&
|
2014-08-04 09:28:51 +04:00
|
|
|
aEvent->mClass != eWheelEventClass &&
|
2014-08-04 09:28:52 +04:00
|
|
|
aEvent->mClass != ePointerEventClass &&
|
2014-08-04 09:28:53 +04:00
|
|
|
aEvent->mClass != eTouchEventClass &&
|
2014-08-04 09:28:50 +04:00
|
|
|
aEvent->mClass != eDragEventClass &&
|
2014-08-04 09:28:53 +04:00
|
|
|
aEvent->mClass != eSimpleGestureEventClass)) {
|
2015-11-10 19:32:40 +03:00
|
|
|
return CSSIntPoint(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Doing a straight conversion from LayoutDeviceIntPoint to CSSIntPoint
|
|
|
|
// seem incorrect, but it is needed to maintain legacy functionality.
|
2013-10-22 12:55:20 +04:00
|
|
|
WidgetGUIEvent* guiEvent = aEvent->AsGUIEvent();
|
2015-11-27 05:04:16 +03:00
|
|
|
if (!aPresContext || !(guiEvent && guiEvent->widget)) {
|
|
|
|
return CSSIntPoint(aPoint.x, aPoint.y);
|
2011-12-17 04:24:11 +04:00
|
|
|
}
|
|
|
|
|
2015-11-10 19:32:40 +03:00
|
|
|
nsPoint pt =
|
2015-11-27 05:04:16 +03:00
|
|
|
LayoutDevicePixel::ToAppUnits(aPoint, aPresContext->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom());
|
|
|
|
|
2016-01-27 23:01:00 +03:00
|
|
|
if (nsIPresShell* ps = aPresContext->GetPresShell()) {
|
|
|
|
pt = pt.RemoveResolution(nsLayoutUtils::GetCurrentAPZResolutionScale(ps));
|
2015-11-27 05:51:13 +03:00
|
|
|
}
|
|
|
|
|
2015-11-27 05:04:16 +03:00
|
|
|
pt += LayoutDevicePixel::ToAppUnits(guiEvent->widget->WidgetToScreenOffset(),
|
|
|
|
aPresContext->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom());
|
2015-11-10 19:32:40 +03:00
|
|
|
|
|
|
|
return CSSPixel::FromAppUnitsRounded(pt);
|
2011-12-17 04:24:11 +04:00
|
|
|
}
|
|
|
|
|
2014-03-05 04:37:43 +04:00
|
|
|
// static
|
2013-07-10 13:55:05 +04:00
|
|
|
CSSIntPoint
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::GetPageCoords(nsPresContext* aPresContext,
|
|
|
|
WidgetEvent* aEvent,
|
|
|
|
LayoutDeviceIntPoint aPoint,
|
|
|
|
CSSIntPoint aDefaultPoint)
|
2011-12-17 04:24:11 +04:00
|
|
|
{
|
2014-03-05 04:37:43 +04:00
|
|
|
CSSIntPoint pagePoint =
|
|
|
|
Event::GetClientCoords(aPresContext, aEvent, aPoint, aDefaultPoint);
|
2011-12-17 04:24:11 +04: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 13:55:05 +04:00
|
|
|
pagePoint += CSSIntPoint::FromAppUnitsRounded(scrollframe->GetScrollPosition());
|
2011-12-17 04:24:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pagePoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2013-07-10 13:55:05 +04:00
|
|
|
CSSIntPoint
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::GetClientCoords(nsPresContext* aPresContext,
|
|
|
|
WidgetEvent* aEvent,
|
|
|
|
LayoutDeviceIntPoint aPoint,
|
|
|
|
CSSIntPoint aDefaultPoint)
|
2011-12-17 04:24:11 +04:00
|
|
|
{
|
2014-04-01 08:09:23 +04:00
|
|
|
if (EventStateManager::sIsPointerLocked) {
|
|
|
|
return EventStateManager::sLastClientPoint;
|
2012-04-12 01:55:21 +04:00
|
|
|
}
|
|
|
|
|
2011-12-17 04:24:11 +04:00
|
|
|
if (!aEvent ||
|
2014-08-04 09:28:50 +04:00
|
|
|
(aEvent->mClass != eMouseEventClass &&
|
2014-08-04 09:28:51 +04:00
|
|
|
aEvent->mClass != eMouseScrollEventClass &&
|
2014-08-04 09:28:51 +04:00
|
|
|
aEvent->mClass != eWheelEventClass &&
|
2014-08-04 09:28:53 +04:00
|
|
|
aEvent->mClass != eTouchEventClass &&
|
2014-08-04 09:28:50 +04:00
|
|
|
aEvent->mClass != eDragEventClass &&
|
2014-08-04 09:28:52 +04:00
|
|
|
aEvent->mClass != ePointerEventClass &&
|
2014-08-04 09:28:53 +04:00
|
|
|
aEvent->mClass != eSimpleGestureEventClass) ||
|
2011-12-17 04:24:11 +04:00
|
|
|
!aPresContext ||
|
2013-10-22 12:55:20 +04:00
|
|
|
!aEvent->AsGUIEvent()->widget) {
|
2011-12-17 04:24:11 +04:00
|
|
|
return aDefaultPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIPresShell* shell = aPresContext->GetPresShell();
|
|
|
|
if (!shell) {
|
2013-07-10 13:55:05 +04:00
|
|
|
return CSSIntPoint(0, 0);
|
2011-12-17 04:24:11 +04:00
|
|
|
}
|
|
|
|
nsIFrame* rootFrame = shell->GetRootFrame();
|
2013-07-10 13:55:05 +04:00
|
|
|
if (!rootFrame) {
|
|
|
|
return CSSIntPoint(0, 0);
|
|
|
|
}
|
|
|
|
nsPoint pt =
|
2015-02-02 01:27:31 +03:00
|
|
|
nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, aPoint, rootFrame);
|
2011-12-17 04:24:11 +04:00
|
|
|
|
2013-07-10 13:55:05 +04:00
|
|
|
return CSSIntPoint::FromAppUnitsRounded(pt);
|
2011-12-17 04:24:11 +04:00
|
|
|
}
|
|
|
|
|
2015-03-13 14:50:10 +03:00
|
|
|
// static
|
|
|
|
CSSIntPoint
|
|
|
|
Event::GetOffsetCoords(nsPresContext* aPresContext,
|
|
|
|
WidgetEvent* aEvent,
|
|
|
|
LayoutDeviceIntPoint aPoint,
|
|
|
|
CSSIntPoint aDefaultPoint)
|
|
|
|
{
|
2015-09-18 20:36:13 +03:00
|
|
|
if (!aEvent->target) {
|
2015-03-13 14:50:10 +03:00
|
|
|
return GetPageCoords(aPresContext, aEvent, aPoint, aDefaultPoint);
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aEvent->target);
|
2015-03-17 16:04:32 +03:00
|
|
|
if (!content || !aPresContext) {
|
2015-03-13 14:50:10 +03:00
|
|
|
return CSSIntPoint(0, 0);
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIPresShell> shell = aPresContext->GetPresShell();
|
|
|
|
if (!shell) {
|
|
|
|
return CSSIntPoint(0, 0);
|
|
|
|
}
|
|
|
|
shell->FlushPendingNotifications(Flush_Layout);
|
|
|
|
nsIFrame* frame = content->GetPrimaryFrame();
|
|
|
|
if (!frame) {
|
|
|
|
return CSSIntPoint(0, 0);
|
|
|
|
}
|
|
|
|
nsIFrame* rootFrame = shell->GetRootFrame();
|
|
|
|
if (!rootFrame) {
|
|
|
|
return CSSIntPoint(0, 0);
|
|
|
|
}
|
|
|
|
CSSIntPoint clientCoords =
|
|
|
|
GetClientCoords(aPresContext, aEvent, aPoint, aDefaultPoint);
|
|
|
|
nsPoint pt = CSSPixel::ToAppUnits(clientCoords);
|
|
|
|
if (nsLayoutUtils::TransformPoint(rootFrame, frame, pt) ==
|
|
|
|
nsLayoutUtils::TRANSFORM_SUCCEEDED) {
|
|
|
|
pt -= frame->GetPaddingRectRelativeToSelf().TopLeft();
|
|
|
|
return CSSPixel::FromAppUnitsRounded(pt);
|
|
|
|
}
|
|
|
|
return CSSIntPoint(0, 0);
|
|
|
|
}
|
|
|
|
|
2014-03-05 04:37:43 +04:00
|
|
|
// To be called ONLY by Event::GetType (which has the additional
|
2005-08-27 01:38:38 +04:00
|
|
|
// logic for handling user-defined events).
|
2004-09-04 23:28:46 +04:00
|
|
|
// static
|
2014-03-05 04:37:43 +04:00
|
|
|
const char*
|
2015-08-26 15:56:59 +03:00
|
|
|
Event::GetEventName(EventMessage aEventType)
|
1998-07-17 08:52:12 +04:00
|
|
|
{
|
|
|
|
switch(aEventType) {
|
2015-08-26 15:56:59 +03:00
|
|
|
#define MESSAGE_TO_EVENT(name_, _message, _type, _struct) \
|
|
|
|
case _message: return #name_;
|
2014-04-01 15:42:12 +04:00
|
|
|
#include "mozilla/EventNameList.h"
|
2015-08-26 15:56:59 +03:00
|
|
|
#undef MESSAGE_TO_EVENT
|
1998-07-17 08:52:12 +04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-10-02 07:46:04 +04:00
|
|
|
// XXXldb We can hit this case for WidgetEvent objects that we didn't
|
2005-08-28 20:45:39 +04:00
|
|
|
// create and that are not user defined events since this function and
|
|
|
|
// SetEventType are incomplete. (But fixing that requires fixing the
|
|
|
|
// arrays in nsEventListenerManager too, since the events for which
|
2014-03-05 04:37:43 +04:00
|
|
|
// this is a problem generally *are* created by Event.)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
1998-07-17 08:52:12 +04:00
|
|
|
}
|
1998-07-23 06:55:33 +04:00
|
|
|
|
2013-12-08 19:51:16 +04:00
|
|
|
bool
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::DefaultPrevented(JSContext* aCx) const
|
2013-12-08 19:51:16 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aCx, "JS context must be specified");
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE(mEvent, false);
|
|
|
|
|
|
|
|
// If preventDefault() has never been called, just return false.
|
|
|
|
if (!mEvent->mFlags.mDefaultPrevented) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If preventDefault() has been called by content, return true. Otherwise,
|
|
|
|
// i.e., preventDefault() has been called by chrome, return true only when
|
|
|
|
// this is called by chrome.
|
|
|
|
return mEvent->mFlags.mDefaultPreventedByContent || IsChrome(aCx);
|
|
|
|
}
|
|
|
|
|
2014-06-06 09:29:49 +04:00
|
|
|
double
|
2014-06-06 09:29:49 +04:00
|
|
|
Event::TimeStamp() const
|
|
|
|
{
|
|
|
|
if (!sReturnHighResTimeStamp) {
|
2014-06-06 09:29:49 +04:00
|
|
|
return static_cast<double>(mEvent->time);
|
2014-06-06 09:29:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mEvent->timeStamp.IsNull()) {
|
2014-06-06 09:29:49 +04:00
|
|
|
return 0.0;
|
2014-06-06 09:29:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mIsMainThreadEvent) {
|
|
|
|
if (NS_WARN_IF(!mOwner)) {
|
2014-06-06 09:29:49 +04:00
|
|
|
return 0.0;
|
2014-06-06 09:29:49 +04:00
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> win = do_QueryInterface(mOwner);
|
2015-02-23 18:03:40 +03:00
|
|
|
if (NS_WARN_IF(!win)) {
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
nsPerformance* perf = win->GetPerformance();
|
2014-06-06 09:29:49 +04:00
|
|
|
if (NS_WARN_IF(!perf)) {
|
2014-06-06 09:29:49 +04:00
|
|
|
return 0.0;
|
2014-06-06 09:29:49 +04:00
|
|
|
}
|
|
|
|
|
2014-06-06 09:29:49 +04:00
|
|
|
return perf->GetDOMTiming()->TimeStampToDOMHighRes(mEvent->timeStamp);
|
2014-06-06 09:29:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// For dedicated workers, we should make times relative to the navigation
|
2014-08-30 08:56:35 +04:00
|
|
|
// start of the document that created the worker, which is the same as the
|
|
|
|
// timebase for performance.now().
|
2014-06-06 09:29:49 +04:00
|
|
|
workers::WorkerPrivate* workerPrivate =
|
|
|
|
workers::GetCurrentThreadWorkerPrivate();
|
|
|
|
MOZ_ASSERT(workerPrivate);
|
|
|
|
|
|
|
|
TimeDuration duration =
|
2015-11-19 23:32:49 +03:00
|
|
|
mEvent->timeStamp - workerPrivate->CreationTimeStamp();
|
2014-06-06 09:29:49 +04:00
|
|
|
return duration.ToMilliseconds();
|
2014-06-06 09:29:49 +04:00
|
|
|
}
|
|
|
|
|
2013-05-27 18:43:51 +04:00
|
|
|
bool
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::GetPreventDefault() const
|
2013-05-27 18:43:51 +04:00
|
|
|
{
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> win(do_QueryInterface(mOwner));
|
2015-02-23 18:03:40 +03:00
|
|
|
if (win) {
|
|
|
|
if (nsIDocument* doc = win->GetExtantDoc()) {
|
2013-05-27 18:43:51 +04:00
|
|
|
doc->WarnOnceAbout(nsIDocument::eGetPreventDefault);
|
|
|
|
}
|
|
|
|
}
|
2013-12-08 19:51:16 +04:00
|
|
|
// GetPreventDefault() is legacy and Gecko specific method. Although,
|
|
|
|
// the result should be same as defaultPrevented, we don't need to break
|
|
|
|
// backward compatibility of legacy method. Let's behave traditionally.
|
2013-05-27 18:43:51 +04:00
|
|
|
return DefaultPrevented();
|
|
|
|
}
|
|
|
|
|
2009-06-23 14:07:39 +04:00
|
|
|
NS_IMETHODIMP
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::GetPreventDefault(bool* aReturn)
|
2009-06-23 14:07:39 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aReturn);
|
2013-03-17 11:55:17 +04:00
|
|
|
*aReturn = GetPreventDefault();
|
2009-06-23 14:07:39 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-14 00:44:35 +04:00
|
|
|
NS_IMETHODIMP
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::GetDefaultPrevented(bool* aReturn)
|
2011-05-14 00:44:35 +04:00
|
|
|
{
|
2013-03-17 11:55:17 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aReturn);
|
2013-12-08 19:51:16 +04:00
|
|
|
// This method must be called by only event handlers implemented by C++.
|
|
|
|
// Then, the handlers must handle default action. So, this method don't need
|
|
|
|
// to check if preventDefault() has been called by content or chrome.
|
2013-03-17 11:55:17 +04:00
|
|
|
*aReturn = DefaultPrevented();
|
|
|
|
return NS_OK;
|
2011-05-14 00:44:35 +04:00
|
|
|
}
|
|
|
|
|
2012-06-10 22:14:30 +04:00
|
|
|
NS_IMETHODIMP_(void)
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::Serialize(IPC::Message* aMsg, bool aSerializeInterfaceType)
|
2009-11-17 17:22:23 +03:00
|
|
|
{
|
|
|
|
if (aSerializeInterfaceType) {
|
|
|
|
IPC::WriteParam(aMsg, NS_LITERAL_STRING("event"));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsString type;
|
|
|
|
GetType(type);
|
|
|
|
IPC::WriteParam(aMsg, type);
|
|
|
|
|
2013-03-17 11:55:17 +04:00
|
|
|
IPC::WriteParam(aMsg, Bubbles());
|
|
|
|
IPC::WriteParam(aMsg, Cancelable());
|
|
|
|
IPC::WriteParam(aMsg, IsTrusted());
|
2009-11-17 17:22:23 +03:00
|
|
|
|
|
|
|
// No timestamp serialization for now!
|
|
|
|
}
|
|
|
|
|
2012-06-10 22:14:30 +04:00
|
|
|
NS_IMETHODIMP_(bool)
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::Deserialize(const IPC::Message* aMsg, void** aIter)
|
2009-11-17 17:22:23 +03:00
|
|
|
{
|
|
|
|
nsString type;
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &type), false);
|
2009-11-17 17:22:23 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool bubbles = false;
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &bubbles), false);
|
2009-11-17 17:22:23 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool cancelable = false;
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &cancelable), false);
|
2009-11-17 17:22:23 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool trusted = false;
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &trusted), false);
|
2009-11-17 17:22:23 +03:00
|
|
|
|
2015-11-13 03:09:42 +03:00
|
|
|
InitEvent(type, bubbles, cancelable);
|
2009-11-17 17:22:23 +03:00
|
|
|
SetTrusted(trusted);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2009-11-17 17:22:23 +03:00
|
|
|
}
|
|
|
|
|
2013-03-09 15:34:29 +04:00
|
|
|
NS_IMETHODIMP_(void)
|
2014-03-05 04:37:43 +04:00
|
|
|
Event::SetOwner(mozilla::dom::EventTarget* aOwner)
|
2013-03-09 15:34:29 +04:00
|
|
|
{
|
|
|
|
mOwner = nullptr;
|
|
|
|
|
|
|
|
if (!aOwner) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsINode> n = do_QueryInterface(aOwner);
|
|
|
|
if (n) {
|
2015-02-23 18:03:40 +03:00
|
|
|
mOwner = n->OwnerDoc()->GetScopeObject();
|
2013-03-09 15:34:29 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> w = do_QueryInterface(aOwner);
|
2013-03-09 15:34:29 +04:00
|
|
|
if (w) {
|
2016-01-30 20:05:36 +03:00
|
|
|
mOwner = do_QueryInterface(w);
|
2013-03-09 15:34:29 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-01 10:13:50 +04:00
|
|
|
nsCOMPtr<DOMEventTargetHelper> eth = do_QueryInterface(aOwner);
|
2013-03-09 15:34:29 +04:00
|
|
|
if (eth) {
|
2015-02-23 18:03:40 +03:00
|
|
|
mOwner = eth->GetParentObject();
|
2013-03-09 15:34:29 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsCOMPtr<nsPIWindowRoot> root = do_QueryInterface(aOwner);
|
|
|
|
MOZ_ASSERT(root, "Unexpected EventTarget!");
|
|
|
|
#endif
|
|
|
|
}
|
2009-11-17 17:22:23 +03:00
|
|
|
|
2014-08-27 07:19:56 +04:00
|
|
|
// static
|
|
|
|
nsIContent*
|
|
|
|
Event::GetShadowRelatedTarget(nsIContent* aCurrentTarget,
|
|
|
|
nsIContent* aRelatedTarget)
|
|
|
|
{
|
|
|
|
if (!aCurrentTarget || !aRelatedTarget) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Walk up the ancestor node trees of the related target until
|
|
|
|
// we encounter the node tree of the current target in order
|
|
|
|
// to find the adjusted related target. Walking up the tree may
|
|
|
|
// not find a common ancestor node tree if the related target is in
|
|
|
|
// an ancestor tree, but in that case it does not need to be adjusted.
|
|
|
|
ShadowRoot* currentTargetShadow = aCurrentTarget->GetContainingShadow();
|
|
|
|
if (!currentTargetShadow) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent* relatedTarget = aCurrentTarget;
|
|
|
|
while (relatedTarget) {
|
|
|
|
ShadowRoot* ancestorShadow = relatedTarget->GetContainingShadow();
|
|
|
|
if (currentTargetShadow == ancestorShadow) {
|
|
|
|
return relatedTarget;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Didn't find the ancestor tree, thus related target does not have to
|
|
|
|
// adjusted.
|
|
|
|
if (!ancestorShadow) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
relatedTarget = ancestorShadow->GetHost();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-03-05 04:37:43 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2015-08-12 14:39:31 +03:00
|
|
|
already_AddRefed<Event>
|
|
|
|
NS_NewDOMEvent(EventTarget* aOwner,
|
2014-03-05 04:37:43 +04:00
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetEvent* aEvent)
|
1998-07-23 06:55:33 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Event> it = new Event(aOwner, aPresContext, aEvent);
|
2015-08-12 14:39:31 +03:00
|
|
|
return it.forget();
|
1998-07-23 06:55:33 +04:00
|
|
|
}
|