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