Search in sources :

Example 11 with ComputedCSSStyleDeclaration

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

the class HTMLElement method getOffsetParentInternal.

private Object getOffsetParentInternal(final boolean returnNullIfFixed) {
    DomNode currentElement = getDomNodeOrDie();
    if (currentElement.getParentNode() == null) {
        return null;
    }
    final HTMLElement htmlElement = currentElement.getScriptableObject();
    if (returnNullIfFixed && "fixed".equals(htmlElement.getStyle().getStyleAttribute(StyleAttributes.Definition.POSITION, true))) {
        return null;
    }
    final ComputedCSSStyleDeclaration style = htmlElement.getWindow().getComputedStyle(htmlElement, null);
    final String position = style.getPositionWithInheritance();
    final boolean staticPos = "static".equals(position);
    while (currentElement != null) {
        final DomNode parentNode = currentElement.getParentNode();
        if (parentNode instanceof HtmlBody || (staticPos && parentNode instanceof HtmlTableDataCell) || (staticPos && parentNode instanceof HtmlTable)) {
            return parentNode.getScriptableObject();
        }
        if (parentNode != null && parentNode.getScriptableObject() instanceof HTMLElement) {
            final HTMLElement parentElement = parentNode.getScriptableObject();
            final ComputedCSSStyleDeclaration parentStyle = parentElement.getWindow().getComputedStyle(parentElement, null);
            final String parentPosition = parentStyle.getPositionWithInheritance();
            if (!"static".equals(parentPosition)) {
                return parentNode.getScriptableObject();
            }
        }
        currentElement = currentElement.getParentNode();
    }
    return null;
}
Also used : DomNode(com.gargoylesoftware.htmlunit.html.DomNode) HtmlBody(com.gargoylesoftware.htmlunit.html.HtmlBody) HtmlTable(com.gargoylesoftware.htmlunit.html.HtmlTable) HtmlTableDataCell(com.gargoylesoftware.htmlunit.html.HtmlTableDataCell) ComputedCSSStyleDeclaration(com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration)

Example 12 with ComputedCSSStyleDeclaration

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

the class HtmlSerializerInnerOuterText method whiteSpaceStyle.

private static Mode whiteSpaceStyle(final DomNode domNode, final Mode defaultMode) {
    if (domNode instanceof DomElement) {
        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) 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;
                            }
                        }
                    }
                    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) Page(com.gargoylesoftware.htmlunit.Page) WebWindow(com.gargoylesoftware.htmlunit.WebWindow)

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