List of usage examples for com.google.gwt.dom.client NativeEvent getTouches
public final JsArray<Touch> getTouches()
From source file:ch.unifr.pai.twice.dragndrop.client.TouchDragNDrop.java
License:Apache License
/** * return the x position of the touch instead of the mouse * /*from w w w. j a va 2 s .c o m*/ * @see ch.unifr.pai.twice.dragndrop.client.MPDragNDrop#getX(com.google.gwt.dom.client.NativeEvent) */ @Override int getX(NativeEvent event) { if (event.getTouches().length() > 0) { Touch t = event.getTouches().get(0); return t.getClientX(); } // if(event.getTouches().length()>0){ // Touch t = event.getTouches().shift(); // return t.getClientX(); // } return 0; }
From source file:ch.unifr.pai.twice.dragndrop.client.TouchDragNDrop.java
License:Apache License
/** * return the y position of the touch instead of the mouse * // w w w .ja v a 2 s .co m * @see ch.unifr.pai.twice.dragndrop.client.MPDragNDrop#getY(com.google.gwt.dom.client.NativeEvent) */ @Override int getY(NativeEvent event) { if (event.getTouches().length() > 0) { Touch t = event.getTouches().get(0); return t.getClientY(); } // if(event.getTouches().length()>0){ // Touch t = event.getTouches().shift(); // return t.getClientY(); // } return 0; }
From source file:com.sencha.gxt.core.client.gestures.AbstractGestureRecognizer.java
License:sencha.com license
/** * Handles gesture cancel events//from w w w . j ava2 s. c om * * @param cancelEvent * @return true if the gesture is not handling the event and can allow it to be propagated, false to indicate that * it has been handled and should not be given to other handlers. Should always return true for any start * event. */ public boolean handleCancel(NativeEvent cancelEvent) { JsArray<Touch> empty = JsArray.createArray().cast(); JsArray<Touch> touches = pointerEventsSupport.isSupported() ? empty : cancelEvent.getTouches(); //list of items that we are interested in that were canceled by this dom event List<TouchData> canceledData = new ArrayList<TouchData>(interested.values()); for (int i = 0; i < touches.length(); i++) { Touch t = touches.get(i); if (interested.containsKey(t.getIdentifier())) { canceledData.remove(interested.get(t.getIdentifier())); } } for (TouchData data : canceledData) { data.setLastChange(Type.Cancel); data.setLastNativeEvent(cancelEvent); setInterest(data, false); } if (!canceledData.isEmpty()) { handlePreventDefault(cancelEvent); onCancel(canceledData); } //never stopPropagation the cancel event, same as stop return true; }
From source file:com.sencha.gxt.core.client.gestures.AbstractGestureRecognizer.java
License:sencha.com license
/** * Handles gesture end events/*w ww .ja v a 2s . c o m*/ * * @param endEvent * @return true if the gesture is not handling the event and can allow it to be propagated, false to indicate that * it has been handled and should not be given to other handlers. Should always return true for any start * event. */ public boolean handleEnd(NativeEvent endEvent) { // TODO: For pointers, it may not be as easy to determine what current touches are on the surface JsArray<Touch> empty = JsArray.createArray().cast(); JsArray<Touch> touches = pointerEventsSupport.isSupported() ? empty : endEvent.getTouches(); //list of items that we are interested that were ended by this dom event List<TouchData> endedData = new ArrayList<TouchData>(interested.values()); for (int i = 0; i < touches.length(); i++) { Touch t = touches.get(i); if (interested.containsKey(t.getIdentifier())) { endedData.remove(interested.get(t.getIdentifier())); } } for (TouchData data : endedData) { data.setLastChange(Type.End); data.setLastNativeEvent(endEvent); setInterest(data, false); } if (!endedData.isEmpty()) { handlePreventDefault(endEvent); onEnd(endedData); } return true; }
From source file:com.vaadin.client.ui.TouchScrollDelegate.java
License:Apache License
private void doTouchStart(NativeEvent nativeEvent) { if (transitionOn) { momentum.cancel();/*w w w . ja v a 2s . co m*/ } Touch touch = nativeEvent.getTouches().get(0); if (detectScrolledElement(touch)) { VConsole.log("TouchDelegate takes over"); nativeEvent.stopPropagation(); handlerRegistration = Event.addNativePreviewHandler(this); activeScrollDelegate = this; origY = touch.getClientY(); yPositions[0] = origY; eventTimeStamps[0] = getTimeStamp(); nextEvent = 1; origScrollTop = getScrollTop(); VConsole.log("ST" + origScrollTop); moved = false; // event.preventDefault(); // event.stopPropagation(); } }
From source file:forplay.html.HtmlPointer.java
License:Apache License
HtmlPointer(final Element rootElement) { // capture mouse down on the root element, only. captureEvent(rootElement, "mousedown", new EventHandler() { @Override/*from w w w . j av a 2 s. c om*/ public void handleEvent(NativeEvent evt) { if (listener != null) { // Prevent the default so that the target element doesn't highlight. evt.preventDefault(); inDragSequence = true; listener.onPointerStart(getRelativeX(evt, rootElement), getRelativeY(evt, rootElement)); } } }); // capture mouse up anywhere on the page as long as we are in a drag sequence capturePageEvent("mouseup", new EventHandler() { @Override public void handleEvent(NativeEvent evt) { if (listener != null && inDragSequence) { // Prevent the default so that the target element doesn't highlight. evt.preventDefault(); inDragSequence = false; listener.onPointerEnd(getRelativeX(evt, rootElement), getRelativeY(evt, rootElement)); } } }); // capture mouse move anywhere on the page that fires only if we are in a drag sequence capturePageEvent("mousemove", new EventHandler() { @Override public void handleEvent(NativeEvent evt) { if (listener != null && inDragSequence) { evt.preventDefault(); listener.onPointerDrag(getRelativeX(evt, rootElement), getRelativeY(evt, rootElement)); } } }); // capture touch start on the root element, only. captureEvent(rootElement, "touchstart", new EventHandler() { @Override public void handleEvent(NativeEvent evt) { if (listener != null) { // Prevent the default so that the target element doesn't highlight. evt.preventDefault(); if (evt.getTouches().length() > 0) { inDragSequence = true; com.google.gwt.dom.client.Touch touch = evt.getTouches().get(0); float x = touch.getRelativeX(rootElement); float y = touch.getRelativeY(rootElement); listener.onPointerStart(x, y); } } } }); // capture touch end anywhere on the page as long as we are in a drag sequence capturePageEvent("touchend", new EventHandler() { @Override public void handleEvent(NativeEvent evt) { if (listener != null && inDragSequence) { // Prevent the default so that the target element doesn't highlight. evt.preventDefault(); if (evt.getTouches().length() > 0) { inDragSequence = false; com.google.gwt.dom.client.Touch touch = evt.getTouches().get(0); float x = touch.getRelativeX(rootElement); float y = touch.getRelativeY(rootElement); listener.onPointerEnd(x, y); } } } }); // capture touch move anywhere on the page as long as we are in a drag sequence capturePageEvent("touchmove", new EventHandler() { @Override public void handleEvent(NativeEvent evt) { if (listener != null && inDragSequence) { // Prevent the default so that the target element doesn't highlight. evt.preventDefault(); if (evt.getTouches().length() > 0) { com.google.gwt.dom.client.Touch touch = evt.getTouches().get(0); float x = touch.getRelativeX(rootElement); float y = touch.getRelativeY(rootElement); listener.onPointerDrag(x, y); } } } }); }
From source file:forplay.html.HtmlTouch.java
License:Apache License
HtmlTouch(final Element rootElement) { // capture touch start on the root element, only. captureEvent(rootElement, "touchstart", new EventHandler() { @Override/* ww w. ja v a 2 s . c o m*/ public void handleEvent(NativeEvent evt) { if (listener != null) { // Prevent the default so that the target element doesn't highlight. evt.preventDefault(); JsArray<com.google.gwt.dom.client.Touch> nativeTouches = evt.getTouches(); int nativeTouchesLen = nativeTouches.length(); if (nativeTouchesLen == 0) { listener.onTouchStart(new TouchEvent[0]); return; } inTouchSequence = true; // Convert the JsArray<Native Touch> to an array of TouchEvents // TODO(pdr): replace TouchEvent with a JSO overlay type to avoid so much work here TouchEvent[] touches = new TouchEvent[nativeTouchesLen]; for (int t = 0; t < nativeTouchesLen; t++) { com.google.gwt.dom.client.Touch touch = nativeTouches.get(t); float x = touch.getRelativeX(rootElement); float y = touch.getRelativeY(rootElement); int id = getTouchIdentifier(evt, t); touches[t] = new TouchEvent(x, y, id); } listener.onTouchStart(touches); } } }); // capture touch end anywhere on the page as long as we are in a touch sequence capturePageEvent("touchend", new EventHandler() { @Override public void handleEvent(NativeEvent evt) { if (listener != null && inTouchSequence) { // Prevent the default so that the target element doesn't highlight. evt.preventDefault(); JsArray<com.google.gwt.dom.client.Touch> nativeTouches = evt.getTouches(); int nativeTouchesLen = nativeTouches.length(); // Convert the JsArray<Native Touch> to an array of TouchEvents // TODO(pdr): replace TouchEvent with a JSO overlay type to avoid so much work here TouchEvent[] touches = new TouchEvent[nativeTouchesLen]; for (int t = 0; t < nativeTouchesLen; t++) { com.google.gwt.dom.client.Touch touch = nativeTouches.get(t); float x = touch.getRelativeX(rootElement); float y = touch.getRelativeY(rootElement); int id = getTouchIdentifier(evt, t); touches[t] = new TouchEvent(x, y, id); } listener.onTouchEnd(touches); // ending a touch sequence inTouchSequence = false; } } }); // capture touch move anywhere on the page as long as we are in a touch sequence capturePageEvent("touchmove", new EventHandler() { @Override public void handleEvent(NativeEvent evt) { if (listener != null && inTouchSequence) { // Prevent the default so that the target element doesn't highlight. evt.preventDefault(); JsArray<com.google.gwt.dom.client.Touch> nativeTouches = evt.getTouches(); int nativeTouchesLen = nativeTouches.length(); // Convert the JsArray<Native Touch> to an array of TouchEvents // TODO(pdr): replace TouchEvent with a JSO overlay type to avoid so much work here TouchEvent[] touches = new TouchEvent[nativeTouchesLen]; for (int t = 0; t < nativeTouchesLen; t++) { com.google.gwt.dom.client.Touch touch = nativeTouches.get(t); float x = touch.getRelativeX(rootElement); float y = touch.getRelativeY(rootElement); int id = getTouchIdentifier(evt, t); touches[t] = new TouchEvent(x, y, id); } listener.onTouchMove(touches); } } }); }
From source file:org.tltv.gantt.client.GanttWidget.java
License:Apache License
protected void onTouchOrMouseDown(NativeEvent event) { JavaScriptObject target = event.getEventTarget().cast(); if (touchSupported) { if (target == container || target == content || (!isMovableSteps())) { containerScrollStartPosY = container.getScrollTop() + event.getTouches().get(0).getPageY(); return; } else {// ww w. j av a 2s .co m containerScrollStartPosY = -1; } } Element bar = getBar(event); if (bar == null) { return; } Event.setCapture(bar); // can't trust this one, unfortunately targetBarElement = bar; capturePoint = new Point(getTouchOrMouseClientX(event), getTouchOrMouseClientY(event)); movePoint = new Point(getTouchOrMouseClientX(event), getTouchOrMouseClientY(event)); capturePointLeftPercentage = bar.getStyle().getProperty("left"); capturePointWidthPercentage = bar.getStyle().getProperty("width"); capturePointLeftPx = bar.getOffsetLeft(); capturePointWidthPx = bar.getClientWidth(); capturePointBgColor = bar.getStyle().getBackgroundColor(); if (detectResizing(bar)) { resizing = true; resizingFromLeft = isResizingLeft(bar); } else { resizing = false; } disallowClickTimer.schedule(CLICK_INTERVAL); event.stopPropagation(); }
From source file:playn.html.HtmlTouch.java
License:Apache License
HtmlTouch(Element rootElement) { this.rootElement = rootElement; // capture touch start on the root element, only. HtmlInput.captureEvent(rootElement, "touchstart", new EventHandler() { @Override//from w w w . j av a2 s . c o m public void handleEvent(NativeEvent nativeEvent) { inTouchSequence = true; boolean[] preventDefault = { false }; onTouchStart(toEvents(nativeEvent, preventDefault)); if (preventDefault[0]) nativeEvent.preventDefault(); } }); // capture touch move anywhere on the page as long as we are in a touch sequence HtmlInput.capturePageEvent("touchmove", new EventHandler() { @Override public void handleEvent(NativeEvent nativeEvent) { if (inTouchSequence) { boolean[] preventDefault = { false }; onTouchMove(toEvents(nativeEvent, preventDefault)); if (preventDefault[0]) nativeEvent.preventDefault(); } } }); // capture touch end anywhere on the page as long as we are in a touch sequence HtmlInput.capturePageEvent("touchend", new EventHandler() { @Override public void handleEvent(NativeEvent nativeEvent) { if (inTouchSequence) { boolean[] preventDefault = { false }; onTouchEnd(toEvents(nativeEvent, preventDefault)); if (preventDefault[0]) nativeEvent.preventDefault(); // if there are no remaining active touches, note that this touch sequence has ended if (nativeEvent.getTouches().length() == 0) inTouchSequence = false; } } }); }