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

Side by Side Diff: ash/common/accelerators/accelerator_controller.cc

Issue 2658853003: Remove the deprecated Alt+Shift shortcut completely (Closed)
Patch Set: More comments Created 3 years, 10 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 (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
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
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) ==
624 AcceleratorProcessingStatus::STOP) {
625 return false;
626 }
650 627
651 // We always display the notification as long as this entry exists, 628 PerformAction(action, accelerator);
652 // except for NEXT_IME, we must check to avoid showing it for the wrong 629 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 } 630 }
678 631
679 bool AcceleratorController::CanHandleAccelerators() const { 632 bool AcceleratorController::CanHandleAccelerators() const {
680 return true; 633 return true;
681 } 634 }
682 635
683 void AcceleratorController::BindRequest( 636 void AcceleratorController::BindRequest(
684 mojom::AcceleratorControllerRequest request) { 637 mojom::AcceleratorControllerRequest request) {
685 bindings_.AddBinding(this, std::move(request)); 638 bindings_.AddBinding(this, std::move(request));
686 } 639 }
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 } 1119 }
1167 if (wm_shell->mru_window_tracker()->BuildMruWindowList().empty() && 1120 if (wm_shell->mru_window_tracker()->BuildMruWindowList().empty() &&
1168 actions_needing_window_.find(action) != actions_needing_window_.end()) { 1121 actions_needing_window_.find(action) != actions_needing_window_.end()) {
1169 wm_shell->accessibility_delegate()->TriggerAccessibilityAlert( 1122 wm_shell->accessibility_delegate()->TriggerAccessibilityAlert(
1170 A11Y_ALERT_WINDOW_NEEDED); 1123 A11Y_ALERT_WINDOW_NEEDED);
1171 return RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION; 1124 return RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION;
1172 } 1125 }
1173 return RESTRICTION_NONE; 1126 return RESTRICTION_NONE;
1174 } 1127 }
1175 1128
1129 AcceleratorController::AcceleratorProcessingStatus
1130 AcceleratorController::MaybeDeprecatedAcceleratorPressed(
1131 AcceleratorAction action,
1132 const ui::Accelerator& accelerator) const {
1133 auto itr = actions_with_deprecations_.find(action);
1134 if (itr == actions_with_deprecations_.end()) {
1135 // The action is not associated with any deprecated accelerators, and hence
1136 // should be performed normally.
1137 return AcceleratorProcessingStatus::PROCEED;
1138 }
1139
1140 // This action is associated with new and deprecated accelerators, find which
1141 // one is |accelerator|.
1142 const DeprecatedAcceleratorData* data = itr->second;
1143 if (!deprecated_accelerators_.count(accelerator)) {
1144 // This is a new accelerator replacing the old deprecated one.
1145 // Record UMA stats and proceed normally to perform it.
1146 RecordUmaHistogram(data->uma_histogram_name, NEW_USED);
1147 return AcceleratorProcessingStatus::PROCEED;
1148 }
1149
1150 // This accelerator has been deprecated and should be treated according
1151 // to its |DeprecatedAcceleratorData|.
1152
1153 // Record UMA stats.
1154 RecordUmaHistogram(data->uma_histogram_name, DEPRECATED_USED);
1155
1156 if (delegate_) {
1157 // We always display the notification as long as this |data| entry exists.
1158 delegate_->ShowDeprecatedAcceleratorNotification(
1159 data->uma_histogram_name, data->notification_message_id,
1160 data->old_shortcut_id, data->new_shortcut_id);
1161 }
1162
1163 if (!data->deprecated_enabled)
1164 return AcceleratorProcessingStatus::STOP;
1165
1166 return AcceleratorProcessingStatus::PROCEED;
1167 }
1168
1176 } // namespace ash 1169 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/accelerators/accelerator_controller.h ('k') | ash/common/accelerators/accelerator_table.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698