Line data Source code
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/. */
6 :
7 : #include "mozilla/dom/SimpleGestureEvent.h"
8 : #include "mozilla/TouchEvents.h"
9 : #include "prtime.h"
10 :
11 : namespace mozilla {
12 : namespace dom {
13 :
14 0 : SimpleGestureEvent::SimpleGestureEvent(EventTarget* aOwner,
15 : nsPresContext* aPresContext,
16 0 : WidgetSimpleGestureEvent* aEvent)
17 : : MouseEvent(aOwner, aPresContext,
18 : aEvent ? aEvent :
19 : new WidgetSimpleGestureEvent(false, eVoidEvent,
20 0 : nullptr))
21 : {
22 0 : NS_ASSERTION(mEvent->mClass == eSimpleGestureEventClass,
23 : "event type mismatch");
24 :
25 0 : if (aEvent) {
26 0 : mEventIsInternal = false;
27 : } else {
28 0 : mEventIsInternal = true;
29 0 : mEvent->mTime = PR_Now();
30 0 : mEvent->mRefPoint = LayoutDeviceIntPoint(0, 0);
31 0 : static_cast<WidgetMouseEventBase*>(mEvent)->inputSource =
32 : nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN;
33 : }
34 0 : }
35 :
36 0 : NS_IMPL_ADDREF_INHERITED(SimpleGestureEvent, MouseEvent)
37 0 : NS_IMPL_RELEASE_INHERITED(SimpleGestureEvent, MouseEvent)
38 :
39 0 : NS_INTERFACE_MAP_BEGIN(SimpleGestureEvent)
40 0 : NS_INTERFACE_MAP_ENTRY(nsIDOMSimpleGestureEvent)
41 0 : NS_INTERFACE_MAP_END_INHERITING(MouseEvent)
42 :
43 : uint32_t
44 0 : SimpleGestureEvent::AllowedDirections()
45 : {
46 0 : return mEvent->AsSimpleGestureEvent()->mAllowedDirections;
47 : }
48 :
49 : NS_IMETHODIMP
50 0 : SimpleGestureEvent::GetAllowedDirections(uint32_t* aAllowedDirections)
51 : {
52 0 : NS_ENSURE_ARG_POINTER(aAllowedDirections);
53 0 : *aAllowedDirections = AllowedDirections();
54 0 : return NS_OK;
55 : }
56 :
57 : NS_IMETHODIMP
58 0 : SimpleGestureEvent::SetAllowedDirections(uint32_t aAllowedDirections)
59 : {
60 0 : mEvent->AsSimpleGestureEvent()->mAllowedDirections = aAllowedDirections;
61 0 : return NS_OK;
62 : }
63 :
64 : uint32_t
65 0 : SimpleGestureEvent::Direction()
66 : {
67 0 : return mEvent->AsSimpleGestureEvent()->mDirection;
68 : }
69 :
70 : NS_IMETHODIMP
71 0 : SimpleGestureEvent::GetDirection(uint32_t* aDirection)
72 : {
73 0 : NS_ENSURE_ARG_POINTER(aDirection);
74 0 : *aDirection = Direction();
75 0 : return NS_OK;
76 : }
77 :
78 : double
79 0 : SimpleGestureEvent::Delta()
80 : {
81 0 : return mEvent->AsSimpleGestureEvent()->mDelta;
82 : }
83 :
84 : NS_IMETHODIMP
85 0 : SimpleGestureEvent::GetDelta(double* aDelta)
86 : {
87 0 : NS_ENSURE_ARG_POINTER(aDelta);
88 0 : *aDelta = Delta();
89 0 : return NS_OK;
90 : }
91 :
92 : uint32_t
93 0 : SimpleGestureEvent::ClickCount()
94 : {
95 0 : return mEvent->AsSimpleGestureEvent()->mClickCount;
96 : }
97 :
98 : NS_IMETHODIMP
99 0 : SimpleGestureEvent::GetClickCount(uint32_t* aClickCount)
100 : {
101 0 : NS_ENSURE_ARG_POINTER(aClickCount);
102 0 : *aClickCount = ClickCount();
103 0 : return NS_OK;
104 : }
105 :
106 : void
107 0 : SimpleGestureEvent::InitSimpleGestureEvent(const nsAString& aTypeArg,
108 : bool aCanBubbleArg,
109 : bool aCancelableArg,
110 : nsGlobalWindow* aViewArg,
111 : int32_t aDetailArg,
112 : int32_t aScreenX,
113 : int32_t aScreenY,
114 : int32_t aClientX,
115 : int32_t aClientY,
116 : bool aCtrlKeyArg,
117 : bool aAltKeyArg,
118 : bool aShiftKeyArg,
119 : bool aMetaKeyArg,
120 : uint16_t aButton,
121 : EventTarget* aRelatedTarget,
122 : uint32_t aAllowedDirectionsArg,
123 : uint32_t aDirectionArg,
124 : double aDeltaArg,
125 : uint32_t aClickCountArg)
126 : {
127 0 : NS_ENSURE_TRUE_VOID(!mEvent->mFlags.mIsBeingDispatched);
128 :
129 0 : MouseEvent::InitMouseEvent(aTypeArg, aCanBubbleArg, aCancelableArg,
130 : aViewArg, aDetailArg,
131 : aScreenX, aScreenY, aClientX, aClientY,
132 : aCtrlKeyArg, aAltKeyArg, aShiftKeyArg,
133 0 : aMetaKeyArg, aButton, aRelatedTarget);
134 :
135 0 : WidgetSimpleGestureEvent* simpleGestureEvent = mEvent->AsSimpleGestureEvent();
136 0 : simpleGestureEvent->mAllowedDirections = aAllowedDirectionsArg;
137 0 : simpleGestureEvent->mDirection = aDirectionArg;
138 0 : simpleGestureEvent->mDelta = aDeltaArg;
139 0 : simpleGestureEvent->mClickCount = aClickCountArg;
140 : }
141 :
142 : } // namespace dom
143 : } // namespace mozilla
144 :
145 : using namespace mozilla;
146 : using namespace mozilla::dom;
147 :
148 : already_AddRefed<SimpleGestureEvent>
149 0 : NS_NewDOMSimpleGestureEvent(EventTarget* aOwner,
150 : nsPresContext* aPresContext,
151 : WidgetSimpleGestureEvent* aEvent)
152 : {
153 : RefPtr<SimpleGestureEvent> it =
154 0 : new SimpleGestureEvent(aOwner, aPresContext, aEvent);
155 0 : return it.forget();
156 : }
|