Bumping manifests a=b2g-bump
[gecko.git] / dom / events / UIEvent.h
blobd13dc788019979516e2428b6cd0a7167fd1d34cf
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"
17 class nsINode;
19 namespace mozilla {
20 namespace dom {
22 class UIEvent : public Event,
23 public nsIDOMUIEvent
25 public:
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
34 NS_DECL_NSIDOMUIEVENT
36 // Forward to Event
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,
43 WidgetEvent* aEvent)
45 if (!aEvent ||
46 (aEvent->mClass != eMouseEventClass &&
47 aEvent->mClass != eMouseScrollEventClass &&
48 aEvent->mClass != eWheelEventClass &&
49 aEvent->mClass != eDragEventClass &&
50 aEvent->mClass != ePointerEventClass &&
51 aEvent->mClass != eSimpleGestureEventClass)) {
52 return nsIntPoint(0, 0);
55 WidgetGUIEvent* event = aEvent->AsGUIEvent();
56 if (!event->widget) {
57 return LayoutDeviceIntPoint::ToUntyped(aEvent->refPoint);
60 LayoutDeviceIntPoint offset = aEvent->refPoint +
61 LayoutDeviceIntPoint::FromUntyped(event->widget->WidgetToScreenOffset());
62 nscoord factor =
63 aPresContext->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom();
64 return nsIntPoint(nsPresContext::AppUnitsToIntCSSPixels(offset.x * factor),
65 nsPresContext::AppUnitsToIntCSSPixels(offset.y * factor));
68 static CSSIntPoint CalculateClientPoint(nsPresContext* aPresContext,
69 WidgetEvent* aEvent,
70 CSSIntPoint* aDefaultClientPoint)
72 if (!aEvent ||
73 (aEvent->mClass != eMouseEventClass &&
74 aEvent->mClass != eMouseScrollEventClass &&
75 aEvent->mClass != eWheelEventClass &&
76 aEvent->mClass != eDragEventClass &&
77 aEvent->mClass != ePointerEventClass &&
78 aEvent->mClass != eSimpleGestureEventClass) ||
79 !aPresContext ||
80 !aEvent->AsGUIEvent()->widget) {
81 return aDefaultClientPoint
82 ? *aDefaultClientPoint
83 : CSSIntPoint(0, 0);
86 nsIPresShell* shell = aPresContext->GetPresShell();
87 if (!shell) {
88 return CSSIntPoint(0, 0);
90 nsIFrame* rootFrame = shell->GetRootFrame();
91 if (!rootFrame) {
92 return CSSIntPoint(0, 0);
94 nsPoint pt =
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,
103 ErrorResult& aRv);
105 virtual JSObject* WrapObjectInternal(JSContext* aCx) MOZ_OVERRIDE
107 return UIEventBinding::Wrap(aCx, this);
110 nsIDOMWindow* GetView() const
112 return mView;
115 int32_t Detail() const
117 return mDetail;
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->mClass != eKeyboardEventClass,
136 "Key events should override Which()");
137 MOZ_ASSERT(mEvent->mClass != eMouseEventClass,
138 "Mouse events should override Which()");
139 return 0;
142 already_AddRefed<nsINode> GetRangeParent();
144 int32_t RangeOffset() const;
146 bool CancelBubble() const
148 return mEvent->mFlags.mPropagationStopped;
151 bool IsChar() const;
153 protected:
154 ~UIEvent() {}
156 // Internal helper functions
157 nsIntPoint GetMovementPoint();
158 nsIntPoint GetLayerPoint() const;
160 nsCOMPtr<nsIDOMWindow> mView;
161 int32_t mDetail;
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);
174 } // namespace dom
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() MOZ_OVERRIDE \
182 return UIEvent::DuplicatePrivateData(); \
184 NS_IMETHOD_(void) Serialize(IPC::Message* aMsg, \
185 bool aSerializeInterfaceType) \
186 MOZ_OVERRIDE \
188 UIEvent::Serialize(aMsg, aSerializeInterfaceType); \
190 NS_IMETHOD_(bool) Deserialize(const IPC::Message* aMsg, \
191 void** aIter) MOZ_OVERRIDE \
193 return UIEvent::Deserialize(aMsg, aIter); \
196 #endif // mozilla_dom_UIEvent_h_