Search in sources :

Example 6 with ComputedCSSStyleDeclaration

use of com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration in project htmlunit by HtmlUnit.

the class HTMLTableCellElement method getOffsetWidth.

/**
 * {@inheritDoc}
 */
@Override
public int getOffsetWidth() {
    float w = super.getOffsetWidth();
    final MouseEvent event = MouseEvent.getCurrentMouseEvent();
    if (isAncestorOfEventTarget(event)) {
        return (int) w;
    }
    if (isDisplayNone()) {
        return 0;
    }
    final ComputedCSSStyleDeclaration style = getWindow().getComputedStyle(this, null);
    if ("collapse".equals(style.getStyleAttribute(StyleAttributes.Definition.BORDER_COLLAPSE))) {
        final HtmlTableRow row = getRow();
        if (row != null) {
            final HtmlElement thiz = getDomNodeOrDie();
            final List<HtmlTableCell> cells = row.getCells();
            final boolean ie = getBrowserVersion().hasFeature(JS_TABLE_CELL_OFFSET_INCLUDES_BORDER);
            final boolean leftmost = cells.indexOf(thiz) == 0;
            final boolean rightmost = cells.indexOf(thiz) == cells.size() - 1;
            w -= (ie && leftmost ? 0 : 0.5) * style.getBorderLeftValue();
            w -= (ie && rightmost ? 0 : 0.5) * style.getBorderRightValue();
        }
    }
    return (int) w;
}
Also used : HtmlTableRow(com.gargoylesoftware.htmlunit.html.HtmlTableRow) MouseEvent(com.gargoylesoftware.htmlunit.javascript.host.event.MouseEvent) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) ComputedCSSStyleDeclaration(com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration) HtmlTableCell(com.gargoylesoftware.htmlunit.html.HtmlTableCell)

Example 7 with ComputedCSSStyleDeclaration

use of com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration in project htmlunit by HtmlUnit.

the class HTMLElement method getOffsetLeft.

/**
 * Returns this element's <tt>offsetLeft</tt>, which is the calculated left position of this
 * element relative to the <tt>offsetParent</tt>.
 *
 * @return this element's <tt>offsetLeft</tt>
 * @see <a href="http://msdn2.microsoft.com/en-us/library/ms534200.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 getOffsetLeft() {
    if (this instanceof HTMLBodyElement) {
        return 0;
    }
    int left = 0;
    // Add the offset for this node.
    DomNode node = getDomNodeOrDie();
    HTMLElement element = node.getScriptableObject();
    ComputedCSSStyleDeclaration style = element.getWindow().getComputedStyle(element, null);
    left += style.getLeft(true, false, false);
    // If this node is absolutely positioned, we're done.
    final String position = style.getPositionWithInheritance();
    if ("absolute".equals(position)) {
        return left;
    }
    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);
            left += style.getLeft(true, true, true);
        }
        node = node.getParentNode();
    }
    if (offsetParent != null) {
        style = offsetParent.getWindow().getComputedStyle(offsetParent, null);
        left += style.getMarginLeftValue();
        left += style.getPaddingLeftValue();
    }
    return left;
}
Also used : DomNode(com.gargoylesoftware.htmlunit.html.DomNode) ComputedCSSStyleDeclaration(com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration) JsxGetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)

Example 8 with ComputedCSSStyleDeclaration

use of com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration in project htmlunit by HtmlUnit.

the class HTMLElement method getPosX.

/**
 * Returns this element's X position.
 * @return this element's X position
 */
public int getPosX() {
    int cumulativeOffset = 0;
    HTMLElement element = this;
    while (element != null) {
        cumulativeOffset += element.getOffsetLeft();
        if (element != this) {
            final ComputedCSSStyleDeclaration style = element.getWindow().getComputedStyle(element, null);
            cumulativeOffset += style.getBorderLeftValue();
        }
        element = element.getOffsetParent();
    }
    return cumulativeOffset;
}
Also used : ComputedCSSStyleDeclaration(com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration)

Example 9 with ComputedCSSStyleDeclaration

use of com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration in project htmlunit by HtmlUnit.

the class HTMLElement method getOffsetHeight.

/**
 * Returns this element's <tt>offsetHeight</tt>, which is the element height plus the element's padding
 * plus the element's border. This method returns a dummy value compatible with mouse event coordinates
 * during mouse events.
 * @return this element's <tt>offsetHeight</tt>
 * @see <a href="http://msdn2.microsoft.com/en-us/library/ms534199.aspx">MSDN Documentation</a>
 * @see <a href="http://www.quirksmode.org/js/elementdimensions.html">Element Dimensions</a>
 */
@JsxGetter
public int getOffsetHeight() {
    if (isDisplayNone() || !getDomNodeOrDie().isAttachedToPage()) {
        return 0;
    }
    final MouseEvent event = MouseEvent.getCurrentMouseEvent();
    if (isAncestorOfEventTarget(event)) {
        // compute appropriate offset height to pretend mouse event was produced within this element
        return event.getClientY() - getPosY() + 50;
    }
    final ComputedCSSStyleDeclaration style = getWindow().getComputedStyle(this, null);
    return style.getCalculatedHeight(true, true);
}
Also used : MouseEvent(com.gargoylesoftware.htmlunit.javascript.host.event.MouseEvent) ComputedCSSStyleDeclaration(com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration) JsxGetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)

Example 10 with ComputedCSSStyleDeclaration

use of com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration in project htmlunit by HtmlUnit.

the class HTMLElement method getOffsetWidth.

/**
 * Returns this element's <tt>offsetWidth</tt>, which is the element width plus the element's padding
 * plus the element's border. This method returns a dummy value compatible with mouse event coordinates
 * during mouse events.
 * @return this element's <tt>offsetWidth</tt>
 * @see <a href="http://msdn2.microsoft.com/en-us/library/ms534304.aspx">MSDN Documentation</a>
 * @see <a href="http://www.quirksmode.org/js/elementdimensions.html">Element Dimensions</a>
 */
@JsxGetter
public int getOffsetWidth() {
    if (isDisplayNone() || !getDomNodeOrDie().isAttachedToPage()) {
        return 0;
    }
    final MouseEvent event = MouseEvent.getCurrentMouseEvent();
    if (isAncestorOfEventTarget(event)) {
        // compute appropriate offset width to pretend mouse event was produced within this element
        return event.getClientX() - getPosX() + 50;
    }
    final ComputedCSSStyleDeclaration style = getWindow().getComputedStyle(this, null);
    return style.getCalculatedWidth(true, true);
}
Also used : MouseEvent(com.gargoylesoftware.htmlunit.javascript.host.event.MouseEvent) ComputedCSSStyleDeclaration(com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration) JsxGetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)

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