michael@0: /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.gfx; michael@0: michael@0: import org.mozilla.gecko.GeckoEvent; michael@0: import org.mozilla.gecko.GeckoThread; michael@0: import org.mozilla.gecko.mozglue.generatorannotations.WrapElementForJNI; michael@0: import org.mozilla.gecko.EventDispatcher; michael@0: import org.mozilla.gecko.util.GeckoEventListener; michael@0: michael@0: import org.json.JSONObject; michael@0: michael@0: import android.graphics.PointF; michael@0: import android.view.KeyEvent; michael@0: import android.view.MotionEvent; michael@0: import android.view.View; michael@0: michael@0: class NativePanZoomController implements PanZoomController, GeckoEventListener { michael@0: private final PanZoomTarget mTarget; michael@0: private final EventDispatcher mDispatcher; michael@0: private final CallbackRunnable mCallbackRunnable; michael@0: michael@0: NativePanZoomController(PanZoomTarget target, View view, EventDispatcher dispatcher) { michael@0: mTarget = target; michael@0: mDispatcher = dispatcher; michael@0: mCallbackRunnable = new CallbackRunnable(); michael@0: if (GeckoThread.checkLaunchState(GeckoThread.LaunchState.GeckoRunning)) { michael@0: init(); michael@0: } else { michael@0: mDispatcher.registerEventListener("Gecko:Ready", this); michael@0: } michael@0: } michael@0: michael@0: public void handleMessage(String event, JSONObject message) { michael@0: if ("Gecko:Ready".equals(event)) { michael@0: mDispatcher.unregisterEventListener("Gecko:Ready", this); michael@0: init(); michael@0: } michael@0: } michael@0: michael@0: public boolean onTouchEvent(MotionEvent event) { michael@0: GeckoEvent wrapped = GeckoEvent.createMotionEvent(event, true); michael@0: handleTouchEvent(wrapped); michael@0: return false; michael@0: } michael@0: michael@0: public boolean onMotionEvent(MotionEvent event) { michael@0: // FIXME implement this michael@0: return false; michael@0: } michael@0: michael@0: public boolean onKeyEvent(KeyEvent event) { michael@0: // FIXME implement this michael@0: return false; michael@0: } michael@0: michael@0: public PointF getVelocityVector() { michael@0: // FIXME implement this michael@0: return new PointF(0, 0); michael@0: } michael@0: michael@0: public void pageRectUpdated() { michael@0: // no-op in APZC, I think michael@0: } michael@0: michael@0: public void abortPanning() { michael@0: // no-op in APZC, I think michael@0: } michael@0: michael@0: public native void abortAnimation(); michael@0: michael@0: private native void init(); michael@0: private native void handleTouchEvent(GeckoEvent event); michael@0: private native void handleMotionEvent(GeckoEvent event); michael@0: private native long runDelayedCallback(); michael@0: michael@0: public native void destroy(); michael@0: public native void notifyDefaultActionPrevented(boolean prevented); michael@0: public native boolean getRedrawHint(); michael@0: public native void setOverScrollMode(int overscrollMode); michael@0: public native int getOverScrollMode(); michael@0: michael@0: @WrapElementForJNI(allowMultithread = true, stubName = "RequestContentRepaintWrapper") michael@0: private void requestContentRepaint(float x, float y, float width, float height, float resolution) { michael@0: mTarget.forceRedraw(new DisplayPortMetrics(x, y, x + width, y + height, resolution)); michael@0: } michael@0: michael@0: @WrapElementForJNI(allowMultithread = true, stubName = "PostDelayedCallbackWrapper") michael@0: private void postDelayedCallback(long delay) { michael@0: mTarget.postDelayed(mCallbackRunnable, delay); michael@0: } michael@0: michael@0: class CallbackRunnable implements Runnable { michael@0: @Override michael@0: public void run() { michael@0: long nextDelay = runDelayedCallback(); michael@0: if (nextDelay >= 0) { michael@0: mTarget.postDelayed(this, nextDelay); michael@0: } michael@0: } michael@0: } michael@0: michael@0: public void setOverscrollHandler(final Overscroll listener) { michael@0: } michael@0: }