Search in sources :

Example 1 with DOMRectImpl

use of org.loboevolution.html.js.geom.DOMRectImpl 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)

Aggregations

HTMLBodyElement (org.loboevolution.html.dom.HTMLBodyElement)1 TextImpl (org.loboevolution.html.dom.nodeimpl.TextImpl)1 DOMRectImpl (org.loboevolution.html.js.geom.DOMRectImpl)1 Window (org.loboevolution.html.node.js.Window)1 RenderState (org.loboevolution.html.renderstate.RenderState)1