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 #include "mozilla/dom/SimpleGestureEvent.h"
7 #include "mozilla/TouchEvents.h"
13 SimpleGestureEvent::SimpleGestureEvent(EventTarget
* aOwner
,
14 nsPresContext
* aPresContext
,
15 WidgetSimpleGestureEvent
* aEvent
)
16 : MouseEvent(aOwner
, aPresContext
,
18 new WidgetSimpleGestureEvent(false, 0, nullptr))
20 NS_ASSERTION(mEvent
->mClass
== eSimpleGestureEventClass
,
21 "event type mismatch");
24 mEventIsInternal
= false;
26 mEventIsInternal
= true;
27 mEvent
->time
= PR_Now();
28 mEvent
->refPoint
.x
= mEvent
->refPoint
.y
= 0;
29 static_cast<WidgetMouseEventBase
*>(mEvent
)->inputSource
=
30 nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN
;
34 NS_IMPL_ADDREF_INHERITED(SimpleGestureEvent
, MouseEvent
)
35 NS_IMPL_RELEASE_INHERITED(SimpleGestureEvent
, MouseEvent
)
37 NS_INTERFACE_MAP_BEGIN(SimpleGestureEvent
)
38 NS_INTERFACE_MAP_ENTRY(nsIDOMSimpleGestureEvent
)
39 NS_INTERFACE_MAP_END_INHERITING(MouseEvent
)
41 /* attribute unsigned long allowedDirections; */
43 SimpleGestureEvent::AllowedDirections()
45 return mEvent
->AsSimpleGestureEvent()->allowedDirections
;
49 SimpleGestureEvent::GetAllowedDirections(uint32_t* aAllowedDirections
)
51 NS_ENSURE_ARG_POINTER(aAllowedDirections
);
52 *aAllowedDirections
= AllowedDirections();
57 SimpleGestureEvent::SetAllowedDirections(uint32_t aAllowedDirections
)
59 mEvent
->AsSimpleGestureEvent()->allowedDirections
= aAllowedDirections
;
63 /* readonly attribute unsigned long direction; */
65 SimpleGestureEvent::Direction()
67 return mEvent
->AsSimpleGestureEvent()->direction
;
71 SimpleGestureEvent::GetDirection(uint32_t* aDirection
)
73 NS_ENSURE_ARG_POINTER(aDirection
);
74 *aDirection
= Direction();
78 /* readonly attribute float delta; */
80 SimpleGestureEvent::Delta()
82 return mEvent
->AsSimpleGestureEvent()->delta
;
86 SimpleGestureEvent::GetDelta(double* aDelta
)
88 NS_ENSURE_ARG_POINTER(aDelta
);
93 /* readonly attribute unsigned long clickCount; */
95 SimpleGestureEvent::ClickCount()
97 return mEvent
->AsSimpleGestureEvent()->clickCount
;
101 SimpleGestureEvent::GetClickCount(uint32_t* aClickCount
)
103 NS_ENSURE_ARG_POINTER(aClickCount
);
104 *aClickCount
= ClickCount();
109 SimpleGestureEvent::InitSimpleGestureEvent(const nsAString
& aTypeArg
,
112 nsIDOMWindow
* aViewArg
,
123 nsIDOMEventTarget
* aRelatedTarget
,
124 uint32_t aAllowedDirectionsArg
,
125 uint32_t aDirectionArg
,
127 uint32_t aClickCountArg
)
130 MouseEvent::InitMouseEvent(aTypeArg
, aCanBubbleArg
, aCancelableArg
,
131 aViewArg
, aDetailArg
,
132 aScreenX
, aScreenY
, aClientX
, aClientY
,
133 aCtrlKeyArg
, aAltKeyArg
, aShiftKeyArg
,
134 aMetaKeyArg
, aButton
, aRelatedTarget
);
135 NS_ENSURE_SUCCESS(rv
, rv
);
137 WidgetSimpleGestureEvent
* simpleGestureEvent
= mEvent
->AsSimpleGestureEvent();
138 simpleGestureEvent
->allowedDirections
= aAllowedDirectionsArg
;
139 simpleGestureEvent
->direction
= aDirectionArg
;
140 simpleGestureEvent
->delta
= aDeltaArg
;
141 simpleGestureEvent
->clickCount
= aClickCountArg
;
147 } // namespace mozilla
149 using namespace mozilla
;
150 using namespace mozilla::dom
;
153 NS_NewDOMSimpleGestureEvent(nsIDOMEvent
** aInstancePtrResult
,
155 nsPresContext
* aPresContext
,
156 WidgetSimpleGestureEvent
* aEvent
)
158 SimpleGestureEvent
* it
= new SimpleGestureEvent(aOwner
, aPresContext
, aEvent
);
160 *aInstancePtrResult
= static_cast<Event
*>(it
);