1/* 2 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved. 3 * Copyright (C) 2008 Collabora, Ltd. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#ifndef PlatformKeyboardEvent_h 28#define PlatformKeyboardEvent_h 29 30#include "PlatformEvent.h" 31#if OS(WINDOWS) 32#include "WindowsExtras.h" 33#endif 34#include <wtf/text/WTFString.h> 35 36#if PLATFORM(MAC) 37#include <wtf/RetainPtr.h> 38OBJC_CLASS NSEvent; 39#endif 40 41#if PLATFORM(GTK) 42typedef struct _GdkEventKey GdkEventKey; 43#include "CompositionResults.h" 44#endif 45 46#if PLATFORM(QT) 47QT_BEGIN_NAMESPACE 48class QKeyEvent; 49QT_END_NAMESPACE 50#endif 51 52#if PLATFORM(BLACKBERRY) 53namespace BlackBerry { 54namespace Platform { 55class KeyboardEvent; 56} 57} 58#endif 59 60#if PLATFORM(EFL) 61typedef struct _Evas_Event_Key_Down Evas_Event_Key_Down; 62typedef struct _Evas_Event_Key_Up Evas_Event_Key_Up; 63#endif 64 65namespace WebCore { 66 67 class PlatformKeyboardEvent : public PlatformEvent { 68 WTF_MAKE_FAST_ALLOCATED; 69 public: 70 PlatformKeyboardEvent() 71 : PlatformEvent(PlatformEvent::KeyDown) 72 , m_windowsVirtualKeyCode(0) 73 , m_nativeVirtualKeyCode(0) 74 , m_macCharCode(0) 75 , m_autoRepeat(false) 76 , m_isKeypad(false) 77 , m_isSystemKey(false) 78#if PLATFORM(BLACKBERRY) 79 , m_unmodifiedCharacter(0) 80#endif 81#if PLATFORM(GTK) 82 , m_gdkEventKey(0) 83#endif 84#if PLATFORM(QT) 85 , m_qtEvent(0) 86#endif 87 { 88 } 89 90 PlatformKeyboardEvent(Type type, const String& text, const String& unmodifiedText, const String& keyIdentifier, int windowsVirtualKeyCode, int nativeVirtualKeyCode, int macCharCode, bool isAutoRepeat, bool isKeypad, bool isSystemKey, Modifiers modifiers, double timestamp) 91 : PlatformEvent(type, modifiers, timestamp) 92 , m_text(text) 93 , m_unmodifiedText(unmodifiedText) 94 , m_keyIdentifier(keyIdentifier) 95 , m_windowsVirtualKeyCode(windowsVirtualKeyCode) 96 , m_nativeVirtualKeyCode(nativeVirtualKeyCode) 97 , m_macCharCode(macCharCode) 98 , m_autoRepeat(isAutoRepeat) 99 , m_isKeypad(isKeypad) 100 , m_isSystemKey(isSystemKey) 101 { 102 } 103 104 void disambiguateKeyDownEvent(Type, bool backwardCompatibilityMode = false); // Only used on platforms that need it, i.e. those that generate KeyDown events. 105 106 // Text as as generated by processing a virtual key code with a keyboard layout 107 // (in most cases, just a character code, but the layout can emit several 108 // characters in a single keypress event on some platforms). 109 // This may bear no resemblance to the ultimately inserted text if an input method 110 // processes the input. 111 // Will be null for KeyUp and RawKeyDown events. 112 String text() const { return m_text; } 113 114 // Text that would have been generated by the keyboard if no modifiers were pressed 115 // (except for Shift); useful for shortcut (accelerator) key handling. 116 // Otherwise, same as text(). 117 String unmodifiedText() const { return m_unmodifiedText; } 118 119 String keyIdentifier() const { return m_keyIdentifier; } 120 121 // Most compatible Windows virtual key code associated with the event. 122 // Zero for Char events. 123 int windowsVirtualKeyCode() const { return m_windowsVirtualKeyCode; } 124 void setWindowsVirtualKeyCode(int code) { m_windowsVirtualKeyCode = code; } 125 126 int nativeVirtualKeyCode() const { return m_nativeVirtualKeyCode; } 127 int macCharCode() const { return m_macCharCode; } 128 129 bool isAutoRepeat() const { return m_autoRepeat; } 130 bool isKeypad() const { return m_isKeypad; } 131 bool isSystemKey() const { return m_isSystemKey; } 132 133 static bool currentCapsLockState(); 134 static void getCurrentModifierState(bool& shiftKey, bool& ctrlKey, bool& altKey, bool& metaKey); 135 136#if PLATFORM(BLACKBERRY) 137 unsigned unmodifiedCharacter() const { return m_unmodifiedCharacter; } 138#endif 139 140#if PLATFORM(MAC) 141 NSEvent* macEvent() const { return m_macEvent.get(); } 142#endif 143 144#if PLATFORM(WIN) 145 PlatformKeyboardEvent(HWND, WPARAM, LPARAM, Type, bool); 146#endif 147 148#if PLATFORM(GTK) 149 PlatformKeyboardEvent(GdkEventKey*, const CompositionResults&); 150 GdkEventKey* gdkEventKey() const { return m_gdkEventKey; } 151 const CompositionResults& compositionResults() const { return m_compositionResults; } 152 153 // Used by WebKit2 154 static String keyIdentifierForGdkKeyCode(unsigned); 155 static int windowsKeyCodeForGdkKeyCode(unsigned); 156 static String singleCharacterString(unsigned); 157#endif 158 159#if PLATFORM(QT) 160 PlatformKeyboardEvent(QKeyEvent*); 161 QKeyEvent* qtEvent() const { return m_qtEvent; } 162 uint32_t nativeModifiers() const; 163 uint32_t nativeScanCode() const; 164#endif 165 166#if PLATFORM(BLACKBERRY) 167 PlatformKeyboardEvent(const BlackBerry::Platform::KeyboardEvent&); 168#endif 169 170#if PLATFORM(EFL) 171 explicit PlatformKeyboardEvent(const Evas_Event_Key_Down*); 172 explicit PlatformKeyboardEvent(const Evas_Event_Key_Up*); 173#endif 174 175 protected: 176 String m_text; 177 String m_unmodifiedText; 178 String m_keyIdentifier; 179 int m_windowsVirtualKeyCode; 180 int m_nativeVirtualKeyCode; 181 int m_macCharCode; 182 bool m_autoRepeat; 183 bool m_isKeypad; 184 bool m_isSystemKey; 185 186#if PLATFORM(BLACKBERRY) 187 unsigned m_unmodifiedCharacter; 188#endif 189 190#if PLATFORM(MAC) 191 RetainPtr<NSEvent> m_macEvent; 192#endif 193#if PLATFORM(GTK) 194 GdkEventKey* m_gdkEventKey; 195 CompositionResults m_compositionResults; 196#endif 197#if PLATFORM(QT) 198 QKeyEvent* m_qtEvent; 199#endif 200 }; 201 202#if PLATFORM(QT) 203// Used by WebKit2. 204String keyIdentifierForQtKeyCode(int keyCode); 205int windowsKeyCodeForKeyEvent(unsigned int keycode, bool isKeypad = false); 206#endif 207 208} // namespace WebCore 209 210#endif // PlatformKeyboardEvent_h 211