Search in sources :

Example 1 with JsxGetter

use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter in project htmlunit by HtmlUnit.

the class Range method getCommonAncestorContainer.

/**
 * Returns the deepest common ancestor container of the Range's two boundary points.
 * @return the deepest common ancestor container of the Range's two boundary points
 */
@JsxGetter
public Object getCommonAncestorContainer() {
    final HashSet<Node> startAncestors = new HashSet<>();
    Node ancestor = startContainer_;
    while (ancestor != null) {
        startAncestors.add(ancestor);
        ancestor = ancestor.getParent();
    }
    ancestor = endContainer_;
    while (ancestor != null) {
        if (startAncestors.contains(ancestor)) {
            return ancestor;
        }
        ancestor = ancestor.getParent();
    }
    return Undefined.instance;
}
Also used : DomNode(com.gargoylesoftware.htmlunit.html.DomNode) HashSet(java.util.HashSet) JsxGetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)

Example 2 with JsxGetter

use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter in project htmlunit by HtmlUnit.

the class TextRange method getHtmlText.

/**
 * Retrieves the HTML fragment contained within the range.
 * @return the HTML fragment contained within the range
 */
@JsxGetter
public String getHtmlText() {
    final org.w3c.dom.Node node = range_.getCommonAncestorContainer();
    if (null == node) {
        return "";
    }
    final HTMLElement element = (HTMLElement) getScriptableFor(node);
    // TODO: not quite right, but good enough for now
    return element.getOuterHTML();
}
Also used : HTMLElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement) JsxGetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)

Example 3 with JsxGetter

use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter in project htmlunit by HtmlUnit.

the class File method getLastModifiedDate.

/**
 * Returns the {@code lastModifiedDate} property.
 * @return the {@code lastModifiedDate} property
 */
@JsxGetter({ CHROME, EDGE, IE })
public String getLastModifiedDate() {
    final Date date = new Date(getLastModified());
    final BrowserVersion browser = getBrowserVersion();
    final Locale locale = browser.getBrowserLocale();
    final TimeZone timezone = browser.getSystemTimezone();
    final FastDateFormat format = FastDateFormat.getInstance(LAST_MODIFIED_DATE_FORMAT, timezone, locale);
    return format.format(date);
}
Also used : Locale(java.util.Locale) TimeZone(java.util.TimeZone) FastDateFormat(org.apache.commons.lang3.time.FastDateFormat) BrowserVersion(com.gargoylesoftware.htmlunit.BrowserVersion) Date(java.util.Date) JsxGetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)

Example 4 with JsxGetter

use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter in project htmlunit by HtmlUnit.

the class MouseEvent method getScreenY.

/**
 * The vertical coordinate at which the event occurred relative to the origin of the screen
 * coordinate system. The value of this attribute is initialized lazily, in order to optimize
 * performance (it requires CSS parsing).
 *
 * @return the vertical coordinate
 */
@JsxGetter
public int getScreenY() {
    if (screenY_ == null) {
        final HTMLElement target = (HTMLElement) getTarget();
        screenY_ = Integer.valueOf(target.getPosY() + 10);
    }
    return screenY_.intValue();
}
Also used : HTMLElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement) JsxGetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)

Example 5 with JsxGetter

use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter 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)

Aggregations

JsxGetter (com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)64 DomNode (com.gargoylesoftware.htmlunit.html.DomNode)15 MalformedURLException (java.net.MalformedURLException)8 URL (java.net.URL)8 BrowserVersion (com.gargoylesoftware.htmlunit.BrowserVersion)4 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)4 Window (com.gargoylesoftware.htmlunit.javascript.host.Window)4 ComputedCSSStyleDeclaration (com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration)4 MediaListImpl (com.gargoylesoftware.css.dom.MediaListImpl)3 WebWindow (com.gargoylesoftware.htmlunit.WebWindow)3 HtmlAnchor (com.gargoylesoftware.htmlunit.html.HtmlAnchor)3 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)3 HtmlInput (com.gargoylesoftware.htmlunit.html.HtmlInput)3 HtmlTableRow (com.gargoylesoftware.htmlunit.html.HtmlTableRow)3 HTMLElement (com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement)3 JS_ANCHOR_PATHNAME_DETECT_WIN_DRIVES_URL (com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ANCHOR_PATHNAME_DETECT_WIN_DRIVES_URL)2 JS_ANCHOR_PATHNAME_NONE_FOR_BROKEN_URL (com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ANCHOR_PATHNAME_NONE_FOR_BROKEN_URL)2 JS_ANCHOR_PATHNAME_NONE_FOR_NONE_HTTP_URL (com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ANCHOR_PATHNAME_NONE_FOR_NONE_HTTP_URL)2 JS_ANCHOR_PATHNAME_PREFIX_WIN_DRIVES_URL (com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ANCHOR_PATHNAME_PREFIX_WIN_DRIVES_URL)2 JS_ANCHOR_PROTOCOL_COLON_FOR_BROKEN_URL (com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ANCHOR_PROTOCOL_COLON_FOR_BROKEN_URL)2