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.");
}
}
}
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);
}
}
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);
}
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;
}
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;
}
Aggregations