PlatformKeyboardEvent.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. #ifndef PlatformKeyboardEvent_h
  27. #define PlatformKeyboardEvent_h
  28. #include "PlatformEvent.h"
  29. #if OS(WINDOWS)
  30. #include "WindowsExtras.h"
  31. #endif
  32. #include <wtf/text/WTFString.h>
  33. #if PLATFORM(MAC)
  34. #include <wtf/RetainPtr.h>
  35. OBJC_CLASS NSEvent;
  36. #endif
  37. #if PLATFORM(GTK)
  38. typedef struct _GdkEventKey GdkEventKey;
  39. #include "CompositionResults.h"
  40. #endif
  41. #if PLATFORM(QT)
  42. QT_BEGIN_NAMESPACE
  43. class QKeyEvent;
  44. QT_END_NAMESPACE
  45. #endif
  46. #if PLATFORM(BLACKBERRY)
  47. namespace BlackBerry {
  48. namespace Platform {
  49. class KeyboardEvent;
  50. }
  51. }
  52. #endif
  53. #if PLATFORM(MANX)
  54. #include <manx/KeyboardEvent.h>
  55. #endif
  56. #if PLATFORM(EFL)
  57. typedef struct _Evas_Event_Key_Down Evas_Event_Key_Down;
  58. typedef struct _Evas_Event_Key_Up Evas_Event_Key_Up;
  59. #endif
  60. namespace WebCore {
  61. class PlatformKeyboardEvent : public PlatformEvent {
  62. WTF_MAKE_FAST_ALLOCATED;
  63. public:
  64. PlatformKeyboardEvent()
  65. : PlatformEvent(PlatformEvent::KeyDown)
  66. , m_windowsVirtualKeyCode(0)
  67. , m_nativeVirtualKeyCode(0)
  68. , m_macCharCode(0)
  69. , m_autoRepeat(false)
  70. , m_isKeypad(false)
  71. , m_isSystemKey(false)
  72. #if PLATFORM(BLACKBERRY)
  73. , m_unmodifiedCharacter(0)
  74. #endif
  75. #if PLATFORM(GTK)
  76. , m_gdkEventKey(0)
  77. #endif
  78. #if PLATFORM(QT)
  79. , m_qtEvent(0)
  80. #endif
  81. {
  82. }
  83. 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)
  84. : PlatformEvent(type, modifiers, timestamp)
  85. , m_text(text)
  86. , m_unmodifiedText(unmodifiedText)
  87. , m_keyIdentifier(keyIdentifier)
  88. , m_windowsVirtualKeyCode(windowsVirtualKeyCode)
  89. , m_nativeVirtualKeyCode(nativeVirtualKeyCode)
  90. , m_macCharCode(macCharCode)
  91. , m_autoRepeat(isAutoRepeat)
  92. , m_isKeypad(isKeypad)
  93. , m_isSystemKey(isSystemKey)
  94. {
  95. }
  96. ~PlatformKeyboardEvent();
  97. void disambiguateKeyDownEvent(Type, bool backwardCompatibilityMode = false); // Only used on platforms that need it, i.e. those that generate KeyDown events.
  98. // Text as as generated by processing a virtual key code with a keyboard layout
  99. // (in most cases, just a character code, but the layout can emit several
  100. // characters in a single keypress event on some platforms).
  101. // This may bear no resemblance to the ultimately inserted text if an input method
  102. // processes the input.
  103. // Will be null for KeyUp and RawKeyDown events.
  104. String text() const { return m_text; }
  105. // Text that would have been generated by the keyboard if no modifiers were pressed
  106. // (except for Shift); useful for shortcut (accelerator) key handling.
  107. // Otherwise, same as text().
  108. String unmodifiedText() const { return m_unmodifiedText; }
  109. String keyIdentifier() const { return m_keyIdentifier; }
  110. // Most compatible Windows virtual key code associated with the event.
  111. // Zero for Char events.
  112. int windowsVirtualKeyCode() const { return m_windowsVirtualKeyCode; }
  113. void setWindowsVirtualKeyCode(int code) { m_windowsVirtualKeyCode = code; }
  114. int nativeVirtualKeyCode() const { return m_nativeVirtualKeyCode; }
  115. int macCharCode() const { return m_macCharCode; }
  116. bool isAutoRepeat() const { return m_autoRepeat; }
  117. bool isKeypad() const { return m_isKeypad; }
  118. bool isSystemKey() const { return m_isSystemKey; }
  119. static bool currentCapsLockState();
  120. static void getCurrentModifierState(bool& shiftKey, bool& ctrlKey, bool& altKey, bool& metaKey);
  121. #if PLATFORM(BLACKBERRY)
  122. unsigned unmodifiedCharacter() const { return m_unmodifiedCharacter; }
  123. #endif
  124. #if PLATFORM(MAC)
  125. NSEvent* macEvent() const { return m_macEvent.get(); }
  126. #endif
  127. #if PLATFORM(WIN)
  128. PlatformKeyboardEvent(HWND, WPARAM, LPARAM, Type, bool);
  129. #endif
  130. #if PLATFORM(GTK)
  131. PlatformKeyboardEvent(GdkEventKey*, const CompositionResults&);
  132. GdkEventKey* gdkEventKey() const { return m_gdkEventKey; }
  133. const CompositionResults& compositionResults() const { return m_compositionResults; }
  134. // Used by WebKit2
  135. static String keyIdentifierForGdkKeyCode(unsigned);
  136. static int windowsKeyCodeForGdkKeyCode(unsigned);
  137. static String singleCharacterString(unsigned);
  138. #endif
  139. #if PLATFORM(QT)
  140. PlatformKeyboardEvent(QKeyEvent*);
  141. QKeyEvent* qtEvent() const { return m_qtEvent; }
  142. uint32_t nativeModifiers() const;
  143. uint32_t nativeScanCode() const;
  144. #endif
  145. #if PLATFORM(BLACKBERRY)
  146. PlatformKeyboardEvent(const BlackBerry::Platform::KeyboardEvent&);
  147. #endif
  148. #if PLATFORM(EFL)
  149. explicit PlatformKeyboardEvent(const Evas_Event_Key_Down*);
  150. explicit PlatformKeyboardEvent(const Evas_Event_Key_Up*);
  151. #endif
  152. #if PLATFORM(MANX)
  153. PlatformKeyboardEvent(const Manx::KeyboardEvent&);
  154. #endif
  155. protected:
  156. String m_text;
  157. String m_unmodifiedText;
  158. String m_keyIdentifier;
  159. int m_windowsVirtualKeyCode;
  160. int m_nativeVirtualKeyCode;
  161. int m_macCharCode;
  162. bool m_autoRepeat;
  163. bool m_isKeypad;
  164. bool m_isSystemKey;
  165. #if PLATFORM(BLACKBERRY)
  166. unsigned m_unmodifiedCharacter;
  167. #endif
  168. #if PLATFORM(MAC)
  169. RetainPtr<NSEvent> m_macEvent;
  170. #endif
  171. #if PLATFORM(GTK)
  172. GdkEventKey* m_gdkEventKey;
  173. CompositionResults m_compositionResults;
  174. #endif
  175. #if PLATFORM(QT)
  176. QKeyEvent* m_qtEvent;
  177. #endif
  178. };
  179. #if PLATFORM(QT)
  180. // Used by WebKit2.
  181. String keyIdentifierForQtKeyCode(int keyCode);
  182. int windowsKeyCodeForKeyEvent(unsigned int keycode, bool isKeypad = false);
  183. #endif
  184. } // namespace WebCore
  185. #endif // PlatformKeyboardEvent_h