Package com.gargoylesoftware.htmlunit.html

Examples of com.gargoylesoftware.htmlunit.html.DomNode


        int top = 0;
        final HTMLElement offsetParent = getOffsetParent();

        // Add the offset for this node.
        DomNode node = getDomNodeOrDie();
        HTMLElement element = (HTMLElement) node.getScriptObject();
        top += element.jsxGet_currentStyle().getTop(true, false, false);

        // If this node is absolutely positioned, we're done.
        final String position = element.jsxGet_currentStyle().getPositionWithInheritance();
        if ("absolute".equals(position)) {
            return top;
        }

        // Add the offset for the ancestor nodes.
        node = node.getParentNode();
        while (node != null && node.getScriptObject() != offsetParent) {
            if (node.getScriptObject() instanceof HTMLElement) {
                element = (HTMLElement) node.getScriptObject();
                top += element.jsxGet_currentStyle().getTop(false, true, true);
            }
            node = node.getParentNode();
        }

        if (offsetParent != null) {
            final HTMLElement thiz = (HTMLElement) getDomNodeOrDie().getScriptObject();
            final boolean thisElementHasTopMargin = (thiz.jsxGet_currentStyle().getMarginTop() != 0);
View Full Code Here


        final boolean isXmlPage = node_ != null && node_.getOwnerDocument() instanceof XmlPage;

        final boolean isIE = getBrowserVersion().isIE();

        for (int i = 0; i < response.size(); i++) {
            final DomNode element = (DomNode) response.get(i);

            //IE: XmlPage ignores all empty text nodes
            if (isIE && isXmlPage && element instanceof DomText
                && ((DomText) element).getNodeValue().trim().length() == 0) { //and 'xml:space' is 'default'
                final Boolean xmlSpaceDefault = isXMLSpaceDefault(element.getParentNode());
                if (xmlSpaceDefault != Boolean.FALSE) {
                    response.remove(i--);
                    continue;
                }
            }
            for (DomNode parent = element.getParentNode(); parent != null;
                parent = parent.getParentNode()) {
                if (parent instanceof HtmlNoScript) {
                    response.remove(i--);
                    break;
                }
View Full Code Here

    public <N extends DomNode> N getDomNodeOrDie() throws IllegalStateException {
        try {
            return (N) super.getDomNodeOrDie();
        }
        catch (final IllegalStateException e) {
            final DomNode node = getDomNodeOrNullFromRealDocument();
            if (node != null) {
                return (N) node;
            }
            throw Context.reportRuntimeError("No node attached to this object");
        }
View Full Code Here

     * {@inheritDoc}
     */
    @Override
    @SuppressWarnings("unchecked")
    public DomNode getDomNodeOrNull() {
        DomNode node = super.getDomNodeOrNull();
        if (node == null) {
            node = getDomNodeOrNullFromRealDocument();
        }
        return node;
    }
View Full Code Here

     * for sample JavaScript code.
     *
     * @return the real document's DOM node, or <tt>null</tt> if we're not emulating IE
     */
    private DomNode getDomNodeOrNullFromRealDocument() {
        DomNode node = null;
        final boolean ie = getWindow().getWebWindow().getWebClient().getBrowserVersion().isIE();
        if (ie) {
            final Scriptable scope = getParentScope();
            if (scope instanceof Window) {
                final Window w = (Window) scope;
View Full Code Here

     * Gets the node that is the last one when exploring following nodes, depth-first.
     * @param node the node to search
     * @return the searched node
     */
    HtmlElement getLastHtmlElement(final HtmlElement node) {
        final DomNode lastChild = node.getLastChild();
        if (lastChild == null
                || !(lastChild instanceof HtmlElement)
                || lastChild instanceof HtmlScript) {
            return node;
        }
View Full Code Here

     * @see DomNode#READY_STATE_LOADED
     * @see DomNode#READY_STATE_INTERACTIVE
     * @see DomNode#READY_STATE_COMPLETE
     */
    public String jsxGet_readyState() {
        final DomNode node = getDomNodeOrDie();
        return node.getReadyState();
    }
View Full Code Here

            return width_;
        }

        int width;
        final String styleWidth = super.jsxGet_width();
        final DomNode parent = getElement().getDomNodeOrDie().getParentNode();
        if (StringUtils.isEmpty(styleWidth) && parent instanceof HtmlElement) {
            // Width not explicitly set.
            final String cssFloat = jsxGet_cssFloat();
            if ("right".equals(cssFloat) || "left".equals(cssFloat)) {
                // We're floating; simplistic approximation: text content * pixels per character.
                width = this.<DomNode>getDomNodeOrDie().getTextContent().length() * PIXELS_PER_CHAR;
            }
            else if ("block".equals(display)) {
                // Block elements take up 100% of the parent's width.
                final HTMLElement parentJS = (HTMLElement) parent.getScriptObject();
                final String parentWidth = getWindow().jsxFunction_getComputedStyle(parentJS, null).jsxGet_width();
                if (getBrowserVersion().isIE() && "auto".equals(parentWidth)) {
                    width = WINDOW_WIDTH;
                }
                else {
View Full Code Here

            // Estimate the vertical displacement caused by *all* siblings.
            // This is very rough, and doesn't even take position or display types into account (hence the
            // need for the explicit check for HtmlHead elements, which are display:none in regular UAs).
            // It also doesn't take into account the fact that the parent's height may be hardcoded in CSS.
            top = 0;
            DomNode child = this.getElement().getDomNodeOrDie().getParentNode().getFirstChild();
            while (child != null) {
                if (child instanceof HtmlElement && !(child instanceof HtmlHead)) {
                    top += 20;
                }
                child = child.getPreviousSibling();
            }
            top -= pixelValue(b);
        }
        else {
            // Estimate the vertical displacement caused by *previous* siblings.
            // This is very rough, and doesn't even take position or display types into account (hence the
            // need for the explicit check for HtmlHead elements, which are display:none in regular UAs).
            top = 0;
            DomNode prev = this.getElement().getDomNodeOrDie().getPreviousSibling();
            while (prev != null) {
                if (prev instanceof HtmlElement && !(prev instanceof HtmlHead)) {
                    top += 20;
                }
                prev = prev.getPreviousSibling();
            }
            // If the position is relative, we also need to add the specified "top" displacement.
            if ("relative".equals(p)) {
                top += pixelValue(t);
            }
View Full Code Here

     * Returns the <tt>text</tt> attribute.
     * @return the <tt>text</tt> attribute
     */
    @Override
    public String jsxGet_text() {
        final DomNode firstChild = getDomNodeOrDie().getFirstChild();
        if (firstChild != null) {
            return firstChild.getNodeValue();
        }
        return "";
    }
View Full Code Here

TOP

Related Classes of com.gargoylesoftware.htmlunit.html.DomNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.