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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "ash/common/accelerators/accelerator_commands.h" | 9 #include "ash/common/accelerators/accelerator_commands.h" |
| 10 #include "ash/common/accelerators/accelerator_controller_delegate.h" | 10 #include "ash/common/accelerators/accelerator_controller_delegate.h" |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 // Touchscreen users have better window switching options. It would be | 166 // Touchscreen users have better window switching options. It would be |
| 167 // preferable if we could tell whether this event actually came from a virtual | 167 // preferable if we could tell whether this event actually came from a virtual |
| 168 // keyboard, but there's no easy way to do so, thus we block Alt+Tab when the | 168 // keyboard, but there's no easy way to do so, thus we block Alt+Tab when the |
| 169 // virtual keyboard is showing, even if it came from a real keyboard. See | 169 // virtual keyboard is showing, even if it came from a real keyboard. See |
| 170 // http://crbug.com/638269 | 170 // http://crbug.com/638269 |
| 171 keyboard::KeyboardController* keyboard_controller = | 171 keyboard::KeyboardController* keyboard_controller = |
| 172 keyboard::KeyboardController::GetInstance(); | 172 keyboard::KeyboardController::GetInstance(); |
| 173 return !(keyboard_controller && keyboard_controller->keyboard_visible()); | 173 return !(keyboard_controller && keyboard_controller->keyboard_visible()); |
| 174 } | 174 } |
| 175 | 175 |
| 176 // We must avoid showing the Deprecated NEXT_IME notification erronously. | |
| 177 bool ShouldShowDeprecatedNextImeNotification( | |
| 178 const ui::Accelerator& previous_accelerator) { | |
| 179 // We only show the deprecation notification if the previous accelerator key | |
| 180 // is ONLY either Shift, or Alt. | |
| 181 const ui::KeyboardCode previous_key_code = previous_accelerator.key_code(); | |
| 182 switch (previous_key_code) { | |
| 183 case ui::VKEY_SHIFT: | |
| 184 case ui::VKEY_LSHIFT: | |
| 185 case ui::VKEY_RSHIFT: | |
| 186 case ui::VKEY_MENU: | |
| 187 case ui::VKEY_LMENU: | |
| 188 case ui::VKEY_RMENU: | |
| 189 return true; | |
| 190 | |
| 191 default: | |
| 192 return false; | |
| 193 } | |
| 194 } | |
| 195 | |
| 196 void HandleNextIme(ImeControlDelegate* ime_control_delegate) { | 176 void HandleNextIme(ImeControlDelegate* ime_control_delegate) { |
| 197 base::RecordAction(UserMetricsAction("Accel_Next_Ime")); | 177 base::RecordAction(UserMetricsAction("Accel_Next_Ime")); |
| 198 ime_control_delegate->HandleNextIme(); | 178 ime_control_delegate->HandleNextIme(); |
| 199 } | 179 } |
| 200 | 180 |
| 201 void HandleOpenFeedbackPage() { | 181 void HandleOpenFeedbackPage() { |
| 202 base::RecordAction(UserMetricsAction("Accel_Open_Feedback_Page")); | 182 base::RecordAction(UserMetricsAction("Accel_Open_Feedback_Page")); |
| 203 WmShell::Get()->new_window_controller()->OpenFeedbackPage(); | 183 WmShell::Get()->new_window_controller()->OpenFeedbackPage(); |
| 204 } | 184 } |
| 205 | 185 |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 628 | 608 |
| 629 //////////////////////////////////////////////////////////////////////////////// | 609 //////////////////////////////////////////////////////////////////////////////// |
| 630 // AcceleratorController, ui::AcceleratorTarget implementation: | 610 // AcceleratorController, ui::AcceleratorTarget implementation: |
| 631 | 611 |
| 632 bool AcceleratorController::AcceleratorPressed( | 612 bool AcceleratorController::AcceleratorPressed( |
| 633 const ui::Accelerator& accelerator) { | 613 const ui::Accelerator& accelerator) { |
| 634 std::map<ui::Accelerator, AcceleratorAction>::const_iterator it = | 614 std::map<ui::Accelerator, AcceleratorAction>::const_iterator it = |
| 635 accelerators_.find(accelerator); | 615 accelerators_.find(accelerator); |
| 636 DCHECK(it != accelerators_.end()); | 616 DCHECK(it != accelerators_.end()); |
| 637 AcceleratorAction action = it->second; | 617 AcceleratorAction action = it->second; |
| 638 if (CanPerformAction(action, accelerator)) { | 618 if (!CanPerformAction(action, accelerator)) |
| 639 // Handling the deprecated accelerators (if any) only if action can be | 619 return false; |
| 640 // performed. | |
| 641 auto itr = actions_with_deprecations_.find(action); | |
| 642 if (itr != actions_with_deprecations_.end()) { | |
| 643 const DeprecatedAcceleratorData* data = itr->second; | |
| 644 if (deprecated_accelerators_.count(accelerator)) { | |
| 645 // This accelerator has been deprecated and should be treated according | |
| 646 // to its |DeprecatedAcceleratorData|. | |
| 647 | 620 |
| 648 // Record UMA stats. | 621 // Handling the deprecated accelerators (if any) only if action can be |
| 649 RecordUmaHistogram(data->uma_histogram_name, DEPRECATED_USED); | 622 // performed. |
| 623 if (!MaybeDeprecatedAcceleratorPressed(action, accelerator)) | |
|
James Cook
2017/01/27 16:40:30
nit: I wonder if there's a better name for this fu
afakhry
2017/01/27 17:27:41
I thought of that too, I didn't want to name it *H
| |
| 624 return false; | |
| 650 | 625 |
| 651 // We always display the notification as long as this entry exists, | 626 PerformAction(action, accelerator); |
| 652 // except for NEXT_IME, we must check to avoid showing it for the wrong | 627 return ShouldActionConsumeKeyEvent(action); |
| 653 // shortcut, as Alt+Shift is tricky and trigger the action on release. | |
| 654 if (delegate_ && | |
| 655 (action != NEXT_IME || | |
| 656 (action == NEXT_IME && | |
| 657 ShouldShowDeprecatedNextImeNotification( | |
| 658 accelerator_history_->previous_accelerator())))) { | |
| 659 delegate_->ShowDeprecatedAcceleratorNotification( | |
| 660 data->uma_histogram_name, data->notification_message_id, | |
| 661 data->old_shortcut_id, data->new_shortcut_id); | |
| 662 } | |
| 663 | |
| 664 if (!data->deprecated_enabled) | |
| 665 return false; | |
| 666 } else { | |
| 667 // This is a new accelerator replacing the old deprecated one. | |
| 668 // Record UMA stats and proceed normally. | |
| 669 RecordUmaHistogram(data->uma_histogram_name, NEW_USED); | |
| 670 } | |
| 671 } | |
| 672 | |
| 673 PerformAction(action, accelerator); | |
| 674 return ShouldActionConsumeKeyEvent(action); | |
| 675 } | |
| 676 return false; | |
| 677 } | 628 } |
| 678 | 629 |
| 679 bool AcceleratorController::CanHandleAccelerators() const { | 630 bool AcceleratorController::CanHandleAccelerators() const { |
| 680 return true; | 631 return true; |
| 681 } | 632 } |
| 682 | 633 |
| 683 void AcceleratorController::BindRequest( | 634 void AcceleratorController::BindRequest( |
| 684 mojom::AcceleratorControllerRequest request) { | 635 mojom::AcceleratorControllerRequest request) { |
| 685 bindings_.AddBinding(this, std::move(request)); | 636 bindings_.AddBinding(this, std::move(request)); |
| 686 } | 637 } |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1166 } | 1117 } |
| 1167 if (wm_shell->mru_window_tracker()->BuildMruWindowList().empty() && | 1118 if (wm_shell->mru_window_tracker()->BuildMruWindowList().empty() && |
| 1168 actions_needing_window_.find(action) != actions_needing_window_.end()) { | 1119 actions_needing_window_.find(action) != actions_needing_window_.end()) { |
| 1169 wm_shell->accessibility_delegate()->TriggerAccessibilityAlert( | 1120 wm_shell->accessibility_delegate()->TriggerAccessibilityAlert( |
| 1170 A11Y_ALERT_WINDOW_NEEDED); | 1121 A11Y_ALERT_WINDOW_NEEDED); |
| 1171 return RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION; | 1122 return RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION; |
| 1172 } | 1123 } |
| 1173 return RESTRICTION_NONE; | 1124 return RESTRICTION_NONE; |
| 1174 } | 1125 } |
| 1175 | 1126 |
| 1127 bool AcceleratorController::MaybeDeprecatedAcceleratorPressed( | |
| 1128 AcceleratorAction action, | |
| 1129 const ui::Accelerator& accelerator) const { | |
| 1130 auto itr = actions_with_deprecations_.find(action); | |
| 1131 if (itr == actions_with_deprecations_.end()) { | |
| 1132 // The action is not associated with any deprecated accelerators, and hence | |
| 1133 // should be performed normally. | |
| 1134 return true; | |
| 1135 } | |
| 1136 | |
| 1137 // This action is associated with new and deprecated accelerators, find which | |
| 1138 // one is |accelerator|. | |
| 1139 const DeprecatedAcceleratorData* data = itr->second; | |
| 1140 if (!deprecated_accelerators_.count(accelerator)) { | |
| 1141 // This is a new accelerator replacing the old deprecated one. | |
| 1142 // Record UMA stats and proceed normally to perform it. | |
| 1143 RecordUmaHistogram(data->uma_histogram_name, NEW_USED); | |
| 1144 return true; | |
| 1145 } | |
| 1146 | |
| 1147 // This accelerator has been deprecated and should be treated according | |
| 1148 // to its |DeprecatedAcceleratorData|. | |
| 1149 | |
| 1150 // Record UMA stats. | |
| 1151 RecordUmaHistogram(data->uma_histogram_name, DEPRECATED_USED); | |
| 1152 | |
| 1153 if (delegate_) { | |
| 1154 // We always display the notification as long as this |data| entry exists. | |
| 1155 delegate_->ShowDeprecatedAcceleratorNotification( | |
| 1156 data->uma_histogram_name, data->notification_message_id, | |
| 1157 data->old_shortcut_id, data->new_shortcut_id); | |
| 1158 } | |
| 1159 | |
| 1160 if (!data->deprecated_enabled) | |
| 1161 return false; | |
| 1162 | |
| 1163 return true; | |
| 1164 } | |
| 1165 | |
| 1176 } // namespace ash | 1166 } // namespace ash |
| OLD | NEW |