Search in sources :

Example 11 with NativePreviewEvent

use of com.google.gwt.user.client.Event.NativePreviewEvent in project rstudio by rstudio.

the class RCompletionToolTip method onLoad.

@Override
protected void onLoad() {
    super.onLoad();
    if (nativePreviewReg_ != null) {
        nativePreviewReg_.removeHandler();
        nativePreviewReg_ = null;
    }
    nativePreviewReg_ = Event.addNativePreviewHandler(new NativePreviewHandler() {

        public void onPreviewNativeEvent(NativePreviewEvent e) {
            int eventType = e.getTypeInt();
            if (eventType == Event.ONKEYDOWN || eventType == Event.ONMOUSEDOWN) {
                // dismiss if we've left our anchor zone
                // (defer this so the current key has a chance to 
                // enter the editor and affect the cursor)
                Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                    @Override
                    public void execute() {
                        Position cursorPos = docDisplay_.getCursorPosition();
                        if (anchor_ != null) {
                            Range anchorRange = anchor_.getRange();
                            if (cursorPos.isBeforeOrEqualTo(anchorRange.getStart()) || cursorPos.isAfterOrEqualTo(anchorRange.getEnd())) {
                                anchor_.detach();
                                anchor_ = null;
                                hide();
                            }
                        }
                    }
                });
            }
        }
    });
}
Also used : NativePreviewHandler(com.google.gwt.user.client.Event.NativePreviewHandler) NativePreviewEvent(com.google.gwt.user.client.Event.NativePreviewEvent) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Position(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position) Range(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range)

Example 12 with NativePreviewEvent

use of com.google.gwt.user.client.Event.NativePreviewEvent in project openremote by openremote.

the class PopupPanel method previewNativeEvent.

/**
 * Preview the {@link NativePreviewEvent}.
 *
 * @param event the {@link NativePreviewEvent}
 */
private void previewNativeEvent(NativePreviewEvent event) {
    // If the event has been canceled or consumed, ignore it
    if (event.isCanceled() || (!previewAllNativeEvents && event.isConsumed())) {
        // that popups lower on the stack do not auto hide
        if (modal) {
            event.cancel();
        }
        return;
    }
    // Fire the event hook and return if the event is canceled
    onPreviewNativeEvent(event);
    if (event.isCanceled()) {
        return;
    }
    // If the event targets the popup or the partner, consume it
    Event nativeEvent = Event.as(event.getNativeEvent());
    boolean eventTargetsPopupOrPartner = eventTargetsPopup(nativeEvent) || eventTargetsPartner(nativeEvent);
    if (eventTargetsPopupOrPartner) {
        event.consume();
    }
    // event can be both canceled and consumed.
    if (modal) {
        event.cancel();
    }
    // Switch on the event type
    int type = nativeEvent.getTypeInt();
    switch(type) {
        case Event.ONKEYDOWN:
            {
                if (!onKeyDownPreview((char) nativeEvent.getKeyCode(), KeyboardListenerCollection.getKeyboardModifiers(nativeEvent))) {
                    event.cancel();
                }
                return;
            }
        case Event.ONKEYUP:
            {
                if (!onKeyUpPreview((char) nativeEvent.getKeyCode(), KeyboardListenerCollection.getKeyboardModifiers(nativeEvent))) {
                    event.cancel();
                }
                return;
            }
        case Event.ONKEYPRESS:
            {
                if (!onKeyPressPreview((char) nativeEvent.getKeyCode(), KeyboardListenerCollection.getKeyboardModifiers(nativeEvent))) {
                    event.cancel();
                }
                return;
            }
        case Event.ONMOUSEDOWN:
        case Event.ONTOUCHSTART:
            // interfere with dialog dragging, for example.
            if (DOM.getCaptureElement() != null) {
                event.consume();
                return;
            }
            if (!eventTargetsPopupOrPartner && autoHide) {
                hide(true);
                return;
            }
            break;
        case Event.ONMOUSEUP:
        case Event.ONMOUSEMOVE:
        case Event.ONCLICK:
        case Event.ONDBLCLICK:
        case Event.ONTOUCHEND:
            {
                // interfere with dialog dragging, for example.
                if (DOM.getCaptureElement() != null) {
                    event.consume();
                    return;
                }
                break;
            }
        case Event.ONFOCUS:
            {
                Element target = nativeEvent.getTarget();
                if (modal && !eventTargetsPopupOrPartner && (target != null)) {
                    blur(target);
                    event.cancel();
                    return;
                }
                break;
            }
    }
}
Also used : Element(com.google.gwt.dom.client.Element) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) NativeEvent(com.google.gwt.dom.client.NativeEvent) CloseEvent(com.google.gwt.event.logical.shared.CloseEvent) NativePreviewEvent(com.google.gwt.user.client.Event.NativePreviewEvent) ResizeEvent(com.google.gwt.event.logical.shared.ResizeEvent)

Aggregations

NativePreviewEvent (com.google.gwt.user.client.Event.NativePreviewEvent)12 NativePreviewHandler (com.google.gwt.user.client.Event.NativePreviewHandler)8 Element (com.google.gwt.dom.client.Element)4 Test (org.junit.Test)3 Position (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)3 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)2 NativeEvent (com.google.gwt.dom.client.NativeEvent)2 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)2 GwtTestTest (com.googlecode.gwt.test.GwtTestTest)2 Range (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Range)2 JsArrayString (com.google.gwt.core.client.JsArrayString)1 RepeatingCommand (com.google.gwt.core.client.Scheduler.RepeatingCommand)1 TableRowElement (com.google.gwt.dom.client.TableRowElement)1 AttachEvent (com.google.gwt.event.logical.shared.AttachEvent)1 CloseEvent (com.google.gwt.event.logical.shared.CloseEvent)1 ResizeEvent (com.google.gwt.event.logical.shared.ResizeEvent)1 HandlerRegistration (com.google.gwt.event.shared.HandlerRegistration)1 Event (com.google.gwt.user.client.Event)1 DockPanel (com.google.gwt.user.client.ui.DockPanel)1 FlowPanel (com.google.gwt.user.client.ui.FlowPanel)1