Java Code Examples for com.google.gwt.user.client.Event#ONKEYPRESS
The following examples show how to use
com.google.gwt.user.client.Event#ONKEYPRESS .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SignalKeyLogic.java From swellrt with Apache License 2.0 | 6 votes |
/** * Common logic between Webkit and IE for deciding whether we want the keydown * or the keypress */ private static boolean maybeNullWebkitIE(boolean ret, int typeInt, KeySignalType type) { // Use keydown as the signal for everything except input. // This is because the mutation always happens after the keypress for // input (this is especially important for chrome, // which interleaves deferred commands between keydown and keypress). // // For everything else, keypress is redundant with keydown, and also, the resulting default // dom mutation (if any) often happens after the keydown but before the keypress in webkit. // Also, if the 'Command' key is held for chrome/safari etc, we want to get the keydown // event, NOT the keypress event, for everything because of things like ctrl+c etc. // where sometimes it'll happen just after the keydown, or sometimes we just won't // get a keypress at all if (typeInt == (type == KeySignalType.INPUT ? Event.ONKEYDOWN : Event.ONKEYPRESS)) { return false; } return ret; }
Example 2
Source File: SignalKeyLogic.java From incubator-retired-wave with Apache License 2.0 | 6 votes |
/** * Common logic between Webkit and IE for deciding whether we want the keydown * or the keypress */ private static boolean maybeNullWebkitIE(boolean ret, int typeInt, KeySignalType type) { // Use keydown as the signal for everything except input. // This is because the mutation always happens after the keypress for // input (this is especially important for chrome, // which interleaves deferred commands between keydown and keypress). // // For everything else, keypress is redundant with keydown, and also, the resulting default // dom mutation (if any) often happens after the keydown but before the keypress in webkit. // Also, if the 'Command' key is held for chrome/safari etc, we want to get the keydown // event, NOT the keypress event, for everything because of things like ctrl+c etc. // where sometimes it'll happen just after the keydown, or sometimes we just won't // get a keypress at all if (typeInt == (type == KeySignalType.INPUT ? Event.ONKEYDOWN : Event.ONKEYPRESS)) { return false; } return ret; }
Example 3
Source File: UniTimeTableHeader.java From unitime with Apache License 2.0 | 5 votes |
@Override public void onBrowserEvent(Event event) { switch (DOM.eventGetType(event)) { case Event.ONKEYPRESS: MenuItem item = iAccessKeys.get(Character.toLowerCase((char)event.getCharCode())); if (item != null) { event.stopPropagation(); event.preventDefault(); item.getScheduledCommand().execute(); } } super.onBrowserEvent(event); }
Example 4
Source File: EventWrapper.java From swellrt with Apache License 2.0 | 5 votes |
public static String asString(Event event) { // Start with the event type string String string = DOM.eventGetTypeString(event); // Next type-specific fields switch (event.getTypeInt()) { case Event.ONKEYPRESS: case Event.ONKEYUP: case Event.ONKEYDOWN: string += key(event) + modifiers(event); break; case Event.ONCLICK: case Event.ONDBLCLICK: case Event.ONMOUSEMOVE: string += mousePoint(event) + modifiers(event); break; case Event.ONMOUSEDOWN: case Event.ONMOUSEUP: string += mousePoint(event) + mouseButtons(event) + modifiers(event); break; case Event.ONMOUSEOUT: string += mousePoint(event) + modifiers(event) + " to: " + getToElement(event); break; case Event.ONMOUSEOVER: string += mousePoint(event) + modifiers(event) + " from: " + getFromElement(event); break; case Event.ONMOUSEWHEEL: string += " " + getMouseWheelVelocityY(event) + mousePoint(event) + modifiers(event); break; case Event.ONFOCUS: case Event.ONBLUR: case Event.ONCHANGE: case Event.ONERROR: case Event.ONLOAD: case Event.ONLOSECAPTURE: case Event.ONSCROLL: break; } return string; }
Example 5
Source File: AbstractInputSelect.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void onBrowserEvent(Event event) { super.onBrowserEvent(event); boolean mustKillEvent = false; switch (DOM.eventGetType(event)) { case Event.ONKEYDOWN: switch (event.getKeyCode()) { case KeyCodes.KEY_HOME: this.selectionHandler.onHomeKeyDown(); mustKillEvent = true; break; case KeyCodes.KEY_END: this.selectionHandler.onEndKeyDown(); mustKillEvent = true; break; case KeyCodes.KEY_UP: this.selectionHandler.onUpKeyDown(); mustKillEvent = true; break; case KeyCodes.KEY_DOWN: this.selectionHandler.onDownKeyDown(); mustKillEvent = true; break; default: break; } break; case Event.ONKEYPRESS: this.keyPressHandler.handleKeyPress(event.getCharCode()); break; default: break; } if (mustKillEvent) { event.preventDefault(); event.stopPropagation(); } }
Example 6
Source File: EventWrapper.java From incubator-retired-wave with Apache License 2.0 | 5 votes |
public static String asString(Event event) { // Start with the event type string String string = DOM.eventGetTypeString(event); // Next type-specific fields switch (event.getTypeInt()) { case Event.ONKEYPRESS: case Event.ONKEYUP: case Event.ONKEYDOWN: string += key(event) + modifiers(event); break; case Event.ONCLICK: case Event.ONDBLCLICK: case Event.ONMOUSEMOVE: string += mousePoint(event) + modifiers(event); break; case Event.ONMOUSEDOWN: case Event.ONMOUSEUP: string += mousePoint(event) + mouseButtons(event) + modifiers(event); break; case Event.ONMOUSEOUT: string += mousePoint(event) + modifiers(event) + " to: " + getToElement(event); break; case Event.ONMOUSEOVER: string += mousePoint(event) + modifiers(event) + " from: " + getFromElement(event); break; case Event.ONMOUSEWHEEL: string += " " + getMouseWheelVelocityY(event) + mousePoint(event) + modifiers(event); break; case Event.ONFOCUS: case Event.ONBLUR: case Event.ONCHANGE: case Event.ONERROR: case Event.ONLOAD: case Event.ONLOSECAPTURE: case Event.ONSCROLL: break; } return string; }
Example 7
Source File: AboutPopup.java From document-management-system with GNU General Public License v2.0 | 4 votes |
public void onPreviewNativeEvent(NativePreviewEvent event) { if (event.getTypeInt() == Event.ONKEYPRESS) { futurama.evaluateKey((char) event.getNativeEvent().getKeyCode()); } }
Example 8
Source File: CubaPopupButtonWidget.java From cuba with Apache License 2.0 | 4 votes |
@Override protected boolean handleKeyboardEvents(Event event) { int type = DOM.eventGetType(event); // Synthesize clicks based on keyboard events AFTER the normal key // handling. if ((event.getTypeInt() & Event.KEYEVENTS) != 0) { switch (type) { case Event.ONKEYDOWN: // Button should not react on shortcuts with ENTER and SPACE if (isShortcut(event) && (event.getKeyCode() == KeyCodes.KEY_ENTER || event.getKeyCode() == KeyCodes.KEY_SPACE)) { return true; } // Stop propagation when the user starts pressing a button that // we are handling to prevent actions from getting triggered if (event.getKeyCode() == KeyCodes.KEY_SPACE) { isFocusing = true; event.preventDefault(); event.stopPropagation(); return true; } else if (event.getKeyCode() == KeyCodes.KEY_ENTER) { isFocusing = true; event.stopPropagation(); return true; } else if (event.getKeyCode() == KeyCodes.KEY_DOWN) { isFocusing = true; event.stopPropagation(); } break; // CAUTION IE sometimes does not generate ONKEYPRESS for ENTER, so we override default Vaadin behavior case Event.ONKEYUP: if (isFocusing) { if (event.getKeyCode() == KeyCodes.KEY_SPACE) { isFocusing = false; onClick(); event.stopPropagation(); event.preventDefault(); return true; } else if (event.getKeyCode() == KeyCodes.KEY_ENTER) { isFocusing = false; onClick(); event.stopPropagation(); event.preventDefault(); return true; } else if (event.getKeyCode() == KeyCodes.KEY_DOWN) { isFocusing = false; onClick(); event.stopPropagation(); event.preventDefault(); return true; } } else if (isShortcut(event) && (event.getKeyCode() == KeyCodes.KEY_ENTER || event.getKeyCode() == KeyCodes.KEY_SPACE)) { return true; } break; case Event.ONKEYPRESS: { // Button should not react on shortcuts with ENTER and SPACE if (isShortcut(event) && (event.getKeyCode() == KeyCodes.KEY_ENTER || event.getKeyCode() == KeyCodes.KEY_SPACE)) { return true; } } } } return false; }
Example 9
Source File: CubaButtonWidget.java From cuba with Apache License 2.0 | 4 votes |
@Override protected boolean handleKeyboardEvents(Event event) { int type = DOM.eventGetType(event); // Synthesize clicks based on keyboard events AFTER the normal key // handling. if ((event.getTypeInt() & Event.KEYEVENTS) != 0) { switch (type) { case Event.ONKEYDOWN: // Button should not react on shortcuts with ENTER and SPACE if (isShortcut(event) && (event.getKeyCode() == KeyCodes.KEY_ENTER || event.getKeyCode() == KeyCodes.KEY_SPACE)) { return true; } // Stop propagation when the user starts pressing a button that // we are handling to prevent actions from getting triggered if (event.getKeyCode() == KeyCodes.KEY_SPACE) { isFocusing = true; event.preventDefault(); event.stopPropagation(); return true; } else if (event.getKeyCode() == KeyCodes.KEY_ENTER) { isFocusing = true; event.preventDefault(); event.stopPropagation(); return true; } break; // CAUTION IE sometimes does not generate ONKEYPRESS for ENTER, so we override default Vaadin behavior case Event.ONKEYUP: if (isFocusing) { if (event.getKeyCode() == KeyCodes.KEY_SPACE) { isFocusing = false; onClick(); event.stopPropagation(); event.preventDefault(); return true; } else if (event.getKeyCode() == KeyCodes.KEY_ENTER) { isFocusing = false; onClick(); event.stopPropagation(); event.preventDefault(); return true; } } else if (isShortcut(event) && (event.getKeyCode() == KeyCodes.KEY_ENTER || event.getKeyCode() == KeyCodes.KEY_SPACE)) { return true; } break; case Event.ONKEYPRESS: { // Button should not react on shortcuts with ENTER and SPACE if (isShortcut(event) && (event.getKeyCode() == KeyCodes.KEY_ENTER || event.getKeyCode() == KeyCodes.KEY_SPACE)) { return true; } } } } return false; }
Example 10
Source File: PopupButtonConnector.java From cuba with Apache License 2.0 | 4 votes |
public void onPreviewNativeEvent(NativePreviewEvent event) { if (isEnabled()) { Element target = Element .as(event.getNativeEvent().getEventTarget()); switch (event.getTypeInt()) { case Event.ONCLICK: if (getWidget().isOrHasChildOfButton(target)) { if (getState().popupVisible && getState().buttonClickTogglesPopupVisibility) { getWidget().sync(); rpc.setPopupVisible(false); } } break; case Event.ONMOUSEDOWN: if (!getWidget().isOrHasChildOfPopup(target) && !getWidget().isOrHasChildOfConsole(target) && !getWidget().isOrHasChildOfButton(target) && getState().closePopupOnOutsideClick) { if (getState().popupVisible) { getWidget().sync(); rpc.setPopupVisible(false); } } break; case Event.ONKEYPRESS: if (getWidget().isOrHasChildOfPopup(target)) { // Catch children that use keyboard, so we can unfocus // them // when // hiding getWidget().addToActiveChildren(target); } break; case Event.ONKEYDOWN: if (getState().popupVisible) { getWidget().onKeyDownOnVisiblePopup(event.getNativeEvent(), this); } break; default: break; } } }
Example 11
Source File: SuggestionMenu.java From swellrt with Apache License 2.0 | 4 votes |
private void handleEventInner(Event event) { switch (DOM.eventGetType(event)) { case Event.ONCONTEXTMENU: event.preventDefault(); break; case Event.ONKEYPRESS: case Event.ONKEYDOWN: { // NOTE(user): It is necessary to stop propagation on the key events to // prevent them from leaking to the blip/wave presenters. int keyCode = DOM.eventGetKeyCode(event); // Move left/right to previous/next drop down widget switch (keyCode) { case KeyCodes.KEY_LEFT: case KeyCodes.KEY_RIGHT: handler.handleLeftRight(keyCode == KeyCodes.KEY_RIGHT); event.stopPropagation(); return; case KeyCodes.KEY_ENTER: event.stopPropagation(); } if (keyCode >= '1' && keyCode <= '9') { // TODO(danilatos): Is this ok? i18n etc? int index = keyCode - '1'; if (index >= 0 && index < getItems().size()) { MenuItem item = getItems().get(index); if (item == null) { return; } item.getCommand().execute(); DOM.eventPreventDefault(event); } } break; } case Event.ONMOUSEOUT: { // Need to check that we really seem to have left the menu, as // mouse-out events get triggered whenever the mouse moves between // selections in the menu. EventTarget target = event.getRelatedEventTarget(); Element targetElement = Element.as(target); if (!getElement().isOrHasChild(targetElement)) { handler.handleMouseOut(); } break; } case Event.ONMOUSEOVER: { handler.handleMouseOver(); break; } } }
Example 12
Source File: SuggestionMenu.java From incubator-retired-wave with Apache License 2.0 | 4 votes |
private void handleEventInner(Event event) { switch (DOM.eventGetType(event)) { case Event.ONCONTEXTMENU: event.preventDefault(); break; case Event.ONKEYPRESS: case Event.ONKEYDOWN: { // NOTE(user): It is necessary to stop propagation on the key events to // prevent them from leaking to the blip/wave presenters. int keyCode = DOM.eventGetKeyCode(event); // Move left/right to previous/next drop down widget switch (keyCode) { case KeyCodes.KEY_LEFT: case KeyCodes.KEY_RIGHT: handler.handleLeftRight(keyCode == KeyCodes.KEY_RIGHT); event.stopPropagation(); return; case KeyCodes.KEY_ENTER: event.stopPropagation(); } if (keyCode >= '1' && keyCode <= '9') { // TODO(danilatos): Is this ok? i18n etc? int index = keyCode - '1'; if (index >= 0 && index < getItems().size()) { MenuItem item = getItems().get(index); if (item == null) { return; } item.getCommand().execute(); DOM.eventPreventDefault(event); } } break; } case Event.ONMOUSEOUT: { // Need to check that we really seem to have left the menu, as // mouse-out events get triggered whenever the mouse moves between // selections in the menu. EventTarget target = event.getRelatedEventTarget(); Element targetElement = Element.as(target); if (!getElement().isOrHasChild(targetElement)) { handler.handleMouseOut(); } break; } case Event.ONMOUSEOVER: { handler.handleMouseOver(); break; } } }