1 /* 2 * Copyright 2010 Daniel Kurka 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14 package com.googlecode.mgwt.dom.client.event.mouse; 15 16 import com.google.gwt.core.client.JsArray; 17 import com.google.gwt.dom.client.NativeEvent; 18 import com.google.gwt.event.dom.client.MouseUpEvent; 19 import com.googlecode.mgwt.collection.client.JsLightArray; 20 import com.googlecode.mgwt.collection.shared.LightArray; 21 import com.googlecode.mgwt.dom.client.event.touch.JsTouch; 22 import com.googlecode.mgwt.dom.client.event.touch.Touch; 23 import com.googlecode.mgwt.dom.client.event.touch.TouchEndEvent; 24 25 /** 26 * A simulated TouchEndEvent is really a mouseup event. This is used mostly in dev mode and for 27 * blackberry devices to handle them equally to real touch devices 28 * 29 * @author Daniel Kurka 30 * @version $Id: $ 31 */ 32 public class SimulatedTouchEndEvent extends TouchEndEvent { 33 34 private final int x; 35 private final int y; 36 private int x_start; 37 private int y_start; 38 private boolean multiTouch; 39 40 /** 41 * Construct a simluated TouchEndEvent from a {@link MouseUpEvent} 42 * 43 * @param mouseUpEvent the data for the simulated event; 44 * @param multiTouch 45 */ 46 public SimulatedTouchEndEvent(MouseUpEvent mouseUpEvent, boolean multiTouch) { 47 x = mouseUpEvent.getClientX(); 48 y = mouseUpEvent.getClientY(); 49 this.multiTouch = multiTouch; 50 if (multiTouch) { 51 int[] start = MultiTouchMouseEmulator.getTouchStart(); 52 x_start = start[0]; 53 y_start = start[1]; 54 } 55 setNativeEvent(mouseUpEvent.getNativeEvent()); 56 setSource(mouseUpEvent.getSource()); 57 } 58 59 @Override 60 public LightArray<Touch> getTouches() { 61 return new JsLightArray<Touch>(touches(getNativeEvent())); 62 } 63 64 @Override 65 public LightArray<Touch> getChangedTouches() { 66 return new JsLightArray<Touch>(changedTouches(getNativeEvent())); 67 } 68 69 /** {@inheritDoc} */ 70 @Override 71 protected native JsArray<JsTouch> touches(NativeEvent nativeEvent) /*-{ 72 var toucharray = []; 73 if (this.@com.googlecode.mgwt.dom.client.event.mouse.SimulatedTouchEndEvent::multiTouch) { 74 var touch_start = {}; 75 touch_start.pageX = this.@com.googlecode.mgwt.dom.client.event.mouse.SimulatedTouchEndEvent::x_start; 76 touch_start.pageY = this.@com.googlecode.mgwt.dom.client.event.mouse.SimulatedTouchEndEvent::y_start; 77 toucharray.push(touch_start); 78 } 79 80 return toucharray; 81 }-*/; 82 83 /** {@inheritDoc} */ 84 @Override 85 protected native JsArray<JsTouch> changedTouches(NativeEvent nativeEvent) /*-{ 86 87 var toucharray = []; 88 89 if (this.@com.googlecode.mgwt.dom.client.event.mouse.SimulatedTouchEndEvent::multiTouch) { 90 var touch_start = {}; 91 touch_start.pageX = this.@com.googlecode.mgwt.dom.client.event.mouse.SimulatedTouchEndEvent::x_start; 92 touch_start.pageY = this.@com.googlecode.mgwt.dom.client.event.mouse.SimulatedTouchEndEvent::y_start; 93 toucharray.push(touch_start); 94 } else { 95 var touch = {}; 96 touch.pageX = this.@com.googlecode.mgwt.dom.client.event.mouse.SimulatedTouchEndEvent::x; 97 touch.pageY = this.@com.googlecode.mgwt.dom.client.event.mouse.SimulatedTouchEndEvent::y; 98 toucharray.push(touch); 99 } 100 101 return toucharray; 102 }-*/; 103 }