OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef WEBKIT_GLUE_WEBINPUTEVENT_H_ | 5 #ifndef WEBKIT_GLUE_WEBINPUTEVENT_H_ |
6 #define WEBKIT_GLUE_WEBINPUTEVENT_H_ | 6 #define WEBKIT_GLUE_WEBINPUTEVENT_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/string16.h" | |
10 | 9 |
11 #if defined(OS_WIN) | 10 #if defined(OS_WIN) |
12 #include <windows.h> | 11 #include <windows.h> |
13 #elif defined(OS_MACOSX) | 12 #elif defined(OS_MACOSX) |
| 13 #include <vector> |
14 #ifdef __OBJC__ | 14 #ifdef __OBJC__ |
15 @class NSEvent; | 15 @class NSEvent; |
16 @class NSView; | 16 @class NSView; |
17 #else | 17 #else |
18 class NSEvent; | 18 class NSEvent; |
19 class NSView; | 19 class NSView; |
20 #endif // __OBJC__ | 20 #endif // __OBJC__ |
21 #elif defined(OS_LINUX) | 21 #elif defined(OS_LINUX) |
22 #include <glib.h> | |
23 typedef struct _GdkEventButton GdkEventButton; | 22 typedef struct _GdkEventButton GdkEventButton; |
24 typedef struct _GdkEventMotion GdkEventMotion; | 23 typedef struct _GdkEventMotion GdkEventMotion; |
25 typedef struct _GdkEventScroll GdkEventScroll; | 24 typedef struct _GdkEventScroll GdkEventScroll; |
26 typedef struct _GdkEventKey GdkEventKey; | 25 typedef struct _GdkEventKey GdkEventKey; |
27 #endif | 26 #endif |
28 | 27 |
29 // The classes defined in this file are intended to be used with WebView's | 28 // The classes defined in this file are intended to be used with WebView's |
30 // HandleInputEvent method. These event types are cross-platform; however, | 29 // HandleInputEvent method. These event types are cross-platform; however, |
31 // there are platform-specific constructors that accept native UI events. | 30 // there are platform-specific constructors that accept native UI events. |
32 // | 31 // |
33 // The fields of these event classes roughly correspond to the fields required | 32 // The fields of these event classes roughly correspond to the fields required |
34 // by WebCore's platform event classes. | 33 // by WebCore's platform event classes. |
35 // | |
36 // WARNING! These classes must remain PODs (plain old data). They will be | |
37 // "serialized" by shipping their raw bytes across the wire, so they must not | |
38 // contain any non-bit-copyable member variables! | |
39 | 34 |
40 // WebInputEvent -------------------------------------------------------------- | 35 // WebInputEvent -------------------------------------------------------------- |
41 | 36 |
42 class WebInputEvent { | 37 class WebInputEvent { |
43 public: | 38 public: |
44 WebInputEvent() : modifiers(0) { } | 39 WebInputEvent() : modifiers(0) { } |
45 | 40 |
46 // There are two schemes used for keyboard input. On Windows (and, | |
47 // interestingly enough, on Mac Carbon) there are two events for a keypress. | |
48 // One is a raw keydown, which provides the keycode only. If the app doesn't | |
49 // handle that, then the system runs key translation to create an event | |
50 // containing the generated character and pumps that event. In such a scheme, | |
51 // those two events are translated to RAW_KEY_DOWN and CHAR events | |
52 // respectively. In Cocoa and Gtk, key events contain both the keycode and any | |
53 // translation into actual text. In such a case, WebCore will eventually need | |
54 // to split the events (see disambiguateKeyDownEvent and its callers) but we | |
55 // don't worry about that here. We just use a different type (KEY_DOWN) to | |
56 // indicate this. | |
57 enum Type { | 41 enum Type { |
58 // WebMouseEvent | 42 // WebMouseEvent |
59 MOUSE_DOWN, | 43 MOUSE_DOWN, |
60 MOUSE_UP, | 44 MOUSE_UP, |
61 MOUSE_MOVE, | 45 MOUSE_MOVE, |
62 MOUSE_LEAVE, | 46 MOUSE_LEAVE, |
63 MOUSE_DOUBLE_CLICK, | 47 MOUSE_DOUBLE_CLICK, |
64 | 48 |
65 // WebMouseWheelEvent | 49 // WebMouseWheelEvent |
66 MOUSE_WHEEL, | 50 MOUSE_WHEEL, |
67 | 51 |
68 // WebKeyboardEvent | 52 // WebKeyboardEvent |
69 RAW_KEY_DOWN, | |
70 KEY_DOWN, | 53 KEY_DOWN, |
71 KEY_UP, | 54 KEY_UP, |
72 CHAR | 55 CHAR |
73 }; | 56 }; |
74 | 57 |
75 enum Modifiers { | 58 enum Modifiers { |
76 // modifiers for all events: | 59 // modifiers for all events: |
77 SHIFT_KEY = 1 << 0, | 60 SHIFT_KEY = 1 << 0, |
78 CTRL_KEY = 1 << 1, | 61 CTRL_KEY = 1 << 1, |
79 ALT_KEY = 1 << 2, | 62 ALT_KEY = 1 << 2, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 WebMouseWheelEvent(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); | 114 WebMouseWheelEvent(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); |
132 #elif defined(OS_MACOSX) | 115 #elif defined(OS_MACOSX) |
133 WebMouseWheelEvent(NSEvent *event, NSView* view); | 116 WebMouseWheelEvent(NSEvent *event, NSView* view); |
134 #elif defined(OS_LINUX) | 117 #elif defined(OS_LINUX) |
135 explicit WebMouseWheelEvent(const GdkEventScroll* event); | 118 explicit WebMouseWheelEvent(const GdkEventScroll* event); |
136 #endif | 119 #endif |
137 }; | 120 }; |
138 | 121 |
139 // WebKeyboardEvent ----------------------------------------------------------- | 122 // WebKeyboardEvent ----------------------------------------------------------- |
140 | 123 |
141 // Caps on string lengths so we can make them static arrays and keep them PODs. | |
142 const size_t kTextLengthCap = 4; | |
143 // http://www.w3.org/TR/DOM-Level-3-Events/keyset.html lists the identifiers. | |
144 // The longest is 18 characters, so we'll round up to the next multiple of 4. | |
145 const size_t kIdentifierLengthCap = 20; | |
146 | |
147 class WebKeyboardEvent : public WebInputEvent { | 124 class WebKeyboardEvent : public WebInputEvent { |
148 public: | 125 public: |
149 // |windows_key_code| is the Windows key code associated with this key event. | 126 // The key_code field is the Windows key code associated with this key event. |
150 // Sometimes it's direct from the event (i.e. on Windows), sometimes it's via | 127 // This sometimes matches the ASCII value of the key (for e.g. a-z) but |
151 // a mapping function. If you want a list, see | 128 // officially ignores case, and has its own set of codes for control keys as |
152 // webkit/port/platform/chromium/KeyboardCodes* . | 129 // well as other visible letters like punctuation. |
153 int windows_key_code; | 130 // webkit/port/platform/chromium/KeyboardCodes* is an attempt at defining all |
| 131 // of these keys, but it's not all the way there yet. (E.g., the Windows |
| 132 // implementation there just passes through the code from the windows message |
| 133 // directly.) |
| 134 int key_code; |
154 | 135 |
155 // The actual key code genenerated by the platform. The DOM spec runs on | 136 #if defined(OS_MACOSX) |
156 // Windows-equivalent codes (thus |windows_key_code| above) but it doesn't | 137 // text arrays extracted from the native event. On Mac, there may be |
157 // hurt to have this one around. | 138 // multiple keys sent as a single event if the flags don't change. |
158 int native_key_code; | 139 std::vector<unsigned short> text; |
159 | 140 std::vector<unsigned short> unmodified_text; |
160 // |text| is the text generated by this keystroke. |unmodified_text| is | 141 std::vector<unsigned short> key_identifier; |
161 // |text|, but unmodified by an concurrently-held modifiers (except shift). | 142 #elif defined(OS_WIN) |
162 // This is useful for working out shortcut keys. Linux and Windows guarantee | 143 bool system_key; // Set if we receive a SYSKEYDOWN/WM_SYSKEYUP message. |
163 // one character per event. The Mac does not, but in reality that's all it | 144 MSG actual_message; // Set to the current keyboard message. |
164 // ever gives. We're generous, and cap it a bit longer. | 145 #elif defined(OS_LINUX) |
165 char16 text[kTextLengthCap]; | 146 // The unicode character, if available, corresponding to this key event. |
166 char16 unmodified_text[kTextLengthCap]; | 147 // TODO(evanm): temporary hack for test_shell. Ideally we'd either manage |
167 | 148 // to stuff everything into key_code, or make this field shared by all |
168 // This is a string identifying the key pressed. | 149 // implementations, but this will have to do for now. |
169 char key_identifier[kIdentifierLengthCap]; | 150 wchar_t text; |
170 | |
171 // This identifies whether this event was tagged by the system as being a | |
172 // "system key" event (see | |
173 // http://msdn.microsoft.com/en-us/library/ms646286(VS.85).aspx for details). | |
174 // Other platforms don't have this concept, but it's just easier to leave it | |
175 // always false than ifdef. | |
176 | |
177 bool system_key; | |
178 | |
179 // References to the original event. | |
180 #if defined(OS_WIN) | |
181 MSG actual_message; // Set to the current keyboard message. TODO(avi): remove | |
182 #endif | 151 #endif |
183 | 152 |
184 WebKeyboardEvent() : windows_key_code(0), | 153 WebKeyboardEvent() |
185 native_key_code(0), | 154 : key_code(0) |
186 system_key(false) { | |
187 memset(&text, 0, sizeof(text)); | |
188 memset(&unmodified_text, 0, sizeof(unmodified_text)); | |
189 memset(&key_identifier, 0, sizeof(key_identifier)); | |
190 #if defined(OS_WIN) | 155 #if defined(OS_WIN) |
| 156 , system_key(false) { |
191 memset(&actual_message, 0, sizeof(actual_message)); | 157 memset(&actual_message, 0, sizeof(actual_message)); |
| 158 } |
| 159 #else |
| 160 {} |
192 #endif | 161 #endif |
193 } | |
194 | 162 |
195 #if defined(OS_WIN) | 163 #if defined(OS_WIN) |
196 explicit WebKeyboardEvent(HWND hwnd, UINT message, WPARAM wparam, | 164 WebKeyboardEvent(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); |
197 LPARAM lparam); | |
198 #elif defined(OS_MACOSX) | 165 #elif defined(OS_MACOSX) |
199 explicit WebKeyboardEvent(NSEvent *event); | 166 WebKeyboardEvent(NSEvent *event); |
200 #elif defined(OS_LINUX) | 167 #elif defined(OS_LINUX) |
201 explicit WebKeyboardEvent(const GdkEventKey* event); | 168 explicit WebKeyboardEvent(const GdkEventKey* event); |
202 #endif | 169 #endif |
203 }; | 170 }; |
204 | 171 |
| 172 |
205 #endif // WEBKIT_GLUE_WEBINPUTEVENT_H_ | 173 #endif // WEBKIT_GLUE_WEBINPUTEVENT_H_ |
OLD | NEW |