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

Side by Side Diff: webkit/glue/webinputevent_linux.cc

Issue 27332: 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/webinputevent.h ('k') | webkit/glue/webinputevent_mac.mm » ('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 #include "config.h" 5 #include "config.h"
6 6
7 #include "webkit/glue/webinputevent.h" 7 #include "webkit/glue/webinputevent.h"
8 8
9 #include "KeyboardCodes.h" 9 #include "KeyboardCodes.h"
10 #include "KeyCodeConversion.h" 10 #include "KeyCodeConversion.h"
11 11
12 #include "webkit/glue/event_conversion.h"
13
14 // This header is out of alphabetical order, but event_conversion.h pulls
15 // in more webkit headers that redefine LOG so I need to undef afterwards.
16 #undef LOG
17 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/string_util.h"
14 #include "webkit/glue/webinputevent_util.h"
18 15
19 #include <gdk/gdk.h> 16 #include <gdk/gdk.h>
20 #include <gdk/gdkkeysyms.h> 17 #include <gdk/gdkkeysyms.h>
21 #include <gtk/gtkversion.h> 18 #include <gtk/gtkversion.h>
22 19
23 namespace { 20 namespace {
24 21
25 double GdkEventTimeToWebEventTime(guint32 time) { 22 double GdkEventTimeToWebEventTime(guint32 time) {
26 // Convert from time in ms to time in sec. 23 // Convert from time in ms to time in sec.
27 return time / 1000.0; 24 return time / 1000.0;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 break; 56 break;
60 case GDK_2BUTTON_PRESS: 57 case GDK_2BUTTON_PRESS:
61 case GDK_3BUTTON_PRESS: 58 case GDK_3BUTTON_PRESS:
62 type = MOUSE_DOUBLE_CLICK; 59 type = MOUSE_DOUBLE_CLICK;
63 break; 60 break;
64 case GDK_BUTTON_RELEASE: 61 case GDK_BUTTON_RELEASE:
65 type = MOUSE_UP; 62 type = MOUSE_UP;
66 break; 63 break;
67 64
68 default: 65 default:
69 ASSERT_NOT_REACHED(); 66 NOTREACHED();
70 }; 67 };
71 68
72 button = BUTTON_NONE; 69 button = BUTTON_NONE;
73 if (event->button == 1) { 70 if (event->button == 1) {
74 button = BUTTON_LEFT; 71 button = BUTTON_LEFT;
75 } else if (event->button == 2) { 72 } else if (event->button == 2) {
76 button = BUTTON_MIDDLE; 73 button = BUTTON_MIDDLE;
77 } else if (event->button == 3) { 74 } else if (event->button == 3) {
78 button = BUTTON_RIGHT; 75 button = BUTTON_RIGHT;
79 } 76 }
80 } 77 }
81 78
82 WebMouseEvent::WebMouseEvent(const GdkEventMotion* event) { 79 WebMouseEvent::WebMouseEvent(const GdkEventMotion* event) {
83 timestamp_sec = GdkEventTimeToWebEventTime(event->time); 80 timestamp_sec = GdkEventTimeToWebEventTime(event->time);
84 modifiers = GdkStateToWebEventModifiers(event->state); 81 modifiers = GdkStateToWebEventModifiers(event->state);
85 x = static_cast<int>(event->x); 82 x = static_cast<int>(event->x);
86 y = static_cast<int>(event->y); 83 y = static_cast<int>(event->y);
87 global_x = static_cast<int>(event->x_root); 84 global_x = static_cast<int>(event->x_root);
88 global_y = static_cast<int>(event->y_root); 85 global_y = static_cast<int>(event->y_root);
89 86
90 switch (event->type) { 87 switch (event->type) {
91 case GDK_MOTION_NOTIFY: 88 case GDK_MOTION_NOTIFY:
92 type = MOUSE_MOVE; 89 type = MOUSE_MOVE;
93 break; 90 break;
94 default: 91 default:
95 ASSERT_NOT_REACHED(); 92 NOTREACHED();
96 } 93 }
97 94
98 button = BUTTON_NONE; 95 button = BUTTON_NONE;
99 if (event->state & GDK_BUTTON1_MASK) { 96 if (event->state & GDK_BUTTON1_MASK) {
100 button = BUTTON_LEFT; 97 button = BUTTON_LEFT;
101 } else if (event->state & GDK_BUTTON2_MASK) { 98 } else if (event->state & GDK_BUTTON2_MASK) {
102 button = BUTTON_MIDDLE; 99 button = BUTTON_MIDDLE;
103 } else if (event->state & GDK_BUTTON3_MASK) { 100 } else if (event->state & GDK_BUTTON3_MASK) {
104 button = BUTTON_RIGHT; 101 button = BUTTON_RIGHT;
105 } 102 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 break; 139 break;
143 case GDK_SCROLL_RIGHT: 140 case GDK_SCROLL_RIGHT:
144 delta_x = kWheelDelta; 141 delta_x = kWheelDelta;
145 break; 142 break;
146 default: 143 default:
147 break; 144 break;
148 } 145 }
149 } 146 }
150 147
151 WebKeyboardEvent::WebKeyboardEvent(const GdkEventKey* event) { 148 WebKeyboardEvent::WebKeyboardEvent(const GdkEventKey* event) {
149 system_key = false;
152 modifiers = GdkStateToWebEventModifiers(event->state); 150 modifiers = GdkStateToWebEventModifiers(event->state);
153 151
154 // GDK only exposes key press and release events. By contrast,
155 // WebKeyboardEvent matches Windows and wants key down/up events along with a
156 // separate CHAR event.
157 // We require the caller to simulate the CHAR event manually. See
158 // test_shell's webwidget_host for an example.
159 switch (event->type) { 152 switch (event->type) {
160 case GDK_KEY_RELEASE: 153 case GDK_KEY_RELEASE:
161 type = KEY_UP; 154 type = KEY_UP;
162 break; 155 break;
163 case GDK_KEY_PRESS: 156 case GDK_KEY_PRESS:
164 type = KEY_DOWN; 157 type = KEY_DOWN;
165 break; 158 break;
166 default: 159 default:
167 NOTREACHED(); 160 NOTREACHED();
168 break; 161 break;
169 } 162 }
170 163
171 // The key code tells us which physical key was pressed (for example, the 164 // The key code tells us which physical key was pressed (for example, the
172 // A key went down or up). It does not determine whether A should be lower 165 // A key went down or up). It does not determine whether A should be lower
173 // or upper case. This is what text does, which should be the keyval. 166 // or upper case. This is what text does, which should be the keyval.
174 key_code = WebCore::windowsKeyCodeForKeyEvent(event->keyval); 167 windows_key_code = WebCore::windowsKeyCodeForKeyEvent(event->keyval);
168 native_key_code = event->hardware_keycode;
169
170 memset(&text, 0, sizeof(text));
171 memset(&unmodified_text, 0, sizeof(unmodified_text));
172 memset(&key_identifier, 0, sizeof(key_identifier));
175 173
176 switch (event->keyval) { 174 switch (event->keyval) {
177 // We need to treat the enter key as a key press of character \r. This 175 // We need to treat the enter key as a key press of character \r. This
178 // is apparently just how webkit handles it and what it expects. 176 // is apparently just how webkit handles it and what it expects.
179 case GDK_ISO_Enter: 177 case GDK_ISO_Enter:
180 case GDK_KP_Enter: 178 case GDK_KP_Enter:
181 case GDK_Return: 179 case GDK_Return:
182 text = '\r'; 180 unmodified_text[0] = text[0] = static_cast<char16>('\r');
183 break; 181 break;
184 default: 182 default:
185 // This should set text to 0 when it's not a real character. 183 // This should set text to 0 when it's not a real character.
186 text = gdk_keyval_to_unicode(event->keyval); 184 // TODO(avi): fix for non BMP chars
185 unmodified_text[0] = text[0] =
186 static_cast<char16>(gdk_keyval_to_unicode(event->keyval));
187 break; 187 break;
188 } 188 }
189 189
190 std::string key_identifier_str =
191 webkit_glue::GetKeyIdentifierForWindowsKeyCode(windows_key_code);
192 base::strlcpy(key_identifier, key_identifier_str.c_str(),
193 kIdentifierLengthCap);
194
190 // TODO(tc): Do we need to set IS_AUTO_REPEAT or IS_KEYPAD? 195 // TODO(tc): Do we need to set IS_AUTO_REPEAT or IS_KEYPAD?
191 } 196 }
OLDNEW
« no previous file with comments | « webkit/glue/webinputevent.h ('k') | webkit/glue/webinputevent_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698