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

Commit b501f77f authored by Shimeng (Simon) Wang's avatar Shimeng (Simon) Wang Committed by Android (Google) Code Review
Browse files

Merge "Use rounded interger to represent the last touch point." into honeycomb

parents fc37018a 1e07da36
Loading
Loading
Loading
Loading
+38 −47
Original line number Original line Diff line number Diff line
@@ -408,10 +408,13 @@ public class WebView extends AbsoluteLayout
    PluginFullScreenHolder mFullScreenHolder;
    PluginFullScreenHolder mFullScreenHolder;


    /**
    /**
     * Position of the last touch event.
     * Position of the last touch event in pixels.
     * Use integer to prevent loss of dragging delta calculation accuracy;
     * which was done in float and converted to integer, and resulted in gradual
     * and compounding touch position and view dragging mismatch.
     */
     */
    private float mLastTouchX;
    private int mLastTouchX;
    private float mLastTouchY;
    private int mLastTouchY;


    /**
    /**
     * Time of the last touch event.
     * Time of the last touch event.
@@ -2218,8 +2221,8 @@ public class WebView extends AbsoluteLayout
        if (type == HitTestResult.UNKNOWN_TYPE
        if (type == HitTestResult.UNKNOWN_TYPE
                || type == HitTestResult.SRC_ANCHOR_TYPE) {
                || type == HitTestResult.SRC_ANCHOR_TYPE) {
            // Now check to see if it is an image.
            // Now check to see if it is an image.
            int contentX = viewToContentX((int) mLastTouchX + mScrollX);
            int contentX = viewToContentX(mLastTouchX + mScrollX);
            int contentY = viewToContentY((int) mLastTouchY + mScrollY);
            int contentY = viewToContentY(mLastTouchY + mScrollY);
            String text = nativeImageURI(contentX, contentY);
            String text = nativeImageURI(contentX, contentY);
            if (text != null) {
            if (text != null) {
                result.setType(type == HitTestResult.UNKNOWN_TYPE ?
                result.setType(type == HitTestResult.UNKNOWN_TYPE ?
@@ -2256,8 +2259,8 @@ public class WebView extends AbsoluteLayout
        if (hrefMsg == null) {
        if (hrefMsg == null) {
            return;
            return;
        }
        }
        int contentX = viewToContentX((int) mLastTouchX + mScrollX);
        int contentX = viewToContentX(mLastTouchX + mScrollX);
        int contentY = viewToContentY((int) mLastTouchY + mScrollY);
        int contentY = viewToContentY(mLastTouchY + mScrollY);
        mWebViewCore.sendMessage(EventHub.REQUEST_CURSOR_HREF,
        mWebViewCore.sendMessage(EventHub.REQUEST_CURSOR_HREF,
                contentX, contentY, hrefMsg);
                contentX, contentY, hrefMsg);
    }
    }
@@ -2271,8 +2274,8 @@ public class WebView extends AbsoluteLayout
     */
     */
    public void requestImageRef(Message msg) {
    public void requestImageRef(Message msg) {
        if (0 == mNativeClass) return; // client isn't initialized
        if (0 == mNativeClass) return; // client isn't initialized
        int contentX = viewToContentX((int) mLastTouchX + mScrollX);
        int contentX = viewToContentX(mLastTouchX + mScrollX);
        int contentY = viewToContentY((int) mLastTouchY + mScrollY);
        int contentY = viewToContentY(mLastTouchY + mScrollY);
        String ref = nativeImageURI(contentX, contentY);
        String ref = nativeImageURI(contentX, contentY);
        Bundle data = msg.getData();
        Bundle data = msg.getData();
        data.putString("url", ref);
        data.putString("url", ref);
@@ -3856,8 +3859,8 @@ public class WebView extends AbsoluteLayout
     * @hide pending API council approval
     * @hide pending API council approval
     */
     */
    public boolean selectText() {
    public boolean selectText() {
        int x = viewToContentX((int) mLastTouchX + mScrollX);
        int x = viewToContentX(mLastTouchX + mScrollX);
        int y = viewToContentY((int) mLastTouchY + mScrollY);
        int y = viewToContentY(mLastTouchY + mScrollY);
        return selectText(x, y);
        return selectText(x, y);
    }
    }


@@ -4858,8 +4861,8 @@ public class WebView extends AbsoluteLayout
            mSelectX = contentToViewX(rect.left);
            mSelectX = contentToViewX(rect.left);
            mSelectY = contentToViewY(rect.top);
            mSelectY = contentToViewY(rect.top);
        } else if (mLastTouchY > getVisibleTitleHeight()) {
        } else if (mLastTouchY > getVisibleTitleHeight()) {
            mSelectX = mScrollX + (int) mLastTouchX;
            mSelectX = mScrollX + mLastTouchX;
            mSelectY = mScrollY + (int) mLastTouchY;
            mSelectY = mScrollY + mLastTouchY;
        } else {
        } else {
            mSelectX = mScrollX + getViewWidth() / 2;
            mSelectX = mScrollX + getViewWidth() / 2;
            mSelectY = mScrollY + getViewHeightWithTitle() / 2;
            mSelectY = mScrollY + getViewHeightWithTitle() / 2;
@@ -5357,7 +5360,7 @@ public class WebView extends AbsoluteLayout
            return true;
            return true;
        }
        }


        return handleTouchEventCommon(ev, ev.getX(), ev.getY());
        return handleTouchEventCommon(ev, Math.round(ev.getX()), Math.round(ev.getY()));
    }
    }


    /*
    /*
@@ -5365,7 +5368,7 @@ public class WebView extends AbsoluteLayout
     * (x, y) denotes current focus point, which is the touch point for single touch
     * (x, y) denotes current focus point, which is the touch point for single touch
     * and the middle point for multi-touch.
     * and the middle point for multi-touch.
     */
     */
    private boolean handleTouchEventCommon(MotionEvent ev, float x, float y) {
    private boolean handleTouchEventCommon(MotionEvent ev, int x, int y) {
        int action = ev.getAction();
        int action = ev.getAction();
        long eventTime = ev.getEventTime();
        long eventTime = ev.getEventTime();


@@ -5377,12 +5380,10 @@ public class WebView extends AbsoluteLayout
        x = Math.min(x, getViewWidth() - 1);
        x = Math.min(x, getViewWidth() - 1);
        y = Math.min(y, getViewHeightWithTitle() - 1);
        y = Math.min(y, getViewHeightWithTitle() - 1);


        float fDeltaX = mLastTouchX - x;
        int deltaX = mLastTouchX - x;
        float fDeltaY = mLastTouchY - y;
        int deltaY = mLastTouchY - y;
        int deltaX = (int) fDeltaX;
        int contentX = viewToContentX(x + mScrollX);
        int deltaY = (int) fDeltaY;
        int contentY = viewToContentY(y + mScrollY);
        int contentX = viewToContentX((int) x + mScrollX);
        int contentY = viewToContentY((int) y + mScrollY);


        switch (action) {
        switch (action) {
            case MotionEvent.ACTION_DOWN: {
            case MotionEvent.ACTION_DOWN: {
@@ -5607,8 +5608,6 @@ public class WebView extends AbsoluteLayout
                    mTouchMode = TOUCH_DRAG_MODE;
                    mTouchMode = TOUCH_DRAG_MODE;
                    mLastTouchX = x;
                    mLastTouchX = x;
                    mLastTouchY = y;
                    mLastTouchY = y;
                    fDeltaX = 0.0f;
                    fDeltaY = 0.0f;
                    deltaX = 0;
                    deltaX = 0;
                    deltaY = 0;
                    deltaY = 0;


@@ -5619,9 +5618,7 @@ public class WebView extends AbsoluteLayout
                // do pan
                // do pan
                boolean done = false;
                boolean done = false;
                boolean keepScrollBarsVisible = false;
                boolean keepScrollBarsVisible = false;
                if (Math.abs(fDeltaX) < 1.0f && Math.abs(fDeltaY) < 1.0f) {
                if (deltaX == 0 && deltaY == 0) {
                    mLastTouchX = x;
                    mLastTouchY = y;
                    keepScrollBarsVisible = done = true;
                    keepScrollBarsVisible = done = true;
                } else {
                } else {
                    if (mSnapScrollMode == SNAP_X || mSnapScrollMode == SNAP_Y) {
                    if (mSnapScrollMode == SNAP_X || mSnapScrollMode == SNAP_Y) {
@@ -5670,12 +5667,6 @@ public class WebView extends AbsoluteLayout
                            mLastTouchY = y;
                            mLastTouchY = y;
                        }
                        }
                        mHeldMotionless = MOTIONLESS_FALSE;
                        mHeldMotionless = MOTIONLESS_FALSE;
                    } else {
                        // keep the scrollbar on the screen even there is no
                        // scroll
                        mLastTouchX = x;
                        mLastTouchY = y;
                        keepScrollBarsVisible = true;
                    }
                    }
                    mLastTouchTime = eventTime;
                    mLastTouchTime = eventTime;
                    mUserScroll = true;
                    mUserScroll = true;
@@ -5937,8 +5928,8 @@ public class WebView extends AbsoluteLayout
            action = MotionEvent.ACTION_DOWN;
            action = MotionEvent.ACTION_DOWN;
        } else if (action == MotionEvent.ACTION_POINTER_UP) {
        } else if (action == MotionEvent.ACTION_POINTER_UP) {
            // set mLastTouchX/Y to the remaining point
            // set mLastTouchX/Y to the remaining point
            mLastTouchX = x;
            mLastTouchX = Math.round(x);
            mLastTouchY = y;
            mLastTouchY = Math.round(y);
        } else if (action == MotionEvent.ACTION_MOVE) {
        } else if (action == MotionEvent.ACTION_MOVE) {
            // negative x or y indicate it is on the edge, skip it.
            // negative x or y indicate it is on the edge, skip it.
            if (x < 0 || y < 0) {
            if (x < 0 || y < 0) {
@@ -5946,7 +5937,7 @@ public class WebView extends AbsoluteLayout
            }
            }
        }
        }


        return handleTouchEventCommon(ev, x, y);
        return handleTouchEventCommon(ev, Math.round(x), Math.round(y));
    }
    }


    private void cancelWebCoreTouchEvent(int x, int y, boolean removeEvents) {
    private void cancelWebCoreTouchEvent(int x, int y, boolean removeEvents) {
@@ -5967,8 +5958,8 @@ public class WebView extends AbsoluteLayout


    private void startTouch(float x, float y, long eventTime) {
    private void startTouch(float x, float y, long eventTime) {
        // Remember where the motion event started
        // Remember where the motion event started
        mLastTouchX = x;
        mLastTouchX = Math.round(x);
        mLastTouchY = y;
        mLastTouchY = Math.round(y);
        mLastTouchTime = eventTime;
        mLastTouchTime = eventTime;
        mVelocityTracker = VelocityTracker.obtain();
        mVelocityTracker = VelocityTracker.obtain();
        mSnapScrollMode = SNAP_NONE;
        mSnapScrollMode = SNAP_NONE;
@@ -6598,8 +6589,8 @@ public class WebView extends AbsoluteLayout
            return;
            return;
        }
        }
        // mLastTouchX and mLastTouchY are the point in the current viewport
        // mLastTouchX and mLastTouchY are the point in the current viewport
        int contentX = viewToContentX((int) mLastTouchX + mScrollX);
        int contentX = viewToContentX(mLastTouchX + mScrollX);
        int contentY = viewToContentY((int) mLastTouchY + mScrollY);
        int contentY = viewToContentY(mLastTouchY + mScrollY);
        Rect rect = new Rect(contentX - mNavSlop, contentY - mNavSlop,
        Rect rect = new Rect(contentX - mNavSlop, contentY - mNavSlop,
                contentX + mNavSlop, contentY + mNavSlop);
                contentX + mNavSlop, contentY + mNavSlop);
        nativeSelectBestAt(rect);
        nativeSelectBestAt(rect);
@@ -6630,8 +6621,8 @@ public class WebView extends AbsoluteLayout
        if (!inEditingMode()) {
        if (!inEditingMode()) {
            return;
            return;
        }
        }
        mLastTouchX = x + (float) (mWebTextView.getLeft() - mScrollX);
        mLastTouchX = Math.round(x + mWebTextView.getLeft() - mScrollX);
        mLastTouchY = y + (float) (mWebTextView.getTop() - mScrollY);
        mLastTouchY = Math.round(y + mWebTextView.getTop() - mScrollY);
        mLastTouchTime = eventTime;
        mLastTouchTime = eventTime;
        if (!mScroller.isFinished()) {
        if (!mScroller.isFinished()) {
            abortAnimation();
            abortAnimation();
@@ -6690,8 +6681,8 @@ public class WebView extends AbsoluteLayout
        mTouchMode = TOUCH_DONE_MODE;
        mTouchMode = TOUCH_DONE_MODE;
        switchOutDrawHistory();
        switchOutDrawHistory();
        // mLastTouchX and mLastTouchY are the point in the current viewport
        // mLastTouchX and mLastTouchY are the point in the current viewport
        int contentX = viewToContentX((int) mLastTouchX + mScrollX);
        int contentX = viewToContentX(mLastTouchX + mScrollX);
        int contentY = viewToContentY((int) mLastTouchY + mScrollY);
        int contentY = viewToContentY(mLastTouchY + mScrollY);
        if (getSettings().supportTouchOnly()) {
        if (getSettings().supportTouchOnly()) {
            removeTouchHighlight(false);
            removeTouchHighlight(false);
            WebViewCore.TouchUpData touchUpData = new WebViewCore.TouchUpData();
            WebViewCore.TouchUpData touchUpData = new WebViewCore.TouchUpData();
@@ -7052,8 +7043,8 @@ public class WebView extends AbsoluteLayout
                            || (msg.arg1 == MotionEvent.ACTION_MOVE
                            || (msg.arg1 == MotionEvent.ACTION_MOVE
                            && mPreventDefault == PREVENT_DEFAULT_NO_FROM_TOUCH_DOWN)) {
                            && mPreventDefault == PREVENT_DEFAULT_NO_FROM_TOUCH_DOWN)) {
                        cancelWebCoreTouchEvent(
                        cancelWebCoreTouchEvent(
                                viewToContentX((int) mLastTouchX + mScrollX),
                                viewToContentX(mLastTouchX + mScrollX),
                                viewToContentY((int) mLastTouchY + mScrollY),
                                viewToContentY(mLastTouchY + mScrollY),
                                true);
                                true);
                    }
                    }
                    break;
                    break;
@@ -7104,8 +7095,8 @@ public class WebView extends AbsoluteLayout
                        ted.mIds = new int[1];
                        ted.mIds = new int[1];
                        ted.mIds[0] = 0;
                        ted.mIds[0] = 0;
                        ted.mPoints = new Point[1];
                        ted.mPoints = new Point[1];
                        ted.mPoints[0] = new Point(viewToContentX((int) mLastTouchX + mScrollX),
                        ted.mPoints[0] = new Point(viewToContentX(mLastTouchX + mScrollX),
                                                   viewToContentY((int) mLastTouchY + mScrollY));
                                                   viewToContentY(mLastTouchY + mScrollY));
                        // metaState for long press is tricky. Should it be the
                        // metaState for long press is tricky. Should it be the
                        // state when the press started or when the press was
                        // state when the press started or when the press was
                        // released? Or some intermediary key state? For
                        // released? Or some intermediary key state? For