widget/android/AndroidJavaWrappers.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
michael@0 2 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef AndroidJavaWrappers_h__
michael@0 7 #define AndroidJavaWrappers_h__
michael@0 8
michael@0 9 #include <jni.h>
michael@0 10 #include <android/input.h>
michael@0 11 #include <android/log.h>
michael@0 12
michael@0 13 #include "nsGeoPosition.h"
michael@0 14 #include "nsRect.h"
michael@0 15 #include "nsString.h"
michael@0 16 #include "nsTArray.h"
michael@0 17 #include "nsIObserver.h"
michael@0 18 #include "nsIAndroidBridge.h"
michael@0 19 #include "mozilla/gfx/Rect.h"
michael@0 20 #include "mozilla/dom/Touch.h"
michael@0 21 #include "mozilla/EventForwards.h"
michael@0 22 #include "InputData.h"
michael@0 23 #include "Units.h"
michael@0 24
michael@0 25 //#define FORCE_ALOG 1
michael@0 26
michael@0 27 class nsIAndroidDisplayport;
michael@0 28 class nsIAndroidViewport;
michael@0 29 class nsIWidget;
michael@0 30
michael@0 31 namespace mozilla {
michael@0 32
michael@0 33 class AutoLocalJNIFrame;
michael@0 34
michael@0 35 void InitAndroidJavaWrappers(JNIEnv *jEnv);
michael@0 36
michael@0 37 /*
michael@0 38 * Note: do not store global refs to any WrappedJavaObject;
michael@0 39 * these are live only during a particular JNI method, as
michael@0 40 * NewGlobalRef is -not- called on the jobject.
michael@0 41 *
michael@0 42 * If this is needed, WrappedJavaObject can be extended to
michael@0 43 * handle it.
michael@0 44 */
michael@0 45
michael@0 46 class RefCountedJavaObject {
michael@0 47 public:
michael@0 48 RefCountedJavaObject(JNIEnv* env, jobject obj) : mRefCnt(0), mObject(env->NewGlobalRef(obj)) {}
michael@0 49
michael@0 50 ~RefCountedJavaObject();
michael@0 51
michael@0 52 int32_t AddRef() { return ++mRefCnt; }
michael@0 53
michael@0 54 int32_t Release() {
michael@0 55 int32_t refcnt = --mRefCnt;
michael@0 56 if (refcnt == 0)
michael@0 57 delete this;
michael@0 58 return refcnt;
michael@0 59 }
michael@0 60
michael@0 61 jobject GetObject() { return mObject; }
michael@0 62 private:
michael@0 63 int32_t mRefCnt;
michael@0 64 jobject mObject;
michael@0 65 };
michael@0 66
michael@0 67 class WrappedJavaObject {
michael@0 68 public:
michael@0 69 WrappedJavaObject() :
michael@0 70 wrapped_obj(nullptr)
michael@0 71 { }
michael@0 72
michael@0 73 WrappedJavaObject(jobject jobj) : wrapped_obj(nullptr) {
michael@0 74 Init(jobj);
michael@0 75 }
michael@0 76
michael@0 77 void Init(jobject jobj) {
michael@0 78 wrapped_obj = jobj;
michael@0 79 }
michael@0 80
michael@0 81 bool isNull() const {
michael@0 82 return wrapped_obj == nullptr;
michael@0 83 }
michael@0 84
michael@0 85 jobject wrappedObject() const {
michael@0 86 return wrapped_obj;
michael@0 87 }
michael@0 88
michael@0 89 protected:
michael@0 90 jobject wrapped_obj;
michael@0 91 };
michael@0 92
michael@0 93 class AutoGlobalWrappedJavaObject : protected WrappedJavaObject{
michael@0 94 public:
michael@0 95 AutoGlobalWrappedJavaObject() :
michael@0 96 wrapped_obj(nullptr)
michael@0 97 { }
michael@0 98
michael@0 99 AutoGlobalWrappedJavaObject(jobject jobj, JNIEnv* env) : wrapped_obj(nullptr) {
michael@0 100 Init(jobj, env);
michael@0 101 }
michael@0 102
michael@0 103 virtual ~AutoGlobalWrappedJavaObject();
michael@0 104 void Dispose();
michael@0 105
michael@0 106 void Init(jobject jobj, JNIEnv* env) {
michael@0 107 if (!isNull()) {
michael@0 108 env->DeleteGlobalRef(wrapped_obj);
michael@0 109 }
michael@0 110 wrapped_obj = env->NewGlobalRef(jobj);
michael@0 111 }
michael@0 112
michael@0 113 bool isNull() const {
michael@0 114 return wrapped_obj == nullptr;
michael@0 115 }
michael@0 116
michael@0 117 jobject wrappedObject() const {
michael@0 118 return wrapped_obj;
michael@0 119 }
michael@0 120
michael@0 121 protected:
michael@0 122 jobject wrapped_obj;
michael@0 123 };
michael@0 124
michael@0 125 class AndroidPoint : public WrappedJavaObject
michael@0 126 {
michael@0 127 public:
michael@0 128 static void InitPointClass(JNIEnv *jEnv);
michael@0 129
michael@0 130 AndroidPoint() { }
michael@0 131 AndroidPoint(JNIEnv *jenv, jobject jobj) {
michael@0 132 Init(jenv, jobj);
michael@0 133 }
michael@0 134
michael@0 135 void Init(JNIEnv *jenv, jobject jobj);
michael@0 136
michael@0 137 int X() { return mX; }
michael@0 138 int Y() { return mY; }
michael@0 139
michael@0 140 protected:
michael@0 141 int mX;
michael@0 142 int mY;
michael@0 143
michael@0 144 static jclass jPointClass;
michael@0 145 static jfieldID jXField;
michael@0 146 static jfieldID jYField;
michael@0 147 };
michael@0 148
michael@0 149 class AndroidRect : public WrappedJavaObject
michael@0 150 {
michael@0 151 public:
michael@0 152 static void InitRectClass(JNIEnv *jEnv);
michael@0 153
michael@0 154 AndroidRect() { }
michael@0 155 AndroidRect(JNIEnv *jenv, jobject jobj) {
michael@0 156 Init(jenv, jobj);
michael@0 157 }
michael@0 158
michael@0 159 void Init(JNIEnv *jenv, jobject jobj);
michael@0 160
michael@0 161 int Bottom() { return mBottom; }
michael@0 162 int Left() { return mLeft; }
michael@0 163 int Right() { return mRight; }
michael@0 164 int Top() { return mTop; }
michael@0 165 int Width() { return mRight - mLeft; }
michael@0 166 int Height() { return mBottom - mTop; }
michael@0 167
michael@0 168 protected:
michael@0 169 int mBottom;
michael@0 170 int mLeft;
michael@0 171 int mRight;
michael@0 172 int mTop;
michael@0 173
michael@0 174 static jclass jRectClass;
michael@0 175 static jfieldID jBottomField;
michael@0 176 static jfieldID jLeftField;
michael@0 177 static jfieldID jRightField;
michael@0 178 static jfieldID jTopField;
michael@0 179 };
michael@0 180
michael@0 181 class AndroidRectF : public WrappedJavaObject
michael@0 182 {
michael@0 183 public:
michael@0 184 static void InitRectFClass(JNIEnv *jEnv);
michael@0 185
michael@0 186 AndroidRectF() { }
michael@0 187 AndroidRectF(JNIEnv *jenv, jobject jobj) {
michael@0 188 Init(jenv, jobj);
michael@0 189 }
michael@0 190
michael@0 191 void Init(JNIEnv *jenv, jobject jobj);
michael@0 192
michael@0 193 float Bottom() { return mBottom; }
michael@0 194 float Left() { return mLeft; }
michael@0 195 float Right() { return mRight; }
michael@0 196 float Top() { return mTop; }
michael@0 197 float Width() { return mRight - mLeft; }
michael@0 198 float Height() { return mBottom - mTop; }
michael@0 199
michael@0 200 protected:
michael@0 201 float mBottom;
michael@0 202 float mLeft;
michael@0 203 float mRight;
michael@0 204 float mTop;
michael@0 205
michael@0 206 static jclass jRectClass;
michael@0 207 static jfieldID jBottomField;
michael@0 208 static jfieldID jLeftField;
michael@0 209 static jfieldID jRightField;
michael@0 210 static jfieldID jTopField;
michael@0 211 };
michael@0 212
michael@0 213 class AndroidLayerRendererFrame : public WrappedJavaObject {
michael@0 214 public:
michael@0 215 static void InitLayerRendererFrameClass(JNIEnv *jEnv);
michael@0 216
michael@0 217 void Init(JNIEnv *env, jobject jobj);
michael@0 218 void Dispose(JNIEnv *env);
michael@0 219
michael@0 220 bool BeginDrawing(AutoLocalJNIFrame *jniFrame);
michael@0 221 bool DrawBackground(AutoLocalJNIFrame *jniFrame);
michael@0 222 bool DrawForeground(AutoLocalJNIFrame *jniFrame);
michael@0 223 bool EndDrawing(AutoLocalJNIFrame *jniFrame);
michael@0 224
michael@0 225 private:
michael@0 226 static jclass jLayerRendererFrameClass;
michael@0 227 static jmethodID jBeginDrawingMethod;
michael@0 228 static jmethodID jDrawBackgroundMethod;
michael@0 229 static jmethodID jDrawForegroundMethod;
michael@0 230 static jmethodID jEndDrawingMethod;
michael@0 231 };
michael@0 232
michael@0 233 enum {
michael@0 234 // These keycode masks are not defined in android/keycodes.h:
michael@0 235 AKEYCODE_ESCAPE = 111,
michael@0 236 AKEYCODE_FORWARD_DEL = 112,
michael@0 237 AKEYCODE_CTRL_LEFT = 113,
michael@0 238 AKEYCODE_CTRL_RIGHT = 114,
michael@0 239 AKEYCODE_CAPS_LOCK = 115,
michael@0 240 AKEYCODE_SCROLL_LOCK = 116,
michael@0 241 AKEYCODE_META_LEFT = 117,
michael@0 242 AKEYCODE_META_RIGHT = 118,
michael@0 243 AKEYCODE_FUNCTION = 119,
michael@0 244 AKEYCODE_SYSRQ = 120,
michael@0 245 AKEYCODE_BREAK = 121,
michael@0 246 AKEYCODE_MOVE_HOME = 122,
michael@0 247 AKEYCODE_MOVE_END = 123,
michael@0 248 AKEYCODE_INSERT = 124,
michael@0 249 AKEYCODE_FORWARD = 125,
michael@0 250 AKEYCODE_MEDIA_PLAY = 126,
michael@0 251 AKEYCODE_MEDIA_PAUSE = 127,
michael@0 252 AKEYCODE_MEDIA_CLOSE = 128,
michael@0 253 AKEYCODE_MEDIA_EJECT = 129,
michael@0 254 AKEYCODE_MEDIA_RECORD = 130,
michael@0 255 AKEYCODE_F1 = 131,
michael@0 256 AKEYCODE_F2 = 132,
michael@0 257 AKEYCODE_F3 = 133,
michael@0 258 AKEYCODE_F4 = 134,
michael@0 259 AKEYCODE_F5 = 135,
michael@0 260 AKEYCODE_F6 = 136,
michael@0 261 AKEYCODE_F7 = 137,
michael@0 262 AKEYCODE_F8 = 138,
michael@0 263 AKEYCODE_F9 = 139,
michael@0 264 AKEYCODE_F10 = 140,
michael@0 265 AKEYCODE_F11 = 141,
michael@0 266 AKEYCODE_F12 = 142,
michael@0 267 AKEYCODE_NUM_LOCK = 143,
michael@0 268 AKEYCODE_NUMPAD_0 = 144,
michael@0 269 AKEYCODE_NUMPAD_1 = 145,
michael@0 270 AKEYCODE_NUMPAD_2 = 146,
michael@0 271 AKEYCODE_NUMPAD_3 = 147,
michael@0 272 AKEYCODE_NUMPAD_4 = 148,
michael@0 273 AKEYCODE_NUMPAD_5 = 149,
michael@0 274 AKEYCODE_NUMPAD_6 = 150,
michael@0 275 AKEYCODE_NUMPAD_7 = 151,
michael@0 276 AKEYCODE_NUMPAD_8 = 152,
michael@0 277 AKEYCODE_NUMPAD_9 = 153,
michael@0 278 AKEYCODE_NUMPAD_DIVIDE = 154,
michael@0 279 AKEYCODE_NUMPAD_MULTIPLY = 155,
michael@0 280 AKEYCODE_NUMPAD_SUBTRACT = 156,
michael@0 281 AKEYCODE_NUMPAD_ADD = 157,
michael@0 282 AKEYCODE_NUMPAD_DOT = 158,
michael@0 283 AKEYCODE_NUMPAD_COMMA = 159,
michael@0 284 AKEYCODE_NUMPAD_ENTER = 160,
michael@0 285 AKEYCODE_NUMPAD_EQUALS = 161,
michael@0 286 AKEYCODE_NUMPAD_LEFT_PAREN = 162,
michael@0 287 AKEYCODE_NUMPAD_RIGHT_PAREN = 163,
michael@0 288 AKEYCODE_VOLUME_MUTE = 164,
michael@0 289 AKEYCODE_INFO = 165,
michael@0 290 AKEYCODE_CHANNEL_UP = 166,
michael@0 291 AKEYCODE_CHANNEL_DOWN = 167,
michael@0 292 AKEYCODE_ZOOM_IN = 168,
michael@0 293 AKEYCODE_ZOOM_OUT = 169,
michael@0 294 AKEYCODE_TV = 170,
michael@0 295 AKEYCODE_WINDOW = 171,
michael@0 296 AKEYCODE_GUIDE = 172,
michael@0 297 AKEYCODE_DVR = 173,
michael@0 298 AKEYCODE_BOOKMARK = 174,
michael@0 299 AKEYCODE_CAPTIONS = 175,
michael@0 300 AKEYCODE_SETTINGS = 176,
michael@0 301 AKEYCODE_TV_POWER = 177,
michael@0 302 AKEYCODE_TV_INPUT = 178,
michael@0 303 AKEYCODE_STB_POWER = 179,
michael@0 304 AKEYCODE_STB_INPUT = 180,
michael@0 305 AKEYCODE_AVR_POWER = 181,
michael@0 306 AKEYCODE_AVR_INPUT = 182,
michael@0 307 AKEYCODE_PROG_RED = 183,
michael@0 308 AKEYCODE_PROG_GREEN = 184,
michael@0 309 AKEYCODE_PROG_YELLOW = 185,
michael@0 310 AKEYCODE_PROG_BLUE = 186,
michael@0 311 AKEYCODE_APP_SWITCH = 187,
michael@0 312 AKEYCODE_BUTTON_1 = 188,
michael@0 313 AKEYCODE_BUTTON_2 = 189,
michael@0 314 AKEYCODE_BUTTON_3 = 190,
michael@0 315 AKEYCODE_BUTTON_4 = 191,
michael@0 316 AKEYCODE_BUTTON_5 = 192,
michael@0 317 AKEYCODE_BUTTON_6 = 193,
michael@0 318 AKEYCODE_BUTTON_7 = 194,
michael@0 319 AKEYCODE_BUTTON_8 = 195,
michael@0 320 AKEYCODE_BUTTON_9 = 196,
michael@0 321 AKEYCODE_BUTTON_10 = 197,
michael@0 322 AKEYCODE_BUTTON_11 = 198,
michael@0 323 AKEYCODE_BUTTON_12 = 199,
michael@0 324 AKEYCODE_BUTTON_13 = 200,
michael@0 325 AKEYCODE_BUTTON_14 = 201,
michael@0 326 AKEYCODE_BUTTON_15 = 202,
michael@0 327 AKEYCODE_BUTTON_16 = 203,
michael@0 328 AKEYCODE_LANGUAGE_SWITCH = 204,
michael@0 329 AKEYCODE_MANNER_MODE = 205,
michael@0 330 AKEYCODE_3D_MODE = 206,
michael@0 331 AKEYCODE_CONTACTS = 207,
michael@0 332 AKEYCODE_CALENDAR = 208,
michael@0 333 AKEYCODE_MUSIC = 209,
michael@0 334 AKEYCODE_CALCULATOR = 210,
michael@0 335 AKEYCODE_ZENKAKU_HANKAKU = 211,
michael@0 336 AKEYCODE_EISU = 212,
michael@0 337 AKEYCODE_MUHENKAN = 213,
michael@0 338 AKEYCODE_HENKAN = 214,
michael@0 339 AKEYCODE_KATAKANA_HIRAGANA = 215,
michael@0 340 AKEYCODE_YEN = 216,
michael@0 341 AKEYCODE_RO = 217,
michael@0 342 AKEYCODE_KANA = 218,
michael@0 343 AKEYCODE_ASSIST = 219,
michael@0 344
michael@0 345 AMETA_FUNCTION_ON = 0x00000008,
michael@0 346 AMETA_CTRL_ON = 0x00001000,
michael@0 347 AMETA_CTRL_LEFT_ON = 0x00002000,
michael@0 348 AMETA_CTRL_RIGHT_ON = 0x00004000,
michael@0 349 AMETA_META_ON = 0x00010000,
michael@0 350 AMETA_META_LEFT_ON = 0x00020000,
michael@0 351 AMETA_META_RIGHT_ON = 0x00040000,
michael@0 352 AMETA_CAPS_LOCK_ON = 0x00100000,
michael@0 353 AMETA_NUM_LOCK_ON = 0x00200000,
michael@0 354 AMETA_SCROLL_LOCK_ON = 0x00400000,
michael@0 355
michael@0 356 AMETA_ALT_MASK = AMETA_ALT_LEFT_ON | AMETA_ALT_RIGHT_ON | AMETA_ALT_ON,
michael@0 357 AMETA_CTRL_MASK = AMETA_CTRL_LEFT_ON | AMETA_CTRL_RIGHT_ON | AMETA_CTRL_ON,
michael@0 358 AMETA_META_MASK = AMETA_META_LEFT_ON | AMETA_META_RIGHT_ON | AMETA_META_ON,
michael@0 359 AMETA_SHIFT_MASK = AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_RIGHT_ON | AMETA_SHIFT_ON,
michael@0 360 };
michael@0 361
michael@0 362 class nsAndroidDisplayport MOZ_FINAL : public nsIAndroidDisplayport
michael@0 363 {
michael@0 364 public:
michael@0 365 NS_DECL_ISUPPORTS
michael@0 366 virtual nsresult GetLeft(float *aLeft) { *aLeft = mLeft; return NS_OK; }
michael@0 367 virtual nsresult GetTop(float *aTop) { *aTop = mTop; return NS_OK; }
michael@0 368 virtual nsresult GetRight(float *aRight) { *aRight = mRight; return NS_OK; }
michael@0 369 virtual nsresult GetBottom(float *aBottom) { *aBottom = mBottom; return NS_OK; }
michael@0 370 virtual nsresult GetResolution(float *aResolution) { *aResolution = mResolution; return NS_OK; }
michael@0 371 virtual nsresult SetLeft(float aLeft) { mLeft = aLeft; return NS_OK; }
michael@0 372 virtual nsresult SetTop(float aTop) { mTop = aTop; return NS_OK; }
michael@0 373 virtual nsresult SetRight(float aRight) { mRight = aRight; return NS_OK; }
michael@0 374 virtual nsresult SetBottom(float aBottom) { mBottom = aBottom; return NS_OK; }
michael@0 375 virtual nsresult SetResolution(float aResolution) { mResolution = aResolution; return NS_OK; }
michael@0 376
michael@0 377 nsAndroidDisplayport(AndroidRectF aRect, float aResolution):
michael@0 378 mLeft(aRect.Left()), mTop(aRect.Top()), mRight(aRect.Right()), mBottom(aRect.Bottom()), mResolution(aResolution) {}
michael@0 379
michael@0 380 private:
michael@0 381 ~nsAndroidDisplayport() {}
michael@0 382 float mLeft, mTop, mRight, mBottom, mResolution;
michael@0 383 };
michael@0 384
michael@0 385 class AndroidMotionEvent
michael@0 386 {
michael@0 387 public:
michael@0 388 enum {
michael@0 389 ACTION_DOWN = 0,
michael@0 390 ACTION_UP = 1,
michael@0 391 ACTION_MOVE = 2,
michael@0 392 ACTION_CANCEL = 3,
michael@0 393 ACTION_OUTSIDE = 4,
michael@0 394 ACTION_POINTER_DOWN = 5,
michael@0 395 ACTION_POINTER_UP = 6,
michael@0 396 ACTION_HOVER_MOVE = 7,
michael@0 397 ACTION_HOVER_ENTER = 9,
michael@0 398 ACTION_HOVER_EXIT = 10,
michael@0 399 ACTION_MAGNIFY_START = 11,
michael@0 400 ACTION_MAGNIFY = 12,
michael@0 401 ACTION_MAGNIFY_END = 13,
michael@0 402 EDGE_TOP = 0x00000001,
michael@0 403 EDGE_BOTTOM = 0x00000002,
michael@0 404 EDGE_LEFT = 0x00000004,
michael@0 405 EDGE_RIGHT = 0x00000008,
michael@0 406 SAMPLE_X = 0,
michael@0 407 SAMPLE_Y = 1,
michael@0 408 SAMPLE_PRESSURE = 2,
michael@0 409 SAMPLE_SIZE = 3,
michael@0 410 NUM_SAMPLE_DATA = 4,
michael@0 411 dummy_java_enum_list_end
michael@0 412 };
michael@0 413 };
michael@0 414
michael@0 415 class AndroidLocation : public WrappedJavaObject
michael@0 416 {
michael@0 417 public:
michael@0 418 static void InitLocationClass(JNIEnv *jEnv);
michael@0 419 static nsGeoPosition* CreateGeoPosition(JNIEnv *jenv, jobject jobj);
michael@0 420 static jclass jLocationClass;
michael@0 421 static jmethodID jGetLatitudeMethod;
michael@0 422 static jmethodID jGetLongitudeMethod;
michael@0 423 static jmethodID jGetAltitudeMethod;
michael@0 424 static jmethodID jGetAccuracyMethod;
michael@0 425 static jmethodID jGetBearingMethod;
michael@0 426 static jmethodID jGetSpeedMethod;
michael@0 427 static jmethodID jGetTimeMethod;
michael@0 428 };
michael@0 429
michael@0 430 class AndroidGeckoEvent : public WrappedJavaObject
michael@0 431 {
michael@0 432 private:
michael@0 433 AndroidGeckoEvent() {
michael@0 434 }
michael@0 435
michael@0 436 void Init(JNIEnv *jenv, jobject jobj);
michael@0 437 void Init(int aType);
michael@0 438 void Init(AndroidGeckoEvent *aResizeEvent);
michael@0 439
michael@0 440 public:
michael@0 441 static void InitGeckoEventClass(JNIEnv *jEnv);
michael@0 442
michael@0 443 static AndroidGeckoEvent* MakeNativePoke() {
michael@0 444 AndroidGeckoEvent *event = new AndroidGeckoEvent();
michael@0 445 event->Init(NATIVE_POKE);
michael@0 446 return event;
michael@0 447 }
michael@0 448
michael@0 449 static AndroidGeckoEvent* MakeIMEEvent(int aAction) {
michael@0 450 AndroidGeckoEvent *event = new AndroidGeckoEvent();
michael@0 451 event->Init(IME_EVENT);
michael@0 452 event->mAction = aAction;
michael@0 453 return event;
michael@0 454 }
michael@0 455
michael@0 456 static AndroidGeckoEvent* MakeDrawEvent(const nsIntRect& aRect) {
michael@0 457 AndroidGeckoEvent *event = new AndroidGeckoEvent();
michael@0 458 event->Init(DRAW);
michael@0 459 event->mRect = aRect;
michael@0 460 return event;
michael@0 461 }
michael@0 462
michael@0 463 static AndroidGeckoEvent* MakeFromJavaObject(JNIEnv *jenv, jobject jobj) {
michael@0 464 AndroidGeckoEvent *event = new AndroidGeckoEvent();
michael@0 465 event->Init(jenv, jobj);
michael@0 466 return event;
michael@0 467 }
michael@0 468
michael@0 469 static AndroidGeckoEvent* CopyResizeEvent(AndroidGeckoEvent *aResizeEvent) {
michael@0 470 AndroidGeckoEvent *event = new AndroidGeckoEvent();
michael@0 471 event->Init(aResizeEvent);
michael@0 472 return event;
michael@0 473 }
michael@0 474
michael@0 475 static AndroidGeckoEvent* MakeBroadcastEvent(const nsCString& topic, const nsCString& data) {
michael@0 476 AndroidGeckoEvent* event = new AndroidGeckoEvent();
michael@0 477 event->Init(BROADCAST);
michael@0 478 CopyUTF8toUTF16(topic, event->mCharacters);
michael@0 479 CopyUTF8toUTF16(data, event->mCharactersExtra);
michael@0 480 return event;
michael@0 481 }
michael@0 482
michael@0 483 static AndroidGeckoEvent* MakeAddObserver(const nsAString &key, nsIObserver *observer) {
michael@0 484 AndroidGeckoEvent *event = new AndroidGeckoEvent();
michael@0 485 event->Init(ADD_OBSERVER);
michael@0 486 event->mCharacters.Assign(key);
michael@0 487 event->mObserver = observer;
michael@0 488 return event;
michael@0 489 }
michael@0 490
michael@0 491 int Action() { return mAction; }
michael@0 492 int Type() { return mType; }
michael@0 493 bool AckNeeded() { return mAckNeeded; }
michael@0 494 int64_t Time() { return mTime; }
michael@0 495 const nsTArray<nsIntPoint>& Points() { return mPoints; }
michael@0 496 const nsTArray<int>& PointIndicies() { return mPointIndicies; }
michael@0 497 const nsTArray<float>& Pressures() { return mPressures; }
michael@0 498 const nsTArray<float>& Orientations() { return mOrientations; }
michael@0 499 const nsTArray<nsIntPoint>& PointRadii() { return mPointRadii; }
michael@0 500 const nsTArray<nsString>& PrefNames() { return mPrefNames; }
michael@0 501 double X() { return mX; }
michael@0 502 double Y() { return mY; }
michael@0 503 double Z() { return mZ; }
michael@0 504 const nsIntRect& Rect() { return mRect; }
michael@0 505 nsAString& Characters() { return mCharacters; }
michael@0 506 nsAString& CharactersExtra() { return mCharactersExtra; }
michael@0 507 nsAString& Data() { return mData; }
michael@0 508 int KeyCode() { return mKeyCode; }
michael@0 509 int MetaState() { return mMetaState; }
michael@0 510 uint32_t DomKeyLocation() { return mDomKeyLocation; }
michael@0 511 Modifiers DOMModifiers() const;
michael@0 512 bool IsAltPressed() const { return (mMetaState & AMETA_ALT_MASK) != 0; }
michael@0 513 bool IsShiftPressed() const { return (mMetaState & AMETA_SHIFT_MASK) != 0; }
michael@0 514 bool IsCtrlPressed() const { return (mMetaState & AMETA_CTRL_MASK) != 0; }
michael@0 515 bool IsMetaPressed() const { return (mMetaState & AMETA_META_MASK) != 0; }
michael@0 516 int Flags() { return mFlags; }
michael@0 517 int UnicodeChar() { return mUnicodeChar; }
michael@0 518 int BaseUnicodeChar() { return mBaseUnicodeChar; }
michael@0 519 int DOMPrintableKeyValue() { return mDOMPrintableKeyValue; }
michael@0 520 int RepeatCount() const { return mRepeatCount; }
michael@0 521 int Count() { return mCount; }
michael@0 522 int Start() { return mStart; }
michael@0 523 int End() { return mEnd; }
michael@0 524 int PointerIndex() { return mPointerIndex; }
michael@0 525 int RangeType() { return mRangeType; }
michael@0 526 int RangeStyles() { return mRangeStyles; }
michael@0 527 int RangeLineStyle() { return mRangeLineStyle; }
michael@0 528 bool RangeBoldLine() { return mRangeBoldLine; }
michael@0 529 int RangeForeColor() { return mRangeForeColor; }
michael@0 530 int RangeBackColor() { return mRangeBackColor; }
michael@0 531 int RangeLineColor() { return mRangeLineColor; }
michael@0 532 nsGeoPosition* GeoPosition() { return mGeoPosition; }
michael@0 533 int ConnectionType() { return mConnectionType; }
michael@0 534 bool IsWifi() { return mIsWifi; }
michael@0 535 int DHCPGateway() { return mDHCPGateway; }
michael@0 536 short ScreenOrientation() { return mScreenOrientation; }
michael@0 537 RefCountedJavaObject* ByteBuffer() { return mByteBuffer; }
michael@0 538 int Width() { return mWidth; }
michael@0 539 int Height() { return mHeight; }
michael@0 540 int RequestId() { return mCount; } // for convenience
michael@0 541 WidgetTouchEvent MakeTouchEvent(nsIWidget* widget);
michael@0 542 MultiTouchInput MakeMultiTouchInput(nsIWidget* widget);
michael@0 543 WidgetMouseEvent MakeMouseEvent(nsIWidget* widget);
michael@0 544 void UnionRect(nsIntRect const& aRect);
michael@0 545 nsIObserver *Observer() { return mObserver; }
michael@0 546
michael@0 547 protected:
michael@0 548 int mAction;
michael@0 549 int mType;
michael@0 550 bool mAckNeeded;
michael@0 551 int64_t mTime;
michael@0 552 nsTArray<nsIntPoint> mPoints;
michael@0 553 nsTArray<nsIntPoint> mPointRadii;
michael@0 554 nsTArray<int> mPointIndicies;
michael@0 555 nsTArray<float> mOrientations;
michael@0 556 nsTArray<float> mPressures;
michael@0 557 nsIntRect mRect;
michael@0 558 int mFlags, mMetaState;
michael@0 559 uint32_t mDomKeyLocation;
michael@0 560 int mKeyCode, mUnicodeChar, mBaseUnicodeChar, mDOMPrintableKeyValue;
michael@0 561 int mRepeatCount;
michael@0 562 int mCount;
michael@0 563 int mStart, mEnd;
michael@0 564 int mRangeType, mRangeStyles, mRangeLineStyle;
michael@0 565 bool mRangeBoldLine;
michael@0 566 int mRangeForeColor, mRangeBackColor, mRangeLineColor;
michael@0 567 double mX, mY, mZ;
michael@0 568 int mPointerIndex;
michael@0 569 nsString mCharacters, mCharactersExtra, mData;
michael@0 570 nsRefPtr<nsGeoPosition> mGeoPosition;
michael@0 571 int mConnectionType;
michael@0 572 bool mIsWifi;
michael@0 573 int mDHCPGateway;
michael@0 574 short mScreenOrientation;
michael@0 575 nsRefPtr<RefCountedJavaObject> mByteBuffer;
michael@0 576 int mWidth, mHeight;
michael@0 577 nsCOMPtr<nsIObserver> mObserver;
michael@0 578 nsTArray<nsString> mPrefNames;
michael@0 579
michael@0 580 void ReadIntArray(nsTArray<int> &aVals,
michael@0 581 JNIEnv *jenv,
michael@0 582 jfieldID field,
michael@0 583 int32_t count);
michael@0 584 void ReadFloatArray(nsTArray<float> &aVals,
michael@0 585 JNIEnv *jenv,
michael@0 586 jfieldID field,
michael@0 587 int32_t count);
michael@0 588 void ReadPointArray(nsTArray<nsIntPoint> &mPoints,
michael@0 589 JNIEnv *jenv,
michael@0 590 jfieldID field,
michael@0 591 int32_t count);
michael@0 592 void ReadStringArray(nsTArray<nsString> &aStrings,
michael@0 593 JNIEnv *jenv,
michael@0 594 jfieldID field);
michael@0 595 void ReadRectField(JNIEnv *jenv);
michael@0 596 void ReadCharactersField(JNIEnv *jenv);
michael@0 597 void ReadCharactersExtraField(JNIEnv *jenv);
michael@0 598 void ReadDataField(JNIEnv *jenv);
michael@0 599 void ReadStringFromJString(nsString &aString, JNIEnv *jenv, jstring s);
michael@0 600
michael@0 601 uint32_t ReadDomKeyLocation(JNIEnv* jenv, jobject jGeckoEventObj);
michael@0 602
michael@0 603 static jclass jGeckoEventClass;
michael@0 604 static jfieldID jActionField;
michael@0 605 static jfieldID jTypeField;
michael@0 606 static jfieldID jAckNeededField;
michael@0 607 static jfieldID jTimeField;
michael@0 608 static jfieldID jPoints;
michael@0 609 static jfieldID jPointIndicies;
michael@0 610 static jfieldID jOrientations;
michael@0 611 static jfieldID jPressures;
michael@0 612 static jfieldID jPointRadii;
michael@0 613 static jfieldID jXField;
michael@0 614 static jfieldID jYField;
michael@0 615 static jfieldID jZField;
michael@0 616 static jfieldID jDistanceField;
michael@0 617 static jfieldID jRectField;
michael@0 618 static jfieldID jNativeWindowField;
michael@0 619
michael@0 620 static jfieldID jCharactersField;
michael@0 621 static jfieldID jCharactersExtraField;
michael@0 622 static jfieldID jDataField;
michael@0 623 static jfieldID jDOMPrintableKeyValueField;
michael@0 624 static jfieldID jKeyCodeField;
michael@0 625 static jfieldID jMetaStateField;
michael@0 626 static jfieldID jDomKeyLocationField;
michael@0 627 static jfieldID jFlagsField;
michael@0 628 static jfieldID jCountField;
michael@0 629 static jfieldID jStartField;
michael@0 630 static jfieldID jEndField;
michael@0 631 static jfieldID jPointerIndexField;
michael@0 632 static jfieldID jUnicodeCharField;
michael@0 633 static jfieldID jBaseUnicodeCharField;
michael@0 634 static jfieldID jRepeatCountField;
michael@0 635 static jfieldID jRangeTypeField;
michael@0 636 static jfieldID jRangeStylesField;
michael@0 637 static jfieldID jRangeLineStyleField;
michael@0 638 static jfieldID jRangeBoldLineField;
michael@0 639 static jfieldID jRangeForeColorField;
michael@0 640 static jfieldID jRangeBackColorField;
michael@0 641 static jfieldID jRangeLineColorField;
michael@0 642 static jfieldID jLocationField;
michael@0 643 static jfieldID jPrefNamesField;
michael@0 644
michael@0 645 static jfieldID jConnectionTypeField;
michael@0 646 static jfieldID jIsWifiField;
michael@0 647 static jfieldID jDHCPGatewayField;
michael@0 648
michael@0 649 static jfieldID jScreenOrientationField;
michael@0 650 static jfieldID jByteBufferField;
michael@0 651
michael@0 652 static jfieldID jWidthField;
michael@0 653 static jfieldID jHeightField;
michael@0 654
michael@0 655 static jclass jDomKeyLocationClass;
michael@0 656 static jfieldID jDomKeyLocationValueField;
michael@0 657
michael@0 658 public:
michael@0 659 enum {
michael@0 660 NATIVE_POKE = 0,
michael@0 661 KEY_EVENT = 1,
michael@0 662 MOTION_EVENT = 2,
michael@0 663 SENSOR_EVENT = 3,
michael@0 664 LOCATION_EVENT = 5,
michael@0 665 IME_EVENT = 6,
michael@0 666 DRAW = 7,
michael@0 667 SIZE_CHANGED = 8,
michael@0 668 APP_BACKGROUNDING = 9,
michael@0 669 APP_FOREGROUNDING = 10,
michael@0 670 LOAD_URI = 12,
michael@0 671 NOOP = 15,
michael@0 672 FORCED_RESIZE = 16, // used internally in nsAppShell/nsWindow
michael@0 673 BROADCAST = 19,
michael@0 674 VIEWPORT = 20,
michael@0 675 VISITED = 21,
michael@0 676 NETWORK_CHANGED = 22,
michael@0 677 THUMBNAIL = 25,
michael@0 678 SCREENORIENTATION_CHANGED = 27,
michael@0 679 COMPOSITOR_CREATE = 28,
michael@0 680 COMPOSITOR_PAUSE = 29,
michael@0 681 COMPOSITOR_RESUME = 30,
michael@0 682 NATIVE_GESTURE_EVENT = 31,
michael@0 683 IME_KEY_EVENT = 32,
michael@0 684 CALL_OBSERVER = 33,
michael@0 685 REMOVE_OBSERVER = 34,
michael@0 686 LOW_MEMORY = 35,
michael@0 687 NETWORK_LINK_CHANGE = 36,
michael@0 688 TELEMETRY_HISTOGRAM_ADD = 37,
michael@0 689 ADD_OBSERVER = 38,
michael@0 690 PREFERENCES_OBSERVE = 39,
michael@0 691 PREFERENCES_GET = 40,
michael@0 692 PREFERENCES_REMOVE_OBSERVERS = 41,
michael@0 693 TELEMETRY_UI_SESSION_START = 42,
michael@0 694 TELEMETRY_UI_SESSION_STOP = 43,
michael@0 695 TELEMETRY_UI_EVENT = 44,
michael@0 696 dummy_java_enum_list_end
michael@0 697 };
michael@0 698
michael@0 699 enum {
michael@0 700 // Memory pressure levels. Keep these in sync with those in MemoryMonitor.java.
michael@0 701 MEMORY_PRESSURE_NONE = 0,
michael@0 702 MEMORY_PRESSURE_CLEANUP = 1,
michael@0 703 MEMORY_PRESSURE_LOW = 2,
michael@0 704 MEMORY_PRESSURE_MEDIUM = 3,
michael@0 705 MEMORY_PRESSURE_HIGH = 4
michael@0 706 };
michael@0 707
michael@0 708 enum {
michael@0 709 // Internal Gecko events
michael@0 710 IME_FLUSH_CHANGES = -2,
michael@0 711 IME_UPDATE_CONTEXT = -1,
michael@0 712 // Events from Java to Gecko
michael@0 713 IME_SYNCHRONIZE = 0,
michael@0 714 IME_REPLACE_TEXT = 1,
michael@0 715 IME_SET_SELECTION = 2,
michael@0 716 IME_ADD_COMPOSITION_RANGE = 3,
michael@0 717 IME_UPDATE_COMPOSITION = 4,
michael@0 718 IME_REMOVE_COMPOSITION = 5,
michael@0 719 IME_ACKNOWLEDGE_FOCUS = 6,
michael@0 720 dummy_ime_enum_list_end
michael@0 721 };
michael@0 722 };
michael@0 723
michael@0 724 class nsJNIString : public nsString
michael@0 725 {
michael@0 726 public:
michael@0 727 nsJNIString(jstring jstr, JNIEnv *jenv);
michael@0 728 };
michael@0 729
michael@0 730 }
michael@0 731
michael@0 732 #endif

mercurial