mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 777468 - Move ownership of TouchEventHandler from LayerView to JavaPanZoomController. r=Cwiiis
This patch has a bunch of semi-independent changes that unfortunately couldn't be split apart without introducing hacks to make stuff build on the intermediate patches. The main changes are: - Moving TouchEventHandler from LayerView to JavaPanZoomController - Registering the touch interceptor on the LayerView rather than the TouchEventHandler - Moving the Tab:HasTouchListener handler from GeckoApp to JPZC The net effect of all of this is that the TouchEventHandler is hidden behind the PanZoomController interface and not accessible to GeckoApp or GeckoAppShell. Additionally, some of the JPZC methods were renamed from onXXX to handleXXX to maintain the convention that onXXX methods are "interface" methods (i.e. exposed to arbitrary other code) whereas handleXXX methods are private/package and should only be called in very specific ways.
This commit is contained in:
parent
5eeb9c6f6a
commit
340661f4dc
@ -863,16 +863,6 @@ abstract public class GeckoApp
|
||||
if (layerView != null && Tabs.getInstance().isSelectedTab(tab)) {
|
||||
layerView.setZoomConstraints(tab.getZoomConstraints());
|
||||
}
|
||||
} else if (event.equals("Tab:HasTouchListener")) {
|
||||
int tabId = message.getInt("tabID");
|
||||
final Tab tab = Tabs.getInstance().getTab(tabId);
|
||||
tab.setHasTouchListeners(true);
|
||||
mMainHandler.post(new Runnable() {
|
||||
public void run() {
|
||||
if (Tabs.getInstance().isSelectedTab(tab))
|
||||
mLayerView.getTouchEventHandler().setWaitForTouchListeners(true);
|
||||
}
|
||||
});
|
||||
} else if (event.equals("Session:StatePurged")) {
|
||||
onStatePurged();
|
||||
} else if (event.equals("Bookmark:Insert")) {
|
||||
@ -1779,7 +1769,6 @@ abstract public class GeckoApp
|
||||
registerEventListener("ToggleChrome:Show");
|
||||
registerEventListener("ToggleChrome:Focus");
|
||||
registerEventListener("Permissions:Data");
|
||||
registerEventListener("Tab:HasTouchListener");
|
||||
registerEventListener("Tab:ViewportMetadata");
|
||||
registerEventListener("Session:StatePurged");
|
||||
registerEventListener("Bookmark:Insert");
|
||||
@ -2179,7 +2168,6 @@ abstract public class GeckoApp
|
||||
unregisterEventListener("ToggleChrome:Show");
|
||||
unregisterEventListener("ToggleChrome:Focus");
|
||||
unregisterEventListener("Permissions:Data");
|
||||
unregisterEventListener("Tab:HasTouchListener");
|
||||
unregisterEventListener("Tab:ViewportMetadata");
|
||||
unregisterEventListener("Session:StatePurged");
|
||||
unregisterEventListener("Bookmark:Insert");
|
||||
@ -2559,7 +2547,7 @@ abstract public class GeckoApp
|
||||
protected void connectGeckoLayerClient() {
|
||||
mLayerView.getLayerClient().notifyGeckoReady();
|
||||
|
||||
mLayerView.getTouchEventHandler().setOnTouchListener(new OnInterceptTouchListener() {
|
||||
mLayerView.setTouchIntercepter(new OnInterceptTouchListener() {
|
||||
private PointF initialPoint = null;
|
||||
|
||||
@Override
|
||||
|
@ -9,7 +9,7 @@ import org.mozilla.gecko.gfx.BitmapUtils;
|
||||
import org.mozilla.gecko.gfx.GeckoLayerClient;
|
||||
import org.mozilla.gecko.gfx.GfxInfoThread;
|
||||
import org.mozilla.gecko.gfx.LayerView;
|
||||
import org.mozilla.gecko.gfx.TouchEventHandler;
|
||||
import org.mozilla.gecko.gfx.PanZoomController;
|
||||
import org.mozilla.gecko.mozglue.GeckoLoader;
|
||||
import org.mozilla.gecko.util.EventDispatcher;
|
||||
import org.mozilla.gecko.util.GeckoBackgroundThread;
|
||||
@ -1370,9 +1370,9 @@ public class GeckoAppShell
|
||||
getMainHandler().post(new Runnable() {
|
||||
public void run() {
|
||||
LayerView view = GeckoApp.mAppContext.getLayerView();
|
||||
TouchEventHandler handler = (view == null ? null : view.getTouchEventHandler());
|
||||
if (handler != null) {
|
||||
handler.handleEventListenerAction(!defaultPrevented);
|
||||
PanZoomController controller = (view == null ? null : view.getPanZoomController());
|
||||
if (controller != null) {
|
||||
controller.notifyDefaultActionPrevented(defaultPrevented);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -114,7 +114,7 @@ public class GeckoLayerClient implements LayerView.Listener, PanZoomTarget
|
||||
mViewportMetrics = new ImmutableViewportMetrics(displayMetrics);
|
||||
mZoomConstraints = new ZoomConstraints(false);
|
||||
|
||||
mPanZoomController = PanZoomController.Factory.create(this, eventDispatcher);
|
||||
mPanZoomController = PanZoomController.Factory.create(this, view, eventDispatcher);
|
||||
mView = view;
|
||||
mView.setListener(this);
|
||||
}
|
||||
|
@ -8,6 +8,8 @@ package org.mozilla.gecko.gfx;
|
||||
import org.mozilla.gecko.GeckoApp;
|
||||
import org.mozilla.gecko.GeckoAppShell;
|
||||
import org.mozilla.gecko.GeckoEvent;
|
||||
import org.mozilla.gecko.Tab;
|
||||
import org.mozilla.gecko.Tabs;
|
||||
import org.mozilla.gecko.ZoomConstraints;
|
||||
import org.mozilla.gecko.util.EventDispatcher;
|
||||
import org.mozilla.gecko.util.FloatUtils;
|
||||
@ -17,10 +19,13 @@ import org.json.JSONObject;
|
||||
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.RectF;
|
||||
import android.os.Build;
|
||||
import android.util.FloatMath;
|
||||
import android.util.Log;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.InputDevice;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
@ -31,7 +36,7 @@ import java.util.TimerTask;
|
||||
* Many ideas are from Joe Hewitt's Scrollability:
|
||||
* https://github.com/joehewitt/scrollability/
|
||||
*/
|
||||
public class JavaPanZoomController
|
||||
class JavaPanZoomController
|
||||
extends GestureDetector.SimpleOnGestureListener
|
||||
implements PanZoomController, SimpleScaleGestureDetector.SimpleScaleGestureListener, GeckoEventListener
|
||||
{
|
||||
@ -39,6 +44,7 @@ public class JavaPanZoomController
|
||||
|
||||
private static String MESSAGE_ZOOM_RECT = "Browser:ZoomToRect";
|
||||
private static String MESSAGE_ZOOM_PAGE = "Browser:ZoomToPageWidth";
|
||||
private static String MESSAGE_TOUCH_LISTENER = "Tab:HasTouchListener";
|
||||
|
||||
// Animation stops if the velocity is below this value when overscrolled or panning.
|
||||
private static final float STOPPED_THRESHOLD = 4.0f;
|
||||
@ -81,6 +87,7 @@ public class JavaPanZoomController
|
||||
private final SubdocumentScrollHelper mSubscroller;
|
||||
private final Axis mX;
|
||||
private final Axis mY;
|
||||
private final TouchEventHandler mTouchEventHandler;
|
||||
private final EventDispatcher mEventDispatcher;
|
||||
private Thread mMainThread;
|
||||
|
||||
@ -95,11 +102,12 @@ public class JavaPanZoomController
|
||||
/* Current state the pan/zoom UI is in. */
|
||||
private PanZoomState mState;
|
||||
|
||||
public JavaPanZoomController(PanZoomTarget target, EventDispatcher eventDispatcher) {
|
||||
public JavaPanZoomController(PanZoomTarget target, View view, EventDispatcher eventDispatcher) {
|
||||
mTarget = target;
|
||||
mSubscroller = new SubdocumentScrollHelper(eventDispatcher);
|
||||
mX = new AxisX(mSubscroller);
|
||||
mY = new AxisY(mSubscroller);
|
||||
mTouchEventHandler = new TouchEventHandler(view.getContext(), view, this);
|
||||
|
||||
mMainThread = GeckoApp.mAppContext.getMainLooper().getThread();
|
||||
checkMainThread();
|
||||
@ -109,6 +117,7 @@ public class JavaPanZoomController
|
||||
mEventDispatcher = eventDispatcher;
|
||||
registerEventListener(MESSAGE_ZOOM_RECT);
|
||||
registerEventListener(MESSAGE_ZOOM_PAGE);
|
||||
registerEventListener(MESSAGE_TOUCH_LISTENER);
|
||||
|
||||
Axis.initPrefs();
|
||||
}
|
||||
@ -116,7 +125,9 @@ public class JavaPanZoomController
|
||||
public void destroy() {
|
||||
unregisterEventListener(MESSAGE_ZOOM_RECT);
|
||||
unregisterEventListener(MESSAGE_ZOOM_PAGE);
|
||||
unregisterEventListener(MESSAGE_TOUCH_LISTENER);
|
||||
mSubscroller.destroy();
|
||||
mTouchEventHandler.destroy();
|
||||
}
|
||||
|
||||
private final static float easeOut(float t) {
|
||||
@ -184,21 +195,56 @@ public class JavaPanZoomController
|
||||
animatedZoomTo(r);
|
||||
}
|
||||
});
|
||||
} else if (MESSAGE_TOUCH_LISTENER.equals(event)) {
|
||||
int tabId = message.getInt("tabID");
|
||||
final Tab tab = Tabs.getInstance().getTab(tabId);
|
||||
tab.setHasTouchListeners(true);
|
||||
mTarget.post(new Runnable() {
|
||||
public void run() {
|
||||
if (Tabs.getInstance().isSelectedTab(tab))
|
||||
mTouchEventHandler.setWaitForTouchListeners(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(LOGTAG, "Exception handling message \"" + event + "\":", e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
switch (event.getAction() & MotionEvent.ACTION_MASK) {
|
||||
case MotionEvent.ACTION_DOWN: return onTouchStart(event);
|
||||
case MotionEvent.ACTION_MOVE: return onTouchMove(event);
|
||||
case MotionEvent.ACTION_UP: return onTouchEnd(event);
|
||||
case MotionEvent.ACTION_CANCEL: return onTouchCancel(event);
|
||||
case MotionEvent.ACTION_SCROLL: return onScroll(event);
|
||||
default: return false;
|
||||
/** This function MUST be called on the UI thread */
|
||||
public boolean onMotionEvent(MotionEvent event) {
|
||||
if (Build.VERSION.SDK_INT <= 11) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (event.getSource() & InputDevice.SOURCE_CLASS_MASK) {
|
||||
case InputDevice.SOURCE_CLASS_POINTER:
|
||||
switch (event.getAction() & MotionEvent.ACTION_MASK) {
|
||||
case MotionEvent.ACTION_SCROLL: return handlePointerScroll(event);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** This function MUST be called on the UI thread */
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
return mTouchEventHandler.handleEvent(event);
|
||||
}
|
||||
|
||||
boolean handleEvent(MotionEvent event) {
|
||||
switch (event.getAction() & MotionEvent.ACTION_MASK) {
|
||||
case MotionEvent.ACTION_DOWN: return handleTouchStart(event);
|
||||
case MotionEvent.ACTION_MOVE: return handleTouchMove(event);
|
||||
case MotionEvent.ACTION_UP: return handleTouchEnd(event);
|
||||
case MotionEvent.ACTION_CANCEL: return handleTouchCancel(event);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** This function MUST be called on the UI thread */
|
||||
public void notifyDefaultActionPrevented(boolean prevented) {
|
||||
mTouchEventHandler.handleEventListenerAction(!prevented);
|
||||
}
|
||||
|
||||
/** This function must be called from the UI thread. */
|
||||
@ -271,7 +317,7 @@ public class JavaPanZoomController
|
||||
* Panning/scrolling
|
||||
*/
|
||||
|
||||
private boolean onTouchStart(MotionEvent event) {
|
||||
private boolean handleTouchStart(MotionEvent event) {
|
||||
// user is taking control of movement, so stop
|
||||
// any auto-movement we have going
|
||||
stopAnimationTimer();
|
||||
@ -298,11 +344,11 @@ public class JavaPanZoomController
|
||||
Log.e(LOGTAG, "Received impossible touch down while in " + mState);
|
||||
return false;
|
||||
}
|
||||
Log.e(LOGTAG, "Unhandled case " + mState + " in onTouchStart");
|
||||
Log.e(LOGTAG, "Unhandled case " + mState + " in handleTouchStart");
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean onTouchMove(MotionEvent event) {
|
||||
private boolean handleTouchMove(MotionEvent event) {
|
||||
|
||||
switch (mState) {
|
||||
case FLING:
|
||||
@ -345,11 +391,11 @@ public class JavaPanZoomController
|
||||
// scale gesture listener will handle this
|
||||
return false;
|
||||
}
|
||||
Log.e(LOGTAG, "Unhandled case " + mState + " in onTouchMove");
|
||||
Log.e(LOGTAG, "Unhandled case " + mState + " in handleTouchMove");
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean onTouchEnd(MotionEvent event) {
|
||||
private boolean handleTouchEnd(MotionEvent event) {
|
||||
|
||||
switch (mState) {
|
||||
case FLING:
|
||||
@ -383,11 +429,11 @@ public class JavaPanZoomController
|
||||
setState(PanZoomState.NOTHING);
|
||||
return true;
|
||||
}
|
||||
Log.e(LOGTAG, "Unhandled case " + mState + " in onTouchEnd");
|
||||
Log.e(LOGTAG, "Unhandled case " + mState + " in handleTouchEnd");
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean onTouchCancel(MotionEvent event) {
|
||||
private boolean handleTouchCancel(MotionEvent event) {
|
||||
cancelTouch();
|
||||
|
||||
if (mState == PanZoomState.WAITING_LISTENERS) {
|
||||
@ -405,7 +451,7 @@ public class JavaPanZoomController
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean onScroll(MotionEvent event) {
|
||||
private boolean handlePointerScroll(MotionEvent event) {
|
||||
if (mState == PanZoomState.NOTHING || mState == PanZoomState.FLING) {
|
||||
float scrollX = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
|
||||
float scrollY = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
|
||||
|
@ -6,6 +6,7 @@
|
||||
package org.mozilla.gecko.gfx;
|
||||
|
||||
import org.mozilla.gecko.GeckoApp;
|
||||
import org.mozilla.gecko.OnInterceptTouchListener;
|
||||
import org.mozilla.gecko.R;
|
||||
import org.mozilla.gecko.ZoomConstraints;
|
||||
import org.mozilla.gecko.util.EventDispatcher;
|
||||
@ -43,7 +44,7 @@ public class LayerView extends FrameLayout {
|
||||
private static String LOGTAG = "GeckoLayerView";
|
||||
|
||||
private GeckoLayerClient mLayerClient;
|
||||
private TouchEventHandler mTouchEventHandler;
|
||||
private PanZoomController mPanZoomController;
|
||||
private GLController mGLController;
|
||||
private InputConnectionHandler mInputConnectionHandler;
|
||||
private LayerRenderer mRenderer;
|
||||
@ -56,6 +57,7 @@ public class LayerView extends FrameLayout {
|
||||
private TextureView mTextureView;
|
||||
|
||||
private Listener mListener;
|
||||
private OnInterceptTouchListener mTouchIntercepter;
|
||||
|
||||
/* Flags used to determine when to show the painted surface. */
|
||||
public static final int PAINT_START = 0;
|
||||
@ -95,8 +97,8 @@ public class LayerView extends FrameLayout {
|
||||
|
||||
public void initializeView(EventDispatcher eventDispatcher) {
|
||||
mLayerClient = new GeckoLayerClient(getContext(), this, eventDispatcher);
|
||||
mPanZoomController = mLayerClient.getPanZoomController();
|
||||
|
||||
mTouchEventHandler = new TouchEventHandler(getContext(), this, mLayerClient);
|
||||
mRenderer = new LayerRenderer(this);
|
||||
mInputConnectionHandler = null;
|
||||
|
||||
@ -123,22 +125,50 @@ public class LayerView extends FrameLayout {
|
||||
if (mRenderer != null) {
|
||||
mRenderer.destroy();
|
||||
}
|
||||
if (mTouchEventHandler != null) {
|
||||
mTouchEventHandler.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
public void setTouchIntercepter(final OnInterceptTouchListener touchIntercepter) {
|
||||
// this gets run on the gecko thread, but for thread safety we want the assignment
|
||||
// on the UI thread.
|
||||
post(new Runnable() {
|
||||
public void run() {
|
||||
mTouchIntercepter = touchIntercepter;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
if (event.getActionMasked() == MotionEvent.ACTION_DOWN)
|
||||
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
|
||||
requestFocus();
|
||||
}
|
||||
|
||||
return mTouchEventHandler == null ? false : mTouchEventHandler.handleEvent(event);
|
||||
if (mTouchIntercepter != null && mTouchIntercepter.onInterceptTouchEvent(this, event)) {
|
||||
return true;
|
||||
}
|
||||
if (mPanZoomController != null && mPanZoomController.onTouchEvent(event)) {
|
||||
return true;
|
||||
}
|
||||
if (mTouchIntercepter != null && mTouchIntercepter.onTouch(this, event)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onHoverEvent(MotionEvent event) {
|
||||
return mTouchEventHandler == null ? false : mTouchEventHandler.handleEvent(event);
|
||||
if (mTouchIntercepter != null && mTouchIntercepter.onTouch(this, event)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onGenericMotionEvent(MotionEvent event) {
|
||||
if (mPanZoomController != null && mPanZoomController.onMotionEvent(event)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -168,7 +198,7 @@ public class LayerView extends FrameLayout {
|
||||
}
|
||||
|
||||
public GeckoLayerClient getLayerClient() { return mLayerClient; }
|
||||
public TouchEventHandler getTouchEventHandler() { return mTouchEventHandler; }
|
||||
public PanZoomController getPanZoomController() { return mPanZoomController; }
|
||||
|
||||
public ImmutableViewportMetrics getViewportMetrics() {
|
||||
return mLayerClient.getViewportMetrics();
|
||||
@ -472,9 +502,4 @@ public class LayerView extends FrameLayout {
|
||||
public boolean isFullScreen() {
|
||||
return mFullScreen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onGenericMotionEvent(MotionEvent event) {
|
||||
return mTouchEventHandler == null ? false : mTouchEventHandler.handleEvent(event);
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,8 @@ import org.mozilla.gecko.GeckoAppShell;
|
||||
import org.mozilla.gecko.util.EventDispatcher;
|
||||
|
||||
import android.graphics.PointF;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
public interface PanZoomController {
|
||||
// The distance the user has to pan before we recognize it as such (e.g. to avoid 1-pixel pans
|
||||
@ -16,13 +18,17 @@ public interface PanZoomController {
|
||||
public static final float PAN_THRESHOLD = 1/16f * GeckoAppShell.getDpi();
|
||||
|
||||
static class Factory {
|
||||
static PanZoomController create(PanZoomTarget target, EventDispatcher dispatcher) {
|
||||
return new JavaPanZoomController(target, dispatcher);
|
||||
static PanZoomController create(PanZoomTarget target, View view, EventDispatcher dispatcher) {
|
||||
return new JavaPanZoomController(target, view, dispatcher);
|
||||
}
|
||||
}
|
||||
|
||||
public void destroy();
|
||||
|
||||
public boolean onTouchEvent(MotionEvent event);
|
||||
public boolean onMotionEvent(MotionEvent event);
|
||||
public void notifyDefaultActionPrevented(boolean prevented);
|
||||
|
||||
public boolean getRedrawHint();
|
||||
public PointF getVelocityVector();
|
||||
|
||||
|
@ -33,7 +33,7 @@ import java.util.Stack;
|
||||
*
|
||||
* - It doesn't take pressure into account, which results in smoother scaling.
|
||||
*/
|
||||
public class SimpleScaleGestureDetector {
|
||||
class SimpleScaleGestureDetector {
|
||||
private static final String LOGTAG = "GeckoSimpleScaleGestureDetector";
|
||||
|
||||
private SimpleScaleGestureListener mListener;
|
||||
@ -44,7 +44,7 @@ public class SimpleScaleGestureDetector {
|
||||
private LinkedList<PointerInfo> mPointerInfo;
|
||||
|
||||
/** Creates a new gesture detector with the given listener. */
|
||||
public SimpleScaleGestureDetector(SimpleScaleGestureListener listener) {
|
||||
SimpleScaleGestureDetector(SimpleScaleGestureListener listener) {
|
||||
mListener = listener;
|
||||
mPointerInfo = new LinkedList<PointerInfo>();
|
||||
}
|
||||
|
@ -10,11 +10,11 @@ import org.mozilla.gecko.Tab;
|
||||
import org.mozilla.gecko.Tabs;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.SystemClock;
|
||||
import android.util.Log;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
@ -49,14 +49,14 @@ import java.util.Queue;
|
||||
* to respond to user actions a timely manner regardless of default-prevention,
|
||||
* and fix issues like bug 749384.
|
||||
*/
|
||||
public final class TouchEventHandler implements Tabs.OnTabsChangedListener {
|
||||
final class TouchEventHandler implements Tabs.OnTabsChangedListener {
|
||||
private static final String LOGTAG = "GeckoTouchEventHandler";
|
||||
|
||||
// The time limit for listeners to respond with preventDefault on touchevents
|
||||
// before we begin panning the page
|
||||
private final int EVENT_LISTENER_TIMEOUT = 200;
|
||||
|
||||
private final LayerView mView;
|
||||
private final View mView;
|
||||
private final GestureDetector mGestureDetector;
|
||||
private final SimpleScaleGestureDetector mScaleGestureDetector;
|
||||
private final JavaPanZoomController mPanZoomController;
|
||||
@ -66,9 +66,6 @@ public final class TouchEventHandler implements Tabs.OnTabsChangedListener {
|
||||
private final Queue<MotionEvent> mEventQueue;
|
||||
private final ListenerTimeoutProcessor mListenerTimeoutProcessor;
|
||||
|
||||
// the listener we use to notify gecko of touch events
|
||||
private OnInterceptTouchListener mOnTouchListener;
|
||||
|
||||
// whether or not we should wait for touch listeners to respond (this state is
|
||||
// per-tab and is updated when we switch tabs).
|
||||
private boolean mWaitForTouchListeners;
|
||||
@ -124,11 +121,11 @@ public final class TouchEventHandler implements Tabs.OnTabsChangedListener {
|
||||
// processed. (n is the absolute value of the balance.)
|
||||
private int mProcessingBalance;
|
||||
|
||||
TouchEventHandler(Context context, LayerView view, GeckoLayerClient layerClient) {
|
||||
TouchEventHandler(Context context, View view, JavaPanZoomController panZoomController) {
|
||||
mView = view;
|
||||
|
||||
mEventQueue = new LinkedList<MotionEvent>();
|
||||
mPanZoomController = (JavaPanZoomController)layerClient.getPanZoomController();
|
||||
mPanZoomController = panZoomController;
|
||||
mGestureDetector = new GestureDetector(context, mPanZoomController);
|
||||
mScaleGestureDetector = new SimpleScaleGestureDetector(mPanZoomController);
|
||||
mListenerTimeoutProcessor = new ListenerTimeoutProcessor();
|
||||
@ -139,34 +136,12 @@ public final class TouchEventHandler implements Tabs.OnTabsChangedListener {
|
||||
Tabs.registerOnTabsChangedListener(this);
|
||||
}
|
||||
|
||||
void destroy() {
|
||||
public void destroy() {
|
||||
Tabs.unregisterOnTabsChangedListener(this);
|
||||
}
|
||||
|
||||
/* This function MUST be called on the UI thread */
|
||||
public boolean handleEvent(MotionEvent event) {
|
||||
// if we don't have gecko listeners, just dispatch the event
|
||||
// and be done with it, no extra work needed.
|
||||
if (mOnTouchListener == null) {
|
||||
dispatchEvent(event);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mOnTouchListener.onInterceptTouchEvent(mView, event)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// if this is a hover event just notify gecko, we don't have any interest in the java layer.
|
||||
if (isHoverEvent(event)) {
|
||||
mOnTouchListener.onTouch(mView, event);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isScrollEvent(event)) {
|
||||
dispatchEvent(event);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isDownEvent(event)) {
|
||||
// this is the start of a new block of events! whee!
|
||||
mHoldInQueue = mWaitForTouchListeners;
|
||||
@ -209,10 +184,7 @@ public final class TouchEventHandler implements Tabs.OnTabsChangedListener {
|
||||
mPanZoomController.preventedTouchFinished();
|
||||
}
|
||||
|
||||
// notify gecko of the event
|
||||
mOnTouchListener.onTouch(mView, event);
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -240,16 +212,6 @@ public final class TouchEventHandler implements Tabs.OnTabsChangedListener {
|
||||
mWaitForTouchListeners = aValue;
|
||||
}
|
||||
|
||||
/* This function MUST be called on the UI thread. */
|
||||
public void setOnTouchListener(OnInterceptTouchListener onTouchListener) {
|
||||
mOnTouchListener = onTouchListener;
|
||||
}
|
||||
|
||||
private boolean isHoverEvent(MotionEvent event) {
|
||||
int action = (event.getAction() & MotionEvent.ACTION_MASK);
|
||||
return (action == MotionEvent.ACTION_HOVER_ENTER || action == MotionEvent.ACTION_HOVER_MOVE || action == MotionEvent.ACTION_HOVER_EXIT);
|
||||
}
|
||||
|
||||
private boolean isDownEvent(MotionEvent event) {
|
||||
int action = (event.getAction() & MotionEvent.ACTION_MASK);
|
||||
return (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_POINTER_DOWN);
|
||||
@ -260,14 +222,6 @@ public final class TouchEventHandler implements Tabs.OnTabsChangedListener {
|
||||
return (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL);
|
||||
}
|
||||
|
||||
private boolean isScrollEvent(MotionEvent event) {
|
||||
if (Build.VERSION.SDK_INT <= 11) {
|
||||
return false;
|
||||
}
|
||||
int action = (event.getAction() & MotionEvent.ACTION_MASK);
|
||||
return (action == MotionEvent.ACTION_SCROLL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch the event to the gesture detectors and the pan/zoom controller.
|
||||
*/
|
||||
@ -279,7 +233,7 @@ public final class TouchEventHandler implements Tabs.OnTabsChangedListener {
|
||||
if (mScaleGestureDetector.isInProgress()) {
|
||||
return;
|
||||
}
|
||||
mPanZoomController.onTouchEvent(event);
|
||||
mPanZoomController.handleEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user