#ifndef KeyboardEvent_h
#define KeyboardEvent_h
#include "KeypressCommand.h"
#include "UIEventWithKeyState.h"
#include <memory>
#include <wtf/Vector.h>
namespace WebCore {
class Node;
class PlatformKeyboardEvent;
struct KeyboardEventInit : public UIEventInit {
KeyboardEventInit();
String keyIdentifier;
unsigned location;
bool ctrlKey;
bool altKey;
bool shiftKey;
bool metaKey;
};
class KeyboardEvent final : public UIEventWithKeyState {
public:
enum KeyLocationCode {
DOM_KEY_LOCATION_STANDARD = 0x00,
DOM_KEY_LOCATION_LEFT = 0x01,
DOM_KEY_LOCATION_RIGHT = 0x02,
DOM_KEY_LOCATION_NUMPAD = 0x03
};
static Ref<KeyboardEvent> create()
{
return adoptRef(*new KeyboardEvent);
}
static Ref<KeyboardEvent> create(const PlatformKeyboardEvent& platformEvent, AbstractView* view)
{
return adoptRef(*new KeyboardEvent(platformEvent, view));
}
static Ref<KeyboardEvent> create(const AtomicString& type, const KeyboardEventInit& initializer)
{
return adoptRef(*new KeyboardEvent(type, initializer));
}
virtual ~KeyboardEvent();
void initKeyboardEvent(const AtomicString& type, bool canBubble, bool cancelable, AbstractView*,
const String& keyIdentifier, unsigned location,
bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, bool altGraphKey = false);
const String& keyIdentifier() const { return m_keyIdentifier; }
unsigned location() const { return m_location; }
bool getModifierState(const String& keyIdentifier) const;
bool altGraphKey() const { return m_altGraphKey; }
const PlatformKeyboardEvent* keyEvent() const { return m_keyEvent.get(); }
virtual int keyCode() const override; virtual int charCode() const override;
virtual EventInterface eventInterface() const override;
virtual bool isKeyboardEvent() const override;
virtual int which() const override;
#if PLATFORM(COCOA)
bool handledByInputMethod() const { return m_handledByInputMethod; }
const Vector<KeypressCommand>& keypressCommands() const { return m_keypressCommands; }
Vector<KeypressCommand>& keypressCommands() { return m_keypressCommands; }
#endif
private:
WEBCORE_EXPORT KeyboardEvent();
WEBCORE_EXPORT KeyboardEvent(const PlatformKeyboardEvent&, AbstractView*);
KeyboardEvent(const AtomicString&, const KeyboardEventInit&);
std::unique_ptr<PlatformKeyboardEvent> m_keyEvent;
String m_keyIdentifier;
unsigned m_location;
bool m_altGraphKey : 1;
#if PLATFORM(COCOA)
bool m_handledByInputMethod;
Vector<KeypressCommand> m_keypressCommands;
#endif
};
KeyboardEvent* findKeyboardEvent(Event*);
}
SPECIALIZE_TYPE_TRAITS_EVENT(KeyboardEvent)
#endif // KeyboardEvent_h