mobile/android/base/gfx/NativePanZoomController.java

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial