Bug 839641 - Add a stub NativePanZoomController class to start Java bindings to APZC. r=Cwiiis

This commit is contained in:
Kartikaya Gupta 2013-04-26 13:24:28 -04:00
parent f23210bd17
commit 8203bd4391
8 changed files with 372 additions and 7 deletions

View File

@ -194,11 +194,12 @@ FENNEC_JAVA_FILES = \
gfx/LayerMarginsAnimator.java \
gfx/LayerRenderer.java \
gfx/LayerView.java \
gfx/PluginLayer.java \
gfx/NativePanZoomController.java \
gfx/NinePatchTileLayer.java \
gfx/PanningPerfAPI.java \
gfx/PanZoomController.java \
gfx/PanZoomTarget.java \
gfx/PluginLayer.java \
gfx/PointUtils.java \
gfx/ProgressiveUpdateData.java \
gfx/RectUtils.java \
@ -1118,7 +1119,8 @@ jars:
CLASSES_WITH_JNI= \
org.mozilla.gecko.GeckoAppShell \
org.mozilla.gecko.GeckoJavaSampler \
org.mozilla.gecko.GeckoJavaSampler \
org.mozilla.gecko.gfx.NativePanZoomController \
$(NULL)
ifdef MOZ_WEBSMS_BACKEND

View File

@ -113,6 +113,7 @@ public class GeckoLayerClient implements LayerView.Listener, PanZoomTarget
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
mViewportMetrics = new ImmutableViewportMetrics(displayMetrics)
.setViewportSize(view.getWidth(), view.getHeight());
mFrameMetrics = mViewportMetrics;
mZoomConstraints = new ZoomConstraints(false);
mPanZoomController = PanZoomController.Factory.create(this, view, eventDispatcher);

View File

@ -0,0 +1,80 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* 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/. */
package org.mozilla.gecko.gfx;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.GeckoThread;
import org.mozilla.gecko.util.EventDispatcher;
import org.mozilla.gecko.util.GeckoEventListener;
import org.json.JSONObject;
import android.graphics.PointF;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
class NativePanZoomController implements PanZoomController, GeckoEventListener {
private final EventDispatcher mDispatcher;
NativePanZoomController(PanZoomTarget target, View view, EventDispatcher dispatcher) {
mDispatcher = dispatcher;
if (GeckoThread.checkLaunchState(GeckoThread.LaunchState.GeckoRunning)) {
init();
} else {
mDispatcher.registerEventListener("Gecko:Ready", this);
}
}
public void handleMessage(String event, JSONObject message) {
if ("Gecko:Ready".equals(event)) {
mDispatcher.unregisterEventListener("Gecko:Ready", this);
init();
}
}
public boolean onTouchEvent(MotionEvent event) {
// FIXME implement this
return false;
}
public boolean onMotionEvent(MotionEvent event) {
// FIXME implement this
return false;
}
public boolean onKeyEvent(KeyEvent event) {
// FIXME implement this
return false;
}
public PointF getVelocityVector() {
// FIXME implement this
return new PointF(0, 0);
}
public void pageRectUpdated() {
// no-op in APZC, I think
}
public void abortPanning() {
// no-op in APZC, I think
}
public void abortAnimation() {
// no-op in APZC, I think
}
private native void init();
private native void handleTouchEvent(GeckoEvent event);
private native void handleMotionEvent(GeckoEvent event);
public native void destroy();
public native void notifyDefaultActionPrevented(boolean prevented);
public native boolean getRedrawHint();
public native void setOverScrollMode(int overscrollMode);
public native int getOverScrollMode();
}

View File

@ -71,6 +71,8 @@ class Generator:
returnValue = 'NULL'
elif returnType in ('jint', 'jfloat', 'jdouble'):
returnValue = '0'
elif returnType == 'jboolean':
returnValue = 'false'
else:
raise Exception(('Unsupported JNI return type %s found; '
+ 'please update mobile/android/base/'

View File

@ -398,3 +398,155 @@ Java_org_mozilla_gecko_GeckoJavaSampler_getProfilerTime(JNIEnv * arg0, jclass ar
xul_dlsym("Java_org_mozilla_gecko_GeckoJavaSampler_getProfilerTime", &f_Java_org_mozilla_gecko_GeckoJavaSampler_getProfilerTime);
#endif
#ifdef JNI_STUBS
typedef void (*Java_org_mozilla_gecko_gfx_NativePanZoomController_init_t)(JNIEnv *, jobject);
static Java_org_mozilla_gecko_gfx_NativePanZoomController_init_t f_Java_org_mozilla_gecko_gfx_NativePanZoomController_init;
extern "C" NS_EXPORT void JNICALL
Java_org_mozilla_gecko_gfx_NativePanZoomController_init(JNIEnv * arg0, jobject arg1) {
if (!f_Java_org_mozilla_gecko_gfx_NativePanZoomController_init) {
arg0->ThrowNew(arg0->FindClass("java/lang/UnsupportedOperationException"),
"JNI Function called before it was loaded");
return ;
}
f_Java_org_mozilla_gecko_gfx_NativePanZoomController_init(arg0, arg1);
}
#endif
#ifdef JNI_BINDINGS
xul_dlsym("Java_org_mozilla_gecko_gfx_NativePanZoomController_init", &f_Java_org_mozilla_gecko_gfx_NativePanZoomController_init);
#endif
#ifdef JNI_STUBS
typedef void (*Java_org_mozilla_gecko_gfx_NativePanZoomController_handleTouchEvent_t)(JNIEnv *, jobject, jobject);
static Java_org_mozilla_gecko_gfx_NativePanZoomController_handleTouchEvent_t f_Java_org_mozilla_gecko_gfx_NativePanZoomController_handleTouchEvent;
extern "C" NS_EXPORT void JNICALL
Java_org_mozilla_gecko_gfx_NativePanZoomController_handleTouchEvent(JNIEnv * arg0, jobject arg1, jobject arg2) {
if (!f_Java_org_mozilla_gecko_gfx_NativePanZoomController_handleTouchEvent) {
arg0->ThrowNew(arg0->FindClass("java/lang/UnsupportedOperationException"),
"JNI Function called before it was loaded");
return ;
}
f_Java_org_mozilla_gecko_gfx_NativePanZoomController_handleTouchEvent(arg0, arg1, arg2);
}
#endif
#ifdef JNI_BINDINGS
xul_dlsym("Java_org_mozilla_gecko_gfx_NativePanZoomController_handleTouchEvent", &f_Java_org_mozilla_gecko_gfx_NativePanZoomController_handleTouchEvent);
#endif
#ifdef JNI_STUBS
typedef void (*Java_org_mozilla_gecko_gfx_NativePanZoomController_handleMotionEvent_t)(JNIEnv *, jobject, jobject);
static Java_org_mozilla_gecko_gfx_NativePanZoomController_handleMotionEvent_t f_Java_org_mozilla_gecko_gfx_NativePanZoomController_handleMotionEvent;
extern "C" NS_EXPORT void JNICALL
Java_org_mozilla_gecko_gfx_NativePanZoomController_handleMotionEvent(JNIEnv * arg0, jobject arg1, jobject arg2) {
if (!f_Java_org_mozilla_gecko_gfx_NativePanZoomController_handleMotionEvent) {
arg0->ThrowNew(arg0->FindClass("java/lang/UnsupportedOperationException"),
"JNI Function called before it was loaded");
return ;
}
f_Java_org_mozilla_gecko_gfx_NativePanZoomController_handleMotionEvent(arg0, arg1, arg2);
}
#endif
#ifdef JNI_BINDINGS
xul_dlsym("Java_org_mozilla_gecko_gfx_NativePanZoomController_handleMotionEvent", &f_Java_org_mozilla_gecko_gfx_NativePanZoomController_handleMotionEvent);
#endif
#ifdef JNI_STUBS
typedef void (*Java_org_mozilla_gecko_gfx_NativePanZoomController_destroy_t)(JNIEnv *, jobject);
static Java_org_mozilla_gecko_gfx_NativePanZoomController_destroy_t f_Java_org_mozilla_gecko_gfx_NativePanZoomController_destroy;
extern "C" NS_EXPORT void JNICALL
Java_org_mozilla_gecko_gfx_NativePanZoomController_destroy(JNIEnv * arg0, jobject arg1) {
if (!f_Java_org_mozilla_gecko_gfx_NativePanZoomController_destroy) {
arg0->ThrowNew(arg0->FindClass("java/lang/UnsupportedOperationException"),
"JNI Function called before it was loaded");
return ;
}
f_Java_org_mozilla_gecko_gfx_NativePanZoomController_destroy(arg0, arg1);
}
#endif
#ifdef JNI_BINDINGS
xul_dlsym("Java_org_mozilla_gecko_gfx_NativePanZoomController_destroy", &f_Java_org_mozilla_gecko_gfx_NativePanZoomController_destroy);
#endif
#ifdef JNI_STUBS
typedef void (*Java_org_mozilla_gecko_gfx_NativePanZoomController_notifyDefaultActionPrevented_t)(JNIEnv *, jobject, jboolean);
static Java_org_mozilla_gecko_gfx_NativePanZoomController_notifyDefaultActionPrevented_t f_Java_org_mozilla_gecko_gfx_NativePanZoomController_notifyDefaultActionPrevented;
extern "C" NS_EXPORT void JNICALL
Java_org_mozilla_gecko_gfx_NativePanZoomController_notifyDefaultActionPrevented(JNIEnv * arg0, jobject arg1, jboolean arg2) {
if (!f_Java_org_mozilla_gecko_gfx_NativePanZoomController_notifyDefaultActionPrevented) {
arg0->ThrowNew(arg0->FindClass("java/lang/UnsupportedOperationException"),
"JNI Function called before it was loaded");
return ;
}
f_Java_org_mozilla_gecko_gfx_NativePanZoomController_notifyDefaultActionPrevented(arg0, arg1, arg2);
}
#endif
#ifdef JNI_BINDINGS
xul_dlsym("Java_org_mozilla_gecko_gfx_NativePanZoomController_notifyDefaultActionPrevented", &f_Java_org_mozilla_gecko_gfx_NativePanZoomController_notifyDefaultActionPrevented);
#endif
#ifdef JNI_STUBS
typedef jboolean (*Java_org_mozilla_gecko_gfx_NativePanZoomController_getRedrawHint_t)(JNIEnv *, jobject);
static Java_org_mozilla_gecko_gfx_NativePanZoomController_getRedrawHint_t f_Java_org_mozilla_gecko_gfx_NativePanZoomController_getRedrawHint;
extern "C" NS_EXPORT jboolean JNICALL
Java_org_mozilla_gecko_gfx_NativePanZoomController_getRedrawHint(JNIEnv * arg0, jobject arg1) {
if (!f_Java_org_mozilla_gecko_gfx_NativePanZoomController_getRedrawHint) {
arg0->ThrowNew(arg0->FindClass("java/lang/UnsupportedOperationException"),
"JNI Function called before it was loaded");
return false;
}
return f_Java_org_mozilla_gecko_gfx_NativePanZoomController_getRedrawHint(arg0, arg1);
}
#endif
#ifdef JNI_BINDINGS
xul_dlsym("Java_org_mozilla_gecko_gfx_NativePanZoomController_getRedrawHint", &f_Java_org_mozilla_gecko_gfx_NativePanZoomController_getRedrawHint);
#endif
#ifdef JNI_STUBS
typedef void (*Java_org_mozilla_gecko_gfx_NativePanZoomController_setOverScrollMode_t)(JNIEnv *, jobject, jint);
static Java_org_mozilla_gecko_gfx_NativePanZoomController_setOverScrollMode_t f_Java_org_mozilla_gecko_gfx_NativePanZoomController_setOverScrollMode;
extern "C" NS_EXPORT void JNICALL
Java_org_mozilla_gecko_gfx_NativePanZoomController_setOverScrollMode(JNIEnv * arg0, jobject arg1, jint arg2) {
if (!f_Java_org_mozilla_gecko_gfx_NativePanZoomController_setOverScrollMode) {
arg0->ThrowNew(arg0->FindClass("java/lang/UnsupportedOperationException"),
"JNI Function called before it was loaded");
return ;
}
f_Java_org_mozilla_gecko_gfx_NativePanZoomController_setOverScrollMode(arg0, arg1, arg2);
}
#endif
#ifdef JNI_BINDINGS
xul_dlsym("Java_org_mozilla_gecko_gfx_NativePanZoomController_setOverScrollMode", &f_Java_org_mozilla_gecko_gfx_NativePanZoomController_setOverScrollMode);
#endif
#ifdef JNI_STUBS
typedef jint (*Java_org_mozilla_gecko_gfx_NativePanZoomController_getOverScrollMode_t)(JNIEnv *, jobject);
static Java_org_mozilla_gecko_gfx_NativePanZoomController_getOverScrollMode_t f_Java_org_mozilla_gecko_gfx_NativePanZoomController_getOverScrollMode;
extern "C" NS_EXPORT jint JNICALL
Java_org_mozilla_gecko_gfx_NativePanZoomController_getOverScrollMode(JNIEnv * arg0, jobject arg1) {
if (!f_Java_org_mozilla_gecko_gfx_NativePanZoomController_getOverScrollMode) {
arg0->ThrowNew(arg0->FindClass("java/lang/UnsupportedOperationException"),
"JNI Function called before it was loaded");
return 0;
}
return f_Java_org_mozilla_gecko_gfx_NativePanZoomController_getOverScrollMode(arg0, arg1);
}
#endif
#ifdef JNI_BINDINGS
xul_dlsym("Java_org_mozilla_gecko_gfx_NativePanZoomController_getOverScrollMode", &f_Java_org_mozilla_gecko_gfx_NativePanZoomController_getOverScrollMode);
#endif

View File

@ -45,7 +45,7 @@ using namespace mozilla;
NS_IMPL_THREADSAFE_ISUPPORTS0(nsFilePickerCallback)
AndroidBridge *AndroidBridge::sBridge = 0;
nsRefPtr<AndroidBridge> AndroidBridge::sBridge = nullptr;
static unsigned sJavaEnvThreadIndex = 0;
static void JavaThreadDetachFunc(void *arg);
@ -2121,7 +2121,8 @@ AndroidBridge::SyncViewportInfo(const nsIntRect& aDisplayPort, float aDisplayRes
}
AndroidBridge::AndroidBridge()
: mLayerClient(NULL)
: mLayerClient(NULL),
mNativePanZoomController(NULL)
{
}
@ -2693,3 +2694,46 @@ AndroidBridge::UnlockProfile()
return ret;
}
jobject
AndroidBridge::SetNativePanZoomController(jobject obj)
{
jobject old = mNativePanZoomController;
mNativePanZoomController = obj;
return old;
}
void
AndroidBridge::RequestContentRepaint(const mozilla::layers::FrameMetrics& aFrameMetrics)
{
// FIXME implement this
}
void
AndroidBridge::HandleDoubleTap(const nsIntPoint& aPoint)
{
// FIXME implement this
}
void
AndroidBridge::HandleSingleTap(const nsIntPoint& aPoint)
{
// FIXME implement this
}
void
AndroidBridge::HandleLongTap(const nsIntPoint& aPoint)
{
// FIXME implement this
}
void
AndroidBridge::SendAsyncScrollDOMEvent(const gfx::Rect& aContentRect, const gfx::Size& aScrollableSize)
{
// FIXME implement this
}
void
AndroidBridge::PostDelayedTask(Task* task, int delay_ms)
{
// FIXME implement this
}

View File

@ -29,6 +29,7 @@
#include "mozilla/Likely.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/layers/GeckoContentController.h"
// Some debug #defines
// #define DEBUG_ANDROID_EVENTS
@ -92,7 +93,7 @@ protected:
virtual ~nsFilePickerCallback() {}
};
class AndroidBridge
class AndroidBridge : public mozilla::layers::GeckoContentController
{
public:
enum {
@ -109,7 +110,7 @@ public:
static void ConstructBridge(JNIEnv *jEnv, jclass jGeckoAppShellClass);
static AndroidBridge *Bridge() {
return sBridge;
return sBridge.get();
}
static JavaVM *GetVM() {
@ -384,7 +385,7 @@ public:
const int32_t aPort,
nsACString & aResult);
protected:
static AndroidBridge *sBridge;
static nsRefPtr<AndroidBridge> sBridge;
nsTArray<nsCOMPtr<nsIMobileMessageCallback> > mSmsRequests;
// the global JavaVM
@ -543,6 +544,18 @@ protected:
int (* Surface_unlockAndPost)(void* surface);
void (* Region_constructor)(void* region);
void (* Region_set)(void* region, void* rect);
private:
jobject mNativePanZoomController;
public:
jobject SetNativePanZoomController(jobject obj);
// GeckoContentController methods
void RequestContentRepaint(const mozilla::layers::FrameMetrics& aFrameMetrics) MOZ_OVERRIDE;
void HandleDoubleTap(const nsIntPoint& aPoint) MOZ_OVERRIDE;
void HandleSingleTap(const nsIntPoint& aPoint) MOZ_OVERRIDE;
void HandleLongTap(const nsIntPoint& aPoint) MOZ_OVERRIDE;
void SendAsyncScrollDOMEvent(const gfx::Rect& aContentRect, const gfx::Size& aScrollableSize) MOZ_OVERRIDE;
void PostDelayedTask(Task* task, int delay_ms) MOZ_OVERRIDE;
};
class AutoJObject {

View File

@ -35,6 +35,7 @@
#include "mozilla/dom/mobilemessage/Types.h"
#include "mozilla/dom/mobilemessage/PSms.h"
#include "mozilla/dom/mobilemessage/SmsParent.h"
#include "mozilla/layers/AsyncPanZoomController.h"
#include "nsIMobileMessageDatabaseService.h"
#include "nsPluginInstanceOwner.h"
#include "nsSurfaceTexture.h"
@ -43,6 +44,7 @@
using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::dom::mobilemessage;
using namespace mozilla::layers;
/* Forward declare all the JNI methods as extern "C" */
@ -883,4 +885,73 @@ Java_org_mozilla_gecko_GeckoJavaSampler_getProfilerTime(JNIEnv *jenv, jclass jc)
return profiler_time();
}
NS_EXPORT void JNICALL
Java_org_mozilla_gecko_gfx_NativePanZoomController_init(JNIEnv* env, jobject instance)
{
if (!AndroidBridge::Bridge()) {
return;
}
jobject oldRef = AndroidBridge::Bridge()->SetNativePanZoomController(env->NewGlobalRef(instance));
if (oldRef) {
MOZ_ASSERT(false, "Registering a new NPZC when we already have one");
env->DeleteGlobalRef(oldRef);
}
nsWindow::SetPanZoomController(new AsyncPanZoomController(AndroidBridge::Bridge(), AsyncPanZoomController::USE_GESTURE_DETECTOR));
}
NS_EXPORT void JNICALL
Java_org_mozilla_gecko_gfx_NativePanZoomController_handleTouchEvent(JNIEnv* env, jobject instance, jobject event)
{
// FIXME implement this
}
NS_EXPORT void JNICALL
Java_org_mozilla_gecko_gfx_NativePanZoomController_handleMotionEvent(JNIEnv* env, jobject instance, jobject event)
{
// FIXME implement this
}
NS_EXPORT void JNICALL
Java_org_mozilla_gecko_gfx_NativePanZoomController_destroy(JNIEnv* env, jobject instance)
{
if (!AndroidBridge::Bridge()) {
return;
}
nsWindow::SetPanZoomController(nullptr);
jobject oldRef = AndroidBridge::Bridge()->SetNativePanZoomController(NULL);
if (!oldRef) {
MOZ_ASSERT(false, "Clearing a non-existent NPZC");
} else {
env->DeleteGlobalRef(oldRef);
}
}
NS_EXPORT void JNICALL
Java_org_mozilla_gecko_gfx_NativePanZoomController_notifyDefaultActionPrevented(JNIEnv* env, jobject instance, jboolean prevented)
{
// FIXME implement this
}
NS_EXPORT jboolean JNICALL
Java_org_mozilla_gecko_gfx_NativePanZoomController_getRedrawHint(JNIEnv* env, jobject instance)
{
// FIXME implement this
return true;
}
NS_EXPORT void JNICALL
Java_org_mozilla_gecko_gfx_NativePanZoomController_setOverScrollMode(JNIEnv* env, jobject instance, jint overscrollMode)
{
// FIXME implement this
}
NS_EXPORT jint JNICALL
Java_org_mozilla_gecko_gfx_NativePanZoomController_getOverScrollMode(JNIEnv* env, jobject instance)
{
// FIXME implement this
return 0;
}
}