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