Example usage for com.google.gwt.dom.client Document createStyleElement

List of usage examples for com.google.gwt.dom.client Document createStyleElement

Introduction

In this page you can find the example usage for com.google.gwt.dom.client Document createStyleElement.

Prototype

public StyleElement createStyleElement() 

Source Link

Usage

From source file:burrito.client.crud.widgets.FormattedRichTextArea.java

License:Apache License

@Override
protected void onAttach() {
    super.onAttach();

    Timer cssTimer = new Timer() {
        @Override/*from  w  w w .j a  va  2s  .  co  m*/
        public void run() {
            Document doc = IFrameElement.as(getElement()).getContentDocument();
            StyleElement style = doc.createStyleElement();
            style.setInnerText(CSS);
            HeadElement.as(Element.as(doc.getBody().getPreviousSibling())).appendChild(style);
        }
    };

    cssTimer.schedule(100);
}

From source file:com.google.speedtracer.client.SourceViewer.java

License:Apache License

private static void injectStyles(IFrameElement sourceFrame, String styleText) {
    Document iframeDocument = sourceFrame.getContentDocument();
    HeadElement head = iframeDocument.getElementsByTagName("head").getItem(0).cast();
    StyleElement styleTag = iframeDocument.createStyleElement();
    styleTag.setInnerText(styleText);/* w ww .j  a v  a 2 s .c  o  m*/
    head.appendChild(styleTag);
}

From source file:org.cruxframework.crux.core.client.screen.ViewPortHandlerIEMobileImpl.java

License:Apache License

@Override
public void createViewport(String content, JavaScriptObject wnd) {
    if (!DeviceAdaptiveUtils.isInternetExplorerMobile()) {
        new ViewPortHandlerImpl().createViewport(content, wnd);
        return;//from   www  .j a  v a 2  s .  co  m
    }

    Document document = getWindowDocument(wnd);
    Element header = document.getElementsByTagName("head").getItem(0);
    StyleElement viewPortStyleElement = document.createStyleElement();

    String newProperties = handlePropertiesToCSS(content);

    viewPortStyleElement.appendChild(document.createTextNode("@-ms-viewport{" + newProperties + "}"));
    header.appendChild(viewPortStyleElement);

    JavaScriptObject parentWindow = getParentWindow(wnd);
    if (parentWindow != null && isCruxWindow(parentWindow)) {
        createViewport(content, parentWindow);
    }
}

From source file:org.rstudio.core.client.widget.FontSizer.java

License:Open Source License

public static void injectStylesIntoDocument(Document doc) {
    StyleElement style = doc.createStyleElement();
    style.setType("text/css");
    style.setInnerText(styles.getText());
    doc.getBody().appendChild(style);//from  ww  w .j  av a  2 s . c o m
}

From source file:org.rstudio.core.client.widget.FontSizer.java

License:Open Source License

public static void setNormalFontSize(Document document, double size) {
    size = size + BrowseCap.getFontSkew();

    final String STYLE_EL_ID = "__rstudio_normal_size";

    Element oldStyle = document.getElementById(STYLE_EL_ID);

    StyleElement style = document.createStyleElement();
    style.setAttribute("type", "text/css");
    style.setInnerText("." + styles.normalSize() + ", " + "." + styles.normalSize() + " td, " + "."
            + styles.normalSize() + " pre" + " {font-size:" + size + "pt !important;}");
    document.getBody().appendChild(style);

    if (oldStyle != null)
        oldStyle.removeFromParent();// w w  w  .  j a  v  a 2s  .c o  m

    style.setId(STYLE_EL_ID);
}

From source file:org.rstudio.core.client.widget.RStudioThemedFrame.java

License:Open Source License

private void addThemesStyle(String customStyle, String urlStyle, boolean removeBodyStyle) {
    if (getWindow() != null && getWindow().getDocument() != null) {
        Document document = getWindow().getDocument();

        if (customStyle == null)
            customStyle = "";

        customStyle += "\n"
                + ".rstudio-themes-flat.rstudio-themes-dark.rstudio-themes-scrollbars::-webkit-scrollbar,\n"
                + ".rstudio-themes-flat.rstudio-themes-dark.rstudio-themes-scrollbars ::-webkit-scrollbar {\n"
                + "   background: #FFF;\n" + "}\n" + "\n"
                + ".rstudio-themes-flat.rstudio-themes-dark.rstudio-themes-scrollbars::-webkit-scrollbar-thumb,\n"
                + ".rstudio-themes-flat.rstudio-themes-dark.rstudio-themes-scrollbars ::-webkit-scrollbar-thumb {\n"
                + "   -webkit-border-radius: 10px;\n" + "   background: " + ThemeColors.darkGreyBackground
                + ";\n" + "}\n" + "\n"
                + ".rstudio-themes-flat.rstudio-themes-dark.rstudio-themes-scrollbars::-webkit-scrollbar-track,\n"
                + ".rstudio-themes-flat.rstudio-themes-dark.rstudio-themes-scrollbars ::-webkit-scrollbar-track,\n"
                + ".rstudio-themes-flat.rstudio-themes-dark.rstudio-themes-scrollbars::-webkit-scrollbar-corner,\n"
                + ".rstudio-themes-flat.rstudio-themes-dark.rstudio-themes-scrollbars ::-webkit-scrollbar-corner {\n"
                + "   background: " + ThemeColors.darkGreyMostInactiveBackground + ";\n" + "}\n"
                + ".rstudio-themes-flat.rstudio-themes-dark.rstudio-themes-scrollbars::-webkit-scrollbar-thumb,\n"
                + ".rstudio-themes-flat.rstudio-themes-dark.rstudio-themes-scrollbars ::-webkit-scrollbar-thumb{\n"
                + "   border: solid 3px " + ThemeColors.darkGreyMostInactiveBackground + ";" + "}\n";

        StyleElement style = document.createStyleElement();
        style.setInnerHTML(customStyle);
        document.getHead().appendChild(style);

        if (urlStyle != null) {
            LinkElement styleLink = document.createLinkElement();
            styleLink.setHref(urlStyle);
            styleLink.setRel("stylesheet");
            document.getHead().appendChild(styleLink);
        }//from   w ww  .jav  a 2s.c o m

        RStudioGinjector.INSTANCE.getAceThemes().applyTheme(document);

        BodyElement body = document.getBody();
        if (body != null) {
            if (removeBodyStyle)
                body.removeAttribute("style");

            RStudioThemes.initializeThemes(RStudioGinjector.INSTANCE.getUIPrefs(), document,
                    document.getBody());

            body.addClassName("ace_editor_theme");
        }
    }
}

From source file:org.rstudio.studio.client.workbench.prefs.views.AceEditorPreview.java

License:Open Source License

@Override
protected void onFrameLoaded() {
    isFrameLoaded_ = true;/*w w w  .ja  v a  2s.  c om*/
    final Document doc = getDocument();

    // NOTE: There is an interesting 'feature' in Firefox whereby an
    // initialized IFrame will report that it has successfully initialized the
    // window / underlying document (readyState is 'complete') but, in fact,
    // there is still some initialization left to occur and any changes made
    // before complete initialization will cause it to be swept out from under
    // our feet. To work around this, we double-check that the document we are
    // working with is the _same document_ after each JavaScript load
    // iteration.
    new ExternalJavaScriptLoader(getDocument(), AceResources.INSTANCE.acejs().getSafeUri().asString())
            .addCallback(new Callback() {
                public void onLoaded() {
                    if (getDocument() != doc) {
                        onFrameLoaded();
                        return;
                    }

                    new ExternalJavaScriptLoader(getDocument(),
                            AceResources.INSTANCE.acesupportjs().getSafeUri().asString())
                                    .addCallback(new Callback() {
                                        public void onLoaded() {

                                            if (getDocument() != doc) {
                                                onFrameLoaded();
                                                return;
                                            }

                                            final Document doc = getDocument();
                                            final BodyElement body = doc.getBody();

                                            if (themeUrl_ != null)
                                                setTheme(themeUrl_);
                                            if (fontSize_ != null)
                                                setFontSize(fontSize_);
                                            if (zoomLevel_ != null)
                                                setZoomLevel(zoomLevel_);

                                            body.getStyle().setMargin(0, Unit.PX);
                                            body.getStyle().setBackgroundColor("white");

                                            StyleElement style = doc.createStyleElement();
                                            style.setType("text/css");
                                            style.setInnerText(
                                                    ".ace_editor {\n" + "border: none !important;\n" + "}");
                                            setFont(ThemeFonts.getFixedWidthFont());
                                            body.appendChild(style);

                                            DivElement div = doc.createDivElement();
                                            div.setId("editor");
                                            div.getStyle().setWidth(100, Unit.PCT);
                                            div.getStyle().setHeight(100, Unit.PCT);
                                            div.setInnerText(code_);
                                            body.appendChild(div);

                                            FontSizer.injectStylesIntoDocument(doc);
                                            FontSizer.applyNormalFontSize(div);

                                            body.appendChild(doc.createScriptElement(
                                                    "var event = require('ace/lib/event');\n"
                                                            + "var Editor = require('ace/editor').Editor;\n"
                                                            + "var Renderer = require('ace/virtual_renderer').VirtualRenderer;\n"
                                                            + "var dom = require('ace/lib/dom');\n"
                                                            + "var container = document.getElementById('editor');\n"
                                                            + "var value = dom.getInnerText(container);\n"
                                                            + "container.innerHTML = '';\n"
                                                            + "var session = ace.createEditSession(value);\n"
                                                            + "var editor = new Editor(new Renderer(container, {}));\n"
                                                            + "editor.setSession(session);\n"
                                                            + "var env = {document: session, editor: editor, onResize: editor.resize.bind(editor, null)};\n"
                                                            + "event.addListener(window, 'resize', env.onResize);\n"
                                                            + "editor.on('destory', function() { event.removeListener(window, 'resize', env.onResize); });\n"
                                                            + "editor.container.env = editor.env = env;\n"
                                                            + "editor.renderer.setHScrollBarAlwaysVisible(false);\n"
                                                            + "editor.setHighlightActiveLine(false);\n"
                                                            + "editor.setReadOnly(true);\n"
                                                            + "editor.renderer.setShowGutter(false);\n"
                                                            + "editor.renderer.setDisplayIndentGuides(false);\n"
                                                            + "var RMode = require('mode/r').Mode;\n"
                                                            + "editor.getSession().setMode(new RMode(false, editor.getSession()));"));
                                        }
                                    });
                }
            });
}

From source file:org.rstudio.studio.client.workbench.prefs.views.AceEditorPreview.java

License:Open Source License

public void setFont(String font) {
    final String STYLE_EL_ID = "__rstudio_font_family";
    Document document = getDocument();

    Element oldStyle = document.getElementById(STYLE_EL_ID);

    StyleElement style = document.createStyleElement();
    style.setAttribute("type", "text/css");
    style.setInnerText(".ace_editor, .ace_text-layer {\n" + "font-family: " + font + " !important;\n" + "}");

    document.getBody().appendChild(style);

    if (oldStyle != null)
        oldStyle.removeFromParent();//from w w  w .j  av  a2 s . co m

    style.setId(STYLE_EL_ID);
}

From source file:org.rstudio.studio.client.workbench.prefs.views.AceEditorPreview.java

License:Open Source License

public void setZoomLevel(double zoomLevel) {
    zoomLevel_ = zoomLevel;/*from w  w w  .  j  ava 2s.  c o m*/
    if (!isFrameLoaded_)
        return;

    final String STYLE_EL_ID = "__rstudio_zoom_level";
    Document document = getDocument();

    Element oldStyle = document.getElementById(STYLE_EL_ID);

    StyleElement style = document.createStyleElement();
    style.setAttribute("type", "text/css");
    String zoom = Double.toString(zoomLevel);
    style.setInnerText(".ace_line {\n" + "  -webkit-transform: scale(" + zoom + ");\n" + "}");

    document.getBody().appendChild(style);

    if (oldStyle != null)
        oldStyle.removeFromParent();

    style.setId(STYLE_EL_ID);
}