WebCore/dom/Event.h
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 /*
       
     2  * Copyright (C) 2001 Peter Kelly (pmk@post.com)
       
     3  * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de)
       
     4  * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
       
     5  * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
       
     6  *
       
     7  * This library is free software; you can redistribute it and/or
       
     8  * modify it under the terms of the GNU Library General Public
       
     9  * License as published by the Free Software Foundation; either
       
    10  * version 2 of the License, or (at your option) any later version.
       
    11  *
       
    12  * This library is distributed in the hope that it will be useful,
       
    13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    15  * Library General Public License for more details.
       
    16  *
       
    17  * You should have received a copy of the GNU Library General Public License
       
    18  * along with this library; see the file COPYING.LIB.  If not, write to
       
    19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
       
    20  * Boston, MA 02110-1301, USA.
       
    21  *
       
    22  */
       
    23 
       
    24 #ifndef Event_h
       
    25 #define Event_h
       
    26 
       
    27 #include "AtomicString.h"
       
    28 #include "EventTarget.h"
       
    29 #include <wtf/RefCounted.h>
       
    30 
       
    31 namespace WebCore {
       
    32 
       
    33     class Clipboard;
       
    34 
       
    35     // FIXME: this should probably defined elsewhere.
       
    36     typedef unsigned long long DOMTimeStamp;
       
    37 
       
    38     class Event : public RefCounted<Event> {
       
    39     public:
       
    40         enum PhaseType { 
       
    41             CAPTURING_PHASE     = 1, 
       
    42             AT_TARGET           = 2,
       
    43             BUBBLING_PHASE      = 3 
       
    44         };
       
    45 
       
    46         enum EventType {
       
    47             MOUSEDOWN           = 1,
       
    48             MOUSEUP             = 2,
       
    49             MOUSEOVER           = 4,
       
    50             MOUSEOUT            = 8,
       
    51             MOUSEMOVE           = 16,
       
    52             MOUSEDRAG           = 32,
       
    53             CLICK               = 64,
       
    54             DBLCLICK            = 128,
       
    55             KEYDOWN             = 256,
       
    56             KEYUP               = 512,
       
    57             KEYPRESS            = 1024,
       
    58             DRAGDROP            = 2048,
       
    59             FOCUS               = 4096,
       
    60             BLUR                = 8192,
       
    61             SELECT              = 16384,
       
    62             CHANGE              = 32768
       
    63         };
       
    64 
       
    65         static PassRefPtr<Event> create()
       
    66         {
       
    67             return adoptRef(new Event);
       
    68         }
       
    69         static PassRefPtr<Event> create(const AtomicString& type, bool canBubble, bool cancelable)
       
    70         {
       
    71             return adoptRef(new Event(type, canBubble, cancelable));
       
    72         }
       
    73         virtual ~Event();
       
    74 
       
    75         void initEvent(const AtomicString& type, bool canBubble, bool cancelable);
       
    76 
       
    77         const AtomicString& type() const { return m_type; }
       
    78         
       
    79         const AtomicString& aliasedType() const;
       
    80         bool hasAliasedType() const;
       
    81 
       
    82         EventTarget* target() const { return m_target.get(); }
       
    83         void setTarget(PassRefPtr<EventTarget>);
       
    84 
       
    85         EventTarget* currentTarget() const { return m_currentTarget; }
       
    86         void setCurrentTarget(EventTarget* currentTarget) { m_currentTarget = currentTarget; }
       
    87 
       
    88         unsigned short eventPhase() const { return m_eventPhase; }
       
    89         void setEventPhase(unsigned short eventPhase) { m_eventPhase = eventPhase; }
       
    90 
       
    91         bool bubbles() const { return m_canBubble; }
       
    92         bool cancelable() const { return m_cancelable; }
       
    93         DOMTimeStamp timeStamp() const { return m_createTime; }
       
    94 
       
    95         void stopPropagation() { m_propagationStopped = true; }
       
    96         void stopImmediatePropagation() { m_immediatePropagationStopped = true; }
       
    97         
       
    98         // IE Extensions
       
    99         EventTarget* srcElement() const { return target(); } // MSIE extension - "the object that fired the event"
       
   100 
       
   101         bool returnValue() const { return !defaultPrevented(); }
       
   102         void setReturnValue(bool returnValue) { setDefaultPrevented(!returnValue); }
       
   103 
       
   104         Clipboard* clipboardData() const { return isClipboardEvent() ? clipboard() : 0; }
       
   105 
       
   106         virtual bool isCustomEvent() const;
       
   107         virtual bool isUIEvent() const;
       
   108         virtual bool isMouseEvent() const;
       
   109         virtual bool isMutationEvent() const;
       
   110         virtual bool isKeyboardEvent() const;
       
   111         virtual bool isTextEvent() const;
       
   112         virtual bool isCompositionEvent() const;
       
   113         virtual bool isDragEvent() const; // a subset of mouse events
       
   114         virtual bool isClipboardEvent() const;
       
   115         virtual bool isMessageEvent() const;
       
   116         virtual bool isWheelEvent() const;
       
   117         virtual bool isBeforeTextInsertedEvent() const;
       
   118         virtual bool isOverflowEvent() const;
       
   119         virtual bool isPageTransitionEvent() const;
       
   120         virtual bool isPopStateEvent() const;
       
   121         virtual bool isProgressEvent() const;
       
   122         virtual bool isXMLHttpRequestProgressEvent() const;
       
   123         virtual bool isWebKitAnimationEvent() const;
       
   124         virtual bool isWebKitTransitionEvent() const;
       
   125         virtual bool isBeforeLoadEvent() const;
       
   126 #if ENABLE(SVG)
       
   127         virtual bool isSVGZoomEvent() const;
       
   128 #endif
       
   129 #if ENABLE(DOM_STORAGE)
       
   130         virtual bool isStorageEvent() const;
       
   131 #endif
       
   132 #if ENABLE(INDEXED_DATABASE)
       
   133         virtual bool isIDBErrorEvent() const;
       
   134         virtual bool isIDBSuccessEvent() const;
       
   135 #endif
       
   136 #if ENABLE(WORKERS)
       
   137         virtual bool isErrorEvent() const;
       
   138 #endif
       
   139 #if ENABLE(TOUCH_EVENTS)
       
   140         virtual bool isTouchEvent() const;
       
   141 #endif
       
   142 #if ENABLE(DEVICE_ORIENTATION)
       
   143         virtual bool isDeviceOrientationEvent() const;
       
   144 #endif
       
   145 #if ENABLE(TRANSFORMACTION_EVENTS)
       
   146         virtual bool isTransformActionEvent() const;
       
   147 #endif
       
   148         bool fromUserGesture();
       
   149         
       
   150         bool propagationStopped() const { return m_propagationStopped || m_immediatePropagationStopped; }
       
   151         bool immediatePropagationStopped() const { return m_immediatePropagationStopped; }
       
   152 
       
   153         bool defaultPrevented() const { return m_defaultPrevented; }
       
   154         void preventDefault() { if (m_cancelable) m_defaultPrevented = true; }
       
   155         void setDefaultPrevented(bool defaultPrevented) { m_defaultPrevented = defaultPrevented; }
       
   156 
       
   157         bool defaultHandled() const { return m_defaultHandled; }
       
   158         void setDefaultHandled() { m_defaultHandled = true; }
       
   159 
       
   160         bool cancelBubble() const { return m_cancelBubble; }
       
   161         void setCancelBubble(bool cancel) { m_cancelBubble = cancel; }
       
   162 
       
   163         Event* underlyingEvent() const { return m_underlyingEvent.get(); }
       
   164         void setUnderlyingEvent(PassRefPtr<Event>);
       
   165 
       
   166         virtual bool storesResultAsString() const;
       
   167         virtual void storeResult(const String&);
       
   168 
       
   169         virtual Clipboard* clipboard() const { return 0; }
       
   170 
       
   171     protected:
       
   172         Event();
       
   173         Event(const AtomicString& type, bool canBubble, bool cancelable);
       
   174 
       
   175         virtual void receivedTarget();
       
   176         bool dispatched() const { return m_target; }
       
   177 
       
   178     private:
       
   179         AtomicString m_type;
       
   180         bool m_canBubble;
       
   181         bool m_cancelable;
       
   182 
       
   183         bool m_propagationStopped;
       
   184         bool m_immediatePropagationStopped;
       
   185         bool m_defaultPrevented;
       
   186         bool m_defaultHandled;
       
   187         bool m_cancelBubble;
       
   188 
       
   189         unsigned short m_eventPhase;
       
   190         EventTarget* m_currentTarget;
       
   191         RefPtr<EventTarget> m_target;
       
   192         DOMTimeStamp m_createTime;
       
   193 
       
   194         RefPtr<Event> m_underlyingEvent;
       
   195     };
       
   196 
       
   197 } // namespace WebCore
       
   198 
       
   199 #endif // Event_h