Search in sources :

Example 26 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 27 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 28 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 29 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)

Example 30 with Element

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);
}
Also used : NativePreviewHandler(com.google.gwt.user.client.Event.NativePreviewHandler) NativePreviewEvent(com.google.gwt.user.client.Event.NativePreviewEvent) Position(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position) Element(com.google.gwt.dom.client.Element) RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand) Markers(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Markers) Marker(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Marker)

Aggregations

Element (com.google.gwt.dom.client.Element)193 DivElement (com.google.gwt.dom.client.DivElement)14 Test (org.junit.Test)13 TableRowElement (com.google.gwt.dom.client.TableRowElement)11 SVGSVGElement (elemental.svg.SVGSVGElement)11 InputElement (com.google.gwt.dom.client.InputElement)9 Node (com.google.gwt.dom.client.Node)8 Image (com.google.gwt.user.client.ui.Image)8 PatchMethod (com.googlecode.gwt.test.patchers.PatchMethod)8 EventTarget (com.google.gwt.dom.client.EventTarget)7 LabelElement (com.google.gwt.dom.client.LabelElement)7 NativeEvent (com.google.gwt.dom.client.NativeEvent)7 JsArrayString (com.google.gwt.core.client.JsArrayString)6 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)6 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)6 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)6 ImageResource (com.google.gwt.resources.client.ImageResource)6 FlowPanel (com.google.gwt.user.client.ui.FlowPanel)6 GwtTestTest (com.googlecode.gwt.test.GwtTestTest)6 Label (com.google.gwt.user.client.ui.Label)5