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 #include "SimpleGestureEvent.h"
9 #include "mozilla/dom/MouseEventBinding.h"
10 #include "mozilla/TouchEvents.h"
12 namespace mozilla::dom
{
14 SimpleGestureEvent::SimpleGestureEvent(EventTarget
* aOwner
,
15 nsPresContext
* aPresContext
,
16 WidgetSimpleGestureEvent
* aEvent
)
20 : new WidgetSimpleGestureEvent(false, eVoidEvent
, nullptr)) {
21 NS_ASSERTION(mEvent
->mClass
== eSimpleGestureEventClass
,
22 "event type mismatch");
25 mEventIsInternal
= false;
27 mEventIsInternal
= true;
28 mEvent
->mRefPoint
= LayoutDeviceIntPoint(0, 0);
29 static_cast<WidgetMouseEventBase
*>(mEvent
)->mInputSource
=
30 MouseEvent_Binding::MOZ_SOURCE_UNKNOWN
;
34 uint32_t SimpleGestureEvent::AllowedDirections() const {
35 return mEvent
->AsSimpleGestureEvent()->mAllowedDirections
;
38 void SimpleGestureEvent::SetAllowedDirections(uint32_t aAllowedDirections
) {
39 mEvent
->AsSimpleGestureEvent()->mAllowedDirections
= aAllowedDirections
;
42 uint32_t SimpleGestureEvent::Direction() const {
43 return mEvent
->AsSimpleGestureEvent()->mDirection
;
46 double SimpleGestureEvent::Delta() const {
47 return mEvent
->AsSimpleGestureEvent()->mDelta
;
50 uint32_t SimpleGestureEvent::ClickCount() const {
51 return mEvent
->AsSimpleGestureEvent()->mClickCount
;
54 void SimpleGestureEvent::InitSimpleGestureEventInternal(
55 const nsAString
& aTypeArg
, bool aCanBubbleArg
, bool aCancelableArg
,
56 nsGlobalWindowInner
* aViewArg
, int32_t aDetailArg
, double aScreenX
,
57 double aScreenY
, double aClientX
, double aClientY
, bool aCtrlKeyArg
,
58 bool aAltKeyArg
, bool aShiftKeyArg
, bool aMetaKeyArg
, uint16_t aButton
,
59 EventTarget
* aRelatedTarget
, uint32_t aAllowedDirectionsArg
,
60 uint32_t aDirectionArg
, double aDeltaArg
, uint32_t aClickCountArg
) {
61 NS_ENSURE_TRUE_VOID(!mEvent
->mFlags
.mIsBeingDispatched
);
63 MouseEvent::InitMouseEventInternal(
64 aTypeArg
, aCanBubbleArg
, aCancelableArg
, aViewArg
, aDetailArg
, aScreenX
,
65 aScreenY
, aClientX
, aClientY
, aCtrlKeyArg
, aAltKeyArg
, aShiftKeyArg
,
66 aMetaKeyArg
, aButton
, aRelatedTarget
);
68 WidgetSimpleGestureEvent
* simpleGestureEvent
= mEvent
->AsSimpleGestureEvent();
69 simpleGestureEvent
->mAllowedDirections
= aAllowedDirectionsArg
;
70 simpleGestureEvent
->mDirection
= aDirectionArg
;
71 simpleGestureEvent
->mDelta
= aDeltaArg
;
72 simpleGestureEvent
->mClickCount
= aClickCountArg
;
75 } // namespace mozilla::dom
77 using namespace mozilla
;
78 using namespace mozilla::dom
;
80 already_AddRefed
<SimpleGestureEvent
> NS_NewDOMSimpleGestureEvent(
81 EventTarget
* aOwner
, nsPresContext
* aPresContext
,
82 WidgetSimpleGestureEvent
* aEvent
) {
83 RefPtr
<SimpleGestureEvent
> it
=
84 new SimpleGestureEvent(aOwner
, aPresContext
, aEvent
);