Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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 | #include "AndroidJavaWrappers.h" |
michael@0 | 7 | #include "AndroidBridge.h" |
michael@0 | 8 | #include "AndroidBridgeUtilities.h" |
michael@0 | 9 | #include "nsIDOMKeyEvent.h" |
michael@0 | 10 | #include "nsIWidget.h" |
michael@0 | 11 | #include "mozilla/BasicEvents.h" |
michael@0 | 12 | #include "mozilla/TouchEvents.h" |
michael@0 | 13 | |
michael@0 | 14 | using namespace mozilla; |
michael@0 | 15 | using namespace mozilla::dom; |
michael@0 | 16 | using namespace mozilla::widget::android; |
michael@0 | 17 | |
michael@0 | 18 | jclass AndroidGeckoEvent::jGeckoEventClass = 0; |
michael@0 | 19 | jfieldID AndroidGeckoEvent::jActionField = 0; |
michael@0 | 20 | jfieldID AndroidGeckoEvent::jTypeField = 0; |
michael@0 | 21 | jfieldID AndroidGeckoEvent::jAckNeededField = 0; |
michael@0 | 22 | jfieldID AndroidGeckoEvent::jTimeField = 0; |
michael@0 | 23 | jfieldID AndroidGeckoEvent::jPoints = 0; |
michael@0 | 24 | jfieldID AndroidGeckoEvent::jPointIndicies = 0; |
michael@0 | 25 | jfieldID AndroidGeckoEvent::jPressures = 0; |
michael@0 | 26 | jfieldID AndroidGeckoEvent::jPointRadii = 0; |
michael@0 | 27 | jfieldID AndroidGeckoEvent::jOrientations = 0; |
michael@0 | 28 | jfieldID AndroidGeckoEvent::jXField = 0; |
michael@0 | 29 | jfieldID AndroidGeckoEvent::jYField = 0; |
michael@0 | 30 | jfieldID AndroidGeckoEvent::jZField = 0; |
michael@0 | 31 | jfieldID AndroidGeckoEvent::jDistanceField = 0; |
michael@0 | 32 | jfieldID AndroidGeckoEvent::jRectField = 0; |
michael@0 | 33 | jfieldID AndroidGeckoEvent::jNativeWindowField = 0; |
michael@0 | 34 | |
michael@0 | 35 | jfieldID AndroidGeckoEvent::jCharactersField = 0; |
michael@0 | 36 | jfieldID AndroidGeckoEvent::jCharactersExtraField = 0; |
michael@0 | 37 | jfieldID AndroidGeckoEvent::jDataField = 0; |
michael@0 | 38 | jfieldID AndroidGeckoEvent::jDOMPrintableKeyValueField = 0; |
michael@0 | 39 | jfieldID AndroidGeckoEvent::jKeyCodeField = 0; |
michael@0 | 40 | jfieldID AndroidGeckoEvent::jMetaStateField = 0; |
michael@0 | 41 | jfieldID AndroidGeckoEvent::jDomKeyLocationField = 0; |
michael@0 | 42 | jfieldID AndroidGeckoEvent::jFlagsField = 0; |
michael@0 | 43 | jfieldID AndroidGeckoEvent::jUnicodeCharField = 0; |
michael@0 | 44 | jfieldID AndroidGeckoEvent::jBaseUnicodeCharField = 0; |
michael@0 | 45 | jfieldID AndroidGeckoEvent::jRepeatCountField = 0; |
michael@0 | 46 | jfieldID AndroidGeckoEvent::jCountField = 0; |
michael@0 | 47 | jfieldID AndroidGeckoEvent::jStartField = 0; |
michael@0 | 48 | jfieldID AndroidGeckoEvent::jEndField = 0; |
michael@0 | 49 | jfieldID AndroidGeckoEvent::jPointerIndexField = 0; |
michael@0 | 50 | jfieldID AndroidGeckoEvent::jRangeTypeField = 0; |
michael@0 | 51 | jfieldID AndroidGeckoEvent::jRangeStylesField = 0; |
michael@0 | 52 | jfieldID AndroidGeckoEvent::jRangeLineStyleField = 0; |
michael@0 | 53 | jfieldID AndroidGeckoEvent::jRangeBoldLineField = 0; |
michael@0 | 54 | jfieldID AndroidGeckoEvent::jRangeForeColorField = 0; |
michael@0 | 55 | jfieldID AndroidGeckoEvent::jRangeBackColorField = 0; |
michael@0 | 56 | jfieldID AndroidGeckoEvent::jRangeLineColorField = 0; |
michael@0 | 57 | jfieldID AndroidGeckoEvent::jLocationField = 0; |
michael@0 | 58 | jfieldID AndroidGeckoEvent::jConnectionTypeField = 0; |
michael@0 | 59 | jfieldID AndroidGeckoEvent::jIsWifiField = 0; |
michael@0 | 60 | jfieldID AndroidGeckoEvent::jDHCPGatewayField = 0; |
michael@0 | 61 | jfieldID AndroidGeckoEvent::jScreenOrientationField = 0; |
michael@0 | 62 | jfieldID AndroidGeckoEvent::jByteBufferField = 0; |
michael@0 | 63 | jfieldID AndroidGeckoEvent::jWidthField = 0; |
michael@0 | 64 | jfieldID AndroidGeckoEvent::jHeightField = 0; |
michael@0 | 65 | jfieldID AndroidGeckoEvent::jPrefNamesField = 0; |
michael@0 | 66 | |
michael@0 | 67 | jclass AndroidGeckoEvent::jDomKeyLocationClass = 0; |
michael@0 | 68 | jfieldID AndroidGeckoEvent::jDomKeyLocationValueField = 0; |
michael@0 | 69 | |
michael@0 | 70 | jclass AndroidPoint::jPointClass = 0; |
michael@0 | 71 | jfieldID AndroidPoint::jXField = 0; |
michael@0 | 72 | jfieldID AndroidPoint::jYField = 0; |
michael@0 | 73 | |
michael@0 | 74 | jclass AndroidRect::jRectClass = 0; |
michael@0 | 75 | jfieldID AndroidRect::jBottomField = 0; |
michael@0 | 76 | jfieldID AndroidRect::jLeftField = 0; |
michael@0 | 77 | jfieldID AndroidRect::jRightField = 0; |
michael@0 | 78 | jfieldID AndroidRect::jTopField = 0; |
michael@0 | 79 | |
michael@0 | 80 | jclass AndroidRectF::jRectClass = 0; |
michael@0 | 81 | jfieldID AndroidRectF::jBottomField = 0; |
michael@0 | 82 | jfieldID AndroidRectF::jLeftField = 0; |
michael@0 | 83 | jfieldID AndroidRectF::jRightField = 0; |
michael@0 | 84 | jfieldID AndroidRectF::jTopField = 0; |
michael@0 | 85 | |
michael@0 | 86 | jclass AndroidLocation::jLocationClass = 0; |
michael@0 | 87 | jmethodID AndroidLocation::jGetLatitudeMethod = 0; |
michael@0 | 88 | jmethodID AndroidLocation::jGetLongitudeMethod = 0; |
michael@0 | 89 | jmethodID AndroidLocation::jGetAltitudeMethod = 0; |
michael@0 | 90 | jmethodID AndroidLocation::jGetAccuracyMethod = 0; |
michael@0 | 91 | jmethodID AndroidLocation::jGetBearingMethod = 0; |
michael@0 | 92 | jmethodID AndroidLocation::jGetSpeedMethod = 0; |
michael@0 | 93 | jmethodID AndroidLocation::jGetTimeMethod = 0; |
michael@0 | 94 | |
michael@0 | 95 | jclass AndroidLayerRendererFrame::jLayerRendererFrameClass = 0; |
michael@0 | 96 | jmethodID AndroidLayerRendererFrame::jBeginDrawingMethod = 0; |
michael@0 | 97 | jmethodID AndroidLayerRendererFrame::jDrawBackgroundMethod = 0; |
michael@0 | 98 | jmethodID AndroidLayerRendererFrame::jDrawForegroundMethod = 0; |
michael@0 | 99 | jmethodID AndroidLayerRendererFrame::jEndDrawingMethod = 0; |
michael@0 | 100 | |
michael@0 | 101 | RefCountedJavaObject::~RefCountedJavaObject() { |
michael@0 | 102 | if (mObject) |
michael@0 | 103 | GetJNIForThread()->DeleteGlobalRef(mObject); |
michael@0 | 104 | mObject = nullptr; |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | void |
michael@0 | 108 | mozilla::InitAndroidJavaWrappers(JNIEnv *jEnv) |
michael@0 | 109 | { |
michael@0 | 110 | AndroidGeckoEvent::InitGeckoEventClass(jEnv); |
michael@0 | 111 | AndroidPoint::InitPointClass(jEnv); |
michael@0 | 112 | AndroidLocation::InitLocationClass(jEnv); |
michael@0 | 113 | AndroidRect::InitRectClass(jEnv); |
michael@0 | 114 | AndroidRectF::InitRectFClass(jEnv); |
michael@0 | 115 | AndroidLayerRendererFrame::InitLayerRendererFrameClass(jEnv); |
michael@0 | 116 | InitStubs(jEnv); |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | void |
michael@0 | 120 | AndroidGeckoEvent::InitGeckoEventClass(JNIEnv *jEnv) |
michael@0 | 121 | { |
michael@0 | 122 | initInit(); |
michael@0 | 123 | |
michael@0 | 124 | jGeckoEventClass = getClassGlobalRef("org/mozilla/gecko/GeckoEvent"); |
michael@0 | 125 | |
michael@0 | 126 | jActionField = getField("mAction", "I"); |
michael@0 | 127 | jTypeField = getField("mType", "I"); |
michael@0 | 128 | jAckNeededField = getField("mAckNeeded", "Z"); |
michael@0 | 129 | jTimeField = getField("mTime", "J"); |
michael@0 | 130 | jPoints = getField("mPoints", "[Landroid/graphics/Point;"); |
michael@0 | 131 | jPointIndicies = getField("mPointIndicies", "[I"); |
michael@0 | 132 | jOrientations = getField("mOrientations", "[F"); |
michael@0 | 133 | jPressures = getField("mPressures", "[F"); |
michael@0 | 134 | jPointRadii = getField("mPointRadii", "[Landroid/graphics/Point;"); |
michael@0 | 135 | jXField = getField("mX", "D"); |
michael@0 | 136 | jYField = getField("mY", "D"); |
michael@0 | 137 | jZField = getField("mZ", "D"); |
michael@0 | 138 | jRectField = getField("mRect", "Landroid/graphics/Rect;"); |
michael@0 | 139 | |
michael@0 | 140 | jCharactersField = getField("mCharacters", "Ljava/lang/String;"); |
michael@0 | 141 | jCharactersExtraField = getField("mCharactersExtra", "Ljava/lang/String;"); |
michael@0 | 142 | jDataField = getField("mData", "Ljava/lang/String;"); |
michael@0 | 143 | jKeyCodeField = getField("mKeyCode", "I"); |
michael@0 | 144 | jMetaStateField = getField("mMetaState", "I"); |
michael@0 | 145 | jDomKeyLocationField = getField("mDomKeyLocation", "Lorg/mozilla/gecko/GeckoEvent$DomKeyLocation;"); |
michael@0 | 146 | jFlagsField = getField("mFlags", "I"); |
michael@0 | 147 | jUnicodeCharField = getField("mUnicodeChar", "I"); |
michael@0 | 148 | jBaseUnicodeCharField = getField("mBaseUnicodeChar", "I"); |
michael@0 | 149 | jDOMPrintableKeyValueField = getField("mDOMPrintableKeyValue", "I"); |
michael@0 | 150 | jRepeatCountField = getField("mRepeatCount", "I"); |
michael@0 | 151 | jCountField = getField("mCount", "I"); |
michael@0 | 152 | jStartField = getField("mStart", "I"); |
michael@0 | 153 | jEndField = getField("mEnd", "I"); |
michael@0 | 154 | jPointerIndexField = getField("mPointerIndex", "I"); |
michael@0 | 155 | jRangeTypeField = getField("mRangeType", "I"); |
michael@0 | 156 | jRangeStylesField = getField("mRangeStyles", "I"); |
michael@0 | 157 | jRangeLineStyleField = getField("mRangeLineStyle", "I"); |
michael@0 | 158 | jRangeBoldLineField = getField("mRangeBoldLine", "Z"); |
michael@0 | 159 | jRangeForeColorField = getField("mRangeForeColor", "I"); |
michael@0 | 160 | jRangeBackColorField = getField("mRangeBackColor", "I"); |
michael@0 | 161 | jRangeLineColorField = getField("mRangeLineColor", "I"); |
michael@0 | 162 | jLocationField = getField("mLocation", "Landroid/location/Location;"); |
michael@0 | 163 | jConnectionTypeField = getField("mConnectionType", "I"); |
michael@0 | 164 | jIsWifiField = getField("mIsWifi", "Z"); |
michael@0 | 165 | jDHCPGatewayField = getField("mDHCPGateway", "I"); |
michael@0 | 166 | jScreenOrientationField = getField("mScreenOrientation", "S"); |
michael@0 | 167 | jByteBufferField = getField("mBuffer", "Ljava/nio/ByteBuffer;"); |
michael@0 | 168 | jWidthField = getField("mWidth", "I"); |
michael@0 | 169 | jHeightField = getField("mHeight", "I"); |
michael@0 | 170 | jPrefNamesField = getField("mPrefNames", "[Ljava/lang/String;"); |
michael@0 | 171 | |
michael@0 | 172 | // Init GeckoEvent.DomKeyLocation enum |
michael@0 | 173 | jDomKeyLocationClass = getClassGlobalRef("org/mozilla/gecko/GeckoEvent$DomKeyLocation"); |
michael@0 | 174 | jDomKeyLocationValueField = getField("value", "I"); |
michael@0 | 175 | } |
michael@0 | 176 | |
michael@0 | 177 | void |
michael@0 | 178 | AndroidLocation::InitLocationClass(JNIEnv *jEnv) |
michael@0 | 179 | { |
michael@0 | 180 | initInit(); |
michael@0 | 181 | |
michael@0 | 182 | jLocationClass = getClassGlobalRef("android/location/Location"); |
michael@0 | 183 | jGetLatitudeMethod = getMethod("getLatitude", "()D"); |
michael@0 | 184 | jGetLongitudeMethod = getMethod("getLongitude", "()D"); |
michael@0 | 185 | jGetAltitudeMethod = getMethod("getAltitude", "()D"); |
michael@0 | 186 | jGetAccuracyMethod = getMethod("getAccuracy", "()F"); |
michael@0 | 187 | jGetBearingMethod = getMethod("getBearing", "()F"); |
michael@0 | 188 | jGetSpeedMethod = getMethod("getSpeed", "()F"); |
michael@0 | 189 | jGetTimeMethod = getMethod("getTime", "()J"); |
michael@0 | 190 | } |
michael@0 | 191 | |
michael@0 | 192 | nsGeoPosition* |
michael@0 | 193 | AndroidLocation::CreateGeoPosition(JNIEnv *jenv, jobject jobj) |
michael@0 | 194 | { |
michael@0 | 195 | AutoLocalJNIFrame jniFrame(jenv); |
michael@0 | 196 | |
michael@0 | 197 | double latitude = jenv->CallDoubleMethod(jobj, jGetLatitudeMethod); |
michael@0 | 198 | if (jniFrame.CheckForException()) return nullptr; |
michael@0 | 199 | double longitude = jenv->CallDoubleMethod(jobj, jGetLongitudeMethod); |
michael@0 | 200 | if (jniFrame.CheckForException()) return nullptr; |
michael@0 | 201 | double altitude = jenv->CallDoubleMethod(jobj, jGetAltitudeMethod); |
michael@0 | 202 | if (jniFrame.CheckForException()) return nullptr; |
michael@0 | 203 | float accuracy = jenv->CallFloatMethod (jobj, jGetAccuracyMethod); |
michael@0 | 204 | if (jniFrame.CheckForException()) return nullptr; |
michael@0 | 205 | float bearing = jenv->CallFloatMethod (jobj, jGetBearingMethod); |
michael@0 | 206 | if (jniFrame.CheckForException()) return nullptr; |
michael@0 | 207 | float speed = jenv->CallFloatMethod (jobj, jGetSpeedMethod); |
michael@0 | 208 | if (jniFrame.CheckForException()) return nullptr; |
michael@0 | 209 | long long time = jenv->CallLongMethod (jobj, jGetTimeMethod); |
michael@0 | 210 | if (jniFrame.CheckForException()) return nullptr; |
michael@0 | 211 | |
michael@0 | 212 | return new nsGeoPosition(latitude, longitude, |
michael@0 | 213 | altitude, accuracy, |
michael@0 | 214 | accuracy, bearing, |
michael@0 | 215 | speed, time); |
michael@0 | 216 | } |
michael@0 | 217 | |
michael@0 | 218 | void |
michael@0 | 219 | AndroidPoint::InitPointClass(JNIEnv *jEnv) |
michael@0 | 220 | { |
michael@0 | 221 | initInit(); |
michael@0 | 222 | |
michael@0 | 223 | jPointClass = getClassGlobalRef("android/graphics/Point"); |
michael@0 | 224 | |
michael@0 | 225 | jXField = getField("x", "I"); |
michael@0 | 226 | jYField = getField("y", "I"); |
michael@0 | 227 | } |
michael@0 | 228 | |
michael@0 | 229 | void |
michael@0 | 230 | AndroidRect::InitRectClass(JNIEnv *jEnv) |
michael@0 | 231 | { |
michael@0 | 232 | initInit(); |
michael@0 | 233 | |
michael@0 | 234 | jRectClass = getClassGlobalRef("android/graphics/Rect"); |
michael@0 | 235 | |
michael@0 | 236 | jBottomField = getField("bottom", "I"); |
michael@0 | 237 | jLeftField = getField("left", "I"); |
michael@0 | 238 | jTopField = getField("top", "I"); |
michael@0 | 239 | jRightField = getField("right", "I"); |
michael@0 | 240 | } |
michael@0 | 241 | |
michael@0 | 242 | void |
michael@0 | 243 | AndroidRectF::InitRectFClass(JNIEnv *jEnv) |
michael@0 | 244 | { |
michael@0 | 245 | initInit(); |
michael@0 | 246 | |
michael@0 | 247 | jRectClass = getClassGlobalRef("android/graphics/RectF"); |
michael@0 | 248 | |
michael@0 | 249 | jBottomField = getField("bottom", "F"); |
michael@0 | 250 | jLeftField = getField("left", "F"); |
michael@0 | 251 | jTopField = getField("top", "F"); |
michael@0 | 252 | jRightField = getField("right", "F"); |
michael@0 | 253 | } |
michael@0 | 254 | |
michael@0 | 255 | void |
michael@0 | 256 | AndroidLayerRendererFrame::InitLayerRendererFrameClass(JNIEnv *jEnv) |
michael@0 | 257 | { |
michael@0 | 258 | initInit(); |
michael@0 | 259 | |
michael@0 | 260 | jLayerRendererFrameClass = getClassGlobalRef("org/mozilla/gecko/gfx/LayerRenderer$Frame"); |
michael@0 | 261 | |
michael@0 | 262 | jBeginDrawingMethod = getMethod("beginDrawing", "()V"); |
michael@0 | 263 | jDrawBackgroundMethod = getMethod("drawBackground", "()V"); |
michael@0 | 264 | jDrawForegroundMethod = getMethod("drawForeground", "()V"); |
michael@0 | 265 | jEndDrawingMethod = getMethod("endDrawing", "()V"); |
michael@0 | 266 | } |
michael@0 | 267 | |
michael@0 | 268 | #undef initInit |
michael@0 | 269 | #undef initClassGlobalRef |
michael@0 | 270 | #undef getField |
michael@0 | 271 | #undef getMethod |
michael@0 | 272 | |
michael@0 | 273 | void |
michael@0 | 274 | AndroidGeckoEvent::ReadPointArray(nsTArray<nsIntPoint> &points, |
michael@0 | 275 | JNIEnv *jenv, |
michael@0 | 276 | jfieldID field, |
michael@0 | 277 | int32_t count) |
michael@0 | 278 | { |
michael@0 | 279 | jobjectArray jObjArray = (jobjectArray)jenv->GetObjectField(wrapped_obj, field); |
michael@0 | 280 | for (int32_t i = 0; i < count; i++) { |
michael@0 | 281 | jobject jObj = jenv->GetObjectArrayElement(jObjArray, i); |
michael@0 | 282 | AndroidPoint jpoint(jenv, jObj); |
michael@0 | 283 | |
michael@0 | 284 | nsIntPoint p(jpoint.X(), jpoint.Y()); |
michael@0 | 285 | points.AppendElement(p); |
michael@0 | 286 | } |
michael@0 | 287 | } |
michael@0 | 288 | |
michael@0 | 289 | void |
michael@0 | 290 | AndroidGeckoEvent::ReadIntArray(nsTArray<int> &aVals, |
michael@0 | 291 | JNIEnv *jenv, |
michael@0 | 292 | jfieldID field, |
michael@0 | 293 | int32_t count) |
michael@0 | 294 | { |
michael@0 | 295 | jintArray jIntArray = (jintArray)jenv->GetObjectField(wrapped_obj, field); |
michael@0 | 296 | jint *vals = jenv->GetIntArrayElements(jIntArray, nullptr); |
michael@0 | 297 | for (int32_t i = 0; i < count; i++) { |
michael@0 | 298 | aVals.AppendElement(vals[i]); |
michael@0 | 299 | } |
michael@0 | 300 | jenv->ReleaseIntArrayElements(jIntArray, vals, JNI_ABORT); |
michael@0 | 301 | } |
michael@0 | 302 | |
michael@0 | 303 | void |
michael@0 | 304 | AndroidGeckoEvent::ReadFloatArray(nsTArray<float> &aVals, |
michael@0 | 305 | JNIEnv *jenv, |
michael@0 | 306 | jfieldID field, |
michael@0 | 307 | int32_t count) |
michael@0 | 308 | { |
michael@0 | 309 | jfloatArray jFloatArray = (jfloatArray)jenv->GetObjectField(wrapped_obj, field); |
michael@0 | 310 | jfloat *vals = jenv->GetFloatArrayElements(jFloatArray, nullptr); |
michael@0 | 311 | for (int32_t i = 0; i < count; i++) { |
michael@0 | 312 | aVals.AppendElement(vals[i]); |
michael@0 | 313 | } |
michael@0 | 314 | jenv->ReleaseFloatArrayElements(jFloatArray, vals, JNI_ABORT); |
michael@0 | 315 | } |
michael@0 | 316 | |
michael@0 | 317 | void |
michael@0 | 318 | AndroidGeckoEvent::ReadStringArray(nsTArray<nsString> &array, |
michael@0 | 319 | JNIEnv *jenv, |
michael@0 | 320 | jfieldID field) |
michael@0 | 321 | { |
michael@0 | 322 | jarray jArray = (jarray)jenv->GetObjectField(wrapped_obj, field); |
michael@0 | 323 | jsize length = jenv->GetArrayLength(jArray); |
michael@0 | 324 | jobjectArray jStringArray = (jobjectArray)jArray; |
michael@0 | 325 | nsString *strings = array.AppendElements(length); |
michael@0 | 326 | for (jsize i = 0; i < length; ++i) { |
michael@0 | 327 | jstring javastring = (jstring) jenv->GetObjectArrayElement(jStringArray, i); |
michael@0 | 328 | ReadStringFromJString(strings[i], jenv, javastring); |
michael@0 | 329 | } |
michael@0 | 330 | } |
michael@0 | 331 | |
michael@0 | 332 | void |
michael@0 | 333 | AndroidGeckoEvent::ReadRectField(JNIEnv *jenv) |
michael@0 | 334 | { |
michael@0 | 335 | AndroidRect r(jenv, jenv->GetObjectField(wrappedObject(), jRectField)); |
michael@0 | 336 | if (!r.isNull()) { |
michael@0 | 337 | mRect.SetRect(r.Left(), |
michael@0 | 338 | r.Top(), |
michael@0 | 339 | r.Width(), |
michael@0 | 340 | r.Height()); |
michael@0 | 341 | } else { |
michael@0 | 342 | mRect.SetEmpty(); |
michael@0 | 343 | } |
michael@0 | 344 | } |
michael@0 | 345 | |
michael@0 | 346 | void |
michael@0 | 347 | AndroidGeckoEvent::ReadStringFromJString(nsString &aString, JNIEnv *jenv, |
michael@0 | 348 | jstring s) |
michael@0 | 349 | { |
michael@0 | 350 | if (!s) { |
michael@0 | 351 | aString.SetIsVoid(true); |
michael@0 | 352 | return; |
michael@0 | 353 | } |
michael@0 | 354 | |
michael@0 | 355 | int len = jenv->GetStringLength(s); |
michael@0 | 356 | aString.SetLength(len); |
michael@0 | 357 | jenv->GetStringRegion(s, 0, len, reinterpret_cast<jchar*>(aString.BeginWriting())); |
michael@0 | 358 | } |
michael@0 | 359 | |
michael@0 | 360 | void |
michael@0 | 361 | AndroidGeckoEvent::ReadCharactersField(JNIEnv *jenv) |
michael@0 | 362 | { |
michael@0 | 363 | jstring s = (jstring) jenv->GetObjectField(wrapped_obj, jCharactersField); |
michael@0 | 364 | ReadStringFromJString(mCharacters, jenv, s); |
michael@0 | 365 | } |
michael@0 | 366 | |
michael@0 | 367 | void |
michael@0 | 368 | AndroidGeckoEvent::ReadCharactersExtraField(JNIEnv *jenv) |
michael@0 | 369 | { |
michael@0 | 370 | jstring s = (jstring) jenv->GetObjectField(wrapped_obj, jCharactersExtraField); |
michael@0 | 371 | ReadStringFromJString(mCharactersExtra, jenv, s); |
michael@0 | 372 | } |
michael@0 | 373 | |
michael@0 | 374 | void |
michael@0 | 375 | AndroidGeckoEvent::ReadDataField(JNIEnv *jenv) |
michael@0 | 376 | { |
michael@0 | 377 | jstring s = (jstring) jenv->GetObjectField(wrapped_obj, jDataField); |
michael@0 | 378 | ReadStringFromJString(mData, jenv, s); |
michael@0 | 379 | } |
michael@0 | 380 | |
michael@0 | 381 | void |
michael@0 | 382 | AndroidGeckoEvent::UnionRect(nsIntRect const& aRect) |
michael@0 | 383 | { |
michael@0 | 384 | mRect = aRect.Union(mRect); |
michael@0 | 385 | } |
michael@0 | 386 | |
michael@0 | 387 | uint32_t |
michael@0 | 388 | AndroidGeckoEvent::ReadDomKeyLocation(JNIEnv* jenv, jobject jGeckoEventObj) |
michael@0 | 389 | { |
michael@0 | 390 | jobject enumObject = jenv->GetObjectField(jGeckoEventObj, |
michael@0 | 391 | jDomKeyLocationField); |
michael@0 | 392 | MOZ_ASSERT(enumObject); |
michael@0 | 393 | int enumValue = jenv->GetIntField(enumObject, jDomKeyLocationValueField); |
michael@0 | 394 | MOZ_ASSERT(enumValue >= nsIDOMKeyEvent::DOM_KEY_LOCATION_STANDARD && |
michael@0 | 395 | enumValue <= nsIDOMKeyEvent::DOM_KEY_LOCATION_JOYSTICK); |
michael@0 | 396 | return static_cast<uint32_t>(enumValue); |
michael@0 | 397 | } |
michael@0 | 398 | |
michael@0 | 399 | void |
michael@0 | 400 | AndroidGeckoEvent::Init(JNIEnv *jenv, jobject jobj) |
michael@0 | 401 | { |
michael@0 | 402 | NS_ASSERTION(!wrapped_obj, "Init called on non-null wrapped_obj!"); |
michael@0 | 403 | |
michael@0 | 404 | wrapped_obj = jobj; |
michael@0 | 405 | |
michael@0 | 406 | if (!jobj) |
michael@0 | 407 | return; |
michael@0 | 408 | |
michael@0 | 409 | mAction = jenv->GetIntField(jobj, jActionField); |
michael@0 | 410 | mType = jenv->GetIntField(jobj, jTypeField); |
michael@0 | 411 | mAckNeeded = jenv->GetBooleanField(jobj, jAckNeededField); |
michael@0 | 412 | |
michael@0 | 413 | switch (mType) { |
michael@0 | 414 | case SIZE_CHANGED: |
michael@0 | 415 | ReadPointArray(mPoints, jenv, jPoints, 2); |
michael@0 | 416 | break; |
michael@0 | 417 | |
michael@0 | 418 | case KEY_EVENT: |
michael@0 | 419 | case IME_KEY_EVENT: |
michael@0 | 420 | mTime = jenv->GetLongField(jobj, jTimeField); |
michael@0 | 421 | mMetaState = jenv->GetIntField(jobj, jMetaStateField); |
michael@0 | 422 | mDomKeyLocation = ReadDomKeyLocation(jenv, jobj); |
michael@0 | 423 | mFlags = jenv->GetIntField(jobj, jFlagsField); |
michael@0 | 424 | mKeyCode = jenv->GetIntField(jobj, jKeyCodeField); |
michael@0 | 425 | mUnicodeChar = jenv->GetIntField(jobj, jUnicodeCharField); |
michael@0 | 426 | mBaseUnicodeChar = jenv->GetIntField(jobj, jBaseUnicodeCharField); |
michael@0 | 427 | mDOMPrintableKeyValue = |
michael@0 | 428 | jenv->GetIntField(jobj, jDOMPrintableKeyValueField); |
michael@0 | 429 | mRepeatCount = jenv->GetIntField(jobj, jRepeatCountField); |
michael@0 | 430 | ReadCharactersField(jenv); |
michael@0 | 431 | break; |
michael@0 | 432 | |
michael@0 | 433 | case NATIVE_GESTURE_EVENT: |
michael@0 | 434 | mTime = jenv->GetLongField(jobj, jTimeField); |
michael@0 | 435 | mMetaState = jenv->GetIntField(jobj, jMetaStateField); |
michael@0 | 436 | mCount = jenv->GetIntField(jobj, jCountField); |
michael@0 | 437 | ReadPointArray(mPoints, jenv, jPoints, mCount); |
michael@0 | 438 | mX = jenv->GetDoubleField(jobj, jXField); |
michael@0 | 439 | |
michael@0 | 440 | break; |
michael@0 | 441 | |
michael@0 | 442 | case MOTION_EVENT: |
michael@0 | 443 | mTime = jenv->GetLongField(jobj, jTimeField); |
michael@0 | 444 | mMetaState = jenv->GetIntField(jobj, jMetaStateField); |
michael@0 | 445 | mCount = jenv->GetIntField(jobj, jCountField); |
michael@0 | 446 | mPointerIndex = jenv->GetIntField(jobj, jPointerIndexField); |
michael@0 | 447 | |
michael@0 | 448 | ReadPointArray(mPointRadii, jenv, jPointRadii, mCount); |
michael@0 | 449 | ReadFloatArray(mOrientations, jenv, jOrientations, mCount); |
michael@0 | 450 | ReadFloatArray(mPressures, jenv, jPressures, mCount); |
michael@0 | 451 | ReadPointArray(mPoints, jenv, jPoints, mCount); |
michael@0 | 452 | ReadIntArray(mPointIndicies, jenv, jPointIndicies, mCount); |
michael@0 | 453 | |
michael@0 | 454 | break; |
michael@0 | 455 | |
michael@0 | 456 | case IME_EVENT: |
michael@0 | 457 | mStart = jenv->GetIntField(jobj, jStartField); |
michael@0 | 458 | mEnd = jenv->GetIntField(jobj, jEndField); |
michael@0 | 459 | |
michael@0 | 460 | if (mAction == IME_REPLACE_TEXT) { |
michael@0 | 461 | ReadCharactersField(jenv); |
michael@0 | 462 | } else if (mAction == IME_UPDATE_COMPOSITION || |
michael@0 | 463 | mAction == IME_ADD_COMPOSITION_RANGE) { |
michael@0 | 464 | mRangeType = jenv->GetIntField(jobj, jRangeTypeField); |
michael@0 | 465 | mRangeStyles = jenv->GetIntField(jobj, jRangeStylesField); |
michael@0 | 466 | mRangeLineStyle = |
michael@0 | 467 | jenv->GetIntField(jobj, jRangeLineStyleField); |
michael@0 | 468 | mRangeBoldLine = |
michael@0 | 469 | jenv->GetBooleanField(jobj, jRangeBoldLineField); |
michael@0 | 470 | mRangeForeColor = |
michael@0 | 471 | jenv->GetIntField(jobj, jRangeForeColorField); |
michael@0 | 472 | mRangeBackColor = |
michael@0 | 473 | jenv->GetIntField(jobj, jRangeBackColorField); |
michael@0 | 474 | mRangeLineColor = |
michael@0 | 475 | jenv->GetIntField(jobj, jRangeLineColorField); |
michael@0 | 476 | } |
michael@0 | 477 | break; |
michael@0 | 478 | |
michael@0 | 479 | case DRAW: |
michael@0 | 480 | ReadRectField(jenv); |
michael@0 | 481 | break; |
michael@0 | 482 | |
michael@0 | 483 | case SENSOR_EVENT: |
michael@0 | 484 | mX = jenv->GetDoubleField(jobj, jXField); |
michael@0 | 485 | mY = jenv->GetDoubleField(jobj, jYField); |
michael@0 | 486 | mZ = jenv->GetDoubleField(jobj, jZField); |
michael@0 | 487 | mFlags = jenv->GetIntField(jobj, jFlagsField); |
michael@0 | 488 | mMetaState = jenv->GetIntField(jobj, jMetaStateField); |
michael@0 | 489 | break; |
michael@0 | 490 | |
michael@0 | 491 | case LOCATION_EVENT: { |
michael@0 | 492 | jobject location = jenv->GetObjectField(jobj, jLocationField); |
michael@0 | 493 | mGeoPosition = AndroidLocation::CreateGeoPosition(jenv, location); |
michael@0 | 494 | break; |
michael@0 | 495 | } |
michael@0 | 496 | |
michael@0 | 497 | case LOAD_URI: { |
michael@0 | 498 | ReadCharactersField(jenv); |
michael@0 | 499 | ReadCharactersExtraField(jenv); |
michael@0 | 500 | break; |
michael@0 | 501 | } |
michael@0 | 502 | |
michael@0 | 503 | case VIEWPORT: |
michael@0 | 504 | case BROADCAST: { |
michael@0 | 505 | ReadCharactersField(jenv); |
michael@0 | 506 | ReadCharactersExtraField(jenv); |
michael@0 | 507 | break; |
michael@0 | 508 | } |
michael@0 | 509 | |
michael@0 | 510 | case NETWORK_CHANGED: { |
michael@0 | 511 | mConnectionType = jenv->GetIntField(jobj, jConnectionTypeField); |
michael@0 | 512 | mIsWifi = jenv->GetBooleanField(jobj, jIsWifiField); |
michael@0 | 513 | mDHCPGateway = jenv->GetIntField(jobj, jDHCPGatewayField); |
michael@0 | 514 | break; |
michael@0 | 515 | } |
michael@0 | 516 | |
michael@0 | 517 | case VISITED: { |
michael@0 | 518 | ReadCharactersField(jenv); |
michael@0 | 519 | break; |
michael@0 | 520 | } |
michael@0 | 521 | |
michael@0 | 522 | case THUMBNAIL: { |
michael@0 | 523 | mMetaState = jenv->GetIntField(jobj, jMetaStateField); |
michael@0 | 524 | ReadPointArray(mPoints, jenv, jPoints, 1); |
michael@0 | 525 | mByteBuffer = new RefCountedJavaObject(jenv, jenv->GetObjectField(jobj, jByteBufferField)); |
michael@0 | 526 | break; |
michael@0 | 527 | } |
michael@0 | 528 | |
michael@0 | 529 | case SCREENORIENTATION_CHANGED: { |
michael@0 | 530 | mScreenOrientation = jenv->GetShortField(jobj, jScreenOrientationField); |
michael@0 | 531 | break; |
michael@0 | 532 | } |
michael@0 | 533 | |
michael@0 | 534 | case COMPOSITOR_CREATE: { |
michael@0 | 535 | mWidth = jenv->GetIntField(jobj, jWidthField); |
michael@0 | 536 | mHeight = jenv->GetIntField(jobj, jHeightField); |
michael@0 | 537 | break; |
michael@0 | 538 | } |
michael@0 | 539 | |
michael@0 | 540 | case CALL_OBSERVER: { |
michael@0 | 541 | ReadCharactersField(jenv); |
michael@0 | 542 | ReadCharactersExtraField(jenv); |
michael@0 | 543 | ReadDataField(jenv); |
michael@0 | 544 | break; |
michael@0 | 545 | } |
michael@0 | 546 | |
michael@0 | 547 | case REMOVE_OBSERVER: { |
michael@0 | 548 | ReadCharactersField(jenv); |
michael@0 | 549 | break; |
michael@0 | 550 | } |
michael@0 | 551 | |
michael@0 | 552 | case LOW_MEMORY: { |
michael@0 | 553 | mMetaState = jenv->GetIntField(jobj, jMetaStateField); |
michael@0 | 554 | break; |
michael@0 | 555 | } |
michael@0 | 556 | |
michael@0 | 557 | case NETWORK_LINK_CHANGE: { |
michael@0 | 558 | ReadCharactersField(jenv); |
michael@0 | 559 | break; |
michael@0 | 560 | } |
michael@0 | 561 | |
michael@0 | 562 | case TELEMETRY_HISTOGRAM_ADD: { |
michael@0 | 563 | ReadCharactersField(jenv); |
michael@0 | 564 | mCount = jenv->GetIntField(jobj, jCountField); |
michael@0 | 565 | break; |
michael@0 | 566 | } |
michael@0 | 567 | |
michael@0 | 568 | case TELEMETRY_UI_SESSION_START: { |
michael@0 | 569 | ReadCharactersField(jenv); |
michael@0 | 570 | mTime = jenv->GetLongField(jobj, jTimeField); |
michael@0 | 571 | break; |
michael@0 | 572 | } |
michael@0 | 573 | |
michael@0 | 574 | case TELEMETRY_UI_SESSION_STOP: { |
michael@0 | 575 | ReadCharactersField(jenv); |
michael@0 | 576 | ReadCharactersExtraField(jenv); |
michael@0 | 577 | mTime = jenv->GetLongField(jobj, jTimeField); |
michael@0 | 578 | break; |
michael@0 | 579 | } |
michael@0 | 580 | |
michael@0 | 581 | case TELEMETRY_UI_EVENT: { |
michael@0 | 582 | ReadCharactersField(jenv); |
michael@0 | 583 | ReadCharactersExtraField(jenv); |
michael@0 | 584 | ReadDataField(jenv); |
michael@0 | 585 | mTime = jenv->GetLongField(jobj, jTimeField); |
michael@0 | 586 | break; |
michael@0 | 587 | } |
michael@0 | 588 | |
michael@0 | 589 | case PREFERENCES_OBSERVE: |
michael@0 | 590 | case PREFERENCES_GET: { |
michael@0 | 591 | ReadStringArray(mPrefNames, jenv, jPrefNamesField); |
michael@0 | 592 | mCount = jenv->GetIntField(jobj, jCountField); |
michael@0 | 593 | break; |
michael@0 | 594 | } |
michael@0 | 595 | |
michael@0 | 596 | case PREFERENCES_REMOVE_OBSERVERS: { |
michael@0 | 597 | mCount = jenv->GetIntField(jobj, jCountField); |
michael@0 | 598 | break; |
michael@0 | 599 | } |
michael@0 | 600 | |
michael@0 | 601 | default: |
michael@0 | 602 | break; |
michael@0 | 603 | } |
michael@0 | 604 | |
michael@0 | 605 | #ifdef DEBUG_ANDROID_EVENTS |
michael@0 | 606 | ALOG("AndroidGeckoEvent: %p : %d", (void*)jobj, mType); |
michael@0 | 607 | #endif |
michael@0 | 608 | } |
michael@0 | 609 | |
michael@0 | 610 | void |
michael@0 | 611 | AndroidGeckoEvent::Init(int aType) |
michael@0 | 612 | { |
michael@0 | 613 | mType = aType; |
michael@0 | 614 | mAckNeeded = false; |
michael@0 | 615 | } |
michael@0 | 616 | |
michael@0 | 617 | void |
michael@0 | 618 | AndroidGeckoEvent::Init(AndroidGeckoEvent *aResizeEvent) |
michael@0 | 619 | { |
michael@0 | 620 | NS_ASSERTION(aResizeEvent->Type() == SIZE_CHANGED, "Init called on non-SIZE_CHANGED event"); |
michael@0 | 621 | |
michael@0 | 622 | mType = FORCED_RESIZE; |
michael@0 | 623 | mAckNeeded = false; |
michael@0 | 624 | mTime = aResizeEvent->mTime; |
michael@0 | 625 | mPoints = aResizeEvent->mPoints; // x,y coordinates |
michael@0 | 626 | } |
michael@0 | 627 | |
michael@0 | 628 | WidgetTouchEvent |
michael@0 | 629 | AndroidGeckoEvent::MakeTouchEvent(nsIWidget* widget) |
michael@0 | 630 | { |
michael@0 | 631 | int type = NS_EVENT_NULL; |
michael@0 | 632 | int startIndex = 0; |
michael@0 | 633 | int endIndex = Count(); |
michael@0 | 634 | |
michael@0 | 635 | switch (Action()) { |
michael@0 | 636 | case AndroidMotionEvent::ACTION_DOWN: |
michael@0 | 637 | case AndroidMotionEvent::ACTION_POINTER_DOWN: { |
michael@0 | 638 | type = NS_TOUCH_START; |
michael@0 | 639 | break; |
michael@0 | 640 | } |
michael@0 | 641 | case AndroidMotionEvent::ACTION_MOVE: { |
michael@0 | 642 | type = NS_TOUCH_MOVE; |
michael@0 | 643 | break; |
michael@0 | 644 | } |
michael@0 | 645 | case AndroidMotionEvent::ACTION_UP: |
michael@0 | 646 | case AndroidMotionEvent::ACTION_POINTER_UP: { |
michael@0 | 647 | type = NS_TOUCH_END; |
michael@0 | 648 | // for pointer-up events we only want the data from |
michael@0 | 649 | // the one pointer that went up |
michael@0 | 650 | startIndex = PointerIndex(); |
michael@0 | 651 | endIndex = startIndex + 1; |
michael@0 | 652 | break; |
michael@0 | 653 | } |
michael@0 | 654 | case AndroidMotionEvent::ACTION_OUTSIDE: |
michael@0 | 655 | case AndroidMotionEvent::ACTION_CANCEL: { |
michael@0 | 656 | type = NS_TOUCH_CANCEL; |
michael@0 | 657 | break; |
michael@0 | 658 | } |
michael@0 | 659 | } |
michael@0 | 660 | |
michael@0 | 661 | WidgetTouchEvent event(true, type, widget); |
michael@0 | 662 | if (type == NS_EVENT_NULL) { |
michael@0 | 663 | // An event we don't know about |
michael@0 | 664 | return event; |
michael@0 | 665 | } |
michael@0 | 666 | |
michael@0 | 667 | event.modifiers = DOMModifiers(); |
michael@0 | 668 | event.time = Time(); |
michael@0 | 669 | |
michael@0 | 670 | const nsIntPoint& offset = widget->WidgetToScreenOffset(); |
michael@0 | 671 | event.touches.SetCapacity(endIndex - startIndex); |
michael@0 | 672 | for (int i = startIndex; i < endIndex; i++) { |
michael@0 | 673 | // In this code branch, we are dispatching this event directly |
michael@0 | 674 | // into Gecko (as opposed to going through the AsyncPanZoomController), |
michael@0 | 675 | // and the Points() array has points in CSS pixels, which we need |
michael@0 | 676 | // to convert. |
michael@0 | 677 | CSSToLayoutDeviceScale scale = widget->GetDefaultScale(); |
michael@0 | 678 | nsIntPoint pt( |
michael@0 | 679 | (Points()[i].x * scale.scale) - offset.x, |
michael@0 | 680 | (Points()[i].y * scale.scale) - offset.y); |
michael@0 | 681 | nsIntPoint radii( |
michael@0 | 682 | PointRadii()[i].x * scale.scale, |
michael@0 | 683 | PointRadii()[i].y * scale.scale); |
michael@0 | 684 | nsRefPtr<Touch> t = new Touch(PointIndicies()[i], |
michael@0 | 685 | pt, |
michael@0 | 686 | radii, |
michael@0 | 687 | Orientations()[i], |
michael@0 | 688 | Pressures()[i]); |
michael@0 | 689 | event.touches.AppendElement(t); |
michael@0 | 690 | } |
michael@0 | 691 | |
michael@0 | 692 | return event; |
michael@0 | 693 | } |
michael@0 | 694 | |
michael@0 | 695 | MultiTouchInput |
michael@0 | 696 | AndroidGeckoEvent::MakeMultiTouchInput(nsIWidget* widget) |
michael@0 | 697 | { |
michael@0 | 698 | MultiTouchInput::MultiTouchType type = (MultiTouchInput::MultiTouchType)-1; |
michael@0 | 699 | int startIndex = 0; |
michael@0 | 700 | int endIndex = Count(); |
michael@0 | 701 | |
michael@0 | 702 | switch (Action()) { |
michael@0 | 703 | case AndroidMotionEvent::ACTION_DOWN: |
michael@0 | 704 | case AndroidMotionEvent::ACTION_POINTER_DOWN: { |
michael@0 | 705 | type = MultiTouchInput::MULTITOUCH_START; |
michael@0 | 706 | break; |
michael@0 | 707 | } |
michael@0 | 708 | case AndroidMotionEvent::ACTION_MOVE: { |
michael@0 | 709 | type = MultiTouchInput::MULTITOUCH_MOVE; |
michael@0 | 710 | break; |
michael@0 | 711 | } |
michael@0 | 712 | case AndroidMotionEvent::ACTION_UP: |
michael@0 | 713 | case AndroidMotionEvent::ACTION_POINTER_UP: { |
michael@0 | 714 | // for pointer-up events we only want the data from |
michael@0 | 715 | // the one pointer that went up |
michael@0 | 716 | startIndex = PointerIndex(); |
michael@0 | 717 | endIndex = startIndex + 1; |
michael@0 | 718 | type = MultiTouchInput::MULTITOUCH_END; |
michael@0 | 719 | break; |
michael@0 | 720 | } |
michael@0 | 721 | case AndroidMotionEvent::ACTION_OUTSIDE: |
michael@0 | 722 | case AndroidMotionEvent::ACTION_CANCEL: { |
michael@0 | 723 | type = MultiTouchInput::MULTITOUCH_CANCEL; |
michael@0 | 724 | break; |
michael@0 | 725 | } |
michael@0 | 726 | } |
michael@0 | 727 | |
michael@0 | 728 | MultiTouchInput event(type, Time(), 0); |
michael@0 | 729 | event.modifiers = DOMModifiers(); |
michael@0 | 730 | |
michael@0 | 731 | if (type < 0) { |
michael@0 | 732 | // An event we don't know about |
michael@0 | 733 | return event; |
michael@0 | 734 | } |
michael@0 | 735 | |
michael@0 | 736 | const nsIntPoint& offset = widget->WidgetToScreenOffset(); |
michael@0 | 737 | event.mTouches.SetCapacity(endIndex - startIndex); |
michael@0 | 738 | for (int i = startIndex; i < endIndex; i++) { |
michael@0 | 739 | nsIntPoint point = Points()[i] - offset; |
michael@0 | 740 | nsIntPoint radius = PointRadii()[i]; |
michael@0 | 741 | SingleTouchData data(PointIndicies()[i], |
michael@0 | 742 | ScreenIntPoint::FromUnknownPoint( |
michael@0 | 743 | gfx::IntPoint(point.x, point.y)), |
michael@0 | 744 | ScreenSize::FromUnknownSize( |
michael@0 | 745 | gfx::Size(radius.x, radius.y)), |
michael@0 | 746 | Orientations()[i], |
michael@0 | 747 | Pressures()[i]); |
michael@0 | 748 | event.mTouches.AppendElement(data); |
michael@0 | 749 | } |
michael@0 | 750 | |
michael@0 | 751 | return event; |
michael@0 | 752 | } |
michael@0 | 753 | |
michael@0 | 754 | WidgetMouseEvent |
michael@0 | 755 | AndroidGeckoEvent::MakeMouseEvent(nsIWidget* widget) |
michael@0 | 756 | { |
michael@0 | 757 | uint32_t msg = NS_EVENT_NULL; |
michael@0 | 758 | if (Points().Length() > 0) { |
michael@0 | 759 | switch (Action()) { |
michael@0 | 760 | case AndroidMotionEvent::ACTION_HOVER_MOVE: |
michael@0 | 761 | msg = NS_MOUSE_MOVE; |
michael@0 | 762 | break; |
michael@0 | 763 | case AndroidMotionEvent::ACTION_HOVER_ENTER: |
michael@0 | 764 | msg = NS_MOUSEENTER; |
michael@0 | 765 | break; |
michael@0 | 766 | case AndroidMotionEvent::ACTION_HOVER_EXIT: |
michael@0 | 767 | msg = NS_MOUSELEAVE; |
michael@0 | 768 | break; |
michael@0 | 769 | default: |
michael@0 | 770 | break; |
michael@0 | 771 | } |
michael@0 | 772 | } |
michael@0 | 773 | |
michael@0 | 774 | WidgetMouseEvent event(true, msg, widget, |
michael@0 | 775 | WidgetMouseEvent::eReal, WidgetMouseEvent::eNormal); |
michael@0 | 776 | |
michael@0 | 777 | if (msg == NS_EVENT_NULL) { |
michael@0 | 778 | // unknown type, or no point data. abort |
michael@0 | 779 | return event; |
michael@0 | 780 | } |
michael@0 | 781 | |
michael@0 | 782 | // XXX can we synthesize different buttons? |
michael@0 | 783 | event.button = WidgetMouseEvent::eLeftButton; |
michael@0 | 784 | if (msg != NS_MOUSE_MOVE) { |
michael@0 | 785 | event.clickCount = 1; |
michael@0 | 786 | } |
michael@0 | 787 | event.modifiers = DOMModifiers(); |
michael@0 | 788 | event.time = Time(); |
michael@0 | 789 | |
michael@0 | 790 | // We are dispatching this event directly into Gecko (as opposed to going |
michael@0 | 791 | // through the AsyncPanZoomController), and the Points() array has points |
michael@0 | 792 | // in CSS pixels, which we need to convert to LayoutDevice pixels. |
michael@0 | 793 | const nsIntPoint& offset = widget->WidgetToScreenOffset(); |
michael@0 | 794 | CSSToLayoutDeviceScale scale = widget->GetDefaultScale(); |
michael@0 | 795 | event.refPoint = LayoutDeviceIntPoint((Points()[0].x * scale.scale) - offset.x, |
michael@0 | 796 | (Points()[0].y * scale.scale) - offset.y); |
michael@0 | 797 | |
michael@0 | 798 | return event; |
michael@0 | 799 | } |
michael@0 | 800 | |
michael@0 | 801 | Modifiers |
michael@0 | 802 | AndroidGeckoEvent::DOMModifiers() const |
michael@0 | 803 | { |
michael@0 | 804 | Modifiers result = 0; |
michael@0 | 805 | if (mMetaState & AMETA_ALT_MASK) { |
michael@0 | 806 | result |= MODIFIER_ALT; |
michael@0 | 807 | } |
michael@0 | 808 | if (mMetaState & AMETA_SHIFT_MASK) { |
michael@0 | 809 | result |= MODIFIER_SHIFT; |
michael@0 | 810 | } |
michael@0 | 811 | if (mMetaState & AMETA_CTRL_MASK) { |
michael@0 | 812 | result |= MODIFIER_CONTROL; |
michael@0 | 813 | } |
michael@0 | 814 | if (mMetaState & AMETA_META_MASK) { |
michael@0 | 815 | result |= MODIFIER_META; |
michael@0 | 816 | } |
michael@0 | 817 | if (mMetaState & AMETA_FUNCTION_ON) { |
michael@0 | 818 | result |= MODIFIER_FN; |
michael@0 | 819 | } |
michael@0 | 820 | if (mMetaState & AMETA_CAPS_LOCK_ON) { |
michael@0 | 821 | result |= MODIFIER_CAPSLOCK; |
michael@0 | 822 | } |
michael@0 | 823 | if (mMetaState & AMETA_NUM_LOCK_ON) { |
michael@0 | 824 | result |= MODIFIER_NUMLOCK; |
michael@0 | 825 | } |
michael@0 | 826 | if (mMetaState & AMETA_SCROLL_LOCK_ON) { |
michael@0 | 827 | result |= MODIFIER_SCROLLLOCK; |
michael@0 | 828 | } |
michael@0 | 829 | return result; |
michael@0 | 830 | } |
michael@0 | 831 | |
michael@0 | 832 | void |
michael@0 | 833 | AndroidPoint::Init(JNIEnv *jenv, jobject jobj) |
michael@0 | 834 | { |
michael@0 | 835 | if (jobj) { |
michael@0 | 836 | mX = jenv->GetIntField(jobj, jXField); |
michael@0 | 837 | mY = jenv->GetIntField(jobj, jYField); |
michael@0 | 838 | } else { |
michael@0 | 839 | mX = 0; |
michael@0 | 840 | mY = 0; |
michael@0 | 841 | } |
michael@0 | 842 | } |
michael@0 | 843 | |
michael@0 | 844 | void |
michael@0 | 845 | AndroidLayerRendererFrame::Init(JNIEnv *env, jobject jobj) |
michael@0 | 846 | { |
michael@0 | 847 | if (!isNull()) { |
michael@0 | 848 | Dispose(env); |
michael@0 | 849 | } |
michael@0 | 850 | |
michael@0 | 851 | wrapped_obj = env->NewGlobalRef(jobj); |
michael@0 | 852 | } |
michael@0 | 853 | |
michael@0 | 854 | void |
michael@0 | 855 | AndroidLayerRendererFrame::Dispose(JNIEnv *env) |
michael@0 | 856 | { |
michael@0 | 857 | if (isNull()) { |
michael@0 | 858 | return; |
michael@0 | 859 | } |
michael@0 | 860 | |
michael@0 | 861 | env->DeleteGlobalRef(wrapped_obj); |
michael@0 | 862 | wrapped_obj = 0; |
michael@0 | 863 | } |
michael@0 | 864 | |
michael@0 | 865 | NS_IMPL_ISUPPORTS(nsAndroidDisplayport, nsIAndroidDisplayport) |
michael@0 | 866 | |
michael@0 | 867 | bool |
michael@0 | 868 | AndroidLayerRendererFrame::BeginDrawing(AutoLocalJNIFrame *jniFrame) |
michael@0 | 869 | { |
michael@0 | 870 | if (!jniFrame || !jniFrame->GetEnv()) |
michael@0 | 871 | return false; |
michael@0 | 872 | |
michael@0 | 873 | jniFrame->GetEnv()->CallVoidMethod(wrapped_obj, jBeginDrawingMethod); |
michael@0 | 874 | if (jniFrame->CheckForException()) |
michael@0 | 875 | return false; |
michael@0 | 876 | |
michael@0 | 877 | return true; |
michael@0 | 878 | } |
michael@0 | 879 | |
michael@0 | 880 | bool |
michael@0 | 881 | AndroidLayerRendererFrame::DrawBackground(AutoLocalJNIFrame *jniFrame) |
michael@0 | 882 | { |
michael@0 | 883 | if (!jniFrame || !jniFrame->GetEnv()) |
michael@0 | 884 | return false; |
michael@0 | 885 | |
michael@0 | 886 | jniFrame->GetEnv()->CallVoidMethod(wrapped_obj, jDrawBackgroundMethod); |
michael@0 | 887 | if (jniFrame->CheckForException()) |
michael@0 | 888 | return false; |
michael@0 | 889 | |
michael@0 | 890 | return true; |
michael@0 | 891 | } |
michael@0 | 892 | |
michael@0 | 893 | bool |
michael@0 | 894 | AndroidLayerRendererFrame::DrawForeground(AutoLocalJNIFrame *jniFrame) |
michael@0 | 895 | { |
michael@0 | 896 | if (!jniFrame || !jniFrame->GetEnv()) |
michael@0 | 897 | return false; |
michael@0 | 898 | |
michael@0 | 899 | jniFrame->GetEnv()->CallVoidMethod(wrapped_obj, jDrawForegroundMethod); |
michael@0 | 900 | if (jniFrame->CheckForException()) |
michael@0 | 901 | return false; |
michael@0 | 902 | |
michael@0 | 903 | return true; |
michael@0 | 904 | } |
michael@0 | 905 | |
michael@0 | 906 | bool |
michael@0 | 907 | AndroidLayerRendererFrame::EndDrawing(AutoLocalJNIFrame *jniFrame) |
michael@0 | 908 | { |
michael@0 | 909 | if (!jniFrame || !jniFrame->GetEnv()) |
michael@0 | 910 | return false; |
michael@0 | 911 | |
michael@0 | 912 | jniFrame->GetEnv()->CallVoidMethod(wrapped_obj, jEndDrawingMethod); |
michael@0 | 913 | if (jniFrame->CheckForException()) |
michael@0 | 914 | return false; |
michael@0 | 915 | |
michael@0 | 916 | return true; |
michael@0 | 917 | } |
michael@0 | 918 | |
michael@0 | 919 | void |
michael@0 | 920 | AndroidRect::Init(JNIEnv *jenv, jobject jobj) |
michael@0 | 921 | { |
michael@0 | 922 | NS_ASSERTION(wrapped_obj == nullptr, "Init called on non-null wrapped_obj!"); |
michael@0 | 923 | |
michael@0 | 924 | wrapped_obj = jobj; |
michael@0 | 925 | |
michael@0 | 926 | if (jobj) { |
michael@0 | 927 | mTop = jenv->GetIntField(jobj, jTopField); |
michael@0 | 928 | mLeft = jenv->GetIntField(jobj, jLeftField); |
michael@0 | 929 | mRight = jenv->GetIntField(jobj, jRightField); |
michael@0 | 930 | mBottom = jenv->GetIntField(jobj, jBottomField); |
michael@0 | 931 | } else { |
michael@0 | 932 | mTop = 0; |
michael@0 | 933 | mLeft = 0; |
michael@0 | 934 | mRight = 0; |
michael@0 | 935 | mBottom = 0; |
michael@0 | 936 | } |
michael@0 | 937 | } |
michael@0 | 938 | |
michael@0 | 939 | void |
michael@0 | 940 | AndroidRectF::Init(JNIEnv *jenv, jobject jobj) |
michael@0 | 941 | { |
michael@0 | 942 | NS_ASSERTION(wrapped_obj == nullptr, "Init called on non-null wrapped_obj!"); |
michael@0 | 943 | |
michael@0 | 944 | wrapped_obj = jobj; |
michael@0 | 945 | |
michael@0 | 946 | if (jobj) { |
michael@0 | 947 | mTop = jenv->GetFloatField(jobj, jTopField); |
michael@0 | 948 | mLeft = jenv->GetFloatField(jobj, jLeftField); |
michael@0 | 949 | mRight = jenv->GetFloatField(jobj, jRightField); |
michael@0 | 950 | mBottom = jenv->GetFloatField(jobj, jBottomField); |
michael@0 | 951 | } else { |
michael@0 | 952 | mTop = 0; |
michael@0 | 953 | mLeft = 0; |
michael@0 | 954 | mRight = 0; |
michael@0 | 955 | mBottom = 0; |
michael@0 | 956 | } |
michael@0 | 957 | } |
michael@0 | 958 | |
michael@0 | 959 | nsJNIString::nsJNIString(jstring jstr, JNIEnv *jenv) |
michael@0 | 960 | { |
michael@0 | 961 | if (!jstr) { |
michael@0 | 962 | SetIsVoid(true); |
michael@0 | 963 | return; |
michael@0 | 964 | } |
michael@0 | 965 | JNIEnv *jni = jenv; |
michael@0 | 966 | if (!jni) { |
michael@0 | 967 | jni = AndroidBridge::GetJNIEnv(); |
michael@0 | 968 | } |
michael@0 | 969 | const jchar* jCharPtr = jni->GetStringChars(jstr, nullptr); |
michael@0 | 970 | |
michael@0 | 971 | if (!jCharPtr) { |
michael@0 | 972 | SetIsVoid(true); |
michael@0 | 973 | return; |
michael@0 | 974 | } |
michael@0 | 975 | |
michael@0 | 976 | jsize len = jni->GetStringLength(jstr); |
michael@0 | 977 | |
michael@0 | 978 | if (len <= 0) { |
michael@0 | 979 | SetIsVoid(true); |
michael@0 | 980 | } else { |
michael@0 | 981 | Assign(reinterpret_cast<const char16_t*>(jCharPtr), len); |
michael@0 | 982 | } |
michael@0 | 983 | jni->ReleaseStringChars(jstr, jCharPtr); |
michael@0 | 984 | } |