2013-05-22 03:23:53 +04: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/. */
|
2011-04-26 16:30:17 +04:00
|
|
|
|
2014-02-28 18:58:42 +04:00
|
|
|
#include "mozilla/dom/TouchEvent.h"
|
2013-04-05 12:49:00 +04:00
|
|
|
#include "mozilla/dom/Touch.h"
|
2013-07-10 13:53:53 +04:00
|
|
|
#include "mozilla/dom/TouchListBinding.h"
|
2014-02-28 18:58:42 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2013-09-25 15:21:16 +04:00
|
|
|
#include "mozilla/TouchEvents.h"
|
2014-02-28 18:58:42 +04:00
|
|
|
#include "nsContentUtils.h"
|
2015-05-08 04:29:00 +03:00
|
|
|
#include "mozilla/WidgetUtils.h"
|
2011-05-25 10:31:59 +04:00
|
|
|
|
2014-02-28 18:58:42 +04:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
namespace dom {
|
2011-04-26 16:30:17 +04:00
|
|
|
|
2014-02-28 18:58:42 +04:00
|
|
|
/******************************************************************************
|
|
|
|
* TouchList
|
|
|
|
*****************************************************************************/
|
2011-04-26 16:30:17 +04:00
|
|
|
|
2014-02-28 18:58:42 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TouchList)
|
2013-07-10 13:53:53 +04:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2011-04-26 16:30:17 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2014-04-29 12:57:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(TouchList, mParent, mPoints)
|
2011-04-26 16:30:17 +04:00
|
|
|
|
2014-02-28 18:58:42 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(TouchList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(TouchList)
|
2011-04-26 16:30:17 +04:00
|
|
|
|
2014-02-28 18:58:42 +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
|
|
|
TouchList::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-07-10 13:53:53 +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 TouchListBinding::Wrap(aCx, this, aGivenProto);
|
2013-07-10 13:53:53 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 18:58:42 +04:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
TouchList::PrefEnabled(JSContext* aCx, JSObject* aGlobal)
|
2013-07-10 13:53:53 +04:00
|
|
|
{
|
2014-02-28 18:58:42 +04:00
|
|
|
return TouchEvent::PrefEnabled(aCx, aGlobal);
|
2013-07-10 13:53:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Touch*
|
2014-02-28 18:58:42 +04:00
|
|
|
TouchList::IdentifiedTouch(int32_t aIdentifier) const
|
2013-07-10 13:53:53 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < mPoints.Length(); ++i) {
|
2013-07-10 13:53:53 +04:00
|
|
|
Touch* point = mPoints[i];
|
2013-07-10 13:53:09 +04:00
|
|
|
if (point && point->Identifier() == aIdentifier) {
|
2013-07-10 13:53:53 +04:00
|
|
|
return point;
|
2011-04-26 16:30:17 +04:00
|
|
|
}
|
|
|
|
}
|
2013-07-10 13:53:53 +04:00
|
|
|
return nullptr;
|
2011-04-26 16:30:17 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 18:58:42 +04:00
|
|
|
/******************************************************************************
|
|
|
|
* TouchEvent
|
|
|
|
*****************************************************************************/
|
2011-04-26 16:30:17 +04:00
|
|
|
|
2014-02-28 18:58:42 +04:00
|
|
|
TouchEvent::TouchEvent(EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetTouchEvent* aEvent)
|
2014-02-28 18:58:43 +04:00
|
|
|
: UIEvent(aOwner, aPresContext,
|
2015-08-26 15:56:59 +03:00
|
|
|
aEvent ? aEvent :
|
2015-08-29 02:58:26 +03:00
|
|
|
new WidgetTouchEvent(false, eVoidEvent, nullptr))
|
2011-04-26 16:30:17 +04:00
|
|
|
{
|
|
|
|
if (aEvent) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mEventIsInternal = false;
|
2011-12-17 04:24:11 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < aEvent->touches.Length(); ++i) {
|
2013-08-02 11:06:35 +04:00
|
|
|
Touch* touch = aEvent->touches[i];
|
|
|
|
touch->InitializePoints(mPresContext, aEvent);
|
2011-12-17 04:24:11 +04:00
|
|
|
}
|
2011-04-26 16:30:17 +04:00
|
|
|
} else {
|
2011-10-17 18:59:28 +04:00
|
|
|
mEventIsInternal = true;
|
2011-04-26 16:30:17 +04:00
|
|
|
mEvent->time = PR_Now();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-25 20:49:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(TouchEvent, UIEvent,
|
|
|
|
mTouches,
|
|
|
|
mTargetTouches,
|
|
|
|
mChangedTouches)
|
2011-04-26 16:30:17 +04:00
|
|
|
|
2014-02-28 18:58:42 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(TouchEvent)
|
2014-02-28 18:58:43 +04:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(UIEvent)
|
2011-04-26 16:30:17 +04:00
|
|
|
|
2014-02-28 18:58:43 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(TouchEvent, UIEvent)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(TouchEvent, UIEvent)
|
2011-04-26 16:30:17 +04:00
|
|
|
|
2013-08-05 08:51:21 +04:00
|
|
|
void
|
2014-02-28 18:58:42 +04:00
|
|
|
TouchEvent::InitTouchEvent(const nsAString& aType,
|
|
|
|
bool aCanBubble,
|
|
|
|
bool aCancelable,
|
|
|
|
nsIDOMWindow* aView,
|
|
|
|
int32_t aDetail,
|
|
|
|
bool aCtrlKey,
|
|
|
|
bool aAltKey,
|
|
|
|
bool aShiftKey,
|
|
|
|
bool aMetaKey,
|
|
|
|
TouchList* aTouches,
|
|
|
|
TouchList* aTargetTouches,
|
2015-11-13 03:09:42 +03:00
|
|
|
TouchList* aChangedTouches)
|
2013-08-05 08:51:21 +04:00
|
|
|
{
|
2015-11-13 03:09:42 +03:00
|
|
|
UIEvent::InitUIEvent(aType, aCanBubble, aCancelable, aView, aDetail);
|
2013-10-18 10:10:26 +04:00
|
|
|
mEvent->AsInputEvent()->InitBasicModifiers(aCtrlKey, aAltKey,
|
|
|
|
aShiftKey, aMetaKey);
|
2013-08-05 08:51:21 +04:00
|
|
|
mTouches = aTouches;
|
|
|
|
mTargetTouches = aTargetTouches;
|
|
|
|
mChangedTouches = aChangedTouches;
|
2013-04-26 10:48:00 +04:00
|
|
|
}
|
2011-12-17 04:24:11 +04:00
|
|
|
|
2014-02-28 18:58:42 +04:00
|
|
|
TouchList*
|
|
|
|
TouchEvent::Touches()
|
2013-04-26 10:48:00 +04:00
|
|
|
{
|
|
|
|
if (!mTouches) {
|
2013-10-18 10:10:23 +04:00
|
|
|
WidgetTouchEvent* touchEvent = mEvent->AsTouchEvent();
|
2015-09-14 18:14:35 +03:00
|
|
|
if (mEvent->mMessage == eTouchEnd || mEvent->mMessage == eTouchCancel) {
|
2013-04-26 10:48:00 +04:00
|
|
|
// for touchend events, remove any changed touches from the touches array
|
2014-07-09 20:17:05 +04:00
|
|
|
WidgetTouchEvent::AutoTouchArray unchangedTouches;
|
2014-07-09 00:48:19 +04:00
|
|
|
const WidgetTouchEvent::TouchArray& touches = touchEvent->touches;
|
2013-04-26 10:48:00 +04:00
|
|
|
for (uint32_t i = 0; i < touches.Length(); ++i) {
|
|
|
|
if (!touches[i]->mChanged) {
|
|
|
|
unchangedTouches.AppendElement(touches[i]);
|
|
|
|
}
|
2011-12-17 04:24:11 +04:00
|
|
|
}
|
2014-02-28 18:58:42 +04:00
|
|
|
mTouches = new TouchList(ToSupports(this), unchangedTouches);
|
2013-04-26 10:48:00 +04:00
|
|
|
} else {
|
2014-02-28 18:58:42 +04:00
|
|
|
mTouches = new TouchList(ToSupports(this), touchEvent->touches);
|
2011-12-17 04:24:11 +04:00
|
|
|
}
|
|
|
|
}
|
2013-04-26 10:48:00 +04:00
|
|
|
return mTouches;
|
2011-04-26 16:30:17 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 18:58:42 +04:00
|
|
|
TouchList*
|
|
|
|
TouchEvent::TargetTouches()
|
2013-04-26 10:48:00 +04:00
|
|
|
{
|
|
|
|
if (!mTargetTouches) {
|
2014-07-09 20:17:05 +04:00
|
|
|
WidgetTouchEvent::AutoTouchArray targetTouches;
|
2013-10-18 10:10:23 +04:00
|
|
|
WidgetTouchEvent* touchEvent = mEvent->AsTouchEvent();
|
2014-07-09 00:48:19 +04:00
|
|
|
const WidgetTouchEvent::TouchArray& touches = touchEvent->touches;
|
2013-04-26 10:48:00 +04: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 18:14:35 +03:00
|
|
|
if ((mEvent->mMessage != eTouchEnd && mEvent->mMessage != eTouchCancel) ||
|
|
|
|
!touches[i]->mChanged) {
|
2013-07-10 13:53:09 +04:00
|
|
|
if (touches[i]->mTarget == mEvent->originalTarget) {
|
2013-04-26 10:48:00 +04:00
|
|
|
targetTouches.AppendElement(touches[i]);
|
|
|
|
}
|
2011-12-17 04:24:11 +04:00
|
|
|
}
|
|
|
|
}
|
2014-02-28 18:58:42 +04:00
|
|
|
mTargetTouches = new TouchList(ToSupports(this), targetTouches);
|
2011-12-17 04:24:11 +04:00
|
|
|
}
|
2013-04-26 10:48:00 +04:00
|
|
|
return mTargetTouches;
|
2011-04-26 16:30:17 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 18:58:42 +04:00
|
|
|
TouchList*
|
|
|
|
TouchEvent::ChangedTouches()
|
2013-04-26 10:48:00 +04:00
|
|
|
{
|
|
|
|
if (!mChangedTouches) {
|
2014-07-09 20:17:05 +04:00
|
|
|
WidgetTouchEvent::AutoTouchArray changedTouches;
|
2013-10-18 10:10:23 +04:00
|
|
|
WidgetTouchEvent* touchEvent = mEvent->AsTouchEvent();
|
2014-07-09 00:48:19 +04:00
|
|
|
const WidgetTouchEvent::TouchArray& touches = touchEvent->touches;
|
2013-04-26 10:48:00 +04:00
|
|
|
for (uint32_t i = 0; i < touches.Length(); ++i) {
|
|
|
|
if (touches[i]->mChanged) {
|
|
|
|
changedTouches.AppendElement(touches[i]);
|
|
|
|
}
|
2011-12-17 04:24:11 +04:00
|
|
|
}
|
2014-02-28 18:58:42 +04:00
|
|
|
mChangedTouches = new TouchList(ToSupports(this), changedTouches);
|
2011-12-17 04:24:11 +04:00
|
|
|
}
|
2013-04-26 10:48:00 +04:00
|
|
|
return mChangedTouches;
|
2011-04-26 16:30:17 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 18:58:42 +04:00
|
|
|
// static
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2014-02-28 18:58:42 +04:00
|
|
|
TouchEvent::PrefEnabled(JSContext* aCx, JSObject* aGlobal)
|
2011-04-26 16:30:17 +04:00
|
|
|
{
|
2013-09-03 11:15:51 +04:00
|
|
|
bool prefValue = false;
|
|
|
|
int32_t flag = 0;
|
2015-05-08 04:29:00 +03:00
|
|
|
if (NS_SUCCEEDED(Preferences::GetInt("dom.w3c_touch_events.enabled", &flag))) {
|
2013-09-03 11:15:51 +04:00
|
|
|
if (flag == 2) {
|
2015-10-26 23:06:27 +03:00
|
|
|
#if defined(MOZ_B2G) || defined(MOZ_WIDGET_ANDROID)
|
|
|
|
// Touch support is always enabled on B2G and android.
|
|
|
|
prefValue = true;
|
|
|
|
#elif defined(XP_WIN) || MOZ_WIDGET_GTK == 3
|
2013-09-03 11:15:51 +04:00
|
|
|
static bool sDidCheckTouchDeviceSupport = false;
|
|
|
|
static bool sIsTouchDeviceSupportPresent = false;
|
2015-04-29 23:29:34 +03:00
|
|
|
// On Windows and GTK3 we auto-detect based on device support.
|
2013-09-03 11:15:51 +04:00
|
|
|
if (!sDidCheckTouchDeviceSupport) {
|
|
|
|
sDidCheckTouchDeviceSupport = true;
|
2015-05-08 04:29:00 +03:00
|
|
|
sIsTouchDeviceSupportPresent = WidgetUtils::IsTouchDeviceSupportPresent();
|
2013-09-03 11:15:51 +04:00
|
|
|
}
|
|
|
|
prefValue = sIsTouchDeviceSupportPresent;
|
2012-10-25 18:57:51 +04:00
|
|
|
#else
|
2013-09-03 11:15:51 +04:00
|
|
|
NS_WARNING("dom.w3c_touch_events.enabled=2 not implemented!");
|
|
|
|
prefValue = false;
|
2012-10-25 18:57:51 +04:00
|
|
|
#endif
|
2013-09-03 11:15:51 +04:00
|
|
|
} else {
|
|
|
|
prefValue = !!flag;
|
2011-04-26 16:30:17 +04:00
|
|
|
}
|
|
|
|
}
|
2013-09-03 11:15:51 +04:00
|
|
|
if (prefValue) {
|
|
|
|
nsContentUtils::InitializeTouchEventTable();
|
|
|
|
}
|
|
|
|
return prefValue;
|
2011-04-26 16:30:17 +04:00
|
|
|
}
|
|
|
|
|
2013-10-18 10:10:26 +04:00
|
|
|
bool
|
2014-02-28 18:58:42 +04:00
|
|
|
TouchEvent::AltKey()
|
2013-10-18 10:10:26 +04:00
|
|
|
{
|
|
|
|
return mEvent->AsTouchEvent()->IsAlt();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-02-28 18:58:42 +04:00
|
|
|
TouchEvent::MetaKey()
|
2013-10-18 10:10:26 +04:00
|
|
|
{
|
|
|
|
return mEvent->AsTouchEvent()->IsMeta();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-02-28 18:58:42 +04:00
|
|
|
TouchEvent::CtrlKey()
|
2013-10-18 10:10:26 +04:00
|
|
|
{
|
|
|
|
return mEvent->AsTouchEvent()->IsControl();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-02-28 18:58:42 +04:00
|
|
|
TouchEvent::ShiftKey()
|
2013-10-18 10:10:26 +04:00
|
|
|
{
|
|
|
|
return mEvent->AsTouchEvent()->IsShift();
|
|
|
|
}
|
|
|
|
|
2014-02-28 18:58:42 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2015-08-12 14:39:31 +03:00
|
|
|
already_AddRefed<TouchEvent>
|
|
|
|
NS_NewDOMTouchEvent(EventTarget* aOwner,
|
2011-04-26 16:30:17 +04:00
|
|
|
nsPresContext* aPresContext,
|
2013-09-27 10:20:57 +04:00
|
|
|
WidgetTouchEvent* aEvent)
|
2011-04-26 16:30:17 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TouchEvent> it = new TouchEvent(aOwner, aPresContext, aEvent);
|
2015-08-12 14:39:31 +03:00
|
|
|
return it.forget();
|
2011-04-26 16:30:17 +04:00
|
|
|
}
|