List of usage examples for com.google.gwt.user.client Event getChangedTouches
public final JsArray<Touch> getChangedTouches()
From source file:com.sencha.gxt.sample.graph.client.draw.GraphDnD.java
License:Apache License
protected void onTouchMove(Event e) { JsArray<Touch> touches = e.getChangedTouches(); for (int i = 0; i < touches.length(); i++) { Touch t = touches.get(i);//from w w w .ja v a 2 s .c om if (!touchDragStartPositions.containsKey(t.getIdentifier())) { //not an active drag continue; } //TODO fire an event about the move int x = t.getClientX() - graph.getElement().getAbsoluteTop() + graph.getElement().getScrollTop() + graph.getElement().getOwnerDocument().getScrollTop(); int y = t.getClientY() - graph.getElement().getAbsoluteLeft() + graph.getElement().getScrollLeft() + graph.getElement().getOwnerDocument().getScrollLeft(); touchLastDragPositions.put(t.getIdentifier(), new Point(x, y)); //TODO consider getting the offset from the original mouse point to the object // and using that here onDrag("touch" + t.getIdentifier(), x, y); e.preventDefault(); // log.finer("Touch move: " + t.getIdentifier() + " @ " + lastDragPosition.get(t.getIdentifier()).toString()); } }
From source file:com.vaadin.addon.spreadsheet.client.SheetWidget.java
protected void onMouseMoveWhenSelectingCells(Event event) { final Element target; /*//from ww w . ja va 2 s . c o m * Touch events handle target element differently. According to specs, * Touch.getTarget() is the equivalent of event.getTarget(). Of course, * Safari doesn't follow the specifications; all target references are * to the element where we started the drag. * * We need to manually parse x/y coords in #getRealEventTargetCell() to * find the correct cell. */ if (event.getChangedTouches() != null && event.getChangedTouches().length() > 0) { JsArray<Touch> touches = event.getChangedTouches(); target = touches.get(touches.length() - 1).getTarget().cast(); } else if (event.getTouches() != null && event.getTouches().length() > 0) { JsArray<Touch> touches = event.getTouches(); target = touches.get(touches.length() - 1).getTarget().cast(); } else { target = event.getEventTarget().cast(); } // Update scroll deltas int y = SpreadsheetWidget.getTouchOrMouseClientY(event); int x = SpreadsheetWidget.getTouchOrMouseClientX(event); if (checkScrollWhileSelecting(y, x)) { return; } int col = 0, row = 0; String className = null; if (target != null) { className = target.getAttribute("class"); /* * Parse according to classname of target element. As said above, * Safari gives us the wrong target and hence we have the wrong * style name here. * * This also means that if we move outside the sheet, we continue * execution past this check. */ jsniUtil.parseColRow(className); col = jsniUtil.getParsedCol(); row = jsniUtil.getParsedRow(); } if (row == 0 || col == 0) { return; } // skip search of actual cell if this is a merged cell if (!className.endsWith(MERGED_CELL_CLASSNAME)) { Cell targetCell = getRealEventTargetCell(x, y, getCell(col, row)); col = targetCell.getCol(); row = targetCell.getRow(); } if (col != tempCol || row != tempRow) { if (col == 0) { // on top of scroll bar if (x > target.getParentElement().getAbsoluteRight()) { col = getRightVisibleColumnIndex() + 1; } else { col = tempCol; } } if (row == 0) { if (y > sheet.getAbsoluteBottom()) { row = getBottomVisibleRowIndex() + 1; } else { row = tempRow; } } actionHandler.onSelectingCellsWithDrag(col, row); tempCol = col; tempRow = row; } }
From source file:com.vaadin.addon.spreadsheet.client.SpreadsheetWidget.java
static int getTouchOrMouseClientX(Event event) { int scrollLeft = Document.get().getScrollLeft(); if (WidgetUtil.isTouchEvent(event)) { return event.getChangedTouches().get(0).getClientX() + scrollLeft; } else {/*ww w. j av a 2 s . c o m*/ return event.getClientX() + scrollLeft; } }
From source file:com.vaadin.addon.spreadsheet.client.SpreadsheetWidget.java
static int getTouchOrMouseClientY(Event event) { int scrollTop = Document.get().getScrollTop(); if (WidgetUtil.isTouchEvent(event)) { return event.getChangedTouches().get(0).getClientY() + scrollTop; } else {//w ww .j a v a 2s. c o m return event.getClientY() + scrollTop; } }
From source file:com.vaadin.client.widgets.Grid.java
License:Apache License
private boolean handleHeaderDefaultRowEvent(Event event, RowContainer container) { if (container != escalator.getHeader()) { return false; }//from w w w .jav a 2s . c o m if (!getHeader().getRow(eventCell.getRowIndex()).isDefault()) { return false; } if (!eventCell.getColumn().isSortable()) { // Only handle sorting events if the column is sortable return false; } if (BrowserEvents.MOUSEDOWN.equals(event.getType()) && event.getShiftKey()) { // Don't select text when shift clicking on a header. event.preventDefault(); } if (BrowserEvents.TOUCHSTART.equals(event.getType())) { if (event.getTouches().length() > 1) { return false; } event.preventDefault(); Touch touch = event.getChangedTouches().get(0); rowEventTouchStartingPoint = new Point(touch.getClientX(), touch.getClientY()); sorter.sortAfterDelay(GridConstants.LONG_TAP_DELAY, true); return true; } else if (BrowserEvents.TOUCHMOVE.equals(event.getType())) { if (event.getTouches().length() > 1) { return false; } event.preventDefault(); Touch touch = event.getChangedTouches().get(0); double diffX = Math.abs(touch.getClientX() - rowEventTouchStartingPoint.getX()); double diffY = Math.abs(touch.getClientY() - rowEventTouchStartingPoint.getY()); // Cancel long tap if finger strays too far from // starting point if (diffX > GridConstants.LONG_TAP_THRESHOLD || diffY > GridConstants.LONG_TAP_THRESHOLD) { sorter.cancelDelayedSort(); } return true; } else if (BrowserEvents.TOUCHEND.equals(event.getType())) { if (event.getTouches().length() > 1) { return false; } if (sorter.isDelayedSortScheduled()) { // Not a long tap yet, perform single sort sorter.cancelDelayedSort(); sorter.sort(eventCell.getColumn(), false); } return true; } else if (BrowserEvents.TOUCHCANCEL.equals(event.getType())) { if (event.getTouches().length() > 1) { return false; } sorter.cancelDelayedSort(); return true; } else if (BrowserEvents.CLICK.equals(event.getType())) { sorter.sort(eventCell.getColumn(), event.getShiftKey()); // Click events should go onward to cell focus logic return false; } else { return false; } }
From source file:com.vaadin.client.WidgetUtil.java
License:Apache License
/** * A helper method to return the client position from an event. Returns * position from either first changed touch (if touch event) or from the * event itself.//from ww w. j a va 2 s . co m * * @param event * @return */ public static int getTouchOrMouseClientX(Event event) { if (isTouchEvent(event)) { return event.getChangedTouches().get(0).getClientX(); } else { return event.getClientX(); } }
From source file:com.vaadin.client.WidgetUtil.java
License:Apache License
/** * A helper method to return the client position from an event. Returns * position from either first changed touch (if touch event) or from the * event itself.//ww w .ja v a 2 s .co m * * @param event * @return */ public static int getTouchOrMouseClientY(Event event) { if (isTouchEvent(event)) { return event.getChangedTouches().get(0).getClientY(); } else { return event.getClientY(); } }
From source file:com.vaadin.client.WidgetUtil.java
License:Apache License
public static void simulateClickFromTouchEvent(Event touchevent, Widget widget) { Touch touch = touchevent.getChangedTouches().get(0); final NativeEvent createMouseUpEvent = Document.get().createMouseUpEvent(0, touch.getScreenX(), touch.getScreenY(), touch.getClientX(), touch.getClientY(), false, false, false, false, NativeEvent.BUTTON_LEFT);/*from w ww. ja va 2 s . c o m*/ final NativeEvent createMouseDownEvent = Document.get().createMouseDownEvent(0, touch.getScreenX(), touch.getScreenY(), touch.getClientX(), touch.getClientY(), false, false, false, false, NativeEvent.BUTTON_LEFT); final NativeEvent createMouseClickEvent = Document.get().createClickEvent(0, touch.getScreenX(), touch.getScreenY(), touch.getClientX(), touch.getClientY(), false, false, false, false); /* * Get target with element from point as we want the actual element, not * the one that sunk the event. */ final Element target = getElementFromPoint(touch.getClientX(), touch.getClientY()); /* * Fixes infocusable form fields in Safari of iOS 5.x and some Android * browsers. */ Widget targetWidget = findWidget(target, null); if (targetWidget instanceof com.google.gwt.user.client.ui.Focusable) { final com.google.gwt.user.client.ui.Focusable toBeFocusedWidget = (com.google.gwt.user.client.ui.Focusable) targetWidget; toBeFocusedWidget.setFocus(true); } else if (targetWidget instanceof Focusable) { ((Focusable) targetWidget).focus(); } Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { try { target.dispatchEvent(createMouseDownEvent); target.dispatchEvent(createMouseUpEvent); target.dispatchEvent(createMouseClickEvent); } catch (Exception e) { } } }); }
From source file:com.vaadin.terminal.gwt.client.Util.java
License:Open Source License
public static void simulateClickFromTouchEvent(Event touchevent, Widget widget) { Touch touch = touchevent.getChangedTouches().get(0); final NativeEvent createMouseUpEvent = Document.get().createMouseUpEvent(0, touch.getScreenX(), touch.getScreenY(), touch.getClientX(), touch.getClientY(), false, false, false, false, NativeEvent.BUTTON_LEFT);// w w w . ja v a 2 s .co m final NativeEvent createMouseDownEvent = Document.get().createMouseDownEvent(0, touch.getScreenX(), touch.getScreenY(), touch.getClientX(), touch.getClientY(), false, false, false, false, NativeEvent.BUTTON_LEFT); final NativeEvent createMouseClickEvent = Document.get().createClickEvent(0, touch.getScreenX(), touch.getScreenY(), touch.getClientX(), touch.getClientY(), false, false, false, false); /* * Get target with element from point as we want the actual element, not * the one that sunk the event. */ final Element target = getElementFromPoint(touch.getClientX(), touch.getClientY()); Scheduler.get().scheduleDeferred(new ScheduledCommand() { public void execute() { try { target.dispatchEvent(createMouseDownEvent); target.dispatchEvent(createMouseUpEvent); target.dispatchEvent(createMouseClickEvent); } catch (Exception e) { } } }); }