mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1049136 - Stop using the TouchEventInterceptor interface in LayerView as it introduces an unnecessary layer of abstraction. r=wesj
This makes it clearer what the implications of returning true from PanZoomController.onTouchEvent are. Rather than having arbitrary TouchEventInterceptor implementations stop receiving events, this makes it clear that the only thing that stops is the events getting delivered to Gecko.
This commit is contained in:
parent
60f9323125
commit
aa1d4262d0
@ -8,7 +8,6 @@ package org.mozilla.gecko.gfx;
|
||||
import org.mozilla.gecko.GeckoAppShell;
|
||||
import org.mozilla.gecko.GeckoEvent;
|
||||
import org.mozilla.gecko.PrefsHelper;
|
||||
import org.mozilla.gecko.TouchEventInterceptor;
|
||||
import org.mozilla.gecko.util.FloatUtils;
|
||||
import org.mozilla.gecko.util.ThreadUtils;
|
||||
|
||||
@ -20,7 +19,7 @@ import android.view.animation.DecelerateInterpolator;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
public class LayerMarginsAnimator implements TouchEventInterceptor {
|
||||
public class LayerMarginsAnimator {
|
||||
private static final String LOGTAG = "GeckoLayerMarginsAnimator";
|
||||
// The duration of the animation in ns
|
||||
private static final long MARGIN_ANIMATION_DURATION = 250000000;
|
||||
@ -70,9 +69,6 @@ public class LayerMarginsAnimator implements TouchEventInterceptor {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
// Listen to touch events, for auto-pinning
|
||||
aView.addTouchInterceptor(this);
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
@ -247,15 +243,7 @@ public class LayerMarginsAnimator implements TouchEventInterceptor {
|
||||
return aMetrics.setMargins(newMarginsX[0], newMarginsY[0], newMarginsX[1], newMarginsY[1]).offsetViewportBy(aDx, aDy);
|
||||
}
|
||||
|
||||
/** Implementation of TouchEventInterceptor */
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Implementation of TouchEventInterceptor */
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(View view, MotionEvent event) {
|
||||
boolean onInterceptTouchEvent(MotionEvent event) {
|
||||
int action = event.getActionMasked();
|
||||
if (action == MotionEvent.ACTION_DOWN && event.getPointerCount() == 1) {
|
||||
mTouchTravelDistance.set(0.0f, 0.0f);
|
||||
|
@ -17,7 +17,6 @@ import org.mozilla.gecko.GeckoEvent;
|
||||
import org.mozilla.gecko.PrefsHelper;
|
||||
import org.mozilla.gecko.Tab;
|
||||
import org.mozilla.gecko.Tabs;
|
||||
import org.mozilla.gecko.TouchEventInterceptor;
|
||||
import org.mozilla.gecko.ZoomConstraints;
|
||||
import org.mozilla.gecko.mozglue.RobocopTarget;
|
||||
import org.mozilla.gecko.mozglue.generatorannotations.WrapElementForJNI;
|
||||
@ -69,8 +68,10 @@ public class LayerView extends FrameLayout implements Tabs.OnTabsChangedListener
|
||||
|
||||
private Listener mListener;
|
||||
|
||||
private PointF mInitialTouchPoint;
|
||||
private boolean mGeckoIsReady;
|
||||
|
||||
/* This should only be modified on the Java UI thread. */
|
||||
private final ArrayList<TouchEventInterceptor> mTouchInterceptors;
|
||||
private final Overscroll mOverscroll;
|
||||
|
||||
/* Flags used to determine when to show the painted surface. */
|
||||
@ -109,7 +110,6 @@ public class LayerView extends FrameLayout implements Tabs.OnTabsChangedListener
|
||||
mBackgroundColor = Color.WHITE;
|
||||
mFullScreenState = FullScreenState.NONE;
|
||||
|
||||
mTouchInterceptors = new ArrayList<TouchEventInterceptor>();
|
||||
if (Versions.feature14Plus) {
|
||||
mOverscroll = new OverscrollEdgeEffect(this);
|
||||
} else {
|
||||
@ -156,43 +156,36 @@ public class LayerView extends FrameLayout implements Tabs.OnTabsChangedListener
|
||||
});
|
||||
|
||||
mLayerClient.notifyGeckoReady();
|
||||
addTouchInterceptor(new TouchEventInterceptor() {
|
||||
private PointF mInitialTouchPoint;
|
||||
mInitialTouchPoint = null;
|
||||
mGeckoIsReady = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(View view, MotionEvent event) {
|
||||
return false;
|
||||
}
|
||||
private boolean sendEventToGecko(MotionEvent event) {
|
||||
if (!mGeckoIsReady) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent event) {
|
||||
if (event == null) {
|
||||
return true;
|
||||
}
|
||||
int action = event.getActionMasked();
|
||||
PointF point = new PointF(event.getX(), event.getY());
|
||||
if (action == MotionEvent.ACTION_DOWN) {
|
||||
mInitialTouchPoint = point;
|
||||
}
|
||||
|
||||
int action = event.getActionMasked();
|
||||
PointF point = new PointF(event.getX(), event.getY());
|
||||
if (action == MotionEvent.ACTION_DOWN) {
|
||||
mInitialTouchPoint = point;
|
||||
}
|
||||
if (mInitialTouchPoint != null && action == MotionEvent.ACTION_MOVE) {
|
||||
Point p = getEventRadius(event);
|
||||
|
||||
if (mInitialTouchPoint != null && action == MotionEvent.ACTION_MOVE) {
|
||||
Point p = getEventRadius(event);
|
||||
|
||||
if (PointUtils.subtract(point, mInitialTouchPoint).length() <
|
||||
Math.max(PanZoomController.CLICK_THRESHOLD, Math.min(Math.min(p.x, p.y), PanZoomController.PAN_THRESHOLD))) {
|
||||
// Don't send the touchmove event if if the users finger hasn't moved far.
|
||||
// Necessary for Google Maps to work correctly. See bug 771099.
|
||||
return true;
|
||||
} else {
|
||||
mInitialTouchPoint = null;
|
||||
}
|
||||
}
|
||||
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createMotionEvent(event, false));
|
||||
if (PointUtils.subtract(point, mInitialTouchPoint).length() <
|
||||
Math.max(PanZoomController.CLICK_THRESHOLD, Math.min(Math.min(p.x, p.y), PanZoomController.PAN_THRESHOLD))) {
|
||||
// Don't send the touchmove event if if the users finger hasn't moved far.
|
||||
// Necessary for Google Maps to work correctly. See bug 771099.
|
||||
return true;
|
||||
} else {
|
||||
mInitialTouchPoint = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createMotionEvent(event, false));
|
||||
return true;
|
||||
}
|
||||
|
||||
public void showSurface() {
|
||||
@ -215,37 +208,6 @@ public class LayerView extends FrameLayout implements Tabs.OnTabsChangedListener
|
||||
Tabs.unregisterOnTabsChangedListener(this);
|
||||
}
|
||||
|
||||
public void addTouchInterceptor(final TouchEventInterceptor aTouchInterceptor) {
|
||||
post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mTouchInterceptors.add(aTouchInterceptor);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void removeTouchInterceptor(final TouchEventInterceptor aTouchInterceptor) {
|
||||
post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mTouchInterceptors.remove(aTouchInterceptor);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean runTouchInterceptors(MotionEvent event, boolean aOnTouch) {
|
||||
boolean result = false;
|
||||
for (TouchEventInterceptor i : mTouchInterceptors) {
|
||||
if (aOnTouch) {
|
||||
result |= i.onTouch(this, event);
|
||||
} else {
|
||||
result |= i.onInterceptTouchEvent(this, event);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispatchDraw(final Canvas canvas) {
|
||||
super.dispatchDraw(canvas);
|
||||
@ -262,24 +224,18 @@ public class LayerView extends FrameLayout implements Tabs.OnTabsChangedListener
|
||||
requestFocus();
|
||||
}
|
||||
|
||||
if (runTouchInterceptors(event, false)) {
|
||||
if (mMarginsAnimator != null && mMarginsAnimator.onInterceptTouchEvent(event)) {
|
||||
return true;
|
||||
}
|
||||
if (mPanZoomController != null && mPanZoomController.onTouchEvent(event)) {
|
||||
return true;
|
||||
}
|
||||
if (runTouchInterceptors(event, true)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return sendEventToGecko(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onHoverEvent(MotionEvent event) {
|
||||
if (runTouchInterceptors(event, true)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return sendEventToGecko(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user