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

Commit b849134c authored by Cary Clark's avatar Cary Clark
Browse files

use the original hit if the cache is killed

The nav cache may not have a cursor set if it is
rebuilt while the long press timer is running. Use
the original hit test data in this case.

bug:3198707
Change-Id: I795a3afb31de3667b3a69abbe898381912806802
parent 40c01e38
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -485,6 +485,8 @@ public class WebView extends AbsoluteLayout
    // true if onPause has been called (and not onResume)
    private boolean mIsPaused;

    private HitTestResult mInitialHitTestResult;

    /**
     * Customizable constant
     */
@@ -2102,6 +2104,10 @@ public class WebView extends AbsoluteLayout
     * HitTestResult type is set to UNKNOWN_TYPE.
     */
    public HitTestResult getHitTestResult() {
        return hitTestResult(mInitialHitTestResult);
    }

    private HitTestResult hitTestResult(HitTestResult fallback) {
        if (mNativeClass == 0) {
            return null;
        }
@@ -2129,6 +2135,16 @@ public class WebView extends AbsoluteLayout
                    }
                }
            }
        } else if (fallback != null) {
            /* If webkit causes a rebuild while the long press is in progress,
             * the cursor node may be reset, even if it is still around. This
             * uses the cursor node saved when the touch began. Since the
             * nativeImageURI below only changes the result if it is successful,
             * this uses the data beneath the touch if available or the original
             * tap data otherwise.
             */
            Log.v(LOGTAG, "hitTestResult use fallback");
            result = fallback;
        }
        int type = result.getType();
        if (type == HitTestResult.UNKNOWN_TYPE
@@ -5141,6 +5157,7 @@ public class WebView extends AbsoluteLayout
            case MotionEvent.ACTION_DOWN: {
                mPreventDefault = PREVENT_DEFAULT_NO;
                mConfirmMove = false;
                mInitialHitTestResult = null;
                if (!mScroller.isFinished()) {
                    // stop the current scroll animation, but if this is
                    // the start of a fling, allow it to add to the current
@@ -6217,6 +6234,7 @@ public class WebView extends AbsoluteLayout
        Rect rect = new Rect(contentX - mNavSlop, contentY - mNavSlop,
                contentX + mNavSlop, contentY + mNavSlop);
        nativeSelectBestAt(rect);
        mInitialHitTestResult = hitTestResult(null);
    }

    /**
@@ -6657,6 +6675,7 @@ public class WebView extends AbsoluteLayout
                    break;
                }
                case SWITCH_TO_SHORTPRESS: {
                    mInitialHitTestResult = null; // set by updateSelection()
                    if (mTouchMode == TOUCH_INIT_MODE) {
                        if (!getSettings().supportTouchOnly()
                                && mPreventDefault != PREVENT_DEFAULT_YES) {