1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/gfx/NativePanZoomController.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,108 @@ 1.4 +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +package org.mozilla.gecko.gfx; 1.10 + 1.11 +import org.mozilla.gecko.GeckoEvent; 1.12 +import org.mozilla.gecko.GeckoThread; 1.13 +import org.mozilla.gecko.mozglue.generatorannotations.WrapElementForJNI; 1.14 +import org.mozilla.gecko.EventDispatcher; 1.15 +import org.mozilla.gecko.util.GeckoEventListener; 1.16 + 1.17 +import org.json.JSONObject; 1.18 + 1.19 +import android.graphics.PointF; 1.20 +import android.view.KeyEvent; 1.21 +import android.view.MotionEvent; 1.22 +import android.view.View; 1.23 + 1.24 +class NativePanZoomController implements PanZoomController, GeckoEventListener { 1.25 + private final PanZoomTarget mTarget; 1.26 + private final EventDispatcher mDispatcher; 1.27 + private final CallbackRunnable mCallbackRunnable; 1.28 + 1.29 + NativePanZoomController(PanZoomTarget target, View view, EventDispatcher dispatcher) { 1.30 + mTarget = target; 1.31 + mDispatcher = dispatcher; 1.32 + mCallbackRunnable = new CallbackRunnable(); 1.33 + if (GeckoThread.checkLaunchState(GeckoThread.LaunchState.GeckoRunning)) { 1.34 + init(); 1.35 + } else { 1.36 + mDispatcher.registerEventListener("Gecko:Ready", this); 1.37 + } 1.38 + } 1.39 + 1.40 + public void handleMessage(String event, JSONObject message) { 1.41 + if ("Gecko:Ready".equals(event)) { 1.42 + mDispatcher.unregisterEventListener("Gecko:Ready", this); 1.43 + init(); 1.44 + } 1.45 + } 1.46 + 1.47 + public boolean onTouchEvent(MotionEvent event) { 1.48 + GeckoEvent wrapped = GeckoEvent.createMotionEvent(event, true); 1.49 + handleTouchEvent(wrapped); 1.50 + return false; 1.51 + } 1.52 + 1.53 + public boolean onMotionEvent(MotionEvent event) { 1.54 + // FIXME implement this 1.55 + return false; 1.56 + } 1.57 + 1.58 + public boolean onKeyEvent(KeyEvent event) { 1.59 + // FIXME implement this 1.60 + return false; 1.61 + } 1.62 + 1.63 + public PointF getVelocityVector() { 1.64 + // FIXME implement this 1.65 + return new PointF(0, 0); 1.66 + } 1.67 + 1.68 + public void pageRectUpdated() { 1.69 + // no-op in APZC, I think 1.70 + } 1.71 + 1.72 + public void abortPanning() { 1.73 + // no-op in APZC, I think 1.74 + } 1.75 + 1.76 + public native void abortAnimation(); 1.77 + 1.78 + private native void init(); 1.79 + private native void handleTouchEvent(GeckoEvent event); 1.80 + private native void handleMotionEvent(GeckoEvent event); 1.81 + private native long runDelayedCallback(); 1.82 + 1.83 + public native void destroy(); 1.84 + public native void notifyDefaultActionPrevented(boolean prevented); 1.85 + public native boolean getRedrawHint(); 1.86 + public native void setOverScrollMode(int overscrollMode); 1.87 + public native int getOverScrollMode(); 1.88 + 1.89 + @WrapElementForJNI(allowMultithread = true, stubName = "RequestContentRepaintWrapper") 1.90 + private void requestContentRepaint(float x, float y, float width, float height, float resolution) { 1.91 + mTarget.forceRedraw(new DisplayPortMetrics(x, y, x + width, y + height, resolution)); 1.92 + } 1.93 + 1.94 + @WrapElementForJNI(allowMultithread = true, stubName = "PostDelayedCallbackWrapper") 1.95 + private void postDelayedCallback(long delay) { 1.96 + mTarget.postDelayed(mCallbackRunnable, delay); 1.97 + } 1.98 + 1.99 + class CallbackRunnable implements Runnable { 1.100 + @Override 1.101 + public void run() { 1.102 + long nextDelay = runDelayedCallback(); 1.103 + if (nextDelay >= 0) { 1.104 + mTarget.postDelayed(this, nextDelay); 1.105 + } 1.106 + } 1.107 + } 1.108 + 1.109 + public void setOverscrollHandler(final Overscroll listener) { 1.110 + } 1.111 +}