use of com.google.gwt.user.client.Event.NativePreviewHandler in project rstudio by rstudio.
the class DiagnosticsBackgroundPopup method start.
public void start() {
isRunning_ = true;
stopRequested_ = false;
if (handler_ != null) {
handler_.removeHandler();
handler_ = null;
}
handler_ = Event.addNativePreviewHandler(new NativePreviewHandler() {
@Override
public void onPreviewNativeEvent(NativePreviewEvent event) {
if (event.getTypeInt() == Event.ONMOUSEMOVE) {
movedMouseMostRecently_ = true;
Element target = Element.as(event.getNativeEvent().getEventTarget());
if (target.hasClassName("ace_gutter-cell")) {
lastMouseCoords_ = null;
hidePopup();
return;
}
lastMouseCoords_ = ScreenCoordinates.create(event.getNativeEvent().getClientX(), event.getNativeEvent().getClientY());
if (activeMarker_ != null && !activeMarker_.getRange().containsRightExclusive(editor_.toDocumentPosition(lastMouseCoords_))) {
hidePopup();
}
} else {
movedMouseMostRecently_ = false;
}
}
});
Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
@Override
public boolean execute() {
if (stopRequested_)
return stopExecution();
// restarted later)
if (!docDisplay_.isFocused())
return stopExecution();
long currentTime = System.currentTimeMillis();
long lastModifiedTime = docDisplay_.getLastModifiedTime();
long lastCursorChangedTime = docDisplay_.getLastCursorChangedTime();
// cursor was moved recently, then bail
if ((currentTime - lastModifiedTime) < 500)
return completeExecution();
if ((currentTime - lastCursorChangedTime) < 500)
return completeExecution();
Markers markers = editor_.getSession().getMarkers(true);
Position currentPos;
if (movedMouseMostRecently_) {
if (lastMouseCoords_ == null)
return completeExecution();
currentPos = editor_.toDocumentPosition(lastMouseCoords_);
} else {
currentPos = docDisplay_.getCursorPosition();
}
int[] keys = markers.getIds();
for (int i = 0; i < keys.length; i++) {
Marker marker = markers.get(keys[i]);
if (marker.getRange().containsRightExclusive(currentPos)) {
displayMarkerDiagnostics(marker);
return completeExecution();
}
}
return completeExecution();
}
}, 500);
}
use of com.google.gwt.user.client.Event.NativePreviewHandler in project rstudio by rstudio.
the class MiniPopupPanel method addDragHandler.
private void addDragHandler() {
if (dragHandler_ != null)
dragHandler_.removeHandler();
dragHandler_ = Event.addNativePreviewHandler(new NativePreviewHandler() {
@Override
public void onPreviewNativeEvent(NativePreviewEvent npe) {
if (npe.getNativeEvent().getButton() != NativeEvent.BUTTON_LEFT)
return;
int type = npe.getTypeInt();
if (type == Event.ONMOUSEDOWN || type == Event.ONMOUSEMOVE || type == Event.ONMOUSEUP) {
if (dragging_) {
handleDrag(npe);
return;
}
Element target = npe.getNativeEvent().getEventTarget().cast();
String tagName = target.getTagName().toLowerCase();
for (String tag : TAGS_EXCLUDE_DRAG) if (tagName.equals(tag))
return;
if (DomUtils.isDescendantOfElementWithTag(target, TAGS_EXCLUDE_DRAG))
return;
Element self = MiniPopupPanel.this.getElement();
if (!DomUtils.isDescendant(target, self))
return;
handleDrag(npe);
}
}
});
}
use of com.google.gwt.user.client.Event.NativePreviewHandler in project rstudio by rstudio.
the class AceEditorBackgroundLinkHighlighter method onAttachOrDetach.
// Event Handlers ---
@Override
public void onAttachOrDetach(AttachEvent event) {
if (event.isAttached()) {
previewHandler_ = Event.addNativePreviewHandler(new NativePreviewHandler() {
@Override
public void onPreviewNativeEvent(NativePreviewEvent preview) {
int type = preview.getTypeInt();
if (type == Event.ONKEYDOWN) {
int modifier = KeyboardShortcut.getModifierValue(preview.getNativeEvent());
beginDetectClickTarget(mouseTracker_.getLastMouseX(), mouseTracker_.getLastMouseY(), modifier);
} else if (type == Event.ONKEYUP) {
endDetectClickTarget();
}
}
});
} else {
for (HandlerRegistration handler : handlers_) handler.removeHandler();
handlers_.clear();
if (previewHandler_ != null) {
previewHandler_.removeHandler();
previewHandler_ = null;
}
}
}
use of com.google.gwt.user.client.Event.NativePreviewHandler in project rstudio by rstudio.
the class CppCompletionSignatureTip method onLoad.
@Override
protected void onLoad() {
super.onLoad();
allTips_.add(this);
nativePreviewReg_ = Event.addNativePreviewHandler(new NativePreviewHandler() {
public void onPreviewNativeEvent(NativePreviewEvent e) {
if (e.getTypeInt() == Event.ONKEYDOWN) {
// handle keys
switch(e.getNativeEvent().getKeyCode()) {
case KeyCodes.KEY_ESCAPE:
e.cancel();
hide();
break;
case KeyCodes.KEY_DOWN:
e.cancel();
setTextIndex(currentTextIndex_ + 1);
break;
case KeyCodes.KEY_UP:
e.cancel();
setTextIndex(currentTextIndex_ - 1);
break;
}
// 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();
Range anchorRange = anchor_.getRange();
if (cursorPos.isBeforeOrEqualTo(anchorRange.getStart()) || cursorPos.isAfterOrEqualTo(anchorRange.getEnd())) {
hide();
}
}
});
}
}
});
}
use of com.google.gwt.user.client.Event.NativePreviewHandler in project rstudio by rstudio.
the class SignatureToolTipManager method attachPreviewHandler.
private void attachPreviewHandler() {
detachPreviewHandler();
preview_ = Event.addNativePreviewHandler(new NativePreviewHandler() {
@Override
public void onPreviewNativeEvent(NativePreviewEvent preview) {
if (preview.getTypeInt() == Event.ONMOUSEMOVE) {
NativeEvent event = preview.getNativeEvent();
coordinates_ = new MouseCoordinates(event.getClientX(), event.getClientY());
ready_ = true;
} else if (preview.getTypeInt() == Event.ONKEYDOWN) {
coordinates_ = null;
ready_ = true;
if (preview.getNativeEvent().getKeyCode() == KeyCodes.KEY_ESCAPE)
suppressed_ = true;
}
}
});
}
Aggregations