use of com.gargoylesoftware.htmlunit.javascript.host.css.StyleSheetList 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;
}
Aggregations