Search in sources :

Example 6 with JsxConstructor

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

the class UIEvent method jsConstructor.

/**
 * JavaScript constructor.
 *
 * @param type the event type
 * @param details the event details (optional)
 */
@JsxConstructor({ CHROME, EDGE, FF, FF_ESR })
@Override
public void jsConstructor(final String type, final ScriptableObject details) {
    super.jsConstructor(type, details);
    view_ = NO_VIEW;
    if (details != null && !Undefined.isUndefined(details)) {
        final Object view = details.get("view", details);
        if (view instanceof Window) {
            view_ = view;
        } else if (view != Scriptable.NOT_FOUND) {
            throw ScriptRuntime.typeError("View must be a window.");
        }
    }
}
Also used : Window(com.gargoylesoftware.htmlunit.javascript.host.Window) ScriptableObject(net.sourceforge.htmlunit.corejs.javascript.ScriptableObject) JsxConstructor(com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor)

Example 7 with JsxConstructor

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

the class HTMLOptionElement method jsConstructor.

/**
 * JavaScript constructor.
 * @param newText the text
 * @param newValue the value
 * @param defaultSelected Whether the option is initially selected
 * @param selected the current selection state of the option
 */
@JsxConstructor({ CHROME, EDGE, FF, FF_ESR })
public void jsConstructor(final Object newText, final String newValue, final boolean defaultSelected, final boolean selected) {
    final SgmlPage page = (SgmlPage) getWindow().getWebWindow().getEnclosedPage();
    AttributesImpl attributes = null;
    if (defaultSelected) {
        attributes = new AttributesImpl();
        attributes.addAttribute(null, "selected", "selected", null, "selected");
    }
    final HtmlOption htmlOption = (HtmlOption) page.getWebClient().getPageCreator().getHtmlParser().getFactory(HtmlOption.TAG_NAME).createElement(page, HtmlOption.TAG_NAME, attributes);
    htmlOption.setSelected(selected);
    setDomNode(htmlOption);
    if (!Undefined.isUndefined(newText)) {
        final String newTextString = Context.toString(newText);
        htmlOption.appendChild(new DomText(page, newTextString));
        htmlOption.setLabelAttribute(newTextString);
    }
    if (!"undefined".equals(newValue)) {
        htmlOption.setValueAttribute(newValue);
    }
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) DomText(com.gargoylesoftware.htmlunit.html.DomText) SgmlPage(com.gargoylesoftware.htmlunit.SgmlPage) HtmlOption(com.gargoylesoftware.htmlunit.html.HtmlOption) JsxConstructor(com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor)

Example 8 with JsxConstructor

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

the class Image method jsConstructor.

/**
 * JavaScript constructor.
 */
@Override
@JsxConstructor
public void jsConstructor() {
    final SgmlPage page = (SgmlPage) getWindow().getWebWindow().getEnclosedPage();
    final DomElement fake = page.getWebClient().getPageCreator().getHtmlParser().getFactory(HtmlImage.TAG_NAME).createElement(page, HtmlImage.TAG_NAME, null);
    setDomNode(fake);
}
Also used : DomElement(com.gargoylesoftware.htmlunit.html.DomElement) SgmlPage(com.gargoylesoftware.htmlunit.SgmlPage) JsxConstructor(com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor)

Example 9 with JsxConstructor

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

the class DateTimeFormat method jsConstructor.

/**
 * JavaScript constructor.
 * @param cx the current context
 * @param args the arguments to the WebSocket constructor
 * @param ctorObj the function object
 * @param inNewExpr Is new or not
 * @return the java object to allow JavaScript to access
 */
@JsxConstructor
public static Scriptable jsConstructor(final Context cx, final Object[] args, final Function ctorObj, final boolean inNewExpr) {
    final String[] locales;
    if (args.length != 0) {
        if (args[0] instanceof NativeArray) {
            final NativeArray array = (NativeArray) args[0];
            locales = new String[(int) array.getLength()];
            for (int i = 0; i < locales.length; i++) {
                locales[i] = Context.toString(array.get(i));
            }
        } else {
            locales = new String[] { Context.toString(args[0]) };
        }
    } else {
        locales = new String[] { "" };
    }
    final Window window = getWindow(ctorObj);
    final DateTimeFormat format = new DateTimeFormat(locales, window.getBrowserVersion());
    format.setParentScope(window);
    format.setPrototype(window.getPrototype(format.getClass()));
    return format;
}
Also used : NativeArray(net.sourceforge.htmlunit.corejs.javascript.NativeArray) Window(com.gargoylesoftware.htmlunit.javascript.host.Window) JsxConstructor(com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor)

Example 10 with JsxConstructor

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

the class PointerEvent method jsConstructor.

/**
 * JavaScript constructor.
 * @param cx the current context
 * @param args the arguments to the WebSocket constructor
 * @param ctorObj the function object
 * @param inNewExpr Is new or not
 * @return the java object to allow JavaScript to access
 */
@JsxConstructor({ CHROME, EDGE, FF, FF_ESR })
public static Scriptable jsConstructor(final Context cx, final Object[] args, final Function ctorObj, final boolean inNewExpr) {
    final PointerEvent event = new PointerEvent();
    if (args.length != 0) {
        event.setType(Context.toString(args[0]));
        event.setBubbles(false);
        event.setCancelable(false);
        event.width_ = 1;
        event.height_ = 1;
    }
    if (args.length > 1) {
        final NativeObject object = (NativeObject) args[1];
        event.setBubbles((boolean) getValue(object, "bubbles", event.isBubbles()));
        event.pointerId_ = (int) getValue(object, "pointerId", event.pointerId_);
        event.width_ = (int) getValue(object, "width", event.width_);
        event.height_ = (int) getValue(object, "height", event.height_);
        event.pressure_ = (double) getValue(object, "pressure", event.pressure_);
        event.tiltX_ = (int) getValue(object, "tiltX", event.tiltX_);
        event.tiltY_ = (int) getValue(object, "tiltY", event.tiltY_);
        event.pointerType_ = (String) getValue(object, "pointerType", event.pointerType_);
        event.isPrimary_ = (boolean) getValue(object, "isPrimary", event.isPrimary_);
    }
    return event;
}
Also used : NativeObject(net.sourceforge.htmlunit.corejs.javascript.NativeObject) JsxConstructor(com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor)

Aggregations

JsxConstructor (com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor)12 ScriptableObject (net.sourceforge.htmlunit.corejs.javascript.ScriptableObject)6 Window (com.gargoylesoftware.htmlunit.javascript.host.Window)3 SgmlPage (com.gargoylesoftware.htmlunit.SgmlPage)2 WebClient (com.gargoylesoftware.htmlunit.WebClient)1 WebWindow (com.gargoylesoftware.htmlunit.WebWindow)1 MSXMLActiveXObjectFactory (com.gargoylesoftware.htmlunit.activex.javascript.msxml.MSXMLActiveXObjectFactory)1 DomElement (com.gargoylesoftware.htmlunit.html.DomElement)1 DomText (com.gargoylesoftware.htmlunit.html.DomText)1 HtmlOption (com.gargoylesoftware.htmlunit.html.HtmlOption)1 HtmlUnitScriptable (com.gargoylesoftware.htmlunit.javascript.HtmlUnitScriptable)1 WindowProxy (com.gargoylesoftware.htmlunit.javascript.host.WindowProxy)1 NativeArray (net.sourceforge.htmlunit.corejs.javascript.NativeArray)1 NativeObject (net.sourceforge.htmlunit.corejs.javascript.NativeObject)1 Scriptable (net.sourceforge.htmlunit.corejs.javascript.Scriptable)1 NativeUint8ClampedArray (net.sourceforge.htmlunit.corejs.javascript.typedarrays.NativeUint8ClampedArray)1 AttributesImpl (org.xml.sax.helpers.AttributesImpl)1