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

Side by Side Diff: ui/events/keycodes/keyboard_code_conversion_mac.mm

Issue 1331013004: [KeyEvent Mac] Move WebInputEventFactory into chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Format imported code to chromium style Created 5 years, 3 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #import "ui/events/keycodes/keyboard_code_conversion_mac.h" 5 #import "ui/events/keycodes/keyboard_code_conversion_mac.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #import <Carbon/Carbon.h> 9 #import <Carbon/Carbon.h>
10 10
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 { VKEY_CRSEL /* 0xF7 */, -1, 0 }, 193 { VKEY_CRSEL /* 0xF7 */, -1, 0 },
194 { VKEY_EXSEL /* 0xF8 */, -1, 0 }, 194 { VKEY_EXSEL /* 0xF8 */, -1, 0 },
195 { VKEY_EREOF /* 0xF9 */, -1, 0 }, 195 { VKEY_EREOF /* 0xF9 */, -1, 0 },
196 { VKEY_PLAY /* 0xFA */, -1, 0 }, 196 { VKEY_PLAY /* 0xFA */, -1, 0 },
197 { VKEY_ZOOM /* 0xFB */, -1, 0 }, 197 { VKEY_ZOOM /* 0xFB */, -1, 0 },
198 { VKEY_NONAME /* 0xFC */, -1, 0 }, 198 { VKEY_NONAME /* 0xFC */, -1, 0 },
199 { VKEY_PA1 /* 0xFD */, -1, 0 }, 199 { VKEY_PA1 /* 0xFD */, -1, 0 },
200 { VKEY_OEM_CLEAR /* 0xFE */, kVK_ANSI_KeypadClear, kClearCharCode } 200 { VKEY_OEM_CLEAR /* 0xFE */, kVK_ANSI_KeypadClear, kClearCharCode }
201 }; 201 };
202 202
203 bool IsKeypadEvent(NSEvent* event) {
204 // Check that this is the type of event that has a keyCode.
205 switch ([event type]) {
206 case NSKeyDown:
207 case NSKeyUp:
208 case NSFlagsChanged:
209 break;
210 default:
211 return false;
212 }
213
214 switch ([event keyCode]) {
215 case kVK_ANSI_KeypadClear:
216 case kVK_ANSI_KeypadEquals:
217 case kVK_ANSI_KeypadMultiply:
218 case kVK_ANSI_KeypadDivide:
219 case kVK_ANSI_KeypadMinus:
220 case kVK_ANSI_KeypadPlus:
221 case kVK_ANSI_KeypadEnter:
222 case kVK_ANSI_KeypadDecimal:
223 case kVK_ANSI_Keypad0:
224 case kVK_ANSI_Keypad1:
225 case kVK_ANSI_Keypad2:
226 case kVK_ANSI_Keypad3:
227 case kVK_ANSI_Keypad4:
228 case kVK_ANSI_Keypad5:
229 case kVK_ANSI_Keypad6:
230 case kVK_ANSI_Keypad7:
231 case kVK_ANSI_Keypad8:
232 case kVK_ANSI_Keypad9:
233 return true;
234 }
235
236 return false;
237 }
238
203 // A convenient array for getting symbol characters on the number keys. 239 // A convenient array for getting symbol characters on the number keys.
204 const char kShiftCharsForNumberKeys[] = ")!@#$%^&*("; 240 const char kShiftCharsForNumberKeys[] = ")!@#$%^&*(";
205 241
206 // Translates from character code to keyboard code. 242 // Translates from character code to keyboard code.
207 KeyboardCode KeyboardCodeFromCharCode(unichar charCode) { 243 KeyboardCode KeyboardCodeFromCharCode(unichar charCode) {
208 switch (charCode) { 244 switch (charCode) {
209 case 8: case 0x7F: return VKEY_BACK; 245 case 8: case 0x7F: return VKEY_BACK;
210 case 9: return VKEY_TAB; 246 case 9: return VKEY_TAB;
211 case 0xD: case 3: return VKEY_RETURN; 247 case 0xD: case 3: return VKEY_RETURN;
212 case 0x1B: return VKEY_ESCAPE; 248 case 0x1B: return VKEY_ESCAPE;
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 } 562 }
527 } 563 }
528 564
529 // TODO(suzhe): Support characters for Option key bindings. 565 // TODO(suzhe): Support characters for Option key bindings.
530 return macKeycode; 566 return macKeycode;
531 } 567 }
532 568
533 KeyboardCode KeyboardCodeFromNSEvent(NSEvent* event) { 569 KeyboardCode KeyboardCodeFromNSEvent(NSEvent* event) {
534 KeyboardCode code = VKEY_UNKNOWN; 570 KeyboardCode code = VKEY_UNKNOWN;
535 571
536 if ([event type] == NSKeyDown || [event type] == NSKeyUp) { 572 if (!IsKeypadEvent(event) &&
Alexei Svitkine (slow) 2015/09/14 17:14:43 Is this introducing a logic change? if so, it shou
dtapuska 2015/09/14 18:31:21 Done.
573 ([event type] == NSKeyDown || [event type] == NSKeyUp)) {
537 NSString* characters = [event characters]; 574 NSString* characters = [event characters];
538 if ([characters length] > 0) 575 if ([characters length] > 0)
539 code = KeyboardCodeFromCharCode([characters characterAtIndex:0]); 576 code = KeyboardCodeFromCharCode([characters characterAtIndex:0]);
540 if (code) 577 if (code)
541 return code; 578 return code;
542 579
543 characters = [event charactersIgnoringModifiers]; 580 characters = [event charactersIgnoringModifiers];
544 if ([characters length] > 0) 581 if ([characters length] > 0)
545 code = KeyboardCodeFromCharCode([characters characterAtIndex:0]); 582 code = KeyboardCodeFromCharCode([characters characterAtIndex:0]);
546 if (code) 583 if (code)
547 return code; 584 return code;
548 } 585 }
549 return KeyboardCodeFromKeyCode([event keyCode]); 586 return KeyboardCodeFromKeyCode([event keyCode]);
550 } 587 }
551 588
552 DomCode CodeFromNSEvent(NSEvent* event) { 589 DomCode CodeFromNSEvent(NSEvent* event) {
553 return ui::KeycodeConverter::NativeKeycodeToDomCode([event keyCode]); 590 return ui::KeycodeConverter::NativeKeycodeToDomCode([event keyCode]);
554 } 591 }
555 592
556 } // namespace ui 593 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698