Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(523)

Side by Side Diff: webkit/glue/webinputevent.h

Issue 27056: Fixing WebKeyboardEvent. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/glue/glue.vcproj ('k') | webkit/glue/webinputevent_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 typedef struct _GdkEventButton GdkEventButton; 22 typedef struct _GdkEventButton GdkEventButton;
23 typedef struct _GdkEventMotion GdkEventMotion; 23 typedef struct _GdkEventMotion GdkEventMotion;
24 typedef struct _GdkEventScroll GdkEventScroll; 24 typedef struct _GdkEventScroll GdkEventScroll;
25 typedef struct _GdkEventKey GdkEventKey; 25 typedef struct _GdkEventKey GdkEventKey;
26 #endif 26 #endif
27 27
28 // 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
29 // HandleInputEvent method. These event types are cross-platform; however, 29 // HandleInputEvent method. These event types are cross-platform; however,
30 // there are platform-specific constructors that accept native UI events. 30 // there are platform-specific constructors that accept native UI events.
31 // 31 //
32 // 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
33 // by WebCore's platform event classes. 33 // by WebCore's platform event classes.
34 //
35 // WARNING! These classes must remain PODs (plain old data). They will be
36 // "serialized" by shipping their raw bytes across the wire, so they must not
37 // contain any non-bit-copyable member variables!
34 38
35 // WebInputEvent -------------------------------------------------------------- 39 // WebInputEvent --------------------------------------------------------------
36 40
37 class WebInputEvent { 41 class WebInputEvent {
38 public: 42 public:
39 WebInputEvent() : modifiers(0) { } 43 WebInputEvent() : modifiers(0) { }
40 44
45 // There are two schemes used for keyboard input. On Windows (and,
46 // interestingly enough, on Mac Carbon) there are two events for a keypress.
47 // One is a raw keydown, which provides the keycode only. If the app doesn't
48 // handle that, then the system runs key translation to create an event
49 // containing the generated character and pumps that event. In such a scheme,
50 // those two events are translated to RAW_KEY_DOWN and CHAR events
51 // respectively. In Cocoa and Gtk, key events contain both the keycode and any
52 // translation into actual text. In such a case, WebCore will eventually need
53 // to split the events (see disambiguateKeyDownEvent and its callers) but we
54 // don't worry about that here. We just use a different type (KEY_DOWN) to
55 // indicate this.
41 enum Type { 56 enum Type {
42 // WebMouseEvent 57 // WebMouseEvent
43 MOUSE_DOWN, 58 MOUSE_DOWN,
44 MOUSE_UP, 59 MOUSE_UP,
45 MOUSE_MOVE, 60 MOUSE_MOVE,
46 MOUSE_LEAVE, 61 MOUSE_LEAVE,
47 MOUSE_DOUBLE_CLICK, 62 MOUSE_DOUBLE_CLICK,
48 63
49 // WebMouseWheelEvent 64 // WebMouseWheelEvent
50 MOUSE_WHEEL, 65 MOUSE_WHEEL,
51 66
52 // WebKeyboardEvent 67 // WebKeyboardEvent
68 RAW_KEY_DOWN,
53 KEY_DOWN, 69 KEY_DOWN,
54 KEY_UP, 70 KEY_UP,
55 CHAR 71 CHAR
56 }; 72 };
57 73
58 enum Modifiers { 74 enum Modifiers {
59 // modifiers for all events: 75 // modifiers for all events:
60 SHIFT_KEY = 1 << 0, 76 SHIFT_KEY = 1 << 0,
61 CTRL_KEY = 1 << 1, 77 CTRL_KEY = 1 << 1,
62 ALT_KEY = 1 << 2, 78 ALT_KEY = 1 << 2,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 WebMouseWheelEvent(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); 130 WebMouseWheelEvent(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
115 #elif defined(OS_MACOSX) 131 #elif defined(OS_MACOSX)
116 WebMouseWheelEvent(NSEvent *event, NSView* view); 132 WebMouseWheelEvent(NSEvent *event, NSView* view);
117 #elif defined(OS_LINUX) 133 #elif defined(OS_LINUX)
118 explicit WebMouseWheelEvent(const GdkEventScroll* event); 134 explicit WebMouseWheelEvent(const GdkEventScroll* event);
119 #endif 135 #endif
120 }; 136 };
121 137
122 // WebKeyboardEvent ----------------------------------------------------------- 138 // WebKeyboardEvent -----------------------------------------------------------
123 139
140 // Caps on string lengths so we can make them static arrays and keep them PODs.
141 const size_t kTextLengthCap = 4;
142 // http://www.w3.org/TR/DOM-Level-3-Events/keyset.html lists the identifiers.
143 // The longest is 18 characters, so we'll round up to the next multiple of 4.
144 const size_t kIdentifierLengthCap = 20;
145
124 class WebKeyboardEvent : public WebInputEvent { 146 class WebKeyboardEvent : public WebInputEvent {
125 public: 147 public:
126 // The key_code field is the Windows key code associated with this key event. 148 // |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 149 // 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 150 // a mapping function. If you want a list, see
129 // well as other visible letters like punctuation. 151 // webkit/port/platform/chromium/KeyboardCodes* .
130 // webkit/port/platform/chromium/KeyboardCodes* is an attempt at defining all 152 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 153
136 #if defined(OS_MACOSX) 154 // 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 155 // 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. 156 // hurt to have this one around.
139 std::vector<unsigned short> text; 157 int native_key_code;
140 std::vector<unsigned short> unmodified_text; 158
141 std::vector<unsigned short> key_identifier; 159 // |text| is the text generated by this keystroke. |unmodified_text| is
142 #elif defined(OS_WIN) 160 // |text|, but unmodified by an concurrently-held modifiers (except shift).
143 bool system_key; // Set if we receive a SYSKEYDOWN/WM_SYSKEYUP message. 161 // This is useful for working out shortcut keys. Linux and Windows guarantee
144 MSG actual_message; // Set to the current keyboard message. 162 // one character per event. The Mac does not, but in reality that's all it
145 #elif defined(OS_LINUX) 163 // ever gives. We're generous, and cap it a bit longer.
146 // The unicode character, if available, corresponding to this key event. 164 char16 text[kTextLengthCap];
147 // TODO(evanm): temporary hack for test_shell. Ideally we'd either manage 165 char16 unmodified_text[kTextLengthCap];
148 // to stuff everything into key_code, or make this field shared by all 166
149 // implementations, but this will have to do for now. 167 // This is a string identifying the key pressed.
150 wchar_t text; 168 char key_identifier[kIdentifierLengthCap];
169
170 // This identifies whether this event was tagged by the system as being a
171 // "system key" event (see
172 // http://msdn.microsoft.com/en-us/library/ms646286(VS.85).aspx for details).
173 // Other platforms don't have this concept, but it's just easier to leave it
174 // always false than ifdef.
175
176 bool system_key;
177
178 // References to the original event.
179 #if defined(OS_WIN)
180 MSG actual_message; // Set to the current keyboard message. TODO(avi): remove
151 #endif 181 #endif
152 182
153 WebKeyboardEvent() 183 WebKeyboardEvent() : windows_key_code(0),
154 : key_code(0) 184 native_key_code(0),
185 system_key(false) {
186 memset(&text, 0, sizeof(text));
187 memset(&unmodified_text, 0, sizeof(unmodified_text));
188 memset(&key_identifier, 0, sizeof(key_identifier));
155 #if defined(OS_WIN) 189 #if defined(OS_WIN)
156 , system_key(false) {
157 memset(&actual_message, 0, sizeof(actual_message)); 190 memset(&actual_message, 0, sizeof(actual_message));
191 #endif
158 } 192 }
159 #else
160 {}
161 #endif
162 193
163 #if defined(OS_WIN) 194 #if defined(OS_WIN)
164 WebKeyboardEvent(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); 195 explicit WebKeyboardEvent(HWND hwnd, UINT message, WPARAM wparam,
196 LPARAM lparam);
165 #elif defined(OS_MACOSX) 197 #elif defined(OS_MACOSX)
166 WebKeyboardEvent(NSEvent *event); 198 explicit WebKeyboardEvent(NSEvent *event);
167 #elif defined(OS_LINUX) 199 #elif defined(OS_LINUX)
168 explicit WebKeyboardEvent(const GdkEventKey* event); 200 explicit WebKeyboardEvent(const GdkEventKey* event);
169 #endif 201 #endif
170 }; 202 };
171 203
172
173 #endif // WEBKIT_GLUE_WEBINPUTEVENT_H_ 204 #endif // WEBKIT_GLUE_WEBINPUTEVENT_H_
OLDNEW
« no previous file with comments | « webkit/glue/glue.vcproj ('k') | webkit/glue/webinputevent_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698