org.w3c.dom.ranges.Range Java Examples

The following examples show how to use org.w3c.dom.ranges.Range. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TextRange.java    From HtmlUnit-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the endpoint of the range based on the endpoint of another range..
 * @param type end point transfer type. One of "StartToEnd", "StartToStart", "EndToStart" and "EndToEnd"
 * @param other the other range
 * @see <a href="http://msdn.microsoft.com/en-us/library/ms536745.aspx">MSDN doc</a>
 */
@JsxFunction
public void setEndPoint(final String type, final TextRange other) {
    final Range otherRange = other.range_;

    final org.w3c.dom.Node target;
    final int offset;
    if (type.endsWith("ToStart")) {
        target = otherRange.getStartContainer();
        offset = otherRange.getStartOffset();
    }
    else {
        target = otherRange.getEndContainer();
        offset = otherRange.getEndOffset();
    }

    if (type.startsWith("Start")) {
        range_.setStart(target, offset);
    }
    else {
        range_.setEnd(target, offset);
    }
}
 
Example #2
Source File: DocumentImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @serialData Serialized fields. Convert Maps to Hashtables and Lists
 * to Vectors for backward compatibility.
 */
private void writeObject(ObjectOutputStream out) throws IOException {
    // Convert Maps to Hashtables, Lists to Vectors
    Vector<NodeIterator> it = (iterators == null)? null : new Vector<>(iterators);
    Vector<Range> r = (ranges == null)? null : new Vector<>(ranges);

    Hashtable<NodeImpl, Vector<LEntry>> el = null;
    if (eventListeners != null) {
        el = new Hashtable<>();
        for (Map.Entry<NodeImpl, List<LEntry>> e : eventListeners.entrySet()) {
             el.put(e.getKey(), new Vector<>(e.getValue()));
        }
    }

    // Write serialized fields
    ObjectOutputStream.PutField pf = out.putFields();
    pf.put("iterators", it);
    pf.put("ranges", r);
    pf.put("eventListeners", el);
    pf.put("mutationEvents", mutationEvents);
    out.writeFields();
}
 
Example #3
Source File: DocumentImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in)
                    throws IOException, ClassNotFoundException {
    // We have to read serialized fields first.
    ObjectInputStream.GetField gf = in.readFields();
    Vector<NodeIterator> it = (Vector<NodeIterator>)gf.get("iterators", null);
    Vector<Range> r = (Vector<Range>)gf.get("ranges", null);
    Hashtable<NodeImpl, Vector<LEntry>> el =
            (Hashtable<NodeImpl, Vector<LEntry>>)gf.get("eventListeners", null);

    mutationEvents = gf.get("mutationEvents", false);

    //convert Hashtables back to HashMaps and Vectors to Lists
    if (it != null) iterators = new ArrayList<>(it);
    if (r != null) ranges = new ArrayList<>(r);
    if (el != null) {
        eventListeners = new HashMap<>();
        for (Map.Entry<NodeImpl, Vector<LEntry>> e : el.entrySet()) {
             eventListeners.put(e.getKey(), new ArrayList<>(e.getValue()));
        }
    }
}
 
Example #4
Source File: DocumentImpl.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in)
                    throws IOException, ClassNotFoundException {
    // We have to read serialized fields first.
    ObjectInputStream.GetField gf = in.readFields();
    Vector<NodeIterator> it = (Vector<NodeIterator>)gf.get("iterators", null);
    Vector<Range> r = (Vector<Range>)gf.get("ranges", null);
    Hashtable<NodeImpl, Vector<LEntry>> el =
            (Hashtable<NodeImpl, Vector<LEntry>>)gf.get("eventListeners", null);

    mutationEvents = gf.get("mutationEvents", false);

    //convert Hashtables back to HashMaps and Vectors to Lists
    if (it != null) iterators = new ArrayList<>(it);
    if (r != null) ranges = new ArrayList<>(r);
    if (el != null) {
        eventListeners = new HashMap<>();
        for (Map.Entry<NodeImpl, Vector<LEntry>> e : el.entrySet()) {
             eventListeners.put(e.getKey(), new ArrayList<>(e.getValue()));
        }
    }
}
 
Example #5
Source File: DocumentImpl.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in)
                    throws IOException, ClassNotFoundException {
    // We have to read serialized fields first.
    ObjectInputStream.GetField gf = in.readFields();
    Vector<NodeIterator> it = (Vector<NodeIterator>)gf.get("iterators", null);
    Vector<Range> r = (Vector<Range>)gf.get("ranges", null);
    Hashtable<NodeImpl, Vector<LEntry>> el =
            (Hashtable<NodeImpl, Vector<LEntry>>)gf.get("eventListeners", null);

    mutationEvents = gf.get("mutationEvents", false);

    //convert Hashtables back to HashMaps and Vectors to Lists
    if (it != null) iterators = new ArrayList<>(it);
    if (r != null) ranges = new ArrayList<>(r);
    if (el != null) {
        eventListeners = new HashMap<>();
        for (Map.Entry<NodeImpl, Vector<LEntry>> e : el.entrySet()) {
             eventListeners.put(e.getKey(), new ArrayList<>(e.getValue()));
        }
    }
}
 
Example #6
Source File: DocumentImpl.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * @serialData Serialized fields. Convert Maps to Hashtables and Lists
 * to Vectors for backward compatibility.
 */
private void writeObject(ObjectOutputStream out) throws IOException {
    // Convert Maps to Hashtables, Lists to Vectors
    Vector<NodeIterator> it = (iterators == null)? null : new Vector<>(iterators);
    Vector<Range> r = (ranges == null)? null : new Vector<>(ranges);

    Hashtable<NodeImpl, Vector<LEntry>> el = null;
    if (eventListeners != null) {
        el = new Hashtable<>();
        for (Map.Entry<NodeImpl, List<LEntry>> e : eventListeners.entrySet()) {
             el.put(e.getKey(), new Vector<>(e.getValue()));
        }
    }

    // Write serialized fields
    ObjectOutputStream.PutField pf = out.putFields();
    pf.put("iterators", it);
    pf.put("ranges", r);
    pf.put("eventListeners", el);
    pf.put("mutationEvents", mutationEvents);
    out.writeFields();
}
 
Example #7
Source File: DocumentImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in)
                    throws IOException, ClassNotFoundException {
    // We have to read serialized fields first.
    ObjectInputStream.GetField gf = in.readFields();
    Vector<NodeIterator> it = (Vector<NodeIterator>)gf.get("iterators", null);
    Vector<Range> r = (Vector<Range>)gf.get("ranges", null);
    Hashtable<NodeImpl, Vector<LEntry>> el =
            (Hashtable<NodeImpl, Vector<LEntry>>)gf.get("eventListeners", null);

    mutationEvents = gf.get("mutationEvents", false);

    //convert Hashtables back to HashMaps and Vectors to Lists
    if (it != null) iterators = new ArrayList<>(it);
    if (r != null) ranges = new ArrayList<>(r);
    if (el != null) {
        eventListeners = new HashMap<>();
        for (Map.Entry<NodeImpl, Vector<LEntry>> e : el.entrySet()) {
             eventListeners.put(e.getKey(), new ArrayList<>(e.getValue()));
        }
    }
}
 
Example #8
Source File: DocumentImpl.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * @serialData Serialized fields. Convert Maps to Hashtables and Lists
 * to Vectors for backward compatibility.
 */
private void writeObject(ObjectOutputStream out) throws IOException {
    // Convert Maps to Hashtables, Lists to Vectors
    Vector<NodeIterator> it = (iterators == null)? null : new Vector<>(iterators);
    Vector<Range> r = (ranges == null)? null : new Vector<>(ranges);

    Hashtable<NodeImpl, Vector<LEntry>> el = null;
    if (eventListeners != null) {
        el = new Hashtable<>();
        for (Map.Entry<NodeImpl, List<LEntry>> e : eventListeners.entrySet()) {
             el.put(e.getKey(), new Vector<>(e.getValue()));
        }
    }

    // Write serialized fields
    ObjectOutputStream.PutField pf = out.putFields();
    pf.put("iterators", it);
    pf.put("ranges", r);
    pf.put("eventListeners", el);
    pf.put("mutationEvents", mutationEvents);
    out.writeFields();
}
 
Example #9
Source File: DocumentImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in)
                    throws IOException, ClassNotFoundException {
    // We have to read serialized fields first.
    ObjectInputStream.GetField gf = in.readFields();
    Vector<NodeIterator> it = (Vector<NodeIterator>)gf.get("iterators", null);
    Vector<Range> r = (Vector<Range>)gf.get("ranges", null);
    Hashtable<NodeImpl, Vector<LEntry>> el =
            (Hashtable<NodeImpl, Vector<LEntry>>)gf.get("eventListeners", null);

    mutationEvents = gf.get("mutationEvents", false);

    //convert Hashtables back to HashMaps and Vectors to Lists
    if (it != null) iterators = new ArrayList<>(it);
    if (r != null) ranges = new ArrayList<>(r);
    if (el != null) {
        eventListeners = new HashMap<>();
        for (Map.Entry<NodeImpl, Vector<LEntry>> e : el.entrySet()) {
             eventListeners.put(e.getKey(), new ArrayList<>(e.getValue()));
        }
    }
}
 
Example #10
Source File: DocumentImpl.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * @serialData Serialized fields. Convert Maps to Hashtables and Lists
 * to Vectors for backward compatibility.
 */
private void writeObject(ObjectOutputStream out) throws IOException {
    // Convert Maps to Hashtables, Lists to Vectors
    Vector<NodeIterator> it = (iterators == null)? null : new Vector<>(iterators);
    Vector<Range> r = (ranges == null)? null : new Vector<>(ranges);

    Hashtable<NodeImpl, Vector<LEntry>> el = null;
    if (eventListeners != null) {
        el = new Hashtable<>();
        for (Map.Entry<NodeImpl, List<LEntry>> e : eventListeners.entrySet()) {
             el.put(e.getKey(), new Vector<>(e.getValue()));
        }
    }

    // Write serialized fields
    ObjectOutputStream.PutField pf = out.putFields();
    pf.put("iterators", it);
    pf.put("ranges", r);
    pf.put("eventListeners", el);
    pf.put("mutationEvents", mutationEvents);
    out.writeFields();
}
 
Example #11
Source File: DocumentImpl.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in)
                    throws IOException, ClassNotFoundException {
    // We have to read serialized fields first.
    ObjectInputStream.GetField gf = in.readFields();
    Vector<NodeIterator> it = (Vector<NodeIterator>)gf.get("iterators", null);
    Vector<Range> r = (Vector<Range>)gf.get("ranges", null);
    Hashtable<NodeImpl, Vector<LEntry>> el =
            (Hashtable<NodeImpl, Vector<LEntry>>)gf.get("eventListeners", null);

    mutationEvents = gf.get("mutationEvents", false);

    //convert Hashtables back to HashMaps and Vectors to Lists
    if (it != null) iterators = new ArrayList<>(it);
    if (r != null) ranges = new ArrayList<>(r);
    if (el != null) {
        eventListeners = new HashMap<>();
        for (Map.Entry<NodeImpl, Vector<LEntry>> e : el.entrySet()) {
             eventListeners.put(e.getKey(), new ArrayList<>(e.getValue()));
        }
    }
}
 
Example #12
Source File: DocumentImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @serialData Serialized fields. Convert Maps to Hashtables and Lists
 * to Vectors for backward compatibility.
 */
private void writeObject(ObjectOutputStream out) throws IOException {
    // Convert Maps to Hashtables, Lists to Vectors
    Vector<NodeIterator> it = (iterators == null)? null : new Vector<>(iterators);
    Vector<Range> r = (ranges == null)? null : new Vector<>(ranges);

    Hashtable<NodeImpl, Vector<LEntry>> el = null;
    if (eventListeners != null) {
        el = new Hashtable<>();
        for (Map.Entry<NodeImpl, List<LEntry>> e : eventListeners.entrySet()) {
             el.put(e.getKey(), new Vector<>(e.getValue()));
        }
    }

    // Write serialized fields
    ObjectOutputStream.PutField pf = out.putFields();
    pf.put("iterators", it);
    pf.put("ranges", r);
    pf.put("eventListeners", el);
    pf.put("mutationEvents", mutationEvents);
    out.writeFields();
}
 
Example #13
Source File: TextRange.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the endpoint of the range based on the endpoint of another range..
 * @param type end point transfer type. One of "StartToEnd", "StartToStart", "EndToStart" and "EndToEnd"
 * @param other the other range
 * @see <a href="http://msdn.microsoft.com/en-us/library/ms536745.aspx">MSDN doc</a>
 */
@JsxFunction
public void setEndPoint(final String type, final TextRange other) {
    final Range otherRange = other.range_;

    final org.w3c.dom.Node target;
    final int offset;
    if (type.endsWith("ToStart")) {
        target = otherRange.getStartContainer();
        offset = otherRange.getStartOffset();
    }
    else {
        target = otherRange.getEndContainer();
        offset = otherRange.getEndOffset();
    }

    if (type.startsWith("Start")) {
        range_.setStart(target, offset);
    }
    else {
        range_.setEnd(target, offset);
    }
}
 
Example #14
Source File: AbstractViewDropAction.java    From XPagesExtensionLibrary with Apache License 2.0 6 votes vote down vote up
protected Node getTarget(){
    Node target = null;
    Range range = getRange();

    if (range != null) {
        target = range.getEndContainer();
    }
    if (target == null) {
        target = getFocusedNode();
    }
    //if target is still null at this point, check to see if this is a drop to source action.
    if(target == null){
        //if it is, run the drop to source setup and get a valid drop target node back. 
        target = getSelectedNodeFromSource();
    }
    return target;
}
 
Example #15
Source File: DocumentImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @serialData Serialized fields. Convert Maps to Hashtables and Lists
 * to Vectors for backward compatibility.
 */
private void writeObject(ObjectOutputStream out) throws IOException {
    // Convert Maps to Hashtables, Lists to Vectors
    Vector<NodeIterator> it = (iterators == null)? null : new Vector<>(iterators);
    Vector<Range> r = (ranges == null)? null : new Vector<>(ranges);

    Hashtable<NodeImpl, Vector<LEntry>> el = null;
    if (eventListeners != null) {
        el = new Hashtable<>();
        for (Map.Entry<NodeImpl, List<LEntry>> e : eventListeners.entrySet()) {
             el.put(e.getKey(), new Vector<>(e.getValue()));
        }
    }

    // Write serialized fields
    ObjectOutputStream.PutField pf = out.putFields();
    pf.put("iterators", it);
    pf.put("ranges", r);
    pf.put("eventListeners", el);
    pf.put("mutationEvents", mutationEvents);
    out.writeFields();
}
 
Example #16
Source File: Selection.java    From HtmlUnit-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the first selection range in the current document, by document position.
 * @return the first selection range in the current document, by document position
 */
private Range getFirstRange() {
    // avoid concurrent modification exception
    final List<Range> ranges = new ArrayList<>(getRanges());

    Range first = null;
    for (final Range range : ranges) {
        if (first == null) {
            first = range;
        }
        else {
            final Node firstStart = (Node) first.getStartContainer();
            final Node rangeStart = (Node) range.getStartContainer();
            if ((firstStart.compareDocumentPosition(rangeStart) & Node.DOCUMENT_POSITION_PRECEDING) != 0) {
                first = range;
            }
        }
    }
    return first;
}
 
Example #17
Source File: DocumentImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in)
                    throws IOException, ClassNotFoundException {
    // We have to read serialized fields first.
    ObjectInputStream.GetField gf = in.readFields();
    Vector<NodeIterator> it = (Vector<NodeIterator>)gf.get("iterators", null);
    Vector<Range> r = (Vector<Range>)gf.get("ranges", null);
    Hashtable<NodeImpl, Vector<LEntry>> el =
            (Hashtable<NodeImpl, Vector<LEntry>>)gf.get("eventListeners", null);

    mutationEvents = gf.get("mutationEvents", false);

    //convert Hashtables back to HashMaps and Vectors to Lists
    if (it != null) iterators = new ArrayList<>(it);
    if (r != null) ranges = new ArrayList<>(r);
    if (el != null) {
        eventListeners = new HashMap<>();
        for (Map.Entry<NodeImpl, Vector<LEntry>> e : el.entrySet()) {
             eventListeners.put(e.getKey(), new ArrayList<>(e.getValue()));
        }
    }
}
 
Example #18
Source File: DocumentImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @serialData Serialized fields. Convert Maps to Hashtables and Lists
 * to Vectors for backward compatibility.
 */
private void writeObject(ObjectOutputStream out) throws IOException {
    // Convert Maps to Hashtables, Lists to Vectors
    Vector<NodeIterator> it = (iterators == null)? null : new Vector<>(iterators);
    Vector<Range> r = (ranges == null)? null : new Vector<>(ranges);

    Hashtable<NodeImpl, Vector<LEntry>> el = null;
    if (eventListeners != null) {
        el = new Hashtable<>();
        for (Map.Entry<NodeImpl, List<LEntry>> e : eventListeners.entrySet()) {
             el.put(e.getKey(), new Vector<>(e.getValue()));
        }
    }

    // Write serialized fields
    ObjectOutputStream.PutField pf = out.putFields();
    pf.put("iterators", it);
    pf.put("ranges", r);
    pf.put("eventListeners", el);
    pf.put("mutationEvents", mutationEvents);
    out.writeFields();
}
 
Example #19
Source File: Selection.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the first selection range in the current document, by document position.
 * @return the first selection range in the current document, by document position
 */
private Range getFirstRange() {
    // avoid concurrent modification exception
    final List<Range> ranges = new ArrayList<>(getRanges());

    Range first = null;
    for (final Range range : ranges) {
        if (first == null) {
            first = range;
        }
        else {
            final org.w3c.dom.Node firstStart = first.getStartContainer();
            final org.w3c.dom.Node rangeStart = range.getStartContainer();
            if ((firstStart.compareDocumentPosition(rangeStart) & Node.DOCUMENT_POSITION_PRECEDING) != 0) {
                first = range;
            }
        }
    }
    return first;
}
 
Example #20
Source File: Selection.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the last selection range in the current document, by document position.
 * @return the last selection range in the current document, by document position
 */
private Range getLastRange() {
    // avoid concurrent modification exception
    final List<Range> ranges = new ArrayList<>(getRanges());

    Range last = null;
    for (final Range range : ranges) {
        if (last == null) {
            last = range;
        }
        else {
            final org.w3c.dom.Node lastStart = last.getStartContainer();
            final org.w3c.dom.Node rangeStart = range.getStartContainer();
            if ((lastStart.compareDocumentPosition(rangeStart) & Node.DOCUMENT_POSITION_FOLLOWING) != 0) {
                last = range;
            }
        }
    }
    return last;
}
 
Example #21
Source File: Selection.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Removes a range from the selection.
 * @param range the range to remove
 */
@JsxFunction
public void removeRange(final com.gargoylesoftware.htmlunit.javascript.host.dom.Range range) {
    getRanges().remove(range.toW3C());

    if (getRangeCount() < 1) {
        type_ = TYPE_NONE;
    }
}
 
Example #22
Source File: RangeImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public Range cloneRange(){
    if( fDetach) {
            throw new DOMException(
            DOMException.INVALID_STATE_ERR,
            DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_STATE_ERR", null));
    }

    Range range = fDocument.createRange();
    range.setStart(fStartContainer, fStartOffset);
    range.setEnd(fEndContainer, fEndOffset);
    return range;
}
 
Example #23
Source File: Selection.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the number of characters that the selection's focus is offset within the focus node.
 * @return the number of characters that the selection's focus is offset within the focus node
 */
@JsxGetter
public int getFocusOffset() {
    final Range last = getLastRange();
    if (last == null) {
        return 0;
    }
    return last.getEndOffset();
}
 
Example #24
Source File: DocumentImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/** Not a client function. Called by Range.detach(),
 *  so a Range can remove itself from the list of
 *  Ranges.
 */
void removeRange(Range range) {

    if (range == null) return;
    if (ranges == null) return;

    ranges.remove(range);
}
 
Example #25
Source File: Selection.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the number of characters that the selection's anchor is offset within the anchor node.
 * @return the number of characters that the selection's anchor is offset within the anchor node
 */
@JsxGetter
public int getAnchorOffset() {
    final Range last = getLastRange();
    if (last == null) {
        return 0;
    }
    return last.getStartOffset();
}
 
Example #26
Source File: Selection.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the node in which the selection begins.
 * @return the node in which the selection begins
 */
@JsxGetter
public Node getAnchorNode() {
    final Range last = getLastRange();
    if (last == null) {
        return null;
    }
    return (Node) getScriptableNullSafe(last.getStartContainer());
}
 
Example #27
Source File: DocumentImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/** Not a client function. Called by Range.detach(),
 *  so a Range can remove itself from the list of
 *  Ranges.
 */
void removeRange(Range range) {

    if (range == null) return;
    if (ranges == null) return;

    ranges.removeElement(range);
}
 
Example #28
Source File: DocumentImpl.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/** Not a client function. Called by Range.detach(),
 *  so a Range can remove itself from the list of
 *  Ranges.
 */
void removeRange(Range range) {

    if (range == null) return;
    if (ranges == null) return;

    ranges.remove(range);
}
 
Example #29
Source File: TextRange.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Indicates if a range is contained in current one.
 * @param other the other range
 * @return {@code true} if <code>other</code> is contained within current range
 * @see <a href="http://msdn.microsoft.com/en-us/library/ms536371.aspx">MSDN doc</a>
 */
@JsxFunction
public boolean inRange(final TextRange other) {
    final Range otherRange = other.range_;

    final org.w3c.dom.Node start = range_.getStartContainer();
    final org.w3c.dom.Node otherStart = otherRange.getStartContainer();
    if (otherStart == null) {
        return false;
    }
    final short startComparison = start.compareDocumentPosition(otherStart);
    final boolean startNodeBefore = startComparison == 0
            || (startComparison & Node.DOCUMENT_POSITION_CONTAINS) != 0
            || (startComparison & Node.DOCUMENT_POSITION_PRECEDING) != 0;
    if (startNodeBefore && (start != otherStart || range_.getStartOffset() <= otherRange.getStartOffset())) {
        final org.w3c.dom.Node end = range_.getEndContainer();
        final org.w3c.dom.Node otherEnd = otherRange.getEndContainer();
        final short endComparison = end.compareDocumentPosition(otherEnd);
        final boolean endNodeAfter = endComparison == 0
                || (endComparison & Node.DOCUMENT_POSITION_CONTAINS) != 0
                || (endComparison & Node.DOCUMENT_POSITION_FOLLOWING) != 0;
        if (endNodeAfter && (end != otherEnd || range_.getEndOffset() >= otherRange.getEndOffset())) {
            return true;
        }
    }

    return false;
}
 
Example #30
Source File: Selection.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Moves the anchor of the selection to the same point as the focus. The focus does not move.
 */
@JsxFunction
public void collapseToEnd() {
    final Range last = getLastRange();
    if (last != null) {
        final List<Range> ranges = getRanges();
        ranges.clear();
        ranges.add(last);
        last.collapse(false);
    }

    type_ = TYPE_CARET;
}