summaryrefslogtreecommitdiffstats
path: root/dom/events/Touch.h
blob: 43c55348081e5ae1b0622036ca776163d385d1ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef mozilla_dom_Touch_h_
#define mozilla_dom_Touch_h_

#include "mozilla/Attributes.h"
#include "mozilla/EventForwards.h"
#include "mozilla/MouseEvents.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/TouchBinding.h"
#include "nsWrapperCache.h"
#include "Units.h"

class nsPresContext;

namespace mozilla::dom {

class EventTarget;

class Touch final : public nsISupports,
                    public nsWrapperCache,
                    public WidgetPointerHelper {
 public:
  static bool PrefEnabled(JSContext* aCx, JSObject* aGlobal);

  static already_AddRefed<Touch> Constructor(const GlobalObject& aGlobal,
                                             const TouchInit& aParam);

  Touch(EventTarget* aTarget, int32_t aIdentifier, int32_t aPageX,
        int32_t aPageY, int32_t aScreenX, int32_t aScreenY, int32_t aClientX,
        int32_t aClientY, int32_t aRadiusX, int32_t aRadiusY,
        float aRotationAngle, float aForce);
  Touch(int32_t aIdentifier, LayoutDeviceIntPoint aPoint,
        LayoutDeviceIntPoint aRadius, float aRotationAngle, float aForce);
  Touch(int32_t aIdentifier, LayoutDeviceIntPoint aPoint,
        LayoutDeviceIntPoint aRadius, float aRotationAngle, float aForce,
        int32_t aTiltX, int32_t aTiltY, int32_t aTwist);
  Touch(const Touch& aOther);

  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
  NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(Touch)

  void InitializePoints(nsPresContext* aPresContext, WidgetEvent* aEvent);

  // Note, this sets both mOriginalTarget and mTarget.
  void SetTouchTarget(EventTarget* aTarget);

  bool Equals(Touch* aTouch) const;

  // Update this touch's touch area to be the same as aTouch
  void SetSameAs(const Touch* aTouch);

  virtual JSObject* WrapObject(JSContext* aCx,
                               JS::Handle<JSObject*> aGivenProto) override;

  nsIGlobalObject* GetParentObject() const;

  // WebIDL
  int32_t Identifier() const { return mIdentifier; }
  EventTarget* GetTarget() const;
  int32_t ScreenX(CallerType aCallerType) const;
  int32_t ScreenY(CallerType aCallerType) const;
  int32_t ClientX() const { return mClientPoint.x; }
  int32_t ClientY() const { return mClientPoint.y; }
  int32_t PageX() const { return mPagePoint.x; }
  int32_t PageY() const { return mPagePoint.y; }
  int32_t RadiusX(CallerType aCallerType) const;
  int32_t RadiusY(CallerType aCallerType) const;
  float RotationAngle(CallerType aCallerType) const;
  float Force(CallerType aCallerType) const;

  EventTarget* GetOriginalTarget() const;

  nsCOMPtr<EventTarget> mOriginalTarget;
  nsCOMPtr<EventTarget> mTarget;
  LayoutDeviceIntPoint mRefPoint;
  bool mChanged;

  // Is this touch instance being suppressed to dispatch touch event to content.
  // We can't remove touch instance from WidgetTouchEvent::mTouches because we
  // still need it when dispatching pointer events.
  bool mIsTouchEventSuppressed;

  uint32_t mMessage;
  int32_t mIdentifier;
  CSSIntPoint mPagePoint;
  CSSIntPoint mClientPoint;
  CSSIntPoint mScreenPoint;
  LayoutDeviceIntPoint mRadius;
  float mRotationAngle;
  float mForce;

 protected:
  ~Touch();

  bool mPointsInitialized;
};

}  // namespace mozilla::dom

#endif  // mozilla_dom_Touch_h_