Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | #ifndef mozilla_dom_TouchEvent_h_ |
michael@0 | 6 | #define mozilla_dom_TouchEvent_h_ |
michael@0 | 7 | |
michael@0 | 8 | #include "mozilla/dom/Touch.h" |
michael@0 | 9 | #include "mozilla/dom/TouchEventBinding.h" |
michael@0 | 10 | #include "mozilla/dom/UIEvent.h" |
michael@0 | 11 | #include "mozilla/Attributes.h" |
michael@0 | 12 | #include "mozilla/EventForwards.h" |
michael@0 | 13 | #include "nsJSEnvironment.h" |
michael@0 | 14 | #include "nsTArray.h" |
michael@0 | 15 | #include "nsWrapperCache.h" |
michael@0 | 16 | |
michael@0 | 17 | class nsAString; |
michael@0 | 18 | |
michael@0 | 19 | namespace mozilla { |
michael@0 | 20 | namespace dom { |
michael@0 | 21 | |
michael@0 | 22 | class TouchList MOZ_FINAL : public nsISupports |
michael@0 | 23 | , public nsWrapperCache |
michael@0 | 24 | { |
michael@0 | 25 | public: |
michael@0 | 26 | NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
michael@0 | 27 | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(TouchList) |
michael@0 | 28 | |
michael@0 | 29 | TouchList(nsISupports* aParent) |
michael@0 | 30 | : mParent(aParent) |
michael@0 | 31 | { |
michael@0 | 32 | SetIsDOMBinding(); |
michael@0 | 33 | nsJSContext::LikelyShortLivingObjectCreated(); |
michael@0 | 34 | } |
michael@0 | 35 | TouchList(nsISupports* aParent, |
michael@0 | 36 | const nsTArray<nsRefPtr<Touch> >& aTouches) |
michael@0 | 37 | : mParent(aParent) |
michael@0 | 38 | , mPoints(aTouches) |
michael@0 | 39 | { |
michael@0 | 40 | SetIsDOMBinding(); |
michael@0 | 41 | nsJSContext::LikelyShortLivingObjectCreated(); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | void Append(Touch* aPoint) |
michael@0 | 45 | { |
michael@0 | 46 | mPoints.AppendElement(aPoint); |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; |
michael@0 | 50 | |
michael@0 | 51 | nsISupports* GetParentObject() const |
michael@0 | 52 | { |
michael@0 | 53 | return mParent; |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | static bool PrefEnabled(JSContext* aCx = nullptr, |
michael@0 | 57 | JSObject* aGlobal = nullptr); |
michael@0 | 58 | |
michael@0 | 59 | uint32_t Length() const |
michael@0 | 60 | { |
michael@0 | 61 | return mPoints.Length(); |
michael@0 | 62 | } |
michael@0 | 63 | Touch* Item(uint32_t aIndex) const |
michael@0 | 64 | { |
michael@0 | 65 | return mPoints.SafeElementAt(aIndex); |
michael@0 | 66 | } |
michael@0 | 67 | Touch* IndexedGetter(uint32_t aIndex, bool& aFound) const |
michael@0 | 68 | { |
michael@0 | 69 | aFound = aIndex < mPoints.Length(); |
michael@0 | 70 | if (!aFound) { |
michael@0 | 71 | return nullptr; |
michael@0 | 72 | } |
michael@0 | 73 | return mPoints[aIndex]; |
michael@0 | 74 | } |
michael@0 | 75 | Touch* IdentifiedTouch(int32_t aIdentifier) const; |
michael@0 | 76 | |
michael@0 | 77 | protected: |
michael@0 | 78 | nsCOMPtr<nsISupports> mParent; |
michael@0 | 79 | nsTArray<nsRefPtr<Touch> > mPoints; |
michael@0 | 80 | }; |
michael@0 | 81 | |
michael@0 | 82 | class TouchEvent : public UIEvent |
michael@0 | 83 | { |
michael@0 | 84 | public: |
michael@0 | 85 | TouchEvent(EventTarget* aOwner, |
michael@0 | 86 | nsPresContext* aPresContext, |
michael@0 | 87 | WidgetTouchEvent* aEvent); |
michael@0 | 88 | |
michael@0 | 89 | NS_DECL_ISUPPORTS_INHERITED |
michael@0 | 90 | NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TouchEvent, UIEvent) |
michael@0 | 91 | |
michael@0 | 92 | virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE |
michael@0 | 93 | { |
michael@0 | 94 | return TouchEventBinding::Wrap(aCx, this); |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | TouchList* Touches(); |
michael@0 | 98 | TouchList* TargetTouches(); |
michael@0 | 99 | TouchList* ChangedTouches(); |
michael@0 | 100 | |
michael@0 | 101 | bool AltKey(); |
michael@0 | 102 | bool MetaKey(); |
michael@0 | 103 | bool CtrlKey(); |
michael@0 | 104 | bool ShiftKey(); |
michael@0 | 105 | |
michael@0 | 106 | void InitTouchEvent(const nsAString& aType, |
michael@0 | 107 | bool aCanBubble, |
michael@0 | 108 | bool aCancelable, |
michael@0 | 109 | nsIDOMWindow* aView, |
michael@0 | 110 | int32_t aDetail, |
michael@0 | 111 | bool aCtrlKey, |
michael@0 | 112 | bool aAltKey, |
michael@0 | 113 | bool aShiftKey, |
michael@0 | 114 | bool aMetaKey, |
michael@0 | 115 | TouchList* aTouches, |
michael@0 | 116 | TouchList* aTargetTouches, |
michael@0 | 117 | TouchList* aChangedTouches, |
michael@0 | 118 | ErrorResult& aRv); |
michael@0 | 119 | |
michael@0 | 120 | static bool PrefEnabled(JSContext* aCx = nullptr, |
michael@0 | 121 | JSObject* aGlobal = nullptr); |
michael@0 | 122 | protected: |
michael@0 | 123 | nsRefPtr<TouchList> mTouches; |
michael@0 | 124 | nsRefPtr<TouchList> mTargetTouches; |
michael@0 | 125 | nsRefPtr<TouchList> mChangedTouches; |
michael@0 | 126 | }; |
michael@0 | 127 | |
michael@0 | 128 | } // namespace dom |
michael@0 | 129 | } // namespace mozilla |
michael@0 | 130 | |
michael@0 | 131 | #endif // mozilla_dom_TouchEvent_h_ |