#pragma once
#include <wtf/OptionSet.h>
namespace WebCore {
class PlatformEvent {
public:
enum Type : uint8_t {
NoType = 0,
KeyDown,
KeyUp,
RawKeyDown,
Char,
MouseMoved,
MousePressed,
MouseReleased,
MouseForceChanged,
MouseForceDown,
MouseForceUp,
MouseScroll,
Wheel,
#if ENABLE(TOUCH_EVENTS)
TouchStart,
TouchMove,
TouchEnd,
TouchCancel,
TouchForceChange,
#endif
#if ENABLE(MAC_GESTURE_EVENTS)
GestureStart,
GestureChange,
GestureEnd,
#endif
};
enum class Modifier {
AltKey = 1 << 0,
CtrlKey = 1 << 1,
MetaKey = 1 << 2,
ShiftKey = 1 << 3,
CapsLockKey = 1 << 4,
};
Type type() const { return static_cast<Type>(m_type); }
bool shiftKey() const { return m_modifiers.contains(Modifier::ShiftKey); }
bool ctrlKey() const { return m_modifiers.contains(Modifier::CtrlKey); }
bool altKey() const { return m_modifiers.contains(Modifier::AltKey); }
bool metaKey() const { return m_modifiers.contains(Modifier::MetaKey); }
OptionSet<Modifier> modifiers() const { return m_modifiers; }
double timestamp() const { return m_timestamp; }
protected:
PlatformEvent()
: m_type(NoType)
, m_timestamp(0)
{
}
explicit PlatformEvent(Type type)
: m_type(type)
, m_timestamp(0)
{
}
PlatformEvent(Type type, OptionSet<Modifier> modifiers, double timestamp)
: m_type(type)
, m_modifiers(modifiers)
, m_timestamp(timestamp)
{
}
PlatformEvent(Type type, bool shiftKey, bool ctrlKey, bool altKey, bool metaKey, double timestamp)
: m_type(type)
, m_timestamp(timestamp)
{
if (shiftKey)
m_modifiers |= Modifier::ShiftKey;
if (ctrlKey)
m_modifiers |= Modifier::CtrlKey;
if (altKey)
m_modifiers |= Modifier::AltKey;
if (metaKey)
m_modifiers |= Modifier::MetaKey;
}
~PlatformEvent()
{
}
unsigned m_type;
OptionSet<Modifier> m_modifiers;
double m_timestamp;
};
}