Range(final org.w3c.dom.ranges.Range w3cRange) { final DomNode domNodeStartContainer = (DomNode) w3cRange.getStartContainer(); startContainer_ = domNodeStartContainer.getScriptableObject(); startOffset_ = w3cRange.getStartOffset(); final DomNode domNodeEndContainer = (DomNode) w3cRange.getEndContainer(); endContainer_ = domNodeEndContainer.getScriptableObject(); endOffset_ = w3cRange.getEndOffset(); }
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; }
/** * Constructs a text range around the provided range. * @param range the initial range */ public TextRange(final Range range) { range_ = range.cloneRange(); }
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; }
&& range.compareBoundaryPoints(Range.START_TO_START, lastSelectionRange) == 0 && range.compareBoundaryPoints(Range.END_TO_END, lastSelectionRange) == 0) { return; 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); final Node selectionEndNode = range.getEndContainer(); NodeFilter f = new NodeFilter() { public short acceptNode(Node n) { .getCommonAncestorContainer(), NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_CDATA_SECTION, f, false); Box box = getElementContainerBox(t1); int selTxtSt = (t == range.getStartContainer()) ? range.getStartOffset() : 0; int selTxtEnd = (t == range.getEndContainer()) ? range.getEndOffset() : t .getNodeValue().length();
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; }
/** * Returns the number of ranges in the selection. * @return the number of ranges in the selection */ public int jsxGet_rangeCount() { final Range r = getPageSelection(); final boolean valid = (r.getStartContainer() != null && r.getEndContainer() != null); if (valid) { return 1; } return 0; }
/** * {@inheritDoc} */ @Override public void setSelectionEnd(int selectionEnd) { final int length = element_.getText().length(); selectionEnd = Math.min(length, Math.max(selectionEnd, 0)); selection_.setEnd(element_, selectionEnd); if (selection_.getStartOffset() > selectionEnd) { selection_.setStart(element_, selectionEnd); } } }
/** * Retrieves the parent element for the given text range. * The parent element is the element that completely encloses the text in the range. * If the text range spans text in more than one element, this method returns the smallest element that encloses * all the elements. When you insert text into a range that spans multiple elements, the text is placed in the * parent element rather than in any of the contained elements. * * @see <a href="http://msdn.microsoft.com/en-us/library/ms536654.aspx">MSDN doc</a> * @return the parent element object if successful, or null otherwise. */ @JsxFunction public Node parentElement() { final org.w3c.dom.Node parent = range_.getCommonAncestorContainer(); if (null == parent) { if (null == range_.getStartContainer() || null == range_.getEndContainer()) { try { final Window window = (Window) getParentScope(); final HtmlPage page = (HtmlPage) window.getDomNodeOrDie(); return (Node) getScriptableFor(page.getBody()); } catch (final Exception e) { // ok bad luck } } return null; } return (Node) getScriptableFor(parent); }
/** * Returns the selected text in the owner element, or <tt>null</tt> if there is no selected text. * @return the selected text in the owner element, or <tt>null</tt> if there is no selected text */ public String getSelectedText() { final Range selection = getSelectionInner(); if (selection != null) { return element_.getText().substring(selection.getStartOffset(), selection.getEndOffset()); } return null; }
/** * {@inheritDoc} */ @Override public void setSelectionStart(int selectionStart) { if (selectionStart < 0 && element_.getPage().getEnclosingWindow().getWebClient() .getBrowserVersion().hasFeature(JS_INPUT_IGNORE_NEGATIVE_SELECTION_START)) { return; } final int length = element_.getText().length(); selectionStart = Math.max(0, Math.min(selectionStart, length)); selection_.setStart(element_, selectionStart); if (selection_.getEndOffset() < selectionStart) { selection_.setEnd(element_, selectionStart); } }
/** * {@inheritDoc} */ @Override public int getSelectionStart() { return selection_.getStartOffset(); }
/** * {@inheritDoc} */ @Override public int getSelectionEnd() { return selection_.getEndOffset(); }
_commonAncestor = _range.getCommonAncestorContainer(); Node node = _range.getStartContainer(); int offset = _range.getStartOffset(); Node ancestorParent = _commonAncestor.getParentNode(); while (node != ancestorParent) {
/** * Returns the node in which the selection begins. * @return the node in which the selection begins */ public Node jsxGet_anchorNode() { return (Node) getScriptableNullSafe(getPageSelection().getStartContainer()); }
/** * Returns the node in which the selection ends. * @return the node in which the selection ends */ public Node jsxGet_focusNode() { return (Node) getScriptableNullSafe(getPageSelection().getEndContainer()); }
/** * Moves the focus of the selection to a specified point. The anchor of the selection does not move. * @param parentNode the node within which the focus will be moved * @param offset the number of characters from the beginning of parentNode's text the focus will be placed */ public void jsxFunction_extend(final Node parentNode, final int offset) { final Range selection = getPageSelection(); selection.setEnd(parentNode.getDomNodeOrDie(), offset); }
/** * Retrieves the parent element for the given text range. * The parent element is the element that completely encloses the text in the range. * If the text range spans text in more than one element, this method returns the smallest element that encloses * all the elements. When you insert text into a range that spans multiple elements, the text is placed in the * parent element rather than in any of the contained elements. * * @see <a href="http://msdn.microsoft.com/en-us/library/ms536654.aspx">MSDN doc</a> * @return the parent element object if successful, or null otherwise. */ public Object jsxFunction_parentElement() { final org.w3c.dom.Node parent = range_.getCommonAncestorContainer(); return getScriptableFor(parent); }
/** * Collapses the range. * @param toStart indicates if collapse should be done to the start * @see <a href="http://msdn.microsoft.com/en-us/library/ms536371.aspx">MSDN doc</a> */ public void jsxFunction_collapse(final boolean toStart) { collapsed_ = true; range_.collapse(toStart); }