use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class Range method getClientRects.
/**
* Retrieves a collection of rectangles that describes the layout of the contents of an object
* or range within the client. Each rectangle describes a single line.
* @return a collection of rectangles that describes the layout of the contents
*/
@JsxFunction
public ClientRectList getClientRects() {
final Window w = getWindow();
final ClientRectList rectList = new ClientRectList();
rectList.setParentScope(w);
rectList.setPrototype(getPrototype(rectList.getClass()));
// simple impl for now
for (final DomNode node : toW3C().containedNodes()) {
final ScriptableObject scriptable = node.getScriptableObject();
if (scriptable instanceof HTMLElement) {
final ClientRect rect = new ClientRect(0, 0, 1, 1);
rect.setParentScope(w);
rect.setPrototype(getPrototype(rect.getClass()));
rectList.add(rect);
}
}
return rectList;
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class Range method createContextualFragment.
/**
* Parses an HTML snippet.
* @param valueAsString text that contains text and tags to be converted to a document fragment
* @return a document fragment
* @see <a href="https://developer.mozilla.org/en-US/docs/DOM/range.createContextualFragment">Mozilla
* documentation</a>
*/
@JsxFunction
public Object createContextualFragment(final String valueAsString) {
final SgmlPage page = startContainer_.getDomNodeOrDie().getPage();
final DomDocumentFragment fragment = new DomDocumentFragment(page);
try {
page.getWebClient().getPageCreator().getHtmlParser().parseFragment(fragment, startContainer_.getDomNodeOrDie(), valueAsString, false);
} catch (final Exception e) {
LogFactory.getLog(Range.class).error("Unexpected exception occurred in createContextualFragment", e);
throw Context.reportRuntimeError("Unexpected exception occurred in createContextualFragment: " + e.getMessage());
}
return fragment.getScriptableObject();
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class Selection method extend.
/**
* 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
*/
@JsxFunction({ CHROME, EDGE, FF, FF_ESR })
public void extend(final Node parentNode, final int offset) {
final Range last = getLastRange();
if (last != null) {
last.setEnd(parentNode.getDomNodeOrDie(), offset);
type_ = TYPE_RANGE;
}
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class Selection method getRangeAt.
/**
* Returns the range at the specified index.
*
* @param index the index of the range to return
* @return the range at the specified index
*/
@JsxFunction
public com.gargoylesoftware.htmlunit.javascript.host.dom.Range getRangeAt(final int index) {
final List<Range> ranges = getRanges();
if (index < 0 || index >= ranges.size()) {
throw Context.reportRuntimeError("Invalid range index: " + index);
}
final Range range = ranges.get(index);
final com.gargoylesoftware.htmlunit.javascript.host.dom.Range jsRange = new com.gargoylesoftware.htmlunit.javascript.host.dom.Range(range);
jsRange.setParentScope(getWindow());
jsRange.setPrototype(getPrototype(com.gargoylesoftware.htmlunit.javascript.host.dom.Range.class));
return jsRange;
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class Selection method collapseToEnd.
/**
* 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;
}
Aggregations