use of com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration in project htmlunit by HtmlUnit.
the class HTMLElement method getPosY.
/**
* Returns this element's Y position.
* @return this element's Y position
*/
public int getPosY() {
int cumulativeOffset = 0;
HTMLElement element = this;
while (element != null) {
cumulativeOffset += element.getOffsetTop();
if (element != this) {
final ComputedCSSStyleDeclaration style = element.getWindow().getComputedStyle(element, null);
cumulativeOffset += style.getBorderTopValue();
}
element = element.getOffsetParent();
}
return cumulativeOffset;
}
use of com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration in project htmlunit by HtmlUnit.
the class HTMLElement method getOffsetTop.
/**
* Returns this element's {@code offsetTop}, which is the calculated top position of this
* element relative to the {@code offsetParent}.
*
* @return this element's {@code offsetTop}
* @see <a href="http://msdn2.microsoft.com/en-us/library/ms534303.aspx">MSDN Documentation</a>
* @see <a href="http://www.quirksmode.org/js/elementdimensions.html">Element Dimensions</a>
* @see <a href="http://dump.testsuite.org/2006/dom/style/offset/spec">Reverse Engineering by Anne van Kesteren</a>
*/
@JsxGetter
public int getOffsetTop() {
if (this instanceof HTMLBodyElement) {
return 0;
}
int top = 0;
// Add the offset for this node.
DomNode node = getDomNodeOrDie();
HTMLElement element = node.getScriptableObject();
ComputedCSSStyleDeclaration style = element.getWindow().getComputedStyle(element, null);
top += style.getTop(true, false, false);
// If this node is absolutely positioned, we're done.
final String position = style.getPositionWithInheritance();
if ("absolute".equals(position)) {
return top;
}
final HTMLElement offsetParent = getOffsetParent();
// Add the offset for the ancestor nodes.
node = node.getParentNode();
while (node != null && node.getScriptableObject() != offsetParent) {
if (node.getScriptableObject() instanceof HTMLElement) {
element = node.getScriptableObject();
style = element.getWindow().getComputedStyle(element, null);
top += style.getTop(false, true, true);
}
node = node.getParentNode();
}
if (offsetParent != null) {
final HTMLElement thiz = getDomNodeOrDie().getScriptableObject();
style = thiz.getWindow().getComputedStyle(thiz, null);
final boolean thisElementHasTopMargin = style.getMarginTopValue() != 0;
style = offsetParent.getWindow().getComputedStyle(offsetParent, null);
if (!thisElementHasTopMargin) {
top += style.getMarginTopValue();
}
top += style.getPaddingTopValue();
}
return top;
}
use of com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration in project htmlunit by HtmlUnit.
the class HtmlSerializerVisibleText method whiteSpaceStyle.
protected Mode whiteSpaceStyle(final DomNode domNode, final Mode defaultMode) {
final Page page = domNode.getPage();
if (page != null) {
final WebWindow window = page.getEnclosingWindow();
if (window.getWebClient().getOptions().isCssEnabled()) {
DomNode node = domNode;
while (node != null) {
if (node instanceof DomElement) {
final ComputedCSSStyleDeclaration style = window.getComputedStyle((DomElement) node, null);
final String value = style.getStyleAttribute(Definition.WHITE_SPACE, false);
if (StringUtils.isNoneEmpty(value)) {
if ("normal".equalsIgnoreCase(value)) {
return Mode.WHITE_SPACE_NORMAL;
}
if ("nowrap".equalsIgnoreCase(value)) {
return Mode.WHITE_SPACE_NORMAL;
}
if ("pre".equalsIgnoreCase(value)) {
return Mode.WHITE_SPACE_PRE;
}
if ("pre-wrap".equalsIgnoreCase(value)) {
return Mode.WHITE_SPACE_PRE;
}
if ("pre-line".equalsIgnoreCase(value)) {
return Mode.WHITE_SPACE_PRE_LINE;
}
}
}
node = node.getParentNode();
}
}
}
return defaultMode;
}
use of com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration in project htmlunit by HtmlUnit.
the class HtmlSerializerVisibleText method updateWhiteSpaceStyle.
protected Mode updateWhiteSpaceStyle(final DomNode domNode, final Mode defaultMode) {
final Page page = domNode.getPage();
if (page != null) {
final WebWindow window = page.getEnclosingWindow();
if (window.getWebClient().getOptions().isCssEnabled()) {
if (domNode instanceof DomElement) {
final ComputedCSSStyleDeclaration style = window.getComputedStyle((DomElement) domNode, null);
final String value = style.getStyleAttribute(Definition.WHITE_SPACE, false);
if (StringUtils.isNoneEmpty(value)) {
if ("normal".equalsIgnoreCase(value)) {
return Mode.WHITE_SPACE_NORMAL;
}
if ("nowrap".equalsIgnoreCase(value)) {
return Mode.WHITE_SPACE_NORMAL;
}
if ("pre".equalsIgnoreCase(value)) {
return Mode.WHITE_SPACE_PRE;
}
if ("pre-wrap".equalsIgnoreCase(value)) {
return Mode.WHITE_SPACE_PRE;
}
if ("pre-line".equalsIgnoreCase(value)) {
return Mode.WHITE_SPACE_PRE_LINE;
}
}
}
}
}
return defaultMode;
}
use of com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration in project htmlunit by HtmlUnit.
the class HTMLTableCellElement method getOffsetHeight.
/**
* {@inheritDoc}
*/
@Override
public int getOffsetHeight() {
final MouseEvent event = MouseEvent.getCurrentMouseEvent();
if (isAncestorOfEventTarget(event)) {
return super.getOffsetHeight();
}
if (isDisplayNone()) {
return 0;
}
final ComputedCSSStyleDeclaration style = getWindow().getComputedStyle(this, null);
final boolean includeBorder = getBrowserVersion().hasFeature(JS_TABLE_CELL_OFFSET_INCLUDES_BORDER);
return style.getCalculatedHeight(includeBorder, true);
}
Aggregations