Kaydet (Commit) 93e7ffbd authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl

android: PanZoomControler updates from Fennec

Change-Id: Ic338221ced6133771af8f46ae4a257e043a1709f
üst dc169a05
......@@ -80,6 +80,10 @@ public class LayerController {
layerClient.setLayerController(this);
}
public void destroy() {
mPanZoomController.destroy();
}
public void setForceRedraw() {
mForceRedraw = true;
}
......@@ -93,26 +97,10 @@ public class LayerController {
return mViewportMetrics.getViewport();
}
public RectF getCssViewport() {
return mViewportMetrics.getCssViewport();
}
public FloatSize getViewportSize() {
return mViewportMetrics.getSize();
}
public RectF getPageRect() {
return mViewportMetrics.getPageRect();
}
public RectF getCssPageRect() {
return mViewportMetrics.getCssPageRect();
}
public PointF getOrigin() {
return mViewportMetrics.getOrigin();
}
public float getZoomFactor() {
return mViewportMetrics.zoomFactor;
}
......@@ -321,11 +309,6 @@ public class LayerController {
public void setAllowZoom(final boolean aValue) {
mAllowZoom = aValue;
mView.post(new Runnable() {
public void run() {
mView.getTouchEventHandler().setDoubleTapEnabled(aValue);
}
});
}
public boolean getAllowZoom() {
......
......@@ -188,11 +188,9 @@ public class LayerRenderer implements GLSurfaceView.Renderer {
@Override
protected void finalize() throws Throwable {
try {
if (mCoordByteBuffer != null) {
DirectBufferAllocator.free(mCoordByteBuffer);
mCoordByteBuffer = null;
mCoordBuffer = null;
}
DirectBufferAllocator.free(mCoordByteBuffer);
mCoordByteBuffer = null;
mCoordBuffer = null;
} finally {
super.finalize();
}
......@@ -333,14 +331,6 @@ public class LayerRenderer implements GLSurfaceView.Renderer {
moveFrameRateLayer(width, height);
}
// updating the state in the view/controller/client should be
// done on the main UI thread, not the GL renderer thread
mView.post(new Runnable() {
public void run() {
mView.setViewportSize(new IntSize(width, height));
}
});
/* TODO: Throw away tile images? */
}
......
......@@ -74,6 +74,13 @@ public class LayerView extends SurfaceView implements SurfaceHolder.Callback {
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getActionMasked() == MotionEvent.ACTION_DOWN)
requestFocus();
return mTouchEventHandler.handleEvent(event);
}
@Override
public boolean onHoverEvent(MotionEvent event) {
return mTouchEventHandler.handleEvent(event);
}
......
......@@ -7,6 +7,7 @@ package org.mozilla.gecko.gfx;
import android.content.Context;
import android.os.SystemClock;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View.OnTouchListener;
......@@ -58,7 +59,6 @@ public final class TouchEventHandler {
private final GestureDetector mGestureDetector;
private final SimpleScaleGestureDetector mScaleGestureDetector;
private final PanZoomController mPanZoomController;
private final GestureDetector.OnDoubleTapListener mDoubleTapListener;
// the queue of events that we are holding on to while waiting for a preventDefault
// notification
......@@ -133,8 +133,7 @@ public final class TouchEventHandler {
mListenerTimeoutProcessor = new ListenerTimeoutProcessor();
mDispatchEvents = true;
mDoubleTapListener = controller.getDoubleTapListener();
setDoubleTapEnabled(true);
mGestureDetector.setOnDoubleTapListener(controller.getDoubleTapListener());
}
/* This function MUST be called on the UI thread */
......@@ -146,6 +145,12 @@ public final class TouchEventHandler {
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 (isDownEvent(event)) {
// this is the start of a new block of events! whee!
mHoldInQueue = mWaitForTouchListeners;
......@@ -159,18 +164,20 @@ public final class TouchEventHandler {
// other blocks waiting in the queue, then we should let the pan/zoom controller
// know we are waiting for the touch listeners to run
if (mEventQueue.isEmpty()) {
mPanZoomController.waitingForTouchListeners(event);
mPanZoomController.startingNewEventBlock(event, true);
}
// if we're holding the events in the queue, set the timeout so that
// we dispatch these events if we don't get a default-prevented notification
mView.postDelayed(mListenerTimeoutProcessor, EVENT_LISTENER_TIMEOUT);
} else {
// if we're not holding these events, then we still need to pretend like
// we did and had a ListenerTimeoutProcessor fire so that when we get
// the default-prevented notification for this block, it doesn't accidentally
// act upon some other block
mProcessingBalance++;
// we're not going to be holding this block of events in the queue, but we need
// a marker of some sort so that the processEventBlock loop deals with the blocks
// in the right order as notifications come in. we use a single null event in
// the queue as a placeholder for a block of events that has already been dispatched.
mEventQueue.add(null);
mPanZoomController.startingNewEventBlock(event, false);
}
// set the timeout so that we dispatch these events and update mProcessingBalance
// if we don't get a default-prevented notification
mView.postDelayed(mListenerTimeoutProcessor, EVENT_LISTENER_TIMEOUT);
}
// if we need to hold the events, add it to the queue. if we need to dispatch
......@@ -212,11 +219,6 @@ public final class TouchEventHandler {
mProcessingBalance--;
}
/* This function MUST be called on the UI thread. */
public void setDoubleTapEnabled(boolean aValue) {
mGestureDetector.setOnDoubleTapListener(aValue ? mDoubleTapListener : null);
}
/* This function MUST be called on the UI thread. */
public void setWaitForTouchListeners(boolean aValue) {
mWaitForTouchListeners = aValue;
......@@ -227,6 +229,11 @@ public final class TouchEventHandler {
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);
......@@ -242,16 +249,7 @@ public final class TouchEventHandler {
*/
private void dispatchEvent(MotionEvent event) {
if (mGestureDetector.onTouchEvent(event)) {
// An up/cancel event should get passed to both detectors, in
// case it comes from a pointer the scale detector is tracking.
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_POINTER_UP:
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
break;
default:
return;
}
return;
}
mScaleGestureDetector.onTouchEvent(event);
if (mScaleGestureDetector.isInProgress()) {
......@@ -272,6 +270,11 @@ public final class TouchEventHandler {
dispatchEvent(MotionEvent.obtain(now, now, MotionEvent.ACTION_CANCEL, 0, 0, 0));
}
if (mEventQueue.isEmpty()) {
Log.e(LOGTAG, "Unexpected empty event queue in processEventBlock!", new Exception());
return;
}
// the odd loop condition is because the first event in the queue will
// always be a DOWN or POINTER_DOWN event, and we want to process all
// the events in the queue starting at that one, up to but not including
......@@ -279,15 +282,19 @@ public final class TouchEventHandler {
MotionEvent event = mEventQueue.poll();
while (true) {
// for each event we process, only dispatch it if the block hasn't been
// default-prevented.
if (allowDefaultAction) {
dispatchEvent(event);
} else if (touchFinished(event)) {
mPanZoomController.preventedTouchFinished();
// event being null here is valid and represents a block of events
// that has already been dispatched.
if (event != null) {
// for each event we process, only dispatch it if the block hasn't been
// default-prevented.
if (allowDefaultAction) {
dispatchEvent(event);
} else if (touchFinished(event)) {
mPanZoomController.preventedTouchFinished();
}
}
event = mEventQueue.peek();
if (event == null) {
if (mEventQueue.isEmpty()) {
// we have processed the backlog of events, and are all caught up.
// now we can set clear the hold flag and set the dispatch flag so
// that the handleEvent() function can do the right thing for all
......@@ -297,10 +304,13 @@ public final class TouchEventHandler {
mDispatchEvents = allowDefaultAction;
break;
}
if (isDownEvent(event)) {
event = mEventQueue.peek();
if (event == null || isDownEvent(event)) {
// we have finished processing the block we were interested in.
// now we wait for the next call to processEventBlock
mPanZoomController.waitingForTouchListeners(event);
if (event != null) {
mPanZoomController.startingNewEventBlock(event, true);
}
break;
}
// pop the event we peeked above, as it is still part of the block and
......
......@@ -45,6 +45,9 @@ class SubdocumentScrollHelper {
mPendingDisplacement = new PointF();
}
void destroy() {
}
boolean scrollBy(PointF displacement) {
if (! mOverridePanning) {
return false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment