1 /* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
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 Android code.
17 * The Initial Developer of the Original Code is Mozilla Foundation.
18 * Portions created by the Initial Developer are Copyright (C) 2010
19 * the Initial Developer. All Rights Reserved.
22 * Vladimir Vukicevic <vladimir@pobox.com>
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 #ifndef AndroidJavaWrappers_h__
39 #define AndroidJavaWrappers_h__
42 #include <android/log.h>
44 #include "nsGeoPosition.h"
49 //#define FORCE_ALOG 1
52 #if defined(DEBUG) || defined(FORCE_ALOG)
53 #define ALOG(args...) __android_log_print(ANDROID_LOG_INFO, "Gecko" , ## args)
61 void InitAndroidJavaWrappers(JNIEnv
*jEnv
);
64 * Note: do not store global refs to any WrappedJavaObject;
65 * these are live only during a particular JNI method, as
66 * NewGlobalRef is -not- called on the jobject.
68 * If this is needed, WrappedJavaObject can be extended to
72 class WrappedJavaObject
{
78 WrappedJavaObject(jobject jobj
) {
82 void Init(jobject jobj
) {
87 return wrapped_obj
== 0;
90 jobject
wrappedObject() const {
98 class AndroidPoint
: public WrappedJavaObject
101 static void InitPointClass(JNIEnv
*jEnv
);
104 AndroidPoint(JNIEnv
*jenv
, jobject jobj
) {
108 void Init(JNIEnv
*jenv
, jobject jobj
);
110 int X() { return mX
; }
111 int Y() { return mY
; }
117 static jclass jPointClass
;
118 static jfieldID jXField
;
119 static jfieldID jYField
;
122 class AndroidRect
: public WrappedJavaObject
125 static void InitRectClass(JNIEnv
*jEnv
);
128 AndroidRect(JNIEnv
*jenv
, jobject jobj
) {
132 void Init(JNIEnv
*jenv
, jobject jobj
);
134 int Bottom() { return mBottom
; }
135 int Left() { return mLeft
; }
136 int Right() { return mRight
; }
137 int Top() { return mTop
; }
145 static jclass jRectClass
;
146 static jfieldID jBottomField
;
147 static jfieldID jLeftField
;
148 static jfieldID jRightField
;
149 static jfieldID jTopField
;
152 class AndroidGeckoSurfaceView
: public WrappedJavaObject
155 static void InitGeckoSurfaceViewClass(JNIEnv
*jEnv
);
157 AndroidGeckoSurfaceView() { }
158 AndroidGeckoSurfaceView(jobject jobj
) {
162 void Init(jobject jobj
);
170 jobject
GetSoftwareDrawBuffer();
172 void Draw2D(jobject buffer
, int stride
);
174 // must have a JNI local frame when calling this,
175 // and you'd better know what you're doing
176 jobject
GetSurfaceHolder();
179 static jclass jGeckoSurfaceViewClass
;
180 static jmethodID jBeginDrawingMethod
;
181 static jmethodID jEndDrawingMethod
;
182 static jmethodID jDraw2DMethod
;
183 static jmethodID jGetSoftwareDrawBufferMethod
;
184 static jmethodID jGetHolderMethod
;
187 class AndroidKeyEvent
192 KEYCODE_SOFT_LEFT
= 1,
193 KEYCODE_SOFT_RIGHT
= 2,
210 KEYCODE_DPAD_UP
= 19,
211 KEYCODE_DPAD_DOWN
= 20,
212 KEYCODE_DPAD_LEFT
= 21,
213 KEYCODE_DPAD_RIGHT
= 22,
214 KEYCODE_DPAD_CENTER
= 23,
215 KEYCODE_VOLUME_UP
= 24,
216 KEYCODE_VOLUME_DOWN
= 25,
248 KEYCODE_ALT_LEFT
= 57,
249 KEYCODE_ALT_RIGHT
= 58,
250 KEYCODE_SHIFT_LEFT
= 59,
251 KEYCODE_SHIFT_RIGHT
= 60,
255 KEYCODE_EXPLORER
= 64,
256 KEYCODE_ENVELOPE
= 65,
262 KEYCODE_LEFT_BRACKET
= 71,
263 KEYCODE_RIGHT_BRACKET
= 72,
264 KEYCODE_BACKSLASH
= 73,
265 KEYCODE_SEMICOLON
= 74,
266 KEYCODE_APOSTROPHE
= 75,
270 KEYCODE_HEADSETHOOK
= 79,
274 KEYCODE_NOTIFICATION
= 83,
276 KEYCODE_MEDIA_PLAY_PAUSE
= 85,
277 KEYCODE_MEDIA_STOP
= 86,
278 KEYCODE_MEDIA_NEXT
= 87,
279 KEYCODE_MEDIA_PREVIOUS
= 88,
280 KEYCODE_MEDIA_REWIND
= 89,
281 KEYCODE_MEDIA_FAST_FORWARD
= 90,
286 META_ALT_ON
= 0x00000002,
287 META_ALT_LEFT_ON
= 0x00000010,
288 META_ALT_RIGHT_ON
= 0x00000020,
289 META_SHIFT_ON
= 0x00000001,
290 META_SHIFT_LEFT_ON
= 0x00000040,
291 META_SHIFT_RIGHT_ON
= 0x00000080,
292 META_SYM_ON
= 0x00000004,
293 FLAG_WOKE_HERE
= 0x00000001,
294 FLAG_SOFT_KEYBOARD
= 0x00000002,
295 FLAG_KEEP_TOUCH_MODE
= 0x00000004,
296 FLAG_FROM_SYSTEM
= 0x00000008,
297 FLAG_EDITOR_ACTION
= 0x00000010,
298 FLAG_CANCELED
= 0x00000020,
299 FLAG_VIRTUAL_HARD_KEY
= 0x00000040,
300 FLAG_LONG_PRESS
= 0x00000080,
301 FLAG_CANCELED_LONG_PRESS
= 0x00000100,
302 FLAG_TRACKING
= 0x00000200,
303 FLAG_START_TRACKING
= 0x40000000,
304 dummy_java_enum_list_end
308 class AndroidMotionEvent
318 ACTION_POINTER_DOWN
= 5,
319 ACTION_POINTER_UP
= 6,
320 ACTION_POINTER_ID_MASK
= 0xff00,
321 ACTION_POINTER_ID_SHIFT
= 8,
322 EDGE_TOP
= 0x00000001,
323 EDGE_BOTTOM
= 0x00000002,
324 EDGE_LEFT
= 0x00000004,
325 EDGE_RIGHT
= 0x00000008,
331 dummy_java_enum_list_end
335 class AndroidLocation
: public WrappedJavaObject
338 static void InitLocationClass(JNIEnv
*jEnv
);
339 static nsGeoPosition
* CreateGeoPosition(JNIEnv
*jenv
, jobject jobj
);
340 static jclass jLocationClass
;
341 static jmethodID jGetLatitudeMethod
;
342 static jmethodID jGetLongitudeMethod
;
343 static jmethodID jGetAltitudeMethod
;
344 static jmethodID jGetAccuracyMethod
;
345 static jmethodID jGetBearingMethod
;
346 static jmethodID jGetSpeedMethod
;
347 static jmethodID jGetTimeMethod
;
350 class AndroidGeckoEvent
: public WrappedJavaObject
353 static void InitGeckoEventClass(JNIEnv
*jEnv
);
355 AndroidGeckoEvent() { }
356 AndroidGeckoEvent(int aType
) {
359 AndroidGeckoEvent(int x1
, int y1
, int x2
, int y2
) {
360 Init(x1
, y1
, x2
, y2
);
362 AndroidGeckoEvent(JNIEnv
*jenv
, jobject jobj
) {
366 void Init(JNIEnv
*jenv
, jobject jobj
);
367 void Init(int aType
);
368 void Init(int x1
, int y1
, int x2
, int y2
);
370 int Action() { return mAction
; }
371 int Type() { return mType
; }
372 int64_t Time() { return mTime
; }
373 const nsIntPoint
& P0() { return mP0
; }
374 const nsIntPoint
& P1() { return mP1
; }
375 float X() { return mX
; }
376 float Y() { return mY
; }
377 float Z() { return mZ
; }
378 const nsIntRect
& Rect() { return mRect
; }
379 nsAString
& Characters() { return mCharacters
; }
380 int KeyCode() { return mKeyCode
; }
381 int MetaState() { return mMetaState
; }
382 int Flags() { return mFlags
; }
383 int UnicodeChar() { return mUnicodeChar
; }
384 int Offset() { return mOffset
; }
385 int Count() { return mCount
; }
386 int RangeType() { return mRangeType
; }
387 int RangeStyles() { return mRangeStyles
; }
388 int RangeForeColor() { return mRangeForeColor
; }
389 int RangeBackColor() { return mRangeBackColor
; }
390 nsGeoPosition
* GeoPosition() { return mGeoPosition
; }
399 int mFlags
, mMetaState
;
400 int mKeyCode
, mUnicodeChar
;
402 int mRangeType
, mRangeStyles
;
403 int mRangeForeColor
, mRangeBackColor
;
405 nsString mCharacters
;
406 nsRefPtr
<nsGeoPosition
> mGeoPosition
;
408 void ReadP0Field(JNIEnv
*jenv
);
409 void ReadP1Field(JNIEnv
*jenv
);
410 void ReadRectField(JNIEnv
*jenv
);
411 void ReadCharactersField(JNIEnv
*jenv
);
413 static jclass jGeckoEventClass
;
414 static jfieldID jActionField
;
415 static jfieldID jTypeField
;
416 static jfieldID jTimeField
;
417 static jfieldID jP0Field
;
418 static jfieldID jP1Field
;
419 static jfieldID jXField
;
420 static jfieldID jYField
;
421 static jfieldID jZField
;
422 static jfieldID jRectField
;
423 static jfieldID jNativeWindowField
;
425 static jfieldID jCharactersField
;
426 static jfieldID jKeyCodeField
;
427 static jfieldID jMetaStateField
;
428 static jfieldID jFlagsField
;
429 static jfieldID jOffsetField
;
430 static jfieldID jCountField
;
431 static jfieldID jUnicodeCharField
;
432 static jfieldID jRangeTypeField
;
433 static jfieldID jRangeStylesField
;
434 static jfieldID jRangeForeColorField
;
435 static jfieldID jRangeBackColorField
;
436 static jfieldID jLocationField
;
448 ACTIVITY_STOPPING
= 8,
449 ACTIVITY_PAUSING
= 9,
450 ACTIVITY_SHUTDOWN
= 10,
452 SURFACE_CREATED
= 12,
453 SURFACE_DESTROYED
= 13,
454 dummy_java_enum_list_end
458 IME_COMPOSITION_END
= 0,
459 IME_COMPOSITION_BEGIN
= 1,
463 IME_SET_SELECTION
= 5,
464 IME_GET_SELECTION
= 6,
469 class nsJNIString
: public nsString
472 nsJNIString(jstring jstr
, JNIEnv
*jenv
= NULL
);