use of com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleDeclaration in project htmlunit by HtmlUnit.
the class Element method setDomNode.
/**
* Sets the DOM node that corresponds to this JavaScript object.
* @param domNode the DOM node
*/
@Override
public void setDomNode(final DomNode domNode) {
super.setDomNode(domNode);
setParentScope(getWindow().getDocument());
// CSSStyleDeclaration uses the parent scope
style_ = new CSSStyleDeclaration(this);
// Convert JavaScript snippets defined in the attribute map to executable event handlers.
// Should be called only on construction.
final DomElement htmlElt = (DomElement) domNode;
for (final DomAttr attr : htmlElt.getAttributesMap().values()) {
final String eventName = attr.getName().toLowerCase(Locale.ROOT);
if (eventName.startsWith("on")) {
createEventHandler(eventName.substring(2), attr.getValue());
}
}
}
use of com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleDeclaration in project htmlunit by HtmlUnit.
the class DomNode method isDisplayed.
/**
* <p>Returns {@code true} if this node is displayed and can be visible to the user
* (ignoring screen size, scrolling limitations, color, font-size, or overlapping nodes).</p>
*
* <p><b>NOTE:</b> If CSS is
* {@link com.gargoylesoftware.htmlunit.WebClientOptions#setCssEnabled(boolean) disabled}, this method
* does <b>not</b> take this element's style into consideration!</p>
*
* @see <a href="http://www.w3.org/TR/CSS2/visufx.html#visibility">CSS2 Visibility</a>
* @see <a href="http://www.w3.org/TR/CSS2/visuren.html#propdef-display">CSS2 Display</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/ms531180.aspx">MSDN Documentation</a>
* @return {@code true} if the node is visible to the user, {@code false} otherwise
* @see #mayBeDisplayed()
*/
public boolean isDisplayed() {
if (!mayBeDisplayed()) {
return false;
}
final Page page = getPage();
final WebWindow window = page.getEnclosingWindow();
final WebClient webClient = window.getWebClient();
if (webClient.getOptions().isCssEnabled() && webClient.isJavaScriptEnabled()) {
// display: iterate top to bottom, because if a parent is display:none,
// there's nothing that a child can do to override it
final List<Node> ancestors = getAncestors();
final ArrayList<CSSStyleDeclaration> styles = new ArrayList<>(ancestors.size());
for (final Node node : ancestors) {
if (node instanceof HtmlElement && ((HtmlElement) node).isHidden()) {
return false;
}
if (node instanceof HtmlElement) {
final CSSStyleDeclaration style = window.getComputedStyle((HtmlElement) node, null);
if (DisplayStyle.NONE.value().equals(style.getDisplay())) {
return false;
}
styles.add(style);
}
}
// the visibility used by parent nodes
for (int i = styles.size() - 1; i >= 0; i--) {
final CSSStyleDeclaration style = styles.get(i);
final String visibility = style.getStyleAttribute(StyleAttributes.Definition.VISIBILITY);
if (visibility.length() > 5) {
if ("visible".equals(visibility)) {
return true;
}
if ("hidden".equals(visibility) || "collapse".equals(visibility)) {
return false;
}
}
}
}
return true;
}
use of com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleDeclaration in project htmlunit by HtmlUnit.
the class Element method isDisplayNone.
/**
* Returns whether the {@code display} is {@code none} or not.
* @return whether the {@code display} is {@code none} or not
*/
protected final boolean isDisplayNone() {
Element element = this;
while (element != null) {
final CSSStyleDeclaration style = element.getWindow().getComputedStyle(element, null);
final String display = style.getDisplay();
if (DisplayStyle.NONE.value().equals(display)) {
return true;
}
element = element.getParentElement();
}
return false;
}
Aggregations