OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 /* | 5 /* |
6 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. | 6 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. |
7 * Copyright (C) 2006-2009 Google Inc. | 7 * Copyright (C) 2006-2009 Google Inc. |
8 * | 8 * |
9 * Redistribution and use in source and binary forms, with or without | 9 * Redistribution and use in source and binary forms, with or without |
10 * modification, are permitted provided that the following conditions | 10 * modification, are permitted provided that the following conditions |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 return @""; | 143 return @""; |
144 return FilterSpecialCharacter([event characters]); | 144 return FilterSpecialCharacter([event characters]); |
145 } | 145 } |
146 | 146 |
147 inline NSString* UnmodifiedTextFromEvent(NSEvent* event) { | 147 inline NSString* UnmodifiedTextFromEvent(NSEvent* event) { |
148 if ([event type] == NSFlagsChanged) | 148 if ([event type] == NSFlagsChanged) |
149 return @""; | 149 return @""; |
150 return FilterSpecialCharacter([event charactersIgnoringModifiers]); | 150 return FilterSpecialCharacter([event charactersIgnoringModifiers]); |
151 } | 151 } |
152 | 152 |
153 NSString* KeyIdentifierForKeyEvent(NSEvent* event) { | |
154 if ([event type] == NSFlagsChanged) { | |
155 switch ([event keyCode]) { | |
156 case 54: // Right Command | |
157 case 55: // Left Command | |
158 return @"Meta"; | |
159 | |
160 case 57: // Capslock | |
161 return @"CapsLock"; | |
162 | |
163 case 56: // Left Shift | |
164 case 60: // Right Shift | |
165 return @"Shift"; | |
166 | |
167 case 58: // Left Alt | |
168 case 61: // Right Alt | |
169 return @"Alt"; | |
170 | |
171 case 59: // Left Ctrl | |
172 case 62: // Right Ctrl | |
173 return @"Control"; | |
174 | |
175 // Begin non-Apple addition/modification | |
176 // -------------------------------------- | |
177 case 63: // Function | |
178 return @"Function"; | |
179 | |
180 default: // Unknown, but this may be a strange/new keyboard. | |
181 return @"Unidentified"; | |
182 // End non-Apple addition/modification | |
183 // ---------------------------------------- | |
184 } | |
185 } | |
186 | |
187 NSString* s = [event charactersIgnoringModifiers]; | |
188 if ([s length] != 1) | |
189 return @"Unidentified"; | |
190 | |
191 unichar c = [s characterAtIndex:0]; | |
192 switch (c) { | |
193 // Each identifier listed in the DOM spec is listed here. | |
194 // Many are simply commented out since they do not appear on standard | |
195 // Macintosh keyboards | |
196 // or are on a key that doesn't have a corresponding character. | |
197 | |
198 // "Accept" | |
199 // "AllCandidates" | |
200 | |
201 // "Alt" | |
202 case NSMenuFunctionKey: | |
203 return @"Alt"; | |
204 | |
205 // "Apps" | |
206 // "BrowserBack" | |
207 // "BrowserForward" | |
208 // "BrowserHome" | |
209 // "BrowserRefresh" | |
210 // "BrowserSearch" | |
211 // "BrowserStop" | |
212 // "CapsLock" | |
213 | |
214 // "Clear" | |
215 case NSClearLineFunctionKey: | |
216 return @"Clear"; | |
217 | |
218 // "CodeInput" | |
219 // "Compose" | |
220 // "Control" | |
221 // "Crsel" | |
222 // "Convert" | |
223 // "Copy" | |
224 // "Cut" | |
225 | |
226 // "Down" | |
227 case NSDownArrowFunctionKey: | |
228 return @"Down"; | |
229 // "End" | |
230 case NSEndFunctionKey: | |
231 return @"End"; | |
232 // "Enter" | |
233 case 0x3: | |
234 case 0xA: | |
235 case 0xD: // Macintosh calls the one on the main keyboard Return, but | |
236 // Windows calls it Enter, so we'll do the same for the DOM | |
237 return @"Enter"; | |
238 | |
239 // "EraseEof" | |
240 | |
241 // "Execute" | |
242 case NSExecuteFunctionKey: | |
243 return @"Execute"; | |
244 | |
245 // "Exsel" | |
246 | |
247 // "F1" | |
248 case NSF1FunctionKey: | |
249 return @"F1"; | |
250 // "F2" | |
251 case NSF2FunctionKey: | |
252 return @"F2"; | |
253 // "F3" | |
254 case NSF3FunctionKey: | |
255 return @"F3"; | |
256 // "F4" | |
257 case NSF4FunctionKey: | |
258 return @"F4"; | |
259 // "F5" | |
260 case NSF5FunctionKey: | |
261 return @"F5"; | |
262 // "F6" | |
263 case NSF6FunctionKey: | |
264 return @"F6"; | |
265 // "F7" | |
266 case NSF7FunctionKey: | |
267 return @"F7"; | |
268 // "F8" | |
269 case NSF8FunctionKey: | |
270 return @"F8"; | |
271 // "F9" | |
272 case NSF9FunctionKey: | |
273 return @"F9"; | |
274 // "F10" | |
275 case NSF10FunctionKey: | |
276 return @"F10"; | |
277 // "F11" | |
278 case NSF11FunctionKey: | |
279 return @"F11"; | |
280 // "F12" | |
281 case NSF12FunctionKey: | |
282 return @"F12"; | |
283 // "F13" | |
284 case NSF13FunctionKey: | |
285 return @"F13"; | |
286 // "F14" | |
287 case NSF14FunctionKey: | |
288 return @"F14"; | |
289 // "F15" | |
290 case NSF15FunctionKey: | |
291 return @"F15"; | |
292 // "F16" | |
293 case NSF16FunctionKey: | |
294 return @"F16"; | |
295 // "F17" | |
296 case NSF17FunctionKey: | |
297 return @"F17"; | |
298 // "F18" | |
299 case NSF18FunctionKey: | |
300 return @"F18"; | |
301 // "F19" | |
302 case NSF19FunctionKey: | |
303 return @"F19"; | |
304 // "F20" | |
305 case NSF20FunctionKey: | |
306 return @"F20"; | |
307 // "F21" | |
308 case NSF21FunctionKey: | |
309 return @"F21"; | |
310 // "F22" | |
311 case NSF22FunctionKey: | |
312 return @"F22"; | |
313 // "F23" | |
314 case NSF23FunctionKey: | |
315 return @"F23"; | |
316 // "F24" | |
317 case NSF24FunctionKey: | |
318 return @"F24"; | |
319 | |
320 // "FinalMode" | |
321 | |
322 // "Find" | |
323 case NSFindFunctionKey: | |
324 return @"Find"; | |
325 | |
326 // "FullWidth" | |
327 // "HalfWidth" | |
328 // "HangulMode" | |
329 // "HanjaMode" | |
330 | |
331 // "Help" | |
332 case NSHelpFunctionKey: | |
333 return @"Help"; | |
334 | |
335 // "Hiragana" | |
336 | |
337 // "Home" | |
338 case NSHomeFunctionKey: | |
339 return @"Home"; | |
340 // "Insert" | |
341 case NSInsertFunctionKey: | |
342 return @"Insert"; | |
343 | |
344 // "JapaneseHiragana" | |
345 // "JapaneseKatakana" | |
346 // "JapaneseRomaji" | |
347 // "JunjaMode" | |
348 // "KanaMode" | |
349 // "KanjiMode" | |
350 // "Katakana" | |
351 // "LaunchApplication1" | |
352 // "LaunchApplication2" | |
353 // "LaunchMail" | |
354 | |
355 // "Left" | |
356 case NSLeftArrowFunctionKey: | |
357 return @"Left"; | |
358 | |
359 // "Meta" | |
360 // "MediaNextTrack" | |
361 // "MediaPlayPause" | |
362 // "MediaPreviousTrack" | |
363 // "MediaStop" | |
364 | |
365 // "ModeChange" | |
366 case NSModeSwitchFunctionKey: | |
367 return @"ModeChange"; | |
368 | |
369 // "Nonconvert" | |
370 // "NumLock" | |
371 | |
372 // "PageDown" | |
373 case NSPageDownFunctionKey: | |
374 return @"PageDown"; | |
375 // "PageUp" | |
376 case NSPageUpFunctionKey: | |
377 return @"PageUp"; | |
378 | |
379 // "Paste" | |
380 | |
381 // "Pause" | |
382 case NSPauseFunctionKey: | |
383 return @"Pause"; | |
384 | |
385 // "Play" | |
386 // "PreviousCandidate" | |
387 | |
388 // "PrintScreen" | |
389 case NSPrintScreenFunctionKey: | |
390 return @"PrintScreen"; | |
391 | |
392 // "Process" | |
393 // "Props" | |
394 | |
395 // "Right" | |
396 case NSRightArrowFunctionKey: | |
397 return @"Right"; | |
398 | |
399 // "RomanCharacters" | |
400 | |
401 // "Scroll" | |
402 case NSScrollLockFunctionKey: | |
403 return @"Scroll"; | |
404 // "Select" | |
405 case NSSelectFunctionKey: | |
406 return @"Select"; | |
407 | |
408 // "SelectMedia" | |
409 // "Shift" | |
410 | |
411 // "Stop" | |
412 case NSStopFunctionKey: | |
413 return @"Stop"; | |
414 // "Up" | |
415 case NSUpArrowFunctionKey: | |
416 return @"Up"; | |
417 // "Undo" | |
418 case NSUndoFunctionKey: | |
419 return @"Undo"; | |
420 | |
421 // "VolumeDown" | |
422 // "VolumeMute" | |
423 // "VolumeUp" | |
424 // "Win" | |
425 // "Zoom" | |
426 | |
427 // More function keys, not in the key identifier specification. | |
428 case NSF25FunctionKey: | |
429 return @"F25"; | |
430 case NSF26FunctionKey: | |
431 return @"F26"; | |
432 case NSF27FunctionKey: | |
433 return @"F27"; | |
434 case NSF28FunctionKey: | |
435 return @"F28"; | |
436 case NSF29FunctionKey: | |
437 return @"F29"; | |
438 case NSF30FunctionKey: | |
439 return @"F30"; | |
440 case NSF31FunctionKey: | |
441 return @"F31"; | |
442 case NSF32FunctionKey: | |
443 return @"F32"; | |
444 case NSF33FunctionKey: | |
445 return @"F33"; | |
446 case NSF34FunctionKey: | |
447 return @"F34"; | |
448 case NSF35FunctionKey: | |
449 return @"F35"; | |
450 | |
451 // Turn 0x7F into 0x08, because backspace needs to always be 0x08. | |
452 case 0x7F: | |
453 return @"U+0008"; | |
454 // Standard says that DEL becomes U+007F. | |
455 case NSDeleteFunctionKey: | |
456 return @"U+007F"; | |
457 | |
458 // Always use 0x09 for tab instead of AppKit's backtab character. | |
459 case NSBackTabCharacter: | |
460 return @"U+0009"; | |
461 | |
462 case NSBeginFunctionKey: | |
463 case NSBreakFunctionKey: | |
464 case NSClearDisplayFunctionKey: | |
465 case NSDeleteCharFunctionKey: | |
466 case NSDeleteLineFunctionKey: | |
467 case NSInsertCharFunctionKey: | |
468 case NSInsertLineFunctionKey: | |
469 case NSNextFunctionKey: | |
470 case NSPrevFunctionKey: | |
471 case NSPrintFunctionKey: | |
472 case NSRedoFunctionKey: | |
473 case NSResetFunctionKey: | |
474 case NSSysReqFunctionKey: | |
475 case NSSystemFunctionKey: | |
476 case NSUserFunctionKey: | |
477 // FIXME: We should use something other than the vendor-area Unicode values | |
478 // for the above keys. | |
479 // For now, just fall through to the default. | |
480 default: | |
481 return [NSString stringWithFormat:@"U+%04X", base::ToUpperASCII(c)]; | |
482 } | |
483 } | |
484 | |
485 // End Apple code. | 153 // End Apple code. |
486 // ---------------------------------------------------------------------------- | 154 // ---------------------------------------------------------------------------- |
487 | 155 |
488 int ModifiersFromEvent(NSEvent* event) { | 156 int ModifiersFromEvent(NSEvent* event) { |
489 int modifiers = 0; | 157 int modifiers = 0; |
490 | 158 |
491 if ([event modifierFlags] & NSControlKeyMask) | 159 if ([event modifierFlags] & NSControlKeyMask) |
492 modifiers |= blink::WebInputEvent::ControlKey; | 160 modifiers |= blink::WebInputEvent::ControlKey; |
493 if ([event modifierFlags] & NSShiftKeyMask) | 161 if ([event modifierFlags] & NSShiftKeyMask) |
494 modifiers |= blink::WebInputEvent::ShiftKey; | 162 modifiers |= blink::WebInputEvent::ShiftKey; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 | 285 |
618 ui::DomCode dom_code = ui::DomCodeFromNSEvent(event); | 286 ui::DomCode dom_code = ui::DomCodeFromNSEvent(event); |
619 result.windowsKeyCode = | 287 result.windowsKeyCode = |
620 ui::LocatedToNonLocatedKeyboardCode(ui::KeyboardCodeFromNSEvent(event)); | 288 ui::LocatedToNonLocatedKeyboardCode(ui::KeyboardCodeFromNSEvent(event)); |
621 result.modifiers |= DomCodeToWebInputEventModifiers(dom_code); | 289 result.modifiers |= DomCodeToWebInputEventModifiers(dom_code); |
622 result.nativeKeyCode = [event keyCode]; | 290 result.nativeKeyCode = [event keyCode]; |
623 result.domCode = static_cast<int>(dom_code); | 291 result.domCode = static_cast<int>(dom_code); |
624 result.domKey = DomKeyFromEvent(event); | 292 result.domKey = DomKeyFromEvent(event); |
625 NSString* text_str = TextFromEvent(event); | 293 NSString* text_str = TextFromEvent(event); |
626 NSString* unmodified_str = UnmodifiedTextFromEvent(event); | 294 NSString* unmodified_str = UnmodifiedTextFromEvent(event); |
627 NSString* identifier_str = KeyIdentifierForKeyEvent(event); | |
628 | 295 |
629 // Begin Apple code, copied from KeyEventMac.mm | 296 // Begin Apple code, copied from KeyEventMac.mm |
630 | 297 |
631 // Always use 13 for Enter/Return -- we don't want to use AppKit's | 298 // Always use 13 for Enter/Return -- we don't want to use AppKit's |
632 // different character for Enter. | 299 // different character for Enter. |
633 if (result.windowsKeyCode == '\r') { | 300 if (result.windowsKeyCode == '\r') { |
634 text_str = @"\r"; | 301 text_str = @"\r"; |
635 unmodified_str = @"\r"; | 302 unmodified_str = @"\r"; |
636 } | 303 } |
637 | 304 |
638 // Always use 9 for tab -- we don't want to use AppKit's different character | 305 // Always use 9 for tab -- we don't want to use AppKit's different character |
639 // for shift-tab. | 306 // for shift-tab. |
640 if (result.windowsKeyCode == 9) { | 307 if (result.windowsKeyCode == 9) { |
641 text_str = @"\x9"; | 308 text_str = @"\x9"; |
642 unmodified_str = @"\x9"; | 309 unmodified_str = @"\x9"; |
643 } | 310 } |
644 | 311 |
645 // End Apple code. | 312 // End Apple code. |
646 | 313 |
647 if ([text_str length] < blink::WebKeyboardEvent::textLengthCap && | 314 if ([text_str length] < blink::WebKeyboardEvent::textLengthCap && |
648 [unmodified_str length] < blink::WebKeyboardEvent::textLengthCap) { | 315 [unmodified_str length] < blink::WebKeyboardEvent::textLengthCap) { |
649 [text_str getCharacters:&result.text[0]]; | 316 [text_str getCharacters:&result.text[0]]; |
650 [unmodified_str getCharacters:&result.unmodifiedText[0]]; | 317 [unmodified_str getCharacters:&result.unmodifiedText[0]]; |
651 } else | 318 } else |
652 NOTIMPLEMENTED(); | 319 NOTIMPLEMENTED(); |
653 | 320 |
654 [identifier_str getCString:&result.keyIdentifier[0] | |
655 maxLength:sizeof(result.keyIdentifier) | |
656 encoding:NSASCIIStringEncoding]; | |
657 | |
658 result.timeStampSeconds = [event timestamp]; | 321 result.timeStampSeconds = [event timestamp]; |
659 result.isSystemKey = IsSystemKeyEvent(result); | 322 result.isSystemKey = IsSystemKeyEvent(result); |
660 | 323 |
661 return result; | 324 return result; |
662 } | 325 } |
663 | 326 |
664 // WebMouseEvent -------------------------------------------------------------- | 327 // WebMouseEvent -------------------------------------------------------------- |
665 | 328 |
666 blink::WebMouseEvent WebMouseEventBuilder::Build(NSEvent* event, NSView* view) { | 329 blink::WebMouseEvent WebMouseEventBuilder::Build(NSEvent* event, NSView* view) { |
667 blink::WebMouseEvent result; | 330 blink::WebMouseEvent result; |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
951 break; | 614 break; |
952 default: | 615 default: |
953 NOTIMPLEMENTED(); | 616 NOTIMPLEMENTED(); |
954 result.type = blink::WebInputEvent::Undefined; | 617 result.type = blink::WebInputEvent::Undefined; |
955 } | 618 } |
956 | 619 |
957 return result; | 620 return result; |
958 } | 621 } |
959 | 622 |
960 } // namespace content | 623 } // namespace content |
OLD | NEW |