/** * Sets the start position of the selected text in the owner element. * @param selectionStart the start position of the selected text in the owner element */ public void setSelectionStart(int selectionStart) { if (element_.getPage() instanceof HtmlPage) { final HtmlPage page = (HtmlPage) element_.getPage(); final int length = element_.getText().length(); selectionStart = Math.max(0, Math.min(selectionStart, length)); page.getSelection().setStart(element_, selectionStart); if (page.getSelection().getEndContainer() != element_) { page.getSelection().setEnd(element_, length); } else if (page.getSelection().getEndOffset() < selectionStart) { page.getSelection().setEnd(element_, selectionStart); } } }
/** * Sets the end position of the selected text in the owner element. * @param selectionEnd the end position of the selected text in the owner element */ public void setSelectionEnd(int selectionEnd) { if (element_.getPage() instanceof HtmlPage) { final HtmlPage page = (HtmlPage) element_.getPage(); final int length = element_.getText().length(); selectionEnd = Math.min(length, Math.max(selectionEnd, 0)); page.getSelection().setEnd(element_, selectionEnd); if (page.getSelection().getStartContainer() != element_) { page.getSelection().setStart(element_, 0); } else if (page.getSelection().getStartOffset() > selectionEnd) { page.getSelection().setStart(element_, selectionEnd); } } }
/** * Sets the start position of the selected text in the owner element. * @param selectionStart the start position of the selected text in the owner element */ public void setSelectionStart(int selectionStart) { if (element_.getPage() instanceof HtmlPage) { final HtmlPage page = (HtmlPage) element_.getPage(); final int length = element_.getText().length(); selectionStart = Math.max(0, Math.min(selectionStart, length)); page.getSelection().setStart(element_, selectionStart); if (page.getSelection().getEndContainer() != element_) { page.getSelection().setEnd(element_, length); } else if (page.getSelection().getEndOffset() < selectionStart) { page.getSelection().setEnd(element_, selectionStart); } } }
/** * Returns the current HtmlUnit DOM selection range. * @return the current HtmlUnit DOM selection range */ private Range getPageSelection() { final HtmlPage page = (HtmlPage) getWindow().getDomNodeOrDie(); return page.getSelection(); }
/** * Returns the current HtmlUnit DOM selection range. * @return the current HtmlUnit DOM selection range */ private Range getPageSelection() { final HtmlPage page = (HtmlPage) getWindow().getDomNodeOrDie(); return page.getSelection(); }
/** * Sets the end position of the selected text in the owner element. * @param selectionEnd the end position of the selected text in the owner element */ public void setSelectionEnd(int selectionEnd) { if (element_.getPage() instanceof HtmlPage) { final HtmlPage page = (HtmlPage) element_.getPage(); final int length = element_.getText().length(); selectionEnd = Math.min(length, Math.max(selectionEnd, 0)); page.getSelection().setEnd(element_, selectionEnd); if (page.getSelection().getStartContainer() != element_) { page.getSelection().setStart(element_, 0); } else if (page.getSelection().getStartOffset() > selectionEnd) { page.getSelection().setStart(element_, selectionEnd); } } }
/** * Sets the end position of the selected text in the owner element. * @param selectionEnd the end position of the selected text in the owner element */ public void setSelectionEnd(int selectionEnd) { if (element_.getPage() instanceof HtmlPage) { final HtmlPage page = (HtmlPage) element_.getPage(); final int length = element_.getText().length(); selectionEnd = Math.min(length, Math.max(selectionEnd, 0)); page.getSelection().setEnd(element_, selectionEnd); if (page.getSelection().getStartContainer() != element_) { page.getSelection().setStart(element_, 0); } else if (page.getSelection().getStartOffset() > selectionEnd) { page.getSelection().setStart(element_, selectionEnd); } } }
/** * Sets the start position of the selected text in the owner element. * @param selectionStart the start position of the selected text in the owner element */ public void setSelectionStart(int selectionStart) { if (element_.getPage() instanceof HtmlPage) { final HtmlPage page = (HtmlPage) element_.getPage(); final int length = element_.getText().length(); selectionStart = Math.max(0, Math.min(selectionStart, length)); page.getSelection().setStart(element_, selectionStart); if (page.getSelection().getEndContainer() != element_) { page.getSelection().setEnd(element_, length); } else if (page.getSelection().getEndOffset() < selectionStart) { page.getSelection().setEnd(element_, selectionStart); } } }
/** * Returns the current HtmlUnit DOM selection range. * @return the current HtmlUnit DOM selection range */ private Range getPageSelection() { final HtmlPage page = (HtmlPage) getWindow().getDomNodeOrDie(); return page.getSelection(); }
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; }
/** * {@inheritDoc} */ @Override public void focus() { super.focus(); valueAtFocus_ = getText(); if (getPage() instanceof HtmlPage) { final Range selection = ((HtmlPage) getPage()).getSelection(); selection.setStart(this, 0); selection.setEnd(this, getText().length()); } }
/** * {@inheritDoc} */ @Override public void focus() { super.focus(); valueAtFocus_ = getText(); if (getPage() instanceof HtmlPage) { final Range selection = ((HtmlPage) getPage()).getSelection(); selection.setStart(this, 0); selection.setEnd(this, getText().length()); } }
/** * {@inheritDoc} */ @Override public void focus() { super.focus(); valueAtFocus_ = getText(); if (getPage() instanceof HtmlPage) { final Range selection = ((HtmlPage) getPage()).getSelection(); selection.setStart(this, 0); selection.setEnd(this, getText().length()); } }
/** * Sets the text contained within the range. * @param text the text contained within the range */ public void jsxSet_text(final String text) { collapsed_ = false; final HtmlPage page = (HtmlPage) getWindow().getDomNodeOrDie(); final Range selection = page.getSelection(); // currently only working for text input and textarea if (selection.getStartContainer() == selection.getEndContainer()) { if (selection.getStartContainer() instanceof HtmlTextInput) { final HtmlTextInput input = (HtmlTextInput) selection.getStartContainer(); final String oldValue = input.getValueAttribute(); input.setValueAttribute(oldValue.substring(0, input.getSelectionStart()) + text + oldValue.substring(input.getSelectionEnd())); } else if (selection.getStartContainer() instanceof HtmlTextArea) { final HtmlTextArea input = (HtmlTextArea) selection.getStartContainer(); final String oldValue = input.getText(); input.setText(oldValue.substring(0, input.getSelectionStart()) + text + oldValue.substring(input.getSelectionEnd())); } } }
/** * Sets the text contained within the range. * @param text the text contained within the range */ public void jsxSet_text(final String text) { collapsed_ = false; final HtmlPage page = (HtmlPage) getWindow().getDomNodeOrDie(); final Range selection = page.getSelection(); // currently only working for text input and textarea if (selection.getStartContainer() == selection.getEndContainer()) { if (selection.getStartContainer() instanceof HtmlTextInput) { final HtmlTextInput input = (HtmlTextInput) selection.getStartContainer(); final String oldValue = input.getValueAttribute(); input.setValueAttribute(oldValue.substring(0, input.getSelectionStart()) + text + oldValue.substring(input.getSelectionEnd())); } else if (selection.getStartContainer() instanceof HtmlTextArea) { final HtmlTextArea input = (HtmlTextArea) selection.getStartContainer(); final String oldValue = input.getText(); input.setText(oldValue.substring(0, input.getSelectionStart()) + text + oldValue.substring(input.getSelectionEnd())); } } }
/** * Sets the text contained within the range. * @param text the text contained within the range */ public void jsxSet_text(final String text) { collapsed_ = false; final HtmlPage page = (HtmlPage) getWindow().getDomNodeOrDie(); final Range selection = page.getSelection(); // currently only working for text input and textarea if (selection.getStartContainer() == selection.getEndContainer()) { if (selection.getStartContainer() instanceof HtmlTextInput) { final HtmlTextInput input = (HtmlTextInput) selection.getStartContainer(); final String oldValue = input.getValueAttribute(); input.setValueAttribute(oldValue.substring(0, input.getSelectionStart()) + text + oldValue.substring(input.getSelectionEnd())); } else if (selection.getStartContainer() instanceof HtmlTextArea) { final HtmlTextArea input = (HtmlTextArea) selection.getStartContainer(); final String oldValue = input.getText(); input.setText(oldValue.substring(0, input.getSelectionStart()) + text + oldValue.substring(input.getSelectionEnd())); } } }
/** * Retrieves the text contained within the range. * @return the text contained within the range */ public Object jsxGet_text() { if (collapsed_) { return ""; } final HtmlPage page = (HtmlPage) getWindow().getDomNodeOrDie(); final Range selection = page.getSelection(); // currently only working for text input and textarea if (selection.getStartContainer() == selection.getEndContainer()) { if (selection.getStartContainer() instanceof HtmlTextInput) { final HtmlTextInput input = (HtmlTextInput) selection.getStartContainer(); return input.getValueAttribute().substring(input.getSelectionStart(), input.getSelectionEnd()); } else if (selection.getStartContainer() instanceof HtmlTextArea) { final HtmlTextArea input = (HtmlTextArea) selection.getStartContainer(); return input.getText().substring(input.getSelectionStart(), input.getSelectionEnd()); } } return ""; }
/** * Retrieves the text contained within the range. * @return the text contained within the range */ public Object jsxGet_text() { if (collapsed_) { return ""; } final HtmlPage page = (HtmlPage) getWindow().getDomNodeOrDie(); final Range selection = page.getSelection(); // currently only working for text input and textarea if (selection.getStartContainer() == selection.getEndContainer()) { if (selection.getStartContainer() instanceof HtmlTextInput) { final HtmlTextInput input = (HtmlTextInput) selection.getStartContainer(); return input.getValueAttribute().substring(input.getSelectionStart(), input.getSelectionEnd()); } else if (selection.getStartContainer() instanceof HtmlTextArea) { final HtmlTextArea input = (HtmlTextArea) selection.getStartContainer(); return input.getText().substring(input.getSelectionStart(), input.getSelectionEnd()); } } return ""; }