Search in sources :

Example 21 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 22 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 23 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)

Example 24 with NativeEvent

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

the class ModifyKeyboardShortcutsWidget method onNameCellPreview.

private void onNameCellPreview(CellPreviewEvent<KeyboardShortcutEntry> preview) {
    NativeEvent event = preview.getNativeEvent();
    String type = event.getType();
    if (type.equals("blur")) {
        buffer_.clear();
    } else if (type.equals("keydown")) {
        int keyCode = event.getKeyCode();
        int modifiers = KeyboardShortcut.getModifierValue(event);
        if (keyCode == KeyCodes.KEY_ESCAPE && modifiers == 0) {
            event.stopPropagation();
            event.preventDefault();
            filterWidget_.focus();
        } else if (keyCode == KeyCodes.KEY_ENTER && modifiers == 0) {
            event.stopPropagation();
            event.preventDefault();
            table_.setKeyboardSelectedColumn(1);
        }
    }
}
Also used : JsArrayString(com.google.gwt.core.client.JsArrayString) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Example 25 with NativeEvent

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

the class ModifyKeyboardShortcutsWidget method onShortcutCellPreview.

private void onShortcutCellPreview(CellPreviewEvent<KeyboardShortcutEntry> preview) {
    NativeEvent event = preview.getNativeEvent();
    String type = event.getType();
    if (type.equals("keydown")) {
        int keyCode = event.getKeyCode();
        int modifiers = KeyboardShortcut.getModifierValue(event);
        // widget process)
        if (keyCode == KeyCodes.KEY_ENTER && modifiers == 0)
            return;
        // Handle any other key events.
        if (modifiers != 0)
            swallowNextKeyUpEvent_ = true;
        event.stopPropagation();
        event.preventDefault();
        if (KeyboardHelper.isModifierKey(event.getKeyCode()))
            return;
        if (keyCode == KeyCodes.KEY_BACKSPACE && modifiers == 0) {
            buffer_.pop();
        } else if (keyCode == KeyCodes.KEY_DELETE && modifiers == 0) {
            buffer_.clear();
        } else if (keyCode == KeyCodes.KEY_ESCAPE && modifiers == 0) {
            buffer_.set(preview.getValue().getOriginalKeySequence());
        } else {
            buffer_.add(event);
        }
        // Sneak into the element and find the active <input>, then update it.
        Element el = getElement(table_, preview.getIndex(), preview.getColumn());
        Element input = el.getFirstChildElement().getFirstChildElement();
        if (input == null)
            return;
        assert input.getTagName().toLowerCase().equals("input") : "Failed to find <input> element in table";
        String bufferString = buffer_.toString();
        input.setAttribute("value", bufferString);
        input.setInnerHTML(bufferString);
        // Move the cursor to the end of the selection.
        DomUtils.setSelectionRange(input, bufferString.length(), bufferString.length());
    }
}
Also used : Element(com.google.gwt.dom.client.Element) TableRowElement(com.google.gwt.dom.client.TableRowElement) JsArrayString(com.google.gwt.core.client.JsArrayString) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Aggregations

NativeEvent (com.google.gwt.dom.client.NativeEvent)35 Element (com.google.gwt.dom.client.Element)7 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)3 JsArrayString (com.google.gwt.core.client.JsArrayString)3 TableRowElement (com.google.gwt.dom.client.TableRowElement)3 Column (com.google.gwt.user.cellview.client.Column)3 D3 (org.opennms.features.topology.app.internal.gwt.client.d3.D3)3 MarqueeSelectHandler (org.opennms.features.topology.app.internal.gwt.client.handler.MarqueeSelectHandler)3 PanHandler (org.opennms.features.topology.app.internal.gwt.client.handler.PanHandler)3 SVGGElement (org.opennms.features.topology.app.internal.gwt.client.svg.SVGGElement)3 Context (com.google.gwt.cell.client.Cell.Context)2 ValueUpdater (com.google.gwt.cell.client.ValueUpdater)2 JsArray (com.google.gwt.core.client.JsArray)2 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)2 EventTarget (com.google.gwt.dom.client.EventTarget)2 ImageElement (com.google.gwt.dom.client.ImageElement)2 HasHandlers (com.google.gwt.event.shared.HasHandlers)2 ImageResource (com.google.gwt.resources.client.ImageResource)2 ListHandler (com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler)2 HTML (com.google.gwt.user.client.ui.HTML)2