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

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

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