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();
}
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);
}
});
}
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;
}
}
}
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);
}
}
}
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());
}
}
Aggregations