9292import android .webkit .WebViewCore .EventHub ;
9393import android .webkit .WebViewCore .TouchEventData ;
9494import android .webkit .WebViewCore .TouchHighlightData ;
95+ import android .webkit .WebViewCore .WebKitHitTest ;
9596import android .widget .AbsoluteLayout ;
9697import android .widget .Adapter ;
9798import android .widget .AdapterView ;
@@ -699,7 +700,7 @@ public void onTrimMemory(int level) {
699700 private Drawable mSelectHandleLeft ;
700701 private Drawable mSelectHandleRight ;
701702
702- static final boolean USE_WEBKIT_RINGS = false ;
703+ static boolean sDisableNavcache = false ;
703704 // the color used to highlight the touch rectangles
704705 private static final int HIGHLIGHT_COLOR = 0x6633b5e5 ;
705706 // the round corner for the highlight path
@@ -775,7 +776,7 @@ public void onTrimMemory(int level) {
775776 static final int REQUEST_KEYBOARD_WITH_SELECTION_MSG_ID = 128 ;
776777 static final int SET_SCROLLBAR_MODES = 129 ;
777778 static final int SELECTION_STRING_CHANGED = 130 ;
778- static final int SET_TOUCH_HIGHLIGHT_RECTS = 131 ;
779+ static final int HIT_TEST_RESULT = 131 ;
779780 static final int SAVE_WEBARCHIVE_FINISHED = 132 ;
780781
781782 static final int SET_AUTOFILLABLE = 133 ;
@@ -788,7 +789,7 @@ public void onTrimMemory(int level) {
788789 static final int UPDATE_ZOOM_DENSITY = 139 ;
789790
790791 private static final int FIRST_PACKAGE_MSG_ID = SCROLL_TO_MSG_ID ;
791- private static final int LAST_PACKAGE_MSG_ID = SET_TOUCH_HIGHLIGHT_RECTS ;
792+ private static final int LAST_PACKAGE_MSG_ID = HIT_TEST_RESULT ;
792793
793794 static final String [] HandlerPrivateDebugString = {
794795 "REMEMBER_PASSWORD" , // = 1;
@@ -1311,6 +1312,7 @@ void updateMultiTouchSupport(Context context) {
13111312
13121313 private void init () {
13131314 OnTrimMemoryListener .init (getContext ());
1315+ sDisableNavcache = nativeDisableNavcache ();
13141316
13151317 setWillNotDraw (false );
13161318 setFocusable (true );
@@ -2618,8 +2620,8 @@ public HitTestResult getHitTestResult() {
26182620 }
26192621
26202622 private HitTestResult hitTestResult (HitTestResult fallback ) {
2621- if (mNativeClass == 0 ) {
2622- return null ;
2623+ if (mNativeClass == 0 || sDisableNavcache ) {
2624+ return fallback ;
26232625 }
26242626
26252627 HitTestResult result = new HitTestResult ();
@@ -4376,7 +4378,7 @@ protected void onDraw(Canvas canvas) {
43764378 || mTouchMode == TOUCH_SHORTPRESS_MODE
43774379 || mTouchMode == TOUCH_DONE_MODE );
43784380 boolean drawNativeRings = !drawJavaRings ;
4379- if (USE_WEBKIT_RINGS ) {
4381+ if (sDisableNavcache ) {
43804382 drawNativeRings = !drawJavaRings && !isInTouchMode ();
43814383 }
43824384 drawContent (canvas , drawNativeRings );
@@ -4431,8 +4433,8 @@ protected void onDraw(Canvas canvas) {
44314433 }
44324434
44334435 private void removeTouchHighlight () {
4434- mWebViewCore .removeMessages (EventHub .GET_TOUCH_HIGHLIGHT_RECTS );
4435- mPrivateHandler .removeMessages (SET_TOUCH_HIGHLIGHT_RECTS );
4436+ mWebViewCore .removeMessages (EventHub .HIT_TEST );
4437+ mPrivateHandler .removeMessages (HIT_TEST_RESULT );
44364438 setTouchHighlightRects (null );
44374439 }
44384440
@@ -6198,7 +6200,7 @@ private boolean handleTouchEventCommon(MotionEvent ev, int action, int x, int y)
61986200 nativeSetIsScrolling (false );
61996201 } else if (mPrivateHandler .hasMessages (RELEASE_SINGLE_TAP )) {
62006202 mPrivateHandler .removeMessages (RELEASE_SINGLE_TAP );
6201- if (USE_WEBKIT_RINGS || getSettings (). supportTouchOnly () ) {
6203+ if (sDisableNavcache ) {
62026204 removeTouchHighlight ();
62036205 }
62046206 if (deltaX * deltaX + deltaY * deltaY < mDoubleTapSlopSquare ) {
@@ -6222,7 +6224,7 @@ private boolean handleTouchEventCommon(MotionEvent ev, int action, int x, int y)
62226224 mWebViewCore .sendMessage (
62236225 EventHub .UPDATE_FRAME_CACHE_IF_LOADING );
62246226 }
6225- if (USE_WEBKIT_RINGS || getSettings (). supportTouchOnly () ) {
6227+ if (sDisableNavcache ) {
62266228 TouchHighlightData data = new TouchHighlightData ();
62276229 data .mX = contentX ;
62286230 data .mY = contentY ;
@@ -6234,7 +6236,7 @@ private boolean handleTouchEventCommon(MotionEvent ev, int action, int x, int y)
62346236 if (!mBlockWebkitViewMessages ) {
62356237 mTouchHighlightRequested = System .currentTimeMillis ();
62366238 mWebViewCore .sendMessageAtFrontOfQueue (
6237- EventHub .GET_TOUCH_HIGHLIGHT_RECTS , data );
6239+ EventHub .HIT_TEST , data );
62386240 }
62396241 if (DEBUG_TOUCH_HIGHLIGHT ) {
62406242 if (getSettings ().getNavDump ()) {
@@ -6322,7 +6324,7 @@ public void run() {
63226324 if (mTouchMode == TOUCH_DOUBLE_TAP_MODE ) {
63236325 mTouchMode = TOUCH_INIT_MODE ;
63246326 }
6325- if (USE_WEBKIT_RINGS || getSettings (). supportTouchOnly () ) {
6327+ if (sDisableNavcache ) {
63266328 removeTouchHighlight ();
63276329 }
63286330 }
@@ -6924,7 +6926,7 @@ private void cancelTouch() {
69246926 mPrivateHandler .removeMessages (SWITCH_TO_LONGPRESS );
69256927 mPrivateHandler .removeMessages (DRAG_HELD_MOTIONLESS );
69266928 mPrivateHandler .removeMessages (AWAKEN_SCROLL_BARS );
6927- if (USE_WEBKIT_RINGS || getSettings (). supportTouchOnly () ) {
6929+ if (sDisableNavcache ) {
69286930 removeTouchHighlight ();
69296931 }
69306932 mHeldMotionless = MOTIONLESS_TRUE ;
@@ -7481,7 +7483,7 @@ public boolean zoomOut() {
74817483 * and calls showCursorTimed on the native side
74827484 */
74837485 private void updateSelection () {
7484- if (mNativeClass == 0 ) {
7486+ if (mNativeClass == 0 || sDisableNavcache ) {
74857487 return ;
74867488 }
74877489 mPrivateHandler .removeMessages (UPDATE_SELECTION );
@@ -7589,7 +7591,7 @@ private void doShortPress() {
75897591 int contentX = viewToContentX (mLastTouchX + mScrollX );
75907592 int contentY = viewToContentY (mLastTouchY + mScrollY );
75917593 int slop = viewToContentDimension (mNavSlop );
7592- if (USE_WEBKIT_RINGS && !mTouchHighlightRegion .isEmpty ()) {
7594+ if (sDisableNavcache && !mTouchHighlightRegion .isEmpty ()) {
75937595 // set mTouchHighlightRequested to 0 to cause an immediate
75947596 // drawing of the touch rings
75957597 mTouchHighlightRequested = 0 ;
@@ -7601,8 +7603,7 @@ public void run() {
76017603 }
76027604 }, ViewConfiguration .getPressedStateDuration ());
76037605 }
7604- if (getSettings ().supportTouchOnly ()) {
7605- removeTouchHighlight ();
7606+ if (sDisableNavcache ) {
76067607 WebViewCore .TouchUpData touchUpData = new WebViewCore .TouchUpData ();
76077608 // use "0" as generation id to inform WebKit to use the same x/y as
76087609 // it used when processing GET_TOUCH_HIGHLIGHT_RECTS
@@ -8487,9 +8488,8 @@ public void handleMessage(Message msg) {
84878488 break ;
84888489 }
84898490 case SWITCH_TO_SHORTPRESS : {
8490- mInitialHitTestResult = null ; // set by updateSelection()
84918491 if (mTouchMode == TOUCH_INIT_MODE ) {
8492- if (!getSettings (). supportTouchOnly ()
8492+ if (!sDisableNavcache
84938493 && mPreventDefault != PREVENT_DEFAULT_YES ) {
84948494 mTouchMode = TOUCH_SHORTPRESS_START_MODE ;
84958495 updateSelection ();
@@ -8504,7 +8504,7 @@ public void handleMessage(Message msg) {
85048504 break ;
85058505 }
85068506 case SWITCH_TO_LONGPRESS : {
8507- if (USE_WEBKIT_RINGS || getSettings (). supportTouchOnly () ) {
8507+ if (sDisableNavcache ) {
85088508 removeTouchHighlight ();
85098509 }
85108510 if (inFullScreenMode () || mDeferTouchProcess ) {
@@ -8835,10 +8835,16 @@ public void handleMessage(Message msg) {
88358835 }
88368836 break ;
88378837
8838- case SET_TOUCH_HIGHLIGHT_RECTS :
8839- @ SuppressWarnings ("unchecked" )
8840- ArrayList <Rect > rects = (ArrayList <Rect >) msg .obj ;
8841- setTouchHighlightRects (rects );
8838+ case HIT_TEST_RESULT :
8839+ WebKitHitTest hit = (WebKitHitTest ) msg .obj ;
8840+ setTouchHighlightRects (hit != null ? hit .mTouchRects : null );
8841+ if (hit == null ) {
8842+ mInitialHitTestResult = null ;
8843+ } else {
8844+ mInitialHitTestResult = new HitTestResult ();
8845+ mInitialHitTestResult .mType = hit .mType ;
8846+ mInitialHitTestResult .mExtra = hit .mExtra ;
8847+ }
88428848 break ;
88438849
88448850 case SAVE_WEBARCHIVE_FINISHED :
@@ -8875,7 +8881,7 @@ public void handleMessage(Message msg) {
88758881 }
88768882 }
88778883
8878- private void setTouchHighlightRects (ArrayList < Rect > rects ) {
8884+ private void setTouchHighlightRects (Rect [] rects ) {
88798885 invalidate (mTouchHighlightRegion .getBounds ());
88808886 mTouchHighlightRegion .setEmpty ();
88818887 if (rects != null ) {
@@ -9793,4 +9799,5 @@ private native int nativeScrollableLayer(int x, int y, Rect scrollRect,
97939799 */
97949800 private static native void nativeOnTrimMemory (int level );
97959801 private static native void nativeSetPauseDrawing (int instance , boolean pause );
9802+ private static native boolean nativeDisableNavcache ();
97969803}
0 commit comments