Search in sources :

Example 1 with ComputedCSSStyleDeclaration

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;
}
Also used : ComputedCSSStyleDeclaration(com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration)

Example 2 with ComputedCSSStyleDeclaration

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;
}
Also used : DomNode(com.gargoylesoftware.htmlunit.html.DomNode) ComputedCSSStyleDeclaration(com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration) JsxGetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)

Example 3 with ComputedCSSStyleDeclaration

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;
}
Also used : DomNode(com.gargoylesoftware.htmlunit.html.DomNode) DomElement(com.gargoylesoftware.htmlunit.html.DomElement) ComputedCSSStyleDeclaration(com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration) SgmlPage(com.gargoylesoftware.htmlunit.SgmlPage) Page(com.gargoylesoftware.htmlunit.Page) WebWindow(com.gargoylesoftware.htmlunit.WebWindow)

Example 4 with ComputedCSSStyleDeclaration

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;
}
Also used : DomElement(com.gargoylesoftware.htmlunit.html.DomElement) ComputedCSSStyleDeclaration(com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration) SgmlPage(com.gargoylesoftware.htmlunit.SgmlPage) Page(com.gargoylesoftware.htmlunit.Page) WebWindow(com.gargoylesoftware.htmlunit.WebWindow)

Example 5 with ComputedCSSStyleDeclaration

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);
}
Also used : MouseEvent(com.gargoylesoftware.htmlunit.javascript.host.event.MouseEvent) ComputedCSSStyleDeclaration(com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration)

Aggregations

ComputedCSSStyleDeclaration (com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration)12 DomNode (com.gargoylesoftware.htmlunit.html.DomNode)5 JsxGetter (com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)4 MouseEvent (com.gargoylesoftware.htmlunit.javascript.host.event.MouseEvent)4 Page (com.gargoylesoftware.htmlunit.Page)3 WebWindow (com.gargoylesoftware.htmlunit.WebWindow)3 DomElement (com.gargoylesoftware.htmlunit.html.DomElement)3 SgmlPage (com.gargoylesoftware.htmlunit.SgmlPage)2 HtmlBody (com.gargoylesoftware.htmlunit.html.HtmlBody)1 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)1 HtmlTable (com.gargoylesoftware.htmlunit.html.HtmlTable)1 HtmlTableCell (com.gargoylesoftware.htmlunit.html.HtmlTableCell)1 HtmlTableDataCell (com.gargoylesoftware.htmlunit.html.HtmlTableDataCell)1 HtmlTableRow (com.gargoylesoftware.htmlunit.html.HtmlTableRow)1