use of com.gargoylesoftware.htmlunit.javascript.host.Element in project htmlunit by HtmlUnit.
the class ComputedCSSStyleDeclaration method getHeight.
/**
* {@inheritDoc}
*/
@Override
public String getHeight() {
if (NONE.equals(getDisplay())) {
return AUTO;
}
final Element elem = getElement();
if (!elem.getDomNodeOrDie().isAttachedToPage()) {
if (getBrowserVersion().hasFeature(CSS_STYLE_PROP_DISCONNECTED_IS_EMPTY)) {
return "";
}
if (getStyleAttribute(HEIGHT, true).isEmpty()) {
return AUTO;
}
}
final int windowHeight = elem.getWindow().getWebWindow().getInnerHeight();
return pixelString(elem, new CssValue(0, windowHeight) {
@Override
public String get(final ComputedCSSStyleDeclaration style) {
final String offsetHeight = ((HTMLElement) elem).getOffsetHeight() + "px";
return defaultIfEmpty(style.getStyleAttribute(HEIGHT, true), offsetHeight, AUTO);
}
});
}
use of com.gargoylesoftware.htmlunit.javascript.host.Element in project htmlunit by HtmlUnit.
the class ComputedCSSStyleDeclaration method getWidth.
/**
* {@inheritDoc}
*/
@Override
public String getWidth() {
if (NONE.equals(getDisplay())) {
return AUTO;
}
final Element elem = getElement();
if (!elem.getDomNodeOrDie().isAttachedToPage()) {
if (getBrowserVersion().hasFeature(CSS_STYLE_PROP_DISCONNECTED_IS_EMPTY)) {
return "";
}
if (getStyleAttribute(WIDTH, true).isEmpty()) {
return AUTO;
}
}
final int windowWidth = elem.getWindow().getWebWindow().getInnerWidth();
return pixelString(elem, new CssValue(0, windowWidth) {
@Override
public String get(final ComputedCSSStyleDeclaration style) {
final String value = style.getStyleAttribute(WIDTH, true);
if (StringUtils.isEmpty(value)) {
if (ABSOLUTE.equals(getStyleAttribute(POSITION, true))) {
final String content = getDomNodeOrDie().getVisibleText();
// at least for empty div's this is more correct
if (null != content && content.length() < 13) {
return (content.length() * 7) + "px";
}
}
int windowDefaultValue = getWindowDefaultValue();
if (elem instanceof HTMLBodyElement) {
windowDefaultValue -= 16;
}
return windowDefaultValue + "px";
} else if (AUTO.equals(value)) {
int windowDefaultValue = getWindowDefaultValue();
if (elem instanceof HTMLBodyElement) {
windowDefaultValue -= 16;
}
return windowDefaultValue + "px";
}
return value;
}
});
}
use of com.gargoylesoftware.htmlunit.javascript.host.Element in project htmlunit by HtmlUnit.
the class ComputedCSSStyleDeclaration method isScrollable.
/**
* @param ignoreSize whether to consider the content/calculated width/height
*/
private boolean isScrollable(final boolean horizontal, final boolean ignoreSize) {
final boolean scrollable;
final Element node = getElement();
final String overflow = getStyleAttribute(OVERFLOW, true);
if (horizontal) {
// TODO: inherit, overflow-x
scrollable = (node instanceof HTMLBodyElement || "scroll".equals(overflow) || AUTO.equals(overflow)) && (ignoreSize || getContentWidth() > getCalculatedWidth());
} else {
// TODO: inherit, overflow-y
scrollable = (node instanceof HTMLBodyElement || "scroll".equals(overflow) || AUTO.equals(overflow)) && (ignoreSize || getContentHeight() > getEmptyHeight());
}
return scrollable;
}
use of com.gargoylesoftware.htmlunit.javascript.host.Element in project htmlunit by HtmlUnit.
the class XMLDocument method makeScriptableFor.
/**
* {@inheritDoc}
*/
@Override
public HtmlUnitScriptable makeScriptableFor(final DomNode domNode) {
final HtmlUnitScriptable scriptable;
// TODO: cleanup, getScriptObject() should be used!!!
if (domNode instanceof DomElement && !(domNode instanceof HtmlElement)) {
if (domNode instanceof SvgElement) {
final Class<? extends HtmlUnitScriptable> javaScriptClass = ((JavaScriptEngine) getWindow().getWebWindow().getWebClient().getJavaScriptEngine()).getJavaScriptClass(domNode.getClass());
try {
scriptable = javaScriptClass.newInstance();
} catch (final Exception e) {
throw Context.throwAsScriptRuntimeEx(e);
}
} else {
scriptable = new Element();
}
} else if (domNode instanceof DomAttr) {
scriptable = new Attr();
} else {
return super.makeScriptableFor(domNode);
}
scriptable.setPrototype(getPrototype(scriptable.getClass()));
scriptable.setParentScope(getParentScope());
scriptable.setDomNode(domNode);
return scriptable;
}
use of com.gargoylesoftware.htmlunit.javascript.host.Element in project htmlunit by HtmlUnit.
the class XMLSerializer method serializeToString.
/**
* The subtree rooted by the specified element is serialized to a string.
* @param root the root of the subtree to be serialized (this may be any node, even a document)
* @return the serialized string
*/
@JsxFunction
public String serializeToString(Node root) {
if (root == null) {
return "";
}
if (root instanceof DocumentFragment) {
if (root.getOwnerDocument() instanceof HTMLDocument && getBrowserVersion().hasFeature(JS_XML_SERIALIZER_HTML_DOCUMENT_FRAGMENT_ALWAYS_EMPTY)) {
return "";
}
Node node = root.getFirstChild();
if (node == null) {
return "";
}
final StringBuilder builder = new StringBuilder();
while (node != null) {
builder.append(serializeToString(node));
node = node.getNextSibling();
}
return builder.toString();
}
if (root instanceof Document) {
root = ((Document) root).getDocumentElement();
}
if (root instanceof Element) {
final StringBuilder builder = new StringBuilder();
final DomNode node = root.getDomNodeOrDie();
final SgmlPage page = node.getPage();
final boolean isHtmlPage = page != null && page.isHtmlPage();
String forcedNamespace = null;
if (isHtmlPage) {
forcedNamespace = "http://www.w3.org/1999/xhtml";
}
toXml(1, node, builder, forcedNamespace);
return builder.toString();
}
if (root instanceof CDATASection && getBrowserVersion().hasFeature(JS_XML_SERIALIZER_ROOT_CDATA_AS_ESCAPED_TEXT)) {
final DomCDataSection domCData = (DomCDataSection) root.getDomNodeOrDie();
final String data = domCData.getData();
if (org.apache.commons.lang3.StringUtils.isNotBlank(data)) {
return StringUtils.escapeXmlChars(data);
}
}
return root.getDomNodeOrDie().asXml();
}
Aggregations