Event.java revision f4ce5c4028bf4001cd718df83d5641913ca9c928
1/*
2 * Copyright (c) 2000 World Wide Web Consortium,
3 * (Massachusetts Institute of Technology, Institut National de
4 * Recherche en Informatique et en Automatique, Keio University). All
5 * Rights Reserved. This program is distributed under the W3C's Software
6 * Intellectual Property License. This program is distributed in the
7 * hope that it will be useful, but WITHOUT ANY WARRANTY; without even
8 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9 * PURPOSE.
10 * See W3C License http://www.w3.org/Consortium/Legal/ for more details.
11 */
12
13package org.w3c.dom.events;
14
15/**
16 * The <code>Event</code> interface is used to provide contextual information
17 * about an event to the handler processing the event. An object which
18 * implements the <code>Event</code> interface is generally passed as the
19 * first parameter to an event handler. More specific context information is
20 * passed to event handlers by deriving additional interfaces from
21 * <code>Event</code> which contain information directly relating to the
22 * type of event they accompany. These derived interfaces are also
23 * implemented by the object passed to the event listener.
24 * <p>See also the <a href='http://www.w3.org/TR/2000/REC-DOM-Level-2-Events-20001113'>Document Object Model (DOM) Level 2 Events Specification</a>.
25 * @since DOM Level 2
26 */
27public interface Event {
28    // PhaseType
29    /**
30     * The current event phase is the capturing phase.
31     */
32    public static final short CAPTURING_PHASE           = 1;
33    /**
34     * The event is currently being evaluated at the target
35     * <code>EventTarget</code>.
36     */
37    public static final short AT_TARGET                 = 2;
38    /**
39     * The current event phase is the bubbling phase.
40     */
41    public static final short BUBBLING_PHASE            = 3;
42
43    /**
44     * The name of the event (case-insensitive). The name must be an XML name.
45     */
46    public String getType();
47
48    /**
49     * Used to indicate the <code>EventTarget</code> to which the event was
50     * originally dispatched.
51     */
52    public EventTarget getTarget();
53
54    /**
55     * Used to indicate the <code>EventTarget</code> whose
56     * <code>EventListeners</code> are currently being processed. This is
57     * particularly useful during capturing and bubbling.
58     */
59    public EventTarget getCurrentTarget();
60
61    /**
62     * Used to indicate which phase of event flow is currently being
63     * evaluated.
64     */
65    public short getEventPhase();
66
67    /**
68     * Used to indicate whether or not an event is a bubbling event. If the
69     * event can bubble the value is true, else the value is false.
70     */
71    public boolean getBubbles();
72
73    /**
74     * Used to indicate whether or not an event can have its default action
75     * prevented. If the default action can be prevented the value is true,
76     * else the value is false.
77     */
78    public boolean getCancelable();
79
80    /**
81     *  Used to specify the time (in milliseconds relative to the epoch) at
82     * which the event was created. Due to the fact that some systems may
83     * not provide this information the value of <code>timeStamp</code> may
84     * be not available for all events. When not available, a value of 0
85     * will be returned. Examples of epoch time are the time of the system
86     * start or 0:0:0 UTC 1st January 1970.
87     */
88    public long getTimeStamp();
89
90    /**
91     * The <code>stopPropagation</code> method is used prevent further
92     * propagation of an event during event flow. If this method is called
93     * by any <code>EventListener</code> the event will cease propagating
94     * through the tree. The event will complete dispatch to all listeners
95     * on the current <code>EventTarget</code> before event flow stops. This
96     * method may be used during any stage of event flow.
97     */
98    public void stopPropagation();
99
100    /**
101     * If an event is cancelable, the <code>preventDefault</code> method is
102     * used to signify that the event is to be canceled, meaning any default
103     * action normally taken by the implementation as a result of the event
104     * will not occur. If, during any stage of event flow, the
105     * <code>preventDefault</code> method is called the event is canceled.
106     * Any default action associated with the event will not occur. Calling
107     * this method for a non-cancelable event has no effect. Once
108     * <code>preventDefault</code> has been called it will remain in effect
109     * throughout the remainder of the event's propagation. This method may
110     * be used during any stage of event flow.
111     */
112    public void preventDefault();
113
114    /**
115     * The <code>initEvent</code> method is used to initialize the value of an
116     * <code>Event</code> created through the <code>DocumentEvent</code>
117     * interface. This method may only be called before the
118     * <code>Event</code> has been dispatched via the
119     * <code>dispatchEvent</code> method, though it may be called multiple
120     * times during that phase if necessary. If called multiple times the
121     * final invocation takes precedence. If called from a subclass of
122     * <code>Event</code> interface only the values specified in the
123     * <code>initEvent</code> method are modified, all other attributes are
124     * left unchanged.
125     * @param eventTypeArg Specifies the event type. This type may be any
126     *   event type currently defined in this specification or a new event
127     *   type.. The string must be an XML name. Any new event type must not
128     *   begin with any upper, lower, or mixed case version of the string
129     *   "DOM". This prefix is reserved for future DOM event sets. It is
130     *   also strongly recommended that third parties adding their own
131     *   events use their own prefix to avoid confusion and lessen the
132     *   probability of conflicts with other new events.
133     * @param canBubbleArg Specifies whether or not the event can bubble.
134     * @param cancelableArg Specifies whether or not the event's default
135     *   action can be prevented.
136     */
137    public void initEvent(String eventTypeArg,
138                          boolean canBubbleArg,
139                          boolean cancelableArg);
140
141}
142