use of com.google.gwt.dom.client.Element in project rstudio by rstudio.
the class DesktopApplicationHeader method isSelectionEmpty.
public static boolean isSelectionEmpty() {
Element activeElement = DomUtils.getActiveElement();
AceEditorNative editor = AceEditorNative.getEditor(activeElement);
if (editor != null) {
Selection selection = editor.getSession().getSelection();
return selection.isEmpty();
}
// has focus)
return false;
}
use of com.google.gwt.dom.client.Element in project rstudio by rstudio.
the class MathJax method renderLatexLineWidget.
private void renderLatexLineWidget(LineWidget widget, final Range range, final String text, final MathJaxTypesetCallback callback) {
final Element el = DomUtils.getFirstElementWithClassName(widget.getElement(), MATHJAX_ROOT_CLASSNAME);
// call 'onLineWidgetChanged' to ensure the widget is attached
docDisplay_.onLineWidgetChanged(widget);
// defer typesetting just to ensure that the widget has actually been
// attached to the DOM
final LineWidget lineWidget = widget;
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
mathjaxTypeset(el, text, new MathJaxTypesetCallback() {
@Override
public void onMathJaxTypesetComplete(final boolean error) {
// force expansion
withExpandedLineWidget(lineWidget, new CommandWithArg<Boolean>() {
@Override
public void execute(Boolean stateChanged) {
// re-position the element
int height = el.getOffsetHeight() + 30;
Element ppElement = el.getParentElement().getParentElement();
ppElement.getStyle().setHeight(height, Unit.PX);
docDisplay_.onLineWidgetChanged(lineWidget);
// invoke supplied callback
if (callback != null)
callback.onMathJaxTypesetComplete(error);
}
});
}
});
}
});
}
use of com.google.gwt.dom.client.Element in project rstudio by rstudio.
the class MathJax method onMathJaxTypesetCompleted.
private void onMathJaxTypesetCompleted(final Object mathjaxElObject, final String text, final boolean error, final Object commandObject, final int attempt) {
final Element mathjaxEl = (Element) mathjaxElObject;
if (attempt < MAX_RENDER_ATTEMPTS) {
// if mathjax displayed an error, try re-rendering once more
Element[] errorEls = DomUtils.getElementsByClassName(mathjaxEl, "MathJax_Error");
if (errorEls != null && errorEls.length > 0 && attempt < MAX_RENDER_ATTEMPTS) {
// hide the error and retry in 25ms (experimentally this seems to
// produce a better shot at rendering successfully than an immediate
// or deferred retry)
mathjaxEl.getStyle().setVisibility(Visibility.HIDDEN);
new Timer() {
@Override
public void run() {
mathjaxTypeset(mathjaxEl, text, commandObject, attempt + 1);
}
}.schedule(25);
return;
}
}
// show whatever we've got (could be an error if we ran out of retries)
mathjaxEl.getStyle().setVisibility(Visibility.VISIBLE);
// execute callback
if (commandObject != null && commandObject instanceof MathJaxTypesetCallback) {
MathJaxTypesetCallback callback = (MathJaxTypesetCallback) commandObject;
callback.onMathJaxTypesetComplete(error);
}
if (!error) {
lastRenderedText_ = text;
}
}
use of com.google.gwt.dom.client.Element in project rstudio by rstudio.
the class ShellWidget method output.
private boolean output(String text, String className, boolean addToTop) {
if (text.indexOf('\f') >= 0)
clearOutput();
Element outEl = output_.getElement();
if (addToTop) {
SpanElement leading = Document.get().createSpanElement();
outEl.insertFirst(leading);
VirtualConsole console = new VirtualConsole(leading);
console.submit(text, className);
lines_ += DomUtils.countLines(leading, true);
} else {
// create trailing output console if it doesn't already exist
if (virtualConsole_ == null) {
SpanElement trailing = Document.get().createSpanElement();
outEl.appendChild(trailing);
virtualConsole_ = new VirtualConsole(trailing);
}
int oldLineCount = DomUtils.countLines(virtualConsole_.getParent(), true);
virtualConsole_.submit(text, className);
int newLineCount = DomUtils.countLines(virtualConsole_.getParent(), true);
lines_ += newLineCount - oldLineCount;
}
boolean result = !trimExcess();
resizeCommand_.nudge();
return result;
}
use of com.google.gwt.dom.client.Element 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);
}
Aggregations