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 "ash/accelerators/accelerator_controller.h" | 5 #include "ash/accelerators/accelerator_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 | 443 |
444 // Ignore accelerators invoked as repeated (while holding a key for a long | 444 // Ignore accelerators invoked as repeated (while holding a key for a long |
445 // time, if their handling is nonrepeatable. | 445 // time, if their handling is nonrepeatable. |
446 if (nonrepeatable_actions_.find(action) != nonrepeatable_actions_.end() && | 446 if (nonrepeatable_actions_.find(action) != nonrepeatable_actions_.end() && |
447 context_.repeated() && !gesture_event) { | 447 context_.repeated() && !gesture_event) { |
448 return true; | 448 return true; |
449 } | 449 } |
450 // Type of the previous accelerator. Used by NEXT_IME and DISABLE_CAPS_LOCK. | 450 // Type of the previous accelerator. Used by NEXT_IME and DISABLE_CAPS_LOCK. |
451 const ui::EventType previous_event_type = | 451 const ui::EventType previous_event_type = |
452 context_.previous_accelerator().type(); | 452 context_.previous_accelerator().type(); |
| 453 const ui::KeyboardCode previous_key_code = |
| 454 context_.previous_accelerator().key_code(); |
453 | 455 |
454 // You *MUST* return true when some action is performed. Otherwise, this | 456 // You *MUST* return true when some action is performed. Otherwise, this |
455 // function might be called *twice*, via BrowserView::PreHandleKeyboardEvent | 457 // function might be called *twice*, via BrowserView::PreHandleKeyboardEvent |
456 // and BrowserView::HandleKeyboardEvent, for a single accelerator press. | 458 // and BrowserView::HandleKeyboardEvent, for a single accelerator press. |
457 switch (action) { | 459 switch (action) { |
458 case CYCLE_BACKWARD_MRU: | 460 case CYCLE_BACKWARD_MRU: |
459 if (key_code == ui::VKEY_TAB) | 461 if (key_code == ui::VKEY_TAB) |
460 shell->delegate()->RecordUserMetricsAction(UMA_ACCEL_PREVWINDOW_TAB); | 462 shell->delegate()->RecordUserMetricsAction(UMA_ACCEL_PREVWINDOW_TAB); |
461 return HandleCycleWindowMRU(WindowCycleController::BACKWARD, | 463 return HandleCycleWindowMRU(WindowCycleController::BACKWARD, |
462 accelerator.IsAltDown()); | 464 accelerator.IsAltDown()); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 screenshot_delegate_.get()); | 534 screenshot_delegate_.get()); |
533 } | 535 } |
534 // Return true to prevent propagation of the key event because | 536 // Return true to prevent propagation of the key event because |
535 // this key combination is reserved for partial screenshot. | 537 // this key combination is reserved for partial screenshot. |
536 return true; | 538 return true; |
537 case TOGGLE_APP_LIST: | 539 case TOGGLE_APP_LIST: |
538 if (accelerator.key_code() == ui::VKEY_LWIN) { | 540 if (accelerator.key_code() == ui::VKEY_LWIN) { |
539 // For bindings on the Search key, activate the binding on press if the | 541 // For bindings on the Search key, activate the binding on press if the |
540 // Search key is not acting as a modifier. Otherwise, activate it on | 542 // Search key is not acting as a modifier. Otherwise, activate it on |
541 // release. | 543 // release. |
542 | |
543 const ui::KeyboardCode previous_key_code = | |
544 context_.previous_accelerator().key_code(); | |
545 | |
546 const bool search_as_function_key = | 544 const bool search_as_function_key = |
547 Shell::GetInstance()->delegate()->IsSearchKeyActingAsFunctionKey(); | 545 Shell::GetInstance()->delegate()->IsSearchKeyActingAsFunctionKey(); |
548 const bool type_pressed = accelerator.type() == ui::ET_KEY_PRESSED; | 546 const bool type_pressed = accelerator.type() == ui::ET_KEY_PRESSED; |
549 | 547 |
550 if (!search_as_function_key && !type_pressed) | 548 if (!search_as_function_key && !type_pressed) |
551 return false; | 549 return false; |
552 if (search_as_function_key && type_pressed) | 550 if (search_as_function_key && type_pressed) |
553 return false; | 551 return false; |
554 if (search_as_function_key && | 552 if (search_as_function_key && |
555 // If something else was pressed between the Search key (LWIN) | 553 // If something else was pressed between the Search key (LWIN) |
556 // being pressed and released, then ignore the release of the | 554 // being pressed and released, then ignore the release of the |
557 // Search key. | 555 // Search key. |
558 (previous_event_type == ui::ET_KEY_RELEASED || | 556 (previous_event_type == ui::ET_KEY_RELEASED || |
559 previous_key_code != ui::VKEY_LWIN)) { | 557 previous_key_code != ui::VKEY_LWIN)) { |
560 return false; | 558 return false; |
561 } | 559 } |
562 } | 560 } |
563 if (key_code == ui::VKEY_LWIN) | 561 if (key_code == ui::VKEY_LWIN) |
564 shell->delegate()->RecordUserMetricsAction(UMA_ACCEL_SEARCH_LWIN); | 562 shell->delegate()->RecordUserMetricsAction(UMA_ACCEL_SEARCH_LWIN); |
565 // When spoken feedback is enabled, we should neither toggle the list nor | 563 // When spoken feedback is enabled, we should neither toggle the list nor |
566 // consume the key since Search+Shift is one of the shortcuts the a11y | 564 // consume the key since Search+Shift is one of the shortcuts the a11y |
567 // feature uses. crbug.com/132296 | 565 // feature uses. crbug.com/132296 |
568 DCHECK_EQ(ui::VKEY_LWIN, accelerator.key_code()); | 566 DCHECK_EQ(ui::VKEY_LWIN, accelerator.key_code()); |
569 if (Shell::GetInstance()->delegate()->IsSpokenFeedbackEnabled()) | 567 if (Shell::GetInstance()->delegate()->IsSpokenFeedbackEnabled()) |
570 return false; | 568 return false; |
571 ash::Shell::GetInstance()->ToggleAppList(); | 569 ash::Shell::GetInstance()->ToggleAppList(); |
572 return true; | 570 return true; |
573 case DISABLE_CAPS_LOCK: | 571 case DISABLE_CAPS_LOCK: |
574 // See: case NEXT_IME. | 572 if (previous_event_type == ui::ET_KEY_RELEASED || |
575 if (previous_event_type == ui::ET_KEY_RELEASED) { | 573 (previous_key_code != ui::VKEY_LSHIFT && |
576 // We totally ignore this accelerator. | 574 previous_key_code != ui::VKEY_SHIFT && |
| 575 previous_key_code != ui::VKEY_RSHIFT)) { |
| 576 // If something else was pressed between the Shift key being pressed |
| 577 // and released, then ignore the release of the Shift key. |
577 return false; | 578 return false; |
578 } | 579 } |
579 if (shell->caps_lock_delegate()->IsCapsLockEnabled()) { | 580 if (shell->caps_lock_delegate()->IsCapsLockEnabled()) { |
580 shell->caps_lock_delegate()->SetCapsLockEnabled(false); | 581 shell->caps_lock_delegate()->SetCapsLockEnabled(false); |
581 return true; | 582 return true; |
582 } | 583 } |
583 return false; | 584 return false; |
584 case TOGGLE_CAPS_LOCK: | 585 case TOGGLE_CAPS_LOCK: |
585 shell->caps_lock_delegate()->ToggleCapsLock(); | 586 shell->caps_lock_delegate()->ToggleCapsLock(); |
586 return true; | 587 return true; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 // ET_KEY_RELEASED accelerator for Chrome OS (see ash/accelerators/ | 650 // ET_KEY_RELEASED accelerator for Chrome OS (see ash/accelerators/ |
650 // accelerator_controller.cc) when Shift+Alt+Tab is pressed and then Tab | 651 // accelerator_controller.cc) when Shift+Alt+Tab is pressed and then Tab |
651 // is released. | 652 // is released. |
652 if (previous_event_type == ui::ET_KEY_RELEASED && | 653 if (previous_event_type == ui::ET_KEY_RELEASED && |
653 // Workaround for crbug.com/139556. CJK IME users tend to press | 654 // Workaround for crbug.com/139556. CJK IME users tend to press |
654 // Enter (or Space) and Shift+Alt almost at the same time to commit | 655 // Enter (or Space) and Shift+Alt almost at the same time to commit |
655 // an IME string and then switch from the IME to the English layout. | 656 // an IME string and then switch from the IME to the English layout. |
656 // This workaround allows the user to trigger NEXT_IME even if the | 657 // This workaround allows the user to trigger NEXT_IME even if the |
657 // user presses Shift+Alt before releasing Enter. | 658 // user presses Shift+Alt before releasing Enter. |
658 // TODO(nona|mazda): Fix crbug.com/139556 in a cleaner way. | 659 // TODO(nona|mazda): Fix crbug.com/139556 in a cleaner way. |
659 context_.previous_accelerator().key_code() != ui::VKEY_RETURN && | 660 previous_key_code != ui::VKEY_RETURN && |
660 context_.previous_accelerator().key_code() != ui::VKEY_SPACE) { | 661 previous_key_code != ui::VKEY_SPACE) { |
661 // We totally ignore this accelerator. | 662 // We totally ignore this accelerator. |
662 // TODO(mazda): Fix crbug.com/158217 | 663 // TODO(mazda): Fix crbug.com/158217 |
663 return false; | 664 return false; |
664 } | 665 } |
665 if (ime_control_delegate_.get()) | 666 if (ime_control_delegate_.get()) |
666 return ime_control_delegate_->HandleNextIme(); | 667 return ime_control_delegate_->HandleNextIme(); |
667 break; | 668 break; |
668 case PREVIOUS_IME: | 669 case PREVIOUS_IME: |
669 if (ime_control_delegate_.get()) | 670 if (ime_control_delegate_.get()) |
670 return ime_control_delegate_->HandlePreviousIme(); | 671 return ime_control_delegate_->HandlePreviousIme(); |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 keyboard_brightness_control_delegate) { | 879 keyboard_brightness_control_delegate) { |
879 keyboard_brightness_control_delegate_ = | 880 keyboard_brightness_control_delegate_ = |
880 keyboard_brightness_control_delegate.Pass(); | 881 keyboard_brightness_control_delegate.Pass(); |
881 } | 882 } |
882 | 883 |
883 bool AcceleratorController::CanHandleAccelerators() const { | 884 bool AcceleratorController::CanHandleAccelerators() const { |
884 return true; | 885 return true; |
885 } | 886 } |
886 | 887 |
887 } // namespace ash | 888 } // namespace ash |
OLD | NEW |