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