mobile/android/base/gfx/NativePanZoomController.java

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
michael@0 2 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 package org.mozilla.gecko.gfx;
michael@0 7
michael@0 8 import org.mozilla.gecko.GeckoEvent;
michael@0 9 import org.mozilla.gecko.GeckoThread;
michael@0 10 import org.mozilla.gecko.mozglue.generatorannotations.WrapElementForJNI;
michael@0 11 import org.mozilla.gecko.EventDispatcher;
michael@0 12 import org.mozilla.gecko.util.GeckoEventListener;
michael@0 13
michael@0 14 import org.json.JSONObject;
michael@0 15
michael@0 16 import android.graphics.PointF;
michael@0 17 import android.view.KeyEvent;
michael@0 18 import android.view.MotionEvent;
michael@0 19 import android.view.View;
michael@0 20
michael@0 21 class NativePanZoomController implements PanZoomController, GeckoEventListener {
michael@0 22 private final PanZoomTarget mTarget;
michael@0 23 private final EventDispatcher mDispatcher;
michael@0 24 private final CallbackRunnable mCallbackRunnable;
michael@0 25
michael@0 26 NativePanZoomController(PanZoomTarget target, View view, EventDispatcher dispatcher) {
michael@0 27 mTarget = target;
michael@0 28 mDispatcher = dispatcher;
michael@0 29 mCallbackRunnable = new CallbackRunnable();
michael@0 30 if (GeckoThread.checkLaunchState(GeckoThread.LaunchState.GeckoRunning)) {
michael@0 31 init();
michael@0 32 } else {
michael@0 33 mDispatcher.registerEventListener("Gecko:Ready", this);
michael@0 34 }
michael@0 35 }
michael@0 36
michael@0 37 public void handleMessage(String event, JSONObject message) {
michael@0 38 if ("Gecko:Ready".equals(event)) {
michael@0 39 mDispatcher.unregisterEventListener("Gecko:Ready", this);
michael@0 40 init();
michael@0 41 }
michael@0 42 }
michael@0 43
michael@0 44 public boolean onTouchEvent(MotionEvent event) {
michael@0 45 GeckoEvent wrapped = GeckoEvent.createMotionEvent(event, true);
michael@0 46 handleTouchEvent(wrapped);
michael@0 47 return false;
michael@0 48 }
michael@0 49
michael@0 50 public boolean onMotionEvent(MotionEvent event) {
michael@0 51 // FIXME implement this
michael@0 52 return false;
michael@0 53 }
michael@0 54
michael@0 55 public boolean onKeyEvent(KeyEvent event) {
michael@0 56 // FIXME implement this
michael@0 57 return false;
michael@0 58 }
michael@0 59
michael@0 60 public PointF getVelocityVector() {
michael@0 61 // FIXME implement this
michael@0 62 return new PointF(0, 0);
michael@0 63 }
michael@0 64
michael@0 65 public void pageRectUpdated() {
michael@0 66 // no-op in APZC, I think
michael@0 67 }
michael@0 68
michael@0 69 public void abortPanning() {
michael@0 70 // no-op in APZC, I think
michael@0 71 }
michael@0 72
michael@0 73 public native void abortAnimation();
michael@0 74
michael@0 75 private native void init();
michael@0 76 private native void handleTouchEvent(GeckoEvent event);
michael@0 77 private native void handleMotionEvent(GeckoEvent event);
michael@0 78 private native long runDelayedCallback();
michael@0 79
michael@0 80 public native void destroy();
michael@0 81 public native void notifyDefaultActionPrevented(boolean prevented);
michael@0 82 public native boolean getRedrawHint();
michael@0 83 public native void setOverScrollMode(int overscrollMode);
michael@0 84 public native int getOverScrollMode();
michael@0 85
michael@0 86 @WrapElementForJNI(allowMultithread = true, stubName = "RequestContentRepaintWrapper")
michael@0 87 private void requestContentRepaint(float x, float y, float width, float height, float resolution) {
michael@0 88 mTarget.forceRedraw(new DisplayPortMetrics(x, y, x + width, y + height, resolution));
michael@0 89 }
michael@0 90
michael@0 91 @WrapElementForJNI(allowMultithread = true, stubName = "PostDelayedCallbackWrapper")
michael@0 92 private void postDelayedCallback(long delay) {
michael@0 93 mTarget.postDelayed(mCallbackRunnable, delay);
michael@0 94 }
michael@0 95
michael@0 96 class CallbackRunnable implements Runnable {
michael@0 97 @Override
michael@0 98 public void run() {
michael@0 99 long nextDelay = runDelayedCallback();
michael@0 100 if (nextDelay >= 0) {
michael@0 101 mTarget.postDelayed(this, nextDelay);
michael@0 102 }
michael@0 103 }
michael@0 104 }
michael@0 105
michael@0 106 public void setOverscrollHandler(final Overscroll listener) {
michael@0 107 }
michael@0 108 }

mercurial