Bug 1238761 - Switch NativePanZoomController to use native methods; r=rbarker

This patch turns NativePanZoomController's MotionEvent handler into a
native method, and it adds the WrapForJNI annotations to all native
methods so that bindings will be automatically generated for them.
This commit is contained in:
Jim Chen 2016-01-15 13:05:44 -05:00
parent 798fd94c71
commit ebe41f27c9
7 changed files with 235 additions and 166 deletions

View File

@ -234,7 +234,6 @@ CLASSES_WITH_JNI= \
org.mozilla.gecko.GeckoAppShell \
org.mozilla.gecko.GeckoJavaSampler \
org.mozilla.gecko.GeckoSmsManager \
org.mozilla.gecko.gfx.NativePanZoomController \
$(NULL)
jni-stubs.inc: gecko-browser.jar constants.jar gecko-mozglue.jar gecko-util.jar sync-thirdparty.jar

View File

@ -5,11 +5,10 @@
package org.mozilla.gecko.gfx;
import org.mozilla.gecko.annotation.WrapForJNI;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.GeckoThread;
import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.util.GeckoEventListener;
import org.mozilla.gecko.annotation.WrapForJNI;
import org.mozilla.gecko.mozglue.JNIObject;
import org.json.JSONObject;
@ -18,32 +17,73 @@ import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
class NativePanZoomController implements PanZoomController, GeckoEventListener {
class NativePanZoomController extends JNIObject implements PanZoomController {
private final PanZoomTarget mTarget;
private final EventDispatcher mDispatcher;
private final LayerView mView;
private boolean mDestroyed;
NativePanZoomController(PanZoomTarget target, View view, EventDispatcher dispatcher) {
mTarget = target;
mDispatcher = dispatcher;
if (GeckoThread.isRunning()) {
init();
} else {
mDispatcher.registerGeckoThreadListener(this, "Gecko:Ready");
@WrapForJNI
private native boolean handleMotionEvent(
int action, int actionIndex, long time, int metaState,
int pointerId[], float x[], float y[], float orientation[], float pressure[],
float toolMajor[], float toolMinor[]);
private boolean handleMotionEvent(MotionEvent event, boolean keepInViewCoordinates) {
if (mDestroyed) {
return false;
}
final int action = event.getActionMasked();
final int count = event.getPointerCount();
final int[] pointerId = new int[count];
final float[] x = new float[count];
final float[] y = new float[count];
final float[] orientation = new float[count];
final float[] pressure = new float[count];
final float[] toolMajor = new float[count];
final float[] toolMinor = new float[count];
final MotionEvent.PointerCoords coords = new MotionEvent.PointerCoords();
final PointF point = !keepInViewCoordinates ? new PointF() : null;
final float zoom = !keepInViewCoordinates ? mView.getViewportMetrics().zoomFactor : 1.0f;
for (int i = 0; i < count; i++) {
pointerId[i] = event.getPointerId(i);
event.getPointerCoords(i, coords);
if (keepInViewCoordinates) {
x[i] = coords.x;
y[i] = coords.y;
} else {
point.x = coords.x;
point.y = coords.y;
final PointF newPoint = mView.convertViewPointToLayerPoint(point);
x[i] = newPoint.x;
y[i] = newPoint.y;
}
orientation[i] = coords.orientation;
pressure[i] = coords.pressure;
// If we are converting to CSS pixels, we should adjust the radii as well.
toolMajor[i] = coords.toolMajor / zoom;
toolMinor[i] = coords.toolMinor / zoom;
}
return handleMotionEvent(action, event.getActionIndex(), event.getEventTime(),
event.getMetaState(), pointerId, x, y, orientation, pressure,
toolMajor, toolMinor);
}
@Override
public void handleMessage(String event, JSONObject message) {
if ("Gecko:Ready".equals(event)) {
mDispatcher.unregisterGeckoThreadListener(this, "Gecko:Ready");
init();
}
NativePanZoomController(PanZoomTarget target, View view) {
mTarget = target;
mView = (LayerView) view;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
GeckoEvent wrapped = GeckoEvent.createMotionEvent(event, true);
return handleTouchEvent(wrapped);
return handleMotionEvent(event, /* keepInViewCoordinates */ true);
}
@Override
@ -81,17 +121,35 @@ class NativePanZoomController implements PanZoomController, GeckoEventListener {
// we just want to ignore this callback.
}
@Override
public native void abortAnimation();
@WrapForJNI(stubName = "AbortAnimation")
private native void nativeAbortAnimation();
private native void init();
private native boolean handleTouchEvent(GeckoEvent event);
private native void handleMotionEvent(GeckoEvent event);
@Override // PanZoomController
public void abortAnimation()
{
if (!mDestroyed) {
nativeAbortAnimation();
}
}
@Override
public native void destroy();
@Override
public native boolean getRedrawHint();
@Override // PanZoomController
public boolean getRedrawHint()
{
// FIXME implement this
return true;
}
@Override @WrapForJNI(allowMultithread = true) // PanZoomController
public void destroy() {
if (mDestroyed) {
return;
}
mDestroyed = true;
disposeNative();
}
@Override @WrapForJNI // JNIObject
protected native void disposeNative();
@Override
public void setOverScrollMode(int overscrollMode) {
@ -113,6 +171,13 @@ class NativePanZoomController implements PanZoomController, GeckoEventListener {
public void setOverscrollHandler(final Overscroll listener) {
}
@Override
public native void setIsLongpressEnabled(boolean isLongpressEnabled);
@WrapForJNI(stubName = "SetIsLongpressEnabled")
private native void nativeSetIsLongpressEnabled(boolean isLongpressEnabled);
@Override // PanZoomController
public void setIsLongpressEnabled(boolean isLongpressEnabled) {
if (!mDestroyed) {
nativeSetIsLongpressEnabled(isLongpressEnabled);
}
}
}

View File

@ -24,7 +24,7 @@ public interface PanZoomController {
static class Factory {
static PanZoomController create(PanZoomTarget target, View view, EventDispatcher dispatcher) {
if (org.mozilla.gecko.AppConstants.MOZ_ANDROID_APZ) {
return new NativePanZoomController(target, view, dispatcher);
return new NativePanZoomController(target, view);
} else {
return new JavaPanZoomController(target, view, dispatcher);
}

View File

@ -569,136 +569,3 @@ Java_org_mozilla_gecko_GeckoSmsManager_notifyCursorDone(JNIEnv * arg0, jclass ar
xul_dlsym("Java_org_mozilla_gecko_GeckoSmsManager_notifyCursorDone", &f_Java_org_mozilla_gecko_GeckoSmsManager_notifyCursorDone);
#endif
#ifdef JNI_STUBS
typedef void (*Java_org_mozilla_gecko_gfx_NativePanZoomController_abortAnimation_t)(JNIEnv *, jobject);
static Java_org_mozilla_gecko_gfx_NativePanZoomController_abortAnimation_t f_Java_org_mozilla_gecko_gfx_NativePanZoomController_abortAnimation;
extern "C" NS_EXPORT void MOZ_JNICALL
Java_org_mozilla_gecko_gfx_NativePanZoomController_abortAnimation(JNIEnv * arg0, jobject arg1) {
if (!f_Java_org_mozilla_gecko_gfx_NativePanZoomController_abortAnimation) {
arg0->ThrowNew(arg0->FindClass("java/lang/UnsupportedOperationException"),
"JNI Function called before it was loaded");
return ;
}
f_Java_org_mozilla_gecko_gfx_NativePanZoomController_abortAnimation(arg0, arg1);
}
#endif
#ifdef JNI_BINDINGS
xul_dlsym("Java_org_mozilla_gecko_gfx_NativePanZoomController_abortAnimation", &f_Java_org_mozilla_gecko_gfx_NativePanZoomController_abortAnimation);
#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 MOZ_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 jboolean (*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 jboolean MOZ_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 false;
}
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 MOZ_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 MOZ_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 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 MOZ_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_setIsLongpressEnabled_t)(JNIEnv *, jobject, jboolean);
static Java_org_mozilla_gecko_gfx_NativePanZoomController_setIsLongpressEnabled_t f_Java_org_mozilla_gecko_gfx_NativePanZoomController_setIsLongpressEnabled;
extern "C" NS_EXPORT void MOZ_JNICALL
Java_org_mozilla_gecko_gfx_NativePanZoomController_setIsLongpressEnabled(JNIEnv * arg0, jobject arg1, jboolean arg2) {
if (!f_Java_org_mozilla_gecko_gfx_NativePanZoomController_setIsLongpressEnabled) {
arg0->ThrowNew(arg0->FindClass("java/lang/UnsupportedOperationException"),
"JNI Function called before it was loaded");
return ;
}
f_Java_org_mozilla_gecko_gfx_NativePanZoomController_setIsLongpressEnabled(arg0, arg1, arg2);
}
#endif
#ifdef JNI_BINDINGS
xul_dlsym("Java_org_mozilla_gecko_gfx_NativePanZoomController_setIsLongpressEnabled", &f_Java_org_mozilla_gecko_gfx_NativePanZoomController_setIsLongpressEnabled);
#endif

View File

@ -268,6 +268,33 @@ public:
template<class Impl>
constexpr JNINativeMethod GLController::Natives<Impl>::methods[];
template<class Impl>
class NativePanZoomController::Natives : public mozilla::jni::NativeImpl<NativePanZoomController, Impl>
{
public:
static constexpr JNINativeMethod methods[] = {
mozilla::jni::MakeNativeMethod<NativePanZoomController::DisposeNative_t>(
mozilla::jni::NativeStub<NativePanZoomController::DisposeNative_t, Impl>
::template Wrap<&Impl::DisposeNative>),
mozilla::jni::MakeNativeMethod<NativePanZoomController::HandleMotionEvent_t>(
mozilla::jni::NativeStub<NativePanZoomController::HandleMotionEvent_t, Impl>
::template Wrap<&Impl::HandleMotionEvent>),
mozilla::jni::MakeNativeMethod<NativePanZoomController::AbortAnimation_t>(
mozilla::jni::NativeStub<NativePanZoomController::AbortAnimation_t, Impl>
::template Wrap<&Impl::AbortAnimation>),
mozilla::jni::MakeNativeMethod<NativePanZoomController::SetIsLongpressEnabled_t>(
mozilla::jni::NativeStub<NativePanZoomController::SetIsLongpressEnabled_t, Impl>
::template Wrap<&Impl::SetIsLongpressEnabled>)
};
};
template<class Impl>
constexpr JNINativeMethod NativePanZoomController::Natives<Impl>::methods[];
template<class Impl>
class NativeJSContainer::Natives : public mozilla::jni::NativeImpl<NativeJSContainer, Impl>
{

View File

@ -1432,6 +1432,26 @@ auto LayerView::updateZoomedView(mozilla::jni::Object::Param a0) -> void
constexpr char NativePanZoomController::name[];
constexpr char NativePanZoomController::Destroy_t::name[];
constexpr char NativePanZoomController::Destroy_t::signature[];
auto NativePanZoomController::Destroy() const -> void
{
return mozilla::jni::Method<Destroy_t>::Call(this, nullptr);
}
constexpr char NativePanZoomController::DisposeNative_t::name[];
constexpr char NativePanZoomController::DisposeNative_t::signature[];
constexpr char NativePanZoomController::HandleMotionEvent_t::name[];
constexpr char NativePanZoomController::HandleMotionEvent_t::signature[];
constexpr char NativePanZoomController::AbortAnimation_t::name[];
constexpr char NativePanZoomController::AbortAnimation_t::signature[];
constexpr char NativePanZoomController::SetIsLongpressEnabled_t::name[];
constexpr char NativePanZoomController::SetIsLongpressEnabled_t::signature[];
constexpr char NativePanZoomController::RequestContentRepaintWrapper_t::name[];
constexpr char NativePanZoomController::RequestContentRepaintWrapper_t::signature[];

View File

@ -3947,6 +3947,95 @@ public:
protected:
NativePanZoomController(jobject instance) : Class(instance) {}
public:
struct Destroy_t {
typedef NativePanZoomController Owner;
typedef void ReturnType;
typedef void SetterType;
typedef mozilla::jni::Args<> Args;
static constexpr char name[] = "destroy";
static constexpr char signature[] =
"()V";
static const bool isStatic = false;
static const bool isMultithreaded = true;
static const mozilla::jni::ExceptionMode exceptionMode =
mozilla::jni::ExceptionMode::ABORT;
};
auto Destroy() const -> void;
public:
struct DisposeNative_t {
typedef NativePanZoomController Owner;
typedef void ReturnType;
typedef void SetterType;
typedef mozilla::jni::Args<> Args;
static constexpr char name[] = "disposeNative";
static constexpr char signature[] =
"()V";
static const bool isStatic = false;
static const bool isMultithreaded = false;
static const mozilla::jni::ExceptionMode exceptionMode =
mozilla::jni::ExceptionMode::ABORT;
};
public:
struct HandleMotionEvent_t {
typedef NativePanZoomController Owner;
typedef bool ReturnType;
typedef bool SetterType;
typedef mozilla::jni::Args<
int32_t,
int32_t,
int64_t,
int32_t,
mozilla::jni::IntArray::Param,
mozilla::jni::FloatArray::Param,
mozilla::jni::FloatArray::Param,
mozilla::jni::FloatArray::Param,
mozilla::jni::FloatArray::Param,
mozilla::jni::FloatArray::Param,
mozilla::jni::FloatArray::Param> Args;
static constexpr char name[] = "handleMotionEvent";
static constexpr char signature[] =
"(IIJI[I[F[F[F[F[F[F)Z";
static const bool isStatic = false;
static const bool isMultithreaded = false;
static const mozilla::jni::ExceptionMode exceptionMode =
mozilla::jni::ExceptionMode::ABORT;
};
public:
struct AbortAnimation_t {
typedef NativePanZoomController Owner;
typedef void ReturnType;
typedef void SetterType;
typedef mozilla::jni::Args<> Args;
static constexpr char name[] = "nativeAbortAnimation";
static constexpr char signature[] =
"()V";
static const bool isStatic = false;
static const bool isMultithreaded = false;
static const mozilla::jni::ExceptionMode exceptionMode =
mozilla::jni::ExceptionMode::ABORT;
};
public:
struct SetIsLongpressEnabled_t {
typedef NativePanZoomController Owner;
typedef void ReturnType;
typedef void SetterType;
typedef mozilla::jni::Args<
bool> Args;
static constexpr char name[] = "nativeSetIsLongpressEnabled";
static constexpr char signature[] =
"(Z)V";
static const bool isStatic = false;
static const bool isMultithreaded = false;
static const mozilla::jni::ExceptionMode exceptionMode =
mozilla::jni::ExceptionMode::ABORT;
};
public:
struct RequestContentRepaintWrapper_t {
typedef NativePanZoomController Owner;
@ -3969,6 +4058,8 @@ public:
auto RequestContentRepaintWrapper(float, float, float, float, float) const -> void;
public:
template<class Impl> class Natives;
};
class ProgressiveUpdateData : public mozilla::jni::Class<ProgressiveUpdateData>