use of com.gargoylesoftware.htmlunit.html.HtmlStyle in project htmlunit by HtmlUnit.
the class HTMLStyleElement method setMedia.
/**
* Sets the media of this style.
* @param media the new media
*/
@JsxSetter
public void setMedia(final String media) {
final HtmlStyle style = (HtmlStyle) getDomNodeOrDie();
style.setAttribute("media", media);
}
use of com.gargoylesoftware.htmlunit.html.HtmlStyle in project htmlunit by HtmlUnit.
the class CSSStyleSheet2Test method selects_miscSelectors.
/**
* @throws Exception if the test fails
*/
@Test
public void selects_miscSelectors() throws Exception {
final String html = "<html><head><title>test</title>\n" + "</head><body><style></style>\n" + "<form name='f1' action='foo' class='yui-log'>\n" + "<div><div><input name='i1' id='m1'></div></div>\n" + "<input name='i2' class='yui-log'>\n" + "<button name='b1' class='yui-log'>\n" + "<button name='b2'>\n" + "</form>\n" + "</body></html>";
final HtmlPage page = loadPage(html);
final HtmlElement body = page.getBody();
final HtmlForm form = page.getFormByName("f1");
final HtmlInput input1 = (HtmlInput) page.getElementsByName("i1").get(0);
final HtmlInput input2 = (HtmlInput) page.getElementsByName("i2").get(0);
final DomElement button1 = page.getElementsByName("b1").get(0);
final DomElement button2 = page.getElementsByName("b2").get(0);
final BrowserVersion browserVersion = getBrowserVersion();
final HtmlStyle node = (HtmlStyle) page.getElementsByTagName("style").item(0);
final HTMLStyleElement host = (HTMLStyleElement) node.getScriptableObject();
final CSSStyleSheet sheet = host.getSheet();
Selector selector = parseSelector(sheet, "*.yui-log input");
assertFalse(CSSStyleSheet.selects(browserVersion, selector, body, null, false));
assertFalse(CSSStyleSheet.selects(browserVersion, selector, form, null, false));
assertTrue(CSSStyleSheet.selects(browserVersion, selector, input1, null, false));
assertTrue(CSSStyleSheet.selects(browserVersion, selector, input2, null, false));
assertFalse(CSSStyleSheet.selects(browserVersion, selector, button1, null, false));
assertFalse(CSSStyleSheet.selects(browserVersion, selector, button2, null, false));
selector = parseSelector(sheet, "#m1");
assertTrue(CSSStyleSheet.selects(browserVersion, selector, input1, null, false));
assertFalse(CSSStyleSheet.selects(browserVersion, selector, input2, null, false));
}
use of com.gargoylesoftware.htmlunit.html.HtmlStyle in project htmlunit by HtmlUnit.
the class CSSStyleSheet method getHref.
/**
* Returns the URL of the stylesheet.
* @return the URL of the stylesheet
*/
@JsxGetter
public String getHref() {
if (ownerNode_ != null) {
final DomNode node = ownerNode_.getDomNodeOrDie();
if (node instanceof HtmlStyle) {
return null;
}
if (node instanceof HtmlLink) {
// <link rel="stylesheet" type="text/css" href="..." />
final HtmlLink link = (HtmlLink) node;
final String href = link.getHrefAttribute();
if ("".equals(href) && getBrowserVersion().hasFeature(STYLESHEET_HREF_EMPTY_IS_NULL)) {
return null;
}
// Expand relative URLs.
try {
final HtmlPage page = (HtmlPage) link.getPage();
final URL url = page.getFullyQualifiedUrl(href);
return url.toExternalForm();
} catch (final MalformedURLException e) {
// Log the error and fall through to the return values below.
LOG.warn(e.getMessage(), e);
}
}
}
return getUri();
}
use of com.gargoylesoftware.htmlunit.html.HtmlStyle in project htmlunit by HtmlUnit.
the class CSSStyleSheet method isActive.
/**
* Returns {@code true} if this stylesheet is active, based on the media types it is associated with (if any).
* @return {@code true} if this stylesheet is active, based on the media types it is associated with (if any)
*/
public boolean isActive() {
final String media;
final HtmlElement e = ownerNode_.getDomNodeOrNull();
if (e instanceof HtmlStyle) {
final HtmlStyle style = (HtmlStyle) e;
media = style.getMediaAttribute();
} else if (e instanceof HtmlLink) {
final HtmlLink link = (HtmlLink) e;
media = link.getMediaAttribute();
} else {
return true;
}
if (StringUtils.isBlank(media)) {
return true;
}
final WebClient webClient = getWindow().getWebWindow().getWebClient();
final MediaListImpl mediaList = parseMedia(webClient.getCssErrorHandler(), media);
return isActive(this, mediaList);
}
use of com.gargoylesoftware.htmlunit.html.HtmlStyle in project htmlunit by HtmlUnit.
the class HTMLStyleElement method setType.
/**
* Sets the type of this style.
* @param type the new type
*/
@JsxSetter
public void setType(final String type) {
final HtmlStyle style = (HtmlStyle) getDomNodeOrDie();
style.setTypeAttribute(type);
}
Aggregations