@@ -1346,20 +1346,40 @@ private void onHandleUiEvent(MotionEvent event, int eventType, int flags) {
13461346
13471347 private void onHandleUiTouchEvent (MotionEvent ev ) {
13481348 final ScaleGestureDetector detector =
1349- mZoomManager .getMultiTouchGestureDetector ();
1349+ mZoomManager .getScaleGestureDetector ();
13501350
1351- float x = ev .getX ();
1352- float y = ev .getY ();
1351+ int action = ev .getActionMasked ();
1352+ final boolean pointerUp = action == MotionEvent .ACTION_POINTER_UP ;
1353+ final boolean configChanged =
1354+ action == MotionEvent .ACTION_POINTER_UP ||
1355+ action == MotionEvent .ACTION_POINTER_DOWN ;
1356+ final int skipIndex = pointerUp ? ev .getActionIndex () : -1 ;
1357+
1358+ // Determine focal point
1359+ float sumX = 0 , sumY = 0 ;
1360+ final int count = ev .getPointerCount ();
1361+ for (int i = 0 ; i < count ; i ++) {
1362+ if (skipIndex == i ) continue ;
1363+ sumX += ev .getX (i );
1364+ sumY += ev .getY (i );
1365+ }
1366+ final int div = pointerUp ? count - 1 : count ;
1367+ float x = sumX / div ;
1368+ float y = sumY / div ;
1369+
1370+ if (configChanged ) {
1371+ mLastTouchX = Math .round (x );
1372+ mLastTouchY = Math .round (y );
1373+ mLastTouchTime = ev .getEventTime ();
1374+ mWebView .cancelLongPress ();
1375+ mPrivateHandler .removeMessages (SWITCH_TO_LONGPRESS );
1376+ }
13531377
13541378 if (detector != null ) {
13551379 detector .onTouchEvent (ev );
13561380 if (detector .isInProgress ()) {
13571381 mLastTouchTime = ev .getEventTime ();
1358- x = detector .getFocusX ();
1359- y = detector .getFocusY ();
13601382
1361- mWebView .cancelLongPress ();
1362- mPrivateHandler .removeMessages (SWITCH_TO_LONGPRESS );
13631383 if (!mZoomManager .supportsPanDuringZoom ()) {
13641384 return ;
13651385 }
@@ -1370,14 +1390,9 @@ private void onHandleUiTouchEvent(MotionEvent ev) {
13701390 }
13711391 }
13721392
1373- int action = ev .getActionMasked ();
13741393 if (action == MotionEvent .ACTION_POINTER_DOWN ) {
13751394 cancelTouch ();
13761395 action = MotionEvent .ACTION_DOWN ;
1377- } else if (action == MotionEvent .ACTION_POINTER_UP ) {
1378- // set mLastTouchX/Y to the remaining points for multi-touch.
1379- mLastTouchX = Math .round (x );
1380- mLastTouchY = Math .round (y );
13811396 } else if (action == MotionEvent .ACTION_MOVE ) {
13821397 // negative x or y indicate it is on the edge, skip it.
13831398 if (x < 0 || y < 0 ) {
@@ -4385,7 +4400,7 @@ public boolean performLongClick() {
43854400
43864401 // A multi-finger gesture can look like a long press; make sure we don't take
43874402 // long press actions if we're scaling.
4388- final ScaleGestureDetector detector = mZoomManager .getMultiTouchGestureDetector ();
4403+ final ScaleGestureDetector detector = mZoomManager .getScaleGestureDetector ();
43894404 if (detector != null && detector .isInProgress ()) {
43904405 return false ;
43914406 }
@@ -5823,7 +5838,7 @@ private float calculateDragAngle(int dx, int dy) {
58235838 * and the middle point for multi-touch.
58245839 */
58255840 private void handleTouchEventCommon (MotionEvent event , int action , int x , int y ) {
5826- ScaleGestureDetector detector = mZoomManager .getMultiTouchGestureDetector ();
5841+ ScaleGestureDetector detector = mZoomManager .getScaleGestureDetector ();
58275842
58285843 long eventTime = event .getEventTime ();
58295844
0 commit comments