Rubber-stamped by Brady Eidson.
[webbrowser.git] / WebCore / platform / PlatformKeyboardEvent.h
blob5d847c87bcdda2e7ebc228db2c0cad28e95bbadf
1 /*
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
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.
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 "PlatformString.h"
31 #include <wtf/Platform.h>
33 #if PLATFORM(MAC)
34 #include <wtf/RetainPtr.h>
35 #ifdef __OBJC__
36 @class NSEvent;
37 #else
38 class NSEvent;
39 #endif
40 #endif
42 #if PLATFORM(WIN)
43 typedef struct HWND__ *HWND;
44 typedef unsigned WPARAM;
45 typedef long LPARAM;
46 #endif
48 #if PLATFORM(GTK)
49 typedef struct _GdkEventKey GdkEventKey;
50 #endif
52 #if PLATFORM(QT)
53 QT_BEGIN_NAMESPACE
54 class QKeyEvent;
55 QT_END_NAMESPACE
56 #endif
58 #if PLATFORM(WX)
59 class wxKeyEvent;
60 #endif
62 #if PLATFORM(HAIKU)
63 class BMessage;
64 #endif
66 namespace WebCore {
68 class PlatformKeyboardEvent : public FastAllocBase {
69 public:
70 enum Type {
71 // KeyDown is sent by platforms such as Mac OS X, gtk and Qt, and has information about both physical pressed key, and its translation.
72 // For DOM processing, it needs to be disambiguated as RawKeyDown or Char event.
73 KeyDown,
75 // KeyUp is sent by all platforms.
76 KeyUp,
78 // These events are sent by platforms such as Windows and wxWidgets. RawKeyDown only has information about a physical key, and Char
79 // only has information about a character it was translated into.
80 RawKeyDown,
81 Char
84 enum ModifierKey {
85 AltKey = 1 << 0,
86 CtrlKey = 1 << 1,
87 MetaKey = 1 << 2,
88 ShiftKey = 1 << 3,
91 Type type() const { return m_type; }
92 void disambiguateKeyDownEvent(Type, bool backwardCompatibilityMode = false); // Only used on platforms that need it, i.e. those that generate KeyDown events.
94 // Text as as generated by processing a virtual key code with a keyboard layout
95 // (in most cases, just a character code, but the layout can emit several
96 // characters in a single keypress event on some platforms).
97 // This may bear no resemblance to the ultimately inserted text if an input method
98 // processes the input.
99 // Will be null for KeyUp and RawKeyDown events.
100 String text() const { return m_text; }
102 // Text that would have been generated by the keyboard if no modifiers were pressed
103 // (except for Shift); useful for shortcut (accelerator) key handling.
104 // Otherwise, same as text().
105 String unmodifiedText() const { return m_unmodifiedText; }
107 // Most compatible Windows virtual key code associated with the event.
108 // Zero for Char events.
109 int windowsVirtualKeyCode() const { return m_windowsVirtualKeyCode; }
110 void setWindowsVirtualKeyCode(int code) { m_windowsVirtualKeyCode = code; }
112 int nativeVirtualKeyCode() const { return m_nativeVirtualKeyCode; }
113 void setNativeVirtualKeyCode(int code) { m_nativeVirtualKeyCode = code; }
115 String keyIdentifier() const { return m_keyIdentifier; }
116 bool isAutoRepeat() const { return m_autoRepeat; }
117 void setIsAutoRepeat(bool in) { m_autoRepeat = in; }
118 bool isKeypad() const { return m_isKeypad; }
119 bool shiftKey() const { return m_shiftKey; }
120 bool ctrlKey() const { return m_ctrlKey; }
121 bool altKey() const { return m_altKey; }
122 bool metaKey() const { return m_metaKey; }
123 unsigned modifiers() const {
124 return (altKey() ? AltKey : 0)
125 | (ctrlKey() ? CtrlKey : 0)
126 | (metaKey() ? MetaKey : 0)
127 | (shiftKey() ? ShiftKey : 0);
130 static bool currentCapsLockState();
132 #if PLATFORM(MAC)
133 PlatformKeyboardEvent();
134 PlatformKeyboardEvent(NSEvent*);
135 NSEvent* macEvent() const { return m_macEvent.get(); }
136 #endif
138 #if PLATFORM(WIN)
139 PlatformKeyboardEvent(HWND, WPARAM, LPARAM, Type, bool);
140 #endif
142 #if PLATFORM(GTK)
143 PlatformKeyboardEvent(GdkEventKey*);
144 GdkEventKey* gdkEventKey() const;
145 #endif
147 #if PLATFORM(QT)
148 PlatformKeyboardEvent(QKeyEvent*);
149 QKeyEvent* qtEvent() const { return m_qtEvent; }
150 #endif
152 #if PLATFORM(WX)
153 PlatformKeyboardEvent(wxKeyEvent&);
154 #endif
156 #if PLATFORM(HAIKU)
157 PlatformKeyboardEvent(BMessage*);
158 #endif
160 #if PLATFORM(WIN) || PLATFORM(CHROMIUM)
161 bool isSystemKey() const { return m_isSystemKey; }
162 #endif
164 protected:
165 Type m_type;
166 String m_text;
167 String m_unmodifiedText;
168 String m_keyIdentifier;
169 bool m_autoRepeat;
170 int m_windowsVirtualKeyCode;
171 int m_nativeVirtualKeyCode;
172 bool m_isKeypad;
173 bool m_shiftKey;
174 bool m_ctrlKey;
175 bool m_altKey;
176 bool m_metaKey;
178 #if PLATFORM(MAC)
179 RetainPtr<NSEvent> m_macEvent;
180 #endif
181 #if PLATFORM(WIN) || PLATFORM(CHROMIUM)
182 bool m_isSystemKey;
183 #endif
184 #if PLATFORM(GTK)
185 GdkEventKey* m_gdkEventKey;
186 #endif
187 #if PLATFORM(QT)
188 QKeyEvent* m_qtEvent;
189 #endif
192 } // namespace WebCore
194 #endif // PlatformKeyboardEvent_h