Skip to content

Commit b123e96

Browse files
jreckAndroid (Google) Code Review
authored andcommitted
Merge "Initial NavCache removal support"
2 parents 1f7b23d + 4eda105 commit b123e96

File tree

3 files changed

+47
-50
lines changed

3 files changed

+47
-50
lines changed

core/java/android/webkit/WebSettings.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -534,21 +534,6 @@ public boolean getNavDump() {
534534
return mNavDump;
535535
}
536536

537-
/**
538-
* If WebView only supports touch, a different navigation model will be
539-
* applied. Otherwise, the navigation to support both touch and keyboard
540-
* will be used.
541-
* @hide
542-
public void setSupportTouchOnly(boolean touchOnly) {
543-
mSupportTounchOnly = touchOnly;
544-
}
545-
*/
546-
547-
boolean supportTouchOnly() {
548-
// for debug only, use mLightTouchEnabled for mSupportTounchOnly
549-
return mLightTouchEnabled;
550-
}
551-
552537
/**
553538
* Set whether the WebView supports zoom
554539
*/

core/java/android/webkit/WebView.java

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
import android.webkit.WebViewCore.EventHub;
9393
import android.webkit.WebViewCore.TouchEventData;
9494
import android.webkit.WebViewCore.TouchHighlightData;
95+
import android.webkit.WebViewCore.WebKitHitTest;
9596
import android.widget.AbsoluteLayout;
9697
import android.widget.Adapter;
9798
import 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
}

core/java/android/webkit/WebViewCore.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,12 @@ static class TouchHighlightData {
860860
Rect mNativeLayerRect;
861861
}
862862

863+
static class WebKitHitTest {
864+
int mType;
865+
String mExtra;
866+
Rect[] mTouchRects;
867+
}
868+
863869
static class AutoFillData {
864870
public AutoFillData() {
865871
mQueryId = WebTextView.FORM_NOT_AUTOFILLABLE;
@@ -1072,7 +1078,7 @@ public class EventHub {
10721078
static final int ADD_PACKAGE_NAME = 185;
10731079
static final int REMOVE_PACKAGE_NAME = 186;
10741080

1075-
static final int GET_TOUCH_HIGHLIGHT_RECTS = 187;
1081+
static final int HIT_TEST = 187;
10761082

10771083
// accessibility support
10781084
static final int MODIFY_SELECTION = 190;
@@ -1550,7 +1556,7 @@ public void handleMessage(Message msg) {
15501556
break;
15511557

15521558
case MODIFY_SELECTION:
1553-
String modifiedSelectionString =
1559+
String modifiedSelectionString =
15541560
nativeModifySelection(mNativeClass, msg.arg1,
15551561
msg.arg2);
15561562
mWebView.mPrivateHandler.obtainMessage(WebView.SELECTION_STRING_CHANGED,
@@ -1671,16 +1677,16 @@ public void handleMessage(Message msg) {
16711677
(Set<String>) msg.obj);
16721678
break;
16731679

1674-
case GET_TOUCH_HIGHLIGHT_RECTS:
1680+
case HIT_TEST:
16751681
TouchHighlightData d = (TouchHighlightData) msg.obj;
16761682
if (d.mNativeLayer != 0) {
16771683
nativeScrollLayer(mNativeClass,
16781684
d.mNativeLayer, d.mNativeLayerRect);
16791685
}
1680-
ArrayList<Rect> rects = nativeGetTouchHighlightRects
1681-
(mNativeClass, d.mX, d.mY, d.mSlop);
1686+
WebKitHitTest hit = nativeHitTest(mNativeClass,
1687+
d.mX, d.mY, d.mSlop);
16821688
mWebView.mPrivateHandler.obtainMessage(
1683-
WebView.SET_TOUCH_HIGHLIGHT_RECTS, rects)
1689+
WebView.HIT_TEST_RESULT, hit)
16841690
.sendToTarget();
16851691
break;
16861692

@@ -2335,9 +2341,9 @@ private void didFirstLayout(boolean standardLoad) {
23352341
}
23362342

23372343
// remove the touch highlight when moving to a new page
2338-
if (WebView.USE_WEBKIT_RINGS || getSettings().supportTouchOnly()) {
2344+
if (WebView.sDisableNavcache) {
23392345
mWebView.mPrivateHandler.sendEmptyMessage(
2340-
WebView.SET_TOUCH_HIGHLIGHT_RECTS);
2346+
WebView.HIT_TEST_RESULT);
23412347
}
23422348

23432349
// reset the scroll position, the restored offset and scales
@@ -2927,8 +2933,7 @@ protected DeviceOrientationService getDeviceOrientationService() {
29272933
private native boolean nativeValidNodeAndBounds(int nativeClass, int frame,
29282934
int node, Rect bounds);
29292935

2930-
private native ArrayList<Rect> nativeGetTouchHighlightRects(int nativeClass,
2931-
int x, int y, int slop);
2936+
private native WebKitHitTest nativeHitTest(int nativeClass, int x, int y, int slop);
29322937

29332938
private native void nativeAutoFillForm(int nativeClass, int queryId);
29342939
private native void nativeScrollLayer(int nativeClass, int layer, Rect rect);

0 commit comments

Comments
 (0)