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

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

Issue 2891263002: chromeos: Remove some IME methods from ash::SystemTrayDelegate (Closed)
Patch Set: rebase Created 3 years, 7 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/accelerators/accelerator_controller.h" 5 #include "ash/accelerators/accelerator_controller.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "ash/accelerators/accelerator_commands.h" 9 #include "ash/accelerators/accelerator_commands.h"
10 #include "ash/accelerators/accelerator_controller_delegate.h" 10 #include "ash/accelerators/accelerator_controller_delegate.h"
11 #include "ash/accelerators/debug_commands.h" 11 #include "ash/accelerators/debug_commands.h"
12 #include "ash/accessibility_delegate.h" 12 #include "ash/accessibility_delegate.h"
13 #include "ash/accessibility_types.h" 13 #include "ash/accessibility_types.h"
14 #include "ash/focus_cycler.h" 14 #include "ash/focus_cycler.h"
15 #include "ash/ime_control_delegate.h" 15 #include "ash/ime/ime_switch_type.h"
16 #include "ash/media_controller.h" 16 #include "ash/media_controller.h"
17 #include "ash/multi_profile_uma.h" 17 #include "ash/multi_profile_uma.h"
18 #include "ash/new_window_controller.h" 18 #include "ash/new_window_controller.h"
19 #include "ash/resources/vector_icons/vector_icons.h" 19 #include "ash/resources/vector_icons/vector_icons.h"
20 #include "ash/root_window_controller.h" 20 #include "ash/root_window_controller.h"
21 #include "ash/rotator/window_rotation.h" 21 #include "ash/rotator/window_rotation.h"
22 #include "ash/session/session_controller.h" 22 #include "ash/session/session_controller.h"
23 #include "ash/shelf/shelf_widget.h" 23 #include "ash/shelf/shelf_widget.h"
24 #include "ash/shelf/wm_shelf.h" 24 #include "ash/shelf/wm_shelf.h"
25 #include "ash/shell.h" 25 #include "ash/shell.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 #include "ui/compositor/layer_animation_sequence.h" 61 #include "ui/compositor/layer_animation_sequence.h"
62 #include "ui/compositor/layer_animator.h" 62 #include "ui/compositor/layer_animator.h"
63 #include "ui/gfx/paint_vector_icon.h" 63 #include "ui/gfx/paint_vector_icon.h"
64 #include "ui/keyboard/keyboard_controller.h" 64 #include "ui/keyboard/keyboard_controller.h"
65 #include "ui/message_center/message_center.h" 65 #include "ui/message_center/message_center.h"
66 66
67 namespace ash { 67 namespace ash {
68 namespace { 68 namespace {
69 69
70 using base::UserMetricsAction; 70 using base::UserMetricsAction;
71 using chromeos::input_method::InputMethodManager;
71 using message_center::Notification; 72 using message_center::Notification;
72 73
73 // Identifier for the high contrast toggle accelerator notification. 74 // Identifier for the high contrast toggle accelerator notification.
74 const char kHighContrastToggleAccelNotificationId[] = 75 const char kHighContrastToggleAccelNotificationId[] =
75 "chrome://settings/accessibility/highcontrast"; 76 "chrome://settings/accessibility/highcontrast";
76 77
77 // The notification delegate that will be used to open the keyboard shortcut 78 // The notification delegate that will be used to open the keyboard shortcut
78 // help page when the notification is clicked. 79 // help page when the notification is clicked.
79 class DeprecatedAcceleratorNotificationDelegate 80 class DeprecatedAcceleratorNotificationDelegate
80 : public message_center::NotificationDelegate { 81 : public message_center::NotificationDelegate {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 } 165 }
165 166
166 void RecordUmaHistogram(const char* histogram_name, 167 void RecordUmaHistogram(const char* histogram_name,
167 DeprecatedAcceleratorUsage sample) { 168 DeprecatedAcceleratorUsage sample) {
168 auto* histogram = base::LinearHistogram::FactoryGet( 169 auto* histogram = base::LinearHistogram::FactoryGet(
169 histogram_name, 1, DEPRECATED_USAGE_COUNT, DEPRECATED_USAGE_COUNT + 1, 170 histogram_name, 1, DEPRECATED_USAGE_COUNT, DEPRECATED_USAGE_COUNT + 1,
170 base::HistogramBase::kUmaTargetedHistogramFlag); 171 base::HistogramBase::kUmaTargetedHistogramFlag);
171 histogram->Add(sample); 172 histogram->Add(sample);
172 } 173 }
173 174
175 void RecordImeSwitchByAccelerator() {
176 UMA_HISTOGRAM_ENUMERATION("InputMethod.ImeSwitch",
177 ImeSwitchType::kAccelerator, ImeSwitchType::kCount);
178 }
179
174 void HandleCycleBackwardMRU(const ui::Accelerator& accelerator) { 180 void HandleCycleBackwardMRU(const ui::Accelerator& accelerator) {
175 if (accelerator.key_code() == ui::VKEY_TAB) 181 if (accelerator.key_code() == ui::VKEY_TAB)
176 base::RecordAction(base::UserMetricsAction("Accel_PrevWindow_Tab")); 182 base::RecordAction(base::UserMetricsAction("Accel_PrevWindow_Tab"));
177 183
178 Shell::Get()->window_cycle_controller()->HandleCycleWindow( 184 Shell::Get()->window_cycle_controller()->HandleCycleWindow(
179 WindowCycleController::BACKWARD); 185 WindowCycleController::BACKWARD);
180 } 186 }
181 187
182 void HandleCycleForwardMRU(const ui::Accelerator& accelerator) { 188 void HandleCycleForwardMRU(const ui::Accelerator& accelerator) {
183 if (accelerator.key_code() == ui::VKEY_TAB) 189 if (accelerator.key_code() == ui::VKEY_TAB)
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 if (accelerator.key_code() == ui::VKEY_T) 250 if (accelerator.key_code() == ui::VKEY_T)
245 base::RecordAction(UserMetricsAction("Accel_NewTab_T")); 251 base::RecordAction(UserMetricsAction("Accel_NewTab_T"));
246 Shell::Get()->new_window_controller()->NewTab(); 252 Shell::Get()->new_window_controller()->NewTab();
247 } 253 }
248 254
249 void HandleNewWindow() { 255 void HandleNewWindow() {
250 base::RecordAction(UserMetricsAction("Accel_New_Window")); 256 base::RecordAction(UserMetricsAction("Accel_New_Window"));
251 Shell::Get()->new_window_controller()->NewWindow(false /* is_incognito */); 257 Shell::Get()->new_window_controller()->NewWindow(false /* is_incognito */);
252 } 258 }
253 259
254 bool CanHandleNextIme(ImeControlDelegate* ime_control_delegate) { 260 bool CanCycleInputMethod() {
255 return ime_control_delegate && ime_control_delegate->CanCycleIme(); 261 InputMethodManager* manager = InputMethodManager::Get();
262 DCHECK(manager);
263 if (!manager->GetActiveIMEState()) {
264 LOG(WARNING) << "Cannot cycle through input methods as they are not "
265 "initialized yet.";
266 return false;
267 }
268 return manager->GetActiveIMEState()->CanCycleInputMethod();
256 } 269 }
257 270
258 bool CanHandleCycleMru(const ui::Accelerator& accelerator) { 271 bool CanHandleCycleMru(const ui::Accelerator& accelerator) {
259 // Don't do anything when Alt+Tab is hit while a virtual keyboard is showing. 272 // Don't do anything when Alt+Tab is hit while a virtual keyboard is showing.
260 // Touchscreen users have better window switching options. It would be 273 // Touchscreen users have better window switching options. It would be
261 // preferable if we could tell whether this event actually came from a virtual 274 // preferable if we could tell whether this event actually came from a virtual
262 // keyboard, but there's no easy way to do so, thus we block Alt+Tab when the 275 // keyboard, but there's no easy way to do so, thus we block Alt+Tab when the
263 // virtual keyboard is showing, even if it came from a real keyboard. See 276 // virtual keyboard is showing, even if it came from a real keyboard. See
264 // http://crbug.com/638269 277 // http://crbug.com/638269
265 keyboard::KeyboardController* keyboard_controller = 278 keyboard::KeyboardController* keyboard_controller =
266 keyboard::KeyboardController::GetInstance(); 279 keyboard::KeyboardController::GetInstance();
267 return !(keyboard_controller && keyboard_controller->keyboard_visible()); 280 return !(keyboard_controller && keyboard_controller->keyboard_visible());
268 } 281 }
269 282
270 void HandleNextIme(ImeControlDelegate* ime_control_delegate) { 283 void HandleNextIme() {
271 base::RecordAction(UserMetricsAction("Accel_Next_Ime")); 284 base::RecordAction(UserMetricsAction("Accel_Next_Ime"));
272 ime_control_delegate->HandleNextIme(); 285 RecordImeSwitchByAccelerator();
286 InputMethodManager::Get()->GetActiveIMEState()->SwitchToNextInputMethod();
273 } 287 }
274 288
275 void HandleOpenFeedbackPage() { 289 void HandleOpenFeedbackPage() {
276 base::RecordAction(UserMetricsAction("Accel_Open_Feedback_Page")); 290 base::RecordAction(UserMetricsAction("Accel_Open_Feedback_Page"));
277 Shell::Get()->new_window_controller()->OpenFeedbackPage(); 291 Shell::Get()->new_window_controller()->OpenFeedbackPage();
278 } 292 }
279 293
280 bool CanHandlePreviousIme(ImeControlDelegate* ime_control_delegate) { 294 void HandlePreviousIme(const ui::Accelerator& accelerator) {
281 return ime_control_delegate && ime_control_delegate->CanCycleIme();
282 }
283
284 void HandlePreviousIme(ImeControlDelegate* ime_control_delegate,
285 const ui::Accelerator& accelerator) {
286 base::RecordAction(UserMetricsAction("Accel_Previous_Ime")); 295 base::RecordAction(UserMetricsAction("Accel_Previous_Ime"));
287 if (accelerator.key_state() == ui::Accelerator::KeyState::PRESSED) 296 if (accelerator.key_state() == ui::Accelerator::KeyState::PRESSED) {
288 ime_control_delegate->HandlePreviousIme(); 297 RecordImeSwitchByAccelerator();
298 InputMethodManager::Get()
299 ->GetActiveIMEState()
300 ->SwitchToPreviousInputMethod();
301 }
289 // Else: consume the Ctrl+Space ET_KEY_RELEASED event but do not do anything. 302 // Else: consume the Ctrl+Space ET_KEY_RELEASED event but do not do anything.
290 } 303 }
291 304
292 void HandleRestoreTab() { 305 void HandleRestoreTab() {
293 base::RecordAction(UserMetricsAction("Accel_Restore_Tab")); 306 base::RecordAction(UserMetricsAction("Accel_Restore_Tab"));
294 Shell::Get()->new_window_controller()->RestoreTab(); 307 Shell::Get()->new_window_controller()->RestoreTab();
295 } 308 }
296 309
297 // Rotate the active window. 310 // Rotate the active window.
298 void HandleRotateActiveWindow() { 311 void HandleRotateActiveWindow() {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 tray->ShowDefaultView(BUBBLE_CREATE_NEW); 358 tray->ShowDefaultView(BUBBLE_CREATE_NEW);
346 tray->ActivateBubble(); 359 tray->ActivateBubble();
347 } 360 }
348 } 361 }
349 362
350 void HandleShowTaskManager() { 363 void HandleShowTaskManager() {
351 base::RecordAction(UserMetricsAction("Accel_Show_Task_Manager")); 364 base::RecordAction(UserMetricsAction("Accel_Show_Task_Manager"));
352 Shell::Get()->new_window_controller()->ShowTaskManager(); 365 Shell::Get()->new_window_controller()->ShowTaskManager();
353 } 366 }
354 367
355 bool CanHandleSwitchIme(ImeControlDelegate* ime_control_delegate, 368 bool CanHandleSwitchIme(const ui::Accelerator& accelerator) {
356 const ui::Accelerator& accelerator) { 369 InputMethodManager* manager = InputMethodManager::Get();
357 return ime_control_delegate && 370 DCHECK(manager);
358 ime_control_delegate->CanSwitchIme(accelerator); 371 if (!manager->GetActiveIMEState()) {
372 LOG(WARNING) << "Cannot switch input methods as they are not "
373 "initialized yet.";
374 return false;
375 }
376 return manager->GetActiveIMEState()->CanSwitchInputMethod(accelerator);
359 } 377 }
360 378
361 void HandleSwitchIme(ImeControlDelegate* ime_control_delegate, 379 void HandleSwitchIme(const ui::Accelerator& accelerator) {
362 const ui::Accelerator& accelerator) {
363 base::RecordAction(UserMetricsAction("Accel_Switch_Ime")); 380 base::RecordAction(UserMetricsAction("Accel_Switch_Ime"));
364 ime_control_delegate->HandleSwitchIme(accelerator); 381 RecordImeSwitchByAccelerator();
382 InputMethodManager::Get()->GetActiveIMEState()->SwitchInputMethod(
383 accelerator);
365 } 384 }
366 385
367 bool CanHandleToggleAppList(const ui::Accelerator& accelerator, 386 bool CanHandleToggleAppList(const ui::Accelerator& accelerator,
368 const ui::Accelerator& previous_accelerator) { 387 const ui::Accelerator& previous_accelerator) {
369 if (accelerator.key_code() == ui::VKEY_LWIN) { 388 if (accelerator.key_code() == ui::VKEY_LWIN) {
370 // If something else was pressed between the Search key (LWIN) 389 // If something else was pressed between the Search key (LWIN)
371 // being pressed and released, then ignore the release of the 390 // being pressed and released, then ignore the release of the
372 // Search key. 391 // Search key.
373 if (previous_accelerator.key_state() != 392 if (previous_accelerator.key_state() !=
374 ui::Accelerator::KeyState::PRESSED || 393 ui::Accelerator::KeyState::PRESSED ||
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 return true; 747 return true;
729 } 748 }
730 return false; 749 return false;
731 } 750 }
732 751
733 AcceleratorController::AcceleratorProcessingRestriction 752 AcceleratorController::AcceleratorProcessingRestriction
734 AcceleratorController::GetCurrentAcceleratorRestriction() { 753 AcceleratorController::GetCurrentAcceleratorRestriction() {
735 return GetAcceleratorProcessingRestriction(-1); 754 return GetAcceleratorProcessingRestriction(-1);
736 } 755 }
737 756
738 void AcceleratorController::SetImeControlDelegate(
739 std::unique_ptr<ImeControlDelegate> ime_control_delegate) {
740 ime_control_delegate_ = std::move(ime_control_delegate);
741 }
742
743 bool AcceleratorController::ShouldCloseMenuAndRepostAccelerator( 757 bool AcceleratorController::ShouldCloseMenuAndRepostAccelerator(
744 const ui::Accelerator& accelerator) const { 758 const ui::Accelerator& accelerator) const {
745 auto itr = accelerators_.find(accelerator); 759 auto itr = accelerators_.find(accelerator);
746 if (itr == accelerators_.end()) 760 if (itr == accelerators_.end())
747 return false; // Menu shouldn't be closed for an invalid accelerator. 761 return false; // Menu shouldn't be closed for an invalid accelerator.
748 762
749 AcceleratorAction action = itr->second; 763 AcceleratorAction action = itr->second;
750 return actions_keeping_menu_open_.count(action) == 0; 764 return actions_keeping_menu_open_.count(action) == 0;
751 } 765 }
752 766
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 case DEBUG_TOGGLE_WALLPAPER_MODE: 919 case DEBUG_TOGGLE_WALLPAPER_MODE:
906 case DEBUG_TRIGGER_CRASH: 920 case DEBUG_TRIGGER_CRASH:
907 return debug::DebugAcceleratorsEnabled(); 921 return debug::DebugAcceleratorsEnabled();
908 case DISABLE_CAPS_LOCK: 922 case DISABLE_CAPS_LOCK:
909 return CanHandleDisableCapsLock(previous_accelerator); 923 return CanHandleDisableCapsLock(previous_accelerator);
910 case LOCK_SCREEN: 924 case LOCK_SCREEN:
911 return CanHandleLock(); 925 return CanHandleLock();
912 case NEW_INCOGNITO_WINDOW: 926 case NEW_INCOGNITO_WINDOW:
913 return CanHandleNewIncognitoWindow(); 927 return CanHandleNewIncognitoWindow();
914 case NEXT_IME: 928 case NEXT_IME:
915 return CanHandleNextIme(ime_control_delegate_.get()); 929 return CanCycleInputMethod();
916 case PREVIOUS_IME: 930 case PREVIOUS_IME:
917 return CanHandlePreviousIme(ime_control_delegate_.get()); 931 return CanCycleInputMethod();
918 case SHOW_MESSAGE_CENTER_BUBBLE: 932 case SHOW_MESSAGE_CENTER_BUBBLE:
919 return CanHandleShowMessageCenterBubble(); 933 return CanHandleShowMessageCenterBubble();
920 case SHOW_STYLUS_TOOLS: 934 case SHOW_STYLUS_TOOLS:
921 return CanHandleShowStylusTools(); 935 return CanHandleShowStylusTools();
922 case SWITCH_IME: 936 case SWITCH_IME:
923 return CanHandleSwitchIme(ime_control_delegate_.get(), accelerator); 937 return CanHandleSwitchIme(accelerator);
924 case SWITCH_TO_PREVIOUS_USER: 938 case SWITCH_TO_PREVIOUS_USER:
925 case SWITCH_TO_NEXT_USER: 939 case SWITCH_TO_NEXT_USER:
926 return CanHandleCycleUser(); 940 return CanHandleCycleUser();
927 case TOGGLE_APP_LIST: 941 case TOGGLE_APP_LIST:
928 return CanHandleToggleAppList(accelerator, previous_accelerator); 942 return CanHandleToggleAppList(accelerator, previous_accelerator);
929 case TOGGLE_CAPS_LOCK: 943 case TOGGLE_CAPS_LOCK:
930 return CanHandleToggleCapsLock(accelerator, previous_accelerator); 944 return CanHandleToggleCapsLock(accelerator, previous_accelerator);
931 case WINDOW_CYCLE_SNAP_LEFT: 945 case WINDOW_CYCLE_SNAP_LEFT:
932 case WINDOW_CYCLE_SNAP_RIGHT: 946 case WINDOW_CYCLE_SNAP_RIGHT:
933 return CanHandleWindowSnap(); 947 return CanHandleWindowSnap();
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
1104 case NEW_INCOGNITO_WINDOW: 1118 case NEW_INCOGNITO_WINDOW:
1105 HandleNewIncognitoWindow(); 1119 HandleNewIncognitoWindow();
1106 break; 1120 break;
1107 case NEW_TAB: 1121 case NEW_TAB:
1108 HandleNewTab(accelerator); 1122 HandleNewTab(accelerator);
1109 break; 1123 break;
1110 case NEW_WINDOW: 1124 case NEW_WINDOW:
1111 HandleNewWindow(); 1125 HandleNewWindow();
1112 break; 1126 break;
1113 case NEXT_IME: 1127 case NEXT_IME:
1114 HandleNextIme(ime_control_delegate_.get()); 1128 HandleNextIme();
1115 break; 1129 break;
1116 case OPEN_CROSH: 1130 case OPEN_CROSH:
1117 HandleCrosh(); 1131 HandleCrosh();
1118 break; 1132 break;
1119 case OPEN_FEEDBACK_PAGE: 1133 case OPEN_FEEDBACK_PAGE:
1120 HandleOpenFeedbackPage(); 1134 HandleOpenFeedbackPage();
1121 break; 1135 break;
1122 case OPEN_FILE_MANAGER: 1136 case OPEN_FILE_MANAGER:
1123 HandleFileManager(); 1137 HandleFileManager();
1124 break; 1138 break;
1125 case OPEN_GET_HELP: 1139 case OPEN_GET_HELP:
1126 HandleGetHelp(); 1140 HandleGetHelp();
1127 break; 1141 break;
1128 case PREVIOUS_IME: 1142 case PREVIOUS_IME:
1129 HandlePreviousIme(ime_control_delegate_.get(), accelerator); 1143 HandlePreviousIme(accelerator);
1130 break; 1144 break;
1131 case PRINT_UI_HIERARCHIES: 1145 case PRINT_UI_HIERARCHIES:
1132 debug::PrintUIHierarchies(); 1146 debug::PrintUIHierarchies();
1133 break; 1147 break;
1134 case RESTORE_TAB: 1148 case RESTORE_TAB:
1135 HandleRestoreTab(); 1149 HandleRestoreTab();
1136 break; 1150 break;
1137 case ROTATE_WINDOW: 1151 case ROTATE_WINDOW:
1138 HandleRotateActiveWindow(); 1152 HandleRotateActiveWindow();
1139 break; 1153 break;
(...skipping 12 matching lines...) Expand all
1152 case SHOW_SYSTEM_TRAY_BUBBLE: 1166 case SHOW_SYSTEM_TRAY_BUBBLE:
1153 HandleShowSystemTrayBubble(); 1167 HandleShowSystemTrayBubble();
1154 break; 1168 break;
1155 case SHOW_TASK_MANAGER: 1169 case SHOW_TASK_MANAGER:
1156 HandleShowTaskManager(); 1170 HandleShowTaskManager();
1157 break; 1171 break;
1158 case SUSPEND: 1172 case SUSPEND:
1159 HandleSuspend(); 1173 HandleSuspend();
1160 break; 1174 break;
1161 case SWITCH_IME: 1175 case SWITCH_IME:
1162 HandleSwitchIme(ime_control_delegate_.get(), accelerator); 1176 HandleSwitchIme(accelerator);
1163 break; 1177 break;
1164 case SWITCH_TO_NEXT_USER: 1178 case SWITCH_TO_NEXT_USER:
1165 HandleCycleUser(CycleUserDirection::NEXT); 1179 HandleCycleUser(CycleUserDirection::NEXT);
1166 break; 1180 break;
1167 case SWITCH_TO_PREVIOUS_USER: 1181 case SWITCH_TO_PREVIOUS_USER:
1168 HandleCycleUser(CycleUserDirection::PREVIOUS); 1182 HandleCycleUser(CycleUserDirection::PREVIOUS);
1169 break; 1183 break;
1170 case TOGGLE_APP_LIST: 1184 case TOGGLE_APP_LIST:
1171 HandleToggleAppList(accelerator); 1185 HandleToggleAppList(accelerator);
1172 break; 1186 break;
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 data->uma_histogram_name, data->notification_message_id, 1311 data->uma_histogram_name, data->notification_message_id,
1298 data->old_shortcut_id, data->new_shortcut_id); 1312 data->old_shortcut_id, data->new_shortcut_id);
1299 1313
1300 if (!data->deprecated_enabled) 1314 if (!data->deprecated_enabled)
1301 return AcceleratorProcessingStatus::STOP; 1315 return AcceleratorProcessingStatus::STOP;
1302 1316
1303 return AcceleratorProcessingStatus::PROCEED; 1317 return AcceleratorProcessingStatus::PROCEED;
1304 } 1318 }
1305 1319
1306 } // namespace ash 1320 } // namespace ash
OLDNEW
« no previous file with comments | « ash/accelerators/accelerator_controller.h ('k') | ash/accelerators/accelerator_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698