Example usage for com.google.gwt.dom.client StyleElement setType

List of usage examples for com.google.gwt.dom.client StyleElement setType

Introduction

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

Prototype

public void setType(String type) 

Source Link

Document

The content type of the style sheet language.

Usage

From source file:com.dianaui.universal.core.client.ui.gwt.RichTextArea.java

License:Apache License

public void injectStyle(String css) {
    IFrameElement iframe = IFrameElement.as(getElement());

    StyleElement style = iframe.getContentDocument().createStyleElement();
    style.setPropertyString("language", "text/css");
    style.setType("text/css");

    setStyleContent(style, css);// w  w w  .j  a  va  2 s  . c  o m

    iframe.getContentDocument().getElementsByTagName("head").getItem(0).appendChild(style);
}

From source file:com.google.gwt.modernizr.client.tests.FontFace.java

License:MIT License

@Override
protected boolean runTest() {
    StyleElement style = Document.get().createStyleElement();
    HeadElement head = getHeadElement();

    style.setType("text/css");
    head.insertFirst(style);//from w w  w  .  j a  v  a 2  s.  c o  m
    SupportRuleTest test = hasCss2Feature() ? new Css2SupportRuleTest() : new SupportRuleTest();

    return test.isFontFaceSupported(StyleSheet.get(style));
}

From source file:com.qualogy.qafe.mgwt.client.main.MainController.java

License:Apache License

private void handleStyling(String css) {
    if ((css == null) || (css.length() == 0)) {
        return;/*  ww  w .ja  va2  s. co m*/
    }
    if (isIE()) {
        addStyleSheet(css);
    } else {
        // Append custom css style as last thing in the Head element
        Element head = Document.get().getElementsByTagName("head").getItem(0);
        StyleElement styleElement = Document.get().createStyleElement();
        styleElement.setType("text/css");
        styleElement.setInnerText(css);
        head.appendChild(styleElement);
    }
}

From source file:com.vaadin.client.ui.ui.UIConnector.java

License:Apache License

public void init(String rootPanelId, ApplicationConnection applicationConnection) {
    // Create a style tag for style injections so they don't end up in
    // the theme tag in IE8-IE10 (we don't want to wipe them out if we
    // change theme).
    // StyleInjectorImplIE always injects to the last style tag on the page.
    if (BrowserInfo.get().isIE() && BrowserInfo.get().getBrowserMajorVersion() < 11) {
        StyleElement style = Document.get().createStyleElement();
        style.setType("text/css");
        getHead().appendChild(style);//from w  w  w.j  a va 2  s  .c  o m
    }

    Widget shortcutContextWidget = getWidget();
    if (applicationConnection.getConfiguration().isStandalone()) {
        // Listen to body for standalone apps (#19392)
        shortcutContextWidget = RootPanel.get(); // document body
    }

    shortcutContextWidget.addDomHandler(new KeyDownHandler() {
        @Override
        public void onKeyDown(KeyDownEvent event) {
            if (getWidget().actionHandler != null) {
                getWidget().actionHandler.handleKeyboardEvent((Event) event.getNativeEvent().cast());
            }
        }
    }, KeyDownEvent.getType());

    DOM.sinkEvents(getWidget().getElement(), Event.ONSCROLL);

    RootPanel root = RootPanel.get(rootPanelId);

    // Remove the v-app-loading or any splash screen added inside the div by
    // the user
    root.getElement().setInnerHTML("");

    // Activate the initial theme by only adding the class name. Not calling
    // activateTheme here as it will also cause a full layout and updates to
    // the overlay container which has not yet been created at this point
    activeTheme = applicationConnection.getConfiguration().getThemeName();
    root.addStyleName(activeTheme);

    root.add(getWidget());

    // Set default tab index before focus call. State change handler
    // will update this later if needed.
    getWidget().setTabIndex(1);

    if (applicationConnection.getConfiguration().isStandalone()) {
        // set focus to iview element by default to listen possible keyboard
        // shortcuts. For embedded applications this is unacceptable as we
        // don't want to steal focus from the main page nor we don't want
        // side-effects from focusing (scrollIntoView).
        getWidget().getElement().focus();
    }

    applicationConnection.addHandler(ApplicationConnection.ApplicationStoppedEvent.TYPE,
            new ApplicationConnection.ApplicationStoppedHandler() {

                @Override
                public void onApplicationStopped(ApplicationStoppedEvent event) {
                    // Stop any polling
                    if (pollTimer != null) {
                        pollTimer.cancel();
                        pollTimer = null;
                    }
                }
            });
}

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   w w  w .j a  va2 s . c om
}

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

License:Open Source License

@Override
protected void onFrameLoaded() {
    isFrameLoaded_ = true;/*from  w  w  w. ja  v  a2s  . 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()));"));
                                        }
                                    });
                }
            });
}