2 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved.
3 * Copyright (C) 2008 Collabora, Ltd. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
27 #ifndef PlatformKeyboardEvent_h
28 #define PlatformKeyboardEvent_h
30 #include "PlatformEvent.h"
32 #include "WindowsExtras.h"
34 #include <wtf/text/WTFString.h>
37 #include <wtf/RetainPtr.h>
42 typedef struct _GdkEventKey GdkEventKey;
43 #include "CompositionResults.h"
56 #if PLATFORM(BLACKBERRY)
57 namespace BlackBerry {
65 typedef struct _Evas_Event_Key_Down Evas_Event_Key_Down;
66 typedef struct _Evas_Event_Key_Up Evas_Event_Key_Up;
71 class PlatformKeyboardEvent : public PlatformEvent {
72 WTF_MAKE_FAST_ALLOCATED;
74 PlatformKeyboardEvent()
75 : PlatformEvent(PlatformEvent::KeyDown)
76 , m_windowsVirtualKeyCode(0)
77 , m_nativeVirtualKeyCode(0)
81 , m_isSystemKey(false)
82 #if PLATFORM(BLACKBERRY)
83 , m_unmodifiedCharacter(0)
94 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)
95 : PlatformEvent(type, modifiers, timestamp)
97 , m_unmodifiedText(unmodifiedText)
98 , m_keyIdentifier(keyIdentifier)
99 , m_windowsVirtualKeyCode(windowsVirtualKeyCode)
100 , m_nativeVirtualKeyCode(nativeVirtualKeyCode)
101 , m_macCharCode(macCharCode)
102 , m_autoRepeat(isAutoRepeat)
103 , m_isKeypad(isKeypad)
104 , m_isSystemKey(isSystemKey)
108 void disambiguateKeyDownEvent(Type, bool backwardCompatibilityMode = false); // Only used on platforms that need it, i.e. those that generate KeyDown events.
110 // Text as as generated by processing a virtual key code with a keyboard layout
111 // (in most cases, just a character code, but the layout can emit several
112 // characters in a single keypress event on some platforms).
113 // This may bear no resemblance to the ultimately inserted text if an input method
114 // processes the input.
115 // Will be null for KeyUp and RawKeyDown events.
116 String text() const { return m_text; }
118 // Text that would have been generated by the keyboard if no modifiers were pressed
119 // (except for Shift); useful for shortcut (accelerator) key handling.
120 // Otherwise, same as text().
121 String unmodifiedText() const { return m_unmodifiedText; }
123 String keyIdentifier() const { return m_keyIdentifier; }
125 // Most compatible Windows virtual key code associated with the event.
126 // Zero for Char events.
127 int windowsVirtualKeyCode() const { return m_windowsVirtualKeyCode; }
128 void setWindowsVirtualKeyCode(int code) { m_windowsVirtualKeyCode = code; }
130 int nativeVirtualKeyCode() const { return m_nativeVirtualKeyCode; }
131 int macCharCode() const { return m_macCharCode; }
133 bool isAutoRepeat() const { return m_autoRepeat; }
134 bool isKeypad() const { return m_isKeypad; }
135 bool isSystemKey() const { return m_isSystemKey; }
137 static bool currentCapsLockState();
138 static void getCurrentModifierState(bool& shiftKey, bool& ctrlKey, bool& altKey, bool& metaKey);
140 #if PLATFORM(BLACKBERRY)
141 unsigned short unmodifiedCharacter() const { return m_unmodifiedCharacter; }
145 NSEvent* macEvent() const { return m_macEvent.get(); }
149 PlatformKeyboardEvent(HWND, WPARAM, LPARAM, Type, bool);
153 PlatformKeyboardEvent(GdkEventKey*, const CompositionResults&);
154 GdkEventKey* gdkEventKey() const { return m_gdkEventKey; }
155 const CompositionResults& compositionResults() const { return m_compositionResults; }
158 static String keyIdentifierForGdkKeyCode(unsigned);
159 static int windowsKeyCodeForGdkKeyCode(unsigned);
160 static String singleCharacterString(unsigned);
164 PlatformKeyboardEvent(QKeyEvent*);
165 QKeyEvent* qtEvent() const { return m_qtEvent; }
166 uint32_t nativeModifiers() const;
167 uint32_t nativeScanCode() const;
171 PlatformKeyboardEvent(wxKeyEvent&);
174 #if PLATFORM(BLACKBERRY)
175 PlatformKeyboardEvent(const BlackBerry::Platform::KeyboardEvent&);
179 explicit PlatformKeyboardEvent(const Evas_Event_Key_Down*);
180 explicit PlatformKeyboardEvent(const Evas_Event_Key_Up*);
185 String m_unmodifiedText;
186 String m_keyIdentifier;
187 int m_windowsVirtualKeyCode;
188 int m_nativeVirtualKeyCode;
194 #if PLATFORM(BLACKBERRY)
195 unsigned short m_unmodifiedCharacter;
199 RetainPtr<NSEvent> m_macEvent;
202 GdkEventKey* m_gdkEventKey;
203 CompositionResults m_compositionResults;
206 QKeyEvent* m_qtEvent;
212 String keyIdentifierForQtKeyCode(int keyCode);
213 int windowsKeyCodeForKeyEvent(unsigned int keycode, bool isKeypad = false);
216 } // namespace WebCore
218 #endif // PlatformKeyboardEvent_h