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;
}
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();
}
}
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_;
}
Aggregations