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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 WebMouseWheelEvent(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); | 131 WebMouseWheelEvent(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); |
115 #elif defined(OS_MACOSX) | 132 #elif defined(OS_MACOSX) |
116 WebMouseWheelEvent(NSEvent *event, NSView* view); | 133 WebMouseWheelEvent(NSEvent *event, NSView* view); |
117 #elif defined(OS_LINUX) | 134 #elif defined(OS_LINUX) |
118 explicit WebMouseWheelEvent(const GdkEventScroll* event); | 135 explicit WebMouseWheelEvent(const GdkEventScroll* event); |
119 #endif | 136 #endif |
120 }; | 137 }; |
121 | 138 |
122 // WebKeyboardEvent ----------------------------------------------------------- | 139 // WebKeyboardEvent ----------------------------------------------------------- |
123 | 140 |
| 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 |
124 class WebKeyboardEvent : public WebInputEvent { | 147 class WebKeyboardEvent : public WebInputEvent { |
125 public: | 148 public: |
126 // The key_code field is the Windows key code associated with this key event. | 149 // |windows_key_code| is the Windows key code associated with this key event. |
127 // This sometimes matches the ASCII value of the key (for e.g. a-z) but | 150 // Sometimes it's direct from the event (i.e. on Windows), sometimes it's via |
128 // officially ignores case, and has its own set of codes for control keys as | 151 // a mapping function. If you want a list, see |
129 // well as other visible letters like punctuation. | 152 // webkit/port/platform/chromium/KeyboardCodes* . |
130 // webkit/port/platform/chromium/KeyboardCodes* is an attempt at defining all | 153 int windows_key_code; |
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; | |
135 | 154 |
136 #if defined(OS_MACOSX) | 155 // The actual key code genenerated by the platform. The DOM spec runs on |
137 // text arrays extracted from the native event. On Mac, there may be | 156 // Windows-equivalent codes (thus |windows_key_code| above) but it doesn't |
138 // multiple keys sent as a single event if the flags don't change. | 157 // hurt to have this one around. |
139 std::vector<unsigned short> text; | 158 int native_key_code; |
140 std::vector<unsigned short> unmodified_text; | 159 |
141 std::vector<unsigned short> key_identifier; | 160 // |text| is the text generated by this keystroke. |unmodified_text| is |
142 #elif defined(OS_WIN) | 161 // |text|, but unmodified by an concurrently-held modifiers (except shift). |
143 bool system_key; // Set if we receive a SYSKEYDOWN/WM_SYSKEYUP message. | 162 // This is useful for working out shortcut keys. Linux and Windows guarantee |
144 MSG actual_message; // Set to the current keyboard message. | 163 // one character per event. The Mac does not, but in reality that's all it |
145 #elif defined(OS_LINUX) | 164 // ever gives. We're generous, and cap it a bit longer. |
146 // The unicode character, if available, corresponding to this key event. | 165 char16 text[kTextLengthCap]; |
147 // TODO(evanm): temporary hack for test_shell. Ideally we'd either manage | 166 char16 unmodified_text[kTextLengthCap]; |
148 // to stuff everything into key_code, or make this field shared by all | 167 |
149 // implementations, but this will have to do for now. | 168 // This is a string identifying the key pressed. |
150 wchar_t text; | 169 char key_identifier[kIdentifierLengthCap]; |
| 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 |
| 183 // Stores the GDK keyval and modifier state of the GdkEventKey; this is used |
| 184 // to transport these values across IPC so they can be used in the front end |
| 185 // code. |
| 186 guint gdk_keyval; |
| 187 guint gdk_modifier; |
151 #endif | 188 #endif |
152 | 189 |
153 WebKeyboardEvent() | 190 WebKeyboardEvent() : windows_key_code(0), |
154 : key_code(0) | 191 native_key_code(0), |
| 192 system_key(false) { |
| 193 memset(&text, 0, sizeof(text)); |
| 194 memset(&unmodified_text, 0, sizeof(unmodified_text)); |
| 195 memset(&key_identifier, 0, sizeof(key_identifier)); |
155 #if defined(OS_WIN) | 196 #if defined(OS_WIN) |
156 , system_key(false) { | |
157 memset(&actual_message, 0, sizeof(actual_message)); | 197 memset(&actual_message, 0, sizeof(actual_message)); |
| 198 #endif |
158 } | 199 } |
159 #else | |
160 {} | |
161 #endif | |
162 | 200 |
163 #if defined(OS_WIN) | 201 #if defined(OS_WIN) |
164 WebKeyboardEvent(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); | 202 explicit WebKeyboardEvent(HWND hwnd, UINT message, WPARAM wparam, |
| 203 LPARAM lparam); |
165 #elif defined(OS_MACOSX) | 204 #elif defined(OS_MACOSX) |
166 WebKeyboardEvent(NSEvent *event); | 205 explicit WebKeyboardEvent(NSEvent *event); |
167 #elif defined(OS_LINUX) | 206 #elif defined(OS_LINUX) |
168 explicit WebKeyboardEvent(const GdkEventKey* event); | 207 explicit WebKeyboardEvent(const GdkEventKey* event); |
169 #endif | 208 #endif |
170 }; | 209 }; |
171 | 210 |
172 | |
173 #endif // WEBKIT_GLUE_WEBINPUTEVENT_H_ | 211 #endif // WEBKIT_GLUE_WEBINPUTEVENT_H_ |
OLD | NEW |