Search in sources :

Example 36 with NativeEvent

use of com.google.gwt.dom.client.NativeEvent in project che by eclipse.

the class KeyboardNavigationHandler method handleEvent.

public void handleEvent(NativeEvent event) {
    int code = event.getKeyCode();
    NativeEvent e = event;
    String type = event.getType();
    if ("keydown".equals(type) && keyEvent == Event.ONKEYDOWN || "keypress".equals(type) && keyEvent == Event.ONKEYPRESS) {
    } else {
        return;
    }
    if (component != null && component.getElement() != e.getCurrentEventTarget().cast()) {
        return;
    }
    if (preventDefault) {
        event.preventDefault();
    }
    onKeyPress(e);
    switch(code) {
        case KeyCodes.KEY_ALT:
            onAlt(e);
            break;
        case KeyCodes.KEY_BACKSPACE:
            onBackspace(e);
            break;
        case KeyCodes.KEY_CTRL:
            onControl(e);
            break;
        case KeyCodes.KEY_DELETE:
            onDelete(e);
            break;
        case KeyCodes.KEY_DOWN:
            onDown(e);
            break;
        case KeyCodes.KEY_END:
            onEnd(e);
            break;
        case KeyCodes.KEY_ENTER:
            onEnter(e);
            break;
        case KeyCodes.KEY_ESCAPE:
            onEsc(e);
            break;
        case KeyCodes.KEY_HOME:
            onHome(e);
            break;
        case KeyCodes.KEY_LEFT:
            onLeft(e);
            break;
        case KeyCodes.KEY_PAGEDOWN:
            onPageDown(e);
            break;
        case KeyCodes.KEY_PAGEUP:
            onPageUp(e);
            break;
        case KeyCodes.KEY_SHIFT:
            onShift(e);
            break;
        case KeyCodes.KEY_TAB:
            onTab(e);
            break;
        case KeyCodes.KEY_RIGHT:
            onRight(e);
            break;
        case KeyCodes.KEY_UP:
            onUp(e);
            break;
    }
}
Also used : NativeEvent(com.google.gwt.dom.client.NativeEvent)

Example 37 with NativeEvent

use of com.google.gwt.dom.client.NativeEvent in project libgdx by libgdx.

the class AssetDownloader method loadImage.

public void loadImage(final String url, final String mimeType, final String crossOrigin, final AssetLoaderListener<ImageElement> listener) {
    if (useBrowserCache || useInlineBase64) {
        loadBinary(url, new AssetLoaderListener<Blob>() {

            @Override
            public void onProgress(double amount) {
                listener.onProgress(amount);
            }

            @Override
            public void onFailure() {
                listener.onFailure();
            }

            @Override
            public void onSuccess(Blob result) {
                final ImageElement image = createImage();
                if (crossOrigin != null) {
                    image.setAttribute("crossOrigin", crossOrigin);
                }
                hookImgListener(image, new ImgEventListener() {

                    @Override
                    public void onEvent(NativeEvent event) {
                        if (event.getType().equals("error"))
                            listener.onFailure();
                        else
                            listener.onSuccess(image);
                    }
                });
                if (isUseInlineBase64()) {
                    image.setSrc("data:" + mimeType + ";base64," + result.toBase64());
                } else {
                    image.setSrc(url);
                }
            }
        });
    } else {
        final ImageElement image = createImage();
        if (crossOrigin != null) {
            image.setAttribute("crossOrigin", crossOrigin);
        }
        hookImgListener(image, new ImgEventListener() {

            @Override
            public void onEvent(NativeEvent event) {
                if (event.getType().equals("error"))
                    listener.onFailure();
                else
                    listener.onSuccess(image);
            }
        });
        image.setSrc(url);
    }
}
Also used : ImageElement(com.google.gwt.dom.client.ImageElement) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Example 38 with NativeEvent

use of com.google.gwt.dom.client.NativeEvent in project rstudio by rstudio.

the class ShortcutManager method swallowEvents.

private void swallowEvents(Object object) {
    NativeEvent event = (NativeEvent) object;
    // when seeing unhandled keys.
    if (!keyBuffer_.isEmpty()) {
        for (Map.Entry<KeyMapType, KeyMap> entry : keyMaps_.entrySet()) {
            if (entry.getValue().isPrefix(keyBuffer_)) {
                event.stopPropagation();
                event.preventDefault();
                return;
            }
        }
    }
    // Prevent backspace from performing a browser 'back'
    if (DomUtils.preventBackspaceCausingBrowserBack(event))
        return;
    // Suppress save / quit events from reaching the browser
    KeyCombination keys = new KeyCombination(event);
    int keyCode = keys.getKeyCode();
    int modifiers = keys.getModifier();
    boolean isSaveQuitKey = keyCode == KeyCodes.KEY_S || keyCode == KeyCodes.KEY_W;
    boolean isSaveQuitModifier = BrowseCap.isMacintosh() ? modifiers == KeyboardShortcut.META : modifiers == KeyboardShortcut.CTRL;
    if (isSaveQuitKey && isSaveQuitModifier)
        event.preventDefault();
    // Prevent 'Ctrl+Shift+B' (toggle bookmarks)
    boolean isToggleBookmarksModifier = BrowseCap.isMacintosh() ? modifiers == (KeyboardShortcut.SHIFT | KeyboardShortcut.META) : modifiers == (KeyboardShortcut.SHIFT | KeyboardShortcut.CTRL);
    if (keyCode == KeyCodes.KEY_B && isToggleBookmarksModifier)
        event.preventDefault();
}
Also used : KeyCombination(org.rstudio.core.client.command.KeyboardShortcut.KeyCombination) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) KeyMapType(org.rstudio.core.client.command.KeyMap.KeyMapType) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Example 39 with NativeEvent

use of com.google.gwt.dom.client.NativeEvent in project rstudio by rstudio.

the class WindowEx method fireBlurHandlers.

private static void fireBlurHandlers() {
    NativeEvent nativeEvent = Document.get().createBlurEvent();
    BlurEvent.fireNativeEvent(nativeEvent, new HasHandlers() {

        public void fireEvent(GwtEvent<?> event) {
            handlers_.fireEvent(event);
        }
    });
}
Also used : HasHandlers(com.google.gwt.event.shared.HasHandlers) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Example 40 with NativeEvent

use of com.google.gwt.dom.client.NativeEvent in project rstudio by rstudio.

the class ModalDialogBase method onPreviewNativeEvent.

@Override
public void onPreviewNativeEvent(Event.NativePreviewEvent event) {
    if (!ModalDialogTracker.isTopMost(this))
        return;
    if (event.getTypeInt() == Event.ONKEYDOWN) {
        NativeEvent nativeEvent = event.getNativeEvent();
        switch(nativeEvent.getKeyCode()) {
            case KeyCodes.KEY_ENTER:
                if (enterDisabled_)
                    break;
                // allow Enter on textareas
                Element e = DomUtils.getActiveElement();
                if (e.hasTagName("TEXTAREA"))
                    return;
                ThemedButton defaultButton = defaultOverrideButton_ == null ? okButton_ : defaultOverrideButton_;
                if ((defaultButton != null) && defaultButton.isEnabled()) {
                    nativeEvent.preventDefault();
                    nativeEvent.stopPropagation();
                    event.cancel();
                    defaultButton.click();
                }
                break;
            case KeyCodes.KEY_ESCAPE:
                if (escapeDisabled_)
                    break;
                onEscapeKeyDown(event);
                break;
        }
    }
}
Also used : Element(com.google.gwt.dom.client.Element) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Aggregations

NativeEvent (com.google.gwt.dom.client.NativeEvent)72 Element (com.google.gwt.dom.client.Element)20 Test (org.junit.Test)12 Column (com.google.gwt.user.cellview.client.Column)8 ValueUpdater (com.google.gwt.cell.client.ValueUpdater)6 EventTarget (com.google.gwt.dom.client.EventTarget)6 SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)5 MonacoStandaloneCodeEditor (org.uberfire.client.views.pfly.monaco.jsinterop.MonacoStandaloneCodeEditor)5 AbstractCell (com.google.gwt.cell.client.AbstractCell)4 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)4 Context (com.google.gwt.cell.client.Cell.Context)3 JsArrayString (com.google.gwt.core.client.JsArrayString)3 Scheduler (com.google.gwt.core.client.Scheduler)3 Style (com.google.gwt.dom.client.Style)3 TableRowElement (com.google.gwt.dom.client.TableRowElement)3 BlurEvent (com.google.gwt.event.dom.client.BlurEvent)3 Widget (com.google.gwt.user.client.ui.Widget)3 HTMLButtonElement (elemental2.dom.HTMLButtonElement)3 Button (org.gwtbootstrap3.client.ui.Button)3 Icon (org.gwtbootstrap3.client.ui.Icon)3