Example usage for com.google.gwt.user.client Element dispatchEvent

List of usage examples for com.google.gwt.user.client Element dispatchEvent

Introduction

In this page you can find the example usage for com.google.gwt.user.client Element dispatchEvent.

Prototype

@Override
    public void dispatchEvent(NativeEvent evt) 

Source Link

Usage

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);//from  www  .j  a va 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) {
            }

        }
    });

}