1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/events/TouchEvent.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,131 @@ 1.4 +/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 +#ifndef mozilla_dom_TouchEvent_h_ 1.9 +#define mozilla_dom_TouchEvent_h_ 1.10 + 1.11 +#include "mozilla/dom/Touch.h" 1.12 +#include "mozilla/dom/TouchEventBinding.h" 1.13 +#include "mozilla/dom/UIEvent.h" 1.14 +#include "mozilla/Attributes.h" 1.15 +#include "mozilla/EventForwards.h" 1.16 +#include "nsJSEnvironment.h" 1.17 +#include "nsTArray.h" 1.18 +#include "nsWrapperCache.h" 1.19 + 1.20 +class nsAString; 1.21 + 1.22 +namespace mozilla { 1.23 +namespace dom { 1.24 + 1.25 +class TouchList MOZ_FINAL : public nsISupports 1.26 + , public nsWrapperCache 1.27 +{ 1.28 +public: 1.29 + NS_DECL_CYCLE_COLLECTING_ISUPPORTS 1.30 + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(TouchList) 1.31 + 1.32 + TouchList(nsISupports* aParent) 1.33 + : mParent(aParent) 1.34 + { 1.35 + SetIsDOMBinding(); 1.36 + nsJSContext::LikelyShortLivingObjectCreated(); 1.37 + } 1.38 + TouchList(nsISupports* aParent, 1.39 + const nsTArray<nsRefPtr<Touch> >& aTouches) 1.40 + : mParent(aParent) 1.41 + , mPoints(aTouches) 1.42 + { 1.43 + SetIsDOMBinding(); 1.44 + nsJSContext::LikelyShortLivingObjectCreated(); 1.45 + } 1.46 + 1.47 + void Append(Touch* aPoint) 1.48 + { 1.49 + mPoints.AppendElement(aPoint); 1.50 + } 1.51 + 1.52 + virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; 1.53 + 1.54 + nsISupports* GetParentObject() const 1.55 + { 1.56 + return mParent; 1.57 + } 1.58 + 1.59 + static bool PrefEnabled(JSContext* aCx = nullptr, 1.60 + JSObject* aGlobal = nullptr); 1.61 + 1.62 + uint32_t Length() const 1.63 + { 1.64 + return mPoints.Length(); 1.65 + } 1.66 + Touch* Item(uint32_t aIndex) const 1.67 + { 1.68 + return mPoints.SafeElementAt(aIndex); 1.69 + } 1.70 + Touch* IndexedGetter(uint32_t aIndex, bool& aFound) const 1.71 + { 1.72 + aFound = aIndex < mPoints.Length(); 1.73 + if (!aFound) { 1.74 + return nullptr; 1.75 + } 1.76 + return mPoints[aIndex]; 1.77 + } 1.78 + Touch* IdentifiedTouch(int32_t aIdentifier) const; 1.79 + 1.80 +protected: 1.81 + nsCOMPtr<nsISupports> mParent; 1.82 + nsTArray<nsRefPtr<Touch> > mPoints; 1.83 +}; 1.84 + 1.85 +class TouchEvent : public UIEvent 1.86 +{ 1.87 +public: 1.88 + TouchEvent(EventTarget* aOwner, 1.89 + nsPresContext* aPresContext, 1.90 + WidgetTouchEvent* aEvent); 1.91 + 1.92 + NS_DECL_ISUPPORTS_INHERITED 1.93 + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TouchEvent, UIEvent) 1.94 + 1.95 + virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE 1.96 + { 1.97 + return TouchEventBinding::Wrap(aCx, this); 1.98 + } 1.99 + 1.100 + TouchList* Touches(); 1.101 + TouchList* TargetTouches(); 1.102 + TouchList* ChangedTouches(); 1.103 + 1.104 + bool AltKey(); 1.105 + bool MetaKey(); 1.106 + bool CtrlKey(); 1.107 + bool ShiftKey(); 1.108 + 1.109 + void InitTouchEvent(const nsAString& aType, 1.110 + bool aCanBubble, 1.111 + bool aCancelable, 1.112 + nsIDOMWindow* aView, 1.113 + int32_t aDetail, 1.114 + bool aCtrlKey, 1.115 + bool aAltKey, 1.116 + bool aShiftKey, 1.117 + bool aMetaKey, 1.118 + TouchList* aTouches, 1.119 + TouchList* aTargetTouches, 1.120 + TouchList* aChangedTouches, 1.121 + ErrorResult& aRv); 1.122 + 1.123 + static bool PrefEnabled(JSContext* aCx = nullptr, 1.124 + JSObject* aGlobal = nullptr); 1.125 +protected: 1.126 + nsRefPtr<TouchList> mTouches; 1.127 + nsRefPtr<TouchList> mTargetTouches; 1.128 + nsRefPtr<TouchList> mChangedTouches; 1.129 +}; 1.130 + 1.131 +} // namespace dom 1.132 +} // namespace mozilla 1.133 + 1.134 +#endif // mozilla_dom_TouchEvent_h_