List of usage examples for com.google.gwt.user.client Event getTouches
public final JsArray<Touch> getTouches()
From source file:com.cgxlib.xq.client.plugins.MousePlugin.java
License:Apache License
/** * This method initialize all needed handlers. *//*w w w .j a v a2 s . co m*/ protected void initMouseHandler(MouseOptions options) { this.options = options; for (final Element e : elements()) { $(e).as(Events).bind(Event.ONMOUSEDOWN, getPluginName(), (Object) null, new Function() { @Override public boolean f(Event event) { if (touchSupported) { return true; } return mouseDown(e, XQEvent.create(event)); } }).bind(Event.ONTOUCHSTART, getPluginName(), (Object) null, new Function() { public boolean f(Event event) { if (event.getTouches().length() > 1) { return true; } touchSupported = true; return mouseDown(e, XQEvent.create(event)); } }).bind(Event.ONCLICK, getPluginName(), (Object) null, new Function() { @Override public boolean f(Event event) { preventClickEvent |= !mouseClick(e, XQEvent.create(event)); if (preventClickEvent) { preventClickEvent = false; event.stopPropagation(); event.preventDefault(); return false; } return true; } }); } }
From source file:com.cgxlib.xq.client.plugins.MousePlugin.java
License:Apache License
protected int getClientX(Event e) { if (touchSupported) { return e.getTouches().get(0).getClientX(); } else {/*from w w w .j ava2 s.c om*/ return e.getClientX(); } }
From source file:com.cgxlib.xq.client.plugins.MousePlugin.java
License:Apache License
protected int getClientY(Event e) { if (touchSupported) { return e.getTouches().get(0).getClientY(); } else {//from w ww. j a v a 2s . c om return e.getClientY(); } }
From source file:com.haulmont.cuba.web.toolkit.ui.client.jqueryfileupload.CubaFileUploadProgressWindow.java
License:Apache License
private void onDragEvent(Event event) { if (!WidgetUtil.isTouchEventOrLeftMouseButton(event)) { return;//from w w w. j a va 2s. c o m } switch (DOM.eventGetType(event)) { case Event.ONTOUCHSTART: if (event.getTouches().length() > 1) { return; } case Event.ONMOUSEDOWN: beginMovingWindow(event); break; case Event.ONMOUSEUP: case Event.ONTOUCHEND: case Event.ONTOUCHCANCEL: case Event.ONLOSECAPTURE: stopMovingWindow(); break; case Event.ONMOUSEMOVE: case Event.ONTOUCHMOVE: moveWindow(event); break; default: break; } }
From source file:com.sencha.gxt.sample.graph.client.draw.GraphDnD.java
License:Apache License
protected void onTouchEnd(Event e) { JsArray<Touch> touches = e.getTouches(); Set<Integer> identifiers = new HashSet<Integer>(touchDragStartPositions.keySet()); log.finer("ending, currently tracking: " + identifiers); for (int i = 0; i < touches.length(); i++) { identifiers.remove(touches.get(i).getIdentifier()); }//from w w w .ja v a 2 s. c om log.finer("now down to " + identifiers); for (Integer identifier : identifiers) { log.finer("[End] event for " + identifier); Point lastPosition = touchLastDragPositions.get(identifier); onDrop("touch" + identifier, lastPosition.getX(), lastPosition.getY()); log.finer("Touch end: " + identifier + " @ " + lastPosition.toString()); touchDragStartPositions.remove(identifier); touchLastDragPositions.remove(identifier); } if (touchDragStartPositions.isEmpty()) { assert touchLastDragPositions.isEmpty(); touchHandler.remove(); } }
From source file:com.smartgwt.mobile.client.widgets.form.fields.SliderItem.java
License:Open Source License
@Override public void _onStart(Event event, Touch touch) { if (!active) { event.preventDefault();/*from w w w.j av a2 s . c o m*/ if (_isReadOnly()) return; active = true; offsetX = (event.getTypeInt() == Event.ONTOUCHSTART ? event.getTouches().get(0).getClientX() : event.getClientX()) - lastX; calcInternalWidth(); } }
From source file:com.smartgwt.mobile.client.widgets.form.fields.SliderItem.java
License:Open Source License
protected void onMove(Event event) { event.preventDefault();/* w ww . ja v a 2 s . c o m*/ if (active) { lastX = (event.getTypeInt() == Event.ONTOUCHMOVE ? event.getTouches().get(0).getClientX() : event.getClientX()) - offsetX; if (lastX < 0) { lastX = 0; } if (lastX > internalWidth) { lastX = internalWidth; } value = lastX / ((float) internalWidth) * (maxValue - minValue); _updateValue(getRoundedValue(value)); getElement().getStyle().setProperty(DOMConstants.INSTANCE.getBackgroundSizePropertyName(), lastX + "px " + _CSS.sliderBarHeightPx() + "px, 100% " + _CSS.sliderBarHeightPx() + "px"); knobElem.getStyle().setProperty(DOMConstants.INSTANCE.getTransformPropertyName(), "translate(" + lastX + "px)"); } }
From source file:com.smartgwt.mobile.client.widgets.tab.TabSet.java
License:Open Source License
/** * **************************************************** * Settings/*w ww .ja v a2s. c om*/ * **************************************************** */ @SuppressWarnings("unused") private Tab findTarget(Event event) { Tab tab = null; final int Y = (event.getTouches() != null && event.getTouches().length() > 0) ? event.getTouches().get(0).getClientY() : event.getClientY(); final int X = (event.getTouches() != null && event.getTouches().length() > 0) ? event.getTouches().get(0).getClientX() : event.getClientX(); if (Y >= tabBar.getAbsoluteTop() && !tabs.isEmpty()) { final int width = tabs.get(0)._getTabSetItem().getElement().getOffsetWidth(); final int index = X / width; if (0 <= index && ((showMoreTab && index < moreTabCount) || (!showMoreTab && index < tabs.size()))) { tab = tabs.get(index); } } return tab; }
From source file:com.smartgwt.mobile.client.widgets.tableview.TableView.java
License:Open Source License
@Override public void onBrowserEvent(Event event) { super.onBrowserEvent(event); if (!isEnabled()) return;// w w w .j a va2s. c om final Element targetElem = EventUtil.getTargetElem(event); if (targetElem != null) { final Element element; final JsArray<Touch> touches; final int clientX, clientY; final boolean wasContextClickFired; switch (event.getTypeInt()) { case Event.ONMOUSEDOWN: onStart(event, null); break; case Event.ONTOUCHSTART: touches = event.getTouches(); if (touches.length() == 1 && touchIdentifier == null) { onStart(event, touches.get(0)); } else { // Another finger is touching the screen. onEnd(event); } break; case Event.ONMOUSEMOVE: if (touchActive) { clientX = event.getClientX(); clientY = event.getClientY(); if (Math.abs(touchPointX - clientX) >= 10 || Math.abs(touchPointY - clientY) >= 10) { onEnd(event); } } break; case Event.ONTOUCHMOVE: if (touchActive) { touches = event.getTouches(); if (touches.length() == 1 && touchIdentifier != null) { final Touch touch = touches.get(0); if (touch.getIdentifier() == touchIdentifier.intValue()) { clientX = touch.getClientX(); clientY = touch.getClientY(); if (Math.abs(touchPointX - clientX) >= 10 || Math.abs(touchPointY - clientY) >= 10) { onEnd(event); } } } } break; case Event.ONMOUSEUP: case Event.ONMOUSEOUT: case Event.ONTOUCHEND: case Event.ONTOUCHCANCEL: element = activeElement; wasContextClickFired = contextClickFired; onEnd(event); if (element != null && wasContextClickFired) { onClick(element, null); } break; case Event.ONCLICK: if (!isEnabled()) return; element = _findElement(event); onClick(element, targetElem); break; case Event.ONCONTEXTMENU: if (!isEnabled()) return; element = _findElement(event); if (element != null) { // Find the "context clickable element". // The context clickable element is the title element, unless there // is no title element, in which case it is the <li>. Element contextClickableElement = element; final NodeList<Node> children = element.getChildNodes(); final int children_length = children.getLength(); for (int i = 0; i < children_length; ++i) { final Node child = children.getItem(i); if (child.getNodeType() != Node.ELEMENT_NODE) continue; final Element childElem = (Element) child; if (ElementUtil.hasClassName(childElem, TableView.RECORD_TITLE_CLASS_NAME)) { contextClickableElement = childElem; if (touchActive) contextClickFired = true; break; } } if (contextClickableElement.isOrHasChild(targetElem)) { final Integer recordIndex = _findRecordIndex(element); if (recordIndex != null) { final Record record = _getData().get(recordIndex.intValue()); final boolean cancelled = RowContextClickEvent._fire(this, -1, record, recordIndex.intValue()); if (!cancelled) { final Menu contextMenu = getContextMenu(); if (contextMenu != null) { contextClickableElement.addClassName(_CSS.contextClickedElementClass()); final Object recordID = getRecordId(record); final Element li = elementMap.get(recordID); assert li != null; final Element finalContextClickableElement = contextClickableElement; new BeforeMenuHiddenHandler() { private HandlerRegistration beforeMenuHiddenRegistration = contextMenu ._addBeforeMenuHiddenHandler(this); @Override public void _onBeforeMenuHidden(BeforeMenuHiddenEvent event) { beforeMenuHiddenRegistration.removeHandler(); finalContextClickableElement .removeClassName(_CSS.contextClickedElementClass()); } }; contextMenu._showAt(this, event.getClientX(), event.getClientY(), contextClickableElement.getAbsoluteLeft(), contextClickableElement.getAbsoluteRight(), contextClickableElement.getAbsoluteTop(), contextClickableElement.getAbsoluteBottom()); if (touchActive) contextClickFired = true; break; } } } } } break; } } }
From source file:com.vaadin.addon.spreadsheet.client.SheetWidget.java
protected void onMouseMoveWhenSelectingCells(Event event) { final Element target; /*/*from ww w. j a v a2s .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; } }