use of com.google.gwt.dom.client.Element in project rstudio by rstudio.
the class ImagePreviewer method onPreviewImage.
private static void onPreviewImage(DocDisplay display, DocUpdateSentinel sentinel, UIPrefs prefs, String href, String attributes, Position position, Range tokenRange) {
// check to see if we already have a popup showing for this image;
// if we do then bail early
String encoded = StringUtil.encodeURIComponent(href);
Element el = Document.get().getElementById(encoded);
if (el != null)
return;
String pref = prefs.showLatexPreviewOnCursorIdle().getValue();
// skip if disabled entirely
if (!sentinel.getBoolProperty(TextEditingTargetNotebook.CONTENT_PREVIEW_ENABLED, pref != UIPrefsAccessor.LATEX_PREVIEW_SHOW_NEVER))
return;
// display stand-alone links as line widgets (if enabled)
String line = display.getLine(position.getRow());
if (isStandaloneMarkdownLink(line) && sentinel.getBoolProperty(TextEditingTargetNotebook.CONTENT_PREVIEW_INLINE, prefs.showLatexPreviewOnCursorIdle().getValue() == UIPrefsAccessor.LATEX_PREVIEW_SHOW_ALWAYS)) {
onPreviewImageLineWidget(display, sentinel, href, attributes, position, tokenRange);
return;
}
// construct image el, place in popup, and show
ImagePreviewPopup panel = new ImagePreviewPopup(display, tokenRange, href, imgSrcPathFromHref(sentinel, href));
panel.getElement().setId(encoded);
ScreenCoordinates coordinates = display.documentPositionToScreenCoordinates(position);
panel.setPopupPosition(coordinates.getPageX(), coordinates.getPageY() + 20);
panel.show();
}
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;
}
Aggregations