1 /*
2  * reserved comment block
3  * DO NOT REMOVE OR ALTER!
4  */
5 /*
6  * Licensed to the Apache Software Foundation (ASF) under one or more
7  * contributor license agreements.  See the NOTICE file distributed with
8  * this work for additional information regarding copyright ownership.
9  * The ASF licenses this file to You under the Apache License, Version 2.0
10  * (the "License"); you may not use this file except in compliance with
11  * the License.  You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21 
22 package com.sun.org.apache.xerces.internal.dom.events;
23 
24 import org.w3c.dom.events.Event;
25 import org.w3c.dom.events.EventTarget;
26 
27 /**
28  * EventImpl is an implementation of the basic "generic" DOM Level 2 Event
29  * object. It may be subclassed by more specialized event sets.
30  * Note that in our implementation, events are re-dispatchable (dispatch
31  * clears the stopPropagation and preventDefault flags before it starts);
32  * I believe that is the DOM's intent but I don't see an explicit statement
33  * to this effect.
34  *
35  * @xerces.internal
36  *
37  */
38 public class EventImpl implements Event
39 {
40     public String type=null;
41     public EventTarget target;
42     public EventTarget currentTarget;
43     public short eventPhase;
44     public boolean initialized=false, bubbles=true, cancelable=false;
45     public boolean stopPropagation=false, preventDefault=false;
46 
47     protected long timeStamp = System.currentTimeMillis();
48 
49     /** The DOM doesn't deal with constructors, so instead we have an
50         initializer call to set most of the read-only fields. The
51         others are set, and reset, by the event subsystem during dispatch.
52         <p>
53         Note that init() -- and the subclass-specific initWhatever() calls --
54         may be reinvoked. At least one initialization is required; repeated
55         initializations overwrite the event with new values of their
56         parameters.
57     */
initEvent(String eventTypeArg, boolean canBubbleArg, boolean cancelableArg)58     public void initEvent(String eventTypeArg, boolean canBubbleArg,
59                         boolean cancelableArg)
60     {
61             type=eventTypeArg;
62             bubbles=canBubbleArg;
63             cancelable=cancelableArg;
64 
65             initialized=true;
66     }
67 
68     /** @return true iff this Event is of a class and type which supports
69         bubbling. In the generic case, this is True.
70         */
getBubbles()71     public boolean getBubbles()
72     {
73         return bubbles;
74     }
75 
76     /** @return true iff this Event is of a class and type which (a) has a
77         Default Behavior in this DOM, and (b)allows cancellation (blocking)
78         of that behavior. In the generic case, this is False.
79         */
getCancelable()80     public boolean getCancelable()
81     {
82         return cancelable;
83     }
84 
85     /** @return the Node (EventTarget) whose EventListeners are currently
86         being processed. During capture and bubble phases, this may not be
87         the target node. */
getCurrentTarget()88     public EventTarget getCurrentTarget()
89     {
90         return currentTarget;
91     }
92 
93     /** @return the current processing phase for this event --
94         CAPTURING_PHASE, AT_TARGET, BUBBLING_PHASE. (There may be
95         an internal DEFAULT_PHASE as well, but the users won't see it.) */
getEventPhase()96     public short getEventPhase()
97     {
98         return eventPhase;
99     }
100 
101     /** @return the EventTarget (Node) to which the event was originally
102         dispatched.
103         */
getTarget()104     public EventTarget getTarget()
105     {
106         return target;
107     }
108 
109     /** @return event name as a string
110     */
getType()111     public String getType()
112     {
113         return type;
114     }
115 
getTimeStamp()116     public long getTimeStamp() {
117         return timeStamp;
118     }
119 
120     /** Causes exit from in-progress event dispatch before the next
121         currentTarget is selected. Replaces the preventBubble() and
122         preventCapture() methods which were present in early drafts;
123         they may be reintroduced in future levels of the DOM. */
stopPropagation()124     public void stopPropagation()
125     {
126         stopPropagation=true;
127     }
128 
129     /** Prevents any default processing built into the target node from
130         occurring.
131       */
preventDefault()132     public void preventDefault()
133     {
134         preventDefault=true;
135     }
136 
137 }
138