Search in sources :

Example 66 with Element

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();
}
Also used : Element(com.google.gwt.dom.client.Element) ScreenCoordinates(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Renderer.ScreenCoordinates)

Example 67 with Element

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;
}
Also used : AceEditorNative(org.rstudio.studio.client.workbench.views.source.editors.text.ace.AceEditorNative) Selection(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Selection) Element(com.google.gwt.dom.client.Element)

Example 68 with Element

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);
                        }
                    });
                }
            });
        }
    });
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Element(com.google.gwt.dom.client.Element) PinnedLineWidget(org.rstudio.studio.client.workbench.views.source.editors.text.PinnedLineWidget) LineWidget(org.rstudio.studio.client.workbench.views.source.editors.text.ace.LineWidget)

Example 69 with Element

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;
    }
}
Also used : Timer(com.google.gwt.user.client.Timer) Element(com.google.gwt.dom.client.Element)

Example 70 with Element

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;
}
Also used : SpanElement(com.google.gwt.dom.client.SpanElement) VirtualConsole(org.rstudio.core.client.VirtualConsole) Element(com.google.gwt.dom.client.Element) SpanElement(com.google.gwt.dom.client.SpanElement)

Aggregations

Element (com.google.gwt.dom.client.Element)340 DivElement (com.google.gwt.dom.client.DivElement)19 TableRowElement (com.google.gwt.dom.client.TableRowElement)19 NativeEvent (com.google.gwt.dom.client.NativeEvent)16 Test (org.junit.Test)14 EventTarget (com.google.gwt.dom.client.EventTarget)11 SVGSVGElement (elemental.svg.SVGSVGElement)11 InputElement (com.google.gwt.dom.client.InputElement)10 Node (com.google.gwt.dom.client.Node)9 TableCellElement (com.google.gwt.dom.client.TableCellElement)9 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)8 AnchorElement (com.google.gwt.dom.client.AnchorElement)8 ImageElement (com.google.gwt.dom.client.ImageElement)8 LabelElement (com.google.gwt.dom.client.LabelElement)8 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)8 Image (com.google.gwt.user.client.ui.Image)8 SpanElement (com.google.gwt.dom.client.SpanElement)7 Style (com.google.gwt.dom.client.Style)7 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)7 Widget (com.google.gwt.user.client.ui.Widget)7