weinig | 681a517 | 2006-06-19 22:58:36 +0000 | [diff] [blame] | 1 | /* |
weinig | 681a517 | 2006-06-19 22:58:36 +0000 | [diff] [blame] | 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) |
benjamin@webkit.org | ac28bde | 2013-06-19 22:41:17 +0000 | [diff] [blame] | 5 | * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2013 Apple Inc. All rights reserved. |
weinig | 681a517 | 2006-06-19 22:58:36 +0000 | [diff] [blame] | 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 |
ddkilzer | c8eccec | 2007-09-26 02:29:57 +0000 | [diff] [blame] | 19 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 20 | * Boston, MA 02110-1301, USA. |
weinig | 681a517 | 2006-06-19 22:58:36 +0000 | [diff] [blame] | 21 | * |
| 22 | */ |
| 23 | |
commit-queue@webkit.org | d862d77 | 2016-10-31 22:07:53 +0000 | [diff] [blame] | 24 | #pragma once |
weinig | 681a517 | 2006-06-19 22:58:36 +0000 | [diff] [blame] | 25 | |
commit-queue@webkit.org | 78873c9 | 2010-11-09 04:14:36 +0000 | [diff] [blame] | 26 | #include "DOMTimeStamp.h" |
cdumez@apple.com | a7d6ccf | 2016-10-09 00:03:14 +0000 | [diff] [blame] | 27 | #include "EventInit.h" |
weinig@apple.com | d2bf649 | 2013-09-22 04:15:10 +0000 | [diff] [blame] | 28 | #include "EventInterfaces.h" |
cdumez@apple.com | 68c6eb5 | 2016-10-26 20:17:24 +0000 | [diff] [blame] | 29 | #include "ExceptionOr.h" |
eric@webkit.org | d0219bf | 2012-11-16 22:02:21 +0000 | [diff] [blame] | 30 | #include "ScriptWrappable.h" |
ggaren@apple.com | 58ea1c1 | 2007-11-14 02:05:26 +0000 | [diff] [blame] | 31 | #include <wtf/RefCounted.h> |
cdumez@apple.com | 434faff | 2014-10-01 22:29:14 +0000 | [diff] [blame] | 32 | #include <wtf/TypeCasts.h> |
barraclough@apple.com | bbb3cd4 | 2010-08-10 17:45:41 +0000 | [diff] [blame] | 33 | #include <wtf/text/AtomicString.h> |
weinig | 681a517 | 2006-06-19 22:58:36 +0000 | [diff] [blame] | 34 | |
| 35 | namespace WebCore { |
| 36 | |
ap@apple.com | 236ec76 | 2014-04-08 22:06:16 +0000 | [diff] [blame] | 37 | class DataTransfer; |
rniwa@webkit.org | aaacd15 | 2016-03-12 03:11:04 +0000 | [diff] [blame] | 38 | class EventPath; |
commit-queue@webkit.org | 2b5fd70 | 2012-09-04 22:22:40 +0000 | [diff] [blame] | 39 | class EventTarget; |
commit-queue@webkit.org | 2b5fd70 | 2012-09-04 22:22:40 +0000 | [diff] [blame] | 40 | class HTMLIFrameElement; |
cdumez@apple.com | 68c6eb5 | 2016-10-26 20:17:24 +0000 | [diff] [blame] | 41 | class ScriptExecutionContext; |
weinig | 950051b | 2007-06-13 02:40:00 +0000 | [diff] [blame] | 42 | |
weinig@apple.com | d2bf649 | 2013-09-22 04:15:10 +0000 | [diff] [blame] | 43 | enum EventInterface { |
| 44 | |
| 45 | #define DOM_EVENT_INTERFACE_DECLARE(name) name##InterfaceType, |
| 46 | DOM_EVENT_INTERFACES_FOR_EACH(DOM_EVENT_INTERFACE_DECLARE) |
| 47 | #undef DOM_EVENT_INTERFACE_DECLARE |
| 48 | |
| 49 | }; |
| 50 | |
eric@webkit.org | d0219bf | 2012-11-16 22:02:21 +0000 | [diff] [blame] | 51 | class Event : public ScriptWrappable, public RefCounted<Event> { |
commit-queue@webkit.org | 2b5fd70 | 2012-09-04 22:22:40 +0000 | [diff] [blame] | 52 | public: |
cdumez@apple.com | a7d6ccf | 2016-10-09 00:03:14 +0000 | [diff] [blame] | 53 | enum class IsTrusted { No, Yes }; |
| 54 | |
commit-queue@webkit.org | 2b5fd70 | 2012-09-04 22:22:40 +0000 | [diff] [blame] | 55 | enum PhaseType { |
| 56 | NONE = 0, |
| 57 | CAPTURING_PHASE = 1, |
| 58 | AT_TARGET = 2, |
| 59 | BUBBLING_PHASE = 3 |
weinig@apple.com | 8dc0403 | 2011-08-28 23:58:25 +0000 | [diff] [blame] | 60 | }; |
| 61 | |
ddkilzer@apple.com | 63a5f97 | 2015-02-14 21:52:34 +0000 | [diff] [blame] | 62 | static Ref<Event> create(const AtomicString& type, bool canBubble, bool cancelable) |
commit-queue@webkit.org | 2b5fd70 | 2012-09-04 22:22:40 +0000 | [diff] [blame] | 63 | { |
akling@apple.com | b6c8c7c | 2014-12-14 12:23:31 +0000 | [diff] [blame] | 64 | return adoptRef(*new Event(type, canBubble, cancelable)); |
commit-queue@webkit.org | 2b5fd70 | 2012-09-04 22:22:40 +0000 | [diff] [blame] | 65 | } |
| 66 | |
jiewen_tan@apple.com | cb979e9 | 2016-02-11 00:03:11 +0000 | [diff] [blame] | 67 | static Ref<Event> createForBindings() |
| 68 | { |
| 69 | return adoptRef(*new Event); |
| 70 | } |
| 71 | |
cdumez@apple.com | f998ad2 | 2016-10-19 02:26:50 +0000 | [diff] [blame] | 72 | static Ref<Event> create(const AtomicString& type, const EventInit& initializer, IsTrusted isTrusted = IsTrusted::No) |
commit-queue@webkit.org | 2b5fd70 | 2012-09-04 22:22:40 +0000 | [diff] [blame] | 73 | { |
cdumez@apple.com | f998ad2 | 2016-10-19 02:26:50 +0000 | [diff] [blame] | 74 | return adoptRef(*new Event(type, initializer, isTrusted)); |
commit-queue@webkit.org | 2b5fd70 | 2012-09-04 22:22:40 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | virtual ~Event(); |
| 78 | |
achristensen@apple.com | 760090a | 2016-08-22 15:51:58 +0000 | [diff] [blame] | 79 | WEBCORE_EXPORT void initEvent(const AtomicString& type, bool canBubble, bool cancelable); |
cdumez@apple.com | 68c6eb5 | 2016-10-26 20:17:24 +0000 | [diff] [blame] | 80 | |
cdumez@apple.com | ff1aad8 | 2015-09-06 20:41:48 +0000 | [diff] [blame] | 81 | bool isInitialized() const { return m_isInitialized; } |
commit-queue@webkit.org | 2b5fd70 | 2012-09-04 22:22:40 +0000 | [diff] [blame] | 82 | |
| 83 | const AtomicString& type() const { return m_type; } |
alexis@webkit.org | fab3303 | 2013-05-17 03:26:58 +0000 | [diff] [blame] | 84 | void setType(const AtomicString& type) { m_type = type; } |
commit-queue@webkit.org | 2b5fd70 | 2012-09-04 22:22:40 +0000 | [diff] [blame] | 85 | |
| 86 | EventTarget* target() const { return m_target.get(); } |
cdumez@apple.com | 32216e4 | 2015-11-12 07:28:57 +0000 | [diff] [blame] | 87 | void setTarget(RefPtr<EventTarget>&&); |
commit-queue@webkit.org | 2b5fd70 | 2012-09-04 22:22:40 +0000 | [diff] [blame] | 88 | |
bfulgham@apple.com | bc488af | 2017-02-10 02:21:09 +0000 | [diff] [blame^] | 89 | EventTarget* currentTarget() const { return m_currentTarget.get(); } |
| 90 | void setCurrentTarget(EventTarget*); |
commit-queue@webkit.org | 2b5fd70 | 2012-09-04 22:22:40 +0000 | [diff] [blame] | 91 | |
| 92 | unsigned short eventPhase() const { return m_eventPhase; } |
| 93 | void setEventPhase(unsigned short eventPhase) { m_eventPhase = eventPhase; } |
| 94 | |
| 95 | bool bubbles() const { return m_canBubble; } |
| 96 | bool cancelable() const { return m_cancelable; } |
achristensen@apple.com | 760090a | 2016-08-22 15:51:58 +0000 | [diff] [blame] | 97 | WEBCORE_EXPORT bool composed() const; |
rniwa@webkit.org | aaacd15 | 2016-03-12 03:11:04 +0000 | [diff] [blame] | 98 | |
commit-queue@webkit.org | 2b5fd70 | 2012-09-04 22:22:40 +0000 | [diff] [blame] | 99 | DOMTimeStamp timeStamp() const { return m_createTime; } |
| 100 | |
rniwa@webkit.org | aaacd15 | 2016-03-12 03:11:04 +0000 | [diff] [blame] | 101 | void setEventPath(const EventPath& path) { m_eventPath = &path; } |
| 102 | void clearEventPath() { m_eventPath = nullptr; } |
rniwa@webkit.org | ea6b41a | 2016-05-09 17:47:01 +0000 | [diff] [blame] | 103 | Vector<EventTarget*> composedPath() const; |
rniwa@webkit.org | aaacd15 | 2016-03-12 03:11:04 +0000 | [diff] [blame] | 104 | |
commit-queue@webkit.org | 2b5fd70 | 2012-09-04 22:22:40 +0000 | [diff] [blame] | 105 | void stopPropagation() { m_propagationStopped = true; } |
| 106 | void stopImmediatePropagation() { m_immediatePropagationStopped = true; } |
jiewen_tan@apple.com | 4028c65 | 2016-02-12 23:25:02 +0000 | [diff] [blame] | 107 | |
| 108 | bool isTrusted() const { return m_isTrusted; } |
| 109 | void setUntrusted() { m_isTrusted = false; } |
commit-queue@webkit.org | 2b5fd70 | 2012-09-04 22:22:40 +0000 | [diff] [blame] | 110 | |
| 111 | // IE Extensions |
| 112 | EventTarget* srcElement() const { return target(); } // MSIE extension - "the object that fired the event" |
| 113 | |
ch.dumez@sisa.samsung.com | 231386f | 2013-09-09 18:40:04 +0000 | [diff] [blame] | 114 | bool legacyReturnValue() const { return !defaultPrevented(); } |
| 115 | void setLegacyReturnValue(bool returnValue) { setDefaultPrevented(!returnValue); } |
commit-queue@webkit.org | 2b5fd70 | 2012-09-04 22:22:40 +0000 | [diff] [blame] | 116 | |
weinig@apple.com | d2bf649 | 2013-09-22 04:15:10 +0000 | [diff] [blame] | 117 | virtual EventInterface eventInterface() const; |
commit-queue@webkit.org | 2b5fd70 | 2012-09-04 22:22:40 +0000 | [diff] [blame] | 118 | |
| 119 | // These events are general classes of events. |
| 120 | virtual bool isUIEvent() const; |
| 121 | virtual bool isMouseEvent() const; |
haraken@chromium.org | 4c2d69b | 2013-02-07 08:30:00 +0000 | [diff] [blame] | 122 | virtual bool isFocusEvent() const; |
commit-queue@webkit.org | 2b5fd70 | 2012-09-04 22:22:40 +0000 | [diff] [blame] | 123 | virtual bool isKeyboardEvent() const; |
wenson_hsieh@apple.com | 96830b2 | 2016-10-06 04:05:35 +0000 | [diff] [blame] | 124 | virtual bool isInputEvent() const; |
rniwa@webkit.org | 4c11002 | 2016-07-08 01:57:44 +0000 | [diff] [blame] | 125 | virtual bool isCompositionEvent() const; |
commit-queue@webkit.org | 2b5fd70 | 2012-09-04 22:22:40 +0000 | [diff] [blame] | 126 | virtual bool isTouchEvent() const; |
| 127 | |
commit-queue@webkit.org | 2b5fd70 | 2012-09-04 22:22:40 +0000 | [diff] [blame] | 128 | // These events lack a DOM interface. |
| 129 | virtual bool isClipboardEvent() const; |
| 130 | virtual bool isBeforeTextInsertedEvent() const; |
| 131 | |
ch.dumez@sisa.samsung.com | 231386f | 2013-09-09 18:40:04 +0000 | [diff] [blame] | 132 | virtual bool isBeforeUnloadEvent() const; |
| 133 | |
akling@apple.com | 3a14a92 | 2014-02-16 02:01:04 +0000 | [diff] [blame] | 134 | virtual bool isErrorEvent() const; |
| 135 | virtual bool isTextEvent() const; |
| 136 | virtual bool isWheelEvent() const; |
| 137 | |
beidson@apple.com | 691c3f8 | 2015-12-31 05:43:33 +0000 | [diff] [blame] | 138 | #if ENABLE(INDEXED_DATABASE) |
| 139 | virtual bool isVersionChangeEvent() const { return false; } |
| 140 | #endif |
| 141 | |
commit-queue@webkit.org | 2b5fd70 | 2012-09-04 22:22:40 +0000 | [diff] [blame] | 142 | bool propagationStopped() const { return m_propagationStopped || m_immediatePropagationStopped; } |
| 143 | bool immediatePropagationStopped() const { return m_immediatePropagationStopped; } |
| 144 | |
cdumez@apple.com | 9d5fb89 | 2016-08-19 15:36:55 +0000 | [diff] [blame] | 145 | void resetPropagationFlags(); |
| 146 | |
commit-queue@webkit.org | 2b5fd70 | 2012-09-04 22:22:40 +0000 | [diff] [blame] | 147 | bool defaultPrevented() const { return m_defaultPrevented; } |
| 148 | void preventDefault() |
| 149 | { |
cdumez@apple.com | 613bbf3 | 2016-06-07 17:53:15 +0000 | [diff] [blame] | 150 | if (m_cancelable && !m_isExecutingPassiveEventListener) |
commit-queue@webkit.org | 2b5fd70 | 2012-09-04 22:22:40 +0000 | [diff] [blame] | 151 | m_defaultPrevented = true; |
| 152 | } |
| 153 | void setDefaultPrevented(bool defaultPrevented) { m_defaultPrevented = defaultPrevented; } |
| 154 | |
| 155 | bool defaultHandled() const { return m_defaultHandled; } |
| 156 | void setDefaultHandled() { m_defaultHandled = true; } |
| 157 | |
cdumez@apple.com | 613bbf3 | 2016-06-07 17:53:15 +0000 | [diff] [blame] | 158 | void setInPassiveListener(bool value) { m_isExecutingPassiveEventListener = value; } |
| 159 | |
cdumez@apple.com | 86cd092 | 2017-01-03 23:51:39 +0000 | [diff] [blame] | 160 | bool cancelBubble() const { return propagationStopped(); } |
| 161 | void setCancelBubble(bool); |
commit-queue@webkit.org | 2b5fd70 | 2012-09-04 22:22:40 +0000 | [diff] [blame] | 162 | |
| 163 | Event* underlyingEvent() const { return m_underlyingEvent.get(); } |
gyuyoung.kim@webkit.org | 5c6cefe | 2016-01-31 12:08:32 +0000 | [diff] [blame] | 164 | void setUnderlyingEvent(Event*); |
commit-queue@webkit.org | 2b5fd70 | 2012-09-04 22:22:40 +0000 | [diff] [blame] | 165 | |
commit-queue@webkit.org | 2b5fd70 | 2012-09-04 22:22:40 +0000 | [diff] [blame] | 166 | bool isBeingDispatched() const { return eventPhase(); } |
| 167 | |
rniwa@webkit.org | d0fec7e | 2013-10-09 20:05:13 +0000 | [diff] [blame] | 168 | virtual EventTarget* relatedTarget() const { return nullptr; } |
| 169 | |
commit-queue@webkit.org | 2b5fd70 | 2012-09-04 22:22:40 +0000 | [diff] [blame] | 170 | protected: |
cdumez@apple.com | df8c1e4 | 2016-10-09 03:46:39 +0000 | [diff] [blame] | 171 | Event(IsTrusted = IsTrusted::No); |
achristensen@apple.com | 1d46376 | 2015-02-10 23:07:47 +0000 | [diff] [blame] | 172 | WEBCORE_EXPORT Event(const AtomicString& type, bool canBubble, bool cancelable); |
benjamin@webkit.org | ac28bde | 2013-06-19 22:41:17 +0000 | [diff] [blame] | 173 | Event(const AtomicString& type, bool canBubble, bool cancelable, double timestamp); |
cdumez@apple.com | f998ad2 | 2016-10-19 02:26:50 +0000 | [diff] [blame] | 174 | Event(const AtomicString& type, const EventInit&, IsTrusted); |
commit-queue@webkit.org | 2b5fd70 | 2012-09-04 22:22:40 +0000 | [diff] [blame] | 175 | |
| 176 | virtual void receivedTarget(); |
| 177 | bool dispatched() const { return m_target; } |
| 178 | |
| 179 | private: |
| 180 | AtomicString m_type; |
rniwa@webkit.org | 4c11002 | 2016-07-08 01:57:44 +0000 | [diff] [blame] | 181 | |
| 182 | bool m_isInitialized { false }; |
hs85.jeong@samsung.com | a08a0ad | 2015-11-03 18:24:34 +0000 | [diff] [blame] | 183 | bool m_canBubble { false }; |
| 184 | bool m_cancelable { false }; |
rniwa@webkit.org | 4c11002 | 2016-07-08 01:57:44 +0000 | [diff] [blame] | 185 | bool m_composed { false }; |
commit-queue@webkit.org | 2b5fd70 | 2012-09-04 22:22:40 +0000 | [diff] [blame] | 186 | |
hs85.jeong@samsung.com | a08a0ad | 2015-11-03 18:24:34 +0000 | [diff] [blame] | 187 | bool m_propagationStopped { false }; |
| 188 | bool m_immediatePropagationStopped { false }; |
| 189 | bool m_defaultPrevented { false }; |
| 190 | bool m_defaultHandled { false }; |
jiewen_tan@apple.com | 4028c65 | 2016-02-12 23:25:02 +0000 | [diff] [blame] | 191 | bool m_isTrusted { false }; |
cdumez@apple.com | 613bbf3 | 2016-06-07 17:53:15 +0000 | [diff] [blame] | 192 | bool m_isExecutingPassiveEventListener { false }; |
commit-queue@webkit.org | 2b5fd70 | 2012-09-04 22:22:40 +0000 | [diff] [blame] | 193 | |
hs85.jeong@samsung.com | a08a0ad | 2015-11-03 18:24:34 +0000 | [diff] [blame] | 194 | unsigned short m_eventPhase { 0 }; |
bfulgham@apple.com | bc488af | 2017-02-10 02:21:09 +0000 | [diff] [blame^] | 195 | RefPtr<EventTarget> m_currentTarget; |
rniwa@webkit.org | aaacd15 | 2016-03-12 03:11:04 +0000 | [diff] [blame] | 196 | const EventPath* m_eventPath { nullptr }; |
commit-queue@webkit.org | 2b5fd70 | 2012-09-04 22:22:40 +0000 | [diff] [blame] | 197 | RefPtr<EventTarget> m_target; |
| 198 | DOMTimeStamp m_createTime; |
| 199 | |
| 200 | RefPtr<Event> m_underlyingEvent; |
| 201 | }; |
| 202 | |
cdumez@apple.com | 9d5fb89 | 2016-08-19 15:36:55 +0000 | [diff] [blame] | 203 | inline void Event::resetPropagationFlags() |
| 204 | { |
| 205 | m_propagationStopped = false; |
| 206 | m_immediatePropagationStopped = false; |
| 207 | } |
| 208 | |
cdumez@apple.com | 86cd092 | 2017-01-03 23:51:39 +0000 | [diff] [blame] | 209 | inline void Event::setCancelBubble(bool cancel) |
| 210 | { |
| 211 | if (cancel) |
| 212 | m_propagationStopped = true; |
| 213 | } |
| 214 | |
weinig | 681a517 | 2006-06-19 22:58:36 +0000 | [diff] [blame] | 215 | } // namespace WebCore |
| 216 | |
cdumez@apple.com | 434faff | 2014-10-01 22:29:14 +0000 | [diff] [blame] | 217 | #define SPECIALIZE_TYPE_TRAITS_EVENT(ToValueTypeName) \ |
| 218 | SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ToValueTypeName) \ |
| 219 | static bool isType(const WebCore::Event& event) { return event.is##ToValueTypeName(); } \ |
| 220 | SPECIALIZE_TYPE_TRAITS_END() |