Search in sources :

Example 1 with CSSStyleSheet

use of com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleSheet in project htmlunit by HtmlUnit.

the class WebWindowImpl method getComputedStyle.

/**
 * {@inheritDoc}
 */
@Override
public CSS2Properties getComputedStyle(final DomElement element, final String pseudoElement) {
    String normalizedPseudo = pseudoElement;
    if (normalizedPseudo != null) {
        if (normalizedPseudo.startsWith("::")) {
            normalizedPseudo = normalizedPseudo.substring(1);
        } else if (getWebClient().getBrowserVersion().hasFeature(JS_WINDOW_COMPUTED_STYLE_PSEUDO_ACCEPT_WITHOUT_COLON) && normalizedPseudo.length() > 0 && normalizedPseudo.charAt(0) != ':') {
            normalizedPseudo = ":" + normalizedPseudo;
        }
    }
    final SgmlPage sgmlPage = element.getPage();
    if (sgmlPage instanceof HtmlPage) {
        final CSS2Properties styleFromCache = ((HtmlPage) sgmlPage).getStyleFromCache(element, normalizedPseudo);
        if (styleFromCache != null) {
            return styleFromCache;
        }
    }
    final Element e = element.getScriptableObject();
    final CSS2Properties style = new CSS2Properties(e);
    final Object ownerDocument = e.getOwnerDocument();
    if (ownerDocument instanceof HTMLDocument) {
        final StyleSheetList sheets = ((HTMLDocument) ownerDocument).getStyleSheets();
        final boolean trace = LOG.isTraceEnabled();
        for (int i = 0; i < sheets.getLength(); i++) {
            final CSSStyleSheet sheet = (CSSStyleSheet) sheets.item(i);
            if (sheet.isActive() && sheet.isEnabled()) {
                if (trace) {
                    LOG.trace("modifyIfNecessary: " + sheet + ", " + style + ", " + e);
                }
                sheet.modifyIfNecessary(style, element, normalizedPseudo);
            }
        }
        ((HtmlPage) element.getPage()).putStyleIntoCache(element, normalizedPseudo, style);
    }
    return style;
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HTMLDocument(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument) DomElement(com.gargoylesoftware.htmlunit.html.DomElement) Element(com.gargoylesoftware.htmlunit.javascript.host.Element) CSSStyleSheet(com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleSheet) CSS2Properties(com.gargoylesoftware.htmlunit.javascript.host.css.CSS2Properties) StyleSheetList(com.gargoylesoftware.htmlunit.javascript.host.css.StyleSheetList)

Example 2 with CSSStyleSheet

use of com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleSheet in project htmlunit by HtmlUnit.

the class HTMLStyleElement method setDisabled.

/**
 * Sets the {@code disabled} property.
 * @param disabled the {@code disabled} property
 */
@Override
@JsxSetter
public void setDisabled(final boolean disabled) {
    final CSSStyleSheet sheet = getSheet();
    final boolean modified = disabled == sheet.isEnabled();
    sheet.setEnabled(!disabled);
    if (modified) {
        getDomNodeOrDie().getPage().clearComputedStyles();
    }
}
Also used : CSSStyleSheet(com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleSheet) JsxSetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter)

Example 3 with CSSStyleSheet

use of com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleSheet in project htmlunit by HtmlUnit.

the class HTMLStyleElement method getSheet.

/**
 * Gets the associated sheet.
 * @see <a href="http://www.xulplanet.com/references/objref/HTMLStyleElement.html">Mozilla doc</a>
 * @return the sheet
 */
@JsxGetter
public CSSStyleSheet getSheet() {
    if (sheet_ != null) {
        return sheet_;
    }
    final HtmlStyle style = (HtmlStyle) getDomNodeOrDie();
    final String css = style.getTextContent();
    final Window window = getWindow();
    final Cache cache = window.getWebWindow().getWebClient().getCache();
    final CSSStyleSheetImpl cached = cache.getCachedStyleSheet(css);
    final String uri = getDomNodeOrDie().getPage().getWebResponse().getWebRequest().getUrl().toExternalForm();
    if (cached != null) {
        sheet_ = new CSSStyleSheet(this, window, cached, uri);
    } else {
        sheet_ = new CSSStyleSheet(this, css, uri);
        cache.cache(css, sheet_.getWrappedSheet());
    }
    return sheet_;
}
Also used : Window(com.gargoylesoftware.htmlunit.javascript.host.Window) HtmlStyle(com.gargoylesoftware.htmlunit.html.HtmlStyle) CSSStyleSheetImpl(com.gargoylesoftware.css.dom.CSSStyleSheetImpl) CSSStyleSheet(com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleSheet) Cache(com.gargoylesoftware.htmlunit.Cache) JsxGetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)

Aggregations

CSSStyleSheet (com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleSheet)3 CSSStyleSheetImpl (com.gargoylesoftware.css.dom.CSSStyleSheetImpl)1 Cache (com.gargoylesoftware.htmlunit.Cache)1 DomElement (com.gargoylesoftware.htmlunit.html.DomElement)1 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)1 HtmlStyle (com.gargoylesoftware.htmlunit.html.HtmlStyle)1 JsxGetter (com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)1 JsxSetter (com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter)1 Element (com.gargoylesoftware.htmlunit.javascript.host.Element)1 Window (com.gargoylesoftware.htmlunit.javascript.host.Window)1 CSS2Properties (com.gargoylesoftware.htmlunit.javascript.host.css.CSS2Properties)1 StyleSheetList (com.gargoylesoftware.htmlunit.javascript.host.css.StyleSheetList)1 HTMLDocument (com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument)1