Search in sources :

Example 1 with TextImpl

use of org.loboevolution.html.dom.nodeimpl.TextImpl 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 TextImpl

use of org.loboevolution.html.dom.nodeimpl.TextImpl in project LoboEvolution by LoboEvolution.

the class ElementImpl method getClientRects.

/**
 * {@inheritDoc}
 */
@Override
public DOMRectList getClientRects() {
    DOMRectListImpl list = new DOMRectListImpl();
    AbstractCSSProperties style = ((HTMLElementImpl) this).getCurrentStyle();
    String display = Strings.isNotBlank(style.getDisplay()) ? style.getDisplay() : getAttribute("display");
    if (!"none".equals(display)) {
        for (Node n = getParentNode(); n != null; n = n.getPreviousSibling()) {
            if (!(n instanceof HTMLBodyElement) && !(n instanceof TextImpl) && !(n instanceof HTMLDocumentImpl)) {
                HTMLElementImpl p = (HTMLElementImpl) n;
                AbstractCSSProperties st = p.getStyle();
                display = st.getDisplay();
            }
        }
    }
    if (!"none".equals(display)) {
        list.add(getBoundingClientRect());
    }
    return list;
}
Also used : DOMRectListImpl(org.loboevolution.html.js.geom.DOMRectListImpl) HTMLBodyElement(org.loboevolution.html.dom.HTMLBodyElement) AbstractCSSProperties(org.loboevolution.html.style.AbstractCSSProperties) TextImpl(org.loboevolution.html.dom.nodeimpl.TextImpl)

Example 3 with TextImpl

use of org.loboevolution.html.dom.nodeimpl.TextImpl in project LoboEvolution by LoboEvolution.

the class WindowImpl method initWindowScope.

private void initWindowScope(final Document doc) {
    final Scriptable ws = this.getWindowScope();
    final JavaScript js = JavaScript.getInstance();
    JavaInstantiator jiXhttp = () -> {
        HTMLDocumentImpl hd = (HTMLDocumentImpl) doc;
        return new XMLHttpRequest(getUaContext(), hd.getDocumentURL(), ws);
    };
    JavaInstantiator jidomp = () -> new DOMParserImpl(document);
    js.defineJsObject(ws, "XMLHttpRequest", XMLHttpRequest.class, jiXhttp);
    js.defineJsObject(ws, "DOMParser", DOMParserImpl.class, jidomp);
    js.defineJsObject(ws, "XMLSerializer", XMLSerializerImpl.class, XMLSerializerImpl::new);
    js.defineJsObject(ws, "XPathResult", XPathResultImpl.class, XPathResultImpl::new);
    js.defineJsObject(ws, "MouseEvent", MouseEventImpl.class, MouseEventImpl::new);
    js.defineJsObject(ws, "UIEvent", UIEventImpl.class, MouseEventImpl::new);
    js.defineJsObject(ws, "Element", Element.class, MouseEventImpl::new);
    js.defineJsObject(ws, "Event", EventImpl.class, EventImpl::new);
    js.defineJsObject(ws, "Text", TextImpl.class, TextImpl::new);
    js.defineJsObject(ws, "Storage", LocalStorage.class, LocalStorage::new);
    js.defineElementClass(ws, doc, "Comment", "comment", CommentImpl.class);
    js.defineElementClass(ws, doc, "Image", "img", HTMLImageElementImpl.class);
    js.defineElementClass(ws, doc, "Script", "script", HTMLScriptElementImpl.class);
    js.defineElementClass(ws, doc, "IFrame", "iframe", HTMLIFrameElementImpl.class);
    js.defineElementClass(ws, doc, "Option", "option", HTMLOptionElementImpl.class);
    js.defineElementClass(ws, doc, "Select", "select", HTMLSelectElementImpl.class);
    js.defineElementClass(ws, doc, "Console", "console", ConsoleImpl.class);
    js.defineElementClass(ws, doc, "HTMLDivElement", "div", HTMLDivElementImpl.class);
    js.defineElementClass(ws, doc, "HTMLElement", "html", HTMLElementImpl.class);
    js.defineElementClass(ws, doc, "HTMLDocument", "document", HTMLDocumentImpl.class);
}
Also used : JavaInstantiator(org.loboevolution.js.JavaInstantiator) LocalStorage(org.loboevolution.html.js.storage.LocalStorage) XPathResultImpl(org.loboevolution.html.dom.xpath.XPathResultImpl) EventImpl(org.loboevolution.html.js.events.EventImpl) MouseEventImpl(org.loboevolution.html.js.events.MouseEventImpl) UIEventImpl(org.loboevolution.html.js.events.UIEventImpl) JavaScript(org.loboevolution.js.JavaScript) XMLHttpRequest(org.loboevolution.html.js.xml.XMLHttpRequest) XMLSerializerImpl(org.loboevolution.html.js.xml.XMLSerializerImpl) Scriptable(org.mozilla.javascript.Scriptable) MouseEventImpl(org.loboevolution.html.js.events.MouseEventImpl) TextImpl(org.loboevolution.html.dom.nodeimpl.TextImpl)

Example 4 with TextImpl

use of org.loboevolution.html.dom.nodeimpl.TextImpl in project LoboEvolution by LoboEvolution.

the class DocumentImpl method createTextNode.

/**
 * {@inheritDoc}
 */
@Override
public Text createTextNode(String data) {
    if (data == null) {
        throw new DOMException(DOMException.INVALID_CHARACTER_ERR, "null data");
    }
    final TextImpl node = new TextImpl(data);
    node.setOwnerDocument(this);
    return node;
}
Also used : DOMException(com.gargoylesoftware.css.dom.DOMException) TextImpl(org.loboevolution.html.dom.nodeimpl.TextImpl)

Aggregations

TextImpl (org.loboevolution.html.dom.nodeimpl.TextImpl)4 HTMLBodyElement (org.loboevolution.html.dom.HTMLBodyElement)2 AbstractCSSProperties (org.loboevolution.html.style.AbstractCSSProperties)2 DOMException (com.gargoylesoftware.css.dom.DOMException)1 XPathResultImpl (org.loboevolution.html.dom.xpath.XPathResultImpl)1 EventImpl (org.loboevolution.html.js.events.EventImpl)1 MouseEventImpl (org.loboevolution.html.js.events.MouseEventImpl)1 UIEventImpl (org.loboevolution.html.js.events.UIEventImpl)1 DOMRectImpl (org.loboevolution.html.js.geom.DOMRectImpl)1 DOMRectListImpl (org.loboevolution.html.js.geom.DOMRectListImpl)1 LocalStorage (org.loboevolution.html.js.storage.LocalStorage)1 XMLHttpRequest (org.loboevolution.html.js.xml.XMLHttpRequest)1 XMLSerializerImpl (org.loboevolution.html.js.xml.XMLSerializerImpl)1 Window (org.loboevolution.html.node.js.Window)1 RenderState (org.loboevolution.html.renderstate.RenderState)1 JavaInstantiator (org.loboevolution.js.JavaInstantiator)1 JavaScript (org.loboevolution.js.JavaScript)1 Scriptable (org.mozilla.javascript.Scriptable)1