PlatformKeyboardEvent.h [plain text]
#ifndef PlatformKeyboardEvent_h
#define PlatformKeyboardEvent_h
#include "PlatformString.h"
#if PLATFORM(MAC)
#include <wtf/RetainPtr.h>
#ifdef __OBJC__
@class NSEvent;
#else
class NSEvent;
#endif
#endif
#if PLATFORM(WIN)
typedef struct HWND__ *HWND;
typedef unsigned WPARAM;
typedef long LPARAM;
#endif
#if PLATFORM(GTK)
typedef struct _GdkEventKey GdkEventKey;
#endif
#if PLATFORM(QT)
QT_BEGIN_NAMESPACE
class QKeyEvent;
QT_END_NAMESPACE
#endif
#if PLATFORM(WX)
class wxKeyEvent;
#endif
#if PLATFORM(HAIKU)
class BMessage;
#endif
#if PLATFORM(EFL)
typedef struct _Evas_Event_Key_Down Evas_Event_Key_Down;
typedef struct _Evas_Event_Key_Up Evas_Event_Key_Up;
#endif
#if PLATFORM(BREWMP)
typedef unsigned short uint16;
typedef unsigned long int uint32;
#define AEEEvent uint16
#endif
namespace WebCore {
class PlatformKeyboardEvent {
WTF_MAKE_FAST_ALLOCATED;
public:
enum Type {
KeyDown,
KeyUp,
RawKeyDown,
Char
};
enum ModifierKey {
AltKey = 1 << 0,
CtrlKey = 1 << 1,
MetaKey = 1 << 2,
ShiftKey = 1 << 3
};
PlatformKeyboardEvent()
: m_type(KeyDown)
, m_autoRepeat(false)
, m_windowsVirtualKeyCode(0)
, m_nativeVirtualKeyCode(0)
, m_isKeypad(false)
, m_shiftKey(false)
, m_ctrlKey(false)
, m_altKey(false)
, m_metaKey(false)
#if PLATFORM(WIN) || PLATFORM(CHROMIUM)
, m_isSystemKey(false)
#endif
#if PLATFORM(GTK)
, m_gdkEventKey(0)
#endif
#if PLATFORM(QT)
, m_qtEvent(0)
#endif
{
}
Type type() const { return m_type; }
void disambiguateKeyDownEvent(Type, bool backwardCompatibilityMode = false);
String text() const { return m_text; }
String unmodifiedText() const { return m_unmodifiedText; }
int windowsVirtualKeyCode() const { return m_windowsVirtualKeyCode; }
void setWindowsVirtualKeyCode(int code) { m_windowsVirtualKeyCode = code; }
int nativeVirtualKeyCode() const { return m_nativeVirtualKeyCode; }
void setNativeVirtualKeyCode(int code) { m_nativeVirtualKeyCode = code; }
String keyIdentifier() const { return m_keyIdentifier; }
bool isAutoRepeat() const { return m_autoRepeat; }
void setIsAutoRepeat(bool in) { m_autoRepeat = in; }
bool isKeypad() const { return m_isKeypad; }
bool shiftKey() const { return m_shiftKey; }
bool ctrlKey() const { return m_ctrlKey; }
bool altKey() const { return m_altKey; }
bool metaKey() const { return m_metaKey; }
unsigned modifiers() const {
return (altKey() ? AltKey : 0)
| (ctrlKey() ? CtrlKey : 0)
| (metaKey() ? MetaKey : 0)
| (shiftKey() ? ShiftKey : 0);
}
static bool currentCapsLockState();
static void getCurrentModifierState(bool& shiftKey, bool& ctrlKey, bool& altKey, bool& metaKey);
#if PLATFORM(MAC)
PlatformKeyboardEvent(NSEvent*);
NSEvent* macEvent() const { return m_macEvent.get(); }
#endif
#if PLATFORM(WIN)
PlatformKeyboardEvent(HWND, WPARAM, LPARAM, Type, bool);
#endif
#if PLATFORM(GTK)
PlatformKeyboardEvent(GdkEventKey*);
GdkEventKey* gdkEventKey() const;
static String keyIdentifierForGdkKeyCode(unsigned);
static int windowsKeyCodeForGdkKeyCode(unsigned);
static String singleCharacterString(unsigned);
#endif
#if PLATFORM(QT)
PlatformKeyboardEvent(QKeyEvent*);
QKeyEvent* qtEvent() const { return m_qtEvent; }
uint32_t nativeModifiers() const;
uint32_t nativeScanCode() const;
#endif
#if PLATFORM(WX)
PlatformKeyboardEvent(wxKeyEvent&);
#endif
#if PLATFORM(HAIKU)
PlatformKeyboardEvent(BMessage*);
#endif
#if PLATFORM(BREWMP)
PlatformKeyboardEvent(AEEEvent, uint16, uint32, Type);
#endif
#if PLATFORM(WIN) || PLATFORM(CHROMIUM)
bool isSystemKey() const { return m_isSystemKey; }
#endif
#if PLATFORM(EFL)
PlatformKeyboardEvent(const Evas_Event_Key_Down*);
PlatformKeyboardEvent(const Evas_Event_Key_Up*);
#endif
protected:
Type m_type;
String m_text;
String m_unmodifiedText;
String m_keyIdentifier;
bool m_autoRepeat;
int m_windowsVirtualKeyCode;
int m_nativeVirtualKeyCode;
bool m_isKeypad;
bool m_shiftKey;
bool m_ctrlKey;
bool m_altKey;
bool m_metaKey;
#if PLATFORM(MAC)
RetainPtr<NSEvent> m_macEvent;
#endif
#if PLATFORM(WIN) || PLATFORM(CHROMIUM)
bool m_isSystemKey;
#endif
#if PLATFORM(GTK)
GdkEventKey* m_gdkEventKey;
#endif
#if PLATFORM(QT)
QKeyEvent* m_qtEvent;
#endif
};
#if PLATFORM(QT)
String keyIdentifierForQtKeyCode(int keyCode);
int windowsKeyCodeForKeyEvent(unsigned int keycode, bool isKeypad = false);
#endif
}
#endif // PlatformKeyboardEvent_h