Search in sources :

Example 6 with JsxFunction

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;
}
Also used : Window(com.gargoylesoftware.htmlunit.javascript.host.Window) DomNode(com.gargoylesoftware.htmlunit.html.DomNode) ScriptableObject(net.sourceforge.htmlunit.corejs.javascript.ScriptableObject) HTMLElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement) ClientRect(com.gargoylesoftware.htmlunit.javascript.host.ClientRect) ClientRectList(com.gargoylesoftware.htmlunit.javascript.host.ClientRectList) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Example 7 with JsxFunction

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();
}
Also used : DomDocumentFragment(com.gargoylesoftware.htmlunit.html.DomDocumentFragment) SgmlPage(com.gargoylesoftware.htmlunit.SgmlPage) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Example 8 with JsxFunction

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;
    }
}
Also used : SimpleRange(com.gargoylesoftware.htmlunit.html.impl.SimpleRange) Range(org.w3c.dom.ranges.Range) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Example 9 with JsxFunction

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;
}
Also used : SimpleRange(com.gargoylesoftware.htmlunit.html.impl.SimpleRange) Range(org.w3c.dom.ranges.Range) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Example 10 with JsxFunction

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;
}
Also used : SimpleRange(com.gargoylesoftware.htmlunit.html.impl.SimpleRange) Range(org.w3c.dom.ranges.Range) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Aggregations

JsxFunction (com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)133 DomNode (com.gargoylesoftware.htmlunit.html.DomNode)30 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)20 ScriptableObject (net.sourceforge.htmlunit.corejs.javascript.ScriptableObject)19 WebWindow (com.gargoylesoftware.htmlunit.WebWindow)16 URL (java.net.URL)14 IOException (java.io.IOException)11 Scriptable (net.sourceforge.htmlunit.corejs.javascript.Scriptable)11 WebClient (com.gargoylesoftware.htmlunit.WebClient)10 DomElement (com.gargoylesoftware.htmlunit.html.DomElement)10 SimpleRange (com.gargoylesoftware.htmlunit.html.impl.SimpleRange)10 Event (com.gargoylesoftware.htmlunit.javascript.host.event.Event)10 SgmlPage (com.gargoylesoftware.htmlunit.SgmlPage)8 HtmlUnitScriptable (com.gargoylesoftware.htmlunit.javascript.HtmlUnitScriptable)8 MessageEvent (com.gargoylesoftware.htmlunit.javascript.host.event.MessageEvent)8 HTMLElement (com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement)8 NameValuePair (com.gargoylesoftware.htmlunit.util.NameValuePair)8 Range (org.w3c.dom.ranges.Range)8 HtmlAttributeChangeEvent (com.gargoylesoftware.htmlunit.html.HtmlAttributeChangeEvent)7 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)7