Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 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 "bindings/v8/ScriptWrappable.h" |
| 28 | #include "core/dom/DOMTimeStamp.h" |
| 29 | #include "core/dom/EventContext.h" |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 30 | #include "wtf/RefCounted.h" |
| 31 | #include "wtf/text/AtomicString.h" |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 32 | |
| 33 | namespace WebCore { |
| 34 | |
| 35 | class Clipboard; |
| 36 | class EventTarget; |
| 37 | class EventDispatcher; |
| 38 | class HTMLIFrameElement; |
| 39 | |
| 40 | struct EventInit { |
| 41 | EventInit(); |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 42 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 43 | bool bubbles; |
| 44 | bool cancelable; |
| 45 | }; |
| 46 | |
| 47 | class Event : public ScriptWrappable, public RefCounted<Event> { |
| 48 | public: |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 49 | enum PhaseType { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 50 | NONE = 0, |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 51 | CAPTURING_PHASE = 1, |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 52 | AT_TARGET = 2, |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 53 | BUBBLING_PHASE = 3 |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | enum EventType { |
| 57 | MOUSEDOWN = 1, |
| 58 | MOUSEUP = 2, |
| 59 | MOUSEOVER = 4, |
| 60 | MOUSEOUT = 8, |
| 61 | MOUSEMOVE = 16, |
| 62 | MOUSEDRAG = 32, |
| 63 | CLICK = 64, |
| 64 | DBLCLICK = 128, |
| 65 | KEYDOWN = 256, |
| 66 | KEYUP = 512, |
| 67 | KEYPRESS = 1024, |
| 68 | DRAGDROP = 2048, |
| 69 | FOCUS = 4096, |
| 70 | BLUR = 8192, |
| 71 | SELECT = 16384, |
| 72 | CHANGE = 32768 |
| 73 | }; |
| 74 | |
| 75 | static PassRefPtr<Event> create() |
| 76 | { |
| 77 | return adoptRef(new Event); |
| 78 | } |
| 79 | static PassRefPtr<Event> create(const AtomicString& type, bool canBubble, bool cancelable) |
| 80 | { |
| 81 | return adoptRef(new Event(type, canBubble, cancelable)); |
| 82 | } |
| 83 | |
| 84 | static PassRefPtr<Event> create(const AtomicString& type, const EventInit& initializer) |
| 85 | { |
| 86 | return adoptRef(new Event(type, initializer)); |
| 87 | } |
| 88 | |
| 89 | virtual ~Event(); |
| 90 | |
| 91 | void initEvent(const AtomicString& type, bool canBubble, bool cancelable); |
| 92 | |
| 93 | const AtomicString& type() const { return m_type; } |
Torne (Richard Coles) | 93ac45c | 2013-05-29 14:40:20 +0100 | [diff] [blame] | 94 | void setType(const AtomicString& type) { m_type = type; } |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 95 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 96 | EventTarget* target() const { return m_target.get(); } |
| 97 | void setTarget(PassRefPtr<EventTarget>); |
| 98 | |
| 99 | EventTarget* currentTarget() const { return m_currentTarget; } |
| 100 | void setCurrentTarget(EventTarget* currentTarget) { m_currentTarget = currentTarget; } |
| 101 | |
| 102 | unsigned short eventPhase() const { return m_eventPhase; } |
| 103 | void setEventPhase(unsigned short eventPhase) { m_eventPhase = eventPhase; } |
| 104 | |
| 105 | bool bubbles() const { return m_canBubble; } |
| 106 | bool cancelable() const { return m_cancelable; } |
| 107 | DOMTimeStamp timeStamp() const { return m_createTime; } |
| 108 | |
| 109 | void stopPropagation() { m_propagationStopped = true; } |
| 110 | void stopImmediatePropagation() { m_immediatePropagationStopped = true; } |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 111 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 112 | // IE Extensions |
| 113 | EventTarget* srcElement() const { return target(); } // MSIE extension - "the object that fired the event" |
| 114 | |
| 115 | bool returnValue() const { return !defaultPrevented(); } |
| 116 | void setReturnValue(bool returnValue) { setDefaultPrevented(!returnValue); } |
| 117 | |
| 118 | Clipboard* clipboardData() const { return isClipboardEvent() ? clipboard() : 0; } |
| 119 | |
| 120 | virtual const AtomicString& interfaceName() const; |
| 121 | bool hasInterface(const AtomicString&) const; |
| 122 | |
| 123 | // These events are general classes of events. |
| 124 | virtual bool isUIEvent() const; |
| 125 | virtual bool isMouseEvent() const; |
| 126 | virtual bool isFocusEvent() const; |
| 127 | virtual bool isKeyboardEvent() const; |
| 128 | virtual bool isTouchEvent() const; |
| 129 | |
| 130 | // Drag events are a subset of mouse events. |
| 131 | virtual bool isDragEvent() const; |
| 132 | |
| 133 | // These events lack a DOM interface. |
| 134 | virtual bool isClipboardEvent() const; |
| 135 | virtual bool isBeforeTextInsertedEvent() const; |
| 136 | |
| 137 | bool propagationStopped() const { return m_propagationStopped || m_immediatePropagationStopped; } |
| 138 | bool immediatePropagationStopped() const { return m_immediatePropagationStopped; } |
| 139 | |
| 140 | bool defaultPrevented() const { return m_defaultPrevented; } |
| 141 | void preventDefault() |
| 142 | { |
| 143 | if (m_cancelable) |
| 144 | m_defaultPrevented = true; |
| 145 | } |
| 146 | void setDefaultPrevented(bool defaultPrevented) { m_defaultPrevented = defaultPrevented; } |
| 147 | |
| 148 | bool defaultHandled() const { return m_defaultHandled; } |
| 149 | void setDefaultHandled() { m_defaultHandled = true; } |
| 150 | |
| 151 | bool cancelBubble() const { return m_cancelBubble; } |
| 152 | void setCancelBubble(bool cancel) { m_cancelBubble = cancel; } |
| 153 | |
| 154 | Event* underlyingEvent() const { return m_underlyingEvent.get(); } |
| 155 | void setUnderlyingEvent(PassRefPtr<Event>); |
| 156 | |
| 157 | EventPath& eventPath() { return m_eventPath; } |
Torne (Richard Coles) | 81a5157 | 2013-05-13 16:52:28 +0100 | [diff] [blame] | 158 | PassRefPtr<NodeList> path() const; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 159 | |
| 160 | virtual bool storesResultAsString() const; |
| 161 | virtual void storeResult(const String&); |
| 162 | |
| 163 | virtual Clipboard* clipboard() const { return 0; } |
| 164 | |
| 165 | bool isBeingDispatched() const { return eventPhase(); } |
| 166 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 167 | protected: |
| 168 | Event(); |
| 169 | Event(const AtomicString& type, bool canBubble, bool cancelable); |
| 170 | Event(const AtomicString& type, const EventInit&); |
| 171 | |
| 172 | virtual void receivedTarget(); |
| 173 | bool dispatched() const { return m_target; } |
| 174 | |
| 175 | private: |
| 176 | AtomicString m_type; |
| 177 | bool m_canBubble; |
| 178 | bool m_cancelable; |
| 179 | |
| 180 | bool m_propagationStopped; |
| 181 | bool m_immediatePropagationStopped; |
| 182 | bool m_defaultPrevented; |
| 183 | bool m_defaultHandled; |
| 184 | bool m_cancelBubble; |
| 185 | |
| 186 | unsigned short m_eventPhase; |
| 187 | EventTarget* m_currentTarget; |
| 188 | RefPtr<EventTarget> m_target; |
| 189 | DOMTimeStamp m_createTime; |
| 190 | RefPtr<Event> m_underlyingEvent; |
| 191 | EventPath m_eventPath; |
| 192 | }; |
| 193 | |
| 194 | } // namespace WebCore |
| 195 | |
| 196 | #endif // Event_h |