2013-05-21 23:23:53 +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/. */
|
2011-04-26 12:30:17 +00:00
|
|
|
|
2016-07-18 14:26:38 +00:00
|
|
|
#include "mozilla/dom/Navigator.h"
|
2014-02-28 14:58:42 +00:00
|
|
|
#include "mozilla/dom/TouchEvent.h"
|
2013-04-05 08:49:00 +00:00
|
|
|
#include "mozilla/dom/Touch.h"
|
2013-07-10 09:53:53 +00:00
|
|
|
#include "mozilla/dom/TouchListBinding.h"
|
2014-02-28 14:58:42 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2013-09-25 11:21:16 +00:00
|
|
|
#include "mozilla/TouchEvents.h"
|
2014-02-28 14:58:42 +00:00
|
|
|
#include "nsContentUtils.h"
|
2016-07-18 14:26:38 +00:00
|
|
|
#include "nsIDocShell.h"
|
2015-05-08 01:29:00 +00:00
|
|
|
#include "mozilla/WidgetUtils.h"
|
2011-05-25 06:31:59 +00:00
|
|
|
|
2014-02-28 14:58:42 +00:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
namespace dom {
|
2011-04-26 12:30:17 +00:00
|
|
|
|
2014-02-28 14:58:42 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* TouchList
|
|
|
|
*****************************************************************************/
|
2011-04-26 12:30:17 +00:00
|
|
|
|
2014-02-28 14:58:42 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TouchList)
|
2013-07-10 09:53:53 +00:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2011-04-26 12:30:17 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2014-04-29 08:57:00 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(TouchList, mParent, mPoints)
|
2011-04-26 12:30:17 +00:00
|
|
|
|
2014-02-28 14:58:42 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(TouchList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(TouchList)
|
2011-04-26 12:30:17 +00:00
|
|
|
|
2014-02-28 14:58:42 +00: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 14:13:33 +00:00
|
|
|
TouchList::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-07-10 09:53:53 +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
|
|
|
return TouchListBinding::Wrap(aCx, this, aGivenProto);
|
2013-07-10 09:53:53 +00:00
|
|
|
}
|
|
|
|
|
2014-02-28 14:58:42 +00:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
TouchList::PrefEnabled(JSContext* aCx, JSObject* aGlobal)
|
2013-07-10 09:53:53 +00:00
|
|
|
{
|
2014-02-28 14:58:42 +00:00
|
|
|
return TouchEvent::PrefEnabled(aCx, aGlobal);
|
2013-07-10 09:53:53 +00:00
|
|
|
}
|
|
|
|
|
2014-02-28 14:58:42 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* TouchEvent
|
|
|
|
*****************************************************************************/
|
2011-04-26 12:30:17 +00:00
|
|
|
|
2014-02-28 14:58:42 +00:00
|
|
|
TouchEvent::TouchEvent(EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetTouchEvent* aEvent)
|
2014-02-28 14:58:43 +00:00
|
|
|
: UIEvent(aOwner, aPresContext,
|
2015-08-26 12:56:59 +00:00
|
|
|
aEvent ? aEvent :
|
2015-08-28 23:58:26 +00:00
|
|
|
new WidgetTouchEvent(false, eVoidEvent, nullptr))
|
2011-04-26 12:30:17 +00:00
|
|
|
{
|
|
|
|
if (aEvent) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mEventIsInternal = false;
|
2011-12-17 00:24:11 +00:00
|
|
|
|
2016-03-30 09:44:28 +00:00
|
|
|
for (uint32_t i = 0; i < aEvent->mTouches.Length(); ++i) {
|
|
|
|
Touch* touch = aEvent->mTouches[i];
|
2013-08-02 07:06:35 +00:00
|
|
|
touch->InitializePoints(mPresContext, aEvent);
|
2011-12-17 00:24:11 +00:00
|
|
|
}
|
2011-04-26 12:30:17 +00:00
|
|
|
} else {
|
2011-10-17 14:59:28 +00:00
|
|
|
mEventIsInternal = true;
|
2016-03-28 04:29:42 +00:00
|
|
|
mEvent->mTime = PR_Now();
|
2011-04-26 12:30:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-25 16:49:00 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(TouchEvent, UIEvent,
|
2018-05-25 15:02:59 +00:00
|
|
|
mEvent->AsTouchEvent()->mTouches,
|
2014-04-25 16:49:00 +00:00
|
|
|
mTouches,
|
|
|
|
mTargetTouches,
|
|
|
|
mChangedTouches)
|
2011-04-26 12:30:17 +00:00
|
|
|
|
2017-08-29 23:02:48 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TouchEvent)
|
2014-02-28 14:58:43 +00:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(UIEvent)
|
2011-04-26 12:30:17 +00:00
|
|
|
|
2014-02-28 14:58:43 +00:00
|
|
|
NS_IMPL_ADDREF_INHERITED(TouchEvent, UIEvent)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(TouchEvent, UIEvent)
|
2011-04-26 12:30:17 +00:00
|
|
|
|
2013-08-05 04:51:21 +00:00
|
|
|
void
|
2014-02-28 14:58:42 +00:00
|
|
|
TouchEvent::InitTouchEvent(const nsAString& aType,
|
|
|
|
bool aCanBubble,
|
|
|
|
bool aCancelable,
|
2017-11-06 22:52:14 +00:00
|
|
|
nsGlobalWindowInner* aView,
|
2014-02-28 14:58:42 +00:00
|
|
|
int32_t aDetail,
|
|
|
|
bool aCtrlKey,
|
|
|
|
bool aAltKey,
|
|
|
|
bool aShiftKey,
|
|
|
|
bool aMetaKey,
|
|
|
|
TouchList* aTouches,
|
|
|
|
TouchList* aTargetTouches,
|
2015-11-13 00:09:42 +00:00
|
|
|
TouchList* aChangedTouches)
|
2013-08-05 04:51:21 +00:00
|
|
|
{
|
2016-10-30 19:30:06 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(!mEvent->mFlags.mIsBeingDispatched);
|
|
|
|
|
2015-11-13 00:09:42 +00:00
|
|
|
UIEvent::InitUIEvent(aType, aCanBubble, aCancelable, aView, aDetail);
|
2013-10-18 06:10:26 +00:00
|
|
|
mEvent->AsInputEvent()->InitBasicModifiers(aCtrlKey, aAltKey,
|
|
|
|
aShiftKey, aMetaKey);
|
2018-05-25 15:02:59 +00:00
|
|
|
|
|
|
|
mEvent->AsTouchEvent()->mTouches.Clear();
|
|
|
|
|
|
|
|
// To support touch.target retargeting also when the event is
|
|
|
|
// created by JS, we need to copy Touch objects to the widget event.
|
|
|
|
// In order to not affect targetTouches, we don't check duplicates in that
|
|
|
|
// list.
|
2013-08-05 04:51:21 +00:00
|
|
|
mTargetTouches = aTargetTouches;
|
2018-05-25 15:02:59 +00:00
|
|
|
AssignTouchesToWidgetEvent(mTargetTouches, false);
|
|
|
|
mTouches = aTouches;
|
|
|
|
AssignTouchesToWidgetEvent(mTouches, true);
|
2013-08-05 04:51:21 +00:00
|
|
|
mChangedTouches = aChangedTouches;
|
2018-05-25 15:02:59 +00:00
|
|
|
AssignTouchesToWidgetEvent(mChangedTouches, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TouchEvent::AssignTouchesToWidgetEvent(TouchList* aList, bool aCheckDuplicates)
|
|
|
|
{
|
|
|
|
if (!aList) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
WidgetTouchEvent* widgetTouchEvent = mEvent->AsTouchEvent();
|
|
|
|
for (uint32_t i = 0; i < aList->Length(); ++i) {
|
|
|
|
Touch* touch = aList->Item(i);
|
|
|
|
if (touch &&
|
|
|
|
(!aCheckDuplicates ||
|
|
|
|
!widgetTouchEvent->mTouches.Contains(touch))) {
|
|
|
|
widgetTouchEvent->mTouches.AppendElement(touch);
|
|
|
|
}
|
|
|
|
}
|
2013-04-26 06:48:00 +00:00
|
|
|
}
|
2011-12-17 00:24:11 +00:00
|
|
|
|
2014-02-28 14:58:42 +00:00
|
|
|
TouchList*
|
|
|
|
TouchEvent::Touches()
|
2013-04-26 06:48:00 +00:00
|
|
|
{
|
|
|
|
if (!mTouches) {
|
2013-10-18 06:10:23 +00:00
|
|
|
WidgetTouchEvent* touchEvent = mEvent->AsTouchEvent();
|
2015-09-14 15:14:35 +00:00
|
|
|
if (mEvent->mMessage == eTouchEnd || mEvent->mMessage == eTouchCancel) {
|
2016-03-30 09:44:28 +00:00
|
|
|
// for touchend events, remove any changed touches from mTouches
|
2014-07-09 16:17:05 +00:00
|
|
|
WidgetTouchEvent::AutoTouchArray unchangedTouches;
|
2016-03-30 09:44:28 +00:00
|
|
|
const WidgetTouchEvent::TouchArray& touches = touchEvent->mTouches;
|
2013-04-26 06:48:00 +00:00
|
|
|
for (uint32_t i = 0; i < touches.Length(); ++i) {
|
|
|
|
if (!touches[i]->mChanged) {
|
|
|
|
unchangedTouches.AppendElement(touches[i]);
|
|
|
|
}
|
2011-12-17 00:24:11 +00:00
|
|
|
}
|
2014-02-28 14:58:42 +00:00
|
|
|
mTouches = new TouchList(ToSupports(this), unchangedTouches);
|
2013-04-26 06:48:00 +00:00
|
|
|
} else {
|
2016-03-30 09:44:28 +00:00
|
|
|
mTouches = new TouchList(ToSupports(this), touchEvent->mTouches);
|
2011-12-17 00:24:11 +00:00
|
|
|
}
|
|
|
|
}
|
2013-04-26 06:48:00 +00:00
|
|
|
return mTouches;
|
2011-04-26 12:30:17 +00:00
|
|
|
}
|
|
|
|
|
2014-02-28 14:58:42 +00:00
|
|
|
TouchList*
|
|
|
|
TouchEvent::TargetTouches()
|
2013-04-26 06:48:00 +00:00
|
|
|
{
|
2018-05-25 15:02:59 +00:00
|
|
|
if (!mTargetTouches || !mTargetTouches->Length()) {
|
2013-10-18 06:10:23 +00:00
|
|
|
WidgetTouchEvent* touchEvent = mEvent->AsTouchEvent();
|
2018-05-25 15:02:59 +00:00
|
|
|
if (!mTargetTouches) {
|
|
|
|
mTargetTouches = new TouchList(ToSupports(this));
|
|
|
|
}
|
2016-03-30 09:44:28 +00:00
|
|
|
const WidgetTouchEvent::TouchArray& touches = touchEvent->mTouches;
|
2013-04-26 06:48:00 +00:00
|
|
|
for (uint32_t i = 0; i < touches.Length(); ++i) {
|
|
|
|
// for touchend/cancel events, don't append to the target list if this is a
|
|
|
|
// touch that is ending
|
2015-09-14 15:14:35 +00:00
|
|
|
if ((mEvent->mMessage != eTouchEnd && mEvent->mMessage != eTouchCancel) ||
|
|
|
|
!touches[i]->mChanged) {
|
2018-05-25 15:02:59 +00:00
|
|
|
bool equalTarget = touches[i]->mTarget == mEvent->mTarget;
|
|
|
|
if (!equalTarget) {
|
|
|
|
// Need to still check if we're inside native anonymous content
|
|
|
|
// and the non-NAC target would be the same.
|
|
|
|
nsCOMPtr<nsIContent> touchTarget =
|
|
|
|
do_QueryInterface(touches[i]->mTarget);
|
|
|
|
nsCOMPtr<nsIContent> eventTarget =
|
|
|
|
do_QueryInterface(mEvent->mTarget);
|
|
|
|
equalTarget = touchTarget && eventTarget &&
|
|
|
|
touchTarget->FindFirstNonChromeOnlyAccessContent() ==
|
|
|
|
eventTarget->FindFirstNonChromeOnlyAccessContent();
|
|
|
|
}
|
|
|
|
if (equalTarget) {
|
|
|
|
mTargetTouches->Append(touches[i]);
|
2013-04-26 06:48:00 +00:00
|
|
|
}
|
2011-12-17 00:24:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-04-26 06:48:00 +00:00
|
|
|
return mTargetTouches;
|
2011-04-26 12:30:17 +00:00
|
|
|
}
|
|
|
|
|
2014-02-28 14:58:42 +00:00
|
|
|
TouchList*
|
|
|
|
TouchEvent::ChangedTouches()
|
2013-04-26 06:48:00 +00:00
|
|
|
{
|
|
|
|
if (!mChangedTouches) {
|
2014-07-09 16:17:05 +00:00
|
|
|
WidgetTouchEvent::AutoTouchArray changedTouches;
|
2013-10-18 06:10:23 +00:00
|
|
|
WidgetTouchEvent* touchEvent = mEvent->AsTouchEvent();
|
2016-03-30 09:44:28 +00:00
|
|
|
const WidgetTouchEvent::TouchArray& touches = touchEvent->mTouches;
|
2013-04-26 06:48:00 +00:00
|
|
|
for (uint32_t i = 0; i < touches.Length(); ++i) {
|
|
|
|
if (touches[i]->mChanged) {
|
|
|
|
changedTouches.AppendElement(touches[i]);
|
|
|
|
}
|
2011-12-17 00:24:11 +00:00
|
|
|
}
|
2014-02-28 14:58:42 +00:00
|
|
|
mChangedTouches = new TouchList(ToSupports(this), changedTouches);
|
2011-12-17 00:24:11 +00:00
|
|
|
}
|
2013-04-26 06:48:00 +00:00
|
|
|
return mChangedTouches;
|
2011-04-26 12:30:17 +00:00
|
|
|
}
|
|
|
|
|
2014-02-28 14:58:42 +00:00
|
|
|
// static
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2014-02-28 14:58:42 +00:00
|
|
|
TouchEvent::PrefEnabled(JSContext* aCx, JSObject* aGlobal)
|
2016-07-18 14:26:38 +00:00
|
|
|
{
|
|
|
|
nsIDocShell* docShell = nullptr;
|
|
|
|
if (aGlobal) {
|
2017-11-03 22:25:38 +00:00
|
|
|
nsGlobalWindowInner* win = xpc::WindowOrNull(aGlobal);
|
2016-07-18 14:26:38 +00:00
|
|
|
if (win) {
|
|
|
|
docShell = win->GetDocShell();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PrefEnabled(docShell);
|
|
|
|
}
|
|
|
|
|
2018-06-13 21:52:19 +00:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
TouchEvent::PlatformSupportsTouch()
|
|
|
|
{
|
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
|
|
|
// Touch support is always enabled on android.
|
|
|
|
return true;
|
|
|
|
#elif defined(XP_WIN) || defined(MOZ_WIDGET_GTK)
|
|
|
|
static bool sDidCheckTouchDeviceSupport = false;
|
|
|
|
static bool sIsTouchDeviceSupportPresent = false;
|
|
|
|
// On Windows and GTK3 we auto-detect based on device support.
|
|
|
|
if (!sDidCheckTouchDeviceSupport) {
|
|
|
|
sDidCheckTouchDeviceSupport = true;
|
|
|
|
sIsTouchDeviceSupportPresent = WidgetUtils::IsTouchDeviceSupportPresent();
|
|
|
|
// But touch events are only actually supported if APZ is enabled. If
|
|
|
|
// APZ is disabled globally, we can check that once and incorporate that
|
|
|
|
// into the cached state. If APZ is enabled, we need to further check
|
|
|
|
// based on the widget, which we do below (and don't cache that result).
|
|
|
|
sIsTouchDeviceSupportPresent &= gfxPlatform::AsyncPanZoomEnabled();
|
|
|
|
}
|
|
|
|
return sIsTouchDeviceSupportPresent;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-07-18 14:26:38 +00:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
TouchEvent::PrefEnabled(nsIDocShell* aDocShell)
|
2011-04-26 12:30:17 +00:00
|
|
|
{
|
2016-05-24 15:24:30 +00:00
|
|
|
static bool sPrefCached = false;
|
|
|
|
static int32_t sPrefCacheValue = 0;
|
|
|
|
|
2016-07-18 14:26:38 +00:00
|
|
|
uint32_t touchEventsOverride = nsIDocShell::TOUCHEVENTS_OVERRIDE_NONE;
|
|
|
|
if (aDocShell) {
|
|
|
|
aDocShell->GetTouchEventsOverride(&touchEventsOverride);
|
|
|
|
}
|
|
|
|
|
2016-05-24 15:24:30 +00:00
|
|
|
if (!sPrefCached) {
|
|
|
|
sPrefCached = true;
|
|
|
|
Preferences::AddIntVarCache(&sPrefCacheValue, "dom.w3c_touch_events.enabled");
|
|
|
|
}
|
|
|
|
|
2016-07-18 14:26:38 +00:00
|
|
|
bool enabled = false;
|
|
|
|
if (touchEventsOverride == nsIDocShell::TOUCHEVENTS_OVERRIDE_ENABLED) {
|
|
|
|
enabled = true;
|
|
|
|
} else if (touchEventsOverride == nsIDocShell::TOUCHEVENTS_OVERRIDE_DISABLED) {
|
|
|
|
enabled = false;
|
|
|
|
} else {
|
|
|
|
if (sPrefCacheValue == 2) {
|
2018-06-13 21:52:19 +00:00
|
|
|
enabled = PlatformSupportsTouch();
|
|
|
|
|
|
|
|
static bool firstTime = true;
|
|
|
|
// The touch screen data seems to be inaccurate in the parent process,
|
|
|
|
// and we really need the crash annotation in child processes.
|
|
|
|
if (firstTime && !XRE_IsParentProcess()) {
|
|
|
|
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("HasDeviceTouchScreen"),
|
|
|
|
enabled ?
|
|
|
|
NS_LITERAL_CSTRING("1") :
|
|
|
|
NS_LITERAL_CSTRING("0"));
|
|
|
|
firstTime = false;
|
2016-07-18 14:26:38 +00:00
|
|
|
}
|
2018-06-13 21:52:19 +00:00
|
|
|
|
|
|
|
#if defined(XP_WIN) || defined(MOZ_WIDGET_GTK)
|
2017-04-17 15:56:22 +00:00
|
|
|
if (enabled && aDocShell) {
|
|
|
|
// APZ might be disabled on this particular widget, in which case
|
|
|
|
// TouchEvent support will also be disabled. Try to detect that.
|
2017-04-24 21:38:33 +00:00
|
|
|
RefPtr<nsPresContext> pc;
|
|
|
|
aDocShell->GetPresContext(getter_AddRefs(pc));
|
2017-04-17 15:56:22 +00:00
|
|
|
if (pc && pc->GetRootWidget()) {
|
|
|
|
enabled &= pc->GetRootWidget()->AsyncPanZoomEnabled();
|
|
|
|
}
|
|
|
|
}
|
2012-10-25 14:57:51 +00:00
|
|
|
#endif
|
2016-07-18 14:26:38 +00:00
|
|
|
} else {
|
|
|
|
enabled = !!sPrefCacheValue;
|
|
|
|
}
|
2011-04-26 12:30:17 +00:00
|
|
|
}
|
2016-07-18 14:26:38 +00:00
|
|
|
|
|
|
|
if (enabled) {
|
2013-09-03 07:15:51 +00:00
|
|
|
nsContentUtils::InitializeTouchEventTable();
|
|
|
|
}
|
2016-07-18 14:26:38 +00:00
|
|
|
return enabled;
|
2011-04-26 12:30:17 +00:00
|
|
|
}
|
|
|
|
|
2015-12-29 13:46:18 +00:00
|
|
|
// static
|
2018-04-04 19:32:19 +00:00
|
|
|
already_AddRefed<TouchEvent>
|
2015-12-29 13:46:18 +00:00
|
|
|
TouchEvent::Constructor(const GlobalObject& aGlobal,
|
|
|
|
const nsAString& aType,
|
|
|
|
const TouchEventInit& aParam,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
nsCOMPtr<EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports());
|
|
|
|
RefPtr<TouchEvent> e = new TouchEvent(t, nullptr, nullptr);
|
|
|
|
bool trusted = e->Init(t);
|
|
|
|
RefPtr<TouchList> touches = e->CopyTouches(aParam.mTouches);
|
|
|
|
RefPtr<TouchList> targetTouches = e->CopyTouches(aParam.mTargetTouches);
|
|
|
|
RefPtr<TouchList> changedTouches = e->CopyTouches(aParam.mChangedTouches);
|
|
|
|
e->InitTouchEvent(aType, aParam.mBubbles, aParam.mCancelable, aParam.mView,
|
|
|
|
aParam.mDetail, aParam.mCtrlKey, aParam.mAltKey,
|
|
|
|
aParam.mShiftKey, aParam.mMetaKey, touches, targetTouches,
|
|
|
|
changedTouches);
|
|
|
|
e->SetTrusted(trusted);
|
2016-08-31 03:16:11 +00:00
|
|
|
e->SetComposed(aParam.mComposed);
|
2015-12-29 13:46:18 +00:00
|
|
|
return e.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
already_AddRefed<TouchList>
|
|
|
|
TouchEvent::CopyTouches(const Sequence<OwningNonNull<Touch>>& aTouches)
|
|
|
|
{
|
|
|
|
RefPtr<TouchList> list = new TouchList(GetParentObject());
|
|
|
|
size_t len = aTouches.Length();
|
|
|
|
for (size_t i = 0; i < len; ++i) {
|
|
|
|
list->Append(aTouches[i]);
|
|
|
|
}
|
|
|
|
return list.forget();
|
|
|
|
}
|
|
|
|
|
2013-10-18 06:10:26 +00:00
|
|
|
bool
|
2014-02-28 14:58:42 +00:00
|
|
|
TouchEvent::AltKey()
|
2013-10-18 06:10:26 +00:00
|
|
|
{
|
|
|
|
return mEvent->AsTouchEvent()->IsAlt();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-02-28 14:58:42 +00:00
|
|
|
TouchEvent::MetaKey()
|
2013-10-18 06:10:26 +00:00
|
|
|
{
|
|
|
|
return mEvent->AsTouchEvent()->IsMeta();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-02-28 14:58:42 +00:00
|
|
|
TouchEvent::CtrlKey()
|
2013-10-18 06:10:26 +00:00
|
|
|
{
|
|
|
|
return mEvent->AsTouchEvent()->IsControl();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-02-28 14:58:42 +00:00
|
|
|
TouchEvent::ShiftKey()
|
2013-10-18 06:10:26 +00:00
|
|
|
{
|
|
|
|
return mEvent->AsTouchEvent()->IsShift();
|
|
|
|
}
|
|
|
|
|
2014-02-28 14:58:42 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2015-08-12 11:39:31 +00:00
|
|
|
already_AddRefed<TouchEvent>
|
|
|
|
NS_NewDOMTouchEvent(EventTarget* aOwner,
|
2011-04-26 12:30:17 +00:00
|
|
|
nsPresContext* aPresContext,
|
2013-09-27 06:20:57 +00:00
|
|
|
WidgetTouchEvent* aEvent)
|
2011-04-26 12:30:17 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<TouchEvent> it = new TouchEvent(aOwner, aPresContext, aEvent);
|
2015-08-12 11:39:31 +00:00
|
|
|
return it.forget();
|
2011-04-26 12:30:17 +00:00
|
|
|
}
|