Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9232f2e5 authored by Steve Block's avatar Steve Block Committed by Android (Google) Code Review
Browse files

Merge changes Ib82f897a,I2d689d0f

* changes:
  Fix EventSender mouse events to correctly convert from screen coordinates
  Refactor EventSenderImpl.MousePoint
parents 50c5e4c3 edfdd155
Loading
Loading
Loading
Loading
+45 −35
Original line number Diff line number Diff line
@@ -56,21 +56,38 @@ public class EventSenderImpl {
    private static final int MSG_SET_TOUCH_MODIFIER = 16;
    private static final int MSG_CANCEL_TOUCH_POINT = 17;

    public static class TouchPoint {
        WebView mWebView;
        private int mId;
    private static class Point {
        private int mX;
        private int mY;

        public Point(int x, int y) {
            mX = x;
            mY = y;
        }
        public int x() {
            return mX;
        }
        public int y() {
            return mY;
        }
    }

    private Point createViewPointFromContentCoordinates(int x, int y) {
        return new Point((int)(x * mWebView.getScale()) - mWebView.getScrollX(),
                         (int)(y * mWebView.getScale()) - mWebView.getScrollY());
    }

    public static class TouchPoint {
        private int mId;
        private Point mPoint;
        private long mDownTime;
        private boolean mReleased = false;
        private boolean mMoved = false;
        private boolean mCancelled = false;

        public TouchPoint(WebView webView, int id, int x, int y) {
            mWebView = webView;
        public TouchPoint(int id, Point point) {
            mId = id;
            mX = scaleX(x);
            mY = scaleY(y);
            mPoint = point;
        }

        public int getId() {
@@ -78,20 +95,19 @@ public class EventSenderImpl {
        }

        public int getX() {
            return mX;
            return mPoint.x();
        }

        public int getY() {
            return mY;
            return mPoint.y();
        }

        public boolean hasMoved() {
            return mMoved;
        }

        public void move(int newX, int newY) {
            mX = scaleX(newX);
            mY = scaleY(newY);
        public void move(Point point) {
            mPoint = point;
            mMoved = true;
        }

@@ -122,20 +138,11 @@ public class EventSenderImpl {
        public void cancel() {
            mCancelled = true;
        }

        private int scaleX(int x) {
            return (int)(x * mWebView.getScale()) - mWebView.getScrollX();
        }

        private int scaleY(int y) {
            return (int)(y * mWebView.getScale()) - mWebView.getScrollY();
        }
    }

    private List<TouchPoint> mTouchPoints;
    private int mTouchMetaState;
    private int mMouseX;
    private int mMouseY;
    private Point mMousePoint;

    private WebView mWebView;

@@ -177,15 +184,19 @@ public class EventSenderImpl {
                /** MOUSE */

                case MSG_MOUSE_DOWN:
                    if (mMousePoint != null) {
                        ts = SystemClock.uptimeMillis();
                    event = MotionEvent.obtain(ts, ts, MotionEvent.ACTION_DOWN, mMouseX, mMouseY, 0);
                        event = MotionEvent.obtain(ts, ts, MotionEvent.ACTION_DOWN, mMousePoint.x(), mMousePoint.y(), 0);
                        mWebView.onTouchEvent(event);
                    }
                    break;

                case MSG_MOUSE_UP:
                    if (mMousePoint != null) {
                        ts = SystemClock.uptimeMillis();
                    event = MotionEvent.obtain(ts, ts, MotionEvent.ACTION_UP, mMouseX, mMouseY, 0);
                        event = MotionEvent.obtain(ts, ts, MotionEvent.ACTION_UP, mMousePoint.x(), mMousePoint.y(), 0);
                        mWebView.onTouchEvent(event);
                    }
                    break;

                case MSG_MOUSE_CLICK:
@@ -194,8 +205,7 @@ public class EventSenderImpl {
                    break;

                case MSG_MOUSE_MOVE_TO:
                    mMouseX = msg.arg1;
                    mMouseY = msg.arg2;
                    mMousePoint = createViewPointFromContentCoordinates(msg.arg1, msg.arg2);
                    break;

                /** TOUCH */
@@ -208,8 +218,8 @@ public class EventSenderImpl {
                    } else {
                        id = getTouchPoints().get(numPoints - 1).getId() + 1;
                    }
                    getTouchPoints().add(new TouchPoint(mWebView, id,
                            msg.arg1, msg.arg2));
                    getTouchPoints().add(
                            new TouchPoint(id, createViewPointFromContentCoordinates(msg.arg1, msg.arg2)));
                    break;

                case MSG_TOUCH_START:
@@ -232,7 +242,8 @@ public class EventSenderImpl {
                        break;
                    }

                    getTouchPoints().get(index).move(bundle.getInt("x"), bundle.getInt("y"));
                    getTouchPoints().get(index).move(
                            createViewPointFromContentCoordinates(bundle.getInt("x"), bundle.getInt("y")));
                    break;

                case MSG_TOUCH_MOVE:
@@ -333,8 +344,7 @@ public class EventSenderImpl {
        mWebView = webView;
        mTouchPoints = null;
        mTouchMetaState = 0;
        mMouseX = 0;
        mMouseY = 0;
        mMousePoint = null;
    }

    public void enableDOMUIEventLogging(int domNode) {