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

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

Issue 28186: Reverting key change (again); this breaks every keyboard layout test there is... (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/SConscript ('k') | webkit/glue/glue.vcproj » ('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 "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 8
9 #include "KeyboardCodes.h" 9 #include "KeyboardCodes.h"
10 #include "StringImpl.h" // This is so that the KJS build works 10 #include "StringImpl.h" // This is so that the KJS build works
11 11
12 MSVC_PUSH_WARNING_LEVEL(0); 12 MSVC_PUSH_WARNING_LEVEL(0);
13 #include "PlatformKeyboardEvent.h" 13 #include "PlatformKeyboardEvent.h"
14 #include "PlatformMouseEvent.h" 14 #include "PlatformMouseEvent.h"
15 #include "PlatformWheelEvent.h" 15 #include "PlatformWheelEvent.h"
16 #include "Widget.h" 16 #include "Widget.h"
17 MSVC_POP_WARNING(); 17 MSVC_POP_WARNING();
18 18
19 #undef LOG 19 #undef LOG
20 #include "base/gfx/point.h" 20 #include "base/gfx/point.h"
21 #include "base/logging.h" 21 #include "base/logging.h"
22 #include "webkit/glue/event_conversion.h" 22 #include "webkit/glue/event_conversion.h"
23 #include "webkit/glue/glue_util.h"
24 #include "webkit/glue/webinputevent.h" 23 #include "webkit/glue/webinputevent.h"
25 #include "webkit/glue/webkit_glue.h" 24 #include "webkit/glue/webkit_glue.h"
26 25
27 using namespace WebCore; 26 using namespace WebCore;
28 27
29 // MakePlatformMouseEvent ----------------------------------------------------- 28 // MakePlatformMouseEvent -----------------------------------------------------
30 29
31 int MakePlatformMouseEvent::last_click_count_ = 0; 30 int MakePlatformMouseEvent::last_click_count_ = 0;
32 uint32 MakePlatformMouseEvent::last_click_time_ = 0; 31 uint32 MakePlatformMouseEvent::last_click_time_ = 0;
33 32
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 132
134 // MakePlatformKeyboardEvent -------------------------------------------------- 133 // MakePlatformKeyboardEvent --------------------------------------------------
135 134
136 static inline const PlatformKeyboardEvent::Type ToPlatformKeyboardEventType( 135 static inline const PlatformKeyboardEvent::Type ToPlatformKeyboardEventType(
137 WebInputEvent::Type type) { 136 WebInputEvent::Type type) {
138 switch (type) { 137 switch (type) {
139 case WebInputEvent::KEY_UP: 138 case WebInputEvent::KEY_UP:
140 return PlatformKeyboardEvent::KeyUp; 139 return PlatformKeyboardEvent::KeyUp;
141 case WebInputEvent::KEY_DOWN: 140 case WebInputEvent::KEY_DOWN:
142 return PlatformKeyboardEvent::KeyDown; 141 return PlatformKeyboardEvent::KeyDown;
143 case WebInputEvent::RAW_KEY_DOWN:
144 return PlatformKeyboardEvent::RawKeyDown;
145 case WebInputEvent::CHAR: 142 case WebInputEvent::CHAR:
146 return PlatformKeyboardEvent::Char; 143 return PlatformKeyboardEvent::Char;
147 default: 144 default:
148 ASSERT_NOT_REACHED(); 145 ASSERT_NOT_REACHED();
149 } 146 }
150 return PlatformKeyboardEvent::KeyDown; 147 return PlatformKeyboardEvent::KeyDown;
151 } 148 }
152 149
153 MakePlatformKeyboardEvent::MakePlatformKeyboardEvent( 150 static inline String ToSingleCharacterString(UChar c) {
154 const WebKeyboardEvent& e) { 151 return String(&c, 1);
152 }
153
154 #if !defined(OS_MACOSX)
155 // This function is not used on Mac OS X, and gcc complains.
156 static String GetKeyIdentifierForWindowsKeyCode(unsigned short keyCode) {
157 switch (keyCode) {
158 case VKEY_MENU:
159 return "Alt";
160 case VKEY_CONTROL:
161 return "Control";
162 case VKEY_SHIFT:
163 return "Shift";
164 case VKEY_CAPITAL:
165 return "CapsLock";
166 case VKEY_LWIN:
167 case VKEY_RWIN:
168 return "Win";
169 case VKEY_CLEAR:
170 return "Clear";
171 case VKEY_DOWN:
172 return "Down";
173 // "End"
174 case VKEY_END:
175 return "End";
176 // "Enter"
177 case VKEY_RETURN:
178 return "Enter";
179 case VKEY_EXECUTE:
180 return "Execute";
181 case VKEY_F1:
182 return "F1";
183 case VKEY_F2:
184 return "F2";
185 case VKEY_F3:
186 return "F3";
187 case VKEY_F4:
188 return "F4";
189 case VKEY_F5:
190 return "F5";
191 case VKEY_F6:
192 return "F6";
193 case VKEY_F7:
194 return "F7";
195 case VKEY_F8:
196 return "F8";
197 case VKEY_F9:
198 return "F9";
199 case VKEY_F10:
200 return "F11";
201 case VKEY_F12:
202 return "F12";
203 case VKEY_F13:
204 return "F13";
205 case VKEY_F14:
206 return "F14";
207 case VKEY_F15:
208 return "F15";
209 case VKEY_F16:
210 return "F16";
211 case VKEY_F17:
212 return "F17";
213 case VKEY_F18:
214 return "F18";
215 case VKEY_F19:
216 return "F19";
217 case VKEY_F20:
218 return "F20";
219 case VKEY_F21:
220 return "F21";
221 case VKEY_F22:
222 return "F22";
223 case VKEY_F23:
224 return "F23";
225 case VKEY_F24:
226 return "F24";
227 case VKEY_HELP:
228 return "Help";
229 case VKEY_HOME:
230 return "Home";
231 case VKEY_INSERT:
232 return "Insert";
233 case VKEY_LEFT:
234 return "Left";
235 case VKEY_NEXT:
236 return "PageDown";
237 case VKEY_PRIOR:
238 return "PageUp";
239 case VKEY_PAUSE:
240 return "Pause";
241 case VKEY_SNAPSHOT:
242 return "PrintScreen";
243 case VKEY_RIGHT:
244 return "Right";
245 case VKEY_SCROLL:
246 return "Scroll";
247 case VKEY_SELECT:
248 return "Select";
249 case VKEY_UP:
250 return "Up";
251 // Standard says that DEL becomes U+007F.
252 case VKEY_DELETE:
253 return "U+007F";
254 default:
255 return String::format("U+%04X", toupper(keyCode));
256 }
257 }
258 #endif // !defined(OS_MACOSX)
259
260 MakePlatformKeyboardEvent::MakePlatformKeyboardEvent(const WebKeyboardEvent& e)
261 {
155 m_type = ToPlatformKeyboardEventType(e.type); 262 m_type = ToPlatformKeyboardEventType(e.type);
156 m_text = webkit_glue::String16ToString(string16(e.text)); 263 if (m_type == Char || m_type == KeyDown) {
157 m_unmodifiedText = webkit_glue::String16ToString(string16(e.unmodified_text)); 264 #if defined(OS_MACOSX)
158 m_keyIdentifier = 265 m_text = &e.text[0];
159 webkit_glue::StdStringToString(std::string(e.key_identifier)); 266 m_unmodifiedText = &e.unmodified_text[0];
267 m_keyIdentifier = &e.key_identifier[0];
268
269 // Always use 13 for Enter/Return -- we don't want to use AppKit's
270 // different character for Enter.
271 if (m_windowsVirtualKeyCode == '\r') {
272 m_text = "\r";
273 m_unmodifiedText = "\r";
274 }
275
276 // The adjustments below are only needed in backward compatibility mode,
277 // but we cannot tell what mode we are in from here.
278
279 // Turn 0x7F into 8, because backspace needs to always be 8.
280 if (m_text == "\x7F")
281 m_text = "\x8";
282 if (m_unmodifiedText == "\x7F")
283 m_unmodifiedText = "\x8";
284 // Always use 9 for tab -- we don't want to use AppKit's different character for shift-tab.
285 if (m_windowsVirtualKeyCode == 9) {
286 m_text = "\x9";
287 m_unmodifiedText = "\x9";
288 }
289 #elif defined(OS_WIN)
290 m_text = m_unmodifiedText = ToSingleCharacterString(e.key_code);
291 #elif defined(OS_LINUX)
292 m_text = m_unmodifiedText = ToSingleCharacterString(e.text);
293 #endif
294 }
295 #if defined(OS_WIN) || defined(OS_LINUX)
296 if (m_type != Char)
297 m_keyIdentifier = GetKeyIdentifierForWindowsKeyCode(e.key_code);
298 #endif
299 if (m_type == Char || m_type == KeyDown || m_type == KeyUp ||
300 m_type == RawKeyDown) {
301 m_windowsVirtualKeyCode = e.key_code;
302 } else {
303 m_windowsVirtualKeyCode = 0;
304 }
160 m_autoRepeat = (e.modifiers & WebInputEvent::IS_AUTO_REPEAT) != 0; 305 m_autoRepeat = (e.modifiers & WebInputEvent::IS_AUTO_REPEAT) != 0;
161 m_windowsVirtualKeyCode = e.windows_key_code;
162 m_nativeVirtualKeyCode = e.native_key_code;
163 m_isKeypad = (e.modifiers & WebInputEvent::IS_KEYPAD) != 0; 306 m_isKeypad = (e.modifiers & WebInputEvent::IS_KEYPAD) != 0;
164 m_shiftKey = (e.modifiers & WebInputEvent::SHIFT_KEY) != 0; 307 m_shiftKey = (e.modifiers & WebInputEvent::SHIFT_KEY) != 0;
165 m_ctrlKey = (e.modifiers & WebInputEvent::CTRL_KEY) != 0; 308 m_ctrlKey = (e.modifiers & WebInputEvent::CTRL_KEY) != 0;
166 m_altKey = (e.modifiers & WebInputEvent::ALT_KEY) != 0; 309 m_altKey = (e.modifiers & WebInputEvent::ALT_KEY) != 0;
167 m_metaKey = (e.modifiers & WebInputEvent::META_KEY) != 0; 310 m_metaKey = (e.modifiers & WebInputEvent::META_KEY) != 0;
311 #if defined(OS_WIN)
168 m_isSystemKey = e.system_key; 312 m_isSystemKey = e.system_key;
313 // TODO(port): set this field properly for linux and mac.
314 #elif defined(OS_LINUX)
315 m_isSystemKey = m_altKey;
316 #else
317 m_isSystemKey = false;
318 #endif
169 } 319 }
170 320
171 void MakePlatformKeyboardEvent::SetKeyType(Type type) { 321 void MakePlatformKeyboardEvent::SetKeyType(Type type) {
172 // According to the behavior of Webkit in Windows platform, 322 // According to the behavior of Webkit in Windows platform,
173 // we need to convert KeyDown to RawKeydown and Char events 323 // we need to convert KeyDown to RawKeydown and Char events
174 // See WebKit/WebKit/Win/WebView.cpp 324 // See WebKit/WebKit/Win/WebView.cpp
175 ASSERT(m_type == KeyDown); 325 ASSERT(m_type == KeyDown);
176 ASSERT(type == RawKeyDown || type == Char); 326 ASSERT(type == RawKeyDown || type == Char);
177 m_type = type; 327 m_type = type;
178 328
(...skipping 13 matching lines...) Expand all
192 switch (windowsVirtualKeyCode()) { 342 switch (windowsVirtualKeyCode()) {
193 case VKEY_BACK: 343 case VKEY_BACK:
194 case VKEY_ESCAPE: 344 case VKEY_ESCAPE:
195 return false; 345 return false;
196 346
197 default: 347 default:
198 break; 348 break;
199 } 349 }
200 return true; 350 return true;
201 } 351 }
OLDNEW
« no previous file with comments | « webkit/glue/SConscript ('k') | webkit/glue/glue.vcproj » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698