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