michael@0: /* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: #ifndef mozilla_dom_TouchEvent_h_ michael@0: #define mozilla_dom_TouchEvent_h_ michael@0: michael@0: #include "mozilla/dom/Touch.h" michael@0: #include "mozilla/dom/TouchEventBinding.h" michael@0: #include "mozilla/dom/UIEvent.h" michael@0: #include "mozilla/Attributes.h" michael@0: #include "mozilla/EventForwards.h" michael@0: #include "nsJSEnvironment.h" michael@0: #include "nsTArray.h" michael@0: #include "nsWrapperCache.h" michael@0: michael@0: class nsAString; michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: class TouchList MOZ_FINAL : public nsISupports michael@0: , public nsWrapperCache michael@0: { michael@0: public: michael@0: NS_DECL_CYCLE_COLLECTING_ISUPPORTS michael@0: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(TouchList) michael@0: michael@0: TouchList(nsISupports* aParent) michael@0: : mParent(aParent) michael@0: { michael@0: SetIsDOMBinding(); michael@0: nsJSContext::LikelyShortLivingObjectCreated(); michael@0: } michael@0: TouchList(nsISupports* aParent, michael@0: const nsTArray >& aTouches) michael@0: : mParent(aParent) michael@0: , mPoints(aTouches) michael@0: { michael@0: SetIsDOMBinding(); michael@0: nsJSContext::LikelyShortLivingObjectCreated(); michael@0: } michael@0: michael@0: void Append(Touch* aPoint) michael@0: { michael@0: mPoints.AppendElement(aPoint); michael@0: } michael@0: michael@0: virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; michael@0: michael@0: nsISupports* GetParentObject() const michael@0: { michael@0: return mParent; michael@0: } michael@0: michael@0: static bool PrefEnabled(JSContext* aCx = nullptr, michael@0: JSObject* aGlobal = nullptr); michael@0: michael@0: uint32_t Length() const michael@0: { michael@0: return mPoints.Length(); michael@0: } michael@0: Touch* Item(uint32_t aIndex) const michael@0: { michael@0: return mPoints.SafeElementAt(aIndex); michael@0: } michael@0: Touch* IndexedGetter(uint32_t aIndex, bool& aFound) const michael@0: { michael@0: aFound = aIndex < mPoints.Length(); michael@0: if (!aFound) { michael@0: return nullptr; michael@0: } michael@0: return mPoints[aIndex]; michael@0: } michael@0: Touch* IdentifiedTouch(int32_t aIdentifier) const; michael@0: michael@0: protected: michael@0: nsCOMPtr mParent; michael@0: nsTArray > mPoints; michael@0: }; michael@0: michael@0: class TouchEvent : public UIEvent michael@0: { michael@0: public: michael@0: TouchEvent(EventTarget* aOwner, michael@0: nsPresContext* aPresContext, michael@0: WidgetTouchEvent* aEvent); michael@0: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TouchEvent, UIEvent) michael@0: michael@0: virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE michael@0: { michael@0: return TouchEventBinding::Wrap(aCx, this); michael@0: } michael@0: michael@0: TouchList* Touches(); michael@0: TouchList* TargetTouches(); michael@0: TouchList* ChangedTouches(); michael@0: michael@0: bool AltKey(); michael@0: bool MetaKey(); michael@0: bool CtrlKey(); michael@0: bool ShiftKey(); michael@0: michael@0: void InitTouchEvent(const nsAString& aType, michael@0: bool aCanBubble, michael@0: bool aCancelable, michael@0: nsIDOMWindow* aView, michael@0: int32_t aDetail, michael@0: bool aCtrlKey, michael@0: bool aAltKey, michael@0: bool aShiftKey, michael@0: bool aMetaKey, michael@0: TouchList* aTouches, michael@0: TouchList* aTargetTouches, michael@0: TouchList* aChangedTouches, michael@0: ErrorResult& aRv); michael@0: michael@0: static bool PrefEnabled(JSContext* aCx = nullptr, michael@0: JSObject* aGlobal = nullptr); michael@0: protected: michael@0: nsRefPtr mTouches; michael@0: nsRefPtr mTargetTouches; michael@0: nsRefPtr mChangedTouches; michael@0: }; michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: #endif // mozilla_dom_TouchEvent_h_