Search in sources :

Example 1 with Window

use of org.loboevolution.html.node.js.Window in project LoboEvolution by LoboEvolution.

the class ElementImpl method getBoundingClientRect.

/**
 * {@inheritDoc}
 */
@Override
public DOMRect getBoundingClientRect() {
    AbstractCSSProperties currentStyle = ((HTMLElementImpl) this).getCurrentStyle();
    final HTMLDocumentImpl doc = (HTMLDocumentImpl) this.document;
    final Window win = doc.getDefaultView();
    final RenderState rs = doc.getRenderState();
    int width = calculateWidth(true, true);
    int height = calculateHeight(true, true);
    int top = HtmlValues.getPixelSize(currentStyle.getTop(), rs, win, 0);
    int left = HtmlValues.getPixelSize(currentStyle.getLeft(), rs, win, 0);
    for (Node n = getParentNode(); n != null; n = n.getParentNode()) {
        if (!(n instanceof HTMLBodyElement) && !(n instanceof TextImpl) && !(n instanceof HTMLDocumentImpl)) {
            HTMLElementImpl p = (HTMLElementImpl) n;
            AbstractCSSProperties pCurrentStyle = p.getCurrentStyle();
            String topTxt = pCurrentStyle.getTop();
            String leftTxt = pCurrentStyle.getLeft();
            int scrollTop = (int) p.getScrollTop();
            int scrollLeft = (int) p.getScrollLeft();
            if (Strings.isNotBlank(topTxt)) {
                top += HtmlValues.getPixelSize(topTxt, rs, win, 0);
            }
            if (Strings.isNotBlank(leftTxt)) {
                left += HtmlValues.getPixelSize(leftTxt, rs, win, 0);
            }
            top -= scrollTop;
            left -= scrollLeft;
        }
    }
    return new DOMRectImpl(width, height, top, 0, 0, left);
}
Also used : Window(org.loboevolution.html.node.js.Window) RenderState(org.loboevolution.html.renderstate.RenderState) HTMLBodyElement(org.loboevolution.html.dom.HTMLBodyElement) TextImpl(org.loboevolution.html.dom.nodeimpl.TextImpl) DOMRectImpl(org.loboevolution.html.js.geom.DOMRectImpl)

Example 2 with Window

use of org.loboevolution.html.node.js.Window in project LoboEvolution by LoboEvolution.

the class LoboUnitTest method checkSelectorsTest.

/**
 * <p>checkSelectorsTest.</p>
 *
 * @param html a {@link java.lang.String} object.
 * @param result1 a {@link java.lang.String} object.
 * @param result2 a {@link java.lang.String} object.
 */
public void checkSelectorsTest(final String html, final String result1, final String result2) {
    HTMLDocumentImpl doc = loadHtml(html);
    Window window = doc.getDefaultView();
    HTMLElement div = (HTMLElement) doc.getElementById("myId");
    HTMLElement div2 = (HTMLElement) doc.getElementById("myId2");
    ComputedCSSStyleDeclaration computedStyle = (ComputedCSSStyleDeclaration) window.getComputedStyle(div);
    ComputedCSSStyleDeclaration computedStyle2 = (ComputedCSSStyleDeclaration) window.getComputedStyle(div2);
    assertEquals(result1, computedStyle.getColor());
    assertEquals(result2, computedStyle2.getColor());
}
Also used : Window(org.loboevolution.html.node.js.Window) HTMLDocumentImpl(org.loboevolution.html.dom.domimpl.HTMLDocumentImpl) HTMLElement(org.loboevolution.html.dom.HTMLElement) ComputedCSSStyleDeclaration(org.loboevolution.html.style.ComputedCSSStyleDeclaration)

Example 3 with Window

use of org.loboevolution.html.node.js.Window in project LoboEvolution by LoboEvolution.

the class LoboUnitTest method checkHtmlAlert.

/**
 * <p>checkHtmlAlert.</p>
 *
 * @param html a {@link java.lang.String} object.
 * @param messages an array of {@link java.lang.String} objects.
 */
public void checkHtmlAlert(final String html, final String[] messages) {
    Window window = null;
    List<String> alerts = null;
    try {
        HTMLDocumentImpl doc = loadHtml(html);
        window = doc.getDefaultView();
        alerts = Arrays.asList(messages);
        assertEquals(alerts, window.getMsg());
    } catch (AssertionError e) {
        throw new AssertionError("Result expected: " + alerts + " Result: " + window.getMsg());
    } catch (Exception ex) {
        logger.severe(ex.getMessage());
    }
}
Also used : Window(org.loboevolution.html.node.js.Window) HTMLDocumentImpl(org.loboevolution.html.dom.domimpl.HTMLDocumentImpl)

Example 4 with Window

use of org.loboevolution.html.node.js.Window in project LoboEvolution by LoboEvolution.

the class DelayedPair method helperGetPixelSize.

private Integer helperGetPixelSize(final String spec, final RenderState rs, final int errorValue, final int avail) {
    if (spec != null) {
        Window window = null;
        ModelNode node = getModelNode();
        if (node instanceof HTMLDocument) {
            HTMLDocumentImpl doc = (HTMLDocumentImpl) node;
            window = doc.getDefaultView();
        }
        return "auto".equals(spec) ? null : HtmlValues.getPixelSize(spec, rs, window, errorValue, avail);
    } else {
        return null;
    }
}
Also used : Window(org.loboevolution.html.node.js.Window) HTMLDocumentImpl(org.loboevolution.html.dom.domimpl.HTMLDocumentImpl) HTMLDocument(org.loboevolution.html.dom.HTMLDocument) ModelNode(org.loboevolution.html.dom.nodeimpl.ModelNode)

Aggregations

Window (org.loboevolution.html.node.js.Window)4 HTMLDocumentImpl (org.loboevolution.html.dom.domimpl.HTMLDocumentImpl)3 HTMLBodyElement (org.loboevolution.html.dom.HTMLBodyElement)1 HTMLDocument (org.loboevolution.html.dom.HTMLDocument)1 HTMLElement (org.loboevolution.html.dom.HTMLElement)1 ModelNode (org.loboevolution.html.dom.nodeimpl.ModelNode)1 TextImpl (org.loboevolution.html.dom.nodeimpl.TextImpl)1 DOMRectImpl (org.loboevolution.html.js.geom.DOMRectImpl)1 RenderState (org.loboevolution.html.renderstate.RenderState)1 ComputedCSSStyleDeclaration (org.loboevolution.html.style.ComputedCSSStyleDeclaration)1