Search in sources :

Example 1 with CSS2Properties

use of com.gargoylesoftware.htmlunit.javascript.host.css.CSS2Properties 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)

Aggregations

DomElement (com.gargoylesoftware.htmlunit.html.DomElement)1 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)1 Element (com.gargoylesoftware.htmlunit.javascript.host.Element)1 CSS2Properties (com.gargoylesoftware.htmlunit.javascript.host.css.CSS2Properties)1 CSSStyleSheet (com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleSheet)1 StyleSheetList (com.gargoylesoftware.htmlunit.javascript.host.css.StyleSheetList)1 HTMLDocument (com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument)1