OLD | NEW |
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 #include "chrome/browser/ui/ash/event_rewriter.h" | 5 #include "chrome/browser/ui/ash/event_rewriter.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
13 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
14 #include "ui/aura/event.h" | |
15 #include "ui/aura/root_window.h" | 14 #include "ui/aura/root_window.h" |
| 15 #include "ui/base/event.h" |
16 #include "ui/base/keycodes/keyboard_code_conversion.h" | 16 #include "ui/base/keycodes/keyboard_code_conversion.h" |
17 | 17 |
18 #if defined(OS_CHROMEOS) | 18 #if defined(OS_CHROMEOS) |
19 #include <X11/extensions/XInput2.h> | 19 #include <X11/extensions/XInput2.h> |
20 #include <X11/keysym.h> | 20 #include <X11/keysym.h> |
21 #include <X11/Xlib.h> | 21 #include <X11/Xlib.h> |
22 | 22 |
23 // Get rid of a macro from Xlib.h that conflicts with OwnershipService class. | 23 // Get rid of a macro from Xlib.h that conflicts with OwnershipService class. |
24 #undef Status | 24 #undef Status |
25 | 25 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 found_apple = true; | 166 found_apple = true; |
167 if (!found_keyboard && LowerCaseEqualsASCII(tokens[i], "keyboard")) | 167 if (!found_keyboard && LowerCaseEqualsASCII(tokens[i], "keyboard")) |
168 found_keyboard = true; | 168 found_keyboard = true; |
169 if (found_apple && found_keyboard) | 169 if (found_apple && found_keyboard) |
170 return kDeviceAppleKeyboard; | 170 return kDeviceAppleKeyboard; |
171 } | 171 } |
172 | 172 |
173 return kDeviceUnknown; | 173 return kDeviceUnknown; |
174 } | 174 } |
175 | 175 |
176 void EventRewriter::RewriteForTesting(aura::KeyEvent* event) { | 176 void EventRewriter::RewriteForTesting(ui::KeyEvent* event) { |
177 Rewrite(event); | 177 Rewrite(event); |
178 } | 178 } |
179 | 179 |
180 ash::EventRewriterDelegate::Action EventRewriter::RewriteOrFilterKeyEvent( | 180 ash::EventRewriterDelegate::Action EventRewriter::RewriteOrFilterKeyEvent( |
181 aura::KeyEvent* event) { | 181 ui::KeyEvent* event) { |
182 if (event->HasNativeEvent()) | 182 if (event->HasNativeEvent()) |
183 Rewrite(event); | 183 Rewrite(event); |
184 return ash::EventRewriterDelegate::ACTION_REWRITE_EVENT; | 184 return ash::EventRewriterDelegate::ACTION_REWRITE_EVENT; |
185 } | 185 } |
186 | 186 |
187 ash::EventRewriterDelegate::Action EventRewriter::RewriteOrFilterLocatedEvent( | 187 ash::EventRewriterDelegate::Action EventRewriter::RewriteOrFilterLocatedEvent( |
188 aura::LocatedEvent* event) { | 188 ui::LocatedEvent* event) { |
189 if (event->HasNativeEvent()) | 189 if (event->HasNativeEvent()) |
190 RewriteLocatedEvent(event); | 190 RewriteLocatedEvent(event); |
191 return ash::EventRewriterDelegate::ACTION_REWRITE_EVENT; | 191 return ash::EventRewriterDelegate::ACTION_REWRITE_EVENT; |
192 } | 192 } |
193 | 193 |
194 void EventRewriter::OnKeyboardMappingChanged(const aura::RootWindow* root) { | 194 void EventRewriter::OnKeyboardMappingChanged(const aura::RootWindow* root) { |
195 #if defined(OS_CHROMEOS) | 195 #if defined(OS_CHROMEOS) |
196 RefreshKeycodes(); | 196 RefreshKeycodes(); |
197 #endif | 197 #endif |
198 } | 198 } |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 return kp_9_xkeycode_; | 325 return kp_9_xkeycode_; |
326 case XK_KP_Decimal: | 326 case XK_KP_Decimal: |
327 return kp_decimal_xkeycode_; | 327 return kp_decimal_xkeycode_; |
328 default: | 328 default: |
329 break; | 329 break; |
330 } | 330 } |
331 return 0U; | 331 return 0U; |
332 } | 332 } |
333 #endif | 333 #endif |
334 | 334 |
335 void EventRewriter::Rewrite(aura::KeyEvent* event) { | 335 void EventRewriter::Rewrite(ui::KeyEvent* event) { |
336 #if defined(OS_CHROMEOS) | 336 #if defined(OS_CHROMEOS) |
337 // Do not rewrite an event sent by ui_controls::SendKeyPress(). See | 337 // Do not rewrite an event sent by ui_controls::SendKeyPress(). See |
338 // crbug.com/136465. | 338 // crbug.com/136465. |
339 if (event->native_event()->xkey.send_event) | 339 if (event->native_event()->xkey.send_event) |
340 return; | 340 return; |
341 #endif | 341 #endif |
342 RewriteModifiers(event); | 342 RewriteModifiers(event); |
343 RewriteNumPadKeys(event); | 343 RewriteNumPadKeys(event); |
344 RewriteBackspaceAndArrowKeys(event); | 344 RewriteBackspaceAndArrowKeys(event); |
345 // TODO(yusukes): Implement crosbug.com/27167 (allow sending function keys). | 345 // TODO(yusukes): Implement crosbug.com/27167 (allow sending function keys). |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 | 402 |
403 *remapped_flags = | 403 *remapped_flags = |
404 (original_flags & ~(ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN)) | | 404 (original_flags & ~(ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN)) | |
405 *remapped_flags; | 405 *remapped_flags; |
406 *remapped_native_modifiers = | 406 *remapped_native_modifiers = |
407 (original_native_modifiers & ~(Mod4Mask | ControlMask | Mod1Mask)) | | 407 (original_native_modifiers & ~(Mod4Mask | ControlMask | Mod1Mask)) | |
408 *remapped_native_modifiers; | 408 *remapped_native_modifiers; |
409 #endif | 409 #endif |
410 } | 410 } |
411 | 411 |
412 bool EventRewriter::RewriteModifiers(aura::KeyEvent* event) { | 412 bool EventRewriter::RewriteModifiers(ui::KeyEvent* event) { |
413 // Do nothing if we have just logged in as guest but have not restarted chrome | 413 // Do nothing if we have just logged in as guest but have not restarted chrome |
414 // process yet (so we are still on the login screen). In this situations we | 414 // process yet (so we are still on the login screen). In this situations we |
415 // have no user profile so can not do anything useful. | 415 // have no user profile so can not do anything useful. |
416 // Note that currently, unlike other accounts, when user logs in as guest, we | 416 // Note that currently, unlike other accounts, when user logs in as guest, we |
417 // restart chrome process. In future this is to be changed. | 417 // restart chrome process. In future this is to be changed. |
418 // TODO(glotov): remove the following condition when we do not restart chrome | 418 // TODO(glotov): remove the following condition when we do not restart chrome |
419 // when user logs in as guest. | 419 // when user logs in as guest. |
420 #if defined(OS_CHROMEOS) | 420 #if defined(OS_CHROMEOS) |
421 if (chromeos::UserManager::Get()->IsLoggedInAsGuest() && | 421 if (chromeos::UserManager::Get()->IsLoggedInAsGuest() && |
422 chromeos::BaseLoginDisplayHost::default_host()) | 422 chromeos::BaseLoginDisplayHost::default_host()) |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 OverwriteEvent(event, | 493 OverwriteEvent(event, |
494 remapped_native_keycode, remapped_native_modifiers, | 494 remapped_native_keycode, remapped_native_modifiers, |
495 remapped_keycode, remapped_flags); | 495 remapped_keycode, remapped_flags); |
496 return true; | 496 return true; |
497 #else | 497 #else |
498 // TODO(yusukes): Support Ash on other platforms if needed. | 498 // TODO(yusukes): Support Ash on other platforms if needed. |
499 return false; | 499 return false; |
500 #endif | 500 #endif |
501 } | 501 } |
502 | 502 |
503 bool EventRewriter::RewriteNumPadKeys(aura::KeyEvent* event) { | 503 bool EventRewriter::RewriteNumPadKeys(ui::KeyEvent* event) { |
504 bool rewritten = false; | 504 bool rewritten = false; |
505 #if defined(OS_CHROMEOS) | 505 #if defined(OS_CHROMEOS) |
506 XEvent* xev = event->native_event(); | 506 XEvent* xev = event->native_event(); |
507 XKeyEvent* xkey = &(xev->xkey); | 507 XKeyEvent* xkey = &(xev->xkey); |
508 | 508 |
509 const KeySym keysym = XLookupKeysym(xkey, 0); | 509 const KeySym keysym = XLookupKeysym(xkey, 0); |
510 switch (keysym) { | 510 switch (keysym) { |
511 case XK_KP_Insert: | 511 case XK_KP_Insert: |
512 OverwriteEvent(event, kp_0_xkeycode_, xkey->state | Mod2Mask, | 512 OverwriteEvent(event, kp_0_xkeycode_, xkey->state | Mod2Mask, |
513 ui::VKEY_NUMPAD0, event->flags()); | 513 ui::VKEY_NUMPAD0, event->flags()); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 break; | 575 break; |
576 default: | 576 default: |
577 break; | 577 break; |
578 } | 578 } |
579 #else | 579 #else |
580 // TODO(yusukes): Support Ash on other platforms if needed. | 580 // TODO(yusukes): Support Ash on other platforms if needed. |
581 #endif | 581 #endif |
582 return rewritten; | 582 return rewritten; |
583 } | 583 } |
584 | 584 |
585 bool EventRewriter::RewriteBackspaceAndArrowKeys(aura::KeyEvent* event) { | 585 bool EventRewriter::RewriteBackspaceAndArrowKeys(ui::KeyEvent* event) { |
586 bool rewritten = false; | 586 bool rewritten = false; |
587 #if defined(OS_CHROMEOS) | 587 #if defined(OS_CHROMEOS) |
588 XEvent* xev = event->native_event(); | 588 XEvent* xev = event->native_event(); |
589 XKeyEvent* xkey = &(xev->xkey); | 589 XKeyEvent* xkey = &(xev->xkey); |
590 | 590 |
591 const KeySym keysym = XLookupKeysym(xkey, 0); | 591 const KeySym keysym = XLookupKeysym(xkey, 0); |
592 if (keysym == XK_BackSpace && (xkey->state & Mod1Mask)) { | 592 if (keysym == XK_BackSpace && (xkey->state & Mod1Mask)) { |
593 // Remap Alt+Backspace to Delete. | 593 // Remap Alt+Backspace to Delete. |
594 OverwriteEvent(event, delete_xkeycode_, xkey->state & ~Mod1Mask, | 594 OverwriteEvent(event, delete_xkeycode_, xkey->state & ~Mod1Mask, |
595 ui::VKEY_DELETE, event->flags() & ~ui::EF_ALT_DOWN); | 595 ui::VKEY_DELETE, event->flags() & ~ui::EF_ALT_DOWN); |
(...skipping 26 matching lines...) Expand all Loading... |
622 OverwriteEvent(event, next_xkeycode_, xkey->state & ~Mod1Mask, | 622 OverwriteEvent(event, next_xkeycode_, xkey->state & ~Mod1Mask, |
623 ui::VKEY_NEXT, event->flags() & ~ui::EF_ALT_DOWN); | 623 ui::VKEY_NEXT, event->flags() & ~ui::EF_ALT_DOWN); |
624 rewritten = true; | 624 rewritten = true; |
625 } | 625 } |
626 #else | 626 #else |
627 // TODO(yusukes): Support Ash on other platforms if needed. | 627 // TODO(yusukes): Support Ash on other platforms if needed. |
628 #endif | 628 #endif |
629 return rewritten; | 629 return rewritten; |
630 } | 630 } |
631 | 631 |
632 void EventRewriter::RewriteLocatedEvent(aura::LocatedEvent* event) { | 632 void EventRewriter::RewriteLocatedEvent(ui::LocatedEvent* event) { |
633 #if defined(OS_CHROMEOS) | 633 #if defined(OS_CHROMEOS) |
634 XEvent* xevent = event->native_event(); | 634 XEvent* xevent = event->native_event(); |
635 if (!xevent || xevent->type != GenericEvent) | 635 if (!xevent || xevent->type != GenericEvent) |
636 return; | 636 return; |
637 | 637 |
638 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xevent->xcookie.data); | 638 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xevent->xcookie.data); |
639 if (xievent->evtype != XI_ButtonPress && xievent->evtype != XI_ButtonRelease) | 639 if (xievent->evtype != XI_ButtonPress && xievent->evtype != XI_ButtonRelease) |
640 return; | 640 return; |
641 | 641 |
642 // First, remap modifier masks. | 642 // First, remap modifier masks. |
(...skipping 18 matching lines...) Expand all Loading... |
661 | 661 |
662 const int mouse_event_flags = event->flags() & | 662 const int mouse_event_flags = event->flags() & |
663 (ui::EF_IS_DOUBLE_CLICK | ui::EF_IS_TRIPLE_CLICK | ui::EF_IS_NON_CLIENT | | 663 (ui::EF_IS_DOUBLE_CLICK | ui::EF_IS_TRIPLE_CLICK | ui::EF_IS_NON_CLIENT | |
664 ui::EF_IS_SYNTHESIZED | ui::EF_FROM_TOUCH); | 664 ui::EF_IS_SYNTHESIZED | ui::EF_FROM_TOUCH); |
665 event->set_flags(mouse_event_flags | ui::EventFlagsFromNative(xevent)); | 665 event->set_flags(mouse_event_flags | ui::EventFlagsFromNative(xevent)); |
666 #else | 666 #else |
667 // TODO(yusukes): Support Ash on other platforms if needed. | 667 // TODO(yusukes): Support Ash on other platforms if needed. |
668 #endif | 668 #endif |
669 } | 669 } |
670 | 670 |
671 void EventRewriter::OverwriteEvent(aura::KeyEvent* event, | 671 void EventRewriter::OverwriteEvent(ui::KeyEvent* event, |
672 unsigned int new_native_keycode, | 672 unsigned int new_native_keycode, |
673 unsigned int new_native_state, | 673 unsigned int new_native_state, |
674 ui::KeyboardCode new_keycode, | 674 ui::KeyboardCode new_keycode, |
675 int new_flags) { | 675 int new_flags) { |
676 #if defined(OS_CHROMEOS) | 676 #if defined(OS_CHROMEOS) |
677 XEvent* xev = event->native_event(); | 677 XEvent* xev = event->native_event(); |
678 XKeyEvent* xkey = &(xev->xkey); | 678 XKeyEvent* xkey = &(xev->xkey); |
679 xkey->keycode = new_native_keycode; | 679 xkey->keycode = new_native_keycode; |
680 xkey->state = new_native_state; | 680 xkey->state = new_native_state; |
681 event->set_key_code(new_keycode); | 681 event->set_key_code(new_keycode); |
(...skipping 11 matching lines...) Expand all Loading... |
693 const DeviceType type = EventRewriter::GetDeviceType(device_name); | 693 const DeviceType type = EventRewriter::GetDeviceType(device_name); |
694 if (type == kDeviceAppleKeyboard) { | 694 if (type == kDeviceAppleKeyboard) { |
695 VLOG(1) << "Apple keyboard '" << device_name << "' connected: " | 695 VLOG(1) << "Apple keyboard '" << device_name << "' connected: " |
696 << "id=" << device_id; | 696 << "id=" << device_id; |
697 } | 697 } |
698 // Always overwrite the existing device_id since the X server may reuse a | 698 // Always overwrite the existing device_id since the X server may reuse a |
699 // device id for an unattached device. | 699 // device id for an unattached device. |
700 device_id_to_type_[device_id] = type; | 700 device_id_to_type_[device_id] = type; |
701 return type; | 701 return type; |
702 } | 702 } |
OLD | NEW |