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

Side by Side Diff: chrome/browser/chromeos/events/event_rewriter.cc

Issue 2731283004: Do not use ash in chromeos::EventRewriter. (Closed)
Patch Set: Fix a crash Created 3 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/chromeos/events/event_rewriter.h" 5 #include "chrome/browser/chromeos/events/event_rewriter.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
11 #include "ash/common/wm/window_state.h"
12 #include "ash/sticky_keys/sticky_keys_controller.h"
13 #include "ash/wm/window_util.h"
14 #include "base/command_line.h" 11 #include "base/command_line.h"
15 #include "base/logging.h" 12 #include "base/logging.h"
16 #include "base/macros.h" 13 #include "base/macros.h"
17 #include "base/strings/string_split.h" 14 #include "base/strings/string_split.h"
18 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
19 #include "base/sys_info.h" 16 #include "base/sys_info.h"
20 #include "chrome/browser/chromeos/login/ui/login_display_host.h" 17 #include "chrome/browser/chromeos/login/ui/login_display_host.h"
21 #include "chrome/browser/extensions/extension_commands_global_registry.h" 18 #include "chrome/browser/extensions/extension_commands_global_registry.h"
22 #include "chrome/browser/profiles/profile_manager.h" 19 #include "chrome/browser/profiles/profile_manager.h"
23 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" 20 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
24 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" 21 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
25 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
26 #include "chromeos/chromeos_switches.h" 23 #include "chromeos/chromeos_switches.h"
27 #include "components/prefs/pref_service.h" 24 #include "components/prefs/pref_service.h"
28 #include "components/user_manager/user_manager.h" 25 #include "components/user_manager/user_manager.h"
29 #include "ui/base/ime/chromeos/ime_keyboard.h" 26 #include "ui/base/ime/chromeos/ime_keyboard.h"
30 #include "ui/base/ime/chromeos/input_method_manager.h" 27 #include "ui/base/ime/chromeos/input_method_manager.h"
31 #include "ui/events/devices/input_device_manager.h" 28 #include "ui/events/devices/input_device_manager.h"
32 #include "ui/events/event.h" 29 #include "ui/events/event.h"
33 #include "ui/events/event_utils.h" 30 #include "ui/events/event_utils.h"
34 #include "ui/events/keycodes/dom/dom_code.h" 31 #include "ui/events/keycodes/dom/dom_code.h"
35 #include "ui/events/keycodes/dom/dom_key.h" 32 #include "ui/events/keycodes/dom/dom_key.h"
36 #include "ui/events/keycodes/dom/keycode_converter.h" 33 #include "ui/events/keycodes/dom/keycode_converter.h"
37 #include "ui/events/keycodes/keyboard_code_conversion.h" 34 #include "ui/events/keycodes/keyboard_code_conversion.h"
38 #include "ui/wm/core/window_util.h" 35 #include "ui/wm/core/window_util.h"
39 36
40 #if defined(USE_X11)
41 #include <X11/extensions/XInput2.h>
42 #include <X11/Xlib.h>
43
44 // Get rid of macros from Xlib.h that conflicts with other parts of the code.
45 #undef RootWindow
46 #undef Status
47
48 #include "ui/base/x/x11_util.h"
49 #include "ui/events/keycodes/keyboard_code_conversion_x.h"
50 #endif
51
52 namespace chromeos { 37 namespace chromeos {
53 38
54 namespace { 39 namespace {
55 40
56 // Hotrod controller vendor/product ids. 41 // Hotrod controller vendor/product ids.
57 const int kHotrodRemoteVendorId = 0x0471; 42 const int kHotrodRemoteVendorId = 0x0471;
58 const int kHotrodRemoteProductId = 0x21cc; 43 const int kHotrodRemoteProductId = 0x21cc;
59 const int kUnknownVendorId = -1; 44 const int kUnknownVendorId = -1;
60 const int kUnknownProductId = -1; 45 const int kUnknownProductId = -1;
61 46
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 case ui::DomCode::META_RIGHT: 284 case ui::DomCode::META_RIGHT:
300 return right ? ui::DomCode::META_RIGHT : ui::DomCode::META_LEFT; 285 return right ? ui::DomCode::META_RIGHT : ui::DomCode::META_LEFT;
301 default: 286 default:
302 break; 287 break;
303 } 288 }
304 return code; 289 return code;
305 } 290 }
306 291
307 } // namespace 292 } // namespace
308 293
309 EventRewriter::EventRewriter(ash::StickyKeysController* sticky_keys_controller) 294 EventRewriter::EventRewriter(ui::EventRewriter* sticky_keys_controller)
310 : last_keyboard_device_id_(ui::ED_UNKNOWN_DEVICE), 295 : last_keyboard_device_id_(ui::ED_UNKNOWN_DEVICE),
311 ime_keyboard_for_testing_(NULL), 296 ime_keyboard_for_testing_(NULL),
312 pref_service_for_testing_(NULL), 297 pref_service_for_testing_(NULL),
313 sticky_keys_controller_(sticky_keys_controller), 298 sticky_keys_controller_(sticky_keys_controller),
314 pressed_modifier_latches_(ui::EF_NONE), 299 pressed_modifier_latches_(ui::EF_NONE),
315 latched_modifier_latches_(ui::EF_NONE), 300 latched_modifier_latches_(ui::EF_NONE),
316 used_modifier_latches_(ui::EF_NONE) {} 301 used_modifier_latches_(ui::EF_NONE) {}
317 302
318 EventRewriter::~EventRewriter() {} 303 EventRewriter::~EventRewriter() {}
319 304
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 348
364 ui::EventRewriteStatus EventRewriter::NextDispatchEvent( 349 ui::EventRewriteStatus EventRewriter::NextDispatchEvent(
365 const ui::Event& last_event, 350 const ui::Event& last_event,
366 std::unique_ptr<ui::Event>* new_event) { 351 std::unique_ptr<ui::Event>* new_event) {
367 if (sticky_keys_controller_) { 352 if (sticky_keys_controller_) {
368 // In the case of sticky keys, we know what the events obtained here are: 353 // In the case of sticky keys, we know what the events obtained here are:
369 // modifier key releases that match the ones previously discarded. So, we 354 // modifier key releases that match the ones previously discarded. So, we
370 // know that they don't have to be passed through the post-sticky key 355 // know that they don't have to be passed through the post-sticky key
371 // rewriting phases, |RewriteExtendedKeys()| and |RewriteFunctionKeys()|, 356 // rewriting phases, |RewriteExtendedKeys()| and |RewriteFunctionKeys()|,
372 // because those phases do nothing with modifier key releases. 357 // because those phases do nothing with modifier key releases.
373 return sticky_keys_controller_->NextDispatchEvent(new_event); 358 return sticky_keys_controller_->NextDispatchEvent(last_event, new_event);
374 } 359 }
375 NOTREACHED(); 360 NOTREACHED();
376 return ui::EVENT_REWRITE_CONTINUE; 361 return ui::EVENT_REWRITE_CONTINUE;
377 } 362 }
378 363
379 void EventRewriter::BuildRewrittenKeyEvent( 364 void EventRewriter::BuildRewrittenKeyEvent(
380 const ui::KeyEvent& key_event, 365 const ui::KeyEvent& key_event,
381 const MutableKeyState& state, 366 const MutableKeyState& state,
382 std::unique_ptr<ui::Event>* rewritten_event) { 367 std::unique_ptr<ui::Event>* rewritten_event) {
383 ui::KeyEvent* rewritten_key_event = 368 ui::KeyEvent* rewritten_key_event =
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 // Early exit with completed event. 501 // Early exit with completed event.
517 BuildRewrittenKeyEvent(key_event, state, rewritten_event); 502 BuildRewrittenKeyEvent(key_event, state, rewritten_event);
518 return ui::EVENT_REWRITE_REWRITTEN; 503 return ui::EVENT_REWRITE_REWRITTEN;
519 } 504 }
520 RewriteNumPadKeys(key_event, &state); 505 RewriteNumPadKeys(key_event, &state);
521 } 506 }
522 507
523 ui::EventRewriteStatus status = ui::EVENT_REWRITE_CONTINUE; 508 ui::EventRewriteStatus status = ui::EVENT_REWRITE_CONTINUE;
524 bool is_sticky_key_extension_command = false; 509 bool is_sticky_key_extension_command = false;
525 if (sticky_keys_controller_) { 510 if (sticky_keys_controller_) {
526 status = sticky_keys_controller_->RewriteKeyEvent(key_event, state.key_code, 511 std::unique_ptr<ui::Event> tmp_event = ui::Event::Clone(key_event);
527 &state.flags); 512 tmp_event->AsKeyEvent()->set_key_code(state.key_code);
513 tmp_event->AsKeyEvent()->set_flags(state.flags);
514 std::unique_ptr<ui::Event> output_event;
515 status = sticky_keys_controller_->RewriteEvent(*tmp_event, &output_event);
516 if (status == ui::EVENT_REWRITE_REWRITTEN)
517 state.flags = output_event->flags();
528 if (status == ui::EVENT_REWRITE_DISCARD) 518 if (status == ui::EVENT_REWRITE_DISCARD)
529 return ui::EVENT_REWRITE_DISCARD; 519 return ui::EVENT_REWRITE_DISCARD;
530 is_sticky_key_extension_command = 520 is_sticky_key_extension_command =
531 IsExtensionCommandRegistered(state.key_code, state.flags); 521 IsExtensionCommandRegistered(state.key_code, state.flags);
532 } 522 }
533 523
534 // If flags have changed, this may change the interpretation of the key, 524 // If flags have changed, this may change the interpretation of the key,
535 // so reapply layout. 525 // so reapply layout.
536 if (state.flags != key_event.flags()) 526 if (state.flags != key_event.flags())
537 SetMeaningForLayout(key_event.type(), &state); 527 SetMeaningForLayout(key_event.type(), &state);
538 528
539 // If sticky key rewrites the event, and it matches an extension command, do 529 // If sticky key rewrites the event, and it matches an extension command, do
540 // not further rewrite the event since it won't match the extension command 530 // not further rewrite the event since it won't match the extension command
541 // thereafter. 531 // thereafter.
542 if (!is_sticky_key_extension_command && !(key_event.flags() & ui::EF_FINAL)) { 532 if (!is_sticky_key_extension_command && !(key_event.flags() & ui::EF_FINAL)) {
543 RewriteExtendedKeys(key_event, &state); 533 RewriteExtendedKeys(key_event, &state);
544 RewriteFunctionKeys(key_event, &state); 534 RewriteFunctionKeys(key_event, &state);
545 } 535 }
546 if ((key_event.flags() == state.flags) && 536 if ((key_event.flags() == state.flags) &&
547 (key_event.key_code() == state.key_code) && 537 (key_event.key_code() == state.key_code) &&
548 #if defined(USE_X11)
549 // TODO(kpschoedel): This test is present because several consumers of
550 // key events depend on having a native core X11 event, so we rewrite
551 // all XI2 key events (GenericEvent) into corresponding core X11 key
552 // events. Remove this when event consumers no longer care about
553 // native X11 event details (crbug.com/380349).
554 (!key_event.HasNativeEvent() ||
555 (key_event.native_event()->type != GenericEvent)) &&
556 #endif
557 (status == ui::EVENT_REWRITE_CONTINUE)) { 538 (status == ui::EVENT_REWRITE_CONTINUE)) {
558 return ui::EVENT_REWRITE_CONTINUE; 539 return ui::EVENT_REWRITE_CONTINUE;
559 } 540 }
560 // Sticky keys may have returned a result other than |EVENT_REWRITE_CONTINUE|, 541 // Sticky keys may have returned a result other than |EVENT_REWRITE_CONTINUE|,
561 // in which case we need to preserve that return status. Alternatively, we 542 // in which case we need to preserve that return status. Alternatively, we
562 // might be here because key_event changed, in which case we need to 543 // might be here because key_event changed, in which case we need to
563 // return |EVENT_REWRITE_REWRITTEN|. 544 // return |EVENT_REWRITE_REWRITTEN|.
564 if (status == ui::EVENT_REWRITE_CONTINUE) 545 if (status == ui::EVENT_REWRITE_CONTINUE)
565 status = ui::EVENT_REWRITE_REWRITTEN; 546 status = ui::EVENT_REWRITE_REWRITTEN;
566 BuildRewrittenKeyEvent(key_event, state, rewritten_event); 547 BuildRewrittenKeyEvent(key_event, state, rewritten_event);
567 return status; 548 return status;
568 } 549 }
569 550
570 ui::EventRewriteStatus EventRewriter::RewriteMouseButtonEvent( 551 ui::EventRewriteStatus EventRewriter::RewriteMouseButtonEvent(
571 const ui::MouseEvent& mouse_event, 552 const ui::MouseEvent& mouse_event,
572 std::unique_ptr<ui::Event>* rewritten_event) { 553 std::unique_ptr<ui::Event>* rewritten_event) {
573 int flags = mouse_event.flags(); 554 int flags = mouse_event.flags();
574 RewriteLocatedEvent(mouse_event, &flags); 555 RewriteLocatedEvent(mouse_event, &flags);
575 ui::EventRewriteStatus status = ui::EVENT_REWRITE_CONTINUE; 556 ui::EventRewriteStatus status = ui::EVENT_REWRITE_CONTINUE;
576 if (sticky_keys_controller_) 557 if (sticky_keys_controller_) {
577 status = sticky_keys_controller_->RewriteMouseEvent(mouse_event, &flags); 558 std::unique_ptr<ui::Event> tmp_event = ui::Event::Clone(mouse_event);
559 tmp_event->set_flags(flags);
560 std::unique_ptr<ui::Event> output_event;
561 status = sticky_keys_controller_->RewriteEvent(*tmp_event, &output_event);
562 if (status == ui::EVENT_REWRITE_REWRITTEN)
563 flags = output_event->flags();
564 }
578 int changed_button = ui::EF_NONE; 565 int changed_button = ui::EF_NONE;
579 if ((mouse_event.type() == ui::ET_MOUSE_PRESSED) || 566 if ((mouse_event.type() == ui::ET_MOUSE_PRESSED) ||
580 (mouse_event.type() == ui::ET_MOUSE_RELEASED)) { 567 (mouse_event.type() == ui::ET_MOUSE_RELEASED)) {
581 changed_button = RewriteModifierClick(mouse_event, &flags); 568 changed_button = RewriteModifierClick(mouse_event, &flags);
582 } 569 }
583 if ((mouse_event.flags() == flags) && 570 if ((mouse_event.flags() == flags) &&
584 (status == ui::EVENT_REWRITE_CONTINUE)) { 571 (status == ui::EVENT_REWRITE_CONTINUE)) {
585 return ui::EVENT_REWRITE_CONTINUE; 572 return ui::EVENT_REWRITE_CONTINUE;
586 } 573 }
587 if (status == ui::EVENT_REWRITE_CONTINUE) 574 if (status == ui::EVENT_REWRITE_CONTINUE)
588 status = ui::EVENT_REWRITE_REWRITTEN; 575 status = ui::EVENT_REWRITE_REWRITTEN;
589 ui::MouseEvent* rewritten_mouse_event = new ui::MouseEvent(mouse_event); 576 ui::MouseEvent* rewritten_mouse_event = new ui::MouseEvent(mouse_event);
590 rewritten_event->reset(rewritten_mouse_event); 577 rewritten_event->reset(rewritten_mouse_event);
591 rewritten_mouse_event->set_flags(flags); 578 rewritten_mouse_event->set_flags(flags);
592 #if defined(USE_X11)
593 ui::UpdateX11EventForFlags(rewritten_mouse_event);
594 #endif
595 if (changed_button != ui::EF_NONE) { 579 if (changed_button != ui::EF_NONE) {
596 rewritten_mouse_event->set_changed_button_flags(changed_button); 580 rewritten_mouse_event->set_changed_button_flags(changed_button);
597 #if defined(USE_X11)
598 ui::UpdateX11EventForChangedButtonFlags(rewritten_mouse_event);
599 #endif
600 } 581 }
601 return status; 582 return status;
602 } 583 }
603 584
604 ui::EventRewriteStatus EventRewriter::RewriteMouseWheelEvent( 585 ui::EventRewriteStatus EventRewriter::RewriteMouseWheelEvent(
605 const ui::MouseWheelEvent& wheel_event, 586 const ui::MouseWheelEvent& wheel_event,
606 std::unique_ptr<ui::Event>* rewritten_event) { 587 std::unique_ptr<ui::Event>* rewritten_event) {
607 if (!sticky_keys_controller_) 588 if (!sticky_keys_controller_)
608 return ui::EVENT_REWRITE_CONTINUE; 589 return ui::EVENT_REWRITE_CONTINUE;
609 int flags = wheel_event.flags(); 590 int flags = wheel_event.flags();
610 RewriteLocatedEvent(wheel_event, &flags); 591 RewriteLocatedEvent(wheel_event, &flags);
592 std::unique_ptr<ui::Event> tmp_event = ui::Event::Clone(wheel_event);
593 tmp_event->set_flags(flags);
594 std::unique_ptr<ui::Event> output_event;
611 ui::EventRewriteStatus status = 595 ui::EventRewriteStatus status =
612 sticky_keys_controller_->RewriteMouseEvent(wheel_event, &flags); 596 sticky_keys_controller_->RewriteEvent(*tmp_event, &output_event);
613 if ((wheel_event.flags() == flags) && 597 if (status == ui::EVENT_REWRITE_REWRITTEN) {
614 (status == ui::EVENT_REWRITE_CONTINUE)) { 598 flags = output_event->flags();
615 return ui::EVENT_REWRITE_CONTINUE; 599 } else if (status == ui::EVENT_REWRITE_CONTINUE) {
600 if (wheel_event.flags() == flags)
601 return ui::EVENT_REWRITE_CONTINUE;
602 status = ui::EVENT_REWRITE_REWRITTEN;
616 } 603 }
617 if (status == ui::EVENT_REWRITE_CONTINUE)
618 status = ui::EVENT_REWRITE_REWRITTEN;
619 ui::MouseWheelEvent* rewritten_wheel_event = 604 ui::MouseWheelEvent* rewritten_wheel_event =
620 new ui::MouseWheelEvent(wheel_event); 605 new ui::MouseWheelEvent(wheel_event);
621 rewritten_event->reset(rewritten_wheel_event); 606 rewritten_event->reset(rewritten_wheel_event);
622 rewritten_wheel_event->set_flags(flags); 607 rewritten_wheel_event->set_flags(flags);
623 #if defined(USE_X11)
624 ui::UpdateX11EventForFlags(rewritten_wheel_event);
625 #endif
626 return status; 608 return status;
627 } 609 }
628 610
629 ui::EventRewriteStatus EventRewriter::RewriteTouchEvent( 611 ui::EventRewriteStatus EventRewriter::RewriteTouchEvent(
630 const ui::TouchEvent& touch_event, 612 const ui::TouchEvent& touch_event,
631 std::unique_ptr<ui::Event>* rewritten_event) { 613 std::unique_ptr<ui::Event>* rewritten_event) {
632 int flags = touch_event.flags(); 614 int flags = touch_event.flags();
633 RewriteLocatedEvent(touch_event, &flags); 615 RewriteLocatedEvent(touch_event, &flags);
634 if (touch_event.flags() == flags) 616 if (touch_event.flags() == flags)
635 return ui::EVENT_REWRITE_CONTINUE; 617 return ui::EVENT_REWRITE_CONTINUE;
636 ui::TouchEvent* rewritten_touch_event = new ui::TouchEvent(touch_event); 618 ui::TouchEvent* rewritten_touch_event = new ui::TouchEvent(touch_event);
637 rewritten_event->reset(rewritten_touch_event); 619 rewritten_event->reset(rewritten_touch_event);
638 rewritten_touch_event->set_flags(flags); 620 rewritten_touch_event->set_flags(flags);
639 #if defined(USE_X11)
640 ui::UpdateX11EventForFlags(rewritten_touch_event);
641 #endif
642 return ui::EVENT_REWRITE_REWRITTEN; 621 return ui::EVENT_REWRITE_REWRITTEN;
643 } 622 }
644 623
645 ui::EventRewriteStatus EventRewriter::RewriteScrollEvent( 624 ui::EventRewriteStatus EventRewriter::RewriteScrollEvent(
646 const ui::ScrollEvent& scroll_event, 625 const ui::ScrollEvent& scroll_event,
647 std::unique_ptr<ui::Event>* rewritten_event) { 626 std::unique_ptr<ui::Event>* rewritten_event) {
648 int flags = scroll_event.flags(); 627 if (!sticky_keys_controller_)
649 ui::EventRewriteStatus status = ui::EVENT_REWRITE_CONTINUE; 628 return ui::EVENT_REWRITE_CONTINUE;
650 if (sticky_keys_controller_) 629 return sticky_keys_controller_->RewriteEvent(scroll_event, rewritten_event);
651 status = sticky_keys_controller_->RewriteScrollEvent(scroll_event, &flags);
652 if (status == ui::EVENT_REWRITE_CONTINUE)
653 return status;
654 ui::ScrollEvent* rewritten_scroll_event = new ui::ScrollEvent(scroll_event);
655 rewritten_event->reset(rewritten_scroll_event);
656 rewritten_scroll_event->set_flags(flags);
657 #if defined(USE_X11)
658 ui::UpdateX11EventForFlags(rewritten_scroll_event);
659 #endif
660 return status;
661 } 630 }
662 631
663 bool EventRewriter::RewriteModifierKeys(const ui::KeyEvent& key_event, 632 bool EventRewriter::RewriteModifierKeys(const ui::KeyEvent& key_event,
664 MutableKeyState* state) { 633 MutableKeyState* state) {
665 DCHECK(key_event.type() == ui::ET_KEY_PRESSED || 634 DCHECK(key_event.type() == ui::ET_KEY_PRESSED ||
666 key_event.type() == ui::ET_KEY_RELEASED); 635 key_event.type() == ui::ET_KEY_RELEASED);
667 636
668 // Do nothing if we have just logged in as guest but have not restarted chrome 637 // Do nothing if we have just logged in as guest but have not restarted chrome
669 // process yet (so we are still on the login screen). In this situations we 638 // process yet (so we are still on the login screen). In this situations we
670 // have no user profile so can not do anything useful. 639 // have no user profile so can not do anything useful.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 GetRemappedKey(prefs::kLanguageRemapCapsLockKeyTo, *pref_service); 690 GetRemappedKey(prefs::kLanguageRemapCapsLockKeyTo, *pref_service);
722 } else { 691 } else {
723 characteristic_flag = ui::EF_ALTGR_DOWN; 692 characteristic_flag = ui::EF_ALTGR_DOWN;
724 remapped_key = 693 remapped_key =
725 GetRemappedKey(prefs::kLanguageRemapSearchKeyTo, *pref_service); 694 GetRemappedKey(prefs::kLanguageRemapSearchKeyTo, *pref_service);
726 } 695 }
727 } 696 }
728 if (remapped_key && remapped_key->result.key_code == ui::VKEY_CAPITAL) 697 if (remapped_key && remapped_key->result.key_code == ui::VKEY_CAPITAL)
729 remapped_key = kModifierRemappingNeoMod3; 698 remapped_key = kModifierRemappingNeoMod3;
730 break; 699 break;
731 #if !defined(USE_X11)
732 case ui::DomKey::ALT_GRAPH_LATCH: 700 case ui::DomKey::ALT_GRAPH_LATCH:
733 if (key_event.type() == ui::ET_KEY_PRESSED) { 701 if (key_event.type() == ui::ET_KEY_PRESSED) {
734 pressed_modifier_latches_ |= ui::EF_ALTGR_DOWN; 702 pressed_modifier_latches_ |= ui::EF_ALTGR_DOWN;
735 } else { 703 } else {
736 pressed_modifier_latches_ &= ~ui::EF_ALTGR_DOWN; 704 pressed_modifier_latches_ &= ~ui::EF_ALTGR_DOWN;
737 if (used_modifier_latches_ & ui::EF_ALTGR_DOWN) 705 if (used_modifier_latches_ & ui::EF_ALTGR_DOWN)
738 used_modifier_latches_ &= ~ui::EF_ALTGR_DOWN; 706 used_modifier_latches_ &= ~ui::EF_ALTGR_DOWN;
739 else 707 else
740 latched_modifier_latches_ |= ui::EF_ALTGR_DOWN; 708 latched_modifier_latches_ |= ui::EF_ALTGR_DOWN;
741 } 709 }
742 // Rewrite to AltGraph. When this key is used like a regular modifier, 710 // Rewrite to AltGraph. When this key is used like a regular modifier,
743 // the web-exposed result looks like a use of the regular modifier. 711 // the web-exposed result looks like a use of the regular modifier.
744 // When it's used as a latch, the web-exposed result is a vacuous 712 // When it's used as a latch, the web-exposed result is a vacuous
745 // modifier press-and-release, which should be harmless, but preserves 713 // modifier press-and-release, which should be harmless, but preserves
746 // the event for applications using the |code| (e.g. remoting). 714 // the event for applications using the |code| (e.g. remoting).
747 state->key = ui::DomKey::ALT_GRAPH; 715 state->key = ui::DomKey::ALT_GRAPH;
748 state->key_code = ui::VKEY_ALTGR; 716 state->key_code = ui::VKEY_ALTGR;
749 exact_event = true; 717 exact_event = true;
750 break; 718 break;
751 #endif
752 default: 719 default:
753 break; 720 break;
754 } 721 }
755 722
756 // Remapping based on DomCode. 723 // Remapping based on DomCode.
757 switch (incoming.code) { 724 switch (incoming.code) {
758 // On Chrome OS, XF86XK_Launch7 (F16) with Mod3Mask is sent when Caps Lock 725 // On Chrome OS, XF86XK_Launch7 (F16) with Mod3Mask is sent when Caps Lock
759 // is pressed (with one exception: when 726 // is pressed (with one exception: when
760 // IsISOLevel5ShiftUsedByCurrentInputMethod() is true, the key generates 727 // IsISOLevel5ShiftUsedByCurrentInputMethod() is true, the key generates
761 // XK_ISO_Level3_Shift with Mod3Mask, not XF86XK_Launch7). 728 // XK_ISO_Level3_Shift with Mod3Mask, not XF86XK_Launch7).
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 804
838 if (key_event.type() == ui::ET_KEY_PRESSED) { 805 if (key_event.type() == ui::ET_KEY_PRESSED) {
839 if (!ui::KeycodeConverter::IsDomKeyForModifier(state->key)) { 806 if (!ui::KeycodeConverter::IsDomKeyForModifier(state->key)) {
840 used_modifier_latches_ |= pressed_modifier_latches_; 807 used_modifier_latches_ |= pressed_modifier_latches_;
841 latched_modifier_latches_ = ui::EF_NONE; 808 latched_modifier_latches_ = ui::EF_NONE;
842 } 809 }
843 // Toggle Caps Lock if the remapped key is ui::VKEY_CAPITAL. 810 // Toggle Caps Lock if the remapped key is ui::VKEY_CAPITAL.
844 if (state->key_code == ui::VKEY_CAPITAL 811 if (state->key_code == ui::VKEY_CAPITAL
845 // ... except on linux Chrome OS, where InputMethodChromeOS handles it. 812 // ... except on linux Chrome OS, where InputMethodChromeOS handles it.
846 && (base::SysInfo::IsRunningOnChromeOS() || ime_keyboard_for_testing_) 813 && (base::SysInfo::IsRunningOnChromeOS() || ime_keyboard_for_testing_)
847 #if defined(USE_X11)
848 // ... but for X11, do nothing if the original key is ui::VKEY_CAPITAL
849 // (i.e. a Caps Lock key on an external keyboard is pressed) since X
850 // handles that itself.
851 && incoming.key_code != ui::VKEY_CAPITAL
852 #endif
853 ) { 814 ) {
854 chromeos::input_method::ImeKeyboard* ime_keyboard = 815 chromeos::input_method::ImeKeyboard* ime_keyboard =
855 ime_keyboard_for_testing_ 816 ime_keyboard_for_testing_
856 ? ime_keyboard_for_testing_ 817 ? ime_keyboard_for_testing_
857 : chromeos::input_method::InputMethodManager::Get() 818 : chromeos::input_method::InputMethodManager::Get()
858 ->GetImeKeyboard(); 819 ->GetImeKeyboard();
859 ime_keyboard->SetCapsLockEnabled(!ime_keyboard->CapsLockIsEnabled()); 820 ime_keyboard->SetCapsLockEnabled(!ime_keyboard->CapsLockIsEnabled());
860 } 821 }
861 } 822 }
862 return exact_event; 823 return exact_event;
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 for (const auto& keyboard : keyboard_devices) { 1128 for (const auto& keyboard : keyboard_devices) {
1168 if (keyboard.id == device_id) { 1129 if (keyboard.id == device_id) {
1169 return KeyboardDeviceAddedInternal( 1130 return KeyboardDeviceAddedInternal(
1170 keyboard.id, keyboard.name, keyboard.vendor_id, keyboard.product_id); 1131 keyboard.id, keyboard.name, keyboard.vendor_id, keyboard.product_id);
1171 } 1132 }
1172 } 1133 }
1173 return kDeviceUnknown; 1134 return kDeviceUnknown;
1174 } 1135 }
1175 1136
1176 } // namespace chromeos 1137 } // namespace chromeos
OLDNEW
« ash/sticky_keys/sticky_keys_controller.cc ('K') | « chrome/browser/chromeos/events/event_rewriter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698