Search in sources :

Example 1 with NodeListImpl

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

the class ElementImpl method isVScrollable.

private boolean isVScrollable() {
    String overflow;
    AbstractCSSProperties currentStyle = ((HTMLElementImpl) this).getCurrentStyle();
    overflow = currentStyle.getOverflow();
    int heightChild = 0;
    for (final Node child : (NodeListImpl) this.getChildNodes()) {
        if (child instanceof HTMLElementImpl)
            heightChild += ((HTMLElementImpl) child).getClientHeight();
    }
    return ("scroll".equals(overflow) || "auto".equals(overflow)) && (heightChild > this.getClientHeight());
}
Also used : NodeListImpl(org.loboevolution.html.dom.nodeimpl.NodeListImpl) AbstractCSSProperties(org.loboevolution.html.style.AbstractCSSProperties)

Example 2 with NodeListImpl

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

the class ElementImpl method querySelector.

/**
 * {@inheritDoc}
 */
@Override
public Element querySelector(String selectors) {
    SelectorList selectorList = CSSUtilities.getSelectorList(selectors);
    List<Element> elem = new ArrayList<>();
    if (selectorList != null) {
        NodeListImpl childNodes = (NodeListImpl) getDescendents(new ElementFilter(null), true);
        childNodes.forEach(child -> {
            for (Selector selector : selectorList) {
                if (child instanceof Element && StyleSheetAggregator.selects(selector, child, null)) {
                    elem.add((Element) child);
                }
            }
        });
    }
    return elem.size() > 0 ? elem.get(0) : null;
}
Also used : NodeListImpl(org.loboevolution.html.dom.nodeimpl.NodeListImpl) SelectorList(com.gargoylesoftware.css.parser.selector.SelectorList) HTMLBodyElement(org.loboevolution.html.dom.HTMLBodyElement) ElementFilter(org.loboevolution.html.dom.filter.ElementFilter) Selector(com.gargoylesoftware.css.parser.selector.Selector)

Example 3 with NodeListImpl

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

the class ElementImpl method querySelectorAll.

/**
 * {@inheritDoc}
 */
@Override
public NodeList querySelectorAll(String selector) {
    final ArrayList<Node> al = new ArrayList<>();
    if (selector == null) {
        return new NodeListImpl(al);
    }
    if (selector.isEmpty()) {
        throw new DOMException(DOMException.NOT_FOUND_ERR, "The provided selector is empty.");
    }
    if (selector.trim().isEmpty()) {
        throw new DOMException(DOMException.NOT_FOUND_ERR, "is not a valid selector.");
    }
    SelectorList selectorList = CSSUtilities.getSelectorList(selector);
    if (selectorList != null) {
        NodeListImpl childNodes = (NodeListImpl) getDescendents(new ElementFilter(null), true);
        childNodes.forEach(child -> {
            for (Selector select : selectorList) {
                if (child instanceof Element && StyleSheetAggregator.selects(select, child, null)) {
                    al.add(child);
                }
            }
        });
    }
    return new NodeListImpl(al);
}
Also used : DOMException(com.gargoylesoftware.css.dom.DOMException) NodeListImpl(org.loboevolution.html.dom.nodeimpl.NodeListImpl) SelectorList(com.gargoylesoftware.css.parser.selector.SelectorList) ElementFilter(org.loboevolution.html.dom.filter.ElementFilter) HTMLBodyElement(org.loboevolution.html.dom.HTMLBodyElement) Selector(com.gargoylesoftware.css.parser.selector.Selector)

Example 4 with NodeListImpl

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

the class HTMLTableRowElementImpl method getRowIndex.

/**
 * {@inheritDoc}
 */
@Override
public int getRowIndex() {
    if (index >= 0) {
        return index;
    } else {
        AtomicInteger index = new AtomicInteger(-1);
        if (getParentNode() != null) {
            NodeListImpl childNodes = (NodeListImpl) getParentNode().getChildNodes();
            childNodes.forEach(node -> {
                if (node instanceof HTMLTableRowElement) {
                    index.incrementAndGet();
                }
            });
        }
        return index.get();
    }
}
Also used : HTMLTableRowElement(org.loboevolution.html.dom.HTMLTableRowElement) NodeListImpl(org.loboevolution.html.dom.nodeimpl.NodeListImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 5 with NodeListImpl

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

the class HTMLTextAreaElementImpl method getText.

private String getText() {
    StringBuilder text = new StringBuilder();
    if (hasChildNodes()) {
        NodeListImpl children = (NodeListImpl) getChildNodes();
        children.forEach(child -> {
            if (child.getNodeType() == NodeType.TEXT_NODE) {
                String nodeValue = child.getNodeValue();
                String childText;
                nodeValue = nodeValue.replace('\n', ' ');
                nodeValue = nodeValue.replace('\r', ' ');
                nodeValue = nodeValue.replace('\t', ' ');
                childText = nodeValue;
                text.append(childText).append(" ");
            }
        });
    }
    if (text.length() > 0) {
        return text.substring(0, text.length() - 1);
    } else {
        return text.toString();
    }
}
Also used : NodeListImpl(org.loboevolution.html.dom.nodeimpl.NodeListImpl)

Aggregations

NodeListImpl (org.loboevolution.html.dom.nodeimpl.NodeListImpl)38 ArrayList (java.util.ArrayList)6 Node (org.loboevolution.html.node.Node)5 DOMException (com.gargoylesoftware.css.dom.DOMException)4 Selector (com.gargoylesoftware.css.parser.selector.Selector)4 SelectorList (com.gargoylesoftware.css.parser.selector.SelectorList)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Shape (java.awt.Shape)3 AffineTransform (java.awt.geom.AffineTransform)3 GeneralPath (java.awt.geom.GeneralPath)3 NoninvertibleTransformException (java.awt.geom.NoninvertibleTransformException)3 Rectangle2D (java.awt.geom.Rectangle2D)3 LinearGradientPaint (java.awt.LinearGradientPaint)2 MultipleGradientPaint (java.awt.MultipleGradientPaint)2 Paint (java.awt.Paint)2 RadialGradientPaint (java.awt.RadialGradientPaint)2 Test (org.junit.Test)2 LoboUnitTest (org.loboevolution.driver.LoboUnitTest)2 HTMLBodyElement (org.loboevolution.html.dom.HTMLBodyElement)2 ElementFilter (org.loboevolution.html.dom.filter.ElementFilter)2