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
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/
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
15 * The Original Code is mozilla.org code.
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.
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.
36 * ***** END LICENSE BLOCK ***** */
38 #include "nsDOMSimpleGestureEvent.h"
39 #include "nsGUIEvent.h"
40 #include "nsContentUtils.h"
43 nsDOMSimpleGestureEvent::nsDOMSimpleGestureEvent(nsPresContext
* aPresContext
, nsSimpleGestureEvent
* aEvent
)
44 : nsDOMUIEvent(aPresContext
, aEvent
? aEvent
: new nsSimpleGestureEvent(PR_FALSE
, 0, nsnull
, 0, 0.0))
46 NS_ASSERTION(mEvent
->eventStructType
== NS_SIMPLE_GESTURE_EVENT
, "event type mismatch");
49 mEventIsInternal
= PR_FALSE
;
51 mEventIsInternal
= PR_TRUE
;
52 mEvent
->time
= PR_Now();
56 nsDOMSimpleGestureEvent::~nsDOMSimpleGestureEvent()
58 if (mEventIsInternal
) {
59 delete static_cast<nsSimpleGestureEvent
*>(mEvent
);
64 NS_IMPL_ADDREF_INHERITED(nsDOMSimpleGestureEvent
, nsDOMUIEvent
)
65 NS_IMPL_RELEASE_INHERITED(nsDOMSimpleGestureEvent
, nsDOMUIEvent
)
67 NS_INTERFACE_MAP_BEGIN(nsDOMSimpleGestureEvent
)
68 NS_INTERFACE_MAP_ENTRY(nsIDOMSimpleGestureEvent
)
69 NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(SimpleGestureEvent
)
70 NS_INTERFACE_MAP_END_INHERITING(nsDOMUIEvent
)
72 /* readonly attribute unsigned long direction; */
74 nsDOMSimpleGestureEvent::GetDirection(PRUint32
*aDirection
)
76 NS_ENSURE_ARG_POINTER(aDirection
);
77 *aDirection
= static_cast<nsSimpleGestureEvent
*>(mEvent
)->direction
;
81 /* readonly attribute float delta; */
83 nsDOMSimpleGestureEvent::GetDelta(PRFloat64
*aDelta
)
85 NS_ENSURE_ARG_POINTER(aDelta
);
86 *aDelta
= static_cast<nsSimpleGestureEvent
*>(mEvent
)->delta
;
90 /* readonly attribute boolean altKey; */
92 nsDOMSimpleGestureEvent::GetAltKey(PRBool
* aIsDown
)
94 NS_ENSURE_ARG_POINTER(aIsDown
);
95 *aIsDown
= static_cast<nsInputEvent
*>(mEvent
)->isAlt
;
99 /* readonly attribute boolean ctrlKey; */
101 nsDOMSimpleGestureEvent::GetCtrlKey(PRBool
* aIsDown
)
103 NS_ENSURE_ARG_POINTER(aIsDown
);
104 *aIsDown
= static_cast<nsInputEvent
*>(mEvent
)->isControl
;
108 /* readonly attribute boolean shiftKey; */
110 nsDOMSimpleGestureEvent::GetShiftKey(PRBool
* aIsDown
)
112 NS_ENSURE_ARG_POINTER(aIsDown
);
113 *aIsDown
= static_cast<nsInputEvent
*>(mEvent
)->isShift
;
117 /* readonly attribute boolean metaKey; */
119 nsDOMSimpleGestureEvent::GetMetaKey(PRBool
* aIsDown
)
121 NS_ENSURE_ARG_POINTER(aIsDown
);
122 *aIsDown
= static_cast<nsInputEvent
*>(mEvent
)->isMeta
;
128 nsDOMSimpleGestureEvent::InitSimpleGestureEvent(const nsAString
& typeArg
, PRBool canBubbleArg
, PRBool cancelableArg
, nsIDOMAbstractView
*viewArg
, PRInt32 detailArg
, PRUint32 directionArg
, PRFloat64 deltaArg
, PRBool altKeyArg
, PRBool ctrlKeyArg
, PRBool shiftKeyArg
, PRBool metaKeyArg
)
130 nsresult rv
= nsDOMUIEvent::InitUIEvent(typeArg
, canBubbleArg
, cancelableArg
, viewArg
, detailArg
);
131 NS_ENSURE_SUCCESS(rv
, rv
);
133 nsSimpleGestureEvent
* simpleGestureEvent
= static_cast<nsSimpleGestureEvent
*>(mEvent
);
134 simpleGestureEvent
->direction
= directionArg
;
135 simpleGestureEvent
->delta
= deltaArg
;
136 simpleGestureEvent
->isAlt
= altKeyArg
;
137 simpleGestureEvent
->isControl
= ctrlKeyArg
;
138 simpleGestureEvent
->isShift
= shiftKeyArg
;
139 simpleGestureEvent
->isMeta
= metaKeyArg
;
144 nsresult
NS_NewDOMSimpleGestureEvent(nsIDOMEvent
** aInstancePtrResult
,
145 nsPresContext
* aPresContext
,
146 nsSimpleGestureEvent
*aEvent
)
148 nsDOMSimpleGestureEvent
*it
= new nsDOMSimpleGestureEvent(aPresContext
, aEvent
);
150 return NS_ERROR_OUT_OF_MEMORY
;
152 return CallQueryInterface(it
, aInstancePtrResult
);