Search in sources :

Example 36 with JsxFunction

use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.

the class XMLDOMElement method setAttributeNode.

/**
 * Sets or updates the supplied attribute node on this element.
 * @param newAtt the attribute node to be associated with this element
 * @return the replaced attribute node, if any, {@code null} otherwise
 */
@JsxFunction
public XMLDOMAttribute setAttributeNode(final XMLDOMAttribute newAtt) {
    if (newAtt == null) {
        throw Context.reportRuntimeError("Type mismatch.");
    }
    final String name = newAtt.getBaseName();
    final XMLDOMNamedNodeMap nodes = (XMLDOMNamedNodeMap) getAttributes();
    final XMLDOMAttribute replacedAtt = (XMLDOMAttribute) nodes.getNamedItemWithoutSyntheticClassAttr(name);
    if (replacedAtt != null) {
        replacedAtt.detachFromParent();
    }
    final DomAttr newDomAttr = newAtt.getDomNodeOrDie();
    getDomNodeOrDie().setAttributeNode(newDomAttr);
    return replacedAtt;
}
Also used : DomAttr(com.gargoylesoftware.htmlunit.html.DomAttr) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Example 37 with JsxFunction

use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.

the class HTMLCollectionFrames method showModelessDialog.

/**
 * Creates a modeless dialog box that displays the specified HTML document.
 * @param url the URL of the document to load and display
 * @param arguments object to be made available via <tt>window.dialogArguments</tt> in the dialog window
 * @param features string that specifies the window ornaments for the dialog window
 * @return a reference to the new window object created for the modeless dialog
 * @see <a href="http://msdn.microsoft.com/en-us/library/ms536761.aspx">MSDN Documentation</a>
 */
@JsxFunction(IE)
public Object showModelessDialog(final String url, final Object arguments, final String features) {
    final WebWindow webWindow = getWebWindow();
    final WebClient client = webWindow.getWebClient();
    try {
        final URL completeUrl = ((HtmlPage) getDomNodeOrDie()).getFullyQualifiedUrl(url);
        final DialogWindow dialog = client.openDialogWindow(completeUrl, webWindow, arguments);
        return dialog.getScriptableObject();
    } catch (final IOException e) {
        throw Context.throwAsScriptRuntimeEx(e);
    }
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) IOException(java.io.IOException) WebClient(com.gargoylesoftware.htmlunit.WebClient) DialogWindow(com.gargoylesoftware.htmlunit.DialogWindow) URL(java.net.URL) WebWindow(com.gargoylesoftware.htmlunit.WebWindow) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Example 38 with JsxFunction

use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.

the class HTMLCollectionFrames method focus.

/**
 * Sets the focus to this element.
 */
@JsxFunction
public void focus() {
    final WebWindow window = getWebWindow();
    window.getWebClient().setCurrentWindow(window);
}
Also used : WebWindow(com.gargoylesoftware.htmlunit.WebWindow) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Example 39 with JsxFunction

use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.

the class HTMLCollectionFrames method postMessage.

/**
 * Posts a message.
 * @param message the object passed to the window
 * @param targetOrigin the origin this window must be for the event to be dispatched
 * @param transfer an optional sequence of Transferable objects
 * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/window.postMessage">MDN documentation</a>
 */
@JsxFunction
public void postMessage(final String message, final String targetOrigin, final Object transfer) {
    final WebWindow webWindow = getWebWindow();
    final Page page = webWindow.getEnclosedPage();
    final URL currentURL = page.getUrl();
    if (!"*".equals(targetOrigin) && !"/".equals(targetOrigin)) {
        final URL targetURL;
        try {
            targetURL = new URL(targetOrigin);
        } catch (final Exception e) {
            throw Context.throwAsScriptRuntimeEx(new Exception("SyntaxError: Failed to execute 'postMessage' on 'Window': Invalid target origin '" + targetOrigin + "' was specified (reason: " + e.getMessage() + "."));
        }
        if (getPort(targetURL) != getPort(currentURL)) {
            return;
        }
        if (!targetURL.getHost().equals(currentURL.getHost())) {
            return;
        }
        if (!targetURL.getProtocol().equals(currentURL.getProtocol())) {
            return;
        }
    }
    final MessageEvent event = new MessageEvent();
    final String origin = currentURL.getProtocol() + "://" + currentURL.getHost() + ':' + currentURL.getPort();
    event.initMessageEvent(Event.TYPE_MESSAGE, false, false, message, origin, "", this, transfer);
    event.setParentScope(this);
    event.setPrototype(getPrototype(event.getClass()));
    final JavaScriptEngine jsEngine = (JavaScriptEngine) webWindow.getWebClient().getJavaScriptEngine();
    final PostponedAction action = new PostponedAction(page, "Window.postMessage") {

        @Override
        public void execute() throws Exception {
            final ContextAction<Object> contextAction = cx -> dispatchEvent(event);
            final ContextFactory cf = jsEngine.getContextFactory();
            cf.call(contextAction);
        }
    };
    jsEngine.addPostponedAction(action);
}
Also used : DomElement(com.gargoylesoftware.htmlunit.html.DomElement) WebWindow(com.gargoylesoftware.htmlunit.WebWindow) DialogWindow(com.gargoylesoftware.htmlunit.DialogWindow) HtmlMap(com.gargoylesoftware.htmlunit.html.HtmlMap) JS_WINDOW_SELECTION_NULL_IF_INVISIBLE(com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_WINDOW_SELECTION_NULL_IF_INVISIBLE) FF(com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.FF) MediaQueryList(com.gargoylesoftware.htmlunit.javascript.host.css.MediaQueryList) EDGE(com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.EDGE) StringUtils(org.apache.commons.lang3.StringUtils) JsxConstant(com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstant) MouseEvent(com.gargoylesoftware.htmlunit.javascript.host.event.MouseEvent) BaseFrameElement(com.gargoylesoftware.htmlunit.html.BaseFrameElement) ContextAction(net.sourceforge.htmlunit.corejs.javascript.ContextAction) Map(java.util.Map) JS_WINDOW_CHANGE_OPENER_ONLY_WINDOW_OBJECT(com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_WINDOW_CHANGE_OPENER_ONLY_WINDOW_OBJECT) Scriptable(net.sourceforge.htmlunit.corejs.javascript.Scriptable) JsxSetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter) HTMLCollection(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLCollection) EnumMap(java.util.EnumMap) DomNode(com.gargoylesoftware.htmlunit.html.DomNode) JsxGetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter) SpeechSynthesis(com.gargoylesoftware.htmlunit.javascript.host.speech.SpeechSynthesis) JS_WINDOW_TOP_WRITABLE(com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_WINDOW_TOP_WRITABLE) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) HtmlInput(com.gargoylesoftware.htmlunit.html.HtmlInput) LogFactory(org.apache.commons.logging.LogFactory) AlertHandler(com.gargoylesoftware.htmlunit.AlertHandler) HtmlAnchor(com.gargoylesoftware.htmlunit.html.HtmlAnchor) HtmlEmbed(com.gargoylesoftware.htmlunit.html.HtmlEmbed) ScriptableObject(net.sourceforge.htmlunit.corejs.javascript.ScriptableObject) PromptHandler(com.gargoylesoftware.htmlunit.PromptHandler) UrlUtils(com.gargoylesoftware.htmlunit.util.UrlUtils) ArrayList(java.util.ArrayList) JavaScriptException(net.sourceforge.htmlunit.corejs.javascript.JavaScriptException) XmlPage(com.gargoylesoftware.htmlunit.xml.XmlPage) IOException(java.io.IOException) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction) CSS2Properties(com.gargoylesoftware.htmlunit.javascript.host.css.CSS2Properties) JsxClass(com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass) Performance(com.gargoylesoftware.htmlunit.javascript.host.performance.Performance) IE(com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.IE) WebClient(com.gargoylesoftware.htmlunit.WebClient) JS_WINDOW_FRAMES_ACCESSIBLE_BY_ID(com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_WINDOW_FRAMES_ACCESSIBLE_BY_ID) ElementNotFoundException(com.gargoylesoftware.htmlunit.ElementNotFoundException) StyleMedia(com.gargoylesoftware.htmlunit.javascript.host.css.StyleMedia) ScriptResult(com.gargoylesoftware.htmlunit.ScriptResult) HtmlImage(com.gargoylesoftware.htmlunit.html.HtmlImage) URL(java.net.URL) ObjectInputStream(java.io.ObjectInputStream) HtmlTextArea(com.gargoylesoftware.htmlunit.html.HtmlTextArea) HtmlObject(com.gargoylesoftware.htmlunit.html.HtmlObject) HtmlAttributeChangeEvent(com.gargoylesoftware.htmlunit.html.HtmlAttributeChangeEvent) JS_WINDOW_FRAME_BY_ID_RETURNS_WINDOW(com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_WINDOW_FRAME_BY_ID_RETURNS_WINDOW) DataTransfer(com.gargoylesoftware.htmlunit.javascript.host.html.DataTransfer) ScriptException(com.gargoylesoftware.htmlunit.ScriptException) FF_ESR(com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.FF_ESR) Selection(com.gargoylesoftware.htmlunit.javascript.host.dom.Selection) HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) StatusHandler(com.gargoylesoftware.htmlunit.StatusHandler) ConfirmHandler(com.gargoylesoftware.htmlunit.ConfirmHandler) Crypto(com.gargoylesoftware.htmlunit.javascript.host.crypto.Crypto) List(java.util.List) DocumentProxy(com.gargoylesoftware.htmlunit.javascript.host.html.DocumentProxy) ContextFactory(net.sourceforge.htmlunit.corejs.javascript.ContextFactory) Undefined(net.sourceforge.htmlunit.corejs.javascript.Undefined) Function(net.sourceforge.htmlunit.corejs.javascript.Function) Page(com.gargoylesoftware.htmlunit.Page) EventTarget(com.gargoylesoftware.htmlunit.javascript.host.event.EventTarget) HTMLDocument(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument) HtmlUnitScriptable(com.gargoylesoftware.htmlunit.javascript.HtmlUnitScriptable) HashMap(java.util.HashMap) WebWindowNotFoundException(com.gargoylesoftware.htmlunit.WebWindowNotFoundException) HtmlFrame(com.gargoylesoftware.htmlunit.html.HtmlFrame) JS_WINDOW_FORMFIELDS_ACCESSIBLE_BY_NAME(com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_WINDOW_FORMFIELDS_ACCESSIBLE_BY_NAME) TopLevelWindow(com.gargoylesoftware.htmlunit.TopLevelWindow) BrowserVersion(com.gargoylesoftware.htmlunit.BrowserVersion) HtmlSelect(com.gargoylesoftware.htmlunit.html.HtmlSelect) SgmlPage(com.gargoylesoftware.htmlunit.SgmlPage) EcmaError(net.sourceforge.htmlunit.corejs.javascript.EcmaError) Event(com.gargoylesoftware.htmlunit.javascript.host.event.Event) JavaScriptEngine(com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine) Context(net.sourceforge.htmlunit.corejs.javascript.Context) FrameWindow(com.gargoylesoftware.htmlunit.html.FrameWindow) HtmlButton(com.gargoylesoftware.htmlunit.html.HtmlButton) XMLDocument(com.gargoylesoftware.htmlunit.javascript.host.xml.XMLDocument) ScriptRuntime(net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime) MalformedURLException(java.net.MalformedURLException) Type(com.gargoylesoftware.htmlunit.StorageHolder.Type) CHROME(com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.CHROME) PostponedAction(com.gargoylesoftware.htmlunit.javascript.PostponedAction) WebAssert(com.gargoylesoftware.htmlunit.WebAssert) JsxConstructor(com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor) Document(com.gargoylesoftware.htmlunit.javascript.host.dom.Document) HTMLElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement) Log(org.apache.commons.logging.Log) MessageEvent(com.gargoylesoftware.htmlunit.javascript.host.event.MessageEvent) ContextFactory(net.sourceforge.htmlunit.corejs.javascript.ContextFactory) MessageEvent(com.gargoylesoftware.htmlunit.javascript.host.event.MessageEvent) XmlPage(com.gargoylesoftware.htmlunit.xml.XmlPage) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) Page(com.gargoylesoftware.htmlunit.Page) SgmlPage(com.gargoylesoftware.htmlunit.SgmlPage) PostponedAction(com.gargoylesoftware.htmlunit.javascript.PostponedAction) ScriptableObject(net.sourceforge.htmlunit.corejs.javascript.ScriptableObject) HtmlObject(com.gargoylesoftware.htmlunit.html.HtmlObject) URL(java.net.URL) JavaScriptException(net.sourceforge.htmlunit.corejs.javascript.JavaScriptException) IOException(java.io.IOException) ElementNotFoundException(com.gargoylesoftware.htmlunit.ElementNotFoundException) ScriptException(com.gargoylesoftware.htmlunit.ScriptException) WebWindowNotFoundException(com.gargoylesoftware.htmlunit.WebWindowNotFoundException) MalformedURLException(java.net.MalformedURLException) WebWindow(com.gargoylesoftware.htmlunit.WebWindow) JavaScriptEngine(com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Example 40 with JsxFunction

use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.

the class HTMLCollectionFrames method scrollByLines.

/**
 * Scrolls the window content down by the specified number of lines.
 * @param lines the number of lines to scroll down
 */
@JsxFunction({ FF, FF_ESR })
public void scrollByLines(final int lines) {
    final HTMLElement body = document_.getBody();
    if (body != null) {
        body.setScrollTop(body.getScrollTop() + (19 * lines));
        final Event event = new Event(body, Event.TYPE_SCROLL);
        body.fireEvent(event);
    }
}
Also used : HTMLElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement) MouseEvent(com.gargoylesoftware.htmlunit.javascript.host.event.MouseEvent) HtmlAttributeChangeEvent(com.gargoylesoftware.htmlunit.html.HtmlAttributeChangeEvent) Event(com.gargoylesoftware.htmlunit.javascript.host.event.Event) MessageEvent(com.gargoylesoftware.htmlunit.javascript.host.event.MessageEvent) 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