use of org.mozilla.javascript.Function in project LoboEvolution by LoboEvolution.
the class HtmlController method onMouseDown.
/**
* <p>onMouseDown.</p>
*
* @return True to propagate further, false if consumed.
* @param node a {@link org.loboevolution.html.dom.nodeimpl.ModelNode} object.
* @param event a {@link java.awt.event.MouseEvent} object.
* @param x a int.
* @param y a int.
*/
public boolean onMouseDown(ModelNode node, MouseEvent event, int x, int y) {
boolean pass = true;
if (node instanceof HTMLElementImpl) {
final HTMLElementImpl uiElement = (HTMLElementImpl) node;
final Function f = uiElement.getOnmousedown();
if (f != null) {
final MouseEventImpl evt = new MouseEventImpl();
evt.initMouseEvent("mousedown", false, false, null, 0, 0, 0, x, y, true, true, true, true, (short) 0, null);
evt.setIe(event);
pass = Executor.executeFunction(uiElement, f, evt, new Object[0]);
}
}
if (node instanceof HTMLLinkElementImpl) {
((HTMLLinkElementImpl) node).getCurrentStyle().setOverlayColor("#9090FF80");
return false;
}
if (!pass) {
return false;
}
final ModelNode parent = node.getParentModelNode();
if (parent == null) {
return true;
}
return onMouseDown(parent, event, 0, 0);
}
use of org.mozilla.javascript.Function in project LoboEvolution by LoboEvolution.
the class HtmlController method onMouseOver.
/**
* <p>onMouseOver.</p>
*
* @param renderable a {@link org.loboevolution.html.renderer.BaseBoundableRenderable} object.
* @param nodeStart a {@link org.loboevolution.html.dom.nodeimpl.ModelNode} object.
* @param event a {@link java.awt.event.MouseEvent} object.
* @param x a int.
* @param y a int.
* @param limit a {@link org.loboevolution.html.dom.nodeimpl.ModelNode} object.
*/
public void onMouseOver(final BaseBoundableRenderable renderable, final ModelNode nodeStart, final MouseEvent event, final int x, final int y, final ModelNode limit) {
ModelNode node = nodeStart;
while (node != null) {
if (node == limit) {
break;
}
if (node instanceof HTMLElementImpl) {
final HTMLElementImpl uiElement = (HTMLElementImpl) node;
uiElement.setMouseOver(true);
final Function f = uiElement.getOnmouseover();
if (f != null) {
final MouseEventImpl evt = new MouseEventImpl();
evt.initMouseEvent("mouseover", false, false, null, 0, 0, 0, x, y, true, true, true, true, (short) 0, null);
evt.setIe(event);
Executor.executeFunction(uiElement, f, evt, new Object[0]);
}
final HtmlRendererContext rcontext = uiElement.getHtmlRendererContext();
if (rcontext != null) {
rcontext.onMouseOver(uiElement, event);
}
}
node = node.getParentModelNode();
}
setMouseOnMouseOver(renderable, nodeStart, limit);
}
use of org.mozilla.javascript.Function in project LoboEvolution by LoboEvolution.
the class JavaObjectWrapper method get.
/*
* (non-Javadoc)
*
* @see org.mozilla.javascript.ScriptableObject#get(java.lang.String,
* org.mozilla.javascript.Scriptable)
*/
/**
* {@inheritDoc}
*/
@Override
public Object get(String name, Scriptable start) {
PropertyInfo pinfo = this.classWrapper.getProperty(name);
if (pinfo != null) {
Method getter = pinfo.getGetter();
if (getter == null) {
throw new EvaluatorException("Property '" + name + "' is not readable");
}
try {
// Cannot retain delegate with a strong reference.
Object javaObject = this.getJavaObject();
if (javaObject == null) {
throw new IllegalStateException("Java object (class=" + this.classWrapper + ") is null.");
}
Object val = getter.invoke(javaObject, (Object[]) null);
return JavaScript.getInstance().getJavascriptObject(val, start.getParentScope());
} catch (Exception err) {
logger.log(Level.SEVERE, err.getMessage(), err);
return new Object();
}
} else {
Function f = this.classWrapper.getFunction(name);
if (f != null) {
return f;
} else {
// Should check properties set in context
// first. Consider element IDs should not
// override Window variables set by user.
Object result = super.get(name, start);
if (result != Scriptable.NOT_FOUND) {
return result;
}
PropertyInfo ni = this.classWrapper.getNameIndexer();
if (ni != null) {
Method getter = ni.getGetter();
if (getter != null) {
// Cannot retain delegate with a strong reference.
Object javaObject = this.getJavaObject();
if (javaObject == null) {
throw new IllegalStateException("Java object (class=" + this.classWrapper + ") is null.");
}
try {
Object val = getter.invoke(javaObject, name);
if (val == null) {
// There might not be an indexer setter.
return super.get(name, start);
} else {
return JavaScript.getInstance().getJavascriptObject(val, start.getParentScope());
}
} catch (Exception err) {
logger.log(Level.SEVERE, err.getMessage(), err);
}
}
}
return Scriptable.NOT_FOUND;
}
}
}
use of org.mozilla.javascript.Function in project LoboEvolution by LoboEvolution.
the class JavaScript method defineElementClass.
public void defineElementClass(Scriptable scope, final Document document, final String jsClassName, final String elementName, Class<?> javaClass) {
JavaInstantiator ji = () -> {
Document d = document;
if (d == null) {
throw new IllegalStateException("Document not set in current context.");
}
return d.createElement(elementName);
};
JavaClassWrapper classWrapper = JavaClassWrapperFactory.getInstance().getClassWrapper(javaClass);
Function constructorFunction = new JavaConstructorObject(jsClassName, classWrapper, ji);
ScriptableObject.defineProperty(scope, jsClassName, constructorFunction, ScriptableObject.READONLY);
}
use of org.mozilla.javascript.Function in project servoy-client by Servoy.
the class MapSerializer method convertToMap.
public static Map<String, Object> convertToMap(Object jsobj) {
Map<String, Object> retval = new HashMap<String, Object>();
if (jsobj == null || jsobj == Undefined.instance || jsobj instanceof IFoundSet || jsobj instanceof IRecord || !(jsobj instanceof NativeObject)) {
return retval;
}
IdScriptableObject no = (IdScriptableObject) jsobj;
Object[] noIDs = no.getIds();
String propertyKey;
Object propertyValue;
for (Object element : noIDs) {
// id can be Integer or String
if (element instanceof Integer) {
propertyKey = ((Integer) element).toString();
propertyValue = no.get(((Integer) element).intValue(), no);
} else if (element instanceof String) {
propertyKey = (String) element;
propertyValue = no.get((String) element, no);
} else {
// should not happen
continue;
}
if (// allow but ignore functions nested in objects
propertyValue instanceof Function) {
continue;
}
if (propertyValue instanceof NativeObject) {
propertyValue = convertToMap(propertyValue);
}
if (propertyValue instanceof Wrapper) {
propertyValue = ((Wrapper) propertyValue).unwrap();
}
retval.put(propertyKey, propertyValue);
}
return retval;
}
Aggregations