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 #ifndef mozilla_dom_UIEvent_h_
8 #define mozilla_dom_UIEvent_h_
9 
10 #include "mozilla/Attributes.h"
11 #include "mozilla/dom/Event.h"
12 #include "mozilla/dom/UIEventBinding.h"
13 #include "nsDeviceContext.h"
14 #include "nsIDOMUIEvent.h"
15 #include "nsLayoutUtils.h"
16 #include "nsPresContext.h"
17 
18 class nsINode;
19 
20 namespace mozilla {
21 namespace dom {
22 
23 class UIEvent : public Event, public nsIDOMUIEvent {
24  public:
25   UIEvent(EventTarget* aOwner, nsPresContext* aPresContext,
26           WidgetGUIEvent* aEvent);
27 
28   NS_DECL_ISUPPORTS_INHERITED
29   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(UIEvent, Event)
30 
31   // nsIDOMUIEvent Interface
32   NS_DECL_NSIDOMUIEVENT
33 
34   // Forward to Event
35   NS_FORWARD_TO_EVENT_NO_SERIALIZATION_NO_DUPLICATION
36   using Event::GetCurrentTarget;  // Because the forwarding thing shadows it.
37   NS_IMETHOD DuplicatePrivateData() override;
38   NS_IMETHOD_(void)
39   Serialize(IPC::Message* aMsg, bool aSerializeInterfaceType) override;
40   NS_IMETHOD_(bool)
41   Deserialize(const IPC::Message* aMsg, PickleIterator* aIter) override;
42 
43   static already_AddRefed<UIEvent> Constructor(const GlobalObject& aGlobal,
44                                                const nsAString& aType,
45                                                const UIEventInit& aParam,
46                                                ErrorResult& aRv);
47 
WrapObjectInternal(JSContext * aCx,JS::Handle<JSObject * > aGivenProto)48   virtual JSObject* WrapObjectInternal(
49       JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override {
50     return UIEventBinding::Wrap(aCx, this, aGivenProto);
51   }
52 
53   void InitUIEvent(const nsAString& typeArg, bool canBubbleArg,
54                    bool cancelableArg, nsGlobalWindowInner* viewArg,
55                    int32_t detailArg);
56 
GetView()57   nsPIDOMWindowOuter* GetView() const { return mView; }
58 
Detail()59   int32_t Detail() const { return mDetail; }
60 
LayerX()61   int32_t LayerX() const { return GetLayerPoint().x; }
62 
LayerY()63   int32_t LayerY() const { return GetLayerPoint().y; }
64 
65   int32_t PageX() const;
66   int32_t PageY() const;
67 
68   virtual uint32_t Which(CallerType aCallerType = CallerType::System) {
69     MOZ_ASSERT(mEvent->mClass != eKeyboardEventClass,
70                "Key events should override Which()");
71     MOZ_ASSERT(mEvent->mClass != eMouseEventClass,
72                "Mouse events should override Which()");
73     return 0;
74   }
75 
76   already_AddRefed<nsINode> GetRangeParent();
77 
78   int32_t RangeOffset() const;
79 
80  protected:
~UIEvent()81   ~UIEvent() {}
82 
83   // Internal helper functions
84   nsIntPoint GetMovementPoint();
85   nsIntPoint GetLayerPoint() const;
86 
87   nsCOMPtr<nsPIDOMWindowOuter> mView;
88   int32_t mDetail;
89   CSSIntPoint mClientPoint;
90   // Screenpoint is mEvent->mRefPoint.
91   nsIntPoint mLayerPoint;
92   CSSIntPoint mPagePoint;
93   nsIntPoint mMovementPoint;
94   bool mIsPointerLocked;
95   CSSIntPoint mLastClientPoint;
96 
97   static Modifiers ComputeModifierState(const nsAString& aModifiersList);
98   bool GetModifierStateInternal(const nsAString& aKey);
99   void InitModifiers(const EventModifierInit& aParam);
100 };
101 
102 }  // namespace dom
103 }  // namespace mozilla
104 
105 #define NS_FORWARD_TO_UIEVENT                                             \
106   NS_FORWARD_NSIDOMUIEVENT(UIEvent::)                                     \
107   NS_FORWARD_TO_EVENT_NO_SERIALIZATION_NO_DUPLICATION                     \
108   using Event::GetCurrentTarget; /* Forwarding shadows */                 \
109   NS_IMETHOD DuplicatePrivateData() override {                            \
110     return UIEvent::DuplicatePrivateData();                               \
111   }                                                                       \
112   NS_IMETHOD_(void)                                                       \
113   Serialize(IPC::Message* aMsg, bool aSerializeInterfaceType) override {  \
114     UIEvent::Serialize(aMsg, aSerializeInterfaceType);                    \
115   }                                                                       \
116   NS_IMETHOD_(bool)                                                       \
117   Deserialize(const IPC::Message* aMsg, PickleIterator* aIter) override { \
118     return UIEvent::Deserialize(aMsg, aIter);                             \
119   }
120 
121 already_AddRefed<mozilla::dom::UIEvent> NS_NewDOMUIEvent(
122     mozilla::dom::EventTarget* aOwner, nsPresContext* aPresContext,
123     mozilla::WidgetGUIEvent* aEvent);
124 
125 #endif  // mozilla_dom_UIEvent_h_
126