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 create()65 static PassRefPtr<Event> create() 66 { 67 return adoptRef(new Event); 68 } create(const AtomicString & type,bool canBubble,bool cancelable)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 type()77 const AtomicString& type() const { return m_type; } 78 target()79 EventTarget* target() const { return m_target.get(); } 80 void setTarget(PassRefPtr<EventTarget>); 81 currentTarget()82 EventTarget* currentTarget() const { return m_currentTarget; } setCurrentTarget(EventTarget * currentTarget)83 void setCurrentTarget(EventTarget* currentTarget) { m_currentTarget = currentTarget; } 84 eventPhase()85 unsigned short eventPhase() const { return m_eventPhase; } setEventPhase(unsigned short eventPhase)86 void setEventPhase(unsigned short eventPhase) { m_eventPhase = eventPhase; } 87 bubbles()88 bool bubbles() const { return m_canBubble; } cancelable()89 bool cancelable() const { return m_cancelable; } timeStamp()90 DOMTimeStamp timeStamp() const { return m_createTime; } stopPropagation()91 void stopPropagation() { m_propagationStopped = true; } 92 93 // IE Extensions srcElement()94 EventTarget* srcElement() const { return target(); } // MSIE extension - "the object that fired the event" 95 returnValue()96 bool returnValue() const { return !defaultPrevented(); } setReturnValue(bool returnValue)97 void setReturnValue(bool returnValue) { setDefaultPrevented(!returnValue); } 98 clipboardData()99 Clipboard* clipboardData() const { return isClipboardEvent() ? clipboard() : 0; } 100 101 virtual bool isUIEvent() const; 102 virtual bool isMouseEvent() const; 103 virtual bool isMutationEvent() const; 104 virtual bool isKeyboardEvent() const; 105 virtual bool isTextEvent() const; 106 virtual bool isDragEvent() const; // a subset of mouse events 107 virtual bool isClipboardEvent() const; 108 virtual bool isMessageEvent() const; 109 virtual bool isWheelEvent() const; 110 virtual bool isBeforeTextInsertedEvent() const; 111 virtual bool isOverflowEvent() const; 112 virtual bool isProgressEvent() const; 113 virtual bool isXMLHttpRequestProgressEvent() const; 114 virtual bool isWebKitAnimationEvent() const; 115 virtual bool isWebKitTransitionEvent() const; 116 #if ENABLE(SVG) 117 virtual bool isSVGZoomEvent() const; 118 #endif 119 #if ENABLE(DOM_STORAGE) 120 virtual bool isStorageEvent() const; 121 #endif 122 #if ENABLE(TOUCH_EVENTS) // Android 123 virtual bool isTouchEvent() const; 124 #endif 125 propagationStopped()126 bool propagationStopped() const { return m_propagationStopped; } 127 defaultPrevented()128 bool defaultPrevented() const { return m_defaultPrevented; } preventDefault()129 void preventDefault() { if (m_cancelable) m_defaultPrevented = true; } setDefaultPrevented(bool defaultPrevented)130 void setDefaultPrevented(bool defaultPrevented) { m_defaultPrevented = defaultPrevented; } 131 defaultHandled()132 bool defaultHandled() const { return m_defaultHandled; } setDefaultHandled()133 void setDefaultHandled() { m_defaultHandled = true; } 134 cancelBubble()135 bool cancelBubble() const { return m_cancelBubble; } setCancelBubble(bool cancel)136 void setCancelBubble(bool cancel) { m_cancelBubble = cancel; } 137 underlyingEvent()138 Event* underlyingEvent() const { return m_underlyingEvent.get(); } 139 void setUnderlyingEvent(PassRefPtr<Event>); 140 141 virtual bool storesResultAsString() const; 142 virtual void storeResult(const String&); 143 clipboard()144 virtual Clipboard* clipboard() const { return 0; } 145 146 protected: 147 Event(); 148 Event(const AtomicString& type, bool canBubble, bool cancelable); 149 150 virtual void receivedTarget(); dispatched()151 bool dispatched() const { return m_target; } 152 153 private: 154 AtomicString m_type; 155 bool m_canBubble; 156 bool m_cancelable; 157 158 bool m_propagationStopped; 159 bool m_defaultPrevented; 160 bool m_defaultHandled; 161 bool m_cancelBubble; 162 163 EventTarget* m_currentTarget; 164 unsigned short m_eventPhase; 165 RefPtr<EventTarget> m_target; 166 DOMTimeStamp m_createTime; 167 168 RefPtr<Event> m_underlyingEvent; 169 }; 170 171 } // namespace WebCore 172 173 #endif // Event_h 174