2010-06-03 13:56:36 -07:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
2012-05-21 04:12:37 -07: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-03 13:56:36 -07:00
|
|
|
|
|
|
|
#include "AndroidJavaWrappers.h"
|
|
|
|
#include "AndroidBridge.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
|
|
|
|
jclass AndroidGeckoEvent::jGeckoEventClass = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jActionField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jTypeField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jTimeField = 0;
|
2012-01-24 16:31:33 -08:00
|
|
|
jfieldID AndroidGeckoEvent::jPoints = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jPointIndicies = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jPressures = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jPointRadii = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jOrientations = 0;
|
2011-06-19 22:36:17 -07:00
|
|
|
jfieldID AndroidGeckoEvent::jXField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jYField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jZField = 0;
|
2011-10-29 03:35:29 -07:00
|
|
|
jfieldID AndroidGeckoEvent::jDistanceField = 0;
|
2010-06-03 13:56:36 -07:00
|
|
|
jfieldID AndroidGeckoEvent::jRectField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jNativeWindowField = 0;
|
|
|
|
|
|
|
|
jfieldID AndroidGeckoEvent::jCharactersField = 0;
|
2011-11-14 19:12:14 -08:00
|
|
|
jfieldID AndroidGeckoEvent::jCharactersExtraField = 0;
|
2010-06-03 13:56:36 -07:00
|
|
|
jfieldID AndroidGeckoEvent::jKeyCodeField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jMetaStateField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jFlagsField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jUnicodeCharField = 0;
|
2012-04-19 13:55:33 -07:00
|
|
|
jfieldID AndroidGeckoEvent::jRepeatCountField = 0;
|
2010-08-04 12:47:26 -07:00
|
|
|
jfieldID AndroidGeckoEvent::jOffsetField = 0;
|
2010-06-03 13:56:36 -07:00
|
|
|
jfieldID AndroidGeckoEvent::jCountField = 0;
|
2012-01-24 16:31:33 -08:00
|
|
|
jfieldID AndroidGeckoEvent::jPointerIndexField = 0;
|
2010-08-04 12:47:26 -07:00
|
|
|
jfieldID AndroidGeckoEvent::jRangeTypeField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jRangeStylesField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jRangeForeColorField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jRangeBackColorField = 0;
|
2010-06-04 14:14:43 -07:00
|
|
|
jfieldID AndroidGeckoEvent::jLocationField = 0;
|
2012-01-17 10:40:39 -08:00
|
|
|
jfieldID AndroidGeckoEvent::jBandwidthField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jCanBeMeteredField = 0;
|
2012-03-20 06:09:45 -07:00
|
|
|
jfieldID AndroidGeckoEvent::jScreenOrientationField = 0;
|
2012-06-14 09:08:51 -07:00
|
|
|
jfieldID AndroidGeckoEvent::jByteBufferField = 0;
|
2010-06-03 13:56:36 -07: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;
|
|
|
|
|
2010-06-04 14:14:43 -07: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;
|
|
|
|
|
2012-02-02 22:07:05 -08:00
|
|
|
jclass AndroidGeckoLayerClient::jGeckoLayerClientClass = 0;
|
2012-03-12 08:50:21 -07:00
|
|
|
jmethodID AndroidGeckoLayerClient::jSetFirstPaintViewport = 0;
|
2012-05-23 07:51:39 -07:00
|
|
|
jmethodID AndroidGeckoLayerClient::jSetPageRect = 0;
|
2012-03-17 08:08:22 -07:00
|
|
|
jmethodID AndroidGeckoLayerClient::jSyncViewportInfoMethod = 0;
|
2012-02-22 11:45:44 -08:00
|
|
|
jmethodID AndroidGeckoLayerClient::jCreateFrameMethod = 0;
|
|
|
|
jmethodID AndroidGeckoLayerClient::jActivateProgramMethod = 0;
|
|
|
|
jmethodID AndroidGeckoLayerClient::jDeactivateProgramMethod = 0;
|
2012-02-09 22:58:18 -08:00
|
|
|
|
|
|
|
jclass AndroidLayerRendererFrame::jLayerRendererFrameClass = 0;
|
|
|
|
jmethodID AndroidLayerRendererFrame::jBeginDrawingMethod = 0;
|
|
|
|
jmethodID AndroidLayerRendererFrame::jDrawBackgroundMethod = 0;
|
|
|
|
jmethodID AndroidLayerRendererFrame::jDrawForegroundMethod = 0;
|
|
|
|
jmethodID AndroidLayerRendererFrame::jEndDrawingMethod = 0;
|
2012-02-03 23:31:05 -08:00
|
|
|
|
|
|
|
jclass AndroidViewTransform::jViewTransformClass = 0;
|
|
|
|
jfieldID AndroidViewTransform::jXField = 0;
|
|
|
|
jfieldID AndroidViewTransform::jYField = 0;
|
|
|
|
jfieldID AndroidViewTransform::jScaleField = 0;
|
2012-02-03 15:48:26 -08:00
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
jclass AndroidGeckoSurfaceView::jGeckoSurfaceViewClass = 0;
|
|
|
|
jmethodID AndroidGeckoSurfaceView::jBeginDrawingMethod = 0;
|
|
|
|
jmethodID AndroidGeckoSurfaceView::jEndDrawingMethod = 0;
|
2011-06-16 02:03:00 -07:00
|
|
|
jmethodID AndroidGeckoSurfaceView::jDraw2DBitmapMethod = 0;
|
|
|
|
jmethodID AndroidGeckoSurfaceView::jDraw2DBufferMethod = 0;
|
|
|
|
jmethodID AndroidGeckoSurfaceView::jGetSoftwareDrawBitmapMethod = 0;
|
2010-06-03 13:56:36 -07:00
|
|
|
jmethodID AndroidGeckoSurfaceView::jGetSoftwareDrawBufferMethod = 0;
|
2011-09-21 09:46:00 -07:00
|
|
|
jmethodID AndroidGeckoSurfaceView::jGetSurfaceMethod = 0;
|
2010-06-25 17:52:37 -07:00
|
|
|
jmethodID AndroidGeckoSurfaceView::jGetHolderMethod = 0;
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2012-07-11 10:29:03 -07:00
|
|
|
static jclass GetClassGlobalRef(JNIEnv* env, const char* className)
|
|
|
|
{
|
|
|
|
jobject classLocalRef = env->FindClass(className);
|
|
|
|
if (!classLocalRef) {
|
|
|
|
ALOG(">>> FATAL JNI ERROR! FindClass(className=\"%s\") failed. Did "
|
|
|
|
"ProGuard optimize away a non-public class?", className);
|
|
|
|
env->ExceptionDescribe();
|
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
|
|
|
|
|
|
|
jobject classGlobalRef = env->NewGlobalRef(classLocalRef);
|
|
|
|
if (!classGlobalRef) {
|
|
|
|
env->ExceptionDescribe();
|
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Local ref no longer necessary because we have a global ref.
|
|
|
|
env->DeleteLocalRef(classLocalRef);
|
|
|
|
classLocalRef = NULL;
|
|
|
|
|
|
|
|
return static_cast<jclass>(classGlobalRef);
|
|
|
|
}
|
|
|
|
|
|
|
|
static jfieldID GetFieldID(JNIEnv* env, jclass jClass,
|
|
|
|
const char* fieldName, const char* fieldType)
|
|
|
|
{
|
|
|
|
jfieldID fieldID = env->GetFieldID(jClass, fieldName, fieldType);
|
|
|
|
if (!fieldID) {
|
|
|
|
ALOG(">>> FATAL JNI ERROR! GetFieldID(fieldName=\"%s\", "
|
|
|
|
"fieldType=\"%s\") failed. Did ProGuard optimize away a non-"
|
|
|
|
"public field?", fieldName, fieldType);
|
|
|
|
env->ExceptionDescribe();
|
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
|
|
|
return fieldID;
|
|
|
|
}
|
|
|
|
|
|
|
|
static jmethodID GetMethodID(JNIEnv* env, jclass jClass,
|
|
|
|
const char* methodName, const char* methodType)
|
|
|
|
{
|
|
|
|
jmethodID methodID = env->GetMethodID(jClass, methodName, methodType);
|
|
|
|
if (!methodID) {
|
|
|
|
ALOG(">>> FATAL JNI ERROR! GetMethodID(methodName=\"%s\", "
|
|
|
|
"methodType=\"%s\") failed. Did ProGuard optimize away a non-"
|
|
|
|
"public method?", methodName, methodType);
|
|
|
|
env->ExceptionDescribe();
|
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
|
|
|
return methodID;
|
|
|
|
}
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
#define initInit() jclass jClass
|
|
|
|
|
|
|
|
// note that this also sets jClass
|
|
|
|
#define getClassGlobalRef(cname) \
|
2012-07-11 10:29:03 -07:00
|
|
|
(jClass = GetClassGlobalRef(jEnv, cname))
|
2010-06-03 13:56:36 -07:00
|
|
|
|
|
|
|
#define getField(fname, ftype) \
|
2012-07-11 10:29:03 -07:00
|
|
|
GetFieldID(jEnv, jClass, fname, ftype)
|
2010-06-03 13:56:36 -07:00
|
|
|
|
|
|
|
#define getMethod(fname, ftype) \
|
2012-07-11 10:29:03 -07:00
|
|
|
GetMethodID(jEnv, jClass, fname, ftype)
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2012-06-14 09:08:51 -07:00
|
|
|
RefCountedJavaObject::~RefCountedJavaObject() {
|
|
|
|
if (mObject)
|
|
|
|
GetJNIForThread()->DeleteGlobalRef(mObject);
|
|
|
|
mObject = NULL;
|
|
|
|
}
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
void
|
|
|
|
mozilla::InitAndroidJavaWrappers(JNIEnv *jEnv)
|
|
|
|
{
|
|
|
|
AndroidGeckoEvent::InitGeckoEventClass(jEnv);
|
|
|
|
AndroidPoint::InitPointClass(jEnv);
|
2010-06-04 14:14:43 -07:00
|
|
|
AndroidLocation::InitLocationClass(jEnv);
|
2011-11-14 19:12:14 -08:00
|
|
|
AndroidRect::InitRectClass(jEnv);
|
2012-02-02 22:07:05 -08:00
|
|
|
AndroidGeckoLayerClient::InitGeckoLayerClientClass(jEnv);
|
2012-02-09 22:58:18 -08:00
|
|
|
AndroidLayerRendererFrame::InitLayerRendererFrameClass(jEnv);
|
2012-02-03 23:31:05 -08:00
|
|
|
AndroidViewTransform::InitViewTransformClass(jEnv);
|
2011-11-15 09:30:59 -08:00
|
|
|
AndroidGeckoSurfaceView::InitGeckoSurfaceViewClass(jEnv);
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidGeckoEvent::InitGeckoEventClass(JNIEnv *jEnv)
|
|
|
|
{
|
|
|
|
initInit();
|
|
|
|
|
|
|
|
jGeckoEventClass = getClassGlobalRef("org/mozilla/gecko/GeckoEvent");
|
|
|
|
|
|
|
|
jActionField = getField("mAction", "I");
|
|
|
|
jTypeField = getField("mType", "I");
|
|
|
|
jTimeField = getField("mTime", "J");
|
2012-01-24 16:31:33 -08: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-19 22:36:17 -07:00
|
|
|
jXField = getField("mX", "D");
|
|
|
|
jYField = getField("mY", "D");
|
|
|
|
jZField = getField("mZ", "D");
|
2010-06-03 13:56:36 -07:00
|
|
|
jRectField = getField("mRect", "Landroid/graphics/Rect;");
|
|
|
|
|
|
|
|
jCharactersField = getField("mCharacters", "Ljava/lang/String;");
|
2011-11-14 19:12:14 -08:00
|
|
|
jCharactersExtraField = getField("mCharactersExtra", "Ljava/lang/String;");
|
2010-06-03 13:56:36 -07:00
|
|
|
jKeyCodeField = getField("mKeyCode", "I");
|
|
|
|
jMetaStateField = getField("mMetaState", "I");
|
|
|
|
jFlagsField = getField("mFlags", "I");
|
|
|
|
jUnicodeCharField = getField("mUnicodeChar", "I");
|
2012-04-19 13:55:33 -07:00
|
|
|
jRepeatCountField = getField("mRepeatCount", "I");
|
2010-08-04 12:47:26 -07:00
|
|
|
jOffsetField = getField("mOffset", "I");
|
2010-06-03 13:56:36 -07:00
|
|
|
jCountField = getField("mCount", "I");
|
2012-01-24 16:31:33 -08:00
|
|
|
jPointerIndexField = getField("mPointerIndex", "I");
|
2010-08-04 12:47:26 -07:00
|
|
|
jRangeTypeField = getField("mRangeType", "I");
|
|
|
|
jRangeStylesField = getField("mRangeStyles", "I");
|
|
|
|
jRangeForeColorField = getField("mRangeForeColor", "I");
|
|
|
|
jRangeBackColorField = getField("mRangeBackColor", "I");
|
2010-06-04 14:14:43 -07:00
|
|
|
jLocationField = getField("mLocation", "Landroid/location/Location;");
|
2012-01-17 10:40:39 -08:00
|
|
|
jBandwidthField = getField("mBandwidth", "D");
|
|
|
|
jCanBeMeteredField = getField("mCanBeMetered", "Z");
|
2012-03-20 06:09:45 -07:00
|
|
|
jScreenOrientationField = getField("mScreenOrientation", "S");
|
2012-06-14 09:08:51 -07:00
|
|
|
jByteBufferField = getField("mBuffer", "Ljava/nio/ByteBuffer;");
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidGeckoSurfaceView::InitGeckoSurfaceViewClass(JNIEnv *jEnv)
|
|
|
|
{
|
2011-11-15 09:30:59 -08:00
|
|
|
#ifndef MOZ_JAVA_COMPOSITOR
|
2010-06-03 13:56:36 -07:00
|
|
|
initInit();
|
|
|
|
|
|
|
|
jGeckoSurfaceViewClass = getClassGlobalRef("org/mozilla/gecko/GeckoSurfaceView");
|
|
|
|
|
|
|
|
jBeginDrawingMethod = getMethod("beginDrawing", "()I");
|
2011-06-16 02:03:00 -07:00
|
|
|
jGetSoftwareDrawBitmapMethod = getMethod("getSoftwareDrawBitmap", "()Landroid/graphics/Bitmap;");
|
2010-06-03 13:56:36 -07:00
|
|
|
jGetSoftwareDrawBufferMethod = getMethod("getSoftwareDrawBuffer", "()Ljava/nio/ByteBuffer;");
|
|
|
|
jEndDrawingMethod = getMethod("endDrawing", "()V");
|
2011-06-16 02:03:00 -07:00
|
|
|
jDraw2DBitmapMethod = getMethod("draw2D", "(Landroid/graphics/Bitmap;II)V");
|
|
|
|
jDraw2DBufferMethod = getMethod("draw2D", "(Ljava/nio/ByteBuffer;I)V");
|
2011-09-21 09:46:00 -07:00
|
|
|
jGetSurfaceMethod = getMethod("getSurface", "()Landroid/view/Surface;");
|
2010-06-25 17:52:37 -07:00
|
|
|
jGetHolderMethod = getMethod("getHolder", "()Landroid/view/SurfaceHolder;");
|
2011-11-15 09:30:59 -08:00
|
|
|
#endif
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
2010-06-04 14:14:43 -07: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 08:08:47 -07:00
|
|
|
AutoLocalJNIFrame jniFrame(jenv);
|
|
|
|
|
2010-06-04 14:14:43 -07:00
|
|
|
double latitude = jenv->CallDoubleMethod(jobj, jGetLatitudeMethod);
|
2012-05-04 08:08:47 -07:00
|
|
|
if (jniFrame.CheckForException()) return NULL;
|
2010-06-04 14:14:43 -07:00
|
|
|
double longitude = jenv->CallDoubleMethod(jobj, jGetLongitudeMethod);
|
2012-05-04 08:08:47 -07:00
|
|
|
if (jniFrame.CheckForException()) return NULL;
|
2010-06-04 14:14:43 -07:00
|
|
|
double altitude = jenv->CallDoubleMethod(jobj, jGetAltitudeMethod);
|
2012-05-04 08:08:47 -07:00
|
|
|
if (jniFrame.CheckForException()) return NULL;
|
2010-06-04 14:14:43 -07:00
|
|
|
float accuracy = jenv->CallFloatMethod (jobj, jGetAccuracyMethod);
|
2012-05-04 08:08:47 -07:00
|
|
|
if (jniFrame.CheckForException()) return NULL;
|
2010-06-04 14:14:43 -07:00
|
|
|
float bearing = jenv->CallFloatMethod (jobj, jGetBearingMethod);
|
2012-05-04 08:08:47 -07:00
|
|
|
if (jniFrame.CheckForException()) return NULL;
|
2010-06-04 14:14:43 -07:00
|
|
|
float speed = jenv->CallFloatMethod (jobj, jGetSpeedMethod);
|
2012-05-04 08:08:47 -07:00
|
|
|
if (jniFrame.CheckForException()) return NULL;
|
2010-06-04 14:14:43 -07:00
|
|
|
long long time = jenv->CallLongMethod (jobj, jGetTimeMethod);
|
2012-05-04 08:08:47 -07:00
|
|
|
if (jniFrame.CheckForException()) return NULL;
|
2010-06-04 14:14:43 -07:00
|
|
|
|
|
|
|
return new nsGeoPosition(latitude, longitude,
|
|
|
|
altitude, accuracy,
|
|
|
|
accuracy, bearing,
|
|
|
|
speed, time);
|
|
|
|
}
|
|
|
|
|
2010-06-03 13:56:36 -07: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-02-02 22:07:05 -08:00
|
|
|
void
|
|
|
|
AndroidGeckoLayerClient::InitGeckoLayerClientClass(JNIEnv *jEnv)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_JAVA_COMPOSITOR
|
|
|
|
initInit();
|
|
|
|
|
|
|
|
jGeckoLayerClientClass = getClassGlobalRef("org/mozilla/gecko/gfx/GeckoLayerClient");
|
|
|
|
|
2012-05-23 07:51:39 -07:00
|
|
|
jSetFirstPaintViewport = getMethod("setFirstPaintViewport", "(FFFFFFFFFFF)V");
|
2012-06-13 10:49:40 -07:00
|
|
|
jSetPageRect = getMethod("setPageRect", "(FFFF)V");
|
2012-03-17 08:08:22 -07:00
|
|
|
jSyncViewportInfoMethod = getMethod("syncViewportInfo",
|
2012-03-19 21:06:56 -07:00
|
|
|
"(IIIIFZ)Lorg/mozilla/gecko/gfx/ViewTransform;");
|
2012-02-13 20:20:38 -08:00
|
|
|
jCreateFrameMethod = getMethod("createFrame", "()Lorg/mozilla/gecko/gfx/LayerRenderer$Frame;");
|
2012-02-13 13:55:10 -08:00
|
|
|
jActivateProgramMethod = getMethod("activateProgram", "()V");
|
|
|
|
jDeactivateProgramMethod = getMethod("deactivateProgram", "()V");
|
2012-02-09 22:58:18 -08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidLayerRendererFrame::InitLayerRendererFrameClass(JNIEnv *jEnv)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_JAVA_COMPOSITOR
|
|
|
|
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");
|
2012-02-03 23:31:05 -08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidViewTransform::InitViewTransformClass(JNIEnv *jEnv)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_JAVA_COMPOSITOR
|
|
|
|
initInit();
|
|
|
|
|
|
|
|
jViewTransformClass = getClassGlobalRef("org/mozilla/gecko/gfx/ViewTransform");
|
|
|
|
|
|
|
|
jXField = getField("x", "F");
|
|
|
|
jYField = getField("y", "F");
|
|
|
|
jScaleField = getField("scale", "F");
|
2012-02-03 15:48:26 -08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
#undef initInit
|
|
|
|
#undef initClassGlobalRef
|
|
|
|
#undef getField
|
|
|
|
#undef getMethod
|
|
|
|
|
|
|
|
void
|
2012-01-24 16:31:33 -08:00
|
|
|
AndroidGeckoEvent::ReadPointArray(nsTArray<nsIntPoint> &points,
|
|
|
|
JNIEnv *jenv,
|
|
|
|
jfieldID field,
|
2012-07-12 09:52:52 -07:00
|
|
|
PRInt32 count)
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
2012-01-24 16:31:33 -08:00
|
|
|
jobjectArray jObjArray = (jobjectArray)jenv->GetObjectField(wrapped_obj, field);
|
|
|
|
for (PRInt32 i = 0; i < count; i++) {
|
|
|
|
jobject jObj = jenv->GetObjectArrayElement(jObjArray, i);
|
|
|
|
AndroidPoint jpoint(jenv, jObj);
|
|
|
|
|
|
|
|
nsIntPoint p(jpoint.X(), jpoint.Y());
|
|
|
|
points.AppendElement(p);
|
|
|
|
}
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-01-24 16:31:33 -08:00
|
|
|
AndroidGeckoEvent::ReadIntArray(nsTArray<int> &aVals,
|
|
|
|
JNIEnv *jenv,
|
|
|
|
jfieldID field,
|
2012-07-12 09:52:52 -07:00
|
|
|
PRInt32 count)
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
2012-01-24 16:31:33 -08:00
|
|
|
jintArray jIntArray = (jintArray)jenv->GetObjectField(wrapped_obj, field);
|
|
|
|
jint *vals = jenv->GetIntArrayElements(jIntArray, false);
|
|
|
|
for (PRInt32 i = 0; i < count; i++) {
|
|
|
|
aVals.AppendElement(vals[i]);
|
|
|
|
}
|
|
|
|
jenv->ReleaseIntArrayElements(jIntArray, vals, JNI_ABORT);
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
2012-01-24 07:39:53 -08:00
|
|
|
void
|
2012-01-24 16:31:33 -08:00
|
|
|
AndroidGeckoEvent::ReadFloatArray(nsTArray<float> &aVals,
|
|
|
|
JNIEnv *jenv,
|
|
|
|
jfieldID field,
|
2012-07-12 09:52:52 -07:00
|
|
|
PRInt32 count)
|
2012-01-24 07:39:53 -08:00
|
|
|
{
|
2012-01-24 16:31:33 -08:00
|
|
|
jfloatArray jFloatArray = (jfloatArray)jenv->GetObjectField(wrapped_obj, field);
|
|
|
|
jfloat *vals = jenv->GetFloatArrayElements(jFloatArray, false);
|
|
|
|
for (PRInt32 i = 0; i < count; i++) {
|
|
|
|
aVals.AppendElement(vals[i]);
|
|
|
|
}
|
|
|
|
jenv->ReleaseFloatArrayElements(jFloatArray, vals, JNI_ABORT);
|
2010-06-03 13:56:36 -07: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 09:28:10 -08:00
|
|
|
r.Width(),
|
|
|
|
r.Height());
|
2010-06-03 13:56:36 -07:00
|
|
|
} else {
|
2011-04-18 20:07:23 -07:00
|
|
|
mRect.SetEmpty();
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidGeckoEvent::ReadCharactersField(JNIEnv *jenv)
|
|
|
|
{
|
|
|
|
jstring s = (jstring) jenv->GetObjectField(wrapped_obj, jCharactersField);
|
|
|
|
if (!s) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mCharacters.SetIsVoid(true);
|
2010-06-03 13:56:36 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int len = jenv->GetStringLength(s);
|
|
|
|
mCharacters.SetLength(len);
|
|
|
|
jenv->GetStringRegion(s, 0, len, mCharacters.BeginWriting());
|
|
|
|
}
|
|
|
|
|
2011-11-14 19:12:14 -08:00
|
|
|
void
|
|
|
|
AndroidGeckoEvent::ReadCharactersExtraField(JNIEnv *jenv)
|
|
|
|
{
|
|
|
|
jstring s = (jstring) jenv->GetObjectField(wrapped_obj, jCharactersExtraField);
|
|
|
|
if (!s) {
|
2012-04-04 02:15:10 -07:00
|
|
|
mCharactersExtra.SetIsVoid(true);
|
2011-11-14 19:12:14 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int len = jenv->GetStringLength(s);
|
|
|
|
mCharactersExtra.SetLength(len);
|
|
|
|
jenv->GetStringRegion(s, 0, len, mCharactersExtra.BeginWriting());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidGeckoEvent::Init(int aType, nsIntRect const& aRect)
|
|
|
|
{
|
|
|
|
mType = aType;
|
|
|
|
mRect = aRect;
|
|
|
|
}
|
|
|
|
|
2010-06-03 13:56:36 -07: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);
|
|
|
|
|
|
|
|
switch (mType) {
|
|
|
|
case SIZE_CHANGED:
|
2012-02-24 07:51:41 -08:00
|
|
|
ReadPointArray(mPoints, jenv, jPoints, 2);
|
2010-06-03 13:56:36 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_EVENT:
|
|
|
|
mTime = jenv->GetLongField(jobj, jTimeField);
|
|
|
|
mMetaState = jenv->GetIntField(jobj, jMetaStateField);
|
|
|
|
mFlags = jenv->GetIntField(jobj, jFlagsField);
|
|
|
|
mKeyCode = jenv->GetIntField(jobj, jKeyCodeField);
|
|
|
|
mUnicodeChar = jenv->GetIntField(jobj, jUnicodeCharField);
|
2012-04-19 13:55:33 -07:00
|
|
|
mRepeatCount = jenv->GetIntField(jobj, jRepeatCountField);
|
2010-06-03 13:56:36 -07:00
|
|
|
ReadCharactersField(jenv);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MOTION_EVENT:
|
|
|
|
mTime = jenv->GetLongField(jobj, jTimeField);
|
2010-12-21 14:36:28 -08:00
|
|
|
mMetaState = jenv->GetIntField(jobj, jMetaStateField);
|
2010-07-07 14:34:12 -07:00
|
|
|
mCount = jenv->GetIntField(jobj, jCountField);
|
2012-01-24 16:31:33 -08: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-03 13:56:36 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IME_EVENT:
|
2010-08-04 12:47:26 -07:00
|
|
|
if (mAction == IME_GET_TEXT || mAction == IME_SET_SELECTION) {
|
|
|
|
mOffset = jenv->GetIntField(jobj, jOffsetField);
|
|
|
|
mCount = jenv->GetIntField(jobj, jCountField);
|
|
|
|
} else if (mAction == IME_SET_TEXT || mAction == IME_ADD_RANGE) {
|
|
|
|
if (mAction == IME_SET_TEXT)
|
|
|
|
ReadCharactersField(jenv);
|
|
|
|
mOffset = jenv->GetIntField(jobj, jOffsetField);
|
|
|
|
mCount = jenv->GetIntField(jobj, jCountField);
|
|
|
|
mRangeType = jenv->GetIntField(jobj, jRangeTypeField);
|
|
|
|
mRangeStyles = jenv->GetIntField(jobj, jRangeStylesField);
|
|
|
|
mRangeForeColor =
|
|
|
|
jenv->GetIntField(jobj, jRangeForeColorField);
|
|
|
|
mRangeBackColor =
|
|
|
|
jenv->GetIntField(jobj, jRangeBackColorField);
|
|
|
|
}
|
2010-06-03 13:56:36 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DRAW:
|
|
|
|
ReadRectField(jenv);
|
|
|
|
break;
|
|
|
|
|
2012-03-13 16:57:51 -07: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-20 23:36:17 -07:00
|
|
|
mMetaState = jenv->GetIntField(jobj, jMetaStateField);
|
2012-03-13 16:57:51 -07:00
|
|
|
break;
|
2011-06-19 22:36:17 -07:00
|
|
|
|
2010-06-04 14:14:43 -07:00
|
|
|
case LOCATION_EVENT: {
|
|
|
|
jobject location = jenv->GetObjectField(jobj, jLocationField);
|
|
|
|
mGeoPosition = AndroidLocation::CreateGeoPosition(jenv, location);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-06-18 10:42:51 -07:00
|
|
|
case LOAD_URI: {
|
|
|
|
ReadCharactersField(jenv);
|
2012-04-13 19:45:25 -07:00
|
|
|
ReadCharactersExtraField(jenv);
|
2010-06-18 10:42:51 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-22 03:35:32 -08:00
|
|
|
case VIEWPORT:
|
2011-11-14 19:12:14 -08:00
|
|
|
case BROADCAST: {
|
|
|
|
ReadCharactersField(jenv);
|
|
|
|
ReadCharactersExtraField(jenv);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-01-17 10:40:39 -08:00
|
|
|
case NETWORK_CHANGED: {
|
|
|
|
mBandwidth = jenv->GetDoubleField(jobj, jBandwidthField);
|
|
|
|
mCanBeMetered = jenv->GetBooleanField(jobj, jCanBeMeteredField);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-01-24 06:59:31 -08:00
|
|
|
case VISITED: {
|
|
|
|
ReadCharactersField(jenv);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-02-15 12:34:31 -08:00
|
|
|
case ACTIVITY_STOPPING:
|
|
|
|
case ACTIVITY_START:
|
|
|
|
case ACTIVITY_PAUSING:
|
|
|
|
case ACTIVITY_RESUMING: {
|
|
|
|
mFlags = jenv->GetIntField(jobj, jFlagsField);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-02-20 13:37:51 -08:00
|
|
|
case SCREENSHOT: {
|
|
|
|
mMetaState = jenv->GetIntField(jobj, jMetaStateField);
|
2012-04-24 12:13:36 -07:00
|
|
|
mFlags = jenv->GetIntField(jobj, jFlagsField);
|
2012-06-14 09:08:51 -07:00
|
|
|
ReadPointArray(mPoints, jenv, jPoints, 5);
|
|
|
|
mByteBuffer = new RefCountedJavaObject(jenv, jenv->GetObjectField(jobj, jByteBufferField));
|
2012-04-24 12:13:36 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PAINT_LISTEN_START_EVENT: {
|
|
|
|
mMetaState = jenv->GetIntField(jobj, jMetaStateField);
|
2012-04-23 18:05:23 -07:00
|
|
|
break;
|
2012-02-20 13:37:51 -08:00
|
|
|
}
|
|
|
|
|
2012-03-20 06:09:45 -07:00
|
|
|
case SCREENORIENTATION_CHANGED: {
|
|
|
|
mScreenOrientation = jenv->GetShortField(jobj, jScreenOrientationField);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-03-20 23:36:17 -07:00
|
|
|
#ifdef DEBUG_ANDROID_EVENTS
|
2011-01-18 16:25:20 -08:00
|
|
|
ALOG("AndroidGeckoEvent: %p : %d", (void*)jobj, mType);
|
2010-06-03 13:56:36 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidGeckoEvent::Init(int aType)
|
|
|
|
{
|
|
|
|
mType = aType;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-01-18 16:25:20 -08:00
|
|
|
AndroidGeckoEvent::Init(int x1, int y1, int x2, int y2)
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
|
|
|
mType = DRAW;
|
2011-04-18 20:07:23 -07:00
|
|
|
mRect.SetEmpty();
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
2011-08-09 09:08:19 -07:00
|
|
|
void
|
|
|
|
AndroidGeckoEvent::Init(AndroidGeckoEvent *aResizeEvent)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aResizeEvent->Type() == SIZE_CHANGED, "Init called on non-SIZE_CHANGED event");
|
|
|
|
|
|
|
|
mType = FORCED_RESIZE;
|
|
|
|
mTime = aResizeEvent->mTime;
|
2012-01-24 16:31:33 -08:00
|
|
|
mPoints = aResizeEvent->mPoints; // x,y coordinates
|
2011-08-09 09:08:19 -07:00
|
|
|
}
|
|
|
|
|
2011-11-14 19:12:14 -08: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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-03 15:48:26 -08:00
|
|
|
void
|
2012-02-22 11:45:44 -08:00
|
|
|
AndroidGeckoLayerClient::Init(jobject jobj)
|
2012-02-03 15:48:26 -08:00
|
|
|
{
|
|
|
|
NS_ASSERTION(wrapped_obj == nsnull, "Init called on non-null wrapped_obj!");
|
|
|
|
wrapped_obj = jobj;
|
2012-02-03 23:31:05 -08:00
|
|
|
}
|
|
|
|
|
2012-02-09 22:58:18 -08:00
|
|
|
void
|
2012-05-04 08:08:46 -07:00
|
|
|
AndroidLayerRendererFrame::Init(JNIEnv *env, jobject jobj)
|
2012-02-09 22:58:18 -08:00
|
|
|
{
|
2012-02-09 23:55:13 -08:00
|
|
|
if (!isNull()) {
|
2012-05-04 08:08:46 -07:00
|
|
|
Dispose(env);
|
2012-02-09 23:55:13 -08:00
|
|
|
}
|
|
|
|
|
2012-05-04 08:08:46 -07:00
|
|
|
wrapped_obj = env->NewGlobalRef(jobj);
|
2012-02-09 23:55:13 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-04 08:08:46 -07:00
|
|
|
AndroidLayerRendererFrame::Dispose(JNIEnv *env)
|
2012-02-09 23:55:13 -08:00
|
|
|
{
|
|
|
|
if (isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-04 08:08:46 -07:00
|
|
|
env->DeleteGlobalRef(wrapped_obj);
|
2012-02-09 23:55:13 -08:00
|
|
|
wrapped_obj = 0;
|
2012-02-09 22:58:18 -08:00
|
|
|
}
|
|
|
|
|
2012-02-03 23:31:05 -08:00
|
|
|
void
|
|
|
|
AndroidViewTransform::Init(jobject jobj)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(wrapped_obj == nsnull, "Init called on non-null wrapped_obj!");
|
|
|
|
wrapped_obj = jobj;
|
2012-02-03 15:48:26 -08:00
|
|
|
}
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
void
|
|
|
|
AndroidGeckoSurfaceView::Init(jobject jobj)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(wrapped_obj == nsnull, "Init called on non-null wrapped_obj!");
|
|
|
|
|
|
|
|
wrapped_obj = jobj;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
AndroidGeckoSurfaceView::BeginDrawing()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!isNull(), "BeginDrawing called on null surfaceview!");
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = AndroidBridge::GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return 0;
|
|
|
|
|
2012-05-04 08:08:47 -07:00
|
|
|
AutoLocalJNIFrame jniFrame(env, 0);
|
|
|
|
|
|
|
|
int ret = env->CallIntMethod(wrapped_obj, jBeginDrawingMethod);
|
|
|
|
if (jniFrame.CheckForException())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return ret;
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidGeckoSurfaceView::EndDrawing()
|
|
|
|
{
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = AndroidBridge::GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
2012-05-04 08:08:47 -07:00
|
|
|
AutoLocalJNIFrame jniFrame(env, 0);
|
2012-01-29 12:39:30 -08:00
|
|
|
env->CallVoidMethod(wrapped_obj, jEndDrawingMethod);
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
2011-06-16 02:03:00 -07:00
|
|
|
void
|
|
|
|
AndroidGeckoSurfaceView::Draw2D(jobject bitmap, int width, int height)
|
|
|
|
{
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = AndroidBridge::GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
2012-05-04 08:08:47 -07:00
|
|
|
AutoLocalJNIFrame jniFrame(env, 0);
|
2012-01-29 12:39:30 -08:00
|
|
|
env->CallVoidMethod(wrapped_obj, jDraw2DBitmapMethod, bitmap, width, height);
|
2011-06-16 02:03:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-28 23:42:28 -07:00
|
|
|
void
|
2010-11-08 18:11:13 -08:00
|
|
|
AndroidGeckoSurfaceView::Draw2D(jobject buffer, int stride)
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = AndroidBridge::GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
2012-05-04 08:08:47 -07:00
|
|
|
AutoLocalJNIFrame jniFrame(env, 0);
|
2012-01-29 12:39:30 -08:00
|
|
|
env->CallVoidMethod(wrapped_obj, jDraw2DBufferMethod, buffer, stride);
|
2011-06-16 02:03:00 -07:00
|
|
|
}
|
|
|
|
|
2012-03-12 08:50:21 -07:00
|
|
|
void
|
2012-05-23 07:51:39 -07:00
|
|
|
AndroidGeckoLayerClient::SetFirstPaintViewport(const nsIntPoint& aOffset, float aZoom, const nsIntRect& aPageRect, const gfx::Rect& aCssPageRect)
|
2012-03-12 08:50:21 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!isNull(), "SetFirstPaintViewport called on null layer client!");
|
2012-07-13 14:34:58 -07:00
|
|
|
JNIEnv *env = GetJNIForThread(); // this is called on the compositor thread
|
2012-03-12 08:50:21 -07:00
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
2012-05-04 08:08:47 -07:00
|
|
|
AutoLocalJNIFrame jniFrame(env, 0);
|
2012-05-23 07:51:39 -07:00
|
|
|
return env->CallVoidMethod(wrapped_obj, jSetFirstPaintViewport, (float)aOffset.x, (float)aOffset.y, aZoom,
|
|
|
|
(float)aPageRect.x, (float)aPageRect.y, (float)aPageRect.XMost(), (float)aPageRect.YMost(),
|
|
|
|
aCssPageRect.x, aCssPageRect.y, aCssPageRect.XMost(), aCssPageRect.YMost());
|
2012-03-12 08:50:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-06-13 10:49:40 -07:00
|
|
|
AndroidGeckoLayerClient::SetPageRect(const gfx::Rect& aCssPageRect)
|
2012-03-12 08:50:21 -07:00
|
|
|
{
|
2012-05-23 07:51:39 -07:00
|
|
|
NS_ASSERTION(!isNull(), "SetPageRect called on null layer client!");
|
2012-07-13 14:34:58 -07:00
|
|
|
JNIEnv *env = GetJNIForThread(); // this is called on the compositor thread
|
2012-03-12 08:50:21 -07:00
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
2012-05-04 08:08:47 -07:00
|
|
|
AutoLocalJNIFrame jniFrame(env, 0);
|
2012-06-13 10:49:40 -07:00
|
|
|
return env->CallVoidMethod(wrapped_obj, jSetPageRect,
|
2012-05-23 07:51:39 -07:00
|
|
|
aCssPageRect.x, aCssPageRect.y, aCssPageRect.XMost(), aCssPageRect.YMost());
|
2012-03-12 08:50:21 -07:00
|
|
|
}
|
|
|
|
|
2012-03-13 21:15:11 -07:00
|
|
|
void
|
2012-03-19 21:06:56 -07:00
|
|
|
AndroidGeckoLayerClient::SyncViewportInfo(const nsIntRect& aDisplayPort, float aDisplayResolution, bool aLayersUpdated,
|
|
|
|
nsIntPoint& aScrollOffset, float& aScaleX, float& aScaleY)
|
2012-03-13 21:15:11 -07:00
|
|
|
{
|
2012-03-17 08:08:22 -07:00
|
|
|
NS_ASSERTION(!isNull(), "SyncViewportInfo called on null layer client!");
|
2012-07-13 14:34:58 -07:00
|
|
|
JNIEnv *env = GetJNIForThread(); // this is called on the compositor thread
|
2012-03-13 21:15:11 -07:00
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
2012-05-04 08:08:47 -07:00
|
|
|
AutoLocalJNIFrame jniFrame(env);
|
2012-03-13 21:15:11 -07:00
|
|
|
|
2012-03-17 08:08:22 -07:00
|
|
|
jobject viewTransformJObj = env->CallObjectMethod(wrapped_obj, jSyncViewportInfoMethod,
|
|
|
|
aDisplayPort.x, aDisplayPort.y,
|
2012-03-19 21:05:45 -07:00
|
|
|
aDisplayPort.width, aDisplayPort.height,
|
2012-03-19 21:06:56 -07:00
|
|
|
aDisplayResolution, aLayersUpdated);
|
2012-05-04 08:08:47 -07:00
|
|
|
if (jniFrame.CheckForException())
|
|
|
|
return;
|
|
|
|
|
2012-03-13 21:15:11 -07:00
|
|
|
NS_ABORT_IF_FALSE(viewTransformJObj, "No view transform object!");
|
2012-05-04 08:08:47 -07:00
|
|
|
|
|
|
|
AndroidViewTransform viewTransform;
|
2012-03-13 21:15:11 -07:00
|
|
|
viewTransform.Init(viewTransformJObj);
|
|
|
|
|
2012-04-23 18:06:41 -07:00
|
|
|
aScrollOffset = nsIntPoint(viewTransform.GetX(env), viewTransform.GetY(env));
|
|
|
|
aScaleX = aScaleY = viewTransform.GetScale(env);
|
2012-03-13 21:15:11 -07:00
|
|
|
}
|
|
|
|
|
2011-06-16 02:03:00 -07:00
|
|
|
jobject
|
2012-05-08 06:35:59 -07:00
|
|
|
AndroidGeckoSurfaceView::GetSoftwareDrawBitmap(AutoLocalJNIFrame *jniFrame)
|
2011-06-16 02:03:00 -07:00
|
|
|
{
|
2012-05-08 06:35:59 -07:00
|
|
|
if (!jniFrame || !jniFrame->GetEnv())
|
2012-01-29 12:39:30 -08:00
|
|
|
return nsnull;
|
|
|
|
|
2012-05-08 06:35:59 -07:00
|
|
|
jobject ret = jniFrame->GetEnv()->CallObjectMethod(wrapped_obj, jGetSoftwareDrawBitmapMethod);
|
2012-05-04 08:08:47 -07:00
|
|
|
if (jniFrame->CheckForException())
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
return ret;
|
2010-06-28 23:42:28 -07:00
|
|
|
}
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2010-06-28 23:42:28 -07:00
|
|
|
jobject
|
2012-05-08 06:35:59 -07:00
|
|
|
AndroidGeckoSurfaceView::GetSoftwareDrawBuffer(AutoLocalJNIFrame *jniFrame)
|
2010-06-28 23:42:28 -07:00
|
|
|
{
|
2012-05-08 06:35:59 -07:00
|
|
|
if (!jniFrame || !jniFrame->GetEnv())
|
2012-05-04 08:08:47 -07:00
|
|
|
return nsnull;
|
|
|
|
|
2012-05-08 06:35:59 -07:00
|
|
|
jobject ret = jniFrame->GetEnv()->CallObjectMethod(wrapped_obj, jGetSoftwareDrawBufferMethod);
|
2012-05-04 08:08:47 -07:00
|
|
|
if (jniFrame->CheckForException())
|
2012-01-29 12:39:30 -08:00
|
|
|
return nsnull;
|
|
|
|
|
2012-05-04 08:08:47 -07:00
|
|
|
return ret;
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
2011-09-21 09:46:00 -07:00
|
|
|
jobject
|
2012-05-08 06:35:59 -07:00
|
|
|
AndroidGeckoSurfaceView::GetSurface(AutoLocalJNIFrame *jniFrame)
|
2011-09-21 09:46:00 -07:00
|
|
|
{
|
2012-05-08 06:35:59 -07:00
|
|
|
if (!jniFrame || !jniFrame->GetEnv())
|
2012-05-04 08:08:47 -07:00
|
|
|
return nsnull;
|
|
|
|
|
2012-05-08 06:35:59 -07:00
|
|
|
jobject ret = jniFrame->GetEnv()->CallObjectMethod(wrapped_obj, jGetSurfaceMethod);
|
2012-05-04 08:08:47 -07:00
|
|
|
if (jniFrame->CheckForException())
|
2012-01-29 12:39:30 -08:00
|
|
|
return nsnull;
|
|
|
|
|
2012-05-04 08:08:47 -07:00
|
|
|
return ret;
|
2011-09-21 09:46:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-25 17:52:37 -07:00
|
|
|
jobject
|
2012-05-08 06:35:59 -07:00
|
|
|
AndroidGeckoSurfaceView::GetSurfaceHolder(AutoLocalJNIFrame *jniFrame)
|
2010-06-25 17:52:37 -07:00
|
|
|
{
|
2012-05-08 06:35:59 -07:00
|
|
|
if (!jniFrame || !jniFrame->GetEnv())
|
2012-05-04 08:08:47 -07:00
|
|
|
return nsnull;
|
|
|
|
|
2012-05-08 06:35:59 -07:00
|
|
|
jobject ret = jniFrame->GetEnv()->CallObjectMethod(wrapped_obj, jGetHolderMethod);
|
2012-05-04 08:08:47 -07:00
|
|
|
if (jniFrame->CheckForException())
|
2012-04-28 09:55:59 -07:00
|
|
|
return nsnull;
|
|
|
|
|
2012-05-04 08:08:47 -07:00
|
|
|
return ret;
|
2010-06-25 17:52:37 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 08:08:47 -07:00
|
|
|
bool
|
2012-05-08 06:35:59 -07:00
|
|
|
AndroidGeckoLayerClient::CreateFrame(AutoLocalJNIFrame *jniFrame, AndroidLayerRendererFrame& aFrame)
|
2012-02-09 22:58:18 -08:00
|
|
|
{
|
2012-05-08 06:35:59 -07:00
|
|
|
if (!jniFrame || !jniFrame->GetEnv())
|
|
|
|
return false;
|
2012-05-04 08:08:47 -07:00
|
|
|
|
2012-05-08 06:35:59 -07:00
|
|
|
jobject frameJObj = jniFrame->GetEnv()->CallObjectMethod(wrapped_obj, jCreateFrameMethod);
|
|
|
|
if (jniFrame->CheckForException())
|
2012-05-04 08:08:47 -07:00
|
|
|
return false;
|
2012-02-09 22:58:18 -08:00
|
|
|
NS_ABORT_IF_FALSE(frameJObj, "No frame object!");
|
2012-05-04 08:08:47 -07:00
|
|
|
|
2012-05-08 06:35:59 -07:00
|
|
|
aFrame.Init(jniFrame->GetEnv(), frameJObj);
|
2012-05-04 08:08:47 -07:00
|
|
|
return true;
|
2012-02-09 22:58:18 -08:00
|
|
|
}
|
|
|
|
|
2012-05-08 06:35:59 -07:00
|
|
|
bool
|
|
|
|
AndroidGeckoLayerClient::ActivateProgram(AutoLocalJNIFrame *jniFrame)
|
2012-02-13 13:55:10 -08:00
|
|
|
{
|
2012-05-08 06:35:59 -07:00
|
|
|
if (!jniFrame || !jniFrame->GetEnv())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
jniFrame->GetEnv()->CallVoidMethod(wrapped_obj, jActivateProgramMethod);
|
|
|
|
if (jniFrame->CheckForException())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2012-02-13 13:55:10 -08:00
|
|
|
}
|
|
|
|
|
2012-05-08 06:35:59 -07:00
|
|
|
bool
|
|
|
|
AndroidGeckoLayerClient::DeactivateProgram(AutoLocalJNIFrame *jniFrame)
|
2012-02-13 13:55:10 -08:00
|
|
|
{
|
2012-05-08 06:35:59 -07:00
|
|
|
if (!jniFrame || !jniFrame->GetEnv())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
jniFrame->GetEnv()->CallVoidMethod(wrapped_obj, jDeactivateProgramMethod);
|
|
|
|
if (jniFrame->CheckForException())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2012-02-13 13:55:10 -08:00
|
|
|
}
|
|
|
|
|
2012-05-08 06:35:59 -07:00
|
|
|
bool
|
|
|
|
AndroidLayerRendererFrame::BeginDrawing(AutoLocalJNIFrame *jniFrame)
|
2012-02-09 22:58:18 -08:00
|
|
|
{
|
2012-05-08 06:35:59 -07:00
|
|
|
if (!jniFrame || !jniFrame->GetEnv())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
jniFrame->GetEnv()->CallVoidMethod(wrapped_obj, jBeginDrawingMethod);
|
|
|
|
if (jniFrame->CheckForException())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2012-02-09 22:58:18 -08:00
|
|
|
}
|
|
|
|
|
2012-05-08 06:35:59 -07:00
|
|
|
bool
|
|
|
|
AndroidLayerRendererFrame::DrawBackground(AutoLocalJNIFrame *jniFrame)
|
2012-02-09 22:58:18 -08:00
|
|
|
{
|
2012-05-08 06:35:59 -07:00
|
|
|
if (!jniFrame || !jniFrame->GetEnv())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
jniFrame->GetEnv()->CallVoidMethod(wrapped_obj, jDrawBackgroundMethod);
|
|
|
|
if (jniFrame->CheckForException())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2012-02-09 22:58:18 -08:00
|
|
|
}
|
|
|
|
|
2012-05-08 06:35:59 -07:00
|
|
|
bool
|
|
|
|
AndroidLayerRendererFrame::DrawForeground(AutoLocalJNIFrame *jniFrame)
|
2012-02-09 22:58:18 -08:00
|
|
|
{
|
2012-05-08 06:35:59 -07:00
|
|
|
if (!jniFrame || !jniFrame->GetEnv())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
jniFrame->GetEnv()->CallVoidMethod(wrapped_obj, jDrawForegroundMethod);
|
|
|
|
if (jniFrame->CheckForException())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2012-02-09 22:58:18 -08:00
|
|
|
}
|
|
|
|
|
2012-05-08 06:35:59 -07:00
|
|
|
bool
|
|
|
|
AndroidLayerRendererFrame::EndDrawing(AutoLocalJNIFrame *jniFrame)
|
2012-02-09 22:58:18 -08:00
|
|
|
{
|
2012-05-08 06:35:59 -07:00
|
|
|
if (!jniFrame || !jniFrame->GetEnv())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
jniFrame->GetEnv()->CallVoidMethod(wrapped_obj, jEndDrawingMethod);
|
|
|
|
if (jniFrame->CheckForException())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2012-02-09 22:58:18 -08:00
|
|
|
}
|
|
|
|
|
2012-02-03 23:31:05 -08:00
|
|
|
float
|
2012-04-23 18:06:41 -07:00
|
|
|
AndroidViewTransform::GetX(JNIEnv *env)
|
2012-02-03 23:31:05 -08:00
|
|
|
{
|
|
|
|
if (!env)
|
|
|
|
return 0.0f;
|
|
|
|
return env->GetFloatField(wrapped_obj, jXField);
|
|
|
|
}
|
|
|
|
|
|
|
|
float
|
2012-04-23 18:06:41 -07:00
|
|
|
AndroidViewTransform::GetY(JNIEnv *env)
|
2012-02-03 23:31:05 -08:00
|
|
|
{
|
|
|
|
if (!env)
|
|
|
|
return 0.0f;
|
|
|
|
return env->GetFloatField(wrapped_obj, jYField);
|
|
|
|
}
|
|
|
|
|
|
|
|
float
|
2012-04-23 18:06:41 -07:00
|
|
|
AndroidViewTransform::GetScale(JNIEnv *env)
|
2012-02-03 23:31:05 -08:00
|
|
|
{
|
|
|
|
if (!env)
|
|
|
|
return 0.0f;
|
|
|
|
return env->GetFloatField(wrapped_obj, jScaleField);
|
|
|
|
}
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
void
|
|
|
|
AndroidRect::Init(JNIEnv *jenv, jobject jobj)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(wrapped_obj == nsnull, "Init called on non-null wrapped_obj!");
|
|
|
|
|
|
|
|
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 12:04:16 -07:00
|
|
|
|
2010-06-14 19:17:37 -07:00
|
|
|
nsJNIString::nsJNIString(jstring jstr, JNIEnv *jenv)
|
2010-06-14 12:04:16 -07:00
|
|
|
{
|
2010-06-15 16:39:43 -07:00
|
|
|
if (!jstr) {
|
2011-10-17 07:59:28 -07:00
|
|
|
SetIsVoid(true);
|
2010-06-15 16:39:43 -07:00
|
|
|
return;
|
|
|
|
}
|
2010-06-14 19:17:37 -07:00
|
|
|
JNIEnv *jni = jenv;
|
2012-04-28 09:55:59 -07:00
|
|
|
if (!jni) {
|
2012-01-29 12:39:30 -08:00
|
|
|
jni = AndroidBridge::GetJNIEnv();
|
2012-04-28 09:55:59 -07:00
|
|
|
if (!jni) {
|
|
|
|
SetIsVoid(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2011-01-25 10:51:29 -08:00
|
|
|
const jchar* jCharPtr = jni->GetStringChars(jstr, NULL);
|
2011-03-01 16:03:38 -08:00
|
|
|
|
|
|
|
if (!jCharPtr) {
|
2011-10-17 07:59:28 -07:00
|
|
|
SetIsVoid(true);
|
2011-01-25 10:51:29 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-01 16:03:38 -08:00
|
|
|
jsize len = jni->GetStringLength(jstr);
|
|
|
|
|
|
|
|
if (len <= 0) {
|
2011-10-17 07:59:28 -07:00
|
|
|
SetIsVoid(true);
|
2011-03-01 16:03:38 -08:00
|
|
|
} else {
|
|
|
|
Assign(jCharPtr, len);
|
|
|
|
}
|
2010-06-14 19:17:37 -07:00
|
|
|
jni->ReleaseStringChars(jstr, jCharPtr);
|
2010-06-14 12:04:16 -07:00
|
|
|
}
|