tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

TouchEvent.h (4149B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 #ifndef mozilla_dom_TouchEvent_h_
      7 #define mozilla_dom_TouchEvent_h_
      8 
      9 #include "mozilla/EventForwards.h"
     10 #include "mozilla/TouchEvents.h"
     11 #include "mozilla/dom/Touch.h"
     12 #include "mozilla/dom/TouchEventBinding.h"
     13 #include "mozilla/dom/UIEvent.h"
     14 #include "nsJSEnvironment.h"
     15 #include "nsStringFwd.h"
     16 #include "nsWrapperCache.h"
     17 
     18 namespace mozilla::dom {
     19 
     20 class TouchList final : public nsISupports, public nsWrapperCache {
     21 public:
     22  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     23  NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(TouchList)
     24 
     25  explicit TouchList(nsISupports* aParent) : mParent(aParent) {
     26    nsJSContext::LikelyShortLivingObjectCreated();
     27  }
     28  TouchList(nsISupports* aParent, const WidgetTouchEvent::TouchArray& aTouches)
     29      : mParent(aParent), mPoints(aTouches.Clone()) {
     30    nsJSContext::LikelyShortLivingObjectCreated();
     31  }
     32 
     33  void Append(Touch* aPoint) { mPoints.AppendElement(aPoint); }
     34 
     35  virtual JSObject* WrapObject(JSContext* aCx,
     36                               JS::Handle<JSObject*> aGivenProto) override;
     37 
     38  nsISupports* GetParentObject() const { return mParent; }
     39 
     40  static bool PrefEnabled(JSContext* aCx, JSObject* aGlobal);
     41 
     42  uint32_t Length() const { return mPoints.Length(); }
     43  Touch* Item(uint32_t aIndex) const { return mPoints.SafeElementAt(aIndex); }
     44  Touch* IndexedGetter(uint32_t aIndex, bool& aFound) const {
     45    aFound = aIndex < mPoints.Length();
     46    if (!aFound) {
     47      return nullptr;
     48    }
     49    return mPoints[aIndex];
     50  }
     51 
     52  void Clear() { mPoints.Clear(); }
     53 
     54 protected:
     55  ~TouchList() = default;
     56 
     57  nsCOMPtr<nsISupports> mParent;
     58  WidgetTouchEvent::TouchArray mPoints;
     59 };
     60 
     61 class TouchEvent : public UIEvent {
     62 public:
     63  TouchEvent(EventTarget* aOwner, nsPresContext* aPresContext,
     64             WidgetTouchEvent* aEvent);
     65 
     66  NS_DECL_ISUPPORTS_INHERITED
     67  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TouchEvent, UIEvent)
     68 
     69  virtual JSObject* WrapObjectInternal(
     70      JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override {
     71    return TouchEvent_Binding::Wrap(aCx, this, aGivenProto);
     72  }
     73 
     74  already_AddRefed<TouchList> CopyTouches(
     75      const Sequence<OwningNonNull<Touch>>& aTouches);
     76 
     77  TouchList* Touches();
     78  // TargetTouches() populates mTargetTouches from widget event's touch list.
     79  TouchList* TargetTouches();
     80  // GetExistingTargetTouches just returns the existing target touches list.
     81  TouchList* GetExistingTargetTouches() { return mTargetTouches; }
     82  TouchList* ChangedTouches();
     83 
     84  bool AltKey();
     85  bool MetaKey();
     86  bool CtrlKey();
     87  bool ShiftKey();
     88 
     89  void InitTouchEvent(const nsAString& aType, bool aCanBubble, bool aCancelable,
     90                      nsGlobalWindowInner* aView, int32_t aDetail,
     91                      bool aCtrlKey, bool aAltKey, bool aShiftKey,
     92                      bool aMetaKey, TouchList* aTouches,
     93                      TouchList* aTargetTouches, TouchList* aChangedTouches);
     94 
     95  static bool PrefEnabled(JSContext* aCx, JSObject* aGlobal);
     96  static bool PrefEnabled(nsIDocShell* aDocShell);
     97  static bool LegacyAPIEnabled(JSContext* aCx, JSObject* aGlobal);
     98  static bool LegacyAPIEnabled(nsIDocShell* aDocShell, bool aCallerIsSystem);
     99 
    100  static already_AddRefed<TouchEvent> Constructor(const GlobalObject& aGlobal,
    101                                                  const nsAString& aType,
    102                                                  const TouchEventInit& aParam);
    103 
    104 protected:
    105  ~TouchEvent() = default;
    106 
    107  void AssignTouchesToWidgetEvent(TouchList* aList, bool aCheckDuplicates);
    108 
    109  RefPtr<TouchList> mTouches;
    110  RefPtr<TouchList> mTargetTouches;
    111  RefPtr<TouchList> mChangedTouches;
    112 };
    113 
    114 }  // namespace mozilla::dom
    115 
    116 already_AddRefed<mozilla::dom::TouchEvent> NS_NewDOMTouchEvent(
    117    mozilla::dom::EventTarget* aOwner, nsPresContext* aPresContext,
    118    mozilla::WidgetTouchEvent* aEvent);
    119 
    120 #endif  // mozilla_dom_TouchEvent_h_