use of com.google.gwt.user.client.Event.NativePreviewEvent in project rstudio by rstudio.
the class RCompletionToolTip method onLoad.
@Override
protected void onLoad() {
super.onLoad();
if (nativePreviewReg_ != null) {
nativePreviewReg_.removeHandler();
nativePreviewReg_ = null;
}
nativePreviewReg_ = Event.addNativePreviewHandler(new NativePreviewHandler() {
public void onPreviewNativeEvent(NativePreviewEvent e) {
int eventType = e.getTypeInt();
if (eventType == Event.ONKEYDOWN || eventType == Event.ONMOUSEDOWN) {
// dismiss if we've left our anchor zone
// (defer this so the current key has a chance to
// enter the editor and affect the cursor)
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
Position cursorPos = docDisplay_.getCursorPosition();
if (anchor_ != null) {
Range anchorRange = anchor_.getRange();
if (cursorPos.isBeforeOrEqualTo(anchorRange.getStart()) || cursorPos.isAfterOrEqualTo(anchorRange.getEnd())) {
anchor_.detach();
anchor_ = null;
hide();
}
}
}
});
}
}
});
}
use of com.google.gwt.user.client.Event.NativePreviewEvent in project openremote by openremote.
the class PopupPanel method previewNativeEvent.
/**
* Preview the {@link NativePreviewEvent}.
*
* @param event the {@link NativePreviewEvent}
*/
private void previewNativeEvent(NativePreviewEvent event) {
// If the event has been canceled or consumed, ignore it
if (event.isCanceled() || (!previewAllNativeEvents && event.isConsumed())) {
// that popups lower on the stack do not auto hide
if (modal) {
event.cancel();
}
return;
}
// Fire the event hook and return if the event is canceled
onPreviewNativeEvent(event);
if (event.isCanceled()) {
return;
}
// If the event targets the popup or the partner, consume it
Event nativeEvent = Event.as(event.getNativeEvent());
boolean eventTargetsPopupOrPartner = eventTargetsPopup(nativeEvent) || eventTargetsPartner(nativeEvent);
if (eventTargetsPopupOrPartner) {
event.consume();
}
// event can be both canceled and consumed.
if (modal) {
event.cancel();
}
// Switch on the event type
int type = nativeEvent.getTypeInt();
switch(type) {
case Event.ONKEYDOWN:
{
if (!onKeyDownPreview((char) nativeEvent.getKeyCode(), KeyboardListenerCollection.getKeyboardModifiers(nativeEvent))) {
event.cancel();
}
return;
}
case Event.ONKEYUP:
{
if (!onKeyUpPreview((char) nativeEvent.getKeyCode(), KeyboardListenerCollection.getKeyboardModifiers(nativeEvent))) {
event.cancel();
}
return;
}
case Event.ONKEYPRESS:
{
if (!onKeyPressPreview((char) nativeEvent.getKeyCode(), KeyboardListenerCollection.getKeyboardModifiers(nativeEvent))) {
event.cancel();
}
return;
}
case Event.ONMOUSEDOWN:
case Event.ONTOUCHSTART:
// interfere with dialog dragging, for example.
if (DOM.getCaptureElement() != null) {
event.consume();
return;
}
if (!eventTargetsPopupOrPartner && autoHide) {
hide(true);
return;
}
break;
case Event.ONMOUSEUP:
case Event.ONMOUSEMOVE:
case Event.ONCLICK:
case Event.ONDBLCLICK:
case Event.ONTOUCHEND:
{
// interfere with dialog dragging, for example.
if (DOM.getCaptureElement() != null) {
event.consume();
return;
}
break;
}
case Event.ONFOCUS:
{
Element target = nativeEvent.getTarget();
if (modal && !eventTargetsPopupOrPartner && (target != null)) {
blur(target);
event.cancel();
return;
}
break;
}
}
}
Aggregations