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

Side by Side Diff: webkit/api/src/gtk/WebInputEventFactory.cpp

Issue 126118: Integrating GtkIMContext into the RenderWidgetHostViewGtk class.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 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/api/public/gtk/WebInputEventFactory.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006-2009 Google Inc. All rights reserved. 2 * Copyright (C) 2006-2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 #endif 64 #endif
65 if (state & GDK_BUTTON1_MASK) 65 if (state & GDK_BUTTON1_MASK)
66 modifiers |= WebInputEvent::LeftButtonDown; 66 modifiers |= WebInputEvent::LeftButtonDown;
67 if (state & GDK_BUTTON2_MASK) 67 if (state & GDK_BUTTON2_MASK)
68 modifiers |= WebInputEvent::MiddleButtonDown; 68 modifiers |= WebInputEvent::MiddleButtonDown;
69 if (state & GDK_BUTTON3_MASK) 69 if (state & GDK_BUTTON3_MASK)
70 modifiers |= WebInputEvent::RightButtonDown; 70 modifiers |= WebInputEvent::RightButtonDown;
71 return modifiers; 71 return modifiers;
72 } 72 }
73 73
74 static int gdkEventToWindowsKeyCode(const GdkEventKey* event)
75 {
76 static const unsigned int hardwareCodeToGDKKeyval[] = {
77 0, // 0x00:
78 0, // 0x01:
79 0, // 0x02:
80 0, // 0x03:
81 0, // 0x04:
82 0, // 0x05:
83 0, // 0x06:
84 0, // 0x07:
85 0, // 0x08:
86 0, // 0x09: GDK_Escape
87 GDK_1, // 0x0A: GDK_1
88 GDK_2, // 0x0B: GDK_2
89 GDK_3, // 0x0C: GDK_3
90 GDK_4, // 0x0D: GDK_4
91 GDK_5, // 0x0E: GDK_5
92 GDK_6, // 0x0F: GDK_6
93 GDK_7, // 0x10: GDK_7
94 GDK_8, // 0x11: GDK_8
95 GDK_9, // 0x12: GDK_9
96 GDK_0, // 0x13: GDK_0
97 GDK_minus, // 0x14: GDK_minus
98 GDK_equal, // 0x15: GDK_equal
99 0, // 0x16: GDK_BackSpace
100 0, // 0x17: GDK_Tab
101 GDK_q, // 0x18: GDK_q
102 GDK_w, // 0x19: GDK_w
103 GDK_e, // 0x1A: GDK_e
104 GDK_r, // 0x1B: GDK_r
105 GDK_t, // 0x1C: GDK_t
106 GDK_y, // 0x1D: GDK_y
107 GDK_u, // 0x1E: GDK_u
108 GDK_i, // 0x1F: GDK_i
109 GDK_o, // 0x20: GDK_o
110 GDK_p, // 0x21: GDK_p
111 GDK_bracketleft, // 0x22: GDK_bracketleft
112 GDK_bracketright, // 0x23: GDK_bracketright
113 0, // 0x24: GDK_Return
114 0, // 0x25: GDK_Control_L
115 GDK_a, // 0x26: GDK_a
116 GDK_s, // 0x27: GDK_s
117 GDK_d, // 0x28: GDK_d
118 GDK_f, // 0x29: GDK_f
119 GDK_g, // 0x2A: GDK_g
120 GDK_h, // 0x2B: GDK_h
121 GDK_j, // 0x2C: GDK_j
122 GDK_k, // 0x2D: GDK_k
123 GDK_l, // 0x2E: GDK_l
124 GDK_semicolon, // 0x2F: GDK_semicolon
125 GDK_apostrophe, // 0x30: GDK_apostrophe
126 GDK_grave, // 0x31: GDK_grave
127 0, // 0x32: GDK_Shift_L
128 GDK_backslash, // 0x33: GDK_backslash
129 GDK_z, // 0x34: GDK_z
130 GDK_x, // 0x35: GDK_x
131 GDK_c, // 0x36: GDK_c
132 GDK_v, // 0x37: GDK_v
133 GDK_b, // 0x38: GDK_b
134 GDK_n, // 0x39: GDK_n
135 GDK_m, // 0x3A: GDK_m
136 GDK_comma, // 0x3B: GDK_comma
137 GDK_period, // 0x3C: GDK_period
138 GDK_slash, // 0x3D: GDK_slash
139 0, // 0x3E: GDK_Shift_R
140 };
141
142 // |windowKeyCode| shouldn't change even when we change the keyboard
143 // layout, e.g. when we type an 'A' key of a US keyboard on the French
144 // layout, |windowsKeyCode| should be VK_A. On the other hand,
145 // |event->keyval| may change when we change the keyboard layout (the
146 // GdkKeymap object attached to the GdkDisplay object), e.g. when we type
147 // an 'A' key of a US keyboard on the French (or Hebrew) layout,
148 // |event->keyval| becomes GDK_q (or GDK_hebrew_shin).
149 // To improve compatibilty with Windows, we use |event->hardware_keycode|
150 // for retrieving its Windows key-code for the keys that can be changed by
151 // GdkKeymap objects (keyboard-layout drivers).
152 // We shouldn't use |event->hardware_keycode| for keys that GdkKeymap
153 // objects cannot change because |event->hardware_keycode| doesn't change
154 // even when we change the layout options, e.g. when we swap a control
155 // key and a caps-lock key, GTK doesn't swap their
156 // |event->hardware_keycode| values but swap their |event->keyval| values.
157 const int tableSize = sizeof(hardwareCodeToGDKKeyval) / sizeof(hardwareCodeToGDKKeyval[0]);
158 if (event->hardware_keycode < tableSize) {
159 int keyval = hardwareCodeToGDKKeyval[event->hardware_keycode];
160 if (keyval)
161 return WebCore::windowsKeyCodeForKeyEvent(keyval);
162 }
163
164 // This key is one that keyboard-layout drivers cannot change.
165 // Use |event->keyval| to retrieve its |windowsKeyCode| value.
166 return WebCore::windowsKeyCodeForKeyEvent(event->keyval);
167 }
168
74 // WebKeyboardEvent ----------------------------------------------------------- 169 // WebKeyboardEvent -----------------------------------------------------------
75 170
76 WebKeyboardEvent WebInputEventFactory::keyboardEvent(const GdkEventKey* event) 171 WebKeyboardEvent WebInputEventFactory::keyboardEvent(const GdkEventKey* event)
77 { 172 {
78 WebKeyboardEvent result; 173 WebKeyboardEvent result;
79 174
80 result.timeStampSeconds = gdkEventTimeToWebEventTime(event->time); 175 result.timeStampSeconds = gdkEventTimeToWebEventTime(event->time);
81 result.modifiers = gdkStateToWebEventModifiers(event->state); 176 result.modifiers = gdkStateToWebEventModifiers(event->state);
82 177
83 switch (event->type) { 178 switch (event->type) {
84 case GDK_KEY_RELEASE: 179 case GDK_KEY_RELEASE:
85 result.type = WebInputEvent::KeyUp; 180 result.type = WebInputEvent::KeyUp;
86 break; 181 break;
87 case GDK_KEY_PRESS: 182 case GDK_KEY_PRESS:
88 result.type = WebInputEvent::KeyDown; 183 result.type = WebInputEvent::RawKeyDown;
89 break; 184 break;
90 default: 185 default:
91 ASSERT_NOT_REACHED(); 186 ASSERT_NOT_REACHED();
92 } 187 }
93 188
94 // The key code tells us which physical key was pressed (for example, the 189 // The key code tells us which physical key was pressed (for example, the
95 // A key went down or up). It does not determine whether A should be lower 190 // A key went down or up). It does not determine whether A should be lower
96 // or upper case. This is what text does, which should be the keyval. 191 // or upper case. This is what text does, which should be the keyval.
97 result.windowsKeyCode = WebCore::windowsKeyCodeForKeyEvent(event->keyval); 192 result.windowsKeyCode = gdkEventToWindowsKeyCode(event);
98 result.nativeKeyCode = event->hardware_keycode; 193 result.nativeKeyCode = event->hardware_keycode;
99 194
100 switch (event->keyval) { 195 switch (event->keyval) {
101 // We need to treat the enter key as a key press of character \r. This 196 // We need to treat the enter key as a key press of character \r. This
102 // is apparently just how webkit handles it and what it expects. 197 // is apparently just how webkit handles it and what it expects.
103 case GDK_ISO_Enter: 198 case GDK_ISO_Enter:
104 case GDK_KP_Enter: 199 case GDK_KP_Enter:
105 case GDK_Return: 200 case GDK_Return:
106 result.unmodifiedText[0] = result.text[0] = static_cast<WebUChar>('\r'); 201 result.unmodifiedText[0] = result.text[0] = static_cast<WebUChar>('\r');
107 break; 202 break;
108 default: 203 default:
109 // This should set text to 0 when it's not a real character. 204 // This should set text to 0 when it's not a real character.
110 // FIXME: fix for non BMP chars 205 // FIXME: fix for non BMP chars
111 result.unmodifiedText[0] = result.text[0] = 206 result.unmodifiedText[0] = result.text[0] =
112 static_cast<WebUChar>(gdk_keyval_to_unicode(event->keyval)); 207 static_cast<WebUChar>(gdk_keyval_to_unicode(event->keyval));
113 } 208 }
114 209
115 result.setKeyIdentifierFromWindowsKeyCode(); 210 result.setKeyIdentifierFromWindowsKeyCode();
116 211
117 // FIXME: Do we need to set IsAutoRepeat or IsKeyPad? 212 // FIXME: Do we need to set IsAutoRepeat or IsKeyPad?
118 213
119 return result; 214 return result;
120 } 215 }
121 216
217 WebKeyboardEvent WebInputEventFactory::keyboardEvent(wchar_t character, double timeStampSeconds)
218 {
219 // keyboardEvent(const GdkEventKey*) depends on the GdkEventKey object and
220 // it is hard to use/ it from signal handlers which don't use GdkEventKey
221 // objects (e.g. GtkIMContext signal handlers.) For such handlers, this
222 // function creates a WebInputEvent::Char event without using a
223 // GdkEventKey object.
224 WebKeyboardEvent result;
225 result.type = WebKit::WebInputEvent::Char;
226 result.timeStampSeconds = timeStampSeconds;
227 result.windowsKeyCode = character;
228 result.nativeKeyCode = character;
229 result.text[0] = character;
230 result.unmodifiedText[0] = character;
231 return result;
232 }
233
122 // WebMouseEvent -------------------------------------------------------------- 234 // WebMouseEvent --------------------------------------------------------------
123 235
124 WebMouseEvent WebInputEventFactory::mouseEvent(const GdkEventButton* event) 236 WebMouseEvent WebInputEventFactory::mouseEvent(const GdkEventButton* event)
125 { 237 {
126 WebMouseEvent result; 238 WebMouseEvent result;
127 239
128 result.timeStampSeconds = gdkEventTimeToWebEventTime(event->time); 240 result.timeStampSeconds = gdkEventTimeToWebEventTime(event->time);
129 241
130 result.modifiers = gdkStateToWebEventModifiers(event->state); 242 result.modifiers = gdkStateToWebEventModifiers(event->state);
131 result.x = static_cast<int>(event->x); 243 result.x = static_cast<int>(event->x);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 case GDK_SCROLL_RIGHT: 356 case GDK_SCROLL_RIGHT:
245 result.deltaX = -scrollbarPixelsPerTick; 357 result.deltaX = -scrollbarPixelsPerTick;
246 result.wheelTicksX = 1; 358 result.wheelTicksX = 1;
247 break; 359 break;
248 } 360 }
249 361
250 return result; 362 return result;
251 } 363 }
252 364
253 } // namespace WebKit 365 } // namespace WebKit
OLDNEW
« no previous file with comments | « webkit/api/public/gtk/WebInputEventFactory.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698