imported patch 1111-fix-motion-event-targeting
authorPatrick Walton <pwalton@mozilla.com>
Mon, 07 Nov 2011 14:17:01 -0800
changeset 83394 da1cd494b66637fb0680609506d153a4daff3abb
parent 83393 eb5c7179c92e5f8cbcdaf751f714b7410151b57f
child 83395 b2b7cdfb3c01890eaaa1218d7518a1281da12a49
push id519
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 00:38:35 +0000
treeherdermozilla-beta@788ea1ef610b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone10.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
imported patch 1111-fix-motion-event-targeting
embedding/android/GeckoAppShell.java
embedding/android/gfx/IntPoint.java
embedding/android/gfx/Layer.java
embedding/android/gfx/LayerController.java
--- a/embedding/android/GeckoAppShell.java
+++ b/embedding/android/GeckoAppShell.java
@@ -34,16 +34,17 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 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;
 
 import java.io.*;
 import java.lang.reflect.*;
 import java.nio.*;
 import java.nio.channels.*;
 import java.text.*;
@@ -439,23 +440,29 @@ public class GeckoAppShell
         // and go
         GeckoAppShell.nativeRun(combinedArgs);
     }
 
     // Called on the UI thread after Gecko loads.
     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;
             }
         });
 
         GeckoEvent event = new GeckoEvent(GeckoEvent.SIZE_CHANGED,
                                           LayerController.TILE_WIDTH, LayerController.TILE_HEIGHT,
                                           LayerController.TILE_WIDTH, LayerController.TILE_HEIGHT);
--- a/embedding/android/gfx/IntPoint.java
+++ b/embedding/android/gfx/IntPoint.java
@@ -36,11 +36,25 @@
  * ***** END LICENSE BLOCK ***** */
 
 package org.mozilla.fennec.gfx;
 
 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));
+    }
 }
 
 
--- a/embedding/android/gfx/Layer.java
+++ b/embedding/android/gfx/Layer.java
@@ -42,16 +42,17 @@ import javax.microedition.khronos.opengl
 
 public abstract class Layer {
     public IntPoint origin;
 
     public 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);
         onDraw(gl);
         gl.glPopMatrix();
     }
 
     /**
--- a/embedding/android/gfx/LayerController.java
+++ b/embedding/android/gfx/LayerController.java
@@ -223,16 +223,32 @@ public class LayerController implements 
     }
 
     // Returns true if a checkerboard is visible.
     private boolean checkerboarding() {
         IntRect pageRect = new IntRect(0, 0, mPageSize.width, mPageSize.height);
         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.
      */
 
     public boolean onTouchEvent(MotionEvent event) {
         boolean result = mPanZoomController.onTouchEvent(event);
         if (mOnTouchListener != null)