List of usage examples for com.google.gwt.dom.client NativeEvent getButton
public final int getButton()
From source file:client.application.ApplicationView.java
License:Apache License
void register() { if (!registred) { registred = true;//from w ww . ja v a 2s . com Event.addNativePreviewHandler(new Event.NativePreviewHandler() { @Override public void onPreviewNativeEvent(Event.NativePreviewEvent event) { NativeEvent ne = event.getNativeEvent(); if ("keypress".equals(ne.getType()) && ne.getKeyCode() != 0) { logger.log(Level.INFO, String.valueOf((char) ne.getKeyCode())); ServerEventBusService.App.getInstance().onSendKeyEvent(ne.getKeyCode(), counter++, new VoidAsyncCallback()); } else if ("mousedown".equals(ne.getType()) && ne.getButton() == NativeEvent.BUTTON_RIGHT) { ne.preventDefault(); } } }); } }
From source file:com.allen_sauer.gwt.dnd.client.MouseDragHandler.java
License:Apache License
private void synthesizeAsyncMouseUp(MouseUpEvent event) { final Element elem = mouseDownWidget.getElement(); NativeEvent n = event.getNativeEvent(); // One click, see https://developer.mozilla.org/en-US/docs/DOM/event.detail final int detail = 1; final int screenX = n.getScreenX(); final int screenY = n.getScreenY(); final int clientX = n.getClientX(); final int clientY = n.getClientY(); final boolean ctrlKey = n.getCtrlKey(); final boolean altKey = n.getAltKey(); final boolean shiftKey = n.getShiftKey(); final boolean metaKey = n.getMetaKey(); final int button = n.getButton(); Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override/* ww w . ja v a 2 s .co m*/ public void execute() { // TODO determine if we need to set additional event properties elem.dispatchEvent(Document.get().createMouseUpEvent(detail, screenX, screenY, clientX, clientY, ctrlKey, altKey, shiftKey, metaKey, button)); } }); }
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 w w. j a v a 2 s . com } 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.google.gerrit.client.diff.DiffScreen.java
License:Apache License
private GutterClickHandler onGutterClick(final CodeMirror cm) { return new GutterClickHandler() { @Override//from w ww . j ava 2 s. c o m public void handle(CodeMirror instance, final int line, final String gutterClass, NativeEvent clickEvent) { if (Element.as(clickEvent.getEventTarget()).hasClassName(getLineNumberClassName()) && clickEvent.getButton() == NativeEvent.BUTTON_LEFT && !clickEvent.getMetaKey() && !clickEvent.getAltKey() && !clickEvent.getCtrlKey() && !clickEvent.getShiftKey()) { cm.setCursor(Pos.create(line)); Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { getCommentManager().newDraftOnGutterClick(cm, gutterClass, line + 1); } }); } } }; }
From source file:com.google.gerrit.client.diff.SideBySide2.java
License:Apache License
private GutterClickHandler onGutterClick(final CodeMirror cm) { return new GutterClickHandler() { @Override/* w ww . ja va 2 s. co m*/ public void handle(CodeMirror instance, int line, String gutter, NativeEvent clickEvent) { if (clickEvent.getButton() == NativeEvent.BUTTON_LEFT && !clickEvent.getMetaKey() && !clickEvent.getAltKey() && !clickEvent.getCtrlKey() && !clickEvent.getShiftKey()) { if (!(cm.hasActiveLine() && cm.getLineNumber(cm.getActiveLine()) == line)) { cm.setCursor(LineCharacter.create(line)); } Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { commentManager.insertNewDraft(cm).run(); } }); } } }; }
From source file:com.googlecode.gwtquake.client.GwtKBD.java
License:Apache License
private static int translateMouseButton(NativeEvent evt) { switch (evt.getButton()) { case NativeEvent.BUTTON_LEFT: return Keys.K_MOUSE1; case NativeEvent.BUTTON_RIGHT: return Keys.K_MOUSE2; default://from w w w.ja va 2 s. c om return Keys.K_MOUSE3; } }
From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.VDragDropUtil.java
License:Apache License
private static NativeEvent createMouseDownEvent(NativeEvent e) { return Document.get().createMouseDownEvent(0, e.getScreenX(), e.getScreenY(), e.getClientX(), e.getClientY(), e.getCtrlKey(), e.getAltKey(), e.getShiftKey(), e.getMetaKey(), e.getButton()); }
From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.ui.VLayoutDragDropMouseHandler.java
License:Apache License
/** * Is the mouse down event a valid mouse drag event, i.e. left mouse button * is pressed without any modifier keys//from ww w . java2s .c om * * @param event * The mouse event * @return Is the mouse event a valid drag event */ private boolean isMouseDragEvent(NativeEvent event) { boolean hasModifierKey = event.getAltKey() || event.getCtrlKey() || event.getMetaKey() || event.getShiftKey(); return !(hasModifierKey || event.getButton() > NativeEvent.BUTTON_LEFT); }
From source file:com.spaceapplications.vaadin.addon.eventtimeline.gwt.client.VEventTimelineBrowser.java
public void onDoubleClick(DoubleClickEvent event) { NativeEvent mouseEvent = event.getNativeEvent(); if (scroller.isMouseOverScrollElement((Event) mouseEvent) || scroller.isMouseOverScrollArea((Event) mouseEvent)) { if (mouseEvent.getButton() == NativeEvent.BUTTON_LEFT) { scroller.setLeftPosition(0); scroller.setRightPosition(getOffsetWidth() - 28 - 2); refreshSelection();//from w w w. j a v a2 s . com } } }
From source file:com.vaadin.client.MouseEventDetailsBuilder.java
License:Apache License
/** * Construct a {@link MouseEventDetails} object from the given event * //from www . j a v a2 s . co m * @param evt * The event to use as a source for the details * @param relativeToElement * The element whose position * {@link MouseEventDetails#getRelativeX()} and * {@link MouseEventDetails#getRelativeY()} are relative to. * @return a MouseEventDetails containing information from the event */ public static MouseEventDetails buildMouseEventDetails(NativeEvent evt, Element relativeToElement) { MouseEventDetails mouseEventDetails = new MouseEventDetails(); mouseEventDetails.setType(Event.getTypeInt(evt.getType())); mouseEventDetails.setClientX(WidgetUtil.getTouchOrMouseClientX(evt)); mouseEventDetails.setClientY(WidgetUtil.getTouchOrMouseClientY(evt)); if (evt.getButton() == NativeEvent.BUTTON_LEFT) { mouseEventDetails.setButton(MouseButton.LEFT); } else if (evt.getButton() == NativeEvent.BUTTON_RIGHT) { mouseEventDetails.setButton(MouseButton.RIGHT); } else if (evt.getButton() == NativeEvent.BUTTON_MIDDLE) { mouseEventDetails.setButton(MouseButton.MIDDLE); } else { // IE8 does not always report a button. Assume left. mouseEventDetails.setButton(MouseButton.LEFT); } mouseEventDetails.setAltKey(evt.getAltKey()); mouseEventDetails.setCtrlKey(evt.getCtrlKey()); mouseEventDetails.setMetaKey(evt.getMetaKey()); mouseEventDetails.setShiftKey(evt.getShiftKey()); if (relativeToElement != null) { mouseEventDetails.setRelativeX(getRelativeX(mouseEventDetails.getClientX(), relativeToElement)); mouseEventDetails.setRelativeY(getRelativeY(mouseEventDetails.getClientY(), relativeToElement)); } return mouseEventDetails; }