2010-06-04 00:56:36 +04:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Android code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Vladimir Vukicevic <vladimir@pobox.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#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;
|
|
|
|
jfieldID AndroidGeckoEvent::jP0Field = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jP1Field = 0;
|
2011-04-30 03:49:20 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jAlphaField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jBetaField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jGammaField = 0;
|
2011-06-20 09:36:17 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jXField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jYField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jZField = 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;
|
2010-06-04 00:56:36 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jKeyCodeField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jMetaStateField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jFlagsField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jUnicodeCharField = 0;
|
2010-08-04 23:47:26 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jOffsetField = 0;
|
2010-06-04 00:56:36 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jCountField = 0;
|
2010-08-04 23:47:26 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jRangeTypeField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jRangeStylesField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jRangeForeColorField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jRangeBackColorField = 0;
|
2010-06-05 01:14:43 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jLocationField = 0;
|
2011-03-17 10:03:11 +03:00
|
|
|
jfieldID AndroidGeckoEvent::jAddressField = 0;
|
2012-01-17 22:40:39 +04:00
|
|
|
jfieldID AndroidGeckoEvent::jBandwidthField = 0;
|
|
|
|
jfieldID AndroidGeckoEvent::jCanBeMeteredField = 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;
|
|
|
|
|
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;
|
|
|
|
|
2011-03-17 10:03:11 +03:00
|
|
|
jclass AndroidAddress::jAddressClass = 0;
|
|
|
|
jmethodID AndroidAddress::jGetAddressLineMethod;
|
|
|
|
jmethodID AndroidAddress::jGetAdminAreaMethod;
|
|
|
|
jmethodID AndroidAddress::jGetCountryNameMethod;
|
|
|
|
jmethodID AndroidAddress::jGetFeatureNameMethod;
|
|
|
|
jmethodID AndroidAddress::jGetLocalityMethod;
|
|
|
|
jmethodID AndroidAddress::jGetPostalCodeMethod;
|
|
|
|
jmethodID AndroidAddress::jGetPremisesMethod;
|
|
|
|
jmethodID AndroidAddress::jGetSubAdminAreaMethod;
|
|
|
|
jmethodID AndroidAddress::jGetSubLocalityMethod;
|
|
|
|
jmethodID AndroidAddress::jGetSubThoroughfareMethod;
|
|
|
|
jmethodID AndroidAddress::jGetThoroughfareMethod;
|
|
|
|
|
2011-11-15 07:12:14 +04:00
|
|
|
jclass AndroidGeckoSoftwareLayerClient::jGeckoSoftwareLayerClientClass = 0;
|
|
|
|
jmethodID AndroidGeckoSoftwareLayerClient::jLockBufferMethod = 0;
|
|
|
|
jmethodID AndroidGeckoSoftwareLayerClient::jUnlockBufferMethod = 0;
|
|
|
|
jmethodID AndroidGeckoSoftwareLayerClient::jBeginDrawingMethod = 0;
|
|
|
|
jmethodID AndroidGeckoSoftwareLayerClient::jEndDrawingMethod = 0;
|
2010-06-04 00:56:36 +04:00
|
|
|
jclass AndroidGeckoSurfaceView::jGeckoSurfaceViewClass = 0;
|
|
|
|
jmethodID AndroidGeckoSurfaceView::jBeginDrawingMethod = 0;
|
|
|
|
jmethodID AndroidGeckoSurfaceView::jEndDrawingMethod = 0;
|
2011-06-16 13:03:00 +04:00
|
|
|
jmethodID AndroidGeckoSurfaceView::jDraw2DBitmapMethod = 0;
|
|
|
|
jmethodID AndroidGeckoSurfaceView::jDraw2DBufferMethod = 0;
|
|
|
|
jmethodID AndroidGeckoSurfaceView::jGetSoftwareDrawBitmapMethod = 0;
|
2010-06-04 00:56:36 +04:00
|
|
|
jmethodID AndroidGeckoSurfaceView::jGetSoftwareDrawBufferMethod = 0;
|
2011-09-21 20:46:00 +04:00
|
|
|
jmethodID AndroidGeckoSurfaceView::jGetSurfaceMethod = 0;
|
2010-06-26 04:52:37 +04:00
|
|
|
jmethodID AndroidGeckoSurfaceView::jGetHolderMethod = 0;
|
2010-06-04 00:56:36 +04:00
|
|
|
|
|
|
|
#define JNI() (AndroidBridge::JNI())
|
|
|
|
|
|
|
|
#define initInit() jclass jClass
|
|
|
|
|
|
|
|
// note that this also sets jClass
|
|
|
|
#define getClassGlobalRef(cname) \
|
|
|
|
(jClass = jclass(jEnv->NewGlobalRef(jEnv->FindClass(cname))))
|
|
|
|
|
|
|
|
#define getField(fname, ftype) \
|
|
|
|
((jfieldID) jEnv->GetFieldID(jClass, fname, ftype))
|
|
|
|
|
|
|
|
#define getMethod(fname, ftype) \
|
|
|
|
((jmethodID) jEnv->GetMethodID(jClass, fname, ftype))
|
|
|
|
|
|
|
|
void
|
|
|
|
mozilla::InitAndroidJavaWrappers(JNIEnv *jEnv)
|
|
|
|
{
|
|
|
|
AndroidGeckoEvent::InitGeckoEventClass(jEnv);
|
|
|
|
AndroidPoint::InitPointClass(jEnv);
|
2010-06-05 01:14:43 +04:00
|
|
|
AndroidLocation::InitLocationClass(jEnv);
|
2011-03-17 10:03:11 +03:00
|
|
|
AndroidAddress::InitAddressClass(jEnv);
|
2011-11-15 07:12:14 +04:00
|
|
|
AndroidRect::InitRectClass(jEnv);
|
|
|
|
AndroidGeckoSoftwareLayerClient::InitGeckoSoftwareLayerClientClass(jEnv);
|
2011-11-15 21:30:59 +04:00
|
|
|
AndroidGeckoSurfaceView::InitGeckoSurfaceViewClass(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");
|
|
|
|
jTimeField = getField("mTime", "J");
|
|
|
|
jP0Field = getField("mP0", "Landroid/graphics/Point;");
|
|
|
|
jP1Field = getField("mP1", "Landroid/graphics/Point;");
|
2011-04-30 03:49:20 +04:00
|
|
|
jAlphaField = getField("mAlpha", "D");
|
|
|
|
jBetaField = getField("mBeta", "D");
|
|
|
|
jGammaField = getField("mGamma", "D");
|
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;");
|
2010-06-04 00:56:36 +04:00
|
|
|
jKeyCodeField = getField("mKeyCode", "I");
|
|
|
|
jMetaStateField = getField("mMetaState", "I");
|
|
|
|
jFlagsField = getField("mFlags", "I");
|
|
|
|
jUnicodeCharField = getField("mUnicodeChar", "I");
|
2010-08-04 23:47:26 +04:00
|
|
|
jOffsetField = getField("mOffset", "I");
|
2010-06-04 00:56:36 +04:00
|
|
|
jCountField = getField("mCount", "I");
|
2010-08-04 23:47:26 +04:00
|
|
|
jRangeTypeField = getField("mRangeType", "I");
|
|
|
|
jRangeStylesField = getField("mRangeStyles", "I");
|
|
|
|
jRangeForeColorField = getField("mRangeForeColor", "I");
|
|
|
|
jRangeBackColorField = getField("mRangeBackColor", "I");
|
2010-06-05 01:14:43 +04:00
|
|
|
jLocationField = getField("mLocation", "Landroid/location/Location;");
|
2011-03-17 10:03:11 +03:00
|
|
|
jAddressField = getField("mAddress", "Landroid/location/Address;");
|
2012-01-17 22:40:39 +04:00
|
|
|
jBandwidthField = getField("mBandwidth", "D");
|
|
|
|
jCanBeMeteredField = getField("mCanBeMetered", "Z");
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidGeckoSurfaceView::InitGeckoSurfaceViewClass(JNIEnv *jEnv)
|
|
|
|
{
|
2011-11-15 21:30:59 +04:00
|
|
|
#ifndef MOZ_JAVA_COMPOSITOR
|
2010-06-04 00:56:36 +04:00
|
|
|
initInit();
|
|
|
|
|
|
|
|
jGeckoSurfaceViewClass = getClassGlobalRef("org/mozilla/gecko/GeckoSurfaceView");
|
|
|
|
|
|
|
|
jBeginDrawingMethod = getMethod("beginDrawing", "()I");
|
2011-06-16 13:03:00 +04:00
|
|
|
jGetSoftwareDrawBitmapMethod = getMethod("getSoftwareDrawBitmap", "()Landroid/graphics/Bitmap;");
|
2010-06-04 00:56:36 +04:00
|
|
|
jGetSoftwareDrawBufferMethod = getMethod("getSoftwareDrawBuffer", "()Ljava/nio/ByteBuffer;");
|
|
|
|
jEndDrawingMethod = getMethod("endDrawing", "()V");
|
2011-06-16 13:03:00 +04:00
|
|
|
jDraw2DBitmapMethod = getMethod("draw2D", "(Landroid/graphics/Bitmap;II)V");
|
|
|
|
jDraw2DBufferMethod = getMethod("draw2D", "(Ljava/nio/ByteBuffer;I)V");
|
2011-09-21 20:46:00 +04:00
|
|
|
jGetSurfaceMethod = getMethod("getSurface", "()Landroid/view/Surface;");
|
2010-06-26 04:52:37 +04:00
|
|
|
jGetHolderMethod = getMethod("getHolder", "()Landroid/view/SurfaceHolder;");
|
2011-11-15 21:30:59 +04:00
|
|
|
#endif
|
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");
|
|
|
|
}
|
|
|
|
|
2011-03-17 10:03:11 +03:00
|
|
|
void
|
|
|
|
AndroidAddress::InitAddressClass(JNIEnv *jEnv)
|
|
|
|
{
|
|
|
|
initInit();
|
|
|
|
|
|
|
|
jAddressClass = getClassGlobalRef("android/location/Address");
|
|
|
|
|
|
|
|
jGetAddressLineMethod = getMethod("getAddressLine", "(I)Ljava/lang/String;");
|
|
|
|
jGetAdminAreaMethod = getMethod("getAdminArea", "()Ljava/lang/String;");
|
|
|
|
jGetCountryNameMethod = getMethod("getCountryName", "()Ljava/lang/String;");
|
|
|
|
jGetFeatureNameMethod = getMethod("getFeatureName", "()Ljava/lang/String;");
|
|
|
|
jGetLocalityMethod = getMethod("getLocality", "()Ljava/lang/String;");
|
|
|
|
jGetPostalCodeMethod = getMethod("getPostalCode", "()Ljava/lang/String;");
|
|
|
|
jGetPremisesMethod = getMethod("getPremises", "()Ljava/lang/String;");
|
|
|
|
jGetSubAdminAreaMethod = getMethod("getSubAdminArea", "()Ljava/lang/String;");
|
|
|
|
jGetSubLocalityMethod = getMethod("getSubLocality", "()Ljava/lang/String;");
|
|
|
|
jGetSubThoroughfareMethod = getMethod("getSubThoroughfare", "()Ljava/lang/String;");
|
|
|
|
jGetThoroughfareMethod = getMethod("getThoroughfare", "()Ljava/lang/String;");
|
|
|
|
}
|
|
|
|
|
|
|
|
nsGeoPositionAddress*
|
|
|
|
AndroidAddress::CreateGeoPositionAddress(JNIEnv *jenv, jobject jobj)
|
|
|
|
{
|
|
|
|
nsJNIString streetNumber(static_cast<jstring>(jenv->CallObjectMethod(jobj, jGetSubThoroughfareMethod)), jenv);
|
|
|
|
nsJNIString street(static_cast<jstring>(jenv->CallObjectMethod(jobj, jGetThoroughfareMethod)), jenv);
|
|
|
|
nsJNIString city(static_cast<jstring>(jenv->CallObjectMethod(jobj, jGetLocalityMethod)), jenv);
|
|
|
|
nsJNIString county(static_cast<jstring>(jenv->CallObjectMethod(jobj, jGetSubAdminAreaMethod)), jenv);
|
|
|
|
nsJNIString country(static_cast<jstring>(jenv->CallObjectMethod(jobj, jGetCountryNameMethod)), jenv);
|
|
|
|
nsJNIString premises(static_cast<jstring>(jenv->CallObjectMethod(jobj, jGetPremisesMethod)), jenv);
|
|
|
|
nsJNIString postalCode(static_cast<jstring>(jenv->CallObjectMethod(jobj, jGetPostalCodeMethod)), jenv);
|
|
|
|
nsJNIString region(static_cast<jstring>(jenv->CallObjectMethod(jobj, jGetAdminAreaMethod, 0)), jenv);
|
|
|
|
|
2011-03-31 08:13:35 +04:00
|
|
|
#ifdef DEBUG
|
2011-03-17 10:03:11 +03:00
|
|
|
printf_stderr("!!!!!!!!!!!!!! AndroidAddress::CreateGeoPositionAddress:\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n",
|
|
|
|
NS_LossyConvertUTF16toASCII(streetNumber).get(),
|
|
|
|
NS_LossyConvertUTF16toASCII(street).get(),
|
|
|
|
NS_LossyConvertUTF16toASCII(premises).get(),
|
|
|
|
NS_LossyConvertUTF16toASCII(city).get(),
|
|
|
|
NS_LossyConvertUTF16toASCII(county).get(),
|
|
|
|
NS_LossyConvertUTF16toASCII(region).get(),
|
|
|
|
NS_LossyConvertUTF16toASCII(country).get(),
|
|
|
|
NS_LossyConvertUTF16toASCII(postalCode).get());
|
2011-03-31 08:13:35 +04:00
|
|
|
#endif
|
2011-03-17 10:03:11 +03:00
|
|
|
|
|
|
|
return new nsGeoPositionAddress(streetNumber,
|
|
|
|
street,
|
|
|
|
premises,
|
|
|
|
city,
|
|
|
|
county,
|
|
|
|
region,
|
|
|
|
country,
|
|
|
|
postalCode);
|
|
|
|
}
|
|
|
|
|
2010-06-05 01:14:43 +04:00
|
|
|
nsGeoPosition*
|
|
|
|
AndroidLocation::CreateGeoPosition(JNIEnv *jenv, jobject jobj)
|
|
|
|
{
|
|
|
|
double latitude = jenv->CallDoubleMethod(jobj, jGetLatitudeMethod);
|
|
|
|
double longitude = jenv->CallDoubleMethod(jobj, jGetLongitudeMethod);
|
|
|
|
double altitude = jenv->CallDoubleMethod(jobj, jGetAltitudeMethod);
|
|
|
|
float accuracy = jenv->CallFloatMethod (jobj, jGetAccuracyMethod);
|
|
|
|
float bearing = jenv->CallFloatMethod (jobj, jGetBearingMethod);
|
|
|
|
float speed = jenv->CallFloatMethod (jobj, jGetSpeedMethod);
|
|
|
|
long long time = jenv->CallLongMethod (jobj, jGetTimeMethod);
|
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2011-11-15 07:12:14 +04:00
|
|
|
void
|
|
|
|
AndroidGeckoSoftwareLayerClient::InitGeckoSoftwareLayerClientClass(JNIEnv *jEnv)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_JAVA_COMPOSITOR
|
|
|
|
initInit();
|
|
|
|
|
|
|
|
jGeckoSoftwareLayerClientClass =
|
|
|
|
getClassGlobalRef("org/mozilla/gecko/gfx/GeckoSoftwareLayerClient");
|
|
|
|
|
|
|
|
jLockBufferMethod = getMethod("lockBuffer", "()Ljava/nio/ByteBuffer;");
|
|
|
|
jUnlockBufferMethod = getMethod("unlockBuffer", "()V");
|
2011-12-24 04:49:00 +04:00
|
|
|
jBeginDrawingMethod = getMethod("beginDrawing", "(II)V");
|
2011-11-18 07:20:29 +04:00
|
|
|
jEndDrawingMethod = getMethod("endDrawing", "(IIIILjava/lang/String;)V");
|
2011-11-15 07:12:14 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
#undef initInit
|
|
|
|
#undef initClassGlobalRef
|
|
|
|
#undef getField
|
|
|
|
#undef getMethod
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidGeckoEvent::ReadP0Field(JNIEnv *jenv)
|
|
|
|
{
|
|
|
|
AndroidPoint p0(jenv, jenv->GetObjectField(wrappedObject(), jP0Field));
|
|
|
|
mP0.x = p0.X();
|
|
|
|
mP0.y = p0.Y();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidGeckoEvent::ReadP1Field(JNIEnv *jenv)
|
|
|
|
{
|
|
|
|
AndroidPoint p1(jenv, jenv->GetObjectField(wrappedObject(), jP1Field));
|
|
|
|
mP1.x = p1.X();
|
|
|
|
mP1.y = p1.Y();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidGeckoEvent::ReadRectField(JNIEnv *jenv)
|
|
|
|
{
|
|
|
|
AndroidRect r(jenv, jenv->GetObjectField(wrappedObject(), jRectField));
|
|
|
|
if (!r.isNull()) {
|
|
|
|
mRect.SetRect(r.Left(),
|
|
|
|
r.Top(),
|
|
|
|
r.Right() - r.Left(),
|
|
|
|
r.Bottom() - r.Top());
|
|
|
|
} else {
|
2011-04-19 07:07:23 +04:00
|
|
|
mRect.SetEmpty();
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidGeckoEvent::ReadCharactersField(JNIEnv *jenv)
|
|
|
|
{
|
|
|
|
jstring s = (jstring) jenv->GetObjectField(wrapped_obj, jCharactersField);
|
|
|
|
if (!s) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mCharacters.SetIsVoid(true);
|
2010-06-04 00:56:36 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int len = jenv->GetStringLength(s);
|
|
|
|
mCharacters.SetLength(len);
|
|
|
|
jenv->GetStringRegion(s, 0, len, mCharacters.BeginWriting());
|
|
|
|
}
|
|
|
|
|
2011-11-15 07:12:14 +04:00
|
|
|
void
|
|
|
|
AndroidGeckoEvent::ReadCharactersExtraField(JNIEnv *jenv)
|
|
|
|
{
|
|
|
|
jstring s = (jstring) jenv->GetObjectField(wrapped_obj, jCharactersExtraField);
|
|
|
|
if (!s) {
|
|
|
|
mCharactersExtra.SetIsVoid(PR_TRUE);
|
|
|
|
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-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);
|
|
|
|
|
|
|
|
switch (mType) {
|
2012-01-06 15:22:11 +04:00
|
|
|
case TILE_SIZE:
|
|
|
|
ReadP0Field(jenv);
|
|
|
|
break;
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
case SIZE_CHANGED:
|
|
|
|
ReadP0Field(jenv);
|
|
|
|
ReadP1Field(jenv);
|
|
|
|
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);
|
|
|
|
ReadCharactersField(jenv);
|
|
|
|
break;
|
|
|
|
|
|
|
|
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);
|
2010-06-04 00:56:36 +04:00
|
|
|
ReadP0Field(jenv);
|
2010-07-08 01:34:12 +04:00
|
|
|
if (mCount > 1)
|
|
|
|
ReadP1Field(jenv);
|
2010-06-04 00:56:36 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IME_EVENT:
|
2010-08-04 23:47:26 +04: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-04 00:56:36 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DRAW:
|
|
|
|
ReadRectField(jenv);
|
|
|
|
break;
|
|
|
|
|
2011-06-20 09:36:17 +04:00
|
|
|
case ORIENTATION_EVENT:
|
2011-04-30 03:49:20 +04:00
|
|
|
mAlpha = jenv->GetDoubleField(jobj, jAlphaField);
|
|
|
|
mBeta = jenv->GetDoubleField(jobj, jBetaField);
|
|
|
|
mGamma = jenv->GetDoubleField(jobj, jGammaField);
|
2010-06-04 00:56:36 +04:00
|
|
|
break;
|
|
|
|
|
2011-06-20 09:36:17 +04:00
|
|
|
case ACCELERATION_EVENT:
|
|
|
|
mX = jenv->GetDoubleField(jobj, jXField);
|
|
|
|
mY = jenv->GetDoubleField(jobj, jYField);
|
|
|
|
mZ = jenv->GetDoubleField(jobj, jZField);
|
|
|
|
break;
|
|
|
|
|
2010-06-05 01:14:43 +04:00
|
|
|
case LOCATION_EVENT: {
|
|
|
|
jobject location = jenv->GetObjectField(jobj, jLocationField);
|
2011-03-17 10:03:11 +03:00
|
|
|
jobject address = jenv->GetObjectField(jobj, jAddressField);
|
|
|
|
|
2010-06-05 01:14:43 +04:00
|
|
|
mGeoPosition = AndroidLocation::CreateGeoPosition(jenv, location);
|
2011-03-17 10:03:11 +03:00
|
|
|
if (address)
|
|
|
|
mGeoAddress = AndroidAddress::CreateGeoPositionAddress(jenv, address);
|
2010-06-05 01:14:43 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-06-18 21:42:51 +04:00
|
|
|
case LOAD_URI: {
|
|
|
|
ReadCharactersField(jenv);
|
|
|
|
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: {
|
|
|
|
mBandwidth = jenv->GetDoubleField(jobj, jBandwidthField);
|
|
|
|
mCanBeMetered = jenv->GetBooleanField(jobj, jCanBeMeteredField);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-08-29 22:29:39 +04:00
|
|
|
#ifndef 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-01-19 03:25:20 +03:00
|
|
|
AndroidGeckoEvent::Init(int x1, int y1, int x2, int y2)
|
2010-06-04 00:56:36 +04:00
|
|
|
{
|
|
|
|
mType = DRAW;
|
2011-04-19 07:07:23 +04:00
|
|
|
mRect.SetEmpty();
|
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;
|
|
|
|
mTime = aResizeEvent->mTime;
|
|
|
|
mP0.x = aResizeEvent->mP0.x;
|
|
|
|
mP0.y = aResizeEvent->mP0.y;
|
|
|
|
mP1.x = aResizeEvent->mP1.x;
|
|
|
|
mP1.y = aResizeEvent->mP1.y;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidGeckoSoftwareLayerClient::Init(jobject jobj)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(wrapped_obj == nsnull, "Init called on non-null wrapped_obj!");
|
|
|
|
wrapped_obj = jobj;
|
|
|
|
}
|
|
|
|
|
2010-06-04 00:56:36 +04: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!");
|
|
|
|
|
|
|
|
return JNI()->CallIntMethod(wrapped_obj, jBeginDrawingMethod);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidGeckoSurfaceView::EndDrawing()
|
|
|
|
{
|
|
|
|
JNI()->CallVoidMethod(wrapped_obj, jEndDrawingMethod);
|
|
|
|
}
|
|
|
|
|
2011-06-16 13:03:00 +04:00
|
|
|
void
|
|
|
|
AndroidGeckoSurfaceView::Draw2D(jobject bitmap, int width, int height)
|
|
|
|
{
|
|
|
|
JNI()->CallVoidMethod(wrapped_obj, jDraw2DBitmapMethod, bitmap, width, height);
|
|
|
|
}
|
|
|
|
|
2010-06-29 10:42:28 +04:00
|
|
|
void
|
2010-11-09 05:11:13 +03:00
|
|
|
AndroidGeckoSurfaceView::Draw2D(jobject buffer, int stride)
|
2010-06-04 00:56:36 +04:00
|
|
|
{
|
2011-06-16 13:03:00 +04:00
|
|
|
JNI()->CallVoidMethod(wrapped_obj, jDraw2DBufferMethod, buffer, stride);
|
|
|
|
}
|
|
|
|
|
2011-11-15 07:12:14 +04:00
|
|
|
jobject
|
|
|
|
AndroidGeckoSoftwareLayerClient::LockBuffer()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!isNull(), "LockBuffer() called on null software layer client!");
|
|
|
|
AndroidBridge::AutoLocalJNIFrame(1);
|
|
|
|
return JNI()->CallObjectMethod(wrapped_obj, jLockBufferMethod);
|
|
|
|
}
|
|
|
|
|
2011-11-15 21:30:59 +04:00
|
|
|
unsigned char *
|
|
|
|
AndroidGeckoSoftwareLayerClient::LockBufferBits()
|
|
|
|
{
|
|
|
|
AndroidBridge::AutoLocalJNIFrame(1);
|
2011-12-16 03:45:52 +04:00
|
|
|
jobject bufferObject = LockBuffer();
|
|
|
|
|
|
|
|
if (bufferObject != nsnull)
|
|
|
|
return reinterpret_cast<unsigned char *>(JNI()->GetDirectBufferAddress(bufferObject));
|
|
|
|
|
|
|
|
return nsnull;
|
2011-11-15 21:30:59 +04:00
|
|
|
}
|
|
|
|
|
2011-11-15 07:12:14 +04:00
|
|
|
void
|
|
|
|
AndroidGeckoSoftwareLayerClient::UnlockBuffer()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!isNull(), "UnlockBuffer() called on null software layer client!");
|
|
|
|
AndroidBridge::AutoLocalJNIFrame(1);
|
|
|
|
JNI()->CallVoidMethod(wrapped_obj, jUnlockBufferMethod);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-12-24 04:49:00 +04:00
|
|
|
AndroidGeckoSoftwareLayerClient::BeginDrawing(int aWidth, int aHeight)
|
2011-11-15 07:12:14 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!isNull(), "BeginDrawing() called on null software layer client!");
|
|
|
|
AndroidBridge::AutoLocalJNIFrame(1);
|
2011-12-24 04:49:00 +04:00
|
|
|
return JNI()->CallVoidMethod(wrapped_obj, jBeginDrawingMethod, aWidth, aHeight);
|
2011-11-15 07:12:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-11-18 07:20:29 +04:00
|
|
|
AndroidGeckoSoftwareLayerClient::EndDrawing(const nsIntRect &aRect, const nsAString &aMetadata)
|
2011-11-15 07:12:14 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!isNull(), "EndDrawing() called on null software layer client!");
|
|
|
|
AndroidBridge::AutoLocalJNIFrame(1);
|
2011-11-18 07:20:29 +04:00
|
|
|
jstring jMetadata = JNI()->NewString(nsPromiseFlatString(aMetadata).get(), aMetadata.Length());
|
2011-11-15 07:12:14 +04:00
|
|
|
return JNI()->CallVoidMethod(wrapped_obj, jEndDrawingMethod, aRect.x, aRect.y, aRect.width,
|
2011-11-18 07:20:29 +04:00
|
|
|
aRect.height, jMetadata);
|
2011-11-15 07:12:14 +04:00
|
|
|
}
|
|
|
|
|
2011-06-16 13:03:00 +04:00
|
|
|
jobject
|
|
|
|
AndroidGeckoSurfaceView::GetSoftwareDrawBitmap()
|
|
|
|
{
|
|
|
|
return JNI()->CallObjectMethod(wrapped_obj, jGetSoftwareDrawBitmapMethod);
|
2010-06-29 10:42:28 +04:00
|
|
|
}
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2010-06-29 10:42:28 +04:00
|
|
|
jobject
|
|
|
|
AndroidGeckoSurfaceView::GetSoftwareDrawBuffer()
|
|
|
|
{
|
|
|
|
return JNI()->CallObjectMethod(wrapped_obj, jGetSoftwareDrawBufferMethod);
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
2011-09-21 20:46:00 +04:00
|
|
|
jobject
|
|
|
|
AndroidGeckoSurfaceView::GetSurface()
|
|
|
|
{
|
|
|
|
return JNI()->CallObjectMethod(wrapped_obj, jGetSurfaceMethod);
|
|
|
|
}
|
|
|
|
|
2010-06-26 04:52:37 +04:00
|
|
|
jobject
|
|
|
|
AndroidGeckoSurfaceView::GetSurfaceHolder()
|
|
|
|
{
|
|
|
|
return JNI()->CallObjectMethod(wrapped_obj, jGetHolderMethod);
|
|
|
|
}
|
|
|
|
|
2010-06-04 00:56:36 +04: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 23:04:16 +04:00
|
|
|
|
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;
|
|
|
|
if (!jni)
|
|
|
|
jni = JNI();
|
2011-01-25 21:51:29 +03:00
|
|
|
const jchar* jCharPtr = jni->GetStringChars(jstr, NULL);
|
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 {
|
|
|
|
Assign(jCharPtr, len);
|
|
|
|
}
|
2010-06-15 06:17:37 +04:00
|
|
|
jni->ReleaseStringChars(jstr, jCharPtr);
|
2010-06-14 23:04:16 +04:00
|
|
|
}
|