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/. */
7 #ifndef mozilla_dom_UIEvent_h_
8 #define mozilla_dom_UIEvent_h_
10 #include "mozilla/Attributes.h"
11 #include "mozilla/dom/Event.h"
12 #include "mozilla/dom/Nullable.h"
13 #include "mozilla/dom/UIEventBinding.h"
14 #include "mozilla/dom/WindowProxyHolder.h"
15 #include "nsDeviceContext.h"
16 #include "nsDocShell.h"
17 #include "nsIContent.h"
18 #include "nsPresContext.h"
22 namespace mozilla::dom
{
24 class UIEvent
: public Event
{
26 UIEvent(EventTarget
* aOwner
, nsPresContext
* aPresContext
,
27 WidgetGUIEvent
* aEvent
);
29 NS_DECL_ISUPPORTS_INHERITED
30 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(UIEvent
, Event
)
32 void DuplicatePrivateData() override
;
33 void Serialize(IPC::MessageWriter
* aWriter
,
34 bool aSerializeInterfaceType
) override
;
35 bool Deserialize(IPC::MessageReader
* aReader
) override
;
37 static already_AddRefed
<UIEvent
> Constructor(const GlobalObject
& aGlobal
,
38 const nsAString
& aType
,
39 const UIEventInit
& aParam
);
41 virtual JSObject
* WrapObjectInternal(
42 JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
) override
{
43 return UIEvent_Binding::Wrap(aCx
, this, aGivenProto
);
46 UIEvent
* AsUIEvent() override
{ return this; }
48 void InitUIEvent(const nsAString
& typeArg
, bool canBubbleArg
,
49 bool cancelableArg
, nsGlobalWindowInner
* viewArg
,
52 Nullable
<WindowProxyHolder
> GetView() const {
56 return WindowProxyHolder(mView
->GetBrowsingContext());
59 int32_t Detail() const { return mDetail
; }
61 int32_t LayerX() const { return GetLayerPoint().x
; }
63 int32_t LayerY() const { return GetLayerPoint().y
; }
65 virtual uint32_t Which(CallerType aCallerType
= CallerType::System
) {
66 MOZ_ASSERT(mEvent
->mClass
!= eKeyboardEventClass
,
67 "Key events should override Which()");
68 MOZ_ASSERT(mEvent
->mClass
!= eMouseEventClass
,
69 "Mouse events should override Which()");
74 * GetRangeParent() should be used only by JS. C++ callers should use
75 * GetRangeParentContent() or GetRangeParentContentAndOffset() instead.
77 MOZ_CAN_RUN_SCRIPT already_AddRefed
<nsINode
> GetRangeParent() {
78 return GetRangeParentContent();
80 MOZ_CAN_RUN_SCRIPT already_AddRefed
<nsIContent
> GetRangeParentContent() {
81 return GetRangeParentContentAndOffset(nullptr);
84 * aOffset is optional (i.e., can be nullptr), but when you call this with
85 * nullptr, you should use GetRangeParentContent() instead.
87 MOZ_CAN_RUN_SCRIPT already_AddRefed
<nsIContent
>
88 GetRangeParentContentAndOffset(int32_t* aOffset
) const;
91 * If you also need to compute range parent in C++ code, you should use
92 * GetRangeParentContentAndOffset() instead.
94 MOZ_CAN_RUN_SCRIPT
int32_t RangeOffset() const;
99 // Internal helper functions
100 nsIntPoint
GetMovementPoint();
101 nsIntPoint
GetLayerPoint() const;
103 nsCOMPtr
<nsPIDOMWindowOuter
> mView
;
105 CSSIntPoint mDefaultClientPoint
;
106 // Screenpoint is mEvent->mRefPoint.
107 nsIntPoint mLayerPoint
;
108 CSSIntPoint mPagePoint
;
109 nsIntPoint mMovementPoint
;
110 bool mIsPointerLocked
;
111 CSSIntPoint mLastClientPoint
;
113 static Modifiers
ComputeModifierState(const nsAString
& aModifiersList
);
114 bool GetModifierStateInternal(const nsAString
& aKey
);
115 void InitModifiers(const EventModifierInit
& aParam
);
118 } // namespace mozilla::dom
120 already_AddRefed
<mozilla::dom::UIEvent
> NS_NewDOMUIEvent(
121 mozilla::dom::EventTarget
* aOwner
, nsPresContext
* aPresContext
,
122 mozilla::WidgetGUIEvent
* aEvent
);
124 #endif // mozilla_dom_UIEvent_h_