imported patch 1111-fix-motion-event-targeting
This commit is contained in:
@@ -39,6 +39,7 @@
|
||||
package org.mozilla.gecko;
|
||||
|
||||
import org.mozilla.fennec.gfx.GeckoSoftwareLayerClient;
|
||||
import org.mozilla.fennec.gfx.IntPoint;
|
||||
import org.mozilla.fennec.gfx.LayerController;
|
||||
import org.mozilla.fennec.gfx.LayerView;
|
||||
|
||||
@@ -444,13 +445,19 @@ public class GeckoAppShell
|
||||
private static void geckoLoaded() {
|
||||
GeckoApp.mAppContext.connectGeckoLayerClient();
|
||||
|
||||
LayerController layerController = GeckoApp.mAppContext.getLayerController();
|
||||
final LayerController layerController = GeckoApp.mAppContext.getLayerController();
|
||||
LayerView v = layerController.getView();
|
||||
mInputConnection = new GeckoInputConnection(v);
|
||||
v.setInputConnectionHandler(mInputConnection);
|
||||
|
||||
layerController.setOnTouchListener(new View.OnTouchListener() {
|
||||
public boolean onTouch(View view, MotionEvent event) {
|
||||
/* Transform the point to the layer offset. */
|
||||
IntPoint eventPoint = new IntPoint((int)Math.round(event.getX()),
|
||||
(int)Math.round(event.getY()));
|
||||
IntPoint geckoPoint = layerController.convertViewPointToLayerPoint(eventPoint);
|
||||
event.setLocation(geckoPoint.x, geckoPoint.y);
|
||||
|
||||
GeckoAppShell.sendEventToGecko(new GeckoEvent(event));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -41,6 +41,20 @@ public class IntPoint {
|
||||
public final int x, y;
|
||||
|
||||
public IntPoint(int inX, int inY) { x = inX; y = inY; }
|
||||
|
||||
@Override
|
||||
public String toString() { return "(" + x + ", " + y + ")"; }
|
||||
|
||||
/** Returns the result of adding the given point to this point. */
|
||||
public IntPoint add(IntPoint other) { return new IntPoint(x + other.x, y + other.y); }
|
||||
|
||||
/** Returns the result of subtracting the given point from this point. */
|
||||
public IntPoint subtract(IntPoint other) { return new IntPoint(x - other.x, y - other.y); }
|
||||
|
||||
/** Returns the result of multiplying both components by the given scalar. */
|
||||
public IntPoint scale(float scale) {
|
||||
return new IntPoint((int)Math.round((float)x * scale), (int)Math.round((float)y * scale));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ public abstract class Layer {
|
||||
origin = new IntPoint(0, 0);
|
||||
}
|
||||
|
||||
/** Draws the layer. Automatically applies the translation. */
|
||||
public final void draw(GL10 gl) {
|
||||
gl.glPushMatrix();
|
||||
gl.glTranslatef(origin.x, origin.y, 0.0f);
|
||||
|
||||
@@ -228,6 +228,22 @@ public class LayerController implements ScaleGestureDetector.OnScaleGestureListe
|
||||
return !getTileRect().contains(mVisibleRect.intersect(pageRect));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a point from layer view coordinates to layer coordinates. In other words, given a
|
||||
* point measured in pixels from the top left corner of the layer view, returns the point in
|
||||
* pixels measured from the top left corner of the root layer, in the coordinate system of the
|
||||
* layer itself. This method is used by the viewport controller as part of the process of
|
||||
* translating touch events to Gecko's coordinate system.
|
||||
*/
|
||||
public IntPoint convertViewPointToLayerPoint(IntPoint viewPoint) {
|
||||
if (mRootLayer == null)
|
||||
return null;
|
||||
|
||||
// Undo the transforms.
|
||||
IntPoint scaledPoint = viewPoint.scale(1.0f / getZoomFactor());
|
||||
return mVisibleRect.getOrigin().add(scaledPoint).subtract(mRootLayer.origin);
|
||||
}
|
||||
|
||||
/*
|
||||
* Gesture detection. This is handled only at a high level in this class; we dispatch to the
|
||||
* pan/zoom controller to do the dirty work.
|
||||
|
||||
Reference in New Issue
Block a user