From: Julien Dramaix Date: Wed, 9 May 2012 16:09:12 +0000 (+0000) Subject: fix problem for supporting touch events in iOS. X-Git-Tag: release-1.3.2~88 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6339cffd5a672bbfd544831962a7cf9575eb080c;p=gwtquery.git fix problem for supporting touch events in iOS. touches array seems to be shared between events. Keep in memory the original touch point. --- diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/MousePlugin.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/MousePlugin.java index 8f73c250..cfc23677 100755 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/MousePlugin.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/MousePlugin.java @@ -20,6 +20,8 @@ import com.google.gwt.query.client.Function; import com.google.gwt.query.client.GQuery; import com.google.gwt.query.client.plugins.events.GqEvent; import com.google.gwt.user.client.Event; +import com.google.gwt.user.client.ui.Label; +import com.google.gwt.user.client.ui.RootPanel; /** * Base class for all plug-in that need to handle some mouse interactions. @@ -33,6 +35,8 @@ public abstract class MousePlugin extends UiPlugin { private MouseOptions options; private boolean preventClickEvent = false; private boolean touchSupported = false; + private int startX = -1; + private int startY = -1; protected MousePlugin(GQuery gq) { super(gq); @@ -171,6 +175,7 @@ public abstract class MousePlugin extends UiPlugin { * */ protected boolean mouseMove(Element element, GqEvent event) { + if (started) { event.getOriginalEvent().preventDefault(); return mouseDrag(element, event); @@ -208,12 +213,14 @@ public abstract class MousePlugin extends UiPlugin { * */ protected boolean mouseUp(Element element, GqEvent event) { + unbindOtherEvents(); if (started) { started = false; preventClickEvent = (event.getCurrentEventTarget() == startEvent.getCurrentEventTarget()); mouseStop(element, event); } + return true; } @@ -264,14 +271,13 @@ public abstract class MousePlugin extends UiPlugin { private boolean distanceConditionMet(GqEvent event) { int neededDistance = options.getDistance(); - int startX = getClientX(startEvent); - int startY = getClientY(startEvent); int xDistance = Math.abs(startX - getClientX(event)); int yDistance = Math.abs(startY - getClientY(event)); // in jQuery-ui we take the greater distance between x and y... not really // good ! // int mouseDistance = Math.max(xMouseDistance, yMouseDistance); // use Pythagor theorem !! + int mouseDistance = (int) Math.sqrt(xDistance * xDistance + yDistance * yDistance); return mouseDistance >= neededDistance; } @@ -301,6 +307,8 @@ public abstract class MousePlugin extends UiPlugin { private void reset(GqEvent nativeEvent) { this.startEvent = nativeEvent; + this.startX = getClientX(nativeEvent); + this.startY = getClientY(nativeEvent); this.mouseUpDuration = new Duration(); }