Search in sources :

Example 1 with MouseEventImpl

use of org.loboevolution.html.js.events.MouseEventImpl in project LoboEvolution by LoboEvolution.

the class WindowImpl method initWindowScope.

private void initWindowScope(final Document doc) {
    final Scriptable ws = this.getWindowScope();
    final JavaScript js = JavaScript.getInstance();
    JavaInstantiator jiXhttp = () -> {
        HTMLDocumentImpl hd = (HTMLDocumentImpl) doc;
        return new XMLHttpRequest(getUaContext(), hd.getDocumentURL(), ws);
    };
    JavaInstantiator jidomp = () -> new DOMParserImpl(document);
    js.defineJsObject(ws, "XMLHttpRequest", XMLHttpRequest.class, jiXhttp);
    js.defineJsObject(ws, "DOMParser", DOMParserImpl.class, jidomp);
    js.defineJsObject(ws, "XMLSerializer", XMLSerializerImpl.class, XMLSerializerImpl::new);
    js.defineJsObject(ws, "XPathResult", XPathResultImpl.class, XPathResultImpl::new);
    js.defineJsObject(ws, "MouseEvent", MouseEventImpl.class, MouseEventImpl::new);
    js.defineJsObject(ws, "UIEvent", UIEventImpl.class, MouseEventImpl::new);
    js.defineJsObject(ws, "Element", Element.class, MouseEventImpl::new);
    js.defineJsObject(ws, "Event", EventImpl.class, EventImpl::new);
    js.defineJsObject(ws, "Text", TextImpl.class, TextImpl::new);
    js.defineJsObject(ws, "Storage", LocalStorage.class, LocalStorage::new);
    js.defineElementClass(ws, doc, "Comment", "comment", CommentImpl.class);
    js.defineElementClass(ws, doc, "Image", "img", HTMLImageElementImpl.class);
    js.defineElementClass(ws, doc, "Script", "script", HTMLScriptElementImpl.class);
    js.defineElementClass(ws, doc, "IFrame", "iframe", HTMLIFrameElementImpl.class);
    js.defineElementClass(ws, doc, "Option", "option", HTMLOptionElementImpl.class);
    js.defineElementClass(ws, doc, "Select", "select", HTMLSelectElementImpl.class);
    js.defineElementClass(ws, doc, "Console", "console", ConsoleImpl.class);
    js.defineElementClass(ws, doc, "HTMLDivElement", "div", HTMLDivElementImpl.class);
    js.defineElementClass(ws, doc, "HTMLElement", "html", HTMLElementImpl.class);
    js.defineElementClass(ws, doc, "HTMLDocument", "document", HTMLDocumentImpl.class);
}
Also used : JavaInstantiator(org.loboevolution.js.JavaInstantiator) LocalStorage(org.loboevolution.html.js.storage.LocalStorage) XPathResultImpl(org.loboevolution.html.dom.xpath.XPathResultImpl) EventImpl(org.loboevolution.html.js.events.EventImpl) MouseEventImpl(org.loboevolution.html.js.events.MouseEventImpl) UIEventImpl(org.loboevolution.html.js.events.UIEventImpl) JavaScript(org.loboevolution.js.JavaScript) XMLHttpRequest(org.loboevolution.html.js.xml.XMLHttpRequest) XMLSerializerImpl(org.loboevolution.html.js.xml.XMLSerializerImpl) Scriptable(org.mozilla.javascript.Scriptable) MouseEventImpl(org.loboevolution.html.js.events.MouseEventImpl) TextImpl(org.loboevolution.html.dom.nodeimpl.TextImpl)

Example 2 with MouseEventImpl

use of org.loboevolution.html.js.events.MouseEventImpl 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);
}
Also used : HtmlRendererContext(org.loboevolution.http.HtmlRendererContext) Function(org.mozilla.javascript.Function) ModelNode(org.loboevolution.html.dom.nodeimpl.ModelNode) MouseEventImpl(org.loboevolution.html.js.events.MouseEventImpl)

Example 3 with MouseEventImpl

use of org.loboevolution.html.js.events.MouseEventImpl in project LoboEvolution by LoboEvolution.

the class HtmlController method onDoubleClick.

/**
 * <p>onDoubleClick.</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 onDoubleClick(ModelNode node, MouseEvent event, int x, int y) {
    if (logger.isLoggable(Level.INFO)) {
        logger.info("onDoubleClick(): node=" + node + ",class=" + node.getClass().getName());
    }
    if (node instanceof HTMLElementImpl) {
        final HTMLElementImpl uiElement = (HTMLElementImpl) node;
        final Function f = uiElement.getOndblclick();
        if (f != null) {
            final MouseEventImpl evt = new MouseEventImpl();
            evt.initMouseEvent("dblclick", false, false, null, 0, 0, 0, x, y, true, true, true, true, (short) 0, null);
            evt.setIe(event);
            if (!Executor.executeFunction(uiElement, f, evt, new Object[0])) {
                return false;
            }
        }
        final HtmlRendererContext rcontext = uiElement.getHtmlRendererContext();
        if (rcontext != null) {
            if (!rcontext.onDoubleClick(uiElement, event)) {
                return false;
            }
        }
    }
    final ModelNode parent = node.getParentModelNode();
    if (parent == null) {
        return true;
    }
    return onDoubleClick(parent, event, 0, 0);
}
Also used : HtmlRendererContext(org.loboevolution.http.HtmlRendererContext) Function(org.mozilla.javascript.Function) ModelNode(org.loboevolution.html.dom.nodeimpl.ModelNode) MouseEventImpl(org.loboevolution.html.js.events.MouseEventImpl)

Example 4 with MouseEventImpl

use of org.loboevolution.html.js.events.MouseEventImpl 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);
}
Also used : Function(org.mozilla.javascript.Function) ModelNode(org.loboevolution.html.dom.nodeimpl.ModelNode) MouseEventImpl(org.loboevolution.html.js.events.MouseEventImpl)

Example 5 with MouseEventImpl

use of org.loboevolution.html.js.events.MouseEventImpl in project LoboEvolution by LoboEvolution.

the class HtmlController method onMouseOver.

/**
 * <p>onMouseOver.</p>
 *
 * @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.
 * @param limit a {@link org.loboevolution.html.dom.nodeimpl.ModelNode} object.
 */
public void onMouseOver(ModelNode node, MouseEvent event, int x, int y, ModelNode limit) {
    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();
    }
}
Also used : HtmlRendererContext(org.loboevolution.http.HtmlRendererContext) Function(org.mozilla.javascript.Function) MouseEventImpl(org.loboevolution.html.js.events.MouseEventImpl)

Aggregations

MouseEventImpl (org.loboevolution.html.js.events.MouseEventImpl)11 Function (org.mozilla.javascript.Function)10 ModelNode (org.loboevolution.html.dom.nodeimpl.ModelNode)6 HtmlRendererContext (org.loboevolution.http.HtmlRendererContext)6 TextImpl (org.loboevolution.html.dom.nodeimpl.TextImpl)1 XPathResultImpl (org.loboevolution.html.dom.xpath.XPathResultImpl)1 EventImpl (org.loboevolution.html.js.events.EventImpl)1 UIEventImpl (org.loboevolution.html.js.events.UIEventImpl)1 LocalStorage (org.loboevolution.html.js.storage.LocalStorage)1 XMLHttpRequest (org.loboevolution.html.js.xml.XMLHttpRequest)1 XMLSerializerImpl (org.loboevolution.html.js.xml.XMLSerializerImpl)1 JavaInstantiator (org.loboevolution.js.JavaInstantiator)1 JavaScript (org.loboevolution.js.JavaScript)1 Scriptable (org.mozilla.javascript.Scriptable)1