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