1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_dom_UIEvent_h_
7 #define mozilla_dom_UIEvent_h_
9 #include "mozilla/Attributes.h"
10 #include "mozilla/dom/Event.h"
11 #include "mozilla/dom/UIEventBinding.h"
12 #include "nsDeviceContext.h"
13 #include "nsIDOMUIEvent.h"
14 #include "nsLayoutUtils.h"
15 #include "nsPresContext.h"
22 class UIEvent
: public Event
,
26 UIEvent(EventTarget
* aOwner
,
27 nsPresContext
* aPresContext
,
28 WidgetGUIEvent
* aEvent
);
30 NS_DECL_ISUPPORTS_INHERITED
31 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(UIEvent
, Event
)
33 // nsIDOMUIEvent Interface
37 NS_FORWARD_TO_EVENT_NO_SERIALIZATION_NO_DUPLICATION
38 NS_IMETHOD
DuplicatePrivateData() MOZ_OVERRIDE
;
39 NS_IMETHOD_(void) Serialize(IPC::Message
* aMsg
, bool aSerializeInterfaceType
) MOZ_OVERRIDE
;
40 NS_IMETHOD_(bool) Deserialize(const IPC::Message
* aMsg
, void** aIter
) MOZ_OVERRIDE
;
42 static nsIntPoint
CalculateScreenPoint(nsPresContext
* aPresContext
,
46 (aEvent
->eventStructType
!= NS_MOUSE_EVENT
&&
47 aEvent
->eventStructType
!= NS_MOUSE_SCROLL_EVENT
&&
48 aEvent
->eventStructType
!= NS_WHEEL_EVENT
&&
49 aEvent
->eventStructType
!= NS_DRAG_EVENT
&&
50 aEvent
->eventStructType
!= NS_POINTER_EVENT
&&
51 aEvent
->eventStructType
!= NS_SIMPLE_GESTURE_EVENT
)) {
52 return nsIntPoint(0, 0);
55 WidgetGUIEvent
* event
= aEvent
->AsGUIEvent();
57 return LayoutDeviceIntPoint::ToUntyped(aEvent
->refPoint
);
60 LayoutDeviceIntPoint offset
= aEvent
->refPoint
+
61 LayoutDeviceIntPoint::FromUntyped(event
->widget
->WidgetToScreenOffset());
63 aPresContext
->DeviceContext()->UnscaledAppUnitsPerDevPixel();
64 return nsIntPoint(nsPresContext::AppUnitsToIntCSSPixels(offset
.x
* factor
),
65 nsPresContext::AppUnitsToIntCSSPixels(offset
.y
* factor
));
68 static CSSIntPoint
CalculateClientPoint(nsPresContext
* aPresContext
,
70 CSSIntPoint
* aDefaultClientPoint
)
73 (aEvent
->eventStructType
!= NS_MOUSE_EVENT
&&
74 aEvent
->eventStructType
!= NS_MOUSE_SCROLL_EVENT
&&
75 aEvent
->eventStructType
!= NS_WHEEL_EVENT
&&
76 aEvent
->eventStructType
!= NS_DRAG_EVENT
&&
77 aEvent
->eventStructType
!= NS_POINTER_EVENT
&&
78 aEvent
->eventStructType
!= NS_SIMPLE_GESTURE_EVENT
) ||
80 !aEvent
->AsGUIEvent()->widget
) {
81 return aDefaultClientPoint
82 ? *aDefaultClientPoint
86 nsIPresShell
* shell
= aPresContext
->GetPresShell();
88 return CSSIntPoint(0, 0);
90 nsIFrame
* rootFrame
= shell
->GetRootFrame();
92 return CSSIntPoint(0, 0);
95 nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent
, rootFrame
);
97 return CSSIntPoint::FromAppUnitsRounded(pt
);
100 static already_AddRefed
<UIEvent
> Constructor(const GlobalObject
& aGlobal
,
101 const nsAString
& aType
,
102 const UIEventInit
& aParam
,
105 virtual JSObject
* WrapObject(JSContext
* aCx
) MOZ_OVERRIDE
107 return UIEventBinding::Wrap(aCx
, this);
110 nsIDOMWindow
* GetView() const
115 int32_t Detail() const
120 int32_t LayerX() const
122 return GetLayerPoint().x
;
125 int32_t LayerY() const
127 return GetLayerPoint().y
;
130 int32_t PageX() const;
131 int32_t PageY() const;
133 virtual uint32_t Which()
135 MOZ_ASSERT(mEvent
->eventStructType
!= NS_KEY_EVENT
,
136 "Key events should override Which()");
137 MOZ_ASSERT(mEvent
->eventStructType
!= NS_MOUSE_EVENT
,
138 "Mouse events should override Which()");
142 already_AddRefed
<nsINode
> GetRangeParent();
144 int32_t RangeOffset() const;
146 bool CancelBubble() const
148 return mEvent
->mFlags
.mPropagationStopped
;
156 // Internal helper functions
157 nsIntPoint
GetMovementPoint();
158 nsIntPoint
GetLayerPoint() const;
160 nsCOMPtr
<nsIDOMWindow
> mView
;
162 CSSIntPoint mClientPoint
;
163 // Screenpoint is mEvent->refPoint.
164 nsIntPoint mLayerPoint
;
165 CSSIntPoint mPagePoint
;
166 nsIntPoint mMovementPoint
;
167 bool mIsPointerLocked
;
168 CSSIntPoint mLastClientPoint
;
170 static Modifiers
ComputeModifierState(const nsAString
& aModifiersList
);
171 bool GetModifierStateInternal(const nsAString
& aKey
);
175 } // namespace mozilla
177 #define NS_FORWARD_TO_UIEVENT \
178 NS_FORWARD_NSIDOMUIEVENT(UIEvent::) \
179 NS_FORWARD_TO_EVENT_NO_SERIALIZATION_NO_DUPLICATION \
180 NS_IMETHOD DuplicatePrivateData() \
182 return UIEvent::DuplicatePrivateData(); \
184 NS_IMETHOD_(void) Serialize(IPC::Message* aMsg, \
185 bool aSerializeInterfaceType) \
187 UIEvent::Serialize(aMsg, aSerializeInterfaceType); \
189 NS_IMETHOD_(bool) Deserialize(const IPC::Message* aMsg, \
192 return UIEvent::Deserialize(aMsg, aIter); \
195 #endif // mozilla_dom_UIEvent_h_