/** * Same iterator with an option to start the iterator at the range's first node. * @param range - range must be normalized. * @param firstChild - if true start the the range's first child instead of * the common ancestor. */ public RangeIterator(Range range, boolean firstChild) { if (range == null || range.getStartContainer() == null || range.getEndContainer() == null) { throw new NullPointerException(); } _range = range; _firstChild = firstChild; initIterator(); }
/** * 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; }
/** * 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()); }
/** * 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; }
/** * 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()); }
/** * 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()); }
/** * 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; }
/** * Returns the node in which the selection ends. * @return the node in which the selection ends */ @JsxGetter public Node getFocusNode() { final Range last = getLastRange(); if (last == null) { return null; } return (Node) getScriptableNullSafe(last.getEndContainer()); }
/** * Returns the node in which the selection ends. * @return the node in which the selection ends */ @JsxGetter public Node getFocusNode() { final Range last = getLastRange(); if (last == null) { return null; } return (Node) getScriptableNullSafe(last.getEndContainer()); }
/** * Returns the range at the specified index. Note that the HtmlUnit DOM only supports a single range, * but multiple ranges can be created via JavaScript. * * TODO: This method does not currently support indices > 0, but such indices should probably return * ranges created programmatically via createRange(). * * @param index the index of the range to return * @return the range at the specified index */ public Range jsxFunction_getRangeAt(final int index) { final Range r = getPageSelection(); final boolean valid = (r.getStartContainer() != null && r.getEndContainer() != null); if (!valid || index < 0 || index > 0) { throw Context.reportRuntimeError("Invalid range index: " + index); } return r; }
private Range getSelectionInner() { if (element_.getPage() instanceof HtmlPage) { final Range selection = ((HtmlPage) element_.getPage()).getSelection(); if (selection.getStartContainer() == element_ && selection.getEndContainer() == element_) { return selection; } } return null; }
private Range getSelectionInner() { if (element_.getPage() instanceof HtmlPage) { final Range selection = ((HtmlPage) element_.getPage()).getSelection(); if (selection.getStartContainer() == element_ && selection.getEndContainer() == element_) { return selection; } } return null; }
private Range getSelectionInner() { if (element_.getPage() instanceof HtmlPage) { final Range selection = ((HtmlPage) element_.getPage()).getSelection(); if (selection.getStartContainer() == element_ && selection.getEndContainer() == element_) { return selection; } } return null; }
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 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; }
/** * Sets the text contained within the range. * @param text the text contained within the range */ @JsxSetter public void setText(final String text) { if (range_.getStartContainer() == range_.getEndContainer() && range_.getStartContainer() instanceof SelectableTextInput) { final SelectableTextInput input = (SelectableTextInput) range_.getStartContainer(); final String oldValue = input.getText(); input.setText(oldValue.substring(0, input.getSelectionStart()) + text + oldValue.substring(input.getSelectionEnd())); } }
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; }
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; }
/** * Sets the text contained within the range. * @param text the text contained within the range */ @JsxSetter public void setText(final String text) { if (range_.getStartContainer() == range_.getEndContainer() && range_.getStartContainer() instanceof SelectableTextInput) { final SelectableTextInput input = (SelectableTextInput) range_.getStartContainer(); final String oldValue = input.getText(); input.setText(oldValue.substring(0, input.getSelectionStart()) + text + oldValue.substring(input.getSelectionEnd())); } }
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(); }