List of usage examples for com.google.gwt.dom.client NativeEvent getChangedTouches
public final JsArray<Touch> getChangedTouches()
From source file:com.allen_sauer.gwt.dnd.client.MouseDragHandler.java
License:Apache License
private void synthesizeAsyncTouchEnd(TouchEndEvent event) { final Element elem = mouseDownWidget.getElement(); NativeEvent n = event.getNativeEvent(); // TODO extract these properties from the original event final boolean bubbles = true; final boolean cancelable = true; final int detail = 0; final boolean ctrlKey = n.getCtrlKey(); final boolean altKey = n.getAltKey(); final boolean shiftKey = n.getShiftKey(); final boolean metaKey = n.getMetaKey(); final JsArray<Touch> changedTouches = n.getChangedTouches(); Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override/*from w ww . jav a2s. c o m*/ public void execute() { // TODO determine if we need to set additional event properties elem.dispatchEvent(DOMUtil.createTouchEndEvent(bubbles, cancelable, detail, ctrlKey, altKey, shiftKey, metaKey, changedTouches)); } }); }
From source file:com.badlogic.gdx.backends.gwt.GwtInput.java
License:Apache License
private void handleEvent(NativeEvent e) { if (e.getType().equals("mousedown")) { if (!e.getEventTarget().equals(canvas) || touched[0]) { float mouseX = getRelativeX(e, canvas); float mouseY = getRelativeY(e, canvas); if (mouseX < 0 || mouseX > Gdx.graphics.getWidth() || mouseY < 0 || mouseY > Gdx.graphics.getHeight()) { hasFocus = false;/* w ww .ja v a2 s. c om*/ } return; } hasFocus = true; this.justTouched = true; this.touched[0] = true; this.pressedButtons.add(getButton(e.getButton())); this.deltaX[0] = 0; this.deltaY[0] = 0; if (isCursorCatched()) { this.touchX[0] += getMovementXJSNI(e); this.touchY[0] += getMovementYJSNI(e); } else { this.touchX[0] = getRelativeX(e, canvas); this.touchY[0] = getRelativeY(e, canvas); } this.currentEventTimeStamp = TimeUtils.nanoTime(); if (processor != null) processor.touchDown(touchX[0], touchY[0], 0, getButton(e.getButton())); } if (e.getType().equals("mousemove")) { if (isCursorCatched()) { this.deltaX[0] = (int) getMovementXJSNI(e); this.deltaY[0] = (int) getMovementYJSNI(e); this.touchX[0] += getMovementXJSNI(e); this.touchY[0] += getMovementYJSNI(e); } else { this.deltaX[0] = getRelativeX(e, canvas) - touchX[0]; this.deltaY[0] = getRelativeY(e, canvas) - touchY[0]; this.touchX[0] = getRelativeX(e, canvas); this.touchY[0] = getRelativeY(e, canvas); } this.currentEventTimeStamp = TimeUtils.nanoTime(); if (processor != null) { if (touched[0]) processor.touchDragged(touchX[0], touchY[0], 0); else processor.mouseMoved(touchX[0], touchY[0]); } } if (e.getType().equals("mouseup")) { if (!touched[0]) return; this.pressedButtons.remove(getButton(e.getButton())); this.touched[0] = pressedButtons.size > 0; if (isCursorCatched()) { this.deltaX[0] = (int) getMovementXJSNI(e); this.deltaY[0] = (int) getMovementYJSNI(e); this.touchX[0] += getMovementXJSNI(e); this.touchY[0] += getMovementYJSNI(e); } else { this.deltaX[0] = getRelativeX(e, canvas) - touchX[0]; this.deltaY[0] = getRelativeY(e, canvas) - touchY[0]; this.touchX[0] = getRelativeX(e, canvas); this.touchY[0] = getRelativeY(e, canvas); } this.currentEventTimeStamp = TimeUtils.nanoTime(); this.touched[0] = false; if (processor != null) processor.touchUp(touchX[0], touchY[0], 0, getButton(e.getButton())); } if (e.getType().equals(getMouseWheelEvent())) { if (processor != null) { processor.scrolled((int) getMouseWheelVelocity(e)); } this.currentEventTimeStamp = TimeUtils.nanoTime(); e.preventDefault(); } if (e.getType().equals("keydown") && hasFocus) { // System.out.println("keydown"); int code = keyForCode(e.getKeyCode()); if (code == 67) { e.preventDefault(); if (processor != null) { processor.keyDown(code); processor.keyTyped('\b'); } } else { if (!pressedKeys[code]) { pressedKeyCount++; pressedKeys[code] = true; keyJustPressed = true; justPressedKeys[code] = true; if (processor != null) { processor.keyDown(code); } } } } if (e.getType().equals("keypress") && hasFocus) { // System.out.println("keypress"); char c = (char) e.getCharCode(); if (processor != null) processor.keyTyped(c); } if (e.getType().equals("keyup") && hasFocus) { // System.out.println("keyup"); int code = keyForCode(e.getKeyCode()); if (pressedKeys[code]) { pressedKeyCount--; pressedKeys[code] = false; } if (processor != null) { processor.keyUp(code); } } if (e.getType().equals("touchstart")) { this.justTouched = true; JsArray<Touch> touches = e.getChangedTouches(); for (int i = 0, j = touches.length(); i < j; i++) { Touch touch = touches.get(i); int real = touch.getIdentifier(); int touchId; touchMap.put(real, touchId = getAvailablePointer()); touched[touchId] = true; touchX[touchId] = getRelativeX(touch, canvas); touchY[touchId] = getRelativeY(touch, canvas); deltaX[touchId] = 0; deltaY[touchId] = 0; if (processor != null) { processor.touchDown(touchX[touchId], touchY[touchId], touchId, Buttons.LEFT); } } this.currentEventTimeStamp = TimeUtils.nanoTime(); e.preventDefault(); } if (e.getType().equals("touchmove")) { JsArray<Touch> touches = e.getChangedTouches(); for (int i = 0, j = touches.length(); i < j; i++) { Touch touch = touches.get(i); int real = touch.getIdentifier(); int touchId = touchMap.get(real); deltaX[touchId] = getRelativeX(touch, canvas) - touchX[touchId]; deltaY[touchId] = getRelativeY(touch, canvas) - touchY[touchId]; touchX[touchId] = getRelativeX(touch, canvas); touchY[touchId] = getRelativeY(touch, canvas); if (processor != null) { processor.touchDragged(touchX[touchId], touchY[touchId], touchId); } } this.currentEventTimeStamp = TimeUtils.nanoTime(); e.preventDefault(); } if (e.getType().equals("touchcancel")) { JsArray<Touch> touches = e.getChangedTouches(); for (int i = 0, j = touches.length(); i < j; i++) { Touch touch = touches.get(i); int real = touch.getIdentifier(); int touchId = touchMap.get(real); touchMap.remove(real); touched[touchId] = false; deltaX[touchId] = getRelativeX(touch, canvas) - touchX[touchId]; deltaY[touchId] = getRelativeY(touch, canvas) - touchY[touchId]; touchX[touchId] = getRelativeX(touch, canvas); touchY[touchId] = getRelativeY(touch, canvas); if (processor != null) { processor.touchUp(touchX[touchId], touchY[touchId], touchId, Buttons.LEFT); } } this.currentEventTimeStamp = TimeUtils.nanoTime(); e.preventDefault(); } if (e.getType().equals("touchend")) { JsArray<Touch> touches = e.getChangedTouches(); for (int i = 0, j = touches.length(); i < j; i++) { Touch touch = touches.get(i); int real = touch.getIdentifier(); int touchId = touchMap.get(real); touchMap.remove(real); touched[touchId] = false; deltaX[touchId] = getRelativeX(touch, canvas) - touchX[touchId]; deltaY[touchId] = getRelativeY(touch, canvas) - touchY[touchId]; touchX[touchId] = getRelativeX(touch, canvas); touchY[touchId] = getRelativeY(touch, canvas); if (processor != null) { processor.touchUp(touchX[touchId], touchY[touchId], touchId, Buttons.LEFT); } } this.currentEventTimeStamp = TimeUtils.nanoTime(); e.preventDefault(); } // if(hasFocus) e.preventDefault(); }
From source file:com.sencha.gxt.core.client.gestures.AbstractGestureRecognizer.java
License:sencha.com license
/** * Handles the start of gesture. Typically associated by a touchstart or pointerdown event * * @param startEvent/*from w w w .ja v a2 s. c o m*/ * @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 handleStart(NativeEvent startEvent) { JsArray<Touch> touches = pointerEventsSupport.isSupported() ? pointerEventsSupport.getChangedTouches(startEvent) : startEvent.getChangedTouches(); List<TouchData> startedTouches = new ArrayList<TouchData>(); for (int i = 0; i < touches.length(); i++) { Touch t = touches.get(i); TouchData data = new TouchData(new Point(t.getPageX(), t.getPageY()), t.getIdentifier(), startEvent); startedTouches.add(data); } start(startedTouches); return true; }
From source file:com.sencha.gxt.core.client.gestures.AbstractGestureRecognizer.java
License:sencha.com license
/** * Handles gesture move events// w w w . j av a 2 s . c o m * * @param moveEvent * @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 handleMove(NativeEvent moveEvent) { JsArray<Touch> touches = pointerEventsSupport.isSupported() ? pointerEventsSupport.getChangedTouches(moveEvent) : moveEvent.getChangedTouches(); List<TouchData> allData = new ArrayList<TouchData>(); int unhandledTouches = 0; for (int i = 0; i < touches.length(); i++) { Touch t = touches.get(i); if (captured.containsKey(t.getIdentifier())) { TouchData data = captured.get(t.getIdentifier()); data.setLastChange(Type.Move); data.setLastPosition(new Point(t.getPageX(), t.getPageY())); data.setLastNativeEvent(moveEvent); allData.add(data); } else { unhandledTouches++; } } if (!allData.isEmpty()) { handlePreventDefault(moveEvent); onMove(allData); } if (unhandledTouches == 0) { moveEvent.stopPropagation(); return false; } return true; }
From source file:com.vaadin.client.ui.TouchScrollDelegate.java
License:Apache License
/** * /*from www. j a v a2 s . c o m*/ * @param event * @return */ private boolean readPositionAndSpeed(NativeEvent event) { Touch touch = event.getChangedTouches().get(0); lastClientY = touch.getClientY(); int eventIndx = nextEvent++; eventIndx = eventIndx % EVENTS_FOR_SPEED_CALC; eventTimeStamps[eventIndx] = getTimeStamp(); yPositions[eventIndx] = lastClientY; return isMovedSignificantly(); }
From source file:com.vaadin.terminal.gwt.client.ui.TouchScrollDelegate.java
License:Open Source License
/** * //w w w . j a v a 2 s . co m * @param event * @return */ private boolean readPositionAndSpeed(NativeEvent event) { Date now = new Date(); Touch touch = event.getChangedTouches().get(0); lastClientY = touch.getClientY(); int eventIndx = nextEvent++; eventIndx = eventIndx % EVENTS_FOR_SPEED_CALC; eventTimeStamps[eventIndx] = now; yPositions[eventIndx] = lastClientY; return isMovedSignificantly(); }
From source file:org.parallax3d.parallax.platforms.gwt.GwtInput.java
License:Open Source License
private void handleEvent(NativeEvent e) { if (e.getType().equals("mousedown")) { if (!e.getEventTarget().equals(canvas) || touched[0]) { float mouseX = getRelativeX(e, canvas); float mouseY = getRelativeY(e, canvas); if (mouseX < 0 || mouseX > canvas.getWidth() || mouseY < 0 || mouseY > canvas.getHeight()) { hasFocus = false;/*from w w w . j a v a2s. c om*/ } return; } hasFocus = true; this.justTouched = true; this.touched[0] = true; this.pressedButtons.add(getButton(e.getButton())); this.deltaX[0] = 0; this.deltaY[0] = 0; if (isCursorCatched()) { this.touchX[0] += getMovementXJSNI(e); this.touchY[0] += getMovementYJSNI(e); } else { this.touchX[0] = getRelativeX(e, canvas); this.touchY[0] = getRelativeY(e, canvas); } this.currentEventTimeStamp = Duration.nanoTime(); if (touchDownHandler != null) touchDownHandler.onTouchDown(touchX[0], touchY[0], 0, getButton(e.getButton())); } if (e.getType().equals("mousemove")) { if (isCursorCatched()) { this.deltaX[0] = (int) getMovementXJSNI(e); this.deltaY[0] = (int) getMovementYJSNI(e); this.touchX[0] += getMovementXJSNI(e); this.touchY[0] += getMovementYJSNI(e); } else { this.deltaX[0] = getRelativeX(e, canvas) - touchX[0]; this.deltaY[0] = getRelativeY(e, canvas) - touchY[0]; this.touchX[0] = getRelativeX(e, canvas); this.touchY[0] = getRelativeY(e, canvas); } this.currentEventTimeStamp = Duration.nanoTime(); if (touchMoveHandler != null) touchMoveHandler.onTouchMove(touchX[0], touchY[0], 0); if (touchDraggedHandler != null && touched[0]) touchDraggedHandler.onTouchDragged(touchX[0], touchY[0], 0); } if (e.getType().equals("mouseup")) { if (!touched[0]) return; this.pressedButtons.remove(getButton(e.getButton())); this.touched[0] = pressedButtons.size() > 0; if (isCursorCatched()) { this.deltaX[0] = (int) getMovementXJSNI(e); this.deltaY[0] = (int) getMovementYJSNI(e); this.touchX[0] += getMovementXJSNI(e); this.touchY[0] += getMovementYJSNI(e); } else { this.deltaX[0] = getRelativeX(e, canvas) - touchX[0]; this.deltaY[0] = getRelativeY(e, canvas) - touchY[0]; this.touchX[0] = getRelativeX(e, canvas); this.touchY[0] = getRelativeY(e, canvas); } this.currentEventTimeStamp = Duration.nanoTime(); this.touched[0] = false; if (touchUpHandler != null) touchUpHandler.onTouchUp(touchX[0], touchY[0], 0, getButton(e.getButton())); } if (e.getType().equals(getMouseWheelEvent())) { if (scrolledHandler != null) { scrolledHandler.onScrolled((int) getMouseWheelVelocity(e)); } this.currentEventTimeStamp = Duration.nanoTime(); e.preventDefault(); } if (e.getType().equals("keydown") && hasFocus) { // System.out.println("keydown"); int code = e.getKeyCode(); if (code == 67) { e.preventDefault(); if (keyDownHandler != null) keyDownHandler.onKeyDown(code); if (keyTypedHandler != null) keyTypedHandler.onKeyTyped('\b'); } else { if (!pressedKeys[code]) { pressedKeyCount++; pressedKeys[code] = true; keyJustPressed = true; justPressedKeys[code] = true; if (keyDownHandler != null) keyDownHandler.onKeyDown(code); } } } if (e.getType().equals("keypress") && hasFocus) { // System.out.println("keypress"); char c = (char) e.getCharCode(); if (keyTypedHandler != null) keyTypedHandler.onKeyTyped(c); } if (e.getType().equals("keyup") && hasFocus) { // System.out.println("keyup"); int code = e.getKeyCode(); if (pressedKeys[code]) { pressedKeyCount--; pressedKeys[code] = false; } if (keyUpHandler != null) keyUpHandler.onKeyUp(code); } if (e.getType().equals("touchstart")) { this.justTouched = true; JsArray<Touch> touches = e.getChangedTouches(); for (int i = 0, j = touches.length(); i < j; i++) { Touch touch = touches.get(i); int real = touch.getIdentifier(); int touchId; touchMap.put(real, touchId = getAvailablePointer()); touched[touchId] = true; touchX[touchId] = getRelativeX(touch, canvas); touchY[touchId] = getRelativeY(touch, canvas); deltaX[touchId] = 0; deltaY[touchId] = 0; if (touchDownHandler != null) touchDownHandler.onTouchDown(touchX[touchId], touchY[touchId], touchId, Buttons.LEFT); } this.currentEventTimeStamp = Duration.nanoTime(); e.preventDefault(); } if (e.getType().equals("touchmove")) { JsArray<Touch> touches = e.getChangedTouches(); for (int i = 0, j = touches.length(); i < j; i++) { Touch touch = touches.get(i); int real = touch.getIdentifier(); int touchId = touchMap.get(real); deltaX[touchId] = getRelativeX(touch, canvas) - touchX[touchId]; deltaY[touchId] = getRelativeY(touch, canvas) - touchY[touchId]; touchX[touchId] = getRelativeX(touch, canvas); touchY[touchId] = getRelativeY(touch, canvas); if (touchDraggedHandler != null) touchDraggedHandler.onTouchDragged(touchX[touchId], touchY[touchId], touchId); } this.currentEventTimeStamp = Duration.nanoTime(); e.preventDefault(); } if (e.getType().equals("touchcancel")) { JsArray<Touch> touches = e.getChangedTouches(); for (int i = 0, j = touches.length(); i < j; i++) { Touch touch = touches.get(i); int real = touch.getIdentifier(); int touchId = touchMap.get(real); touchMap.remove(real); touched[touchId] = false; deltaX[touchId] = getRelativeX(touch, canvas) - touchX[touchId]; deltaY[touchId] = getRelativeY(touch, canvas) - touchY[touchId]; touchX[touchId] = getRelativeX(touch, canvas); touchY[touchId] = getRelativeY(touch, canvas); if (touchUpHandler != null) touchUpHandler.onTouchUp(touchX[touchId], touchY[touchId], touchId, Buttons.LEFT); } this.currentEventTimeStamp = Duration.nanoTime(); e.preventDefault(); } if (e.getType().equals("touchend")) { JsArray<Touch> touches = e.getChangedTouches(); for (int i = 0, j = touches.length(); i < j; i++) { Touch touch = touches.get(i); int real = touch.getIdentifier(); int touchId = touchMap.get(real); touchMap.remove(real); touched[touchId] = false; deltaX[touchId] = getRelativeX(touch, canvas) - touchX[touchId]; deltaY[touchId] = getRelativeY(touch, canvas) - touchY[touchId]; touchX[touchId] = getRelativeX(touch, canvas); touchY[touchId] = getRelativeY(touch, canvas); if (touchUpHandler != null) touchUpHandler.onTouchUp(touchX[touchId], touchY[touchId], touchId, Buttons.LEFT); } this.currentEventTimeStamp = Duration.nanoTime(); e.preventDefault(); } // if(hasFocus) e.preventDefault(); }
From source file:org.tltv.gantt.client.GanttWidget.java
License:Apache License
public static int getTouchOrMouseClientX(NativeEvent event) { if (isTouchEvent(event)) { return event.getChangedTouches().get(0).getClientX(); } else {//ww w . j ava2 s . c o m return event.getClientX(); } }
From source file:org.tltv.gantt.client.GanttWidget.java
License:Apache License
public static int getTouchOrMouseClientY(NativeEvent event) { if (isTouchEvent(event)) { return event.getChangedTouches().get(0).getClientY(); } else {//from w w w .j a v a 2 s. c om return event.getClientY(); } }
From source file:org.tltv.gantt.client.GanttWidget.java
License:Apache License
protected void onTouchOrMouseMove(NativeEvent event) { // did we intend to scroll the container? if (containerScrollStartPosY != -1) { container.setScrollTop(containerScrollStartPosY - event.getChangedTouches().get(0).getPageY()); return;/* w ww . jav a 2s . c o m*/ } Element bar = getBar(event); if (bar != null) { movePoint = new Point(getTouchOrMouseClientX(event), getTouchOrMouseClientY(event)); showResizingPointer(bar, detectResizing(bar)); } if (targetBarElement == null) { return; } bar = targetBarElement; disallowClickTimer.cancel(); clickOnNextMouseUp = false; // calculate delta x and y by original position and the current one. double deltax = getTouchOrMouseClientX(event) - capturePoint.getX(); double deltay = getTouchOrMouseClientY(event) - capturePoint.getY(); GWT.log("Position delta x: " + deltax + "px"); if (resizing) { resizingInProgress = deltax != 0.0; if (resizingFromLeft) { updateBarResizingLeft(bar, deltax); } else { updateBarResizingRight(bar, deltax); } addResizingStyles(bar); bar.getStyle().clearBackgroundColor(); } else if (isMovableSteps()) { updateMoveInProgressFlag(deltax, deltay); updateBarMovingPosition(bar, deltax); addMovingStyles(bar); bar.getStyle().clearBackgroundColor(); } event.stopPropagation(); }