2010-06-04 00:56:36 +04:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-06-04 00:56:36 +04:00
|
|
|
|
|
|
|
#include "AndroidJavaWrappers.h"
|
|
|
|
#include "AndroidBridge.h"
|
2013-09-09 16:57:36 +04:00
|
|
|
#include "AndroidBridgeUtilities.h"
|
2013-04-10 02:56:03 +04:00
|
|
|
#include "nsIDOMKeyEvent.h"
|
2013-05-18 00:17:53 +04:00
|
|
|
#include "nsIWidget.h"
|
2013-11-26 08:30:26 +04:00
|
|
|
#include "mozilla/BasicEvents.h"
|
2013-09-25 15:21:16 +04:00
|
|
|
#include "mozilla/TouchEvents.h"
|
2010-06-04 00:56:36 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2013-05-18 00:17:53 +04:00
|
|
|
using namespace mozilla::dom;
|
2013-11-12 22:41:01 +04:00
|
|
|
using namespace mozilla::widget::android;
|
2010-06-04 00:56:36 +04:00
|
|
|
|
|
|
|
jclass AndroidGeckoEvent::jGeckoEventClass = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jActionField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jTypeField = 0;
|
2013-03-11 02:43:30 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jAckNeededField = 0;
|
2010-06-04 00:56:36 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jTimeField = 0;
|
2012-01-25 04:31:33 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jPoints = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jPointIndicies = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jPressures = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jPointRadii = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jOrientations = 0;
|
2011-06-20 09:36:17 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jXField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jYField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jZField = 0;
|
2011-10-29 14:35:29 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jDistanceField = 0;
|
2010-06-04 00:56:36 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jRectField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jNativeWindowField = 0;
|
|
|
|
|
|
|
|
jfieldID AndroidGeckoEvent::jCharactersField = 0;
|
2011-11-15 07:12:14 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jCharactersExtraField = 0;
|
2013-06-16 01:40:27 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jDataField = 0;
|
2013-12-10 20:14:54 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jDOMPrintableKeyValueField = 0;
|
2010-06-04 00:56:36 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jKeyCodeField = 0;
|
2014-05-25 06:09:00 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jScanCodeField = 0;
|
2010-06-04 00:56:36 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jMetaStateField = 0;
|
2012-09-13 04:48:29 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jDomKeyLocationField = 0;
|
2010-06-04 00:56:36 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jFlagsField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jUnicodeCharField = 0;
|
2013-03-29 18:54:01 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jBaseUnicodeCharField = 0;
|
2012-04-20 00:55:33 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jRepeatCountField = 0;
|
2010-06-04 00:56:36 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jCountField = 0;
|
2012-11-02 00:11:02 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jStartField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jEndField = 0;
|
2012-01-25 04:31:33 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jPointerIndexField = 0;
|
2010-08-04 23:47:26 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jRangeTypeField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jRangeStylesField = 0;
|
2012-12-06 23:35:59 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jRangeLineStyleField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jRangeBoldLineField = 0;
|
2010-08-04 23:47:26 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jRangeForeColorField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jRangeBackColorField = 0;
|
2012-12-06 23:35:59 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jRangeLineColorField = 0;
|
2010-06-05 01:14:43 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jLocationField = 0;
|
2014-03-05 13:42:42 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jConnectionTypeField = 0;
|
2013-07-11 19:39:36 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jIsWifiField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jDHCPGatewayField = 0;
|
2012-03-20 17:09:45 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jScreenOrientationField = 0;
|
2012-06-14 20:08:51 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jByteBufferField = 0;
|
2013-03-21 02:45:07 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jWidthField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jHeightField = 0;
|
2014-04-22 18:53:48 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jIDField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jGamepadButtonField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jGamepadButtonPressedField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jGamepadButtonValueField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jGamepadValuesField = 0;
|
2013-09-04 17:58:08 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jPrefNamesField = 0;
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2013-04-10 02:56:03 +04:00
|
|
|
jclass AndroidGeckoEvent::jDomKeyLocationClass = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jDomKeyLocationValueField = 0;
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
jclass AndroidPoint::jPointClass = 0;
|
|
|
|
jfieldID AndroidPoint::jXField = 0;
|
|
|
|
jfieldID AndroidPoint::jYField = 0;
|
|
|
|
|
|
|
|
jclass AndroidRect::jRectClass = 0;
|
|
|
|
jfieldID AndroidRect::jBottomField = 0;
|
|
|
|
jfieldID AndroidRect::jLeftField = 0;
|
|
|
|
jfieldID AndroidRect::jRightField = 0;
|
|
|
|
jfieldID AndroidRect::jTopField = 0;
|
|
|
|
|
2012-09-13 01:47:08 +04:00
|
|
|
jclass AndroidRectF::jRectClass = 0;
|
|
|
|
jfieldID AndroidRectF::jBottomField = 0;
|
|
|
|
jfieldID AndroidRectF::jLeftField = 0;
|
|
|
|
jfieldID AndroidRectF::jRightField = 0;
|
|
|
|
jfieldID AndroidRectF::jTopField = 0;
|
|
|
|
|
2010-06-05 01:14:43 +04:00
|
|
|
jclass AndroidLocation::jLocationClass = 0;
|
|
|
|
jmethodID AndroidLocation::jGetLatitudeMethod = 0;
|
|
|
|
jmethodID AndroidLocation::jGetLongitudeMethod = 0;
|
|
|
|
jmethodID AndroidLocation::jGetAltitudeMethod = 0;
|
|
|
|
jmethodID AndroidLocation::jGetAccuracyMethod = 0;
|
|
|
|
jmethodID AndroidLocation::jGetBearingMethod = 0;
|
|
|
|
jmethodID AndroidLocation::jGetSpeedMethod = 0;
|
|
|
|
jmethodID AndroidLocation::jGetTimeMethod = 0;
|
|
|
|
|
2013-11-19 19:56:09 +04:00
|
|
|
jclass AndroidLayerRendererFrame::jLayerRendererFrameClass = 0;
|
|
|
|
jmethodID AndroidLayerRendererFrame::jBeginDrawingMethod = 0;
|
|
|
|
jmethodID AndroidLayerRendererFrame::jDrawBackgroundMethod = 0;
|
|
|
|
jmethodID AndroidLayerRendererFrame::jDrawForegroundMethod = 0;
|
|
|
|
jmethodID AndroidLayerRendererFrame::jEndDrawingMethod = 0;
|
|
|
|
|
2012-06-14 20:08:51 +04:00
|
|
|
RefCountedJavaObject::~RefCountedJavaObject() {
|
|
|
|
if (mObject)
|
|
|
|
GetJNIForThread()->DeleteGlobalRef(mObject);
|
2013-10-11 00:42:52 +04:00
|
|
|
mObject = nullptr;
|
2012-06-14 20:08:51 +04:00
|
|
|
}
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
void
|
|
|
|
mozilla::InitAndroidJavaWrappers(JNIEnv *jEnv)
|
|
|
|
{
|
|
|
|
AndroidGeckoEvent::InitGeckoEventClass(jEnv);
|
|
|
|
AndroidPoint::InitPointClass(jEnv);
|
2010-06-05 01:14:43 +04:00
|
|
|
AndroidLocation::InitLocationClass(jEnv);
|
2011-11-15 07:12:14 +04:00
|
|
|
AndroidRect::InitRectClass(jEnv);
|
2012-09-13 01:47:08 +04:00
|
|
|
AndroidRectF::InitRectFClass(jEnv);
|
2013-11-19 19:56:09 +04:00
|
|
|
AndroidLayerRendererFrame::InitLayerRendererFrameClass(jEnv);
|
2013-11-12 22:41:01 +04:00
|
|
|
InitStubs(jEnv);
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidGeckoEvent::InitGeckoEventClass(JNIEnv *jEnv)
|
|
|
|
{
|
|
|
|
initInit();
|
|
|
|
|
|
|
|
jGeckoEventClass = getClassGlobalRef("org/mozilla/gecko/GeckoEvent");
|
|
|
|
|
|
|
|
jActionField = getField("mAction", "I");
|
|
|
|
jTypeField = getField("mType", "I");
|
2013-03-11 02:43:30 +04:00
|
|
|
jAckNeededField = getField("mAckNeeded", "Z");
|
2010-06-04 00:56:36 +04:00
|
|
|
jTimeField = getField("mTime", "J");
|
2012-01-25 04:31:33 +04:00
|
|
|
jPoints = getField("mPoints", "[Landroid/graphics/Point;");
|
|
|
|
jPointIndicies = getField("mPointIndicies", "[I");
|
|
|
|
jOrientations = getField("mOrientations", "[F");
|
|
|
|
jPressures = getField("mPressures", "[F");
|
|
|
|
jPointRadii = getField("mPointRadii", "[Landroid/graphics/Point;");
|
2011-06-20 09:36:17 +04:00
|
|
|
jXField = getField("mX", "D");
|
|
|
|
jYField = getField("mY", "D");
|
|
|
|
jZField = getField("mZ", "D");
|
2010-06-04 00:56:36 +04:00
|
|
|
jRectField = getField("mRect", "Landroid/graphics/Rect;");
|
|
|
|
|
|
|
|
jCharactersField = getField("mCharacters", "Ljava/lang/String;");
|
2011-11-15 07:12:14 +04:00
|
|
|
jCharactersExtraField = getField("mCharactersExtra", "Ljava/lang/String;");
|
2013-06-16 01:40:27 +04:00
|
|
|
jDataField = getField("mData", "Ljava/lang/String;");
|
2010-06-04 00:56:36 +04:00
|
|
|
jKeyCodeField = getField("mKeyCode", "I");
|
2014-05-25 06:09:00 +04:00
|
|
|
jScanCodeField = getField("mScanCode", "I");
|
2010-06-04 00:56:36 +04:00
|
|
|
jMetaStateField = getField("mMetaState", "I");
|
2013-04-09 00:21:52 +04:00
|
|
|
jDomKeyLocationField = getField("mDomKeyLocation", "Lorg/mozilla/gecko/GeckoEvent$DomKeyLocation;");
|
2010-06-04 00:56:36 +04:00
|
|
|
jFlagsField = getField("mFlags", "I");
|
|
|
|
jUnicodeCharField = getField("mUnicodeChar", "I");
|
2013-03-29 18:54:01 +04:00
|
|
|
jBaseUnicodeCharField = getField("mBaseUnicodeChar", "I");
|
2013-12-10 20:14:54 +04:00
|
|
|
jDOMPrintableKeyValueField = getField("mDOMPrintableKeyValue", "I");
|
2012-04-20 00:55:33 +04:00
|
|
|
jRepeatCountField = getField("mRepeatCount", "I");
|
2010-06-04 00:56:36 +04:00
|
|
|
jCountField = getField("mCount", "I");
|
2012-11-02 00:11:02 +04:00
|
|
|
jStartField = getField("mStart", "I");
|
|
|
|
jEndField = getField("mEnd", "I");
|
2012-01-25 04:31:33 +04:00
|
|
|
jPointerIndexField = getField("mPointerIndex", "I");
|
2010-08-04 23:47:26 +04:00
|
|
|
jRangeTypeField = getField("mRangeType", "I");
|
|
|
|
jRangeStylesField = getField("mRangeStyles", "I");
|
2012-12-06 23:35:59 +04:00
|
|
|
jRangeLineStyleField = getField("mRangeLineStyle", "I");
|
|
|
|
jRangeBoldLineField = getField("mRangeBoldLine", "Z");
|
2010-08-04 23:47:26 +04:00
|
|
|
jRangeForeColorField = getField("mRangeForeColor", "I");
|
|
|
|
jRangeBackColorField = getField("mRangeBackColor", "I");
|
2012-12-06 23:35:59 +04:00
|
|
|
jRangeLineColorField = getField("mRangeLineColor", "I");
|
2010-06-05 01:14:43 +04:00
|
|
|
jLocationField = getField("mLocation", "Landroid/location/Location;");
|
2014-03-05 13:42:42 +04:00
|
|
|
jConnectionTypeField = getField("mConnectionType", "I");
|
2013-07-11 19:39:36 +04:00
|
|
|
jIsWifiField = getField("mIsWifi", "Z");
|
|
|
|
jDHCPGatewayField = getField("mDHCPGateway", "I");
|
2012-03-20 17:09:45 +04:00
|
|
|
jScreenOrientationField = getField("mScreenOrientation", "S");
|
2012-06-14 20:08:51 +04:00
|
|
|
jByteBufferField = getField("mBuffer", "Ljava/nio/ByteBuffer;");
|
2013-03-21 02:45:07 +04:00
|
|
|
jWidthField = getField("mWidth", "I");
|
|
|
|
jHeightField = getField("mHeight", "I");
|
2014-04-22 18:53:48 +04:00
|
|
|
jIDField = getField("mID", "I");
|
|
|
|
jGamepadButtonField = getField("mGamepadButton", "I");
|
|
|
|
jGamepadButtonPressedField = getField("mGamepadButtonPressed", "Z");
|
|
|
|
jGamepadButtonValueField = getField("mGamepadButtonValue", "F");
|
|
|
|
jGamepadValuesField = getField("mGamepadValues", "[F");
|
2013-09-04 17:58:08 +04:00
|
|
|
jPrefNamesField = getField("mPrefNames", "[Ljava/lang/String;");
|
2013-04-10 02:56:03 +04:00
|
|
|
|
|
|
|
// Init GeckoEvent.DomKeyLocation enum
|
|
|
|
jDomKeyLocationClass = getClassGlobalRef("org/mozilla/gecko/GeckoEvent$DomKeyLocation");
|
|
|
|
jDomKeyLocationValueField = getField("value", "I");
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
2010-06-05 01:14:43 +04:00
|
|
|
void
|
|
|
|
AndroidLocation::InitLocationClass(JNIEnv *jEnv)
|
|
|
|
{
|
|
|
|
initInit();
|
|
|
|
|
|
|
|
jLocationClass = getClassGlobalRef("android/location/Location");
|
|
|
|
jGetLatitudeMethod = getMethod("getLatitude", "()D");
|
|
|
|
jGetLongitudeMethod = getMethod("getLongitude", "()D");
|
|
|
|
jGetAltitudeMethod = getMethod("getAltitude", "()D");
|
|
|
|
jGetAccuracyMethod = getMethod("getAccuracy", "()F");
|
|
|
|
jGetBearingMethod = getMethod("getBearing", "()F");
|
|
|
|
jGetSpeedMethod = getMethod("getSpeed", "()F");
|
|
|
|
jGetTimeMethod = getMethod("getTime", "()J");
|
|
|
|
}
|
|
|
|
|
|
|
|
nsGeoPosition*
|
|
|
|
AndroidLocation::CreateGeoPosition(JNIEnv *jenv, jobject jobj)
|
|
|
|
{
|
2012-05-04 19:08:47 +04:00
|
|
|
AutoLocalJNIFrame jniFrame(jenv);
|
|
|
|
|
2010-06-05 01:14:43 +04:00
|
|
|
double latitude = jenv->CallDoubleMethod(jobj, jGetLatitudeMethod);
|
2013-10-11 00:42:52 +04:00
|
|
|
if (jniFrame.CheckForException()) return nullptr;
|
2010-06-05 01:14:43 +04:00
|
|
|
double longitude = jenv->CallDoubleMethod(jobj, jGetLongitudeMethod);
|
2013-10-11 00:42:52 +04:00
|
|
|
if (jniFrame.CheckForException()) return nullptr;
|
2010-06-05 01:14:43 +04:00
|
|
|
double altitude = jenv->CallDoubleMethod(jobj, jGetAltitudeMethod);
|
2013-10-11 00:42:52 +04:00
|
|
|
if (jniFrame.CheckForException()) return nullptr;
|
2010-06-05 01:14:43 +04:00
|
|
|
float accuracy = jenv->CallFloatMethod (jobj, jGetAccuracyMethod);
|
2013-10-11 00:42:52 +04:00
|
|
|
if (jniFrame.CheckForException()) return nullptr;
|
2010-06-05 01:14:43 +04:00
|
|
|
float bearing = jenv->CallFloatMethod (jobj, jGetBearingMethod);
|
2013-10-11 00:42:52 +04:00
|
|
|
if (jniFrame.CheckForException()) return nullptr;
|
2010-06-05 01:14:43 +04:00
|
|
|
float speed = jenv->CallFloatMethod (jobj, jGetSpeedMethod);
|
2013-10-11 00:42:52 +04:00
|
|
|
if (jniFrame.CheckForException()) return nullptr;
|
2010-06-05 01:14:43 +04:00
|
|
|
long long time = jenv->CallLongMethod (jobj, jGetTimeMethod);
|
2013-10-11 00:42:52 +04:00
|
|
|
if (jniFrame.CheckForException()) return nullptr;
|
2010-06-05 01:14:43 +04:00
|
|
|
|
|
|
|
return new nsGeoPosition(latitude, longitude,
|
|
|
|
altitude, accuracy,
|
|
|
|
accuracy, bearing,
|
|
|
|
speed, time);
|
|
|
|
}
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
void
|
|
|
|
AndroidPoint::InitPointClass(JNIEnv *jEnv)
|
|
|
|
{
|
|
|
|
initInit();
|
|
|
|
|
|
|
|
jPointClass = getClassGlobalRef("android/graphics/Point");
|
|
|
|
|
|
|
|
jXField = getField("x", "I");
|
|
|
|
jYField = getField("y", "I");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidRect::InitRectClass(JNIEnv *jEnv)
|
|
|
|
{
|
|
|
|
initInit();
|
|
|
|
|
|
|
|
jRectClass = getClassGlobalRef("android/graphics/Rect");
|
|
|
|
|
|
|
|
jBottomField = getField("bottom", "I");
|
|
|
|
jLeftField = getField("left", "I");
|
|
|
|
jTopField = getField("top", "I");
|
|
|
|
jRightField = getField("right", "I");
|
|
|
|
}
|
|
|
|
|
2012-09-13 01:47:08 +04:00
|
|
|
void
|
|
|
|
AndroidRectF::InitRectFClass(JNIEnv *jEnv)
|
|
|
|
{
|
|
|
|
initInit();
|
|
|
|
|
|
|
|
jRectClass = getClassGlobalRef("android/graphics/RectF");
|
|
|
|
|
|
|
|
jBottomField = getField("bottom", "F");
|
|
|
|
jLeftField = getField("left", "F");
|
|
|
|
jTopField = getField("top", "F");
|
|
|
|
jRightField = getField("right", "F");
|
|
|
|
}
|
|
|
|
|
2013-11-19 19:56:09 +04:00
|
|
|
void
|
|
|
|
AndroidLayerRendererFrame::InitLayerRendererFrameClass(JNIEnv *jEnv)
|
|
|
|
{
|
|
|
|
initInit();
|
|
|
|
|
|
|
|
jLayerRendererFrameClass = getClassGlobalRef("org/mozilla/gecko/gfx/LayerRenderer$Frame");
|
|
|
|
|
|
|
|
jBeginDrawingMethod = getMethod("beginDrawing", "()V");
|
|
|
|
jDrawBackgroundMethod = getMethod("drawBackground", "()V");
|
|
|
|
jDrawForegroundMethod = getMethod("drawForeground", "()V");
|
|
|
|
jEndDrawingMethod = getMethod("endDrawing", "()V");
|
|
|
|
}
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
#undef initInit
|
|
|
|
#undef initClassGlobalRef
|
|
|
|
#undef getField
|
|
|
|
#undef getMethod
|
|
|
|
|
|
|
|
void
|
2012-01-25 04:31:33 +04:00
|
|
|
AndroidGeckoEvent::ReadPointArray(nsTArray<nsIntPoint> &points,
|
|
|
|
JNIEnv *jenv,
|
|
|
|
jfieldID field,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t count)
|
2010-06-04 00:56:36 +04:00
|
|
|
{
|
2012-01-25 04:31:33 +04:00
|
|
|
jobjectArray jObjArray = (jobjectArray)jenv->GetObjectField(wrapped_obj, field);
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0; i < count; i++) {
|
2012-01-25 04:31:33 +04:00
|
|
|
jobject jObj = jenv->GetObjectArrayElement(jObjArray, i);
|
|
|
|
AndroidPoint jpoint(jenv, jObj);
|
|
|
|
|
|
|
|
nsIntPoint p(jpoint.X(), jpoint.Y());
|
|
|
|
points.AppendElement(p);
|
|
|
|
}
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-01-25 04:31:33 +04:00
|
|
|
AndroidGeckoEvent::ReadIntArray(nsTArray<int> &aVals,
|
|
|
|
JNIEnv *jenv,
|
|
|
|
jfieldID field,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t count)
|
2010-06-04 00:56:36 +04:00
|
|
|
{
|
2012-01-25 04:31:33 +04:00
|
|
|
jintArray jIntArray = (jintArray)jenv->GetObjectField(wrapped_obj, field);
|
2013-10-11 00:42:52 +04:00
|
|
|
jint *vals = jenv->GetIntArrayElements(jIntArray, nullptr);
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0; i < count; i++) {
|
2012-01-25 04:31:33 +04:00
|
|
|
aVals.AppendElement(vals[i]);
|
|
|
|
}
|
|
|
|
jenv->ReleaseIntArrayElements(jIntArray, vals, JNI_ABORT);
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
2012-01-24 19:39:53 +04:00
|
|
|
void
|
2012-01-25 04:31:33 +04:00
|
|
|
AndroidGeckoEvent::ReadFloatArray(nsTArray<float> &aVals,
|
|
|
|
JNIEnv *jenv,
|
|
|
|
jfieldID field,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t count)
|
2012-01-24 19:39:53 +04:00
|
|
|
{
|
2012-01-25 04:31:33 +04:00
|
|
|
jfloatArray jFloatArray = (jfloatArray)jenv->GetObjectField(wrapped_obj, field);
|
2013-10-11 00:42:52 +04:00
|
|
|
jfloat *vals = jenv->GetFloatArrayElements(jFloatArray, nullptr);
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0; i < count; i++) {
|
2012-01-25 04:31:33 +04:00
|
|
|
aVals.AppendElement(vals[i]);
|
|
|
|
}
|
|
|
|
jenv->ReleaseFloatArrayElements(jFloatArray, vals, JNI_ABORT);
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
2013-09-04 17:58:08 +04:00
|
|
|
void
|
|
|
|
AndroidGeckoEvent::ReadStringArray(nsTArray<nsString> &array,
|
|
|
|
JNIEnv *jenv,
|
|
|
|
jfieldID field)
|
|
|
|
{
|
|
|
|
jarray jArray = (jarray)jenv->GetObjectField(wrapped_obj, field);
|
|
|
|
jsize length = jenv->GetArrayLength(jArray);
|
|
|
|
jobjectArray jStringArray = (jobjectArray)jArray;
|
|
|
|
nsString *strings = array.AppendElements(length);
|
|
|
|
for (jsize i = 0; i < length; ++i) {
|
|
|
|
jstring javastring = (jstring) jenv->GetObjectArrayElement(jStringArray, i);
|
|
|
|
ReadStringFromJString(strings[i], jenv, javastring);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
void
|
|
|
|
AndroidGeckoEvent::ReadRectField(JNIEnv *jenv)
|
|
|
|
{
|
|
|
|
AndroidRect r(jenv, jenv->GetObjectField(wrappedObject(), jRectField));
|
|
|
|
if (!r.isNull()) {
|
|
|
|
mRect.SetRect(r.Left(),
|
|
|
|
r.Top(),
|
2012-02-09 21:28:10 +04:00
|
|
|
r.Width(),
|
|
|
|
r.Height());
|
2010-06-04 00:56:36 +04:00
|
|
|
} else {
|
2011-04-19 07:07:23 +04:00
|
|
|
mRect.SetEmpty();
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-04 17:58:00 +04:00
|
|
|
AndroidGeckoEvent::ReadStringFromJString(nsString &aString, JNIEnv *jenv,
|
|
|
|
jstring s)
|
2010-06-04 00:56:36 +04:00
|
|
|
{
|
|
|
|
if (!s) {
|
2013-09-04 17:58:00 +04:00
|
|
|
aString.SetIsVoid(true);
|
2010-06-04 00:56:36 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int len = jenv->GetStringLength(s);
|
2013-09-04 17:58:00 +04:00
|
|
|
aString.SetLength(len);
|
2013-10-08 22:00:40 +04:00
|
|
|
jenv->GetStringRegion(s, 0, len, reinterpret_cast<jchar*>(aString.BeginWriting()));
|
2013-09-04 17:58:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidGeckoEvent::ReadCharactersField(JNIEnv *jenv)
|
|
|
|
{
|
|
|
|
jstring s = (jstring) jenv->GetObjectField(wrapped_obj, jCharactersField);
|
|
|
|
ReadStringFromJString(mCharacters, jenv, s);
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
2011-11-15 07:12:14 +04:00
|
|
|
void
|
|
|
|
AndroidGeckoEvent::ReadCharactersExtraField(JNIEnv *jenv)
|
|
|
|
{
|
|
|
|
jstring s = (jstring) jenv->GetObjectField(wrapped_obj, jCharactersExtraField);
|
2013-09-04 17:58:00 +04:00
|
|
|
ReadStringFromJString(mCharactersExtra, jenv, s);
|
2011-11-15 07:12:14 +04:00
|
|
|
}
|
|
|
|
|
2013-06-16 01:40:27 +04:00
|
|
|
void
|
|
|
|
AndroidGeckoEvent::ReadDataField(JNIEnv *jenv)
|
|
|
|
{
|
|
|
|
jstring s = (jstring) jenv->GetObjectField(wrapped_obj, jDataField);
|
2013-09-04 17:58:00 +04:00
|
|
|
ReadStringFromJString(mData, jenv, s);
|
2013-06-16 01:40:27 +04:00
|
|
|
}
|
|
|
|
|
2011-11-15 07:12:14 +04:00
|
|
|
void
|
2013-04-18 01:39:12 +04:00
|
|
|
AndroidGeckoEvent::UnionRect(nsIntRect const& aRect)
|
2011-11-15 07:12:14 +04:00
|
|
|
{
|
2013-04-18 01:39:12 +04:00
|
|
|
mRect = aRect.Union(mRect);
|
2011-11-15 07:12:14 +04:00
|
|
|
}
|
|
|
|
|
2013-04-10 02:56:03 +04:00
|
|
|
uint32_t
|
|
|
|
AndroidGeckoEvent::ReadDomKeyLocation(JNIEnv* jenv, jobject jGeckoEventObj)
|
|
|
|
{
|
|
|
|
jobject enumObject = jenv->GetObjectField(jGeckoEventObj,
|
|
|
|
jDomKeyLocationField);
|
|
|
|
MOZ_ASSERT(enumObject);
|
|
|
|
int enumValue = jenv->GetIntField(enumObject, jDomKeyLocationValueField);
|
|
|
|
MOZ_ASSERT(enumValue >= nsIDOMKeyEvent::DOM_KEY_LOCATION_STANDARD &&
|
|
|
|
enumValue <= nsIDOMKeyEvent::DOM_KEY_LOCATION_JOYSTICK);
|
|
|
|
return static_cast<uint32_t>(enumValue);
|
|
|
|
}
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
void
|
|
|
|
AndroidGeckoEvent::Init(JNIEnv *jenv, jobject jobj)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!wrapped_obj, "Init called on non-null wrapped_obj!");
|
|
|
|
|
|
|
|
wrapped_obj = jobj;
|
|
|
|
|
|
|
|
if (!jobj)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mAction = jenv->GetIntField(jobj, jActionField);
|
|
|
|
mType = jenv->GetIntField(jobj, jTypeField);
|
2013-03-11 02:43:30 +04:00
|
|
|
mAckNeeded = jenv->GetBooleanField(jobj, jAckNeededField);
|
2010-06-04 00:56:36 +04:00
|
|
|
|
|
|
|
switch (mType) {
|
|
|
|
case SIZE_CHANGED:
|
2012-02-24 19:51:41 +04:00
|
|
|
ReadPointArray(mPoints, jenv, jPoints, 2);
|
2010-06-04 00:56:36 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_EVENT:
|
2013-03-29 18:54:01 +04:00
|
|
|
case IME_KEY_EVENT:
|
2010-06-04 00:56:36 +04:00
|
|
|
mTime = jenv->GetLongField(jobj, jTimeField);
|
|
|
|
mMetaState = jenv->GetIntField(jobj, jMetaStateField);
|
2013-04-10 02:56:03 +04:00
|
|
|
mDomKeyLocation = ReadDomKeyLocation(jenv, jobj);
|
2010-06-04 00:56:36 +04:00
|
|
|
mFlags = jenv->GetIntField(jobj, jFlagsField);
|
|
|
|
mKeyCode = jenv->GetIntField(jobj, jKeyCodeField);
|
2014-05-25 06:09:00 +04:00
|
|
|
mScanCode = jenv->GetIntField(jobj, jScanCodeField);
|
2010-06-04 00:56:36 +04:00
|
|
|
mUnicodeChar = jenv->GetIntField(jobj, jUnicodeCharField);
|
2013-03-29 18:54:01 +04:00
|
|
|
mBaseUnicodeChar = jenv->GetIntField(jobj, jBaseUnicodeCharField);
|
2013-12-10 20:14:54 +04:00
|
|
|
mDOMPrintableKeyValue =
|
|
|
|
jenv->GetIntField(jobj, jDOMPrintableKeyValueField);
|
2012-04-20 00:55:33 +04:00
|
|
|
mRepeatCount = jenv->GetIntField(jobj, jRepeatCountField);
|
2010-06-04 00:56:36 +04:00
|
|
|
ReadCharactersField(jenv);
|
|
|
|
break;
|
|
|
|
|
2012-10-03 00:18:21 +04:00
|
|
|
case NATIVE_GESTURE_EVENT:
|
|
|
|
mTime = jenv->GetLongField(jobj, jTimeField);
|
|
|
|
mMetaState = jenv->GetIntField(jobj, jMetaStateField);
|
|
|
|
mCount = jenv->GetIntField(jobj, jCountField);
|
|
|
|
ReadPointArray(mPoints, jenv, jPoints, mCount);
|
|
|
|
mX = jenv->GetDoubleField(jobj, jXField);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
case MOTION_EVENT:
|
|
|
|
mTime = jenv->GetLongField(jobj, jTimeField);
|
2010-12-22 01:36:28 +03:00
|
|
|
mMetaState = jenv->GetIntField(jobj, jMetaStateField);
|
2010-07-08 01:34:12 +04:00
|
|
|
mCount = jenv->GetIntField(jobj, jCountField);
|
2012-01-25 04:31:33 +04:00
|
|
|
mPointerIndex = jenv->GetIntField(jobj, jPointerIndexField);
|
|
|
|
|
|
|
|
ReadPointArray(mPointRadii, jenv, jPointRadii, mCount);
|
|
|
|
ReadFloatArray(mOrientations, jenv, jOrientations, mCount);
|
|
|
|
ReadFloatArray(mPressures, jenv, jPressures, mCount);
|
|
|
|
ReadPointArray(mPoints, jenv, jPoints, mCount);
|
|
|
|
ReadIntArray(mPointIndicies, jenv, jPointIndicies, mCount);
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IME_EVENT:
|
2012-11-02 00:11:02 +04:00
|
|
|
mStart = jenv->GetIntField(jobj, jStartField);
|
|
|
|
mEnd = jenv->GetIntField(jobj, jEndField);
|
|
|
|
|
|
|
|
if (mAction == IME_REPLACE_TEXT) {
|
|
|
|
ReadCharactersField(jenv);
|
|
|
|
} else if (mAction == IME_UPDATE_COMPOSITION ||
|
|
|
|
mAction == IME_ADD_COMPOSITION_RANGE) {
|
2010-08-04 23:47:26 +04:00
|
|
|
mRangeType = jenv->GetIntField(jobj, jRangeTypeField);
|
|
|
|
mRangeStyles = jenv->GetIntField(jobj, jRangeStylesField);
|
2012-12-06 23:35:59 +04:00
|
|
|
mRangeLineStyle =
|
|
|
|
jenv->GetIntField(jobj, jRangeLineStyleField);
|
|
|
|
mRangeBoldLine =
|
|
|
|
jenv->GetBooleanField(jobj, jRangeBoldLineField);
|
2010-08-04 23:47:26 +04:00
|
|
|
mRangeForeColor =
|
|
|
|
jenv->GetIntField(jobj, jRangeForeColorField);
|
|
|
|
mRangeBackColor =
|
|
|
|
jenv->GetIntField(jobj, jRangeBackColorField);
|
2012-12-06 23:35:59 +04:00
|
|
|
mRangeLineColor =
|
|
|
|
jenv->GetIntField(jobj, jRangeLineColorField);
|
2010-08-04 23:47:26 +04:00
|
|
|
}
|
2010-06-04 00:56:36 +04:00
|
|
|
break;
|
|
|
|
|
2012-03-14 03:57:51 +04:00
|
|
|
case SENSOR_EVENT:
|
|
|
|
mX = jenv->GetDoubleField(jobj, jXField);
|
|
|
|
mY = jenv->GetDoubleField(jobj, jYField);
|
|
|
|
mZ = jenv->GetDoubleField(jobj, jZField);
|
|
|
|
mFlags = jenv->GetIntField(jobj, jFlagsField);
|
2012-03-21 10:36:17 +04:00
|
|
|
mMetaState = jenv->GetIntField(jobj, jMetaStateField);
|
2012-03-14 03:57:51 +04:00
|
|
|
break;
|
2011-06-20 09:36:17 +04:00
|
|
|
|
2010-06-05 01:14:43 +04:00
|
|
|
case LOCATION_EVENT: {
|
|
|
|
jobject location = jenv->GetObjectField(jobj, jLocationField);
|
|
|
|
mGeoPosition = AndroidLocation::CreateGeoPosition(jenv, location);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-06-18 21:42:51 +04:00
|
|
|
case LOAD_URI: {
|
|
|
|
ReadCharactersField(jenv);
|
2012-04-14 06:45:25 +04:00
|
|
|
ReadCharactersExtraField(jenv);
|
2010-06-18 21:42:51 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-22 15:35:32 +04:00
|
|
|
case VIEWPORT:
|
2011-11-15 07:12:14 +04:00
|
|
|
case BROADCAST: {
|
|
|
|
ReadCharactersField(jenv);
|
|
|
|
ReadCharactersExtraField(jenv);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-01-17 22:40:39 +04:00
|
|
|
case NETWORK_CHANGED: {
|
2014-03-05 13:42:42 +04:00
|
|
|
mConnectionType = jenv->GetIntField(jobj, jConnectionTypeField);
|
2013-07-11 19:39:36 +04:00
|
|
|
mIsWifi = jenv->GetBooleanField(jobj, jIsWifiField);
|
|
|
|
mDHCPGateway = jenv->GetIntField(jobj, jDHCPGatewayField);
|
2012-01-17 22:40:39 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-01-24 18:59:31 +04:00
|
|
|
case VISITED: {
|
|
|
|
ReadCharactersField(jenv);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-12-15 19:43:52 +04:00
|
|
|
case THUMBNAIL: {
|
2012-02-21 01:37:51 +04:00
|
|
|
mMetaState = jenv->GetIntField(jobj, jMetaStateField);
|
2012-12-15 19:43:52 +04:00
|
|
|
ReadPointArray(mPoints, jenv, jPoints, 1);
|
2012-06-14 20:08:51 +04:00
|
|
|
mByteBuffer = new RefCountedJavaObject(jenv, jenv->GetObjectField(jobj, jByteBufferField));
|
2012-04-24 23:13:36 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-03-20 17:09:45 +04:00
|
|
|
case SCREENORIENTATION_CHANGED: {
|
|
|
|
mScreenOrientation = jenv->GetShortField(jobj, jScreenOrientationField);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-03-21 02:45:07 +04:00
|
|
|
case COMPOSITOR_CREATE: {
|
|
|
|
mWidth = jenv->GetIntField(jobj, jWidthField);
|
|
|
|
mHeight = jenv->GetIntField(jobj, jHeightField);
|
|
|
|
break;
|
2013-06-16 01:40:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
case CALL_OBSERVER: {
|
|
|
|
ReadCharactersField(jenv);
|
|
|
|
ReadCharactersExtraField(jenv);
|
|
|
|
ReadDataField(jenv);
|
|
|
|
break;
|
2013-06-18 01:09:09 +04:00
|
|
|
}
|
|
|
|
|
2013-06-19 21:55:35 +04:00
|
|
|
case REMOVE_OBSERVER: {
|
|
|
|
ReadCharactersField(jenv);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-06-18 01:09:09 +04:00
|
|
|
case LOW_MEMORY: {
|
|
|
|
mMetaState = jenv->GetIntField(jobj, jMetaStateField);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case NETWORK_LINK_CHANGE: {
|
|
|
|
ReadCharactersField(jenv);
|
|
|
|
break;
|
2013-03-21 02:45:07 +04:00
|
|
|
}
|
|
|
|
|
2013-08-15 23:03:47 +04:00
|
|
|
case TELEMETRY_HISTOGRAM_ADD: {
|
|
|
|
ReadCharactersField(jenv);
|
|
|
|
mCount = jenv->GetIntField(jobj, jCountField);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-12-10 22:41:34 +04:00
|
|
|
case TELEMETRY_UI_SESSION_START: {
|
|
|
|
ReadCharactersField(jenv);
|
|
|
|
mTime = jenv->GetLongField(jobj, jTimeField);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case TELEMETRY_UI_SESSION_STOP: {
|
|
|
|
ReadCharactersField(jenv);
|
|
|
|
ReadCharactersExtraField(jenv);
|
|
|
|
mTime = jenv->GetLongField(jobj, jTimeField);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case TELEMETRY_UI_EVENT: {
|
|
|
|
ReadCharactersField(jenv);
|
|
|
|
ReadCharactersExtraField(jenv);
|
|
|
|
ReadDataField(jenv);
|
|
|
|
mTime = jenv->GetLongField(jobj, jTimeField);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-04-22 18:53:48 +04:00
|
|
|
case GAMEPAD_ADDREMOVE: {
|
|
|
|
mID = jenv->GetIntField(jobj, jIDField);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case GAMEPAD_DATA: {
|
|
|
|
mID = jenv->GetIntField(jobj, jIDField);
|
|
|
|
if (mAction == ACTION_GAMEPAD_BUTTON) {
|
|
|
|
mGamepadButton = jenv->GetIntField(jobj, jGamepadButtonField);
|
|
|
|
mGamepadButtonPressed = jenv->GetBooleanField(jobj, jGamepadButtonPressedField);
|
|
|
|
mGamepadButtonValue = jenv->GetFloatField(jobj, jGamepadButtonValueField);
|
|
|
|
} else if (mAction == ACTION_GAMEPAD_AXES) {
|
|
|
|
// Flags is a bitfield of valid entries in gamepadvalues
|
|
|
|
mFlags = jenv->GetIntField(jobj, jFlagsField);
|
|
|
|
mCount = jenv->GetIntField(jobj, jCountField);
|
|
|
|
ReadFloatArray(mGamepadValues, jenv, jGamepadValuesField, mCount);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-09-04 17:58:08 +04:00
|
|
|
case PREFERENCES_OBSERVE:
|
|
|
|
case PREFERENCES_GET: {
|
|
|
|
ReadStringArray(mPrefNames, jenv, jPrefNamesField);
|
|
|
|
mCount = jenv->GetIntField(jobj, jCountField);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-09-04 17:58:23 +04:00
|
|
|
case PREFERENCES_REMOVE_OBSERVERS: {
|
|
|
|
mCount = jenv->GetIntField(jobj, jCountField);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-03-21 10:36:17 +04:00
|
|
|
#ifdef DEBUG_ANDROID_EVENTS
|
2011-01-19 03:25:20 +03:00
|
|
|
ALOG("AndroidGeckoEvent: %p : %d", (void*)jobj, mType);
|
2010-06-04 00:56:36 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidGeckoEvent::Init(int aType)
|
|
|
|
{
|
|
|
|
mType = aType;
|
2013-03-15 00:19:24 +04:00
|
|
|
mAckNeeded = false;
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
2011-08-09 20:08:19 +04:00
|
|
|
void
|
|
|
|
AndroidGeckoEvent::Init(AndroidGeckoEvent *aResizeEvent)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aResizeEvent->Type() == SIZE_CHANGED, "Init called on non-SIZE_CHANGED event");
|
|
|
|
|
|
|
|
mType = FORCED_RESIZE;
|
2013-03-15 00:19:24 +04:00
|
|
|
mAckNeeded = false;
|
2011-08-09 20:08:19 +04:00
|
|
|
mTime = aResizeEvent->mTime;
|
2012-01-25 04:31:33 +04:00
|
|
|
mPoints = aResizeEvent->mPoints; // x,y coordinates
|
2011-08-09 20:08:19 +04:00
|
|
|
}
|
|
|
|
|
2013-09-27 10:20:57 +04:00
|
|
|
WidgetTouchEvent
|
2013-04-18 01:39:10 +04:00
|
|
|
AndroidGeckoEvent::MakeTouchEvent(nsIWidget* widget)
|
|
|
|
{
|
|
|
|
int type = NS_EVENT_NULL;
|
|
|
|
int startIndex = 0;
|
|
|
|
int endIndex = Count();
|
|
|
|
|
2013-04-18 01:39:11 +04:00
|
|
|
switch (Action()) {
|
2013-04-18 01:39:10 +04:00
|
|
|
case AndroidMotionEvent::ACTION_DOWN:
|
|
|
|
case AndroidMotionEvent::ACTION_POINTER_DOWN: {
|
|
|
|
type = NS_TOUCH_START;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case AndroidMotionEvent::ACTION_MOVE: {
|
|
|
|
type = NS_TOUCH_MOVE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case AndroidMotionEvent::ACTION_UP:
|
|
|
|
case AndroidMotionEvent::ACTION_POINTER_UP: {
|
|
|
|
type = NS_TOUCH_END;
|
|
|
|
// for pointer-up events we only want the data from
|
|
|
|
// the one pointer that went up
|
|
|
|
startIndex = PointerIndex();
|
|
|
|
endIndex = startIndex + 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case AndroidMotionEvent::ACTION_OUTSIDE:
|
|
|
|
case AndroidMotionEvent::ACTION_CANCEL: {
|
|
|
|
type = NS_TOUCH_CANCEL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-27 10:20:57 +04:00
|
|
|
WidgetTouchEvent event(true, type, widget);
|
2013-04-18 01:39:10 +04:00
|
|
|
if (type == NS_EVENT_NULL) {
|
|
|
|
// An event we don't know about
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2013-12-18 06:25:10 +04:00
|
|
|
event.modifiers = DOMModifiers();
|
2013-04-18 01:39:10 +04:00
|
|
|
event.time = Time();
|
|
|
|
|
|
|
|
const nsIntPoint& offset = widget->WidgetToScreenOffset();
|
|
|
|
event.touches.SetCapacity(endIndex - startIndex);
|
|
|
|
for (int i = startIndex; i < endIndex; i++) {
|
2013-07-04 17:02:29 +04:00
|
|
|
// In this code branch, we are dispatching this event directly
|
|
|
|
// into Gecko (as opposed to going through the AsyncPanZoomController),
|
|
|
|
// and the Points() array has points in CSS pixels, which we need
|
|
|
|
// to convert.
|
2013-09-18 04:45:19 +04:00
|
|
|
CSSToLayoutDeviceScale scale = widget->GetDefaultScale();
|
2013-07-04 17:02:29 +04:00
|
|
|
nsIntPoint pt(
|
2013-09-18 04:45:19 +04:00
|
|
|
(Points()[i].x * scale.scale) - offset.x,
|
|
|
|
(Points()[i].y * scale.scale) - offset.y);
|
2013-07-04 17:02:29 +04:00
|
|
|
nsIntPoint radii(
|
2013-09-18 04:45:19 +04:00
|
|
|
PointRadii()[i].x * scale.scale,
|
|
|
|
PointRadii()[i].y * scale.scale);
|
2013-05-18 00:17:53 +04:00
|
|
|
nsRefPtr<Touch> t = new Touch(PointIndicies()[i],
|
2013-07-04 17:02:29 +04:00
|
|
|
pt,
|
|
|
|
radii,
|
2013-05-18 00:17:53 +04:00
|
|
|
Orientations()[i],
|
|
|
|
Pressures()[i]);
|
2013-04-18 01:39:10 +04:00
|
|
|
event.touches.AppendElement(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2013-04-26 21:24:28 +04:00
|
|
|
MultiTouchInput
|
|
|
|
AndroidGeckoEvent::MakeMultiTouchInput(nsIWidget* widget)
|
|
|
|
{
|
|
|
|
MultiTouchInput::MultiTouchType type = (MultiTouchInput::MultiTouchType)-1;
|
|
|
|
int startIndex = 0;
|
|
|
|
int endIndex = Count();
|
|
|
|
|
|
|
|
switch (Action()) {
|
|
|
|
case AndroidMotionEvent::ACTION_DOWN:
|
|
|
|
case AndroidMotionEvent::ACTION_POINTER_DOWN: {
|
|
|
|
type = MultiTouchInput::MULTITOUCH_START;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case AndroidMotionEvent::ACTION_MOVE: {
|
|
|
|
type = MultiTouchInput::MULTITOUCH_MOVE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case AndroidMotionEvent::ACTION_UP:
|
|
|
|
case AndroidMotionEvent::ACTION_POINTER_UP: {
|
|
|
|
// for pointer-up events we only want the data from
|
|
|
|
// the one pointer that went up
|
|
|
|
startIndex = PointerIndex();
|
|
|
|
endIndex = startIndex + 1;
|
|
|
|
type = MultiTouchInput::MULTITOUCH_END;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case AndroidMotionEvent::ACTION_OUTSIDE:
|
|
|
|
case AndroidMotionEvent::ACTION_CANCEL: {
|
|
|
|
type = MultiTouchInput::MULTITOUCH_CANCEL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-26 08:30:26 +04:00
|
|
|
MultiTouchInput event(type, Time(), 0);
|
2013-12-18 06:25:10 +04:00
|
|
|
event.modifiers = DOMModifiers();
|
2013-04-26 21:24:28 +04:00
|
|
|
|
|
|
|
if (type < 0) {
|
|
|
|
// An event we don't know about
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsIntPoint& offset = widget->WidgetToScreenOffset();
|
|
|
|
event.mTouches.SetCapacity(endIndex - startIndex);
|
|
|
|
for (int i = startIndex; i < endIndex; i++) {
|
2013-06-12 02:13:11 +04:00
|
|
|
nsIntPoint point = Points()[i] - offset;
|
|
|
|
nsIntPoint radius = PointRadii()[i];
|
2013-04-26 21:24:28 +04:00
|
|
|
SingleTouchData data(PointIndicies()[i],
|
2013-06-12 02:13:11 +04:00
|
|
|
ScreenIntPoint::FromUnknownPoint(
|
|
|
|
gfx::IntPoint(point.x, point.y)),
|
|
|
|
ScreenSize::FromUnknownSize(
|
|
|
|
gfx::Size(radius.x, radius.y)),
|
2013-04-26 21:24:28 +04:00
|
|
|
Orientations()[i],
|
|
|
|
Pressures()[i]);
|
|
|
|
event.mTouches.AppendElement(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2013-10-16 01:11:39 +04:00
|
|
|
WidgetMouseEvent
|
|
|
|
AndroidGeckoEvent::MakeMouseEvent(nsIWidget* widget)
|
|
|
|
{
|
|
|
|
uint32_t msg = NS_EVENT_NULL;
|
|
|
|
if (Points().Length() > 0) {
|
|
|
|
switch (Action()) {
|
|
|
|
case AndroidMotionEvent::ACTION_HOVER_MOVE:
|
|
|
|
msg = NS_MOUSE_MOVE;
|
|
|
|
break;
|
|
|
|
case AndroidMotionEvent::ACTION_HOVER_ENTER:
|
|
|
|
msg = NS_MOUSEENTER;
|
|
|
|
break;
|
|
|
|
case AndroidMotionEvent::ACTION_HOVER_EXIT:
|
|
|
|
msg = NS_MOUSELEAVE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WidgetMouseEvent event(true, msg, widget,
|
|
|
|
WidgetMouseEvent::eReal, WidgetMouseEvent::eNormal);
|
|
|
|
|
|
|
|
if (msg == NS_EVENT_NULL) {
|
|
|
|
// unknown type, or no point data. abort
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX can we synthesize different buttons?
|
|
|
|
event.button = WidgetMouseEvent::eLeftButton;
|
|
|
|
if (msg != NS_MOUSE_MOVE) {
|
|
|
|
event.clickCount = 1;
|
|
|
|
}
|
2013-12-18 06:25:10 +04:00
|
|
|
event.modifiers = DOMModifiers();
|
2013-10-16 01:11:39 +04:00
|
|
|
event.time = Time();
|
|
|
|
|
|
|
|
// We are dispatching this event directly into Gecko (as opposed to going
|
|
|
|
// through the AsyncPanZoomController), and the Points() array has points
|
|
|
|
// in CSS pixels, which we need to convert to LayoutDevice pixels.
|
|
|
|
const nsIntPoint& offset = widget->WidgetToScreenOffset();
|
|
|
|
CSSToLayoutDeviceScale scale = widget->GetDefaultScale();
|
|
|
|
event.refPoint = LayoutDeviceIntPoint((Points()[0].x * scale.scale) - offset.x,
|
|
|
|
(Points()[0].y * scale.scale) - offset.y);
|
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2013-12-18 06:25:10 +04:00
|
|
|
Modifiers
|
|
|
|
AndroidGeckoEvent::DOMModifiers() const
|
|
|
|
{
|
|
|
|
Modifiers result = 0;
|
|
|
|
if (mMetaState & AMETA_ALT_MASK) {
|
|
|
|
result |= MODIFIER_ALT;
|
|
|
|
}
|
|
|
|
if (mMetaState & AMETA_SHIFT_MASK) {
|
|
|
|
result |= MODIFIER_SHIFT;
|
|
|
|
}
|
|
|
|
if (mMetaState & AMETA_CTRL_MASK) {
|
|
|
|
result |= MODIFIER_CONTROL;
|
|
|
|
}
|
|
|
|
if (mMetaState & AMETA_META_MASK) {
|
|
|
|
result |= MODIFIER_META;
|
|
|
|
}
|
|
|
|
if (mMetaState & AMETA_FUNCTION_ON) {
|
|
|
|
result |= MODIFIER_FN;
|
|
|
|
}
|
|
|
|
if (mMetaState & AMETA_CAPS_LOCK_ON) {
|
|
|
|
result |= MODIFIER_CAPSLOCK;
|
|
|
|
}
|
|
|
|
if (mMetaState & AMETA_NUM_LOCK_ON) {
|
|
|
|
result |= MODIFIER_NUMLOCK;
|
|
|
|
}
|
|
|
|
if (mMetaState & AMETA_SCROLL_LOCK_ON) {
|
|
|
|
result |= MODIFIER_SCROLLLOCK;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-11-15 07:12:14 +04:00
|
|
|
void
|
|
|
|
AndroidPoint::Init(JNIEnv *jenv, jobject jobj)
|
|
|
|
{
|
|
|
|
if (jobj) {
|
|
|
|
mX = jenv->GetIntField(jobj, jXField);
|
|
|
|
mY = jenv->GetIntField(jobj, jYField);
|
|
|
|
} else {
|
|
|
|
mX = 0;
|
|
|
|
mY = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-19 19:56:09 +04:00
|
|
|
void
|
|
|
|
AndroidLayerRendererFrame::Init(JNIEnv *env, jobject jobj)
|
|
|
|
{
|
|
|
|
if (!isNull()) {
|
|
|
|
Dispose(env);
|
|
|
|
}
|
|
|
|
|
|
|
|
wrapped_obj = env->NewGlobalRef(jobj);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidLayerRendererFrame::Dispose(JNIEnv *env)
|
|
|
|
{
|
|
|
|
if (isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
env->DeleteGlobalRef(wrapped_obj);
|
|
|
|
wrapped_obj = 0;
|
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsAndroidDisplayport, nsIAndroidDisplayport)
|
2012-09-13 01:47:08 +04:00
|
|
|
|
2013-11-19 19:56:09 +04:00
|
|
|
bool
|
|
|
|
AndroidLayerRendererFrame::BeginDrawing(AutoLocalJNIFrame *jniFrame)
|
|
|
|
{
|
|
|
|
if (!jniFrame || !jniFrame->GetEnv())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
jniFrame->GetEnv()->CallVoidMethod(wrapped_obj, jBeginDrawingMethod);
|
|
|
|
if (jniFrame->CheckForException())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
AndroidLayerRendererFrame::DrawBackground(AutoLocalJNIFrame *jniFrame)
|
|
|
|
{
|
|
|
|
if (!jniFrame || !jniFrame->GetEnv())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
jniFrame->GetEnv()->CallVoidMethod(wrapped_obj, jDrawBackgroundMethod);
|
|
|
|
if (jniFrame->CheckForException())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
AndroidLayerRendererFrame::DrawForeground(AutoLocalJNIFrame *jniFrame)
|
|
|
|
{
|
|
|
|
if (!jniFrame || !jniFrame->GetEnv())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
jniFrame->GetEnv()->CallVoidMethod(wrapped_obj, jDrawForegroundMethod);
|
|
|
|
if (jniFrame->CheckForException())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
AndroidLayerRendererFrame::EndDrawing(AutoLocalJNIFrame *jniFrame)
|
|
|
|
{
|
|
|
|
if (!jniFrame || !jniFrame->GetEnv())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
jniFrame->GetEnv()->CallVoidMethod(wrapped_obj, jEndDrawingMethod);
|
|
|
|
if (jniFrame->CheckForException())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
void
|
|
|
|
AndroidRect::Init(JNIEnv *jenv, jobject jobj)
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ASSERTION(wrapped_obj == nullptr, "Init called on non-null wrapped_obj!");
|
2010-06-04 00:56:36 +04:00
|
|
|
|
|
|
|
wrapped_obj = jobj;
|
|
|
|
|
|
|
|
if (jobj) {
|
|
|
|
mTop = jenv->GetIntField(jobj, jTopField);
|
|
|
|
mLeft = jenv->GetIntField(jobj, jLeftField);
|
|
|
|
mRight = jenv->GetIntField(jobj, jRightField);
|
|
|
|
mBottom = jenv->GetIntField(jobj, jBottomField);
|
|
|
|
} else {
|
|
|
|
mTop = 0;
|
|
|
|
mLeft = 0;
|
|
|
|
mRight = 0;
|
|
|
|
mBottom = 0;
|
|
|
|
}
|
|
|
|
}
|
2010-06-14 23:04:16 +04:00
|
|
|
|
2012-09-13 01:47:08 +04:00
|
|
|
void
|
|
|
|
AndroidRectF::Init(JNIEnv *jenv, jobject jobj)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(wrapped_obj == nullptr, "Init called on non-null wrapped_obj!");
|
|
|
|
|
|
|
|
wrapped_obj = jobj;
|
|
|
|
|
|
|
|
if (jobj) {
|
|
|
|
mTop = jenv->GetFloatField(jobj, jTopField);
|
|
|
|
mLeft = jenv->GetFloatField(jobj, jLeftField);
|
|
|
|
mRight = jenv->GetFloatField(jobj, jRightField);
|
|
|
|
mBottom = jenv->GetFloatField(jobj, jBottomField);
|
|
|
|
} else {
|
|
|
|
mTop = 0;
|
|
|
|
mLeft = 0;
|
|
|
|
mRight = 0;
|
|
|
|
mBottom = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-15 06:17:37 +04:00
|
|
|
nsJNIString::nsJNIString(jstring jstr, JNIEnv *jenv)
|
2010-06-14 23:04:16 +04:00
|
|
|
{
|
2010-06-16 03:39:43 +04:00
|
|
|
if (!jstr) {
|
2011-10-17 18:59:28 +04:00
|
|
|
SetIsVoid(true);
|
2010-06-16 03:39:43 +04:00
|
|
|
return;
|
|
|
|
}
|
2010-06-15 06:17:37 +04:00
|
|
|
JNIEnv *jni = jenv;
|
2012-04-28 20:55:59 +04:00
|
|
|
if (!jni) {
|
2012-01-30 00:39:30 +04:00
|
|
|
jni = AndroidBridge::GetJNIEnv();
|
2012-04-28 20:55:59 +04:00
|
|
|
}
|
2013-10-11 00:42:52 +04:00
|
|
|
const jchar* jCharPtr = jni->GetStringChars(jstr, nullptr);
|
2011-03-02 03:03:38 +03:00
|
|
|
|
|
|
|
if (!jCharPtr) {
|
2011-10-17 18:59:28 +04:00
|
|
|
SetIsVoid(true);
|
2011-01-25 21:51:29 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-02 03:03:38 +03:00
|
|
|
jsize len = jni->GetStringLength(jstr);
|
|
|
|
|
|
|
|
if (len <= 0) {
|
2011-10-17 18:59:28 +04:00
|
|
|
SetIsVoid(true);
|
2011-03-02 03:03:38 +03:00
|
|
|
} else {
|
2014-01-04 19:02:17 +04:00
|
|
|
Assign(reinterpret_cast<const char16_t*>(jCharPtr), len);
|
2011-03-02 03:03:38 +03:00
|
|
|
}
|
2010-06-15 06:17:37 +04:00
|
|
|
jni->ReleaseStringChars(jstr, jCharPtr);
|
2010-06-14 23:04:16 +04:00
|
|
|
}
|
2014-06-04 23:04:12 +04:00
|
|
|
|
|
|
|
nsJNICString::nsJNICString(jstring jstr, JNIEnv *jenv)
|
|
|
|
{
|
|
|
|
if (!jstr) {
|
|
|
|
SetIsVoid(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
JNIEnv *jni = jenv;
|
|
|
|
if (!jni) {
|
|
|
|
jni = AndroidBridge::GetJNIEnv();
|
|
|
|
}
|
|
|
|
const char* jCharPtr = jni->GetStringUTFChars(jstr, nullptr);
|
|
|
|
|
|
|
|
if (!jCharPtr) {
|
|
|
|
SetIsVoid(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
jsize len = jni->GetStringUTFLength(jstr);
|
|
|
|
|
|
|
|
if (len <= 0) {
|
|
|
|
SetIsVoid(true);
|
|
|
|
} else {
|
|
|
|
Assign(jCharPtr, len);
|
|
|
|
}
|
|
|
|
jni->ReleaseStringUTFChars(jstr, jCharPtr);
|
|
|
|
}
|