Search in sources :

Example 6 with MouseEvent

use of com.gargoylesoftware.htmlunit.javascript.host.event.MouseEvent 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 MouseEvent

use of com.gargoylesoftware.htmlunit.javascript.host.event.MouseEvent 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 8 with MouseEvent

use of com.gargoylesoftware.htmlunit.javascript.host.event.MouseEvent 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

MouseEvent (com.gargoylesoftware.htmlunit.javascript.host.event.MouseEvent)8 ComputedCSSStyleDeclaration (com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration)4 PointerEvent (com.gargoylesoftware.htmlunit.javascript.host.event.PointerEvent)3 ScriptResult (com.gargoylesoftware.htmlunit.ScriptResult)2 SgmlPage (com.gargoylesoftware.htmlunit.SgmlPage)2 JsxGetter (com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)2 Event (com.gargoylesoftware.htmlunit.javascript.host.event.Event)2 BrowserVersion (com.gargoylesoftware.htmlunit.BrowserVersion)1 Page (com.gargoylesoftware.htmlunit.Page)1 WebClient (com.gargoylesoftware.htmlunit.WebClient)1 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)1 HtmlTableCell (com.gargoylesoftware.htmlunit.html.HtmlTableCell)1 HtmlTableRow (com.gargoylesoftware.htmlunit.html.HtmlTableRow)1 HTMLElement (com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement)1