Search in sources :

Example 1 with RenderState

use of org.loboevolution.html.renderstate.RenderState 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) AbstractCSSProperties(org.loboevolution.html.style.AbstractCSSProperties) TextImpl(org.loboevolution.html.dom.nodeimpl.TextImpl) DOMRectImpl(org.loboevolution.html.js.geom.DOMRectImpl)

Example 2 with RenderState

use of org.loboevolution.html.renderstate.RenderState in project LoboEvolution by LoboEvolution.

the class RUIControl method paint.

/**
 * {@inheritDoc}
 */
@Override
public final void paint(final Graphics g) {
    final RenderState rs = this.modelNode.getRenderState();
    if ((rs != null) && (rs.getVisibility() == RenderState.VISIBILITY_VISIBLE)) {
        // Prepaint borders, background images, etc.
        this.prePaint(g);
        // We need to paint the GUI component.
        // For various reasons, we need to do that
        // instead of letting AWT do it.
        final Insets insets = this.getBorderInsets();
        g.translate(insets.left, insets.top);
        try {
            this.widget.paint(g);
        } finally {
            g.translate(-insets.left, -insets.top);
        }
    }
}
Also used : RenderState(org.loboevolution.html.renderstate.RenderState)

Example 3 with RenderState

use of org.loboevolution.html.renderstate.RenderState in project LoboEvolution by LoboEvolution.

the class RUIControl method doLayout.

/**
 * {@inheritDoc}
 */
@Override
public void doLayout(final int availWidth, final int availHeight, final boolean sizeOnly) {
    final Map<LayoutKey, LayoutValue> cachedLayout = this.cachedLayout;
    final RenderState rs = this.modelNode.getRenderState();
    final int whitespace = rs == null ? RenderState.WS_NORMAL : rs.getWhiteSpace();
    final Font font = rs == null ? null : rs.getFont();
    final LayoutKey layoutKey = new LayoutKey(availWidth, availHeight, whitespace, font);
    LayoutValue layoutValue;
    if (sizeOnly) {
        layoutValue = cachedLayout.get(layoutKey);
    } else {
        if (Objects.equals(this.lastLayoutKey, layoutKey)) {
            layoutValue = this.lastLayoutValue;
        } else {
            layoutValue = null;
        }
    }
    if (layoutValue == null) {
        this.applyStyle(availWidth, availHeight);
        final RenderState renderState = this.modelNode.getRenderState();
        Insets paddingInsets = this.paddingInsets == null ? RBlockViewport.ZERO_INSETS : this.paddingInsets;
        Insets borderInsets = this.borderInsets == null ? RBlockViewport.ZERO_INSETS : this.borderInsets;
        Insets marginInsets = this.marginInsets == null ? RBlockViewport.ZERO_INSETS : this.marginInsets;
        final int paddingWidth = paddingInsets.left - paddingInsets.right;
        final int borderWidth = borderInsets.left - borderInsets.right;
        final int marginWidth = marginInsets.left - marginInsets.right;
        final int paddingHeight = paddingInsets.top - paddingInsets.bottom;
        final int borderHeight = borderInsets.top - borderInsets.bottom;
        final int marginHeight = marginInsets.top - marginInsets.bottom;
        final int actualAvailWidth = availWidth - paddingWidth - borderWidth - marginWidth;
        final int actualAvailHeight = availHeight - paddingHeight - borderHeight - marginHeight;
        final Integer dw = this.getDeclaredWidth(renderState, actualAvailWidth);
        final Integer dh = this.getDeclaredHeight(renderState, actualAvailHeight);
        final int declaredWidth = dw == null ? -1 : dw;
        final int declaredHeight = dh == null ? -1 : dh;
        this.declaredWidth = declaredWidth;
        this.declaredHeight = declaredHeight;
        final UIControl widget = this.widget;
        widget.reset(availWidth, availHeight);
        final Insets insets = this.getInsets(false, false);
        int finalWidth = declaredWidth == -1 ? -1 : declaredWidth + insets.left + insets.right;
        int finalHeight = declaredHeight == -1 ? -1 : declaredHeight + insets.top + insets.bottom;
        final Dimension size = widget.getPreferredSize();
        if (finalWidth == -1) {
            finalWidth = size.width + insets.left + insets.right;
        }
        if (finalHeight == -1) {
            finalHeight = size.height + insets.top + insets.bottom;
        }
        layoutValue = new LayoutValue(finalWidth, finalHeight);
        if (sizeOnly) {
            if (cachedLayout.size() > MAX_CACHE_SIZE) {
                cachedLayout.clear();
            }
            cachedLayout.put(layoutKey, layoutValue);
            this.lastLayoutKey = null;
            this.lastLayoutValue = null;
        } else {
            this.lastLayoutKey = layoutKey;
            this.lastLayoutValue = layoutValue;
        }
    }
    this.width = layoutValue.width;
    this.height = layoutValue.height;
}
Also used : RenderState(org.loboevolution.html.renderstate.RenderState)

Example 4 with RenderState

use of org.loboevolution.html.renderstate.RenderState in project LoboEvolution by LoboEvolution.

the class BaseElementRenderable method applyStyle.

/**
 * <p>applyStyle.</p>
 *
 * @param availWidth a int.
 * @param availHeight a int.
 */
protected void applyStyle(int availWidth, int availHeight) {
    final Object rootNode = this.modelNode;
    HTMLElementImpl rootElement;
    boolean isRootBlock;
    if (rootNode instanceof HTMLDocumentImpl) {
        isRootBlock = true;
        final HTMLDocumentImpl doc = (HTMLDocumentImpl) rootNode;
        rootElement = (HTMLElementImpl) doc.getBody();
    } else {
        isRootBlock = false;
        rootElement = (HTMLElementImpl) rootNode;
    }
    if (rootElement == null) {
        clearStyle(isRootBlock);
        return;
    }
    final RenderState rs = rootElement.getRenderState();
    if (rs == null) {
        throw new IllegalStateException("Element without render state: " + rootElement + "; parent=" + rootElement.getParentNode());
    }
    backgroundApplyStyle(rs);
    final AbstractCSSProperties props = rootElement.getCurrentStyle();
    if (props == null) {
        clearStyle(isRootBlock);
    } else {
        insetsApplyStyle(rs, availWidth, availHeight, isRootBlock);
        zIndexApplyStyle(props);
        this.overflowX = rs.getOverflowX();
        this.overflowY = rs.getOverflowY();
    }
}
Also used : HTMLElementImpl(org.loboevolution.html.dom.domimpl.HTMLElementImpl) HTMLDocumentImpl(org.loboevolution.html.dom.domimpl.HTMLDocumentImpl) RenderState(org.loboevolution.html.renderstate.RenderState) AbstractCSSProperties(org.loboevolution.html.style.AbstractCSSProperties)

Example 5 with RenderState

use of org.loboevolution.html.renderstate.RenderState in project LoboEvolution by LoboEvolution.

the class BaseElementRenderable method getCollapsibleMarginTop.

/**
 * {@inheritDoc}
 */
@Override
public int getCollapsibleMarginTop() {
    int cm;
    final Insets paddingInsets = this.paddingInsets;
    if (paddingInsets != null && paddingInsets.top > 0) {
        cm = 0;
    } else {
        final Insets borderInsets = this.borderInsets;
        if (borderInsets != null && borderInsets.top > 0) {
            cm = 0;
        } else {
            cm = getMarginTop();
        }
    }
    if (isMarginBoundary()) {
        final RenderState rs = this.modelNode.getRenderState();
        if (rs != null) {
            final FontMetrics fm = rs.getFontMetrics();
            final int fontHeight = fm.getHeight();
            if (fontHeight > cm) {
                cm = fontHeight;
            }
        }
    }
    return cm;
}
Also used : BorderInsets(org.loboevolution.html.style.BorderInsets) HtmlInsets(org.loboevolution.html.style.HtmlInsets) RenderState(org.loboevolution.html.renderstate.RenderState)

Aggregations

RenderState (org.loboevolution.html.renderstate.RenderState)33 HtmlInsets (org.loboevolution.html.style.HtmlInsets)5 HTMLElementImpl (org.loboevolution.html.dom.domimpl.HTMLElementImpl)3 ModelNode (org.loboevolution.html.dom.nodeimpl.ModelNode)3 NodeImpl (org.loboevolution.html.dom.nodeimpl.NodeImpl)3 BlockRenderState (org.loboevolution.html.renderstate.BlockRenderState)3 AbstractCSSProperties (org.loboevolution.html.style.AbstractCSSProperties)3 Color (java.awt.Color)2 FontMetrics (java.awt.FontMetrics)2 CSSValues (org.loboevolution.html.CSSValues)2 HTMLDocumentImpl (org.loboevolution.html.dom.domimpl.HTMLDocumentImpl)2 BorderInsets (org.loboevolution.html.style.BorderInsets)2 HtmlRendererContext (org.loboevolution.http.HtmlRendererContext)2 Cursor (java.awt.Cursor)1 Dimension (java.awt.Dimension)1 ListValues (org.loboevolution.html.ListValues)1 HTMLBodyElement (org.loboevolution.html.dom.HTMLBodyElement)1 HTMLHtmlElement (org.loboevolution.html.dom.HTMLHtmlElement)1 TextImpl (org.loboevolution.html.dom.nodeimpl.TextImpl)1 DOMRectImpl (org.loboevolution.html.js.geom.DOMRectImpl)1