1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Xerces" and "Apache Software Foundation" must
  28. * not be used to endorse or promote products derived from this
  29. * software without prior written permission. For written
  30. * permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * nor may "Apache" appear in their name, without prior written
  34. * permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation and was
  52. * originally based on software copyright (c) 1999, International
  53. * Business Machines, Inc., http://www.apache.org. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package com.sun.org.apache.xerces.internal.dom.events;
  58. import org.w3c.dom.events.Event;
  59. import org.w3c.dom.events.EventTarget;
  60. /** EventImpl is an implementation of the basic "generic" DOM Level 2 Event
  61. object. It may be subclassed by more specialized event sets.
  62. Note that in our implementation, events are re-dispatchable (dispatch
  63. clears the stopPropagation and preventDefault flags before it starts);
  64. I believe that is the DOM's intent but I don't see an explicit statement
  65. to this effect.
  66. */
  67. /**
  68. * @version $Id: EventImpl.java,v 1.8 2003/05/08 19:52:41 elena Exp $
  69. */
  70. public class EventImpl implements Event
  71. {
  72. public String type=null;
  73. public EventTarget target;
  74. public EventTarget currentTarget;
  75. public short eventPhase;
  76. public boolean initialized=false, bubbles=true, cancelable=false;
  77. public boolean stopPropagation=false, preventDefault=false;
  78. protected long timeStamp = System.currentTimeMillis();
  79. /** The DOM doesn't deal with constructors, so instead we have an
  80. initializer call to set most of the read-only fields. The
  81. others are set, and reset, by the event subsystem during dispatch.
  82. <p>
  83. Note that init() -- and the subclass-specific initWhatever() calls --
  84. may be reinvoked. At least one initialization is required; repeated
  85. initializations overwrite the event with new values of their
  86. parameters.
  87. */
  88. public void initEvent(String eventTypeArg, boolean canBubbleArg,
  89. boolean cancelableArg)
  90. {
  91. type=eventTypeArg;
  92. bubbles=canBubbleArg;
  93. cancelable=cancelableArg;
  94. initialized=true;
  95. }
  96. /** @return true iff this Event is of a class and type which supports
  97. bubbling. In the generic case, this is True.
  98. */
  99. public boolean getBubbles()
  100. {
  101. return bubbles;
  102. }
  103. /** @return true iff this Event is of a class and type which (a) has a
  104. Default Behavior in this DOM, and (b)allows cancellation (blocking)
  105. of that behavior. In the generic case, this is False.
  106. */
  107. public boolean getCancelable()
  108. {
  109. return cancelable;
  110. }
  111. /** @return the Node (EventTarget) whose EventListeners are currently
  112. being processed. During capture and bubble phases, this may not be
  113. the target node. */
  114. public EventTarget getCurrentTarget()
  115. {
  116. return currentTarget;
  117. }
  118. /** @return the current processing phase for this event --
  119. CAPTURING_PHASE, AT_TARGET, BUBBLING_PHASE. (There may be
  120. an internal DEFAULT_PHASE as well, but the users won't see it.) */
  121. public short getEventPhase()
  122. {
  123. return eventPhase;
  124. }
  125. /** @return the EventTarget (Node) to which the event was originally
  126. dispatched.
  127. */
  128. public EventTarget getTarget()
  129. {
  130. return target;
  131. }
  132. /** @return event name as a string
  133. */
  134. public String getType()
  135. {
  136. return type;
  137. }
  138. public long getTimeStamp() {
  139. return timeStamp;
  140. }
  141. /** Causes exit from in-progress event dispatch before the next
  142. currentTarget is selected. Replaces the preventBubble() and
  143. preventCapture() methods which were present in early drafts;
  144. they may be reintroduced in future levels of the DOM. */
  145. public void stopPropagation()
  146. {
  147. stopPropagation=true;
  148. }
  149. /** Prevents any default processing built into the target node from
  150. occurring.
  151. */
  152. public void preventDefault()
  153. {
  154. preventDefault=true;
  155. }
  156. }