Search in sources :

Example 16 with HTMLElement

use of com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement in project htmlunit by HtmlUnit.

the class ComputedCSSStyleDeclaration method getRightWithInheritance.

/**
 * Returns the CSS {@code right} attribute, replacing inherited values with the actual parent values.
 * @return the CSS {@code right} attribute, replacing inherited values with the actual parent values
 */
public String getRightWithInheritance() {
    String right = getRight();
    if (INHERIT.equals(right)) {
        final HTMLElement parent = (HTMLElement) getElement().getParentElement();
        if (parent == null) {
            right = AUTO;
        } else {
            final ComputedCSSStyleDeclaration style = parent.getWindow().getComputedStyle(parent, null);
            right = style.getRightWithInheritance();
        }
    }
    return right;
}
Also used : HTMLElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement) AttributedString(java.text.AttributedString)

Example 17 with HTMLElement

use of com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement in project htmlunit by HtmlUnit.

the class ComputedCSSStyleDeclaration method getTop.

/**
 * Returns the computed top (Y coordinate), relative to the node's parent's top edge.
 * @param includeMargin whether or not to take the margin into account in the calculation
 * @param includeBorder whether or not to take the border into account in the calculation
 * @param includePadding whether or not to take the padding into account in the calculation
 * @return the computed top (Y coordinate), relative to the node's parent's top edge
 */
public int getTop(final boolean includeMargin, final boolean includeBorder, final boolean includePadding) {
    int top = 0;
    if (null == top_) {
        final String p = getPositionWithInheritance();
        if (ABSOLUTE.equals(p)) {
            top = getTopForAbsolutePositionWithInheritance();
        } else {
            // Calculate the vertical displacement caused by *previous* siblings.
            DomNode prev = getElement().getDomNodeOrDie().getPreviousSibling();
            boolean prevHadComputedTop = false;
            while (prev != null && !prevHadComputedTop) {
                if (prev instanceof HtmlElement) {
                    final Element e = prev.getScriptableObject();
                    final ComputedCSSStyleDeclaration style = e.getWindow().getComputedStyle(e, null);
                    // only previous block elements are counting
                    final String display = style.getDisplay();
                    if (isBlock(display)) {
                        int prevTop = 0;
                        if (style.top_ == null) {
                            final String prevPosition = style.getPositionWithInheritance();
                            if (ABSOLUTE.equals(prevPosition)) {
                                prevTop += style.getTopForAbsolutePositionWithInheritance();
                            } else {
                                if (RELATIVE.equals(prevPosition)) {
                                    final String t = style.getTopWithInheritance();
                                    prevTop += pixelValue(t);
                                }
                            }
                        } else {
                            prevHadComputedTop = true;
                            prevTop += style.top_;
                        }
                        prevTop += style.getCalculatedHeight(true, true);
                        final int margin = pixelValue(style.getMarginTop());
                        prevTop += margin;
                        top += prevTop;
                    }
                }
                prev = prev.getPreviousSibling();
            }
            // If the position is relative, we also need to add the specified "top" displacement.
            if (RELATIVE.equals(p)) {
                final String t = getTopWithInheritance();
                top += pixelValue(t);
            }
        }
        top_ = Integer.valueOf(top);
    } else {
        top = top_.intValue();
    }
    if (includeMargin) {
        final int margin = pixelValue(getMarginTop());
        top += margin;
    }
    if (includeBorder) {
        final int border = pixelValue(getBorderTopWidth());
        top += border;
    }
    if (includePadding) {
        final int padding = getPaddingTopValue();
        top += padding;
    }
    return top;
}
Also used : DomNode(com.gargoylesoftware.htmlunit.html.DomNode) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) HTMLBodyElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLBodyElement) DomElement(com.gargoylesoftware.htmlunit.html.DomElement) BaseFrameElement(com.gargoylesoftware.htmlunit.html.BaseFrameElement) Element(com.gargoylesoftware.htmlunit.javascript.host.Element) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) HTMLDataElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDataElement) HTMLDivElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDivElement) HTMLSlotElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLSlotElement) HTMLImageElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLImageElement) HTMLUnknownElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLUnknownElement) HTMLCanvasElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLCanvasElement) StyleElement(com.gargoylesoftware.htmlunit.css.StyleElement) HTMLTimeElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLTimeElement) HTMLIFrameElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLIFrameElement) HTMLOutputElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLOutputElement) HTMLLegendElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLLegendElement) HTMLElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement) AttributedString(java.text.AttributedString)

Example 18 with HTMLElement

use of com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement in project htmlunit by HtmlUnit.

the class ComputedCSSStyleDeclaration method getPositionWithInheritance.

/**
 * Returns the CSS {@code position} attribute, replacing inherited values with the actual parent values.
 * @return the CSS {@code position} attribute, replacing inherited values with the actual parent values
 */
public String getPositionWithInheritance() {
    String p = getStyleAttribute(POSITION, true);
    if (INHERIT.equals(p)) {
        final HTMLElement parent = (HTMLElement) getElement().getParentElement();
        if (parent == null) {
            p = STATIC;
        } else {
            final ComputedCSSStyleDeclaration style = parent.getWindow().getComputedStyle(parent, null);
            p = style.getPositionWithInheritance();
        }
    }
    return p;
}
Also used : HTMLElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement) AttributedString(java.text.AttributedString)

Example 19 with HTMLElement

use of com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement in project htmlunit by HtmlUnit.

the class CSSImportRule method getStyleSheet.

/**
 * Returns the style sheet referred to by this rule.
 * @return the style sheet referred to by this rule
 */
@JsxGetter
public CSSStyleSheet getStyleSheet() {
    if (importedStylesheet_ == null) {
        final CSSStyleSheet owningSheet = getParentStyleSheet();
        final HTMLElement ownerNode = owningSheet.getOwnerNode();
        final CSSStyleSheet importedSheet = owningSheet.getImportedStyleSheet(getImportRule());
        importedStylesheet_ = new CSSStyleSheet(null, ownerNode.getWindow(), importedSheet.getWrappedSheet(), importedSheet.getUri());
    }
    return importedStylesheet_;
}
Also used : HTMLElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement) JsxGetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)

Example 20 with HTMLElement

use of com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement in project jenkins by jenkinsci.

the class ViewTest method newJob_descriptionSupportsHtml.

@Test
public void newJob_descriptionSupportsHtml() throws Exception {
    CustomizableTLID customizableTLID = j.jenkins.getExtensionList(TopLevelItemDescriptor.class).get(CustomizableTLID.class);
    customizableTLID.customId = "html-desc";
    customizableTLID.customDescription = "Super <strong>looong</strong> description";
    JenkinsRule.WebClient wc = j.createWebClient();
    HtmlPage page = wc.goTo("view/all/newJob");
    Object result = page.executeJavaScript("document.querySelector('.html-desc .desc strong')").getJavaScriptResult();
    assertThat(result, instanceOf(HTMLElement.class));
    assertThat(((HTMLElement) result).getTagName(), is("STRONG"));
}
Also used : HTMLElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) WebClient(org.jvnet.hudson.test.JenkinsRule.WebClient) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) Test(org.junit.Test)

Aggregations

HTMLElement (com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement)35 AttributedString (java.text.AttributedString)10 DomNode (com.gargoylesoftware.htmlunit.html.DomNode)7 Test (org.junit.Test)7 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)6 JsxFunction (com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)6 DomElement (com.gargoylesoftware.htmlunit.html.DomElement)5 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)5 MouseEvent (com.gargoylesoftware.htmlunit.javascript.host.event.MouseEvent)5 ScriptableObject (net.sourceforge.htmlunit.corejs.javascript.ScriptableObject)5 BaseFrameElement (com.gargoylesoftware.htmlunit.html.BaseFrameElement)4 HtmlAttributeChangeEvent (com.gargoylesoftware.htmlunit.html.HtmlAttributeChangeEvent)4 JsxGetter (com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)4 Event (com.gargoylesoftware.htmlunit.javascript.host.event.Event)4 MessageEvent (com.gargoylesoftware.htmlunit.javascript.host.event.MessageEvent)4 HTMLUnknownElement (com.gargoylesoftware.htmlunit.javascript.host.html.HTMLUnknownElement)4 StyleElement (com.gargoylesoftware.htmlunit.css.StyleElement)3 Element (com.gargoylesoftware.htmlunit.javascript.host.Element)3 HTMLBodyElement (com.gargoylesoftware.htmlunit.javascript.host.html.HTMLBodyElement)3 HTMLCanvasElement (com.gargoylesoftware.htmlunit.javascript.host.html.HTMLCanvasElement)3