Chromium Code Reviews| 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/common/accelerators/accelerator_controller.h" | 5 #include "ash/common/accelerators/accelerator_controller.h" |
| 6 | 6 |
| 7 #include "ash/common/accelerators/accelerator_commands.h" | 7 #include "ash/common/accelerators/accelerator_commands.h" |
| 8 #include "ash/common/accelerators/accelerator_controller_delegate.h" | 8 #include "ash/common/accelerators/accelerator_controller_delegate.h" |
| 9 #include "ash/common/accelerators/debug_commands.h" | 9 #include "ash/common/accelerators/debug_commands.h" |
| 10 #include "ash/common/accessibility_delegate.h" | 10 #include "ash/common/accessibility_delegate.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 #include "ash/common/wm/window_cycle_controller.h" | 26 #include "ash/common/wm/window_cycle_controller.h" |
| 27 #include "ash/common/wm/window_positioning_utils.h" | 27 #include "ash/common/wm/window_positioning_utils.h" |
| 28 #include "ash/common/wm/window_state.h" | 28 #include "ash/common/wm/window_state.h" |
| 29 #include "ash/common/wm/wm_event.h" | 29 #include "ash/common/wm/wm_event.h" |
| 30 #include "ash/common/wm_shell.h" | 30 #include "ash/common/wm_shell.h" |
| 31 #include "ash/common/wm_window.h" | 31 #include "ash/common/wm_window.h" |
| 32 #include "base/metrics/histogram_macros.h" | 32 #include "base/metrics/histogram_macros.h" |
| 33 #include "base/metrics/user_metrics.h" | 33 #include "base/metrics/user_metrics.h" |
| 34 #include "ui/base/accelerators/accelerator.h" | 34 #include "ui/base/accelerators/accelerator.h" |
| 35 #include "ui/base/accelerators/accelerator_manager.h" | 35 #include "ui/base/accelerators/accelerator_manager.h" |
| 36 #include "ui/keyboard/keyboard_controller.h" | |
| 36 | 37 |
| 37 #if defined(OS_CHROMEOS) | 38 #if defined(OS_CHROMEOS) |
| 38 #include "chromeos/dbus/dbus_thread_manager.h" | 39 #include "chromeos/dbus/dbus_thread_manager.h" |
| 39 #include "chromeos/dbus/power_manager_client.h" | 40 #include "chromeos/dbus/power_manager_client.h" |
| 40 #include "ui/base/ime/chromeos/ime_keyboard.h" | 41 #include "ui/base/ime/chromeos/ime_keyboard.h" |
| 41 #include "ui/base/ime/chromeos/input_method_manager.h" | 42 #include "ui/base/ime/chromeos/input_method_manager.h" |
| 42 #endif // defined(OS_CHROMEOS) | 43 #endif // defined(OS_CHROMEOS) |
| 43 | 44 |
| 44 namespace ash { | 45 namespace ash { |
| 45 namespace { | 46 namespace { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 | 124 |
| 124 void HandleNewWindow() { | 125 void HandleNewWindow() { |
| 125 base::RecordAction(UserMetricsAction("Accel_New_Window")); | 126 base::RecordAction(UserMetricsAction("Accel_New_Window")); |
| 126 WmShell::Get()->new_window_delegate()->NewWindow(false /* is_incognito */); | 127 WmShell::Get()->new_window_delegate()->NewWindow(false /* is_incognito */); |
| 127 } | 128 } |
| 128 | 129 |
| 129 bool CanHandleNextIme(ImeControlDelegate* ime_control_delegate) { | 130 bool CanHandleNextIme(ImeControlDelegate* ime_control_delegate) { |
| 130 return ime_control_delegate && ime_control_delegate->CanCycleIme(); | 131 return ime_control_delegate && ime_control_delegate->CanCycleIme(); |
| 131 } | 132 } |
| 132 | 133 |
| 134 bool CanHandleCycleMru(const ui::Accelerator& accelerator) { | |
| 135 // Don't do anything when Alt+Tab comes from a virtual keyboard. Touchscreen | |
| 136 // users have better window switching options. See http://crbug.com/638269 | |
| 137 keyboard::KeyboardController* keyboard_controller = | |
| 138 keyboard::KeyboardController::GetInstance(); | |
| 139 return !(keyboard_controller && keyboard_controller->keyboard_visible() && | |
| 140 (accelerator.modifiers() & ui::EF_IS_SYNTHESIZED)); | |
|
sadrul
2016/08/24 14:22:19
Are you sure you need to look at whether the keybo
Evan Stade
2016/08/26 14:17:55
Since I don't really know all the things that coul
bshe
2016/08/26 15:01:33
Sorry, I am not sure about other cases either. But
| |
| 141 } | |
| 142 | |
| 133 // We must avoid showing the Deprecated NEXT_IME notification erronously. | 143 // We must avoid showing the Deprecated NEXT_IME notification erronously. |
| 134 bool ShouldShowDeprecatedNextImeNotification( | 144 bool ShouldShowDeprecatedNextImeNotification( |
| 135 const ui::Accelerator& previous_accelerator) { | 145 const ui::Accelerator& previous_accelerator) { |
| 136 // We only show the deprecation notification if the previous accelerator key | 146 // We only show the deprecation notification if the previous accelerator key |
| 137 // is ONLY either Shift, or Alt. | 147 // is ONLY either Shift, or Alt. |
| 138 const ui::KeyboardCode previous_key_code = previous_accelerator.key_code(); | 148 const ui::KeyboardCode previous_key_code = previous_accelerator.key_code(); |
| 139 switch (previous_key_code) { | 149 switch (previous_key_code) { |
| 140 case ui::VKEY_SHIFT: | 150 case ui::VKEY_SHIFT: |
| 141 case ui::VKEY_LSHIFT: | 151 case ui::VKEY_LSHIFT: |
| 142 case ui::VKEY_RSHIFT: | 152 case ui::VKEY_RSHIFT: |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 640 if (restriction != RESTRICTION_NONE) | 650 if (restriction != RESTRICTION_NONE) |
| 641 return restriction == RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION; | 651 return restriction == RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION; |
| 642 | 652 |
| 643 const ui::Accelerator& previous_accelerator = | 653 const ui::Accelerator& previous_accelerator = |
| 644 accelerator_history_->previous_accelerator(); | 654 accelerator_history_->previous_accelerator(); |
| 645 | 655 |
| 646 // True should be returned if running |action| does something. Otherwise, | 656 // True should be returned if running |action| does something. Otherwise, |
| 647 // false should be returned to give the web contents a chance at handling the | 657 // false should be returned to give the web contents a chance at handling the |
| 648 // accelerator. | 658 // accelerator. |
| 649 switch (action) { | 659 switch (action) { |
| 660 case CYCLE_BACKWARD_MRU: | |
| 661 case CYCLE_FORWARD_MRU: | |
| 662 return CanHandleCycleMru(accelerator); | |
| 650 case DEBUG_PRINT_LAYER_HIERARCHY: | 663 case DEBUG_PRINT_LAYER_HIERARCHY: |
| 651 case DEBUG_PRINT_VIEW_HIERARCHY: | 664 case DEBUG_PRINT_VIEW_HIERARCHY: |
| 652 case DEBUG_PRINT_WINDOW_HIERARCHY: | 665 case DEBUG_PRINT_WINDOW_HIERARCHY: |
| 653 return debug::DebugAcceleratorsEnabled(); | 666 return debug::DebugAcceleratorsEnabled(); |
| 654 case NEW_INCOGNITO_WINDOW: | 667 case NEW_INCOGNITO_WINDOW: |
| 655 return CanHandleNewIncognitoWindow(); | 668 return CanHandleNewIncognitoWindow(); |
| 656 case NEXT_IME: | 669 case NEXT_IME: |
| 657 return CanHandleNextIme(ime_control_delegate_.get()); | 670 return CanHandleNextIme(ime_control_delegate_.get()); |
| 658 case PREVIOUS_IME: | 671 case PREVIOUS_IME: |
| 659 return CanHandlePreviousIme(ime_control_delegate_.get()); | 672 return CanHandlePreviousIme(ime_control_delegate_.get()); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 675 case DISABLE_CAPS_LOCK: | 688 case DISABLE_CAPS_LOCK: |
| 676 return CanHandleDisableCapsLock(previous_accelerator); | 689 return CanHandleDisableCapsLock(previous_accelerator); |
| 677 case LOCK_SCREEN: | 690 case LOCK_SCREEN: |
| 678 return CanHandleLock(); | 691 return CanHandleLock(); |
| 679 case SWITCH_TO_PREVIOUS_USER: | 692 case SWITCH_TO_PREVIOUS_USER: |
| 680 case SWITCH_TO_NEXT_USER: | 693 case SWITCH_TO_NEXT_USER: |
| 681 return CanHandleCycleUser(); | 694 return CanHandleCycleUser(); |
| 682 case TOGGLE_CAPS_LOCK: | 695 case TOGGLE_CAPS_LOCK: |
| 683 return CanHandleToggleCapsLock(accelerator, previous_accelerator); | 696 return CanHandleToggleCapsLock(accelerator, previous_accelerator); |
| 684 #endif | 697 #endif |
| 685 case CYCLE_BACKWARD_MRU: | |
| 686 case CYCLE_FORWARD_MRU: | |
| 687 case EXIT: | 698 case EXIT: |
| 688 case FOCUS_NEXT_PANE: | 699 case FOCUS_NEXT_PANE: |
| 689 case FOCUS_PREVIOUS_PANE: | 700 case FOCUS_PREVIOUS_PANE: |
| 690 case MEDIA_NEXT_TRACK: | 701 case MEDIA_NEXT_TRACK: |
| 691 case MEDIA_PLAY_PAUSE: | 702 case MEDIA_PLAY_PAUSE: |
| 692 case MEDIA_PREV_TRACK: | 703 case MEDIA_PREV_TRACK: |
| 693 case NEW_TAB: | 704 case NEW_TAB: |
| 694 case NEW_WINDOW: | 705 case NEW_WINDOW: |
| 695 case OPEN_FEEDBACK_PAGE: | 706 case OPEN_FEEDBACK_PAGE: |
| 696 case PRINT_UI_HIERARCHIES: | 707 case PRINT_UI_HIERARCHIES: |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 917 } | 928 } |
| 918 | 929 |
| 919 bool AcceleratorController::ShouldActionConsumeKeyEvent( | 930 bool AcceleratorController::ShouldActionConsumeKeyEvent( |
| 920 AcceleratorAction action) { | 931 AcceleratorAction action) { |
| 921 // Adding new exceptions is *STRONGLY* discouraged. | 932 // Adding new exceptions is *STRONGLY* discouraged. |
| 922 return true; | 933 return true; |
| 923 } | 934 } |
| 924 | 935 |
| 925 AcceleratorController::AcceleratorProcessingRestriction | 936 AcceleratorController::AcceleratorProcessingRestriction |
| 926 AcceleratorController::GetAcceleratorProcessingRestriction(int action) { | 937 AcceleratorController::GetAcceleratorProcessingRestriction(int action) { |
| 927 if (WmShell::Get()->IsPinned() && | 938 WmShell* wm_shell = WmShell::Get(); |
| 939 if (wm_shell->IsPinned() && | |
| 928 actions_allowed_in_pinned_mode_.find(action) == | 940 actions_allowed_in_pinned_mode_.find(action) == |
| 929 actions_allowed_in_pinned_mode_.end()) { | 941 actions_allowed_in_pinned_mode_.end()) { |
| 930 return RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION; | 942 return RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION; |
| 931 } | 943 } |
| 932 WmShell* wm_shell = WmShell::Get(); | |
| 933 if (!wm_shell->GetSessionStateDelegate()->IsActiveUserSessionStarted() && | 944 if (!wm_shell->GetSessionStateDelegate()->IsActiveUserSessionStarted() && |
| 934 actions_allowed_at_login_screen_.find(action) == | 945 actions_allowed_at_login_screen_.find(action) == |
| 935 actions_allowed_at_login_screen_.end()) { | 946 actions_allowed_at_login_screen_.end()) { |
| 936 return RESTRICTION_PREVENT_PROCESSING; | 947 return RESTRICTION_PREVENT_PROCESSING; |
| 937 } | 948 } |
| 938 if (wm_shell->GetSessionStateDelegate()->IsScreenLocked() && | 949 if (wm_shell->GetSessionStateDelegate()->IsScreenLocked() && |
| 939 actions_allowed_at_lock_screen_.find(action) == | 950 actions_allowed_at_lock_screen_.find(action) == |
| 940 actions_allowed_at_lock_screen_.end()) { | 951 actions_allowed_at_lock_screen_.end()) { |
| 941 return RESTRICTION_PREVENT_PROCESSING; | 952 return RESTRICTION_PREVENT_PROCESSING; |
| 942 } | 953 } |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 957 if (wm_shell->mru_window_tracker()->BuildMruWindowList().empty() && | 968 if (wm_shell->mru_window_tracker()->BuildMruWindowList().empty() && |
| 958 actions_needing_window_.find(action) != actions_needing_window_.end()) { | 969 actions_needing_window_.find(action) != actions_needing_window_.end()) { |
| 959 wm_shell->accessibility_delegate()->TriggerAccessibilityAlert( | 970 wm_shell->accessibility_delegate()->TriggerAccessibilityAlert( |
| 960 A11Y_ALERT_WINDOW_NEEDED); | 971 A11Y_ALERT_WINDOW_NEEDED); |
| 961 return RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION; | 972 return RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION; |
| 962 } | 973 } |
| 963 return RESTRICTION_NONE; | 974 return RESTRICTION_NONE; |
| 964 } | 975 } |
| 965 | 976 |
| 966 } // namespace ash | 977 } // namespace ash |
| OLD | NEW |