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/. */
|
2014-02-28 18:58:42 +04:00
|
|
|
#ifndef mozilla_dom_TouchEvent_h_
|
|
|
|
#define mozilla_dom_TouchEvent_h_
|
2011-04-26 16:30:17 +04:00
|
|
|
|
2014-02-28 18:58:43 +04:00
|
|
|
#include "mozilla/dom/Touch.h"
|
|
|
|
#include "mozilla/dom/TouchEventBinding.h"
|
|
|
|
#include "mozilla/dom/UIEvent.h"
|
2012-06-19 06:30:09 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-10-18 10:10:26 +04:00
|
|
|
#include "mozilla/EventForwards.h"
|
2014-07-09 20:17:05 +04:00
|
|
|
#include "mozilla/TouchEvents.h"
|
2013-03-07 22:53:19 +04:00
|
|
|
#include "nsJSEnvironment.h"
|
2017-08-17 02:48:52 +03:00
|
|
|
#include "nsStringFwd.h"
|
2013-07-10 13:53:53 +04:00
|
|
|
#include "nsWrapperCache.h"
|
2011-04-26 16:30:17 +04:00
|
|
|
|
2014-02-28 18:58:42 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2013-07-10 13:53:09 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class TouchList final : public nsISupports, public nsWrapperCache {
|
2011-04-26 16:30:17 +04:00
|
|
|
public:
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2014-02-28 18:58:42 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(TouchList)
|
2011-12-17 04:24:11 +04:00
|
|
|
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit TouchList(nsISupports* aParent) : mParent(aParent) {
|
2013-07-10 13:53:53 +04:00
|
|
|
nsJSContext::LikelyShortLivingObjectCreated();
|
|
|
|
}
|
2014-07-09 20:17:05 +04:00
|
|
|
TouchList(nsISupports* aParent, const WidgetTouchEvent::TouchArray& aTouches)
|
2013-07-10 13:53:53 +04:00
|
|
|
: mParent(aParent), mPoints(aTouches) {
|
2013-03-07 22:53:19 +04:00
|
|
|
nsJSContext::LikelyShortLivingObjectCreated();
|
|
|
|
}
|
2012-05-03 21:01:49 +04:00
|
|
|
|
2012-08-02 21:41:42 +04:00
|
|
|
void Append(Touch* aPoint) { mPoints.AppendElement(aPoint); }
|
2012-05-03 21:01:49 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
2013-07-10 13:53:53 +04:00
|
|
|
|
|
|
|
nsISupports* GetParentObject() const { return mParent; }
|
|
|
|
|
2016-07-18 17:26:38 +03:00
|
|
|
static bool PrefEnabled(JSContext* aCx, JSObject* aGlobal);
|
2013-07-10 13:53:53 +04:00
|
|
|
|
|
|
|
uint32_t Length() const { return mPoints.Length(); }
|
|
|
|
Touch* Item(uint32_t aIndex) const { return mPoints.SafeElementAt(aIndex); }
|
|
|
|
Touch* IndexedGetter(uint32_t aIndex, bool& aFound) const {
|
|
|
|
aFound = aIndex < mPoints.Length();
|
|
|
|
if (!aFound) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return mPoints[aIndex];
|
2012-05-03 21:01:49 +04:00
|
|
|
}
|
|
|
|
|
2018-05-25 18:02:59 +03:00
|
|
|
void Clear() { mPoints.Clear(); }
|
|
|
|
|
2011-04-26 16:30:17 +04:00
|
|
|
protected:
|
2014-06-23 23:56:07 +04:00
|
|
|
~TouchList() {}
|
|
|
|
|
2013-07-10 13:53:53 +04:00
|
|
|
nsCOMPtr<nsISupports> mParent;
|
2014-07-09 20:17:05 +04:00
|
|
|
WidgetTouchEvent::TouchArray mPoints;
|
2011-04-26 16:30:17 +04:00
|
|
|
};
|
|
|
|
|
2014-02-28 18:58:43 +04:00
|
|
|
class TouchEvent : public UIEvent {
|
2011-04-26 16:30:17 +04:00
|
|
|
public:
|
2014-02-28 18:58:42 +04:00
|
|
|
TouchEvent(EventTarget* aOwner, nsPresContext* aPresContext,
|
|
|
|
WidgetTouchEvent* aEvent);
|
2011-04-26 16:30:17 +04:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2014-02-28 18:58:43 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TouchEvent, UIEvent)
|
2011-04-26 16:30:17 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObjectInternal(
|
|
|
|
JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override {
|
2018-06-26 00:20:54 +03:00
|
|
|
return TouchEvent_Binding::Wrap(aCx, this, aGivenProto);
|
2013-04-16 00:33:46 +04:00
|
|
|
}
|
|
|
|
|
2015-12-29 16:46:18 +03:00
|
|
|
already_AddRefed<TouchList> CopyTouches(
|
|
|
|
const Sequence<OwningNonNull<Touch>>& aTouches);
|
|
|
|
|
2014-02-28 18:58:42 +04:00
|
|
|
TouchList* Touches();
|
2018-05-25 18:02:59 +03:00
|
|
|
// TargetTouches() populates mTargetTouches from widget event's touch list.
|
2014-02-28 18:58:42 +04:00
|
|
|
TouchList* TargetTouches();
|
2018-05-25 18:02:59 +03:00
|
|
|
// GetExistingTargetTouches just returns the existing target touches list.
|
|
|
|
TouchList* GetExistingTargetTouches() { return mTargetTouches; }
|
2014-02-28 18:58:42 +04:00
|
|
|
TouchList* ChangedTouches();
|
2013-04-16 00:33:46 +04:00
|
|
|
|
2013-10-18 10:10:26 +04:00
|
|
|
bool AltKey();
|
|
|
|
bool MetaKey();
|
|
|
|
bool CtrlKey();
|
|
|
|
bool ShiftKey();
|
2013-04-16 00:33:46 +04:00
|
|
|
|
|
|
|
void InitTouchEvent(const nsAString& aType, bool aCanBubble, bool aCancelable,
|
2017-11-07 01:52:14 +03:00
|
|
|
nsGlobalWindowInner* aView, int32_t aDetail,
|
2013-04-16 00:33:46 +04:00
|
|
|
bool aCtrlKey, bool aAltKey, bool aShiftKey,
|
2014-02-28 18:58:42 +04:00
|
|
|
bool aMetaKey, TouchList* aTouches,
|
2015-11-13 03:09:42 +03:00
|
|
|
TouchList* aTargetTouches, TouchList* aChangedTouches);
|
2013-04-16 00:33:46 +04:00
|
|
|
|
2018-06-14 00:52:19 +03:00
|
|
|
static bool PlatformSupportsTouch();
|
2016-07-18 17:26:38 +03:00
|
|
|
static bool PrefEnabled(JSContext* aCx, JSObject* aGlobal);
|
|
|
|
static bool PrefEnabled(nsIDocShell* aDocShell);
|
2019-03-04 14:35:53 +03:00
|
|
|
static bool LegacyAPIEnabled(JSContext* aCx, JSObject* aGlobal);
|
|
|
|
static bool LegacyAPIEnabled(nsIDocShell* aDocShell, bool aCallerIsSystem);
|
2014-07-09 01:23:17 +04:00
|
|
|
|
2018-04-04 22:32:19 +03:00
|
|
|
static already_AddRefed<TouchEvent> Constructor(const GlobalObject& aGlobal,
|
|
|
|
const nsAString& aType,
|
2019-09-11 17:35:28 +03:00
|
|
|
const TouchEventInit& aParam);
|
2015-12-29 16:46:18 +03:00
|
|
|
|
2011-04-26 16:30:17 +04:00
|
|
|
protected:
|
2014-07-09 01:23:17 +04:00
|
|
|
~TouchEvent() {}
|
|
|
|
|
2018-05-25 18:02:59 +03:00
|
|
|
void AssignTouchesToWidgetEvent(TouchList* aList, bool aCheckDuplicates);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TouchList> mTouches;
|
|
|
|
RefPtr<TouchList> mTargetTouches;
|
|
|
|
RefPtr<TouchList> mChangedTouches;
|
2011-04-26 16:30:17 +04:00
|
|
|
};
|
|
|
|
|
2014-02-28 18:58:42 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2015-08-12 14:39:31 +03:00
|
|
|
already_AddRefed<mozilla::dom::TouchEvent> NS_NewDOMTouchEvent(
|
|
|
|
mozilla::dom::EventTarget* aOwner, nsPresContext* aPresContext,
|
|
|
|
mozilla::WidgetTouchEvent* aEvent);
|
|
|
|
|
2014-02-28 18:58:42 +04:00
|
|
|
#endif // mozilla_dom_TouchEvent_h_
|