Merge "Make WebView track focal points more accurately" into jb-mr1-dev
This commit is contained in:
@@ -1346,20 +1346,40 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
|
|||||||
|
|
||||||
private void onHandleUiTouchEvent(MotionEvent ev) {
|
private void onHandleUiTouchEvent(MotionEvent ev) {
|
||||||
final ScaleGestureDetector detector =
|
final ScaleGestureDetector detector =
|
||||||
mZoomManager.getMultiTouchGestureDetector();
|
mZoomManager.getScaleGestureDetector();
|
||||||
|
|
||||||
float x = ev.getX();
|
int action = ev.getActionMasked();
|
||||||
float y = ev.getY();
|
final boolean pointerUp = action == MotionEvent.ACTION_POINTER_UP;
|
||||||
|
final boolean configChanged =
|
||||||
|
action == MotionEvent.ACTION_POINTER_UP ||
|
||||||
|
action == MotionEvent.ACTION_POINTER_DOWN;
|
||||||
|
final int skipIndex = pointerUp ? ev.getActionIndex() : -1;
|
||||||
|
|
||||||
|
// Determine focal point
|
||||||
|
float sumX = 0, sumY = 0;
|
||||||
|
final int count = ev.getPointerCount();
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
if (skipIndex == i) continue;
|
||||||
|
sumX += ev.getX(i);
|
||||||
|
sumY += ev.getY(i);
|
||||||
|
}
|
||||||
|
final int div = pointerUp ? count - 1 : count;
|
||||||
|
float x = sumX / div;
|
||||||
|
float y = sumY / div;
|
||||||
|
|
||||||
|
if (configChanged) {
|
||||||
|
mLastTouchX = Math.round(x);
|
||||||
|
mLastTouchY = Math.round(y);
|
||||||
|
mLastTouchTime = ev.getEventTime();
|
||||||
|
mWebView.cancelLongPress();
|
||||||
|
mPrivateHandler.removeMessages(SWITCH_TO_LONGPRESS);
|
||||||
|
}
|
||||||
|
|
||||||
if (detector != null) {
|
if (detector != null) {
|
||||||
detector.onTouchEvent(ev);
|
detector.onTouchEvent(ev);
|
||||||
if (detector.isInProgress()) {
|
if (detector.isInProgress()) {
|
||||||
mLastTouchTime = ev.getEventTime();
|
mLastTouchTime = ev.getEventTime();
|
||||||
x = detector.getFocusX();
|
|
||||||
y = detector.getFocusY();
|
|
||||||
|
|
||||||
mWebView.cancelLongPress();
|
|
||||||
mPrivateHandler.removeMessages(SWITCH_TO_LONGPRESS);
|
|
||||||
if (!mZoomManager.supportsPanDuringZoom()) {
|
if (!mZoomManager.supportsPanDuringZoom()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1370,14 +1390,9 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int action = ev.getActionMasked();
|
|
||||||
if (action == MotionEvent.ACTION_POINTER_DOWN) {
|
if (action == MotionEvent.ACTION_POINTER_DOWN) {
|
||||||
cancelTouch();
|
cancelTouch();
|
||||||
action = MotionEvent.ACTION_DOWN;
|
action = MotionEvent.ACTION_DOWN;
|
||||||
} else if (action == MotionEvent.ACTION_POINTER_UP) {
|
|
||||||
// set mLastTouchX/Y to the remaining points for multi-touch.
|
|
||||||
mLastTouchX = Math.round(x);
|
|
||||||
mLastTouchY = Math.round(y);
|
|
||||||
} else if (action == MotionEvent.ACTION_MOVE) {
|
} else if (action == MotionEvent.ACTION_MOVE) {
|
||||||
// negative x or y indicate it is on the edge, skip it.
|
// negative x or y indicate it is on the edge, skip it.
|
||||||
if (x < 0 || y < 0) {
|
if (x < 0 || y < 0) {
|
||||||
@@ -4385,7 +4400,7 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
|
|||||||
|
|
||||||
// A multi-finger gesture can look like a long press; make sure we don't take
|
// A multi-finger gesture can look like a long press; make sure we don't take
|
||||||
// long press actions if we're scaling.
|
// long press actions if we're scaling.
|
||||||
final ScaleGestureDetector detector = mZoomManager.getMultiTouchGestureDetector();
|
final ScaleGestureDetector detector = mZoomManager.getScaleGestureDetector();
|
||||||
if (detector != null && detector.isInProgress()) {
|
if (detector != null && detector.isInProgress()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -5823,7 +5838,7 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
|
|||||||
* and the middle point for multi-touch.
|
* and the middle point for multi-touch.
|
||||||
*/
|
*/
|
||||||
private void handleTouchEventCommon(MotionEvent event, int action, int x, int y) {
|
private void handleTouchEventCommon(MotionEvent event, int action, int x, int y) {
|
||||||
ScaleGestureDetector detector = mZoomManager.getMultiTouchGestureDetector();
|
ScaleGestureDetector detector = mZoomManager.getScaleGestureDetector();
|
||||||
|
|
||||||
long eventTime = event.getEventTime();
|
long eventTime = event.getEventTime();
|
||||||
|
|
||||||
|
|||||||
@@ -204,7 +204,7 @@ class ZoomManager {
|
|||||||
*/
|
*/
|
||||||
private boolean mAllowPanAndScale;
|
private boolean mAllowPanAndScale;
|
||||||
|
|
||||||
// use the framework's ScaleGestureDetector to handle multi-touch
|
// use the framework's ScaleGestureDetector to handle scaling gestures
|
||||||
private ScaleGestureDetector mScaleDetector;
|
private ScaleGestureDetector mScaleDetector;
|
||||||
private boolean mPinchToZoomAnimating = false;
|
private boolean mPinchToZoomAnimating = false;
|
||||||
|
|
||||||
@@ -768,7 +768,7 @@ class ZoomManager {
|
|||||||
return isZoomAnimating();
|
return isZoomAnimating();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ScaleGestureDetector getMultiTouchGestureDetector() {
|
public ScaleGestureDetector getScaleGestureDetector() {
|
||||||
return mScaleDetector;
|
return mScaleDetector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user