diff options
Diffstat (limited to 'Source/WebCore/dom/Event.h')
-rw-r--r-- | Source/WebCore/dom/Event.h | 152 |
1 files changed, 83 insertions, 69 deletions
diff --git a/Source/WebCore/dom/Event.h b/Source/WebCore/dom/Event.h index 9cd6dcddd..9edb3af31 100644 --- a/Source/WebCore/dom/Event.h +++ b/Source/WebCore/dom/Event.h @@ -21,30 +21,24 @@ * */ -#ifndef Event_h -#define Event_h +#pragma once #include "DOMTimeStamp.h" +#include "EventInit.h" #include "EventInterfaces.h" +#include "ExceptionOr.h" #include "ScriptWrappable.h" -#include <wtf/HashMap.h> -#include <wtf/ListHashSet.h> #include <wtf/RefCounted.h> +#include <wtf/TypeCasts.h> #include <wtf/text/AtomicString.h> namespace WebCore { -class Clipboard; +class DataTransfer; +class EventPath; class EventTarget; class HTMLIFrameElement; - -struct EventInit { - EventInit(); - EventInit(bool bubbles, bool cancelable); - - bool bubbles; - bool cancelable; -}; +class ScriptExecutionContext; enum EventInterface { @@ -56,6 +50,8 @@ DOM_EVENT_INTERFACES_FOR_EACH(DOM_EVENT_INTERFACE_DECLARE) class Event : public ScriptWrappable, public RefCounted<Event> { public: + enum class IsTrusted { No, Yes }; + enum PhaseType { NONE = 0, CAPTURING_PHASE = 1, @@ -63,61 +59,54 @@ public: BUBBLING_PHASE = 3 }; - enum EventType { - MOUSEDOWN = 1, - MOUSEUP = 2, - MOUSEOVER = 4, - MOUSEOUT = 8, - MOUSEMOVE = 16, - MOUSEDRAG = 32, - CLICK = 64, - DBLCLICK = 128, - KEYDOWN = 256, - KEYUP = 512, - KEYPRESS = 1024, - DRAGDROP = 2048, - FOCUS = 4096, - BLUR = 8192, - SELECT = 16384, - CHANGE = 32768 - }; - - static PassRefPtr<Event> create() + static Ref<Event> create(const AtomicString& type, bool canBubble, bool cancelable) { - return adoptRef(new Event); + return adoptRef(*new Event(type, canBubble, cancelable)); } - static PassRefPtr<Event> create(const AtomicString& type, bool canBubble, bool cancelable) + + static Ref<Event> createForBindings() { - return adoptRef(new Event(type, canBubble, cancelable)); + return adoptRef(*new Event); } - static PassRefPtr<Event> create(const AtomicString& type, const EventInit& initializer) + static Ref<Event> create(const AtomicString& type, const EventInit& initializer, IsTrusted isTrusted = IsTrusted::No) { - return adoptRef(new Event(type, initializer)); + return adoptRef(*new Event(type, initializer, isTrusted)); } virtual ~Event(); - void initEvent(const AtomicString& type, bool canBubble, bool cancelable); + WEBCORE_EXPORT void initEvent(const AtomicString& type, bool canBubble, bool cancelable); + + bool isInitialized() const { return m_isInitialized; } const AtomicString& type() const { return m_type; } void setType(const AtomicString& type) { m_type = type; } EventTarget* target() const { return m_target.get(); } - void setTarget(PassRefPtr<EventTarget>); + void setTarget(RefPtr<EventTarget>&&); - EventTarget* currentTarget() const { return m_currentTarget; } - void setCurrentTarget(EventTarget* currentTarget) { m_currentTarget = currentTarget; } + EventTarget* currentTarget() const { return m_currentTarget.get(); } + void setCurrentTarget(EventTarget*); unsigned short eventPhase() const { return m_eventPhase; } void setEventPhase(unsigned short eventPhase) { m_eventPhase = eventPhase; } bool bubbles() const { return m_canBubble; } bool cancelable() const { return m_cancelable; } + WEBCORE_EXPORT bool composed() const; + DOMTimeStamp timeStamp() const { return m_createTime; } + void setEventPath(const EventPath& path) { m_eventPath = &path; } + void clearEventPath() { m_eventPath = nullptr; } + Vector<EventTarget*> composedPath() const; + void stopPropagation() { m_propagationStopped = true; } void stopImmediatePropagation() { m_immediatePropagationStopped = true; } + + bool isTrusted() const { return m_isTrusted; } + void setUntrusted() { m_isTrusted = false; } // IE Extensions EventTarget* srcElement() const { return target(); } // MSIE extension - "the object that fired the event" @@ -125,8 +114,6 @@ public: bool legacyReturnValue() const { return !defaultPrevented(); } void setLegacyReturnValue(bool returnValue) { setDefaultPrevented(!returnValue); } - Clipboard* clipboardData() const { return isClipboardEvent() ? clipboard() : 0; } - virtual EventInterface eventInterface() const; // These events are general classes of events. @@ -134,24 +121,33 @@ public: virtual bool isMouseEvent() const; virtual bool isFocusEvent() const; virtual bool isKeyboardEvent() const; + virtual bool isInputEvent() const; + virtual bool isCompositionEvent() const; virtual bool isTouchEvent() const; - // Drag events are a subset of mouse events. - virtual bool isDragEvent() const; - // These events lack a DOM interface. virtual bool isClipboardEvent() const; virtual bool isBeforeTextInsertedEvent() const; virtual bool isBeforeUnloadEvent() const; + virtual bool isErrorEvent() const; + virtual bool isTextEvent() const; + virtual bool isWheelEvent() const; + +#if ENABLE(INDEXED_DATABASE) + virtual bool isVersionChangeEvent() const { return false; } +#endif + bool propagationStopped() const { return m_propagationStopped || m_immediatePropagationStopped; } bool immediatePropagationStopped() const { return m_immediatePropagationStopped; } + void resetPropagationFlags(); + bool defaultPrevented() const { return m_defaultPrevented; } void preventDefault() { - if (m_cancelable) + if (m_cancelable && !m_isExecutingPassiveEventListener) m_defaultPrevented = true; } void setDefaultPrevented(bool defaultPrevented) { m_defaultPrevented = defaultPrevented; } @@ -159,48 +155,66 @@ public: bool defaultHandled() const { return m_defaultHandled; } void setDefaultHandled() { m_defaultHandled = true; } - bool cancelBubble() const { return m_cancelBubble; } - void setCancelBubble(bool cancel) { m_cancelBubble = cancel; } + void setInPassiveListener(bool value) { m_isExecutingPassiveEventListener = value; } - Event* underlyingEvent() const { return m_underlyingEvent.get(); } - void setUnderlyingEvent(PassRefPtr<Event>); + bool cancelBubble() const { return propagationStopped(); } + void setCancelBubble(bool); - virtual Clipboard* clipboard() const { return 0; } + Event* underlyingEvent() const { return m_underlyingEvent.get(); } + void setUnderlyingEvent(Event*); bool isBeingDispatched() const { return eventPhase(); } - virtual PassRefPtr<Event> cloneFor(HTMLIFrameElement*) const; - virtual EventTarget* relatedTarget() const { return nullptr; } protected: - Event(); - Event(const AtomicString& type, bool canBubble, bool cancelable); + Event(IsTrusted = IsTrusted::No); + WEBCORE_EXPORT Event(const AtomicString& type, bool canBubble, bool cancelable); Event(const AtomicString& type, bool canBubble, bool cancelable, double timestamp); - Event(const AtomicString& type, const EventInit&); + Event(const AtomicString& type, const EventInit&, IsTrusted); virtual void receivedTarget(); bool dispatched() const { return m_target; } private: AtomicString m_type; - bool m_canBubble; - bool m_cancelable; - - bool m_propagationStopped; - bool m_immediatePropagationStopped; - bool m_defaultPrevented; - bool m_defaultHandled; - bool m_cancelBubble; - unsigned short m_eventPhase; - EventTarget* m_currentTarget; + bool m_isInitialized { false }; + bool m_canBubble { false }; + bool m_cancelable { false }; + bool m_composed { false }; + + bool m_propagationStopped { false }; + bool m_immediatePropagationStopped { false }; + bool m_defaultPrevented { false }; + bool m_defaultHandled { false }; + bool m_isTrusted { false }; + bool m_isExecutingPassiveEventListener { false }; + + unsigned short m_eventPhase { 0 }; + RefPtr<EventTarget> m_currentTarget; + const EventPath* m_eventPath { nullptr }; RefPtr<EventTarget> m_target; DOMTimeStamp m_createTime; RefPtr<Event> m_underlyingEvent; }; +inline void Event::resetPropagationFlags() +{ + m_propagationStopped = false; + m_immediatePropagationStopped = false; +} + +inline void Event::setCancelBubble(bool cancel) +{ + if (cancel) + m_propagationStopped = true; +} + } // namespace WebCore -#endif // Event_h +#define SPECIALIZE_TYPE_TRAITS_EVENT(ToValueTypeName) \ +SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ToValueTypeName) \ + static bool isType(const WebCore::Event& event) { return event.is##ToValueTypeName(); } \ +SPECIALIZE_TYPE_TRAITS_END() |