Search in sources :

Example 41 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 42 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)

Example 43 with NativeEvent

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

the class InlineToolbarButton method addClickHandler.

@Override
public HandlerRegistration addClickHandler(ClickHandler clickHandler) {
    /*
       * When we directly subscribe to this widget's ClickEvent, sometimes the
       * click gets ignored (inconsistent repro but it happens enough to be
       * annoying). Doing it this way fixes it.
       */
    hasHandlers_.addHandler(ClickEvent.getType(), clickHandler);
    final HandlerRegistration mouseDown = addDomHandler(new MouseDownHandler() {

        public void onMouseDown(MouseDownEvent event) {
            event.preventDefault();
            event.stopPropagation();
            down_ = true;
        }
    }, MouseDownEvent.getType());
    final HandlerRegistration mouseOut = addDomHandler(new MouseOutHandler() {

        public void onMouseOut(MouseOutEvent event) {
            event.preventDefault();
            event.stopPropagation();
            down_ = false;
        }
    }, MouseOutEvent.getType());
    final HandlerRegistration mouseUp = addDomHandler(new MouseUpHandler() {

        public void onMouseUp(MouseUpEvent event) {
            event.preventDefault();
            event.stopPropagation();
            if (down_) {
                down_ = false;
                NativeEvent clickEvent = Document.get().createClickEvent(1, event.getScreenX(), event.getScreenY(), event.getClientX(), event.getClientY(), event.getNativeEvent().getCtrlKey(), event.getNativeEvent().getAltKey(), event.getNativeEvent().getShiftKey(), event.getNativeEvent().getMetaKey());
                DomEvent.fireNativeEvent(clickEvent, hasHandlers_);
            }
        }
    }, MouseUpEvent.getType());
    return new HandlerRegistration() {

        public void removeHandler() {
            mouseDown.removeHandler();
            mouseOut.removeHandler();
            mouseUp.removeHandler();
        }
    };
}
Also used : HandlerRegistration(com.google.gwt.event.shared.HandlerRegistration) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Example 44 with NativeEvent

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

the class AceEditorBackgroundLinkHighlighter method onMouseUp.

@Override
public void onMouseUp(MouseUpEvent mouseUpEvent) {
    // clicks handled in 'onAceClick' for OS X web mode
    if (BrowseCap.isMacintosh() && !BrowseCap.isMacintoshDesktop())
        return;
    NativeEvent event = mouseUpEvent.getNativeEvent();
    if (!isRequiredClickModifier(event))
        return;
    MarkerRegistration marker = getTargetedMarker(event);
    if (marker == null)
        return;
    boolean hasMouseMoved = Math.abs(event.getClientX() - mouseTracker_.getLastMouseX()) >= 2 || Math.abs(event.getClientY() - mouseTracker_.getLastMouseY()) >= 2;
    if (hasMouseMoved)
        return;
    event.stopPropagation();
    event.preventDefault();
    endDetectClickTarget();
    String url = editor_.getTextForRange(marker.getRange());
    navigateToUrl(url);
}
Also used : NativeEvent(com.google.gwt.dom.client.NativeEvent)

Example 45 with NativeEvent

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

the class ChunkOptionsPopupPanel method makeInputBox.

private TextBox makeInputBox(final String option, final boolean enquote) {
    final TextBox box = new TextBox();
    box.getElement().setAttribute("placeholder", "Default");
    box.setWidth("40px");
    DomUtils.addKeyHandlers(box, new NativeEventHandler() {

        @Override
        public void onNativeEvent(NativeEvent event) {
            Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                @Override
                public void execute() {
                    String text = box.getText().trim();
                    boolean isEmpty = StringUtil.isNullOrEmpty(text);
                    if (enquote && !isEmpty) {
                        text = StringUtil.ensureQuoted(text);
                        text = text.replaceAll("\\\\", "\\\\\\\\");
                    }
                    if (isEmpty)
                        unset(option);
                    else
                        set(option, text);
                    synchronize();
                }
            });
        }
    });
    return box;
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) NativeEventHandler(org.rstudio.core.client.dom.DomUtils.NativeEventHandler) TextBox(com.google.gwt.user.client.ui.TextBox) 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