1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Thomas K. Dyas <tdyas@zecador.org>.
19 : * Portions created by the Initial Developer are Copyright (C) 2008
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either the GNU General Public License Version 2 or later (the "GPL"), or
26 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #include "nsDOMSimpleGestureEvent.h"
39 : #include "nsGUIEvent.h"
40 : #include "nsContentUtils.h"
41 :
42 :
43 0 : nsDOMSimpleGestureEvent::nsDOMSimpleGestureEvent(nsPresContext* aPresContext, nsSimpleGestureEvent* aEvent)
44 0 : : nsDOMMouseEvent(aPresContext, aEvent ? aEvent : new nsSimpleGestureEvent(false, 0, nsnull, 0, 0.0))
45 : {
46 0 : NS_ASSERTION(mEvent->eventStructType == NS_SIMPLE_GESTURE_EVENT, "event type mismatch");
47 :
48 0 : if (aEvent) {
49 0 : mEventIsInternal = false;
50 : } else {
51 0 : mEventIsInternal = true;
52 0 : mEvent->time = PR_Now();
53 0 : mEvent->refPoint.x = mEvent->refPoint.y = 0;
54 0 : static_cast<nsMouseEvent*>(mEvent)->inputSource = nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN;
55 : }
56 0 : }
57 :
58 0 : nsDOMSimpleGestureEvent::~nsDOMSimpleGestureEvent()
59 : {
60 0 : if (mEventIsInternal) {
61 0 : delete static_cast<nsSimpleGestureEvent*>(mEvent);
62 0 : mEvent = nsnull;
63 : }
64 0 : }
65 :
66 0 : NS_IMPL_ADDREF_INHERITED(nsDOMSimpleGestureEvent, nsDOMUIEvent)
67 0 : NS_IMPL_RELEASE_INHERITED(nsDOMSimpleGestureEvent, nsDOMUIEvent)
68 :
69 : DOMCI_DATA(SimpleGestureEvent, nsDOMSimpleGestureEvent)
70 :
71 0 : NS_INTERFACE_MAP_BEGIN(nsDOMSimpleGestureEvent)
72 0 : NS_INTERFACE_MAP_ENTRY(nsIDOMSimpleGestureEvent)
73 0 : NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SimpleGestureEvent)
74 0 : NS_INTERFACE_MAP_END_INHERITING(nsDOMMouseEvent)
75 :
76 : /* readonly attribute unsigned long direction; */
77 : NS_IMETHODIMP
78 0 : nsDOMSimpleGestureEvent::GetDirection(PRUint32 *aDirection)
79 : {
80 0 : NS_ENSURE_ARG_POINTER(aDirection);
81 0 : *aDirection = static_cast<nsSimpleGestureEvent*>(mEvent)->direction;
82 0 : return NS_OK;
83 : }
84 :
85 : /* readonly attribute float delta; */
86 : NS_IMETHODIMP
87 0 : nsDOMSimpleGestureEvent::GetDelta(PRFloat64 *aDelta)
88 : {
89 0 : NS_ENSURE_ARG_POINTER(aDelta);
90 0 : *aDelta = static_cast<nsSimpleGestureEvent*>(mEvent)->delta;
91 0 : return NS_OK;
92 : }
93 :
94 : NS_IMETHODIMP
95 0 : nsDOMSimpleGestureEvent::InitSimpleGestureEvent(const nsAString& aTypeArg,
96 : bool aCanBubbleArg,
97 : bool aCancelableArg,
98 : nsIDOMWindow* aViewArg,
99 : PRInt32 aDetailArg,
100 : PRInt32 aScreenX,
101 : PRInt32 aScreenY,
102 : PRInt32 aClientX,
103 : PRInt32 aClientY,
104 : bool aCtrlKeyArg,
105 : bool aAltKeyArg,
106 : bool aShiftKeyArg,
107 : bool aMetaKeyArg,
108 : PRUint16 aButton,
109 : nsIDOMEventTarget* aRelatedTarget,
110 : PRUint32 aDirectionArg,
111 : PRFloat64 aDeltaArg)
112 : {
113 : nsresult rv = nsDOMMouseEvent::InitMouseEvent(aTypeArg,
114 : aCanBubbleArg,
115 : aCancelableArg,
116 : aViewArg,
117 : aDetailArg,
118 : aScreenX,
119 : aScreenY,
120 : aClientX,
121 : aClientY,
122 : aCtrlKeyArg,
123 : aAltKeyArg,
124 : aShiftKeyArg,
125 : aMetaKeyArg,
126 : aButton,
127 0 : aRelatedTarget);
128 0 : NS_ENSURE_SUCCESS(rv, rv);
129 :
130 0 : nsSimpleGestureEvent* simpleGestureEvent = static_cast<nsSimpleGestureEvent*>(mEvent);
131 0 : simpleGestureEvent->direction = aDirectionArg;
132 0 : simpleGestureEvent->delta = aDeltaArg;
133 :
134 0 : return NS_OK;
135 : }
136 :
137 0 : nsresult NS_NewDOMSimpleGestureEvent(nsIDOMEvent** aInstancePtrResult,
138 : nsPresContext* aPresContext,
139 : nsSimpleGestureEvent *aEvent)
140 : {
141 0 : nsDOMSimpleGestureEvent *it = new nsDOMSimpleGestureEvent(aPresContext, aEvent);
142 0 : if (nsnull == it) {
143 0 : return NS_ERROR_OUT_OF_MEMORY;
144 : }
145 0 : return CallQueryInterface(it, aInstancePtrResult);
146 : }
|