2015-05-03 19:32:37 +00: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 11:12:37 +00: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 07:55:55 +00:00
|
|
|
|
2013-12-08 15:51:16 +00:00
|
|
|
#include "AccessCheck.h"
|
2014-03-05 00:37:43 +00:00
|
|
|
#include "base/basictypes.h"
|
2012-08-28 12:41:04 +00:00
|
|
|
#include "ipc/IPCMessageUtils.h"
|
2014-03-05 00:37:43 +00:00
|
|
|
#include "mozilla/dom/Event.h"
|
2014-08-27 03:19:56 +00:00
|
|
|
#include "mozilla/dom/ShadowRoot.h"
|
2018-05-31 15:57:57 +00:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2013-09-25 11:21:20 +00:00
|
|
|
#include "mozilla/ContentEvents.h"
|
2014-04-01 06:13:50 +00:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2014-04-01 04:09:23 +00:00
|
|
|
#include "mozilla/EventStateManager.h"
|
2014-02-27 10:51:15 +00:00
|
|
|
#include "mozilla/InternalMutationEvent.h"
|
2016-06-09 17:04:42 +00:00
|
|
|
#include "mozilla/dom/Performance.h"
|
2018-01-31 07:25:30 +00:00
|
|
|
#include "mozilla/dom/WorkerPrivate.h"
|
2013-09-25 11:21:20 +00:00
|
|
|
#include "mozilla/MiscEvents.h"
|
2013-09-25 11:21:18 +00:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2014-03-05 00:37:43 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2013-09-25 11:21:19 +00:00
|
|
|
#include "mozilla/TextEvents.h"
|
2013-09-25 11:21:16 +00: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 16:46:42 +00:00
|
|
|
#include "nsContentUtils.h"
|
2014-03-05 00:37:43 +00:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsDeviceContext.h"
|
|
|
|
#include "nsError.h"
|
|
|
|
#include "nsGlobalWindow.h"
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsIContent.h"
|
2018-04-13 18:13:10 +00:00
|
|
|
#include "nsIContentInlines.h"
|
2019-01-02 13:05:23 +00:00
|
|
|
#include "mozilla/dom/Document.h"
|
2014-03-05 00:37:43 +00:00
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIScrollableFrame.h"
|
2013-03-07 18:53:19 +00:00
|
|
|
#include "nsJSEnvironment.h"
|
2011-12-17 00:24:11 +00:00
|
|
|
#include "nsLayoutUtils.h"
|
2013-03-09 11:34:29 +00:00
|
|
|
#include "nsPIWindowRoot.h"
|
2017-06-06 03:45:14 +00:00
|
|
|
#include "nsRFPService.h"
|
1998-07-17 04:52:12 +00:00
|
|
|
|
2013-12-08 15:51:16 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2014-03-05 00:37:43 +00:00
|
|
|
|
2014-06-06 05:29:49 +00:00
|
|
|
static bool sReturnHighResTimeStamp = false;
|
|
|
|
static bool sReturnHighResTimeStampIsSet = false;
|
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
Event::Event(EventTarget* aOwner, nsPresContext* aPresContext,
|
|
|
|
WidgetEvent* aEvent) {
|
2013-05-08 00:55:21 +00:00
|
|
|
ConstructorInit(aOwner, aPresContext, aEvent);
|
|
|
|
}
|
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
Event::Event(nsPIDOMWindowInner* aParent) {
|
2017-11-03 22:25:38 +00:00
|
|
|
ConstructorInit(nsGlobalWindowInner::Cast(aParent), nullptr, nullptr);
|
2013-05-08 00:55:21 +00:00
|
|
|
}
|
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
void Event::ConstructorInit(EventTarget* aOwner, nsPresContext* aPresContext,
|
|
|
|
WidgetEvent* aEvent) {
|
2013-03-09 11:34:29 +00:00
|
|
|
SetOwner(aOwner);
|
2015-06-25 16:26:09 +00:00
|
|
|
mIsMainThreadEvent = NS_IsMainThread();
|
2013-03-09 11:34:29 +00:00
|
|
|
|
2014-06-06 05:29:49 +00:00
|
|
|
if (mIsMainThreadEvent && !sReturnHighResTimeStampIsSet) {
|
|
|
|
Preferences::AddBoolVarCache(&sReturnHighResTimeStamp,
|
|
|
|
"dom.event.highrestimestamp.enabled",
|
|
|
|
sReturnHighResTimeStamp);
|
|
|
|
sReturnHighResTimeStampIsSet = true;
|
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mPrivateDataDuplicated = false;
|
2014-10-15 14:48:04 +00: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 16:46:42 +00:00
|
|
|
|
2000-05-16 11:35:12 +00:00
|
|
|
if (aEvent) {
|
|
|
|
mEvent = aEvent;
|
2011-10-17 14:59:28 +00:00
|
|
|
mEventIsInternal = false;
|
2000-05-16 11:35:12 +00:00
|
|
|
} else {
|
2011-10-17 14:59:28 +00:00
|
|
|
mEventIsInternal = true;
|
2004-08-20 18:09:19 +00:00
|
|
|
/*
|
|
|
|
A derived class might want to allocate its own type of aEvent
|
2013-10-02 03:46:04 +00:00
|
|
|
(derived from WidgetEvent). To do this, it should take care to pass
|
2013-04-03 01:14:24 +00:00
|
|
|
a non-nullptr aEvent to this ctor, e.g.:
|
2017-07-06 12:00:35 +00:00
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
FooEvent::FooEvent(..., WidgetEvent* aEvent)
|
|
|
|
: Event(..., aEvent ? aEvent : new WidgetEvent())
|
2017-07-06 12:00:35 +00:00
|
|
|
|
2004-09-04 19:28:46 +00:00
|
|
|
Then, to override the mEventIsInternal assignments done by the
|
|
|
|
base ctor, it should do this in its own ctor:
|
2004-08-20 18:09:19 +00:00
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
FooEvent::FooEvent(..., WidgetEvent* aEvent)
|
2004-08-20 18:09:19 +00:00
|
|
|
...
|
|
|
|
{
|
|
|
|
...
|
|
|
|
if (aEvent) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mEventIsInternal = false;
|
2004-08-20 18:09:19 +00:00
|
|
|
}
|
|
|
|
else {
|
2011-10-17 14:59:28 +00:00
|
|
|
mEventIsInternal = true;
|
2004-08-20 18:09:19 +00:00
|
|
|
}
|
|
|
|
...
|
|
|
|
}
|
|
|
|
*/
|
2015-08-28 23:58:26 +00:00
|
|
|
mEvent = new WidgetEvent(false, eVoidEvent);
|
2016-03-28 04:29:42 +00:00
|
|
|
mEvent->mTime = PR_Now();
|
2000-05-16 11:35:12 +00: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 16:46:42 +00:00
|
|
|
|
2011-12-14 19:53:48 +00:00
|
|
|
InitPresContextData(aPresContext);
|
|
|
|
}
|
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
void Event::InitPresContextData(nsPresContext* aPresContext) {
|
2011-12-14 19:53:48 +00:00
|
|
|
mPresContext = aPresContext;
|
2003-02-22 08:10:46 +00:00
|
|
|
// Get the explicit original target (if it's anonymous make it null)
|
|
|
|
{
|
2010-06-11 11:10:51 +00:00
|
|
|
nsCOMPtr<nsIContent> content = GetTargetFromFrame();
|
2013-03-17 07:55:17 +00:00
|
|
|
mExplicitOriginalTarget = content;
|
2008-07-23 04:50:20 +00:00
|
|
|
if (content && content->IsInAnonymousSubtree()) {
|
2012-07-30 14:20:58 +00:00
|
|
|
mExplicitOriginalTarget = nullptr;
|
2003-02-22 08:10:46 +00:00
|
|
|
}
|
|
|
|
}
|
1998-06-07 07:55:55 +00:00
|
|
|
}
|
|
|
|
|
2017-07-06 12:00:35 +00:00
|
|
|
Event::~Event() {
|
2014-03-05 00:37:43 +00:00
|
|
|
NS_ASSERT_OWNINGTHREAD(Event);
|
2001-02-12 06:54:31 +00:00
|
|
|
|
2006-06-05 18:38:54 +00:00
|
|
|
if (mEventIsInternal && mEvent) {
|
2004-01-12 08:25:18 +00:00
|
|
|
delete mEvent;
|
2000-05-16 11:35:12 +00:00
|
|
|
}
|
1998-06-07 07:55:55 +00:00
|
|
|
}
|
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Event)
|
2013-03-09 11:34:29 +00:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2013-06-20 14:13:52 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2018-04-20 16:55:31 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(Event)
|
1999-12-21 19:28:15 +00:00
|
|
|
NS_INTERFACE_MAP_END
|
1998-06-07 07:55:55 +00:00
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(Event)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(Event)
|
2007-06-26 08:21:42 +00:00
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(Event)
|
2013-08-02 01:29:05 +00:00
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(Event)
|
2013-03-09 11:34:29 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Event)
|
2007-06-26 08:21:42 +00:00
|
|
|
if (tmp->mEventIsInternal) {
|
2016-04-18 15:46:00 +00:00
|
|
|
tmp->mEvent->mTarget = nullptr;
|
2016-04-18 16:15:16 +00:00
|
|
|
tmp->mEvent->mCurrentTarget = nullptr;
|
2016-04-18 16:33:23 +00:00
|
|
|
tmp->mEvent->mOriginalTarget = nullptr;
|
2017-12-18 17:08:11 +00:00
|
|
|
tmp->mEvent->mRelatedTarget = nullptr;
|
2018-02-15 10:08:42 +00:00
|
|
|
tmp->mEvent->mOriginalRelatedTarget = nullptr;
|
2014-08-04 05:28:46 +00:00
|
|
|
switch (tmp->mEvent->mClass) {
|
2014-08-04 05:28:50 +00:00
|
|
|
case eDragEventClass: {
|
2013-10-18 06:10:26 +00:00
|
|
|
WidgetDragEvent* dragEvent = tmp->mEvent->AsDragEvent();
|
2016-03-31 08:26:32 +00:00
|
|
|
dragEvent->mDataTransfer = nullptr;
|
2008-08-27 12:07:27 +00:00
|
|
|
break;
|
2013-10-18 06:10:26 +00:00
|
|
|
}
|
2014-08-04 05:28:55 +00:00
|
|
|
case eClipboardEventClass:
|
2016-03-26 08:19:57 +00:00
|
|
|
tmp->mEvent->AsClipboardEvent()->mClipboardData = nullptr;
|
2013-03-11 15:49:48 +00:00
|
|
|
break;
|
2014-08-04 05:28:57 +00:00
|
|
|
case eMutationEventClass:
|
2013-10-18 06:10:22 +00:00
|
|
|
tmp->mEvent->AsMutationEvent()->mRelatedNode = nullptr;
|
2007-06-26 08:21:42 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2018-12-11 21:35:40 +00:00
|
|
|
|
|
|
|
if (WidgetMouseEvent* mouseEvent = tmp->mEvent->AsMouseEvent()) {
|
|
|
|
mouseEvent->mClickTarget = nullptr;
|
|
|
|
}
|
2007-06-26 08:21:42 +00:00
|
|
|
}
|
2012-11-15 07:32:40 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPresContext);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mExplicitOriginalTarget);
|
2013-03-09 11:34:29 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mOwner);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
2007-06-26 08:21:42 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Event)
|
2007-06-26 08:21:42 +00:00
|
|
|
if (tmp->mEventIsInternal) {
|
2016-04-18 15:46:00 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEvent->mTarget)
|
2016-04-18 16:15:16 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEvent->mCurrentTarget)
|
2016-04-18 16:33:23 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEvent->mOriginalTarget)
|
2017-12-18 17:08:11 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEvent->mRelatedTarget)
|
2018-02-15 10:08:42 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEvent->mOriginalRelatedTarget);
|
2014-08-04 05:28:46 +00:00
|
|
|
switch (tmp->mEvent->mClass) {
|
2014-08-04 05:28:50 +00:00
|
|
|
case eDragEventClass: {
|
2013-10-18 06:10:26 +00:00
|
|
|
WidgetDragEvent* dragEvent = tmp->mEvent->AsDragEvent();
|
2016-03-31 08:26:32 +00:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mEvent->mDataTransfer");
|
|
|
|
cb.NoteXPCOMChild(dragEvent->mDataTransfer);
|
2008-08-27 12:07:27 +00:00
|
|
|
break;
|
2013-10-18 06:10:26 +00:00
|
|
|
}
|
2014-08-04 05:28:55 +00:00
|
|
|
case eClipboardEventClass:
|
2016-03-26 08:19:57 +00:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mEvent->mClipboardData");
|
|
|
|
cb.NoteXPCOMChild(tmp->mEvent->AsClipboardEvent()->mClipboardData);
|
2013-03-11 15:49:48 +00:00
|
|
|
break;
|
2014-08-04 05:28:57 +00:00
|
|
|
case eMutationEventClass:
|
2008-09-08 18:26:46 +00:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mEvent->mRelatedNode");
|
2013-10-18 06:10:22 +00:00
|
|
|
cb.NoteXPCOMChild(tmp->mEvent->AsMutationEvent()->mRelatedNode);
|
2007-06-26 08:21:42 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2018-12-11 21:35:40 +00:00
|
|
|
|
|
|
|
if (WidgetMouseEvent* mouseEvent = tmp->mEvent->AsMouseEvent()) {
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mEvent->mClickTarget");
|
|
|
|
cb.NoteXPCOMChild(mouseEvent->mClickTarget);
|
|
|
|
}
|
2007-06-26 08:21:42 +00:00
|
|
|
}
|
2012-11-15 07:32:39 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPresContext)
|
2012-11-15 07:32:40 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mExplicitOriginalTarget)
|
2013-03-09 11:34:29 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOwner)
|
2007-06-26 08:21:42 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
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 14:13:33 +00:00
|
|
|
JSObject* Event::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
|
|
|
|
return WrapObjectInternal(aCx, aGivenProto);
|
2014-10-17 23:16:58 +00: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 14:13:33 +00:00
|
|
|
JSObject* Event::WrapObjectInternal(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-25 21:20:54 +00:00
|
|
|
return Event_Binding::Wrap(aCx, this, aGivenProto);
|
2014-10-17 23:16:58 +00:00
|
|
|
}
|
|
|
|
|
2018-04-20 16:55:31 +00:00
|
|
|
void Event::GetType(nsAString& aType) const {
|
2017-03-22 20:44:00 +00:00
|
|
|
GetWidgetEventType(mEvent, aType);
|
1998-07-17 04:52:12 +00:00
|
|
|
}
|
|
|
|
|
2017-01-17 08:17:06 +00:00
|
|
|
EventTarget* Event::GetTarget() const { return mEvent->GetDOMEventTarget(); }
|
1998-06-07 07:55:55 +00:00
|
|
|
|
2019-01-02 13:05:23 +00:00
|
|
|
already_AddRefed<Document> Event::GetDocument() const {
|
2018-10-09 11:55:43 +00:00
|
|
|
nsCOMPtr<EventTarget> eventTarget = GetTarget();
|
|
|
|
|
|
|
|
if (!eventTarget) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsPIDOMWindowInner> win =
|
|
|
|
do_QueryInterface(eventTarget->GetOwnerGlobal());
|
|
|
|
|
|
|
|
if (!win) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-01-02 13:05:23 +00:00
|
|
|
nsCOMPtr<Document> doc;
|
2018-10-09 11:55:43 +00:00
|
|
|
doc = win->GetExtantDoc();
|
|
|
|
|
|
|
|
return doc.forget();
|
|
|
|
}
|
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
EventTarget* Event::GetCurrentTarget() const {
|
2017-01-17 08:17:06 +00:00
|
|
|
return mEvent->GetCurrentDOMEventTarget();
|
2007-04-17 09:18:36 +00:00
|
|
|
}
|
|
|
|
|
2017-12-18 16:07:36 +00:00
|
|
|
void Event::ComposedPath(nsTArray<RefPtr<EventTarget>>& aPath) {
|
|
|
|
EventDispatcher::GetComposedPathFor(mEvent, aPath);
|
|
|
|
}
|
|
|
|
|
2003-02-22 08:10:46 +00:00
|
|
|
//
|
|
|
|
// Get the actual event target node (may have been retargeted for mouse events)
|
|
|
|
//
|
2010-06-11 11:10:51 +00:00
|
|
|
already_AddRefed<nsIContent> Event::GetTargetFromFrame() {
|
2012-07-30 14:20:58 +00:00
|
|
|
if (!mPresContext) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2003-02-22 08:10:46 +00:00
|
|
|
|
2016-04-18 15:46:00 +00:00
|
|
|
// Get the mTarget frame (have to get the ESM first)
|
2011-04-21 17:35:52 +00:00
|
|
|
nsIFrame* targetFrame = mPresContext->EventStateManager()->GetEventTarget();
|
2012-07-30 14:20:58 +00:00
|
|
|
if (!targetFrame) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2003-02-22 08:10:46 +00:00
|
|
|
|
|
|
|
// get the real content
|
|
|
|
nsCOMPtr<nsIContent> realEventContent;
|
2011-09-26 20:55:04 +00:00
|
|
|
targetFrame->GetContentForEvent(mEvent, getter_AddRefs(realEventContent));
|
2010-06-11 11:10:51 +00:00
|
|
|
return realEventContent.forget();
|
2003-02-22 08:10:46 +00:00
|
|
|
}
|
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
EventTarget* Event::GetExplicitOriginalTarget() const {
|
2003-02-22 08:10:46 +00:00
|
|
|
if (mExplicitOriginalTarget) {
|
2013-03-17 07:55:17 +00:00
|
|
|
return mExplicitOriginalTarget;
|
2003-02-22 08:10:46 +00:00
|
|
|
}
|
2013-03-17 07:55:17 +00:00
|
|
|
return GetTarget();
|
2003-02-22 08:10:46 +00:00
|
|
|
}
|
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
EventTarget* Event::GetOriginalTarget() const {
|
2017-01-17 08:17:06 +00:00
|
|
|
return mEvent->GetOriginalDOMEventTarget();
|
2013-03-17 07:55:17 +00:00
|
|
|
}
|
|
|
|
|
2015-01-23 11:55:46 +00: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-16 01:26:03 +00:00
|
|
|
void Event::SetTrusted(bool aTrusted) { mEvent->mFlags.mIsTrusted = aTrusted; }
|
2001-11-20 08:40:54 +00:00
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
bool Event::Init(mozilla::dom::EventTarget* aGlobal) {
|
2013-08-30 09:47:19 +00:00
|
|
|
if (!mIsMainThreadEvent) {
|
2018-02-05 18:55:07 +00:00
|
|
|
return IsCurrentThreadRunningChromeWorker();
|
2013-08-30 09:47:19 +00:00
|
|
|
}
|
2013-03-09 11:34:29 +00:00
|
|
|
bool trusted = false;
|
2016-01-30 17:05:36 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> w = do_QueryInterface(aGlobal);
|
2013-03-09 11:34:29 +00:00
|
|
|
if (w) {
|
2019-01-02 13:05:23 +00:00
|
|
|
nsCOMPtr<Document> d = w->GetExtantDoc();
|
2013-03-09 11:34:29 +00:00
|
|
|
if (d) {
|
|
|
|
trusted = nsContentUtils::IsChromeDoc(d);
|
2018-02-20 22:00:10 +00:00
|
|
|
nsPresContext* presContext = d->GetPresContext();
|
|
|
|
if (presContext) {
|
|
|
|
InitPresContextData(presContext);
|
2013-03-09 11:34:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-03-13 20:02:32 +00:00
|
|
|
return trusted;
|
|
|
|
}
|
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
// static
|
|
|
|
already_AddRefed<Event> Event::Constructor(const GlobalObject& aGlobal,
|
|
|
|
const nsAString& aType,
|
|
|
|
const EventInit& aParam,
|
|
|
|
ErrorResult& aRv) {
|
2013-08-23 05:17:08 +00:00
|
|
|
nsCOMPtr<mozilla::dom::EventTarget> t =
|
|
|
|
do_QueryInterface(aGlobal.GetAsSupports());
|
2017-01-28 14:39:24 +00:00
|
|
|
return Constructor(t, aType, aParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
already_AddRefed<Event> Event::Constructor(EventTarget* aEventTarget,
|
|
|
|
const nsAString& aType,
|
|
|
|
const EventInit& aParam) {
|
|
|
|
RefPtr<Event> e = new Event(aEventTarget, nullptr, nullptr);
|
|
|
|
bool trusted = e->Init(aEventTarget);
|
2015-11-13 00:09:42 +00:00
|
|
|
e->InitEvent(aType, aParam.mBubbles, aParam.mCancelable);
|
2013-03-09 11:34:29 +00:00
|
|
|
e->SetTrusted(trusted);
|
2016-08-31 03:16:11 +00:00
|
|
|
e->SetComposed(aParam.mComposed);
|
2013-03-09 11:34:29 +00:00
|
|
|
return e.forget();
|
|
|
|
}
|
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
uint16_t Event::EventPhase() const {
|
2006-06-22 07:51:57 +00:00
|
|
|
// Note, remember to check that this works also
|
|
|
|
// if or when Bug 235441 is fixed.
|
2016-04-18 16:15:16 +00:00
|
|
|
if ((mEvent->mCurrentTarget && mEvent->mCurrentTarget == mEvent->mTarget) ||
|
2012-12-16 01:26:03 +00:00
|
|
|
mEvent->mFlags.InTargetPhase()) {
|
2018-06-25 21:20:54 +00:00
|
|
|
return Event_Binding::AT_TARGET;
|
2013-03-17 07:55:17 +00:00
|
|
|
}
|
|
|
|
if (mEvent->mFlags.mInCapturePhase) {
|
2018-06-25 21:20:54 +00:00
|
|
|
return Event_Binding::CAPTURING_PHASE;
|
2013-03-17 07:55:17 +00:00
|
|
|
}
|
|
|
|
if (mEvent->mFlags.mInBubblingPhase) {
|
2018-06-25 21:20:54 +00:00
|
|
|
return Event_Binding::BUBBLING_PHASE;
|
1999-07-19 19:54:34 +00:00
|
|
|
}
|
2018-06-25 21:20:54 +00:00
|
|
|
return Event_Binding::NONE;
|
2013-03-17 07:55:17 +00:00
|
|
|
}
|
|
|
|
|
2016-03-17 02:17:42 +00:00
|
|
|
void Event::StopPropagation() { mEvent->StopPropagation(); }
|
1999-11-03 07:11:45 +00:00
|
|
|
|
2016-03-17 02:57:42 +00:00
|
|
|
void Event::StopImmediatePropagation() { mEvent->StopImmediatePropagation(); }
|
2011-11-04 17:17:19 +00:00
|
|
|
|
2015-05-25 20:54:13 +00:00
|
|
|
void Event::StopCrossProcessForwarding() {
|
2016-03-22 07:01:46 +00:00
|
|
|
mEvent->StopCrossProcessForwarding();
|
2004-09-02 15:25:39 +00:00
|
|
|
}
|
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
void Event::PreventDefault() {
|
2013-12-08 15:51:16 +00:00
|
|
|
// This method is called only from C++ code which must handle default action
|
|
|
|
// of this event. So, pass true always.
|
|
|
|
PreventDefaultInternal(true);
|
|
|
|
}
|
|
|
|
|
2016-11-16 19:10:22 +00:00
|
|
|
void Event::PreventDefault(JSContext* aCx, CallerType aCallerType) {
|
2013-12-08 15:51:16 +00:00
|
|
|
// 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.
|
2017-07-10 08:42:01 +00:00
|
|
|
nsIPrincipal* principal =
|
|
|
|
mIsMainThreadEvent ? nsContentUtils::SubjectPrincipal(aCx) : nullptr;
|
|
|
|
|
|
|
|
PreventDefaultInternal(aCallerType == CallerType::System, principal);
|
2013-12-08 15:51:16 +00:00
|
|
|
}
|
|
|
|
|
2017-07-10 08:42:01 +00:00
|
|
|
void Event::PreventDefaultInternal(bool aCalledByDefaultHandler,
|
|
|
|
nsIPrincipal* aPrincipal) {
|
2013-12-08 15:51:16 +00:00
|
|
|
if (!mEvent->mFlags.mCancelable) {
|
|
|
|
return;
|
2000-05-16 11:35:12 +00:00
|
|
|
}
|
2016-05-12 18:50:22 +00:00
|
|
|
if (mEvent->mFlags.mInPassiveListener) {
|
2016-05-12 18:51:02 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> win(do_QueryInterface(mOwner));
|
|
|
|
if (win) {
|
2019-01-02 13:05:23 +00:00
|
|
|
if (Document* doc = win->GetExtantDoc()) {
|
2016-05-12 18:51:02 +00:00
|
|
|
nsString type;
|
|
|
|
GetType(type);
|
|
|
|
const char16_t* params[] = {type.get()};
|
2019-01-02 13:05:23 +00:00
|
|
|
doc->WarnOnceAbout(Document::ePreventDefaultFromPassiveListener, false,
|
|
|
|
params, ArrayLength(params));
|
2016-05-12 18:51:02 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-12 18:50:22 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-10-29 11:11:02 +00:00
|
|
|
|
2017-07-10 08:42:01 +00:00
|
|
|
mEvent->PreventDefault(aCalledByDefaultHandler, aPrincipal);
|
2013-12-12 09:39:04 +00:00
|
|
|
|
|
|
|
if (!IsTrusted()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
WidgetDragEvent* dragEvent = mEvent->AsDragEvent();
|
|
|
|
if (!dragEvent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-18 16:15:16 +00:00
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(mEvent->mCurrentTarget);
|
2013-12-12 09:39:04 +00:00
|
|
|
if (!node) {
|
2016-04-18 16:15:16 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> win =
|
|
|
|
do_QueryInterface(mEvent->mCurrentTarget);
|
2013-12-12 09:39:04 +00:00
|
|
|
if (!win) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
node = win->GetExtantDoc();
|
|
|
|
}
|
|
|
|
if (!nsContentUtils::IsChromeDoc(node->OwnerDoc())) {
|
|
|
|
dragEvent->mDefaultPreventedOnContent = true;
|
|
|
|
}
|
1998-07-17 04:52:12 +00:00
|
|
|
}
|
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
void Event::SetEventType(const nsAString& aEventTypeArg) {
|
2018-07-24 22:15:19 +00:00
|
|
|
mEvent->mSpecifiedEventTypeString.Truncate();
|
2013-08-16 10:06:24 +00:00
|
|
|
if (mIsMainThreadEvent) {
|
2015-08-26 12:56:59 +00:00
|
|
|
mEvent->mSpecifiedEventType = nsContentUtils::GetEventMessageAndAtom(
|
|
|
|
aEventTypeArg, mEvent->mClass, &(mEvent->mMessage));
|
2016-08-31 03:16:11 +00:00
|
|
|
mEvent->SetDefaultComposed();
|
2013-08-16 10:06:24 +00:00
|
|
|
} else {
|
2018-07-24 22:15:19 +00:00
|
|
|
mEvent->mSpecifiedEventType =
|
|
|
|
NS_Atomize(NS_LITERAL_STRING("on") + aEventTypeArg);
|
2015-09-10 01:40:04 +00:00
|
|
|
mEvent->mMessage = eUnidentifiedEvent;
|
2016-08-31 03:16:11 +00:00
|
|
|
mEvent->SetComposed(aEventTypeArg);
|
2013-08-16 10:06:24 +00:00
|
|
|
}
|
2016-09-12 10:15:16 +00:00
|
|
|
mEvent->SetDefaultComposedInNativeAnonymousContent();
|
2000-05-16 11:35:12 +00:00
|
|
|
}
|
|
|
|
|
2016-12-19 11:36:48 +00:00
|
|
|
already_AddRefed<EventTarget> Event::EnsureWebAccessibleRelatedTarget(
|
|
|
|
EventTarget* aRelatedTarget) {
|
|
|
|
nsCOMPtr<EventTarget> relatedTarget = aRelatedTarget;
|
|
|
|
if (relatedTarget) {
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(relatedTarget);
|
|
|
|
|
|
|
|
if (content && content->ChromeOnlyAccess() &&
|
|
|
|
!nsContentUtils::CanAccessNativeAnon()) {
|
|
|
|
content = content->FindFirstNonChromeOnlyAccessContent();
|
2018-10-01 21:38:01 +00:00
|
|
|
relatedTarget = content;
|
2016-12-19 11:36:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (relatedTarget) {
|
|
|
|
relatedTarget = relatedTarget->GetTargetForDOMEvent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return relatedTarget.forget();
|
|
|
|
}
|
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
void Event::InitEvent(const nsAString& aEventTypeArg,
|
2018-06-25 16:23:50 +00:00
|
|
|
mozilla::CanBubble aCanBubbleArg,
|
2018-09-14 00:05:39 +00:00
|
|
|
mozilla::Cancelable aCancelableArg,
|
|
|
|
mozilla::Composed aComposedArg) {
|
2005-06-22 01:53:58 +00:00
|
|
|
// Make sure this event isn't already being dispatched.
|
2015-11-13 00:09:42 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(!mEvent->mFlags.mIsBeingDispatched);
|
2005-06-22 01:53:58 +00:00
|
|
|
|
2013-03-17 07:55:17 +00:00
|
|
|
if (IsTrusted()) {
|
2005-06-22 01:53:58 +00:00
|
|
|
// Ensure the caller is permitted to dispatch trusted DOM events.
|
2013-08-30 09:47:19 +00:00
|
|
|
if (!nsContentUtils::ThreadsafeIsCallerChrome()) {
|
2011-10-17 14:59:28 +00:00
|
|
|
SetTrusted(false);
|
2005-06-22 01:53:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-18 10:36:08 +00:00
|
|
|
SetEventType(aEventTypeArg);
|
2005-06-22 01:53:58 +00:00
|
|
|
|
2018-06-25 16:23:50 +00:00
|
|
|
mEvent->mFlags.mBubbles = aCanBubbleArg == CanBubble::eYes;
|
|
|
|
mEvent->mFlags.mCancelable = aCancelableArg == Cancelable::eYes;
|
2018-09-14 00:05:39 +00:00
|
|
|
if (aComposedArg != Composed::eDefault) {
|
|
|
|
mEvent->mFlags.mComposed = aComposedArg == Composed::eYes;
|
|
|
|
}
|
2005-06-22 01:53:58 +00:00
|
|
|
|
2013-03-20 14:15:58 +00:00
|
|
|
mEvent->mFlags.mDefaultPrevented = false;
|
2015-01-21 01:16:04 +00:00
|
|
|
mEvent->mFlags.mDefaultPreventedByContent = false;
|
|
|
|
mEvent->mFlags.mDefaultPreventedByChrome = false;
|
2016-08-18 13:37:26 +00:00
|
|
|
mEvent->mFlags.mPropagationStopped = false;
|
|
|
|
mEvent->mFlags.mImmediatePropagationStopped = false;
|
2013-03-20 14:15:58 +00:00
|
|
|
|
2006-03-14 21:51:56 +00:00
|
|
|
// Clearing the old targets, so that the event is targeted correctly when
|
|
|
|
// re-dispatching it.
|
2016-04-18 15:46:00 +00:00
|
|
|
mEvent->mTarget = nullptr;
|
2016-04-18 16:33:23 +00:00
|
|
|
mEvent->mOriginalTarget = nullptr;
|
1999-11-03 07:11:45 +00:00
|
|
|
}
|
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
void Event::DuplicatePrivateData() {
|
|
|
|
NS_ASSERTION(mEvent, "No WidgetEvent for Event duplication!");
|
2006-03-07 17:08:51 +00:00
|
|
|
if (mEventIsInternal) {
|
2018-04-20 16:55:31 +00:00
|
|
|
return;
|
2006-03-07 17:08:51 +00:00
|
|
|
}
|
|
|
|
|
2014-01-27 06:10:44 +00:00
|
|
|
mEvent = mEvent->Duplicate();
|
2012-07-30 14:20:58 +00:00
|
|
|
mPresContext = nullptr;
|
2011-10-17 14:59:28 +00:00
|
|
|
mEventIsInternal = true;
|
|
|
|
mPrivateDataDuplicated = true;
|
1998-06-23 21:53:02 +00:00
|
|
|
}
|
1998-07-17 04:52:12 +00:00
|
|
|
|
2018-04-20 04:49:30 +00:00
|
|
|
void Event::SetTarget(EventTarget* aTarget) { mEvent->mTarget = aTarget; }
|
1999-05-21 19:27:02 +00:00
|
|
|
|
2016-03-17 07:21:57 +00:00
|
|
|
bool Event::IsDispatchStopped() { return mEvent->PropagationStopped(); }
|
1999-12-15 22:04:43 +00:00
|
|
|
|
2016-02-12 15:40:07 +00:00
|
|
|
WidgetEvent* Event::WidgetEventPtr() { return mEvent; }
|
2000-05-17 05:27:22 +00:00
|
|
|
|
2015-11-10 16:32:40 +00:00
|
|
|
// static
|
2014-03-05 00:37:43 +00:00
|
|
|
CSSIntPoint Event::GetScreenCoords(nsPresContext* aPresContext,
|
|
|
|
WidgetEvent* aEvent,
|
|
|
|
LayoutDeviceIntPoint aPoint) {
|
2014-04-01 04:09:23 +00:00
|
|
|
if (EventStateManager::sIsPointerLocked) {
|
|
|
|
return EventStateManager::sLastScreenPoint;
|
2012-04-11 21:55:21 +00:00
|
|
|
}
|
|
|
|
|
2014-08-04 05:28:50 +00:00
|
|
|
if (!aEvent || (aEvent->mClass != eMouseEventClass &&
|
2014-08-04 05:28:51 +00:00
|
|
|
aEvent->mClass != eMouseScrollEventClass &&
|
2014-08-04 05:28:51 +00:00
|
|
|
aEvent->mClass != eWheelEventClass &&
|
2014-08-04 05:28:52 +00:00
|
|
|
aEvent->mClass != ePointerEventClass &&
|
2014-08-04 05:28:53 +00:00
|
|
|
aEvent->mClass != eTouchEventClass &&
|
2014-08-04 05:28:50 +00:00
|
|
|
aEvent->mClass != eDragEventClass &&
|
2014-08-04 05:28:53 +00:00
|
|
|
aEvent->mClass != eSimpleGestureEventClass)) {
|
2015-11-10 16:32:40 +00: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 08:55:20 +00:00
|
|
|
WidgetGUIEvent* guiEvent = aEvent->AsGUIEvent();
|
2016-04-14 08:03:14 +00:00
|
|
|
if (!aPresContext || !(guiEvent && guiEvent->mWidget)) {
|
2015-11-27 02:04:16 +00:00
|
|
|
return CSSIntPoint(aPoint.x, aPoint.y);
|
2011-12-17 00:24:11 +00:00
|
|
|
}
|
|
|
|
|
2016-09-29 14:20:52 +00:00
|
|
|
nsPoint pt = LayoutDevicePixel::ToAppUnits(
|
|
|
|
aPoint,
|
|
|
|
aPresContext->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom());
|
2015-11-27 02:04:16 +00:00
|
|
|
|
2016-01-27 20:01:00 +00:00
|
|
|
if (nsIPresShell* ps = aPresContext->GetPresShell()) {
|
|
|
|
pt = pt.RemoveResolution(nsLayoutUtils::GetCurrentAPZResolutionScale(ps));
|
2016-09-29 14:20:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pt += LayoutDevicePixel::ToAppUnits(
|
|
|
|
guiEvent->mWidget->WidgetToScreenOffset(),
|
|
|
|
aPresContext->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom());
|
|
|
|
|
|
|
|
return CSSPixel::FromAppUnitsRounded(pt);
|
2011-12-17 00:24:11 +00:00
|
|
|
}
|
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
// static
|
|
|
|
CSSIntPoint Event::GetPageCoords(nsPresContext* aPresContext,
|
|
|
|
WidgetEvent* aEvent,
|
|
|
|
LayoutDeviceIntPoint aPoint,
|
|
|
|
CSSIntPoint aDefaultPoint) {
|
|
|
|
CSSIntPoint pagePoint =
|
|
|
|
Event::GetClientCoords(aPresContext, aEvent, aPoint, aDefaultPoint);
|
2011-12-17 00:24:11 +00: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 09:55:05 +00:00
|
|
|
pagePoint +=
|
|
|
|
CSSIntPoint::FromAppUnitsRounded(scrollframe->GetScrollPosition());
|
2011-12-17 00:24:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pagePoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2014-03-05 00:37:43 +00:00
|
|
|
CSSIntPoint Event::GetClientCoords(nsPresContext* aPresContext,
|
|
|
|
WidgetEvent* aEvent,
|
|
|
|
LayoutDeviceIntPoint aPoint,
|
|
|
|
CSSIntPoint aDefaultPoint) {
|
2014-04-01 04:09:23 +00:00
|
|
|
if (EventStateManager::sIsPointerLocked) {
|
|
|
|
return EventStateManager::sLastClientPoint;
|
2012-04-11 21:55:21 +00:00
|
|
|
}
|
|
|
|
|
2011-12-17 00:24:11 +00:00
|
|
|
if (!aEvent ||
|
2014-08-04 05:28:50 +00:00
|
|
|
(aEvent->mClass != eMouseEventClass &&
|
2014-08-04 05:28:51 +00:00
|
|
|
aEvent->mClass != eMouseScrollEventClass &&
|
2014-08-04 05:28:51 +00:00
|
|
|
aEvent->mClass != eWheelEventClass &&
|
2014-08-04 05:28:53 +00:00
|
|
|
aEvent->mClass != eTouchEventClass &&
|
2014-08-04 05:28:50 +00:00
|
|
|
aEvent->mClass != eDragEventClass &&
|
2014-08-04 05:28:52 +00:00
|
|
|
aEvent->mClass != ePointerEventClass &&
|
2014-08-04 05:28:53 +00:00
|
|
|
aEvent->mClass != eSimpleGestureEventClass) ||
|
2016-04-14 08:03:14 +00:00
|
|
|
!aPresContext || !aEvent->AsGUIEvent()->mWidget) {
|
2011-12-17 00:24:11 +00:00
|
|
|
return aDefaultPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIPresShell* shell = aPresContext->GetPresShell();
|
|
|
|
if (!shell) {
|
2013-07-10 09:55:05 +00:00
|
|
|
return CSSIntPoint(0, 0);
|
2011-12-17 00:24:11 +00:00
|
|
|
}
|
|
|
|
nsIFrame* rootFrame = shell->GetRootFrame();
|
2013-07-10 09:55:05 +00:00
|
|
|
if (!rootFrame) {
|
|
|
|
return CSSIntPoint(0, 0);
|
|
|
|
}
|
|
|
|
nsPoint pt =
|
2015-02-01 22:27:31 +00:00
|
|
|
nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, aPoint, rootFrame);
|
2011-12-17 00:24:11 +00:00
|
|
|
|
2013-07-10 09:55:05 +00:00
|
|
|
return CSSIntPoint::FromAppUnitsRounded(pt);
|
2011-12-17 00:24:11 +00:00
|
|
|
}
|
|
|
|
|
2015-03-13 11:50:10 +00:00
|
|
|
// static
|
|
|
|
CSSIntPoint Event::GetOffsetCoords(nsPresContext* aPresContext,
|
|
|
|
WidgetEvent* aEvent,
|
|
|
|
LayoutDeviceIntPoint aPoint,
|
|
|
|
CSSIntPoint aDefaultPoint) {
|
2016-04-18 15:46:00 +00:00
|
|
|
if (!aEvent->mTarget) {
|
2015-03-13 11:50:10 +00:00
|
|
|
return GetPageCoords(aPresContext, aEvent, aPoint, aDefaultPoint);
|
|
|
|
}
|
2016-04-18 15:46:00 +00:00
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aEvent->mTarget);
|
2015-03-17 13:04:32 +00:00
|
|
|
if (!content || !aPresContext) {
|
2015-03-13 11:50:10 +00:00
|
|
|
return CSSIntPoint(0, 0);
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIPresShell> shell = aPresContext->GetPresShell();
|
|
|
|
if (!shell) {
|
|
|
|
return CSSIntPoint(0, 0);
|
|
|
|
}
|
2017-01-05 07:31:56 +00:00
|
|
|
shell->FlushPendingNotifications(FlushType::Layout);
|
2015-03-13 11:50:10 +00:00
|
|
|
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 00:37:43 +00:00
|
|
|
// To be called ONLY by Event::GetType (which has the additional
|
2005-08-26 21:38:38 +00:00
|
|
|
// logic for handling user-defined events).
|
2004-09-04 19:28:46 +00:00
|
|
|
// static
|
2015-08-26 12:56:59 +00:00
|
|
|
const char* Event::GetEventName(EventMessage aEventType) {
|
1998-07-17 04:52:12 +00:00
|
|
|
switch (aEventType) {
|
2015-08-26 12:56:59 +00:00
|
|
|
#define MESSAGE_TO_EVENT(name_, _message, _type, _struct) \
|
|
|
|
case _message: \
|
|
|
|
return #name_;
|
2014-04-01 11:42:12 +00:00
|
|
|
#include "mozilla/EventNameList.h"
|
2015-08-26 12:56:59 +00:00
|
|
|
#undef MESSAGE_TO_EVENT
|
1998-07-17 04:52:12 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-10-02 03:46:04 +00:00
|
|
|
// XXXldb We can hit this case for WidgetEvent objects that we didn't
|
2005-08-28 16:45:39 +00: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 00:37:43 +00:00
|
|
|
// this is a problem generally *are* created by Event.)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
1998-07-17 04:52:12 +00:00
|
|
|
}
|
1998-07-23 02:55:33 +00:00
|
|
|
|
2016-11-16 19:10:22 +00:00
|
|
|
bool Event::DefaultPrevented(CallerType aCallerType) const {
|
2013-12-08 15:51:16 +00:00
|
|
|
NS_ENSURE_TRUE(mEvent, false);
|
|
|
|
|
|
|
|
// If preventDefault() has never been called, just return false.
|
2016-03-22 07:47:52 +00:00
|
|
|
if (!mEvent->DefaultPrevented()) {
|
2013-12-08 15:51:16 +00:00
|
|
|
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.
|
2016-11-16 19:10:22 +00:00
|
|
|
return mEvent->DefaultPreventedByContent() ||
|
|
|
|
aCallerType == CallerType::System;
|
2013-12-08 15:51:16 +00:00
|
|
|
}
|
|
|
|
|
2018-08-28 06:28:56 +00:00
|
|
|
bool Event::ReturnValue(CallerType aCallerType) const {
|
|
|
|
return !DefaultPrevented(aCallerType);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Event::SetReturnValue(bool aReturnValue, CallerType aCallerType) {
|
|
|
|
if (!aReturnValue) {
|
|
|
|
PreventDefaultInternal(aCallerType == CallerType::System);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-09 16:00:23 +00:00
|
|
|
double Event::TimeStamp() {
|
2014-06-06 05:29:49 +00:00
|
|
|
if (!sReturnHighResTimeStamp) {
|
2018-03-09 16:00:23 +00:00
|
|
|
// In the situation where you have set a very old, not-very-supported
|
|
|
|
// non-default preference, we will always reduce the precision,
|
|
|
|
// regardless of system principal or not.
|
2018-03-13 17:36:34 +00:00
|
|
|
// The timestamp is absolute, so we supply a zero context mix-in.
|
2018-03-09 16:00:23 +00:00
|
|
|
double ret = static_cast<double>(mEvent->mTime);
|
2018-03-13 17:36:34 +00:00
|
|
|
return nsRFPService::ReduceTimePrecisionAsMSecs(ret, 0);
|
2014-06-06 05:29:49 +00:00
|
|
|
}
|
|
|
|
|
2016-03-28 04:49:02 +00:00
|
|
|
if (mEvent->mTimeStamp.IsNull()) {
|
2014-06-06 05:29:49 +00:00
|
|
|
return 0.0;
|
2014-06-06 05:29:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mIsMainThreadEvent) {
|
|
|
|
if (NS_WARN_IF(!mOwner)) {
|
2014-06-06 05:29:49 +00:00
|
|
|
return 0.0;
|
2014-06-06 05:29:49 +00:00
|
|
|
}
|
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> win = do_QueryInterface(mOwner);
|
2015-02-23 15:03:40 +00:00
|
|
|
if (NS_WARN_IF(!win)) {
|
|
|
|
return 0.0;
|
|
|
|
}
|
2016-06-09 17:04:42 +00:00
|
|
|
|
|
|
|
Performance* perf = win->GetPerformance();
|
2014-06-06 05:29:49 +00:00
|
|
|
if (NS_WARN_IF(!perf)) {
|
2014-06-06 05:29:49 +00:00
|
|
|
return 0.0;
|
2014-06-06 05:29:49 +00:00
|
|
|
}
|
|
|
|
|
2018-03-09 16:00:23 +00:00
|
|
|
double ret =
|
|
|
|
perf->GetDOMTiming()->TimeStampToDOMHighRes(mEvent->mTimeStamp);
|
|
|
|
MOZ_ASSERT(mOwner->PrincipalOrNull());
|
|
|
|
if (nsContentUtils::IsSystemPrincipal(mOwner->PrincipalOrNull()))
|
|
|
|
return ret;
|
|
|
|
|
2018-03-13 17:36:34 +00:00
|
|
|
return nsRFPService::ReduceTimePrecisionAsMSecs(
|
|
|
|
ret, perf->GetRandomTimelineSeed());
|
2014-06-06 05:29:49 +00:00
|
|
|
}
|
|
|
|
|
2018-02-05 18:55:07 +00:00
|
|
|
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
2014-06-06 05:29:49 +00:00
|
|
|
MOZ_ASSERT(workerPrivate);
|
|
|
|
|
2018-03-09 16:00:23 +00:00
|
|
|
double ret = workerPrivate->TimeStampToDOMHighRes(mEvent->mTimeStamp);
|
|
|
|
if (workerPrivate->UsesSystemPrincipal()) return ret;
|
2014-06-06 05:29:49 +00:00
|
|
|
|
2018-03-13 17:36:34 +00:00
|
|
|
return nsRFPService::ReduceTimePrecisionAsMSecs(
|
|
|
|
ret, workerPrivate->GetRandomTimelineSeed());
|
2017-06-06 03:45:14 +00:00
|
|
|
}
|
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
void Event::Serialize(IPC::Message* aMsg, bool aSerializeInterfaceType) {
|
2009-11-17 14:22:23 +00:00
|
|
|
if (aSerializeInterfaceType) {
|
|
|
|
IPC::WriteParam(aMsg, NS_LITERAL_STRING("event"));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsString type;
|
|
|
|
GetType(type);
|
|
|
|
IPC::WriteParam(aMsg, type);
|
|
|
|
|
2013-03-17 07:55:17 +00:00
|
|
|
IPC::WriteParam(aMsg, Bubbles());
|
|
|
|
IPC::WriteParam(aMsg, Cancelable());
|
|
|
|
IPC::WriteParam(aMsg, IsTrusted());
|
2016-08-31 03:16:11 +00:00
|
|
|
IPC::WriteParam(aMsg, Composed());
|
2009-11-17 14:22:23 +00:00
|
|
|
|
|
|
|
// No timestamp serialization for now!
|
|
|
|
}
|
|
|
|
|
2016-04-21 04:09:15 +00:00
|
|
|
bool Event::Deserialize(const IPC::Message* aMsg, PickleIterator* aIter) {
|
2009-11-17 14:22:23 +00:00
|
|
|
nsString type;
|
2011-10-17 14:59:28 +00:00
|
|
|
NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &type), false);
|
2009-11-17 14:22:23 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool bubbles = false;
|
2011-10-17 14:59:28 +00:00
|
|
|
NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &bubbles), false);
|
2009-11-17 14:22:23 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool cancelable = false;
|
2011-10-17 14:59:28 +00:00
|
|
|
NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &cancelable), false);
|
2009-11-17 14:22:23 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool trusted = false;
|
2011-10-17 14:59:28 +00:00
|
|
|
NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &trusted), false);
|
2009-11-17 14:22:23 +00:00
|
|
|
|
2016-08-31 03:16:11 +00:00
|
|
|
bool composed = false;
|
|
|
|
NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &composed), false);
|
|
|
|
|
2015-11-13 00:09:42 +00:00
|
|
|
InitEvent(type, bubbles, cancelable);
|
2009-11-17 14:22:23 +00:00
|
|
|
SetTrusted(trusted);
|
2016-08-31 03:16:11 +00:00
|
|
|
SetComposed(composed);
|
2009-11-17 14:22:23 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2009-11-17 14:22:23 +00:00
|
|
|
}
|
|
|
|
|
2017-01-28 14:39:24 +00:00
|
|
|
void Event::SetOwner(EventTarget* aOwner) {
|
2013-03-09 11:34:29 +00:00
|
|
|
mOwner = nullptr;
|
|
|
|
|
|
|
|
if (!aOwner) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsINode> n = do_QueryInterface(aOwner);
|
|
|
|
if (n) {
|
2015-02-23 15:03:40 +00:00
|
|
|
mOwner = n->OwnerDoc()->GetScopeObject();
|
2013-03-09 11:34:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> w = do_QueryInterface(aOwner);
|
2013-03-09 11:34:29 +00:00
|
|
|
if (w) {
|
2016-01-30 17:05:36 +00:00
|
|
|
mOwner = do_QueryInterface(w);
|
2013-03-09 11:34:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-01 06:13:50 +00:00
|
|
|
nsCOMPtr<DOMEventTargetHelper> eth = do_QueryInterface(aOwner);
|
2013-03-09 11:34:29 +00:00
|
|
|
if (eth) {
|
2015-02-23 15:03:40 +00:00
|
|
|
mOwner = eth->GetParentObject();
|
2013-03-09 11:34:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsCOMPtr<nsPIWindowRoot> root = do_QueryInterface(aOwner);
|
|
|
|
MOZ_ASSERT(root, "Unexpected EventTarget!");
|
|
|
|
#endif
|
|
|
|
}
|
2009-11-17 14:22:23 +00:00
|
|
|
|
2017-03-22 20:44:00 +00:00
|
|
|
void Event::GetWidgetEventType(WidgetEvent* aEvent, nsAString& aType) {
|
|
|
|
if (!aEvent->mSpecifiedEventTypeString.IsEmpty()) {
|
|
|
|
aType = aEvent->mSpecifiedEventTypeString;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* name = GetEventName(aEvent->mMessage);
|
|
|
|
|
|
|
|
if (name) {
|
2018-07-06 07:44:43 +00:00
|
|
|
CopyASCIItoUTF16(mozilla::MakeStringSpan(name), aType);
|
2017-03-22 20:44:00 +00:00
|
|
|
return;
|
|
|
|
} else if (aEvent->mMessage == eUnidentifiedEvent &&
|
|
|
|
aEvent->mSpecifiedEventType) {
|
|
|
|
// Remove "on"
|
|
|
|
aType = Substring(nsDependentAtomString(aEvent->mSpecifiedEventType), 2);
|
|
|
|
aEvent->mSpecifiedEventTypeString = aType;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aType.Truncate();
|
|
|
|
}
|
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2015-08-12 11:39:31 +00:00
|
|
|
already_AddRefed<Event> NS_NewDOMEvent(EventTarget* aOwner,
|
2014-03-05 00:37:43 +00:00
|
|
|
nsPresContext* aPresContext,
|
2017-07-06 12:00:35 +00:00
|
|
|
WidgetEvent* aEvent) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Event> it = new Event(aOwner, aPresContext, aEvent);
|
2015-08-12 11:39:31 +00:00
|
|
|
return it.forget();
|
1998-07-23 02:55:33 +00:00
|
|
|
}
|