Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / events / SimpleGestureEvent.cpp
blob3395cb7dbbb2afc07aca766b0a558b3c9aeaeaf3
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 "mozilla/dom/MouseEventBinding.h"
8 #include "mozilla/dom/SimpleGestureEvent.h"
9 #include "mozilla/TouchEvents.h"
10 #include "prtime.h"
12 namespace mozilla::dom {
14 SimpleGestureEvent::SimpleGestureEvent(EventTarget* aOwner,
15 nsPresContext* aPresContext,
16 WidgetSimpleGestureEvent* aEvent)
17 : MouseEvent(
18 aOwner, aPresContext,
19 aEvent ? aEvent
20 : new WidgetSimpleGestureEvent(false, eVoidEvent, nullptr)) {
21 NS_ASSERTION(mEvent->mClass == eSimpleGestureEventClass,
22 "event type mismatch");
24 if (aEvent) {
25 mEventIsInternal = false;
26 } else {
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::InitSimpleGestureEvent(
55 const nsAString& aTypeArg, bool aCanBubbleArg, bool aCancelableArg,
56 nsGlobalWindowInner* aViewArg, int32_t aDetailArg, int32_t aScreenX,
57 int32_t aScreenY, int32_t aClientX, int32_t 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::InitMouseEvent(aTypeArg, aCanBubbleArg, aCancelableArg, aViewArg,
64 aDetailArg, aScreenX, aScreenY, aClientX, aClientY,
65 aCtrlKeyArg, aAltKeyArg, aShiftKeyArg, aMetaKeyArg,
66 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);
85 return it.forget();