All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gargoylesoftware.htmlunit.javascript.host.EventNode Maven / Gradle / Ivy

There is a newer version: 2.70.0
Show newest version
/*
 * Copyright (c) 2002-2010 Gargoyle Software Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.gargoylesoftware.htmlunit.javascript.host;

import org.apache.commons.lang.StringUtils;

/**
 * A node which supports all of the onXXX event handlers and other event-related functions.
 *
 * Basically contains any event-related features that both elements and the document support.
 *
 * @version $Revision: 5301 $
 * @author Daniel Gredler
 * @author Ahmed Ashour
 */
public class EventNode extends Node {

    /** Serial version UID. */
    private static final long serialVersionUID = 4894810197917509182L;

    /**
     * Sets the onclick event handler for this element.
     * @param handler the onclick event handler for this element
     */
    public void jsxSet_onclick(final Object handler) {
        setEventHandlerProp("onclick", handler);
    }

    /**
     * Returns the onclick event handler for this element.
     * @return the onclick event handler for this element
     */
    public Object jsxGet_onclick() {
        return getEventHandlerProp("onclick");
    }

    /**
     * Sets the ondblclick event handler for this element.
     * @param handler the ondblclick event handler for this element
     */
    public void jsxSet_ondblclick(final Object handler) {
        setEventHandlerProp("ondblclick", handler);
    }

    /**
     * Returns the ondblclick event handler for this element.
     * @return the ondblclick event handler for this element
     */
    public Object jsxGet_ondblclick() {
        return getEventHandlerProp("ondblclick");
    }

    /**
     * Sets the onblur event handler for this element.
     * @param handler the onblur event handler for this element
     */
    public void jsxSet_onblur(final Object handler) {
        setEventHandlerProp("onblur", handler);
    }

    /**
     * Returns the onblur event handler for this element.
     * @return the onblur event handler for this element
     */
    public Object jsxGet_onblur() {
        return getEventHandlerProp("onblur");
    }

    /**
     * Sets the onfocus event handler for this element.
     * @param handler the onfocus event handler for this element
     */
    public void jsxSet_onfocus(final Object handler) {
        setEventHandlerProp("onfocus", handler);
    }

    /**
     * Returns the onfocus event handler for this element.
     * @return the onfocus event handler for this element
     */
    public Object jsxGet_onfocus() {
        return getEventHandlerProp("onfocus");
    }

    /**
     * Sets the onfocusin event handler for this element.
     * @param handler the onfocusin event handler for this element
     */
    public void jsxSet_onfocusin(final Object handler) {
        setEventHandlerProp("onfocusin", handler);
    }

    /**
     * Returns the onfocusin event handler for this element.
     * @return the onfocusin event handler for this element
     */
    public Object jsxGet_onfocusin() {
        return getEventHandlerProp("onfocusin");
    }

    /**
     * Sets the onfocusout event handler for this element.
     * @param handler the onfocusout event handler for this element
     */
    public void jsxSet_onfocusout(final Object handler) {
        setEventHandlerProp("onfocusout", handler);
    }

    /**
     * Returns the onfocusout event handler for this element.
     * @return the onfocusout event handler for this element
     */
    public Object jsxGet_onfocusout() {
        return getEventHandlerProp("onfocusout");
    }

    /**
     * Sets the onkeydown event handler for this element.
     * @param handler the onkeydown event handler for this element
     */
    public void jsxSet_onkeydown(final Object handler) {
        setEventHandlerProp("onkeydown", handler);
    }

    /**
     * Returns the onkeydown event handler for this element.
     * @return the onkeydown event handler for this element
     */
    public Object jsxGet_onkeydown() {
        return getEventHandlerProp("onkeydown");
    }

    /**
     * Sets the onkeypress event handler for this element.
     * @param handler the onkeypress event handler for this element
     */
    public void jsxSet_onkeypress(final Object handler) {
        setEventHandlerProp("onkeypress", handler);
    }

    /**
     * Returns the onkeypress event handler for this element.
     * @return the onkeypress event handler for this element
     */
    public Object jsxGet_onkeypress() {
        return getEventHandlerProp("onkeypress");
    }

    /**
     * Sets the onkeyup event handler for this element.
     * @param handler the onkeyup event handler for this element
     */
    public void jsxSet_onkeyup(final Object handler) {
        setEventHandlerProp("onkeyup", handler);
    }

    /**
     * Returns the onkeyup event handler for this element.
     * @return the onkeyup event handler for this element
     */
    public Object jsxGet_onkeyup() {
        return getEventHandlerProp("onkeyup");
    }

    /**
     * Sets the onmousedown event handler for this element.
     * @param handler the onmousedown event handler for this element
     */
    public void jsxSet_onmousedown(final Object handler) {
        setEventHandlerProp("onmousedown", handler);
    }

    /**
     * Returns the onmousedown event handler for this element.
     * @return the onmousedown event handler for this element
     */
    public Object jsxGet_onmousedown() {
        return getEventHandlerProp("onmousedown");
    }

    /**
     * Sets the onmousemove event handler for this element.
     * @param handler the onmousemove event handler for this element
     */
    public void jsxSet_onmousemove(final Object handler) {
        setEventHandlerProp("onmousemove", handler);
    }

    /**
     * Returns the onmousemove event handler for this element.
     * @return the onmousemove event handler for this element
     */
    public Object jsxGet_onmousemove() {
        return getEventHandlerProp("onmousemove");
    }

    /**
     * Sets the onmouseout event handler for this element.
     * @param handler the onmouseout event handler for this element
     */
    public void jsxSet_onmouseout(final Object handler) {
        setEventHandlerProp("onmouseout", handler);
    }

    /**
     * Returns the onmouseout event handler for this element.
     * @return the onmouseout event handler for this element
     */
    public Object jsxGet_onmouseout() {
        return getEventHandlerProp("onmouseout");
    }

    /**
     * Sets the onmouseover event handler for this element.
     * @param handler the onmouseover event handler for this element
     */
    public void jsxSet_onmouseover(final Object handler) {
        setEventHandlerProp("onmouseover", handler);
    }

    /**
     * Returns the onmouseover event handler for this element.
     * @return the onmouseover event handler for this element
     */
    public Object jsxGet_onmouseover() {
        return getEventHandlerProp("onmouseover");
    }

    /**
     * Sets the onmouseup event handler for this element.
     * @param handler the onmouseup event handler for this element
     */
    public void jsxSet_onmouseup(final Object handler) {
        setEventHandlerProp("onmouseup", handler);
    }

    /**
     * Returns the onmouseup event handler for this element.
     * @return the onmouseup event handler for this element
     */
    public Object jsxGet_onmouseup() {
        return getEventHandlerProp("onmouseup");
    }

    /**
     * Sets the oncontextmenu event handler for this element.
     * @param handler the oncontextmenu event handler for this element
     */
    public void jsxSet_oncontextmenu(final Object handler) {
        setEventHandlerProp("oncontextmenu", handler);
    }

    /**
     * Returns the oncontextmenu event handler for this element.
     * @return the oncontextmenu event handler for this element
     */
    public Object jsxGet_oncontextmenu() {
        return getEventHandlerProp("oncontextmenu");
    }

    /**
     * Sets the onresize event handler for this element.
     * @param handler the onresize event handler for this element
     */
    public void jsxSet_onresize(final Object handler) {
        setEventHandlerProp("onresize", handler);
    }

    /**
     * Returns the onresize event handler for this element.
     * @return the onresize event handler for this element
     */
    public Object jsxGet_onresize() {
        return getEventHandlerProp("onresize");
    }

    /**
     * Sets the onpropertychange event handler for this element.
     * @param handler the onpropertychange event handler for this element
     */
    public void jsxSet_onpropertychange(final Object handler) {
        setEventHandlerProp("onpropertychange", handler);
    }

    /**
     * Returns the onpropertychange event handler for this element.
     * @return the onpropertychange event handler for this element
     */
    public Object jsxGet_onpropertychange() {
        return getEventHandlerProp("onpropertychange");
    }

    /**
     * Sets the onerror event handler for this element.
     * @param handler the onerror event handler for this element
     */
    public void jsxSet_onerror(final Object handler) {
        setEventHandlerProp("onerror", handler);
    }

    /**
     * Returns the onerror event handler for this element.
     * @return the onerror event handler for this element
     */
    public Object jsxGet_onerror() {
        return getEventHandlerProp("onerror");
    }

    /**
     * Fires a specified event on this element (IE only). See the
     * MSDN documentation
     * for more information.
     * @param type specifies the name of the event to fire.
     * @param event specifies the event object from which to obtain event object properties.
     * @return true if the event fired successfully, false if it was canceled
     */
    public boolean jsxFunction_fireEvent(final String type, Event event) {
        if (event == null) {
            event = new MouseEvent();
        }

        // Create the event, whose class will depend on the type specified.
        final String cleanedType = StringUtils.removeStart(type.toLowerCase(), "on");
        if (MouseEvent.isMouseEvent(cleanedType)) {
            event.setPrototype(getPrototype(MouseEvent.class));
        }
        else {
            event.setPrototype(getPrototype(Event.class));
        }
        event.setParentScope(getWindow());

        // These four properties have predefined values, independent of the template.
        event.jsxSet_cancelBubble(false);
        event.jsxSet_returnValue(Boolean.TRUE);
        event.jsxSet_srcElement(this);
        event.setEventType(cleanedType);

        fireEvent(event);
        return ((Boolean) event.jsxGet_returnValue()).booleanValue();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy