2 Copyright (C) 1999,2000,2001 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
40 import gnu
.java
.lang
.CPStringBuilder
;
42 import org
.w3c
.dom
.Node
;
44 import org
.w3c
.dom
.events
.Event
;
45 import org
.w3c
.dom
.events
.EventTarget
;
46 import org
.w3c
.dom
.events
.MutationEvent
;
47 import org
.w3c
.dom
.events
.UIEvent
;
49 import org
.w3c
.dom
.views
.AbstractView
; // used by UIEvent
52 * "Event" implementation. Events are
53 * created (through DocumentEvent interface methods on the document object),
54 * and are sent to any target node in the document.
56 * <p> Applications may define application specific event subclasses, but
57 * should otherwise use the <em>DocumentTraversal</em> interface to acquire
60 * @author David Brownell
68 EventTarget currentNode
;
70 boolean bubbles
; // init
71 boolean cancelable
; // init
74 /** Returns the event's type (name) as initialized */
75 public final String
getType()
81 * Returns event's target; delivery of an event is initiated
82 * by a <em>target.dispatchEvent(event)</em> invocation.
84 public final EventTarget
getTarget()
90 * Returns the target to which events are currently being
91 * delivered. When capturing or bubbling, this will not
92 * be what <em>getTarget</em> returns.
94 public final EventTarget
getCurrentTarget()
100 * Returns CAPTURING_PHASE, AT_TARGET, or BUBBLING;
101 * only meaningful within EventListener.handleEvent
103 public final short getEventPhase()
109 * Returns true if the news of the event bubbles to tree tops
110 * (as specified during initialization).
112 public final boolean getBubbles()
118 * Returns true if the default handling may be canceled
119 * (as specified during initialization).
121 public final boolean getCancelable()
127 * Returns the event's timestamp.
129 public final long getTimeStamp()
138 * Requests the event no longer be captured or bubbled; only
139 * listeners on the event target will see the event, if they
140 * haven't yet been notified.
142 * <p> <em> Avoid using this </em> except for application-specific
143 * events, for which you the protocol explicitly "blesses" the use
144 * of this with some event types. Otherwise, you are likely to break
145 * algorithms which depend on event notification either directly or
146 * through bubbling or capturing. </p>
148 * <p> Note that this method is not final, specifically to enable
149 * enforcing of policies about events always propagating. </p>
151 public void stopPropagation()
157 * Requests that whoever dispatched the event not perform their
158 * default processing when event delivery completes. Initializes
161 public final void preventDefault()
166 /** Initializes basic event state. */
167 public void initEvent(String typeArg
,
168 boolean canBubbleArg
,
169 boolean cancelableArg
)
173 bubbles
= canBubbleArg
;
174 cancelable
= cancelableArg
;
175 timeStamp
= System
.currentTimeMillis();
178 /** Constructs, but does not initialize, an event. */
179 public DomEvent(String type
)
185 * Returns a basic printable description of the event's type,
186 * state, and delivery conditions
188 public String
toString()
190 CPStringBuilder buf
= new CPStringBuilder("[Event ");
194 case CAPTURING_PHASE
:
195 buf
.append(", CAPTURING");
198 buf
.append(", AT TARGET");
201 buf
.append(", BUBBLING");
204 buf
.append(", (inactive)");
207 if (bubbles
&& eventPhase
!= BUBBLING_PHASE
)
209 buf
.append(", bubbles");
213 buf
.append(", can cancel");
215 // were we to provide subclass info, this's where it'd live
217 return buf
.toString();
221 * "MutationEvent" implementation.
223 public static final class DomMutationEvent
225 implements MutationEvent
229 Node relatedNode
; // init
231 private String prevValue
; // init
232 private String newValue
; // init
234 private String attrName
; // init
235 private short attrChange
; // init
237 /** Returns any "related" node provided by this type of event */
238 public final Node
getRelatedNode()
243 /** Returns any "previous value" provided by this type of event */
244 public final String
getPrevValue()
249 /** Returns any "new value" provided by this type of event */
250 public final String
getNewValue()
255 /** For attribute change events, returns the attribute's name */
256 public final String
getAttrName()
261 /** For attribute change events, returns how the attribuet changed */
262 public final short getAttrChange()
267 /** Initializes a mutation event */
268 public final void initMutationEvent(String typeArg
,
269 boolean canBubbleArg
,
270 boolean cancelableArg
,
277 // super.initEvent is inlined here for speed
278 // (mutation events are issued on all DOM changes)
281 bubbles
= canBubbleArg
;
282 cancelable
= cancelableArg
;
283 timeStamp
= System
.currentTimeMillis();
285 relatedNode
= relatedNodeArg
;
286 prevValue
= prevValueArg
;
287 newValue
= newValueArg
;
288 attrName
= attrNameArg
;
289 attrChange
= attrChangeArg
;
292 // clear everything that should be GC-able
299 prevValue
= newValue
= attrName
= null;
302 /** Constructs an uninitialized mutation event. */
303 public DomMutationEvent(String type
)
311 * "UIEvent" implementation.
313 public static class DomUIEvent
318 private AbstractView view
; // init
319 private int detail
; // init
321 /** Constructs an uninitialized User Interface (UI) event */
322 public DomUIEvent (String type
) { super (type
); }
324 public final AbstractView
getView () { return view
; }
325 public final int getDetail () { return detail
; }
327 /** Initializes a UI event */
328 public final void initUIEvent(String typeArg
,
329 boolean canBubbleArg
,
330 boolean cancelableArg
,
331 AbstractView viewArg
,
334 super.initEvent(typeArg
, canBubbleArg
, cancelableArg
);
343 static final class DomMouseEvent extends DomUIEvent
344 implements MouseEvent
346 // another half dozen state variables/accessors