Package org.w3c.dom.ranges

Examples of org.w3c.dom.ranges.Range


        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;
    }
View Full Code Here


        if (ranges == null) {
            ranges = new Vector();
        }

        Range range = new RangeImpl(this);

        ranges.addElement(range);

        return range;
View Full Code Here

        if (ranges == null) {
            ranges = new Vector();
        }

        Range range = new RangeImpl(this);

        ranges.addElement(range);

        return range;
View Full Code Here

        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;
    }
View Full Code Here

            }
        }
        if (firstText == null) {
            return;
        }
        Range r = docRange.createRange();
        r.setStart(firstText, 0);
        ViewModelInfo firstPoint = new ViewModelInfo(r, (InlineText) ((List) textInlineMap
                .get(firstText)).get(0));
        r = docRange.createRange();
        try {
            // possibly some dom impls don't handle this?
            r.setStart(lastText, lastText.getLength());
        } catch (Exception e) {
            r.setStart(lastText, Math.max(0, lastText.getLength() - 1));
        }
        List l = (List) textInlineMap.get(firstText);

        ViewModelInfo lastPoint = new ViewModelInfo(r, (InlineText) l.get(l.size() - 1));
        setDot(firstPoint);
View Full Code Here

            getComponent().getRootBox().clearSelection(modified);
            getComponent().repaint();
            lastHighlightedString = "";
            return;
        }
        Range range = getSelectionRange();

        if (lastSelectionRange != null
                && range.compareBoundaryPoints(Range.START_TO_START, lastSelectionRange) == 0
                && range.compareBoundaryPoints(Range.END_TO_END, lastSelectionRange) == 0) {
            return;
        }
        lastHighlightedString = "";
        lastSelectionRange = range.cloneRange();

        if (range.compareBoundaryPoints(Range.START_TO_END, range) == 0) {
            getComponent().getRootBox().clearSelection(modified);
        } else {
            boolean endBeforeStart = (this.markInfo.range.compareBoundaryPoints(
                    Range.START_TO_START, this.dotInfo.range) >= 0);
            // TODO: track modifications
            getComponent().getRootBox().clearSelection(modified);
            InlineText t1 = (endBeforeStart) ? this.dotInfo.text : this.markInfo.text;
            InlineText t2 = (!endBeforeStart) ? this.dotInfo.text : this.markInfo.text;
            if (t1 == null || t2 == null) {
                // TODO: need general debug here (never print to system.err; use XRLog instead)
                // TODO: is this just a warning, or should we bail out
                XRLog.general(Level.FINE, "null text node");
            }

            final Range acceptRange = docRange.createRange();
            final Range tr = range;
            NodeFilter f = new NodeFilter() {
                public short acceptNode(Node n) {
                    acceptRange.setStart(n, 0);
                    if (tr.getStartContainer() == n) {
                        return FILTER_ACCEPT;
                    }
                    if ((acceptRange.compareBoundaryPoints(Range.START_TO_START, tr) < 0 || acceptRange
                            .compareBoundaryPoints(Range.END_TO_START, tr) > 0)
                            && n != tr.getStartContainer() && n != tr.getEndContainer()) {
                        return NodeFilter.FILTER_SKIP;
                    }

                    return NodeFilter.FILTER_ACCEPT;
                }
View Full Code Here

        return ilbs;
    }

    ViewModelInfo infoFromPoint(MouseEvent e) {
        checkDocument();
        Range r = docRange.createRange();
        InlineText fndTxt = null;
        Box box = panel.getRootLayer().find(panel.getLayoutContext(), e.getX(), e.getY(), true);
        if (box == null) {
            return null;
        }
        Element elt = null;
        int offset = 0;
        InlineLayoutBox ilb = null;
        boolean containsWholeIlb = false;
        if (box instanceof InlineLayoutBox) {
            ilb = (InlineLayoutBox) box;
        } else {
            for (; ilb == null;) {
                List ilbs = getInlineLayoutBoxes(box, false);
                for (int i = ilbs.size() - 1; i >= 0; i--) {
                    InlineLayoutBox ilbt = (InlineLayoutBox) ilbs.get(i);
                    if (ilbt.getAbsY() <= e.getY() && ilbt.getAbsX() <= e.getX()) {
                        if (ilb == null || (ilbt.getAbsY() > ilb.getAbsY())
                                || (ilbt.getAbsY() == ilb.getAbsY() && ilbt.getX() > ilb.getX())) {

                            if (ilbt.isContainsVisibleContent()) {
                                boolean hasDecentTextNode = false;
                                int x = ilbt.getAbsX();

                                for (Iterator it = ilbt.getInlineChildren().iterator(); it
                                        .hasNext();) {
                                    Object o = it.next();
                                    if (o instanceof InlineText) {
                                        InlineText txt = (InlineText) o;
                                        if (txt.getTextNode() != null) {
                                            hasDecentTextNode = true;
                                            break;
                                        }
                                    }
                                }
                                if (hasDecentTextNode) {
                                    ilb = ilbt;
                                }
                            }
                        }
                        containsWholeIlb = true;
                    }
                }
                if (ilb == null) {
                    if (box.getParent() == null) {
                        return null;
                    }
                    box = box.getParent();
                }
            }
        }
        int x = ilb.getAbsX();
        InlineText lastItxt = null;
        for (Iterator it = ilb.getInlineChildren().iterator(); it.hasNext();) {
            Object o = it.next();
            if (o instanceof InlineText) {
                InlineText txt = (InlineText) o;
                if (txt.getTextNode() != null) {
                    if ((e.getX() >= x + txt.getX() && e.getX() < x + txt.getX() + txt.getWidth())
                            || containsWholeIlb) {
                        fndTxt = txt;
                        break;
                    } else {
                        if (e.getX() < x + txt.getX()) {
                            // assume inline image or somesuch
                            if (lastItxt != null) {
                                fndTxt = lastItxt;
                                break;
                            }
                        }
                    }
                }
                lastItxt = txt;
            }
        }

        LayoutContext lc = panel.getLayoutContext();
        if (fndTxt == null) {
            // TODO: need general debug flag here; not sure if this is an error condition and if the logging is necessary
            if (false) {
                XRLog.general(Level.FINE, ilb.dump(lc, "", Box.DUMP_RENDER));
                XRLog.general(Level.FINE, ilb.getParent().dump(lc, "", Box.DUMP_RENDER));
                XRLog.general(Level.FINE, ilb.getParent().getParent().dump(lc, "", Box.DUMP_RENDER));
            }
            return null;
        }

        String txt = fndTxt.getMasterText();

        CalculatedStyle style = ilb.getStyle();
        if (containsWholeIlb) {
            offset = fndTxt.getEnd();
        } else {
            for (offset = fndTxt.getStart(); offset < fndTxt.getEnd(); offset++) {
                int w = getTextWidth(lc, style, txt.substring(fndTxt.getStart(), offset + 1));
                if (w + x + fndTxt.getX() > e.getX()) {
                    break;
                }

            }
        }

        Node node = fndTxt.getTextNode();
        try {
            r.setStart(node, offset);
        } catch (Exception ex) {
            // maybe differs for dom impl? anyway, fix for issue 216
            r.setStart(node, ((Text) node).getLength() - 1);
        }
        return new ViewModelInfo(r, fndTxt);

    }
View Full Code Here

    public Range getSelectionRange() {
        if (this.dotInfo == null || this.dotInfo.range == null) {
            return null;
        }
        Range r = docRange.createRange();
        // some xml parsers don't allow end<start in the same text node. So,
        // handle dot<mark here

        if (this.markInfo.range.compareBoundaryPoints(Range.START_TO_START, this.dotInfo.range) <= 0) {
            r.setStart(this.markInfo.range.getStartContainer(), this.markInfo.range
                    .getStartOffset());
            r.setEnd(this.dotInfo.range.getStartContainer(), this.dotInfo.range.getStartOffset());
        } else {
            r.setStart(this.dotInfo.range.getStartContainer(), this.dotInfo.range.getStartOffset());
            r.setEnd(this.markInfo.range.getStartContainer(), this.markInfo.range.getStartOffset());
        }
        return r;
    }
View Full Code Here

     * @param other the other range
     * @return <code>true</code> if <code>other</code> is contained within current range
     * @see <a href="http://msdn.microsoft.com/en-us/library/ms536371.aspx">MSDN doc</a>
     */
    public boolean jsxFunction_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;
View Full Code Here

    /**
     * Returns the node in which the selection begins.
     * @return the node in which the selection begins
     */
    public Node jsxGet_anchorNode() {
        final Range last = getLastRange();
        if (last == null) {
            return null;
        }
        return (Node) getScriptableNullSafe(last.getStartContainer());
    }
View Full Code Here

TOP

Related Classes of org.w3c.dom.ranges.Range

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.