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

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

Issue 2068333002: Disable the deprecated Alt+Shift for NEXT_IME (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removing the old accelerators entirely. Created 4 years, 6 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
« no previous file with comments | « no previous file | ash/accelerators/accelerator_controller_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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 #include <utility> 10 #include <utility>
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 base::RecordAction(base::UserMetricsAction("Accel_NewTab_T")); 293 base::RecordAction(base::UserMetricsAction("Accel_NewTab_T"));
294 Shell::GetInstance()->new_window_delegate()->NewTab(); 294 Shell::GetInstance()->new_window_delegate()->NewTab();
295 } 295 }
296 296
297 void HandleNewWindow() { 297 void HandleNewWindow() {
298 base::RecordAction(base::UserMetricsAction("Accel_New_Window")); 298 base::RecordAction(base::UserMetricsAction("Accel_New_Window"));
299 Shell::GetInstance()->new_window_delegate()->NewWindow( 299 Shell::GetInstance()->new_window_delegate()->NewWindow(
300 false /* is_incognito */); 300 false /* is_incognito */);
301 } 301 }
302 302
303 bool CanHandleNextIme(ImeControlDelegate* ime_control_delegate, 303 bool CanHandleNextIme(ImeControlDelegate* ime_control_delegate) {
304 const ui::Accelerator& previous_accelerator, 304 return ime_control_delegate && ime_control_delegate->CanCycleIme();
305 bool current_accelerator_is_deprecated) { 305 }
306 if (current_accelerator_is_deprecated) {
307 // We only allow next IME to be triggered if the previous is accelerator key
308 // is ONLY either Shift, Alt, Enter or Space.
309 // The first six cases below are to avoid conflicting accelerators that
310 // contain Alt+Shift (like Alt+Shift+Tab or Alt+Shift+S) to trigger next IME
311 // when the wrong order of key sequences is pressed. crbug.com/527154.
312 // The latter two cases are needed for CJK IME users who tend to press Enter
313 // (or Space) and Shift+Alt almost at the same time to commit an IME string
314 // and then switch from the IME to the English layout. This allows these
315 // users to trigger NEXT_IME even if they press Shift+Alt before releasing
316 // Enter. crbug.com/139556.
317 // TODO(nona|mazda): Fix crbug.com/139556 in a cleaner way.
318 const ui::KeyboardCode previous_key_code = previous_accelerator.key_code();
319 switch (previous_key_code) {
320 case ui::VKEY_SHIFT:
321 case ui::VKEY_LSHIFT:
322 case ui::VKEY_RSHIFT:
323 case ui::VKEY_MENU:
324 case ui::VKEY_LMENU:
325 case ui::VKEY_RMENU:
326 case ui::VKEY_RETURN:
327 case ui::VKEY_SPACE:
328 break;
329 306
330 default: 307 // We must avoid showing the Deprecated NEXT_IME notification erronously.
331 return false; 308 bool ShouldShowDeprecatedNextImeNotification(
332 } 309 const ui::Accelerator& previous_accelerator) {
310 // We only show the deprecation notification if the previous accelerator key
311 // is ONLY either Shift, or Alt.
312 const ui::KeyboardCode previous_key_code = previous_accelerator.key_code();
313 switch (previous_key_code) {
314 case ui::VKEY_SHIFT:
315 case ui::VKEY_LSHIFT:
316 case ui::VKEY_RSHIFT:
317 case ui::VKEY_MENU:
318 case ui::VKEY_LMENU:
319 case ui::VKEY_RMENU:
320 return true;
321
322 default:
323 return false;
333 } 324 }
334
335 return ime_control_delegate && ime_control_delegate->CanCycleIme();
336 } 325 }
337 326
338 void HandleNextIme(ImeControlDelegate* ime_control_delegate) { 327 void HandleNextIme(ImeControlDelegate* ime_control_delegate) {
339 base::RecordAction(UserMetricsAction("Accel_Next_Ime")); 328 base::RecordAction(UserMetricsAction("Accel_Next_Ime"));
340 ime_control_delegate->HandleNextIme(); 329 ime_control_delegate->HandleNextIme();
341 } 330 }
342 331
343 void HandleOpenFeedbackPage() { 332 void HandleOpenFeedbackPage() {
344 base::RecordAction(UserMetricsAction("Accel_Open_Feedback_Page")); 333 base::RecordAction(UserMetricsAction("Accel_Open_Feedback_Page"));
345 ash::Shell::GetInstance()->new_window_delegate()->OpenFeedbackPage(); 334 ash::Shell::GetInstance()->new_window_delegate()->OpenFeedbackPage();
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 auto itr = actions_with_deprecations_.find(action); 860 auto itr = actions_with_deprecations_.find(action);
872 if (itr != actions_with_deprecations_.end()) { 861 if (itr != actions_with_deprecations_.end()) {
873 const DeprecatedAcceleratorData* data = itr->second; 862 const DeprecatedAcceleratorData* data = itr->second;
874 if (deprecated_accelerators_.count(accelerator)) { 863 if (deprecated_accelerators_.count(accelerator)) {
875 // This accelerator has been deprecated and should be treated according 864 // This accelerator has been deprecated and should be treated according
876 // to its |DeprecatedAcceleratorData|. 865 // to its |DeprecatedAcceleratorData|.
877 866
878 // Record UMA stats. 867 // Record UMA stats.
879 RecordUmaHistogram(data->uma_histogram_name, DEPRECATED_USED); 868 RecordUmaHistogram(data->uma_histogram_name, DEPRECATED_USED);
880 869
881 // We always display the notification as long as this entry exists. 870 // We always display the notification as long as this entry exists,
882 ShowDeprecatedAcceleratorNotification( 871 // except for NEXT_IME, we must check to avoid showing it for the wrong
883 data->uma_histogram_name, data->notification_message_id, 872 // shortcut, as Alt+Shift is tricky and trigger the action on release.
884 data->old_shortcut_id, data->new_shortcut_id); 873 if (action != NEXT_IME ||
874 (action == NEXT_IME &&
875 ShouldShowDeprecatedNextImeNotification(
876 accelerator_history_->previous_accelerator()))) {
877 ShowDeprecatedAcceleratorNotification(
878 data->uma_histogram_name, data->notification_message_id,
879 data->old_shortcut_id, data->new_shortcut_id);
880 }
885 881
886 if (!data->deprecated_enabled) 882 if (!data->deprecated_enabled)
887 return false; 883 return false;
888 } else { 884 } else {
889 // This is a new accelerator replacing the old deprecated one. 885 // This is a new accelerator replacing the old deprecated one.
890 // Record UMA stats and proceed normally. 886 // Record UMA stats and proceed normally.
891 RecordUmaHistogram(data->uma_histogram_name, NEW_USED); 887 RecordUmaHistogram(data->uma_histogram_name, NEW_USED);
892 } 888 }
893 } 889 }
894 890
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 case DEBUG_TOGGLE_ROOT_WINDOW_FULL_SCREEN: 1003 case DEBUG_TOGGLE_ROOT_WINDOW_FULL_SCREEN:
1008 case DEBUG_TOGGLE_SHOW_DEBUG_BORDERS: 1004 case DEBUG_TOGGLE_SHOW_DEBUG_BORDERS:
1009 case DEBUG_TOGGLE_SHOW_FPS_COUNTER: 1005 case DEBUG_TOGGLE_SHOW_FPS_COUNTER:
1010 case DEBUG_TOGGLE_SHOW_PAINT_RECTS: 1006 case DEBUG_TOGGLE_SHOW_PAINT_RECTS:
1011 return debug::DebugAcceleratorsEnabled(); 1007 return debug::DebugAcceleratorsEnabled();
1012 case MAGNIFY_SCREEN_ZOOM_IN: 1008 case MAGNIFY_SCREEN_ZOOM_IN:
1013 case MAGNIFY_SCREEN_ZOOM_OUT: 1009 case MAGNIFY_SCREEN_ZOOM_OUT:
1014 return CanHandleMagnifyScreen(); 1010 return CanHandleMagnifyScreen();
1015 case NEW_INCOGNITO_WINDOW: 1011 case NEW_INCOGNITO_WINDOW:
1016 return CanHandleNewIncognitoWindow(); 1012 return CanHandleNewIncognitoWindow();
1017 case NEXT_IME: { 1013 case NEXT_IME:
1018 #if defined(OS_CHROMEOS) 1014 return CanHandleNextIme(ime_control_delegate_.get());
1019 bool accelerator_is_deprecated =
1020 (deprecated_accelerators_.count(accelerator) != 0);
1021 #else
1022 // On non-chromeos, the NEXT_IME deprecated accelerators are always used.
1023 bool accelerator_is_deprecated = true;
1024 #endif // defined(OS_CHROMEOS)
1025
1026 return CanHandleNextIme(ime_control_delegate_.get(), previous_accelerator,
1027 accelerator_is_deprecated);
1028 }
1029 case PREVIOUS_IME: 1015 case PREVIOUS_IME:
1030 return CanHandlePreviousIme(ime_control_delegate_.get()); 1016 return CanHandlePreviousIme(ime_control_delegate_.get());
1031 case SCALE_UI_RESET: 1017 case SCALE_UI_RESET:
1032 case SCALE_UI_UP: 1018 case SCALE_UI_UP:
1033 case SCALE_UI_DOWN: 1019 case SCALE_UI_DOWN:
1034 return accelerators::IsInternalDisplayZoomEnabled(); 1020 return accelerators::IsInternalDisplayZoomEnabled();
1035 case SHOW_MESSAGE_CENTER_BUBBLE: 1021 case SHOW_MESSAGE_CENTER_BUBBLE:
1036 return CanHandleShowMessageCenterBubble(); 1022 return CanHandleShowMessageCenterBubble();
1037 case SWITCH_IME: 1023 case SWITCH_IME:
1038 return CanHandleSwitchIme(ime_control_delegate_.get(), accelerator); 1024 return CanHandleSwitchIme(ime_control_delegate_.get(), accelerator);
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
1451 } 1437 }
1452 1438
1453 void AcceleratorController::SetKeyboardBrightnessControlDelegate( 1439 void AcceleratorController::SetKeyboardBrightnessControlDelegate(
1454 std::unique_ptr<KeyboardBrightnessControlDelegate> 1440 std::unique_ptr<KeyboardBrightnessControlDelegate>
1455 keyboard_brightness_control_delegate) { 1441 keyboard_brightness_control_delegate) {
1456 keyboard_brightness_control_delegate_ = 1442 keyboard_brightness_control_delegate_ =
1457 std::move(keyboard_brightness_control_delegate); 1443 std::move(keyboard_brightness_control_delegate);
1458 } 1444 }
1459 1445
1460 } // namespace ash 1446 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/accelerators/accelerator_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698