#ifndef Event_h
#define Event_h
#include "bindings/v8/ScriptWrappable.h"
#include "core/dom/DOMTimeStamp.h"
#include "core/events/EventPath.h"
#include "heap/Handle.h"
#include "wtf/RefCounted.h"
#include "wtf/text/AtomicString.h"
namespace WebCore {
class EventTarget;
class EventDispatcher;
class HTMLIFrameElement;
struct EventInit {
STACK_ALLOCATED();
public:
EventInit();
bool bubbles;
bool cancelable;
};
class Event : public RefCountedWillBeGarbageCollectedFinalized<Event>, public ScriptWrappable {
public:
enum PhaseType {
NONE = 0,
CAPTURING_PHASE = 1,
AT_TARGET = 2,
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 PassRefPtrWillBeRawPtr<Event> create()
{
return adoptRefWillBeNoop(new Event);
}
static PassRefPtrWillBeRawPtr<Event> create(const AtomicString& type)
{
return adoptRefWillBeNoop(new Event(type, false, false));
}
static PassRefPtrWillBeRawPtr<Event> createCancelable(const AtomicString& type)
{
return adoptRefWillBeNoop(new Event(type, false, true));
}
static PassRefPtrWillBeRawPtr<Event> createBubble(const AtomicString& type)
{
return adoptRefWillBeNoop(new Event(type, true, false));
}
static PassRefPtrWillBeRawPtr<Event> createCancelableBubble(const AtomicString& type)
{
return adoptRefWillBeNoop(new Event(type, true, true));
}
static PassRefPtrWillBeRawPtr<Event> create(const AtomicString& type, const EventInit& initializer)
{
return adoptRefWillBeNoop(new Event(type, initializer));
}
virtual ~Event();
void initEvent(const AtomicString& type, bool canBubble, bool cancelable);
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>);
EventTarget* currentTarget() const { return m_currentTarget; }
void setCurrentTarget(EventTarget* currentTarget) { m_currentTarget = currentTarget; }
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; }
DOMTimeStamp timeStamp() const { return m_createTime; }
void stopPropagation() { m_propagationStopped = true; }
void stopImmediatePropagation() { m_immediatePropagationStopped = true; }
EventTarget* srcElement() const { return target(); }
bool legacyReturnValue() const { return !defaultPrevented(); }
void setLegacyReturnValue(bool returnValue) { setDefaultPrevented(!returnValue); }
virtual const AtomicString& interfaceName() const;
bool hasInterface(const AtomicString&) const;
virtual bool isUIEvent() const;
virtual bool isMouseEvent() const;
virtual bool isFocusEvent() const;
virtual bool isKeyboardEvent() const;
virtual bool isTouchEvent() const;
virtual bool isGestureEvent() const;
virtual bool isWheelEvent() const;
virtual bool isDragEvent() const;
virtual bool isClipboardEvent() const;
virtual bool isBeforeTextInsertedEvent() const;
virtual bool isBeforeUnloadEvent() const;
bool propagationStopped() const { return m_propagationStopped || m_immediatePropagationStopped; }
bool immediatePropagationStopped() const { return m_immediatePropagationStopped; }
bool defaultPrevented() const { return m_defaultPrevented; }
void preventDefault()
{
if (m_cancelable)
m_defaultPrevented = true;
}
void setDefaultPrevented(bool defaultPrevented) { m_defaultPrevented = defaultPrevented; }
bool defaultHandled() const { return m_defaultHandled; }
void setDefaultHandled() { m_defaultHandled = true; }
bool cancelBubble() const { return m_cancelBubble; }
void setCancelBubble(bool cancel) { m_cancelBubble = cancel; }
Event* underlyingEvent() const { return m_underlyingEvent.get(); }
void setUnderlyingEvent(PassRefPtrWillBeRawPtr<Event>);
EventPath& eventPath() { ASSERT(m_eventPath); return *m_eventPath; }
EventPath& ensureEventPath();
PassRefPtr<NodeList> path() const;
bool isBeingDispatched() const { return eventPhase(); }
virtual void trace(Visitor*);
protected:
Event();
Event(const AtomicString& type, bool canBubble, bool cancelable);
Event(const AtomicString& type, const EventInit&);
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;
RefPtr<EventTarget> m_target;
DOMTimeStamp m_createTime;
RefPtrWillBeMember<Event> m_underlyingEvent;
OwnPtrWillBeMember<EventPath> m_eventPath;
};
#define DEFINE_EVENT_TYPE_CASTS(typeName) \
DEFINE_TYPE_CASTS(typeName, Event, event, event->is##typeName(), event.is##typeName())
}
#endif