use of com.gargoylesoftware.htmlunit.javascript.host.html.HTMLHtmlElement in project htmlunit by HtmlUnit.
the class CSSStyleDeclaration method pixelValue.
private static int pixelValue(final Element element, final CssValue value, final boolean percentMode) {
final String s = value.get(element);
if (s.endsWith("%") || (s.isEmpty() && element instanceof HTMLHtmlElement)) {
final float i = NumberUtils.toFloat(TO_FLOAT_PATTERN.matcher(s).replaceAll("$1"), 100);
final Element parent = element.getParentElement();
final int absoluteValue = (parent == null) ? value.getWindowDefaultValue() : pixelValue(parent, value, true);
return Math.round((i / 100f) * absoluteValue);
}
if (AUTO.equals(s)) {
return value.getDefaultValue();
}
if (s.isEmpty()) {
if (element instanceof HTMLCanvasElement) {
return value.getWindowDefaultValue();
}
// we can provide some kind of base value for percent calculation
if (percentMode) {
final Element parent = element.getParentElement();
if (parent == null || parent instanceof HTMLHtmlElement) {
return value.getWindowDefaultValue();
}
return pixelValue(parent, value, true);
}
return 0;
}
return pixelValue(s);
}
Aggregations