dom/events/TouchEvent.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial