Search in sources :

Example 1 with ElementEx

use of org.rstudio.core.client.dom.ElementEx in project rstudio by rstudio.

the class DomUtilsStandardImpl method focus.

public void focus(Element element, boolean alwaysDriveSelection) {
    ElementEx el = (ElementEx) element;
    el.focus();
    if (alwaysDriveSelection || (el.getContentEditable() && (el.getInnerText() == null || el.getInnerText() == ""))) {
        Document doc = el.getOwnerDocument();
        Range range = Range.create(doc);
        range.selectNodeContents(el);
        Selection sel = Selection.get(NativeWindow.get(doc));
        sel.setRange(range);
    }
    NativeWindow.get().focus();
}
Also used : ElementEx(org.rstudio.core.client.dom.ElementEx) Document(com.google.gwt.dom.client.Document)

Example 2 with ElementEx

use of org.rstudio.core.client.dom.ElementEx in project rstudio by rstudio.

the class CopyPlotToClipboardDesktopDialog method copyAsBitmap.

protected void copyAsBitmap(final Operation onCompleted) {
    final ExportPlotSizeEditor sizeEditor = getSizeEditor();
    sizeEditor.prepareForExport(new Command() {

        @Override
        public void execute() {
            if (BrowseCap.isCocoaDesktop()) {
                clipboard_.copyPlotToCocoaPasteboard(sizeEditor.getImageWidth(), sizeEditor.getImageHeight(), new Command() {

                    @Override
                    public void execute() {
                        onCompleted.execute();
                    }
                });
            } else {
                WindowEx win = sizeEditor.getPreviewIFrame().getContentWindow();
                Document doc = win.getDocument();
                NodeList<Element> images = doc.getElementsByTagName("img");
                if (images.getLength() > 0) {
                    ElementEx img = images.getItem(0).cast();
                    DesktopFrame frame = Desktop.getFrame();
                    frame.copyImageToClipboard(img.getClientLeft(), img.getClientTop(), img.getClientWidth(), img.getClientHeight());
                }
                onCompleted.execute();
            }
        }
    });
}
Also used : Command(com.google.gwt.user.client.Command) ElementEx(org.rstudio.core.client.dom.ElementEx) NodeList(com.google.gwt.dom.client.NodeList) WindowEx(org.rstudio.core.client.dom.WindowEx) Document(com.google.gwt.dom.client.Document) DesktopFrame(org.rstudio.studio.client.application.DesktopFrame) ExportPlotSizeEditor(org.rstudio.studio.client.workbench.exportplot.ExportPlotSizeEditor)

Example 3 with ElementEx

use of org.rstudio.core.client.dom.ElementEx in project rstudio by rstudio.

the class DomUtilsIE10Impl method focus.

public void focus(Element element, boolean alwaysDriveSelection) {
    ElementEx el = (ElementEx) element;
    el.focus();
}
Also used : ElementEx(org.rstudio.core.client.dom.ElementEx)

Example 4 with ElementEx

use of org.rstudio.core.client.dom.ElementEx in project rstudio by rstudio.

the class DomUtilsStandardImpl method getCursorBounds.

public Rectangle getCursorBounds(Document doc) {
    Selection sel = Selection.get(NativeWindow.get(doc));
    Range selRng = sel.getRangeAt(0);
    if (selRng == null)
        return null;
    sel.removeAllRanges();
    SpanElement span = doc.createSpanElement();
    Range rng = selRng.cloneRange();
    rng.collapse(true);
    rng.insertNode(span);
    int x = span.getAbsoluteLeft();
    int y = span.getAbsoluteTop();
    int w = 0;
    int h = span.getOffsetHeight();
    Rectangle result = new Rectangle(x, y, w, h);
    ElementEx parent = (ElementEx) span.getParentElement();
    parent.removeChild(span);
    parent.normalize();
    sel.setRange(selRng);
    return result;
}
Also used : SpanElement(com.google.gwt.dom.client.SpanElement) ElementEx(org.rstudio.core.client.dom.ElementEx) Rectangle(org.rstudio.core.client.Rectangle)

Example 5 with ElementEx

use of org.rstudio.core.client.dom.ElementEx in project rstudio by rstudio.

the class HelpPane method helpNavigated.

private void helpNavigated(Document doc) {
    NodeList<Element> elements = doc.getElementsByTagName("a");
    for (int i = 0; i < elements.getLength(); i++) {
        ElementEx a = (ElementEx) elements.getItem(i);
        String href = a.getAttribute("href", 2);
        if (href == null)
            continue;
        if (href.contains(":") || href.endsWith(".pdf")) {
            // external links
            AnchorElement aElement = a.cast();
            aElement.setTarget("_blank");
        } else {
            // Internal links need to be handled in JavaScript so that
            // they can participate in virtual session history. This
            // won't have any effect for right-click > Show in New Window
            // but that's a good thing.
            a.setAttribute("onclick", "window.parent.helpNavigate(this.href, " + (BrowseCap.isLinuxDesktop() || BrowseCap.isWindowsDesktop() ? "true" : "false") + "); return false");
        }
    }
    String effectiveTitle = getDocTitle(doc);
    title_.setText(effectiveTitle);
    this.fireEvent(new HelpNavigateEvent(doc.getURL(), effectiveTitle));
}
Also used : HelpNavigateEvent(org.rstudio.studio.client.workbench.views.help.events.HelpNavigateEvent) IFrameElementEx(org.rstudio.core.client.dom.IFrameElementEx) ElementEx(org.rstudio.core.client.dom.ElementEx)

Aggregations

ElementEx (org.rstudio.core.client.dom.ElementEx)7 Document (com.google.gwt.dom.client.Document)3 Rectangle (org.rstudio.core.client.Rectangle)3 Command (com.google.gwt.user.client.Command)2 IFrameElementEx (org.rstudio.core.client.dom.IFrameElementEx)2 WindowEx (org.rstudio.core.client.dom.WindowEx)2 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 Element (com.google.gwt.dom.client.Element)1 NodeList (com.google.gwt.dom.client.NodeList)1 SpanElement (com.google.gwt.dom.client.SpanElement)1 DesktopFrame (org.rstudio.studio.client.application.DesktopFrame)1 ExportPlotSizeEditor (org.rstudio.studio.client.workbench.exportplot.ExportPlotSizeEditor)1 HelpNavigateEvent (org.rstudio.studio.client.workbench.views.help.events.HelpNavigateEvent)1