diff options
author | Julien Dramaix <julien.dramaix@gmail.com> | 2012-05-09 16:09:12 +0000 |
---|---|---|
committer | Julien Dramaix <julien.dramaix@gmail.com> | 2012-05-09 16:09:12 +0000 |
commit | 6339cffd5a672bbfd544831962a7cf9575eb080c (patch) | |
tree | 6a3b07453506e7634868b212ecd6072247eb36ed | |
parent | d1fb5c77ba944e286e2ac9e061d689bfde02017d (diff) | |
download | gwtquery-6339cffd5a672bbfd544831962a7cf9575eb080c.tar.gz gwtquery-6339cffd5a672bbfd544831962a7cf9575eb080c.zip |
fix problem for supporting touch events in iOS.
touches array seems to be shared between events. Keep in memory the original touch point.
-rwxr-xr-x | gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/MousePlugin.java | 12 |
1 files changed, 10 insertions, 2 deletions
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();
}
|