tor-browser

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

PointerEvent.h (4262B)


      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 *
      7 * Portions Copyright 2013 Microsoft Open Technologies, Inc. */
      8 
      9 #ifndef mozilla_dom_PointerEvent_h_
     10 #define mozilla_dom_PointerEvent_h_
     11 
     12 #include "mozilla/Maybe.h"
     13 #include "mozilla/dom/MouseEvent.h"
     14 #include "mozilla/dom/PointerEventBinding.h"
     15 
     16 class nsPresContext;
     17 
     18 namespace mozilla::dom {
     19 
     20 struct PointerEventInit;
     21 
     22 class PointerEvent : public MouseEvent {
     23 public:
     24  PointerEvent(EventTarget* aOwner, nsPresContext* aPresContext,
     25               WidgetPointerEvent* aEvent);
     26 
     27  NS_DECL_ISUPPORTS_INHERITED
     28  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(PointerEvent, MouseEvent)
     29 
     30  virtual JSObject* WrapObjectInternal(
     31      JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
     32 
     33  static already_AddRefed<PointerEvent> Constructor(
     34      const GlobalObject& aGlobal, const nsAString& aType,
     35      const PointerEventInit& aParam);
     36 
     37  static already_AddRefed<PointerEvent> Constructor(
     38      EventTarget* aOwner, const nsAString& aType,
     39      const PointerEventInit& aParam);
     40 
     41  PointerEvent* AsPointerEvent() final { return this; }
     42 
     43  int32_t PointerId(CallerType aCallerType = CallerType::System) const;
     44  double Width(CallerType aCallerType = CallerType::System) const;
     45  double Height(CallerType aCallerType = CallerType::System) const;
     46  float Pressure(CallerType aCallerType = CallerType::System) const;
     47  float TangentialPressure(CallerType aCallerType = CallerType::System) const;
     48  int32_t TiltX(CallerType aCallerType = CallerType::System);
     49  int32_t TiltY(CallerType aCallerType = CallerType::System);
     50  int32_t Twist(CallerType aCallerType = CallerType::System) const;
     51  double AltitudeAngle(CallerType aCallerType = CallerType::System);
     52  double AzimuthAngle(CallerType aCallerType = CallerType::System);
     53  bool IsPrimary() const;
     54  void GetPointerType(
     55      nsAString& aPointerType,
     56      mozilla::dom::CallerType aCallerType = CallerType::System) const;
     57  int32_t PersistentDeviceId(CallerType aCallerType = CallerType::System);
     58  static bool EnableGetCoalescedEvents(JSContext* aCx, JSObject* aGlobal);
     59  void GetCoalescedEvents(nsTArray<RefPtr<PointerEvent>>& aPointerEvents);
     60  void GetPredictedEvents(nsTArray<RefPtr<PointerEvent>>& aPointerEvents);
     61 
     62 protected:
     63  ~PointerEvent() = default;
     64 
     65 private:
     66  // This method returns the boolean to indicate whether spoofing pointer
     67  // event for fingerprinting resistance.
     68  bool ShouldResistFingerprinting(
     69      CallerType aCallerType = CallerType::System) const;
     70 
     71  uint16_t ResistantInputSource(
     72      CallerType aCallerType = CallerType::System) const;
     73 
     74  // When the instance is a trusted `pointermove` event but the widget event
     75  // does not have proper coalesced events (typically, the event is synthesized
     76  // for tests or instantiated in the main process), this fills mCoalescedEvents
     77  // with this instance.
     78  void EnsureFillingCoalescedEvents(WidgetPointerEvent& aWidgetEvent);
     79 
     80  nsTArray<RefPtr<PointerEvent>> mCoalescedEvents;
     81  nsTArray<RefPtr<PointerEvent>> mPredictedEvents;
     82 
     83  // This is used to store the pointerType assigned from constructor.
     84  Maybe<nsString> mPointerType;
     85 
     86  Maybe<int32_t> mTiltX;
     87  Maybe<int32_t> mTiltY;
     88  Maybe<double> mAltitudeAngle;
     89  Maybe<double> mAzimuthAngle;
     90 
     91  Maybe<int32_t> mPersistentDeviceId;
     92 
     93  // https://w3c.github.io/pointerevents/#dfn-coalesced-events
     94  // https://w3c.github.io/pointerevents/#dfn-predicted-events
     95  // The events in the coalesced/predicted events list of a trusted event will
     96  // have:
     97  // ... Empty coalesced events list and predicted events list of their own.
     98  bool mCoalescedOrPredictedEvent = false;
     99 };
    100 
    101 void ConvertPointerTypeToString(uint16_t aPointerTypeSrc,
    102                                nsAString& aPointerTypeDest);
    103 
    104 }  // namespace mozilla::dom
    105 
    106 already_AddRefed<mozilla::dom::PointerEvent> NS_NewDOMPointerEvent(
    107    mozilla::dom::EventTarget* aOwner, nsPresContext* aPresContext,
    108    mozilla::WidgetPointerEvent* aEvent);
    109 
    110 #endif  // mozilla_dom_PointerEvent_h_