Bug 725458 - Start touch timeout during action_down. r=mbrubeck

This commit is contained in:
Wes Johnston 2012-02-29 14:03:28 -08:00
Родитель ad70bedc53
Коммит 08f4b19f52
1 изменённых файлов: 23 добавлений и 46 удалений

Просмотреть файл

@ -111,11 +111,10 @@ public class LayerController implements Tabs.OnTabsChangedListener {
/* The time limit for pages to respond with preventDefault on touchevents /* The time limit for pages to respond with preventDefault on touchevents
* before we begin panning the page */ * before we begin panning the page */
private static final int PREVENT_DEFAULT_TIMEOUT = 200; private int mTimeout = 200;
private boolean allowDefaultActions = true; private boolean allowDefaultActions = true;
private Timer allowDefaultTimer = null; private Timer allowDefaultTimer = null;
private boolean inTouchSession = false;
private PointF initialTouchLocation = null; private PointF initialTouchLocation = null;
public LayerController(Context context) { public LayerController(Context context) {
@ -127,6 +126,9 @@ public class LayerController implements Tabs.OnTabsChangedListener {
mView = new LayerView(context, this); mView = new LayerView(context, this);
Tabs.getInstance().registerOnTabsChangedListener(this); Tabs.getInstance().registerOnTabsChangedListener(this);
ViewConfiguration vc = ViewConfiguration.get(mContext);
mTimeout = vc.getLongPressTimeout();
} }
public void onDestroy() { public void onDestroy() {
@ -390,15 +392,29 @@ public class LayerController implements Tabs.OnTabsChangedListener {
int action = event.getAction(); int action = event.getAction();
PointF point = new PointF(event.getX(), event.getY()); PointF point = new PointF(event.getX(), event.getY());
// this will only match the first touchstart in a series
if ((action & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) { if ((action & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
mView.clearEventQueue();
initialTouchLocation = point; initialTouchLocation = point;
allowDefaultActions = !mWaitForTouchListeners; allowDefaultActions = !mWaitForTouchListeners;
post(new Runnable() {
// if we have a timer, this may be a double tap,
// cancel the current timer but don't clear the event queue
if (allowDefaultTimer != null) {
allowDefaultTimer.cancel();
} else {
// if we don't have a timer, make sure we remove any old events
mView.clearEventQueue();
}
allowDefaultTimer = new Timer();
allowDefaultTimer.schedule(new TimerTask() {
public void run() { public void run() {
preventPanning(mWaitForTouchListeners); post(new Runnable() {
public void run() {
preventPanning(false);
}
});
} }
}); }, mTimeout);
} }
// After the initial touch, ignore touch moves until they exceed a minimum distance. // After the initial touch, ignore touch moves until they exceed a minimum distance.
@ -410,55 +426,16 @@ public class LayerController implements Tabs.OnTabsChangedListener {
} }
} }
// send the event to content
if (mOnTouchListener != null) if (mOnTouchListener != null)
mOnTouchListener.onTouch(mView, event); mOnTouchListener.onTouch(mView, event);
if (!mWaitForTouchListeners)
return !allowDefaultActions;
boolean createTimer = false;
switch (action & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_MOVE: {
if (!inTouchSession && allowDefaultTimer == null) {
inTouchSession = true;
createTimer = true;
}
break;
}
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP: {
// if we still have initialTouchLocation, we haven't fired any
// touchmove events. We should start the timer to wait for preventDefault
// from touchstart. If we don't hear from it we fire mouse events
if (initialTouchLocation != null)
createTimer = true;
inTouchSession = false;
}
}
if (createTimer) {
if (allowDefaultTimer != null) {
allowDefaultTimer.cancel();
}
allowDefaultTimer = new Timer();
allowDefaultTimer.schedule(new TimerTask() {
public void run() {
post(new Runnable() {
public void run() {
preventPanning(false);
}
});
}
}, PREVENT_DEFAULT_TIMEOUT);
}
return !allowDefaultActions; return !allowDefaultActions;
} }
public void preventPanning(boolean aValue) { public void preventPanning(boolean aValue) {
if (allowDefaultTimer != null) { if (allowDefaultTimer != null) {
allowDefaultTimer.cancel(); allowDefaultTimer.cancel();
allowDefaultTimer.purge();
allowDefaultTimer = null; allowDefaultTimer = null;
} }
if (aValue == allowDefaultActions) { if (aValue == allowDefaultActions) {