Search in sources :

Example 1 with HtmlRendererContext

use of org.loboevolution.http.HtmlRendererContext in project LoboEvolution by LoboEvolution.

the class ElementImpl method calculateWidth.

protected int calculateWidth(boolean border, boolean padding) {
    final HTMLDocumentImpl doc = (HTMLDocumentImpl) this.document;
    final HtmlRendererContext htmlRendererContext = doc.getHtmlRendererContext();
    final HtmlPanel htmlPanel = htmlRendererContext.getHtmlPanel();
    final Dimension preferredSize = htmlPanel.getPreferredSize();
    final AbstractCSSProperties currentStyle = ((HTMLElementImpl) this).getCurrentStyle();
    String width = currentStyle.getWidth();
    String paddingRight = currentStyle.getPaddingRight();
    String paddingLeft = currentStyle.getPaddingLeft();
    String borderLeftWidth = currentStyle.getBorderLeftWidth();
    String borderRightWidth = currentStyle.getBorderRightWidth();
    String boxSizing = currentStyle.getBoxSizing();
    int sizeWidth = preferredSize.width;
    if (this instanceof HTMLBodyElementImpl) {
        width = String.valueOf(doc.getDefaultView().getInnerWidth());
    }
    final Node nodeObj = getParentNode();
    if (nodeObj instanceof HTMLElementImpl) {
        HTMLElementImpl elem = (HTMLElementImpl) nodeObj;
        if (elem.getClientHeight() != -1) {
            sizeWidth = elem.getClientWidth();
        }
    }
    if (Strings.isBlank(width) || "auto".equalsIgnoreCase(width)) {
        width = "100%";
    }
    int widthSize = HtmlValues.getPixelSize(width, null, doc.getDefaultView(), -1, sizeWidth);
    if ("border-box".equals(boxSizing)) {
        padding = false;
        border = false;
    }
    if (padding) {
        widthSize += HtmlValues.getPixelSize(paddingRight, null, doc.getDefaultView(), 0);
        widthSize += HtmlValues.getPixelSize(paddingLeft, null, doc.getDefaultView(), 0);
    }
    if (border) {
        widthSize += HtmlValues.getPixelSize(borderRightWidth, null, doc.getDefaultView(), 0);
        widthSize += HtmlValues.getPixelSize(borderLeftWidth, null, doc.getDefaultView(), 0);
    }
    return widthSize;
}
Also used : HtmlRendererContext(org.loboevolution.http.HtmlRendererContext) HtmlPanel(org.loboevolution.html.gui.HtmlPanel) AbstractCSSProperties(org.loboevolution.html.style.AbstractCSSProperties)

Example 2 with HtmlRendererContext

use of org.loboevolution.http.HtmlRendererContext in project LoboEvolution by LoboEvolution.

the class ElementImpl method setScrollTop.

/**
 * {@inheritDoc}
 */
@Override
public void setScrollTop(double scrollTop) {
    this.scrollTop = scrollTop;
    final HTMLDocumentImpl doc = (HTMLDocumentImpl) this.document;
    HtmlRendererContext htmlRendererContext = doc.getHtmlRendererContext();
    if (scrollTop < 0 || !isVScrollable()) {
        scrollTop = 0;
    }
    htmlRendererContext.setScrolly(scrollTop);
    RBlock bodyBlock = (RBlock) this.getUINode();
    if (bodyBlock != null && bodyBlock.getScroll() != null)
        bodyBlock.getScroll().scrollBy(JScrollBar.VERTICAL, scrollTop);
}
Also used : HtmlRendererContext(org.loboevolution.http.HtmlRendererContext) RBlock(org.loboevolution.html.renderer.RBlock)

Example 3 with HtmlRendererContext

use of org.loboevolution.http.HtmlRendererContext in project LoboEvolution by LoboEvolution.

the class LocationImpl method setHref.

/**
 * {@inheritDoc}
 *
 * <p>
 * setHref.
 * </p>
 */
public void setHref(String uri) {
    final HtmlRendererContext rcontext = this.window.getHtmlRendererContext();
    if (rcontext != null) {
        try {
            URL url;
            final Document document = this.window.getDocumentNode();
            if (document instanceof HTMLDocumentImpl) {
                final HTMLDocumentImpl docImpl = (HTMLDocumentImpl) document;
                url = docImpl.getFullURL(uri);
            } else {
                url = new URL(uri);
            }
            rcontext.navigate(url, this.target);
        } catch (final java.net.MalformedURLException mfu) {
            logger.log(Level.WARNING, "setHref(): Malformed location: [" + uri + "].", mfu);
        }
    }
}
Also used : HtmlRendererContext(org.loboevolution.http.HtmlRendererContext) HTMLDocumentImpl(org.loboevolution.html.dom.domimpl.HTMLDocumentImpl) Document(org.loboevolution.html.node.Document) URL(java.net.URL)

Example 4 with HtmlRendererContext

use of org.loboevolution.http.HtmlRendererContext in project LoboEvolution by LoboEvolution.

the class LocationImpl method reload.

/**
 * <p>
 * reload.
 * </p>
 */
public void reload() {
    // TODO: This is not really reload.
    final Document document = this.window.getDocumentNode();
    if (document instanceof HTMLDocumentImpl) {
        final HTMLDocumentImpl docImpl = (HTMLDocumentImpl) document;
        final HtmlRendererContext rcontext = docImpl.getHtmlRendererContext();
        if (rcontext != null) {
            rcontext.reload();
        } else {
            docImpl.warn("reload(): No renderer context in Location's document.");
        }
    }
}
Also used : HtmlRendererContext(org.loboevolution.http.HtmlRendererContext) HTMLDocumentImpl(org.loboevolution.html.dom.domimpl.HTMLDocumentImpl) Document(org.loboevolution.html.node.Document)

Example 5 with HtmlRendererContext

use of org.loboevolution.http.HtmlRendererContext in project LoboEvolution by LoboEvolution.

the class WindowImpl method setOpener.

/**
 * {@inheritDoc}
 */
@Override
public void setOpener(final Window opener) {
    final HtmlRendererContext rcontext = this.rcontext;
    if (rcontext != null) {
        if (opener == null) {
            rcontext.setOpener(null);
        } else {
            final WindowImpl win = (WindowImpl) opener;
            rcontext.setOpener(win.rcontext);
        }
    }
}
Also used : HtmlRendererContext(org.loboevolution.http.HtmlRendererContext)

Aggregations

HtmlRendererContext (org.loboevolution.http.HtmlRendererContext)30 HtmlPanel (org.loboevolution.html.gui.HtmlPanel)12 Function (org.mozilla.javascript.Function)7 URL (java.net.URL)6 HTMLDocumentImpl (org.loboevolution.html.dom.domimpl.HTMLDocumentImpl)6 ModelNode (org.loboevolution.html.dom.nodeimpl.ModelNode)6 MouseEventImpl (org.loboevolution.html.js.events.MouseEventImpl)6 TimingInfo (org.loboevolution.info.TimingInfo)6 UserAgentContext (org.loboevolution.http.UserAgentContext)5 Document (org.loboevolution.html.node.Document)4 MalformedURLException (java.net.MalformedURLException)3 HTMLImageElementImpl (org.loboevolution.html.dom.domimpl.HTMLImageElementImpl)3 Image (java.awt.Image)2 AffineTransform (java.awt.geom.AffineTransform)2 InputStreamReader (java.io.InputStreamReader)2 SocketTimeoutException (java.net.SocketTimeoutException)2 Instant (java.time.Instant)2 ArrayList (java.util.ArrayList)2 HTMLElementImpl (org.loboevolution.html.dom.domimpl.HTMLElementImpl)2 NodeImpl (org.loboevolution.html.dom.nodeimpl.NodeImpl)2