Skip to content

Commit 4289b49

Browse files
adampAndroid Git Automerger
authored andcommitted
am 9f3b0bf: DO NOT MERGE - Make WebView track focal points more accurately
* commit '9f3b0bfd0b1d8876c96036a303b3ff72df0e8ad0': DO NOT MERGE - Make WebView track focal points more accurately
2 parents 52da9fa + 9f3b0bf commit 4289b49

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

core/java/android/webkit/WebViewClassic.java

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,20 +1340,40 @@ private void onHandleUiEvent(MotionEvent event, int eventType, int flags) {
13401340

13411341
private void onHandleUiTouchEvent(MotionEvent ev) {
13421342
final ScaleGestureDetector detector =
1343-
mZoomManager.getMultiTouchGestureDetector();
1343+
mZoomManager.getScaleGestureDetector();
13441344

1345-
float x = ev.getX();
1346-
float y = ev.getY();
1345+
int action = ev.getActionMasked();
1346+
final boolean pointerUp = action == MotionEvent.ACTION_POINTER_UP;
1347+
final boolean configChanged =
1348+
action == MotionEvent.ACTION_POINTER_UP ||
1349+
action == MotionEvent.ACTION_POINTER_DOWN;
1350+
final int skipIndex = pointerUp ? ev.getActionIndex() : -1;
1351+
1352+
// Determine focal point
1353+
float sumX = 0, sumY = 0;
1354+
final int count = ev.getPointerCount();
1355+
for (int i = 0; i < count; i++) {
1356+
if (skipIndex == i) continue;
1357+
sumX += ev.getX(i);
1358+
sumY += ev.getY(i);
1359+
}
1360+
final int div = pointerUp ? count - 1 : count;
1361+
float x = sumX / div;
1362+
float y = sumY / div;
1363+
1364+
if (configChanged) {
1365+
mLastTouchX = Math.round(x);
1366+
mLastTouchY = Math.round(y);
1367+
mLastTouchTime = ev.getEventTime();
1368+
mWebView.cancelLongPress();
1369+
mPrivateHandler.removeMessages(SWITCH_TO_LONGPRESS);
1370+
}
13471371

13481372
if (detector != null) {
13491373
detector.onTouchEvent(ev);
13501374
if (detector.isInProgress()) {
13511375
mLastTouchTime = ev.getEventTime();
1352-
x = detector.getFocusX();
1353-
y = detector.getFocusY();
13541376

1355-
mWebView.cancelLongPress();
1356-
mPrivateHandler.removeMessages(SWITCH_TO_LONGPRESS);
13571377
if (!mZoomManager.supportsPanDuringZoom()) {
13581378
return;
13591379
}
@@ -1364,14 +1384,9 @@ private void onHandleUiTouchEvent(MotionEvent ev) {
13641384
}
13651385
}
13661386

1367-
int action = ev.getActionMasked();
13681387
if (action == MotionEvent.ACTION_POINTER_DOWN) {
13691388
cancelTouch();
13701389
action = MotionEvent.ACTION_DOWN;
1371-
} else if (action == MotionEvent.ACTION_POINTER_UP) {
1372-
// set mLastTouchX/Y to the remaining points for multi-touch.
1373-
mLastTouchX = Math.round(x);
1374-
mLastTouchY = Math.round(y);
13751390
} else if (action == MotionEvent.ACTION_MOVE) {
13761391
// negative x or y indicate it is on the edge, skip it.
13771392
if (x < 0 || y < 0) {
@@ -4357,7 +4372,7 @@ public boolean performLongClick() {
43574372

43584373
// A multi-finger gesture can look like a long press; make sure we don't take
43594374
// long press actions if we're scaling.
4360-
final ScaleGestureDetector detector = mZoomManager.getMultiTouchGestureDetector();
4375+
final ScaleGestureDetector detector = mZoomManager.getScaleGestureDetector();
43614376
if (detector != null && detector.isInProgress()) {
43624377
return false;
43634378
}
@@ -5764,7 +5779,7 @@ private float calculateDragAngle(int dx, int dy) {
57645779
* and the middle point for multi-touch.
57655780
*/
57665781
private void handleTouchEventCommon(MotionEvent event, int action, int x, int y) {
5767-
ScaleGestureDetector detector = mZoomManager.getMultiTouchGestureDetector();
5782+
ScaleGestureDetector detector = mZoomManager.getScaleGestureDetector();
57685783

57695784
long eventTime = event.getEventTime();
57705785

core/java/android/webkit/ZoomManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ class ZoomManager {
204204
*/
205205
private boolean mAllowPanAndScale;
206206

207-
// use the framework's ScaleGestureDetector to handle multi-touch
207+
// use the framework's ScaleGestureDetector to handle scaling gestures
208208
private ScaleGestureDetector mScaleDetector;
209209
private boolean mPinchToZoomAnimating = false;
210210

@@ -768,7 +768,7 @@ public boolean isPreventingWebkitUpdates() {
768768
return isZoomAnimating();
769769
}
770770

771-
public ScaleGestureDetector getMultiTouchGestureDetector() {
771+
public ScaleGestureDetector getScaleGestureDetector() {
772772
return mScaleDetector;
773773
}
774774

0 commit comments

Comments
 (0)