|
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/. */ |
|
5 |
|
6 package org.mozilla.gecko.gfx; |
|
7 |
|
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; |
|
13 |
|
14 import org.json.JSONObject; |
|
15 |
|
16 import android.graphics.PointF; |
|
17 import android.view.KeyEvent; |
|
18 import android.view.MotionEvent; |
|
19 import android.view.View; |
|
20 |
|
21 class NativePanZoomController implements PanZoomController, GeckoEventListener { |
|
22 private final PanZoomTarget mTarget; |
|
23 private final EventDispatcher mDispatcher; |
|
24 private final CallbackRunnable mCallbackRunnable; |
|
25 |
|
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 } |
|
36 |
|
37 public void handleMessage(String event, JSONObject message) { |
|
38 if ("Gecko:Ready".equals(event)) { |
|
39 mDispatcher.unregisterEventListener("Gecko:Ready", this); |
|
40 init(); |
|
41 } |
|
42 } |
|
43 |
|
44 public boolean onTouchEvent(MotionEvent event) { |
|
45 GeckoEvent wrapped = GeckoEvent.createMotionEvent(event, true); |
|
46 handleTouchEvent(wrapped); |
|
47 return false; |
|
48 } |
|
49 |
|
50 public boolean onMotionEvent(MotionEvent event) { |
|
51 // FIXME implement this |
|
52 return false; |
|
53 } |
|
54 |
|
55 public boolean onKeyEvent(KeyEvent event) { |
|
56 // FIXME implement this |
|
57 return false; |
|
58 } |
|
59 |
|
60 public PointF getVelocityVector() { |
|
61 // FIXME implement this |
|
62 return new PointF(0, 0); |
|
63 } |
|
64 |
|
65 public void pageRectUpdated() { |
|
66 // no-op in APZC, I think |
|
67 } |
|
68 |
|
69 public void abortPanning() { |
|
70 // no-op in APZC, I think |
|
71 } |
|
72 |
|
73 public native void abortAnimation(); |
|
74 |
|
75 private native void init(); |
|
76 private native void handleTouchEvent(GeckoEvent event); |
|
77 private native void handleMotionEvent(GeckoEvent event); |
|
78 private native long runDelayedCallback(); |
|
79 |
|
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(); |
|
85 |
|
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 } |
|
90 |
|
91 @WrapElementForJNI(allowMultithread = true, stubName = "PostDelayedCallbackWrapper") |
|
92 private void postDelayedCallback(long delay) { |
|
93 mTarget.postDelayed(mCallbackRunnable, delay); |
|
94 } |
|
95 |
|
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 } |
|
105 |
|
106 public void setOverscrollHandler(final Overscroll listener) { |
|
107 } |
|
108 } |