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

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

Issue 2131733002: mash: Migrate [Keyboard]Brightness code to ash/common. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 4 years, 5 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 <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 11
12 #include "ash/accelerators/accelerator_commands.h" 12 #include "ash/accelerators/accelerator_commands.h"
13 #include "ash/accelerators/debug_commands.h" 13 #include "ash/accelerators/debug_commands.h"
14 #include "ash/common/accessibility_delegate.h" 14 #include "ash/common/accessibility_delegate.h"
15 #include "ash/common/accessibility_types.h" 15 #include "ash/common/accessibility_types.h"
16 #include "ash/common/ash_switches.h" 16 #include "ash/common/ash_switches.h"
17 #include "ash/common/focus_cycler.h" 17 #include "ash/common/focus_cycler.h"
18 #include "ash/common/media_delegate.h" 18 #include "ash/common/media_delegate.h"
19 #include "ash/common/multi_profile_uma.h" 19 #include "ash/common/multi_profile_uma.h"
20 #include "ash/common/session/session_state_delegate.h" 20 #include "ash/common/session/session_state_delegate.h"
21 #include "ash/common/shelf/shelf_model.h" 21 #include "ash/common/shelf/shelf_model.h"
22 #include "ash/common/shell_delegate.h" 22 #include "ash/common/shell_delegate.h"
23 #include "ash/common/shell_window_ids.h" 23 #include "ash/common/shell_window_ids.h"
24 #include "ash/common/system/brightness_control_delegate.h"
25 #include "ash/common/system/keyboard_brightness_control_delegate.h"
24 #include "ash/common/system/system_notifier.h" 26 #include "ash/common/system/system_notifier.h"
25 #include "ash/common/system/tray/system_tray_delegate.h" 27 #include "ash/common/system/tray/system_tray_delegate.h"
26 #include "ash/common/system/tray/system_tray_notifier.h" 28 #include "ash/common/system/tray/system_tray_notifier.h"
27 #include "ash/common/system/volume_control_delegate.h" 29 #include "ash/common/system/volume_control_delegate.h"
28 #include "ash/common/system/web_notification/web_notification_tray.h" 30 #include "ash/common/system/web_notification/web_notification_tray.h"
29 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" 31 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h"
30 #include "ash/common/wm/mru_window_tracker.h" 32 #include "ash/common/wm/mru_window_tracker.h"
31 #include "ash/common/wm/overview/window_selector_controller.h" 33 #include "ash/common/wm/overview/window_selector_controller.h"
32 #include "ash/common/wm/window_state.h" 34 #include "ash/common/wm/window_state.h"
33 #include "ash/common/wm/wm_event.h" 35 #include "ash/common/wm/wm_event.h"
34 #include "ash/common/wm_shell.h" 36 #include "ash/common/wm_shell.h"
35 #include "ash/debug.h" 37 #include "ash/debug.h"
36 #include "ash/display/window_tree_host_manager.h" 38 #include "ash/display/window_tree_host_manager.h"
37 #include "ash/gpu_support.h" 39 #include "ash/gpu_support.h"
38 #include "ash/ime_control_delegate.h" 40 #include "ash/ime_control_delegate.h"
39 #include "ash/magnifier/magnification_controller.h" 41 #include "ash/magnifier/magnification_controller.h"
40 #include "ash/magnifier/partial_magnification_controller.h" 42 #include "ash/magnifier/partial_magnification_controller.h"
41 #include "ash/new_window_delegate.h" 43 #include "ash/new_window_delegate.h"
42 #include "ash/root_window_controller.h" 44 #include "ash/root_window_controller.h"
43 #include "ash/rotator/screen_rotation_animator.h" 45 #include "ash/rotator/screen_rotation_animator.h"
44 #include "ash/rotator/window_rotation.h" 46 #include "ash/rotator/window_rotation.h"
45 #include "ash/screen_util.h" 47 #include "ash/screen_util.h"
46 #include "ash/screenshot_delegate.h" 48 #include "ash/screenshot_delegate.h"
47 #include "ash/shelf/shelf.h" 49 #include "ash/shelf/shelf.h"
48 #include "ash/shelf/shelf_delegate.h" 50 #include "ash/shelf/shelf_delegate.h"
49 #include "ash/shelf/shelf_widget.h" 51 #include "ash/shelf/shelf_widget.h"
50 #include "ash/shell.h" 52 #include "ash/shell.h"
51 #include "ash/system/brightness_control_delegate.h"
52 #include "ash/system/keyboard_brightness/keyboard_brightness_control_delegate.h"
53 #include "ash/system/status_area_widget.h" 53 #include "ash/system/status_area_widget.h"
54 #include "ash/system/tray/system_tray.h" 54 #include "ash/system/tray/system_tray.h"
55 #include "ash/touch/touch_hud_debug.h" 55 #include "ash/touch/touch_hud_debug.h"
56 #include "ash/utility/screenshot_controller.h" 56 #include "ash/utility/screenshot_controller.h"
57 #include "ash/wm/power_button_controller.h" 57 #include "ash/wm/power_button_controller.h"
58 #include "ash/wm/window_cycle_controller.h" 58 #include "ash/wm/window_cycle_controller.h"
59 #include "ash/wm/window_state_aura.h" 59 #include "ash/wm/window_state_aura.h"
60 #include "ash/wm/window_util.h" 60 #include "ash/wm/window_util.h"
61 #include "base/bind.h" 61 #include "base/bind.h"
62 #include "base/command_line.h" 62 #include "base/command_line.h"
(...skipping 11 matching lines...) Expand all
74 #include "ui/compositor/layer_animator.h" 74 #include "ui/compositor/layer_animator.h"
75 #include "ui/display/screen.h" 75 #include "ui/display/screen.h"
76 #include "ui/events/event.h" 76 #include "ui/events/event.h"
77 #include "ui/events/keycodes/keyboard_codes.h" 77 #include "ui/events/keycodes/keyboard_codes.h"
78 #include "ui/message_center/message_center.h" 78 #include "ui/message_center/message_center.h"
79 #include "ui/message_center/notification.h" 79 #include "ui/message_center/notification.h"
80 #include "ui/message_center/notifier_settings.h" 80 #include "ui/message_center/notifier_settings.h"
81 81
82 #if defined(OS_CHROMEOS) 82 #if defined(OS_CHROMEOS)
83 #include "ash/display/display_configuration_controller.h" 83 #include "ash/display/display_configuration_controller.h"
84 #include "ash/system/chromeos/keyboard_brightness_controller.h"
85 #include "base/sys_info.h" 84 #include "base/sys_info.h"
86 #include "chromeos/dbus/dbus_thread_manager.h" 85 #include "chromeos/dbus/dbus_thread_manager.h"
87 #include "chromeos/dbus/power_manager_client.h" 86 #include "chromeos/dbus/power_manager_client.h"
88 #include "ui/base/ime/chromeos/ime_keyboard.h" 87 #include "ui/base/ime/chromeos/ime_keyboard.h"
89 #include "ui/base/ime/chromeos/input_method_manager.h" 88 #include "ui/base/ime/chromeos/input_method_manager.h"
90 #endif // defined(OS_CHROMEOS) 89 #endif // defined(OS_CHROMEOS)
91 90
92 namespace ash { 91 namespace ash {
93 namespace { 92 namespace {
94 93
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 bool CanHandleUnpin() { 546 bool CanHandleUnpin() {
548 wm::WindowState* window_state = wm::GetActiveWindowState(); 547 wm::WindowState* window_state = wm::GetActiveWindowState();
549 return window_state && window_state->IsPinned(); 548 return window_state && window_state->IsPinned();
550 } 549 }
551 550
552 void HandleUnpin() { 551 void HandleUnpin() {
553 accelerators::Unpin(); 552 accelerators::Unpin();
554 } 553 }
555 554
556 #if defined(OS_CHROMEOS) 555 #if defined(OS_CHROMEOS)
557 void HandleBrightnessDown(BrightnessControlDelegate* delegate,
558 const ui::Accelerator& accelerator) {
559 if (delegate)
560 delegate->HandleBrightnessDown(accelerator);
561 }
562
563 void HandleBrightnessUp(BrightnessControlDelegate* delegate,
564 const ui::Accelerator& accelerator) {
565 if (delegate)
566 delegate->HandleBrightnessUp(accelerator);
567 }
568
569 bool CanHandleDisableCapsLock(const ui::Accelerator& previous_accelerator) { 556 bool CanHandleDisableCapsLock(const ui::Accelerator& previous_accelerator) {
570 ui::KeyboardCode previous_key_code = previous_accelerator.key_code(); 557 ui::KeyboardCode previous_key_code = previous_accelerator.key_code();
571 if (previous_accelerator.type() == ui::ET_KEY_RELEASED || 558 if (previous_accelerator.type() == ui::ET_KEY_RELEASED ||
572 (previous_key_code != ui::VKEY_LSHIFT && 559 (previous_key_code != ui::VKEY_LSHIFT &&
573 previous_key_code != ui::VKEY_SHIFT && 560 previous_key_code != ui::VKEY_SHIFT &&
574 previous_key_code != ui::VKEY_RSHIFT)) { 561 previous_key_code != ui::VKEY_RSHIFT)) {
575 // If something else was pressed between the Shift key being pressed 562 // If something else was pressed between the Shift key being pressed
576 // and released, then ignore the release of the Shift key. 563 // and released, then ignore the release of the Shift key.
577 return false; 564 return false;
578 } 565 }
579 chromeos::input_method::InputMethodManager* ime = 566 chromeos::input_method::InputMethodManager* ime =
580 chromeos::input_method::InputMethodManager::Get(); 567 chromeos::input_method::InputMethodManager::Get();
581 chromeos::input_method::ImeKeyboard* keyboard = 568 chromeos::input_method::ImeKeyboard* keyboard =
582 ime ? ime->GetImeKeyboard() : NULL; 569 ime ? ime->GetImeKeyboard() : NULL;
583 return (keyboard && keyboard->CapsLockIsEnabled()); 570 return (keyboard && keyboard->CapsLockIsEnabled());
584 } 571 }
585 572
586 void HandleDisableCapsLock() { 573 void HandleDisableCapsLock() {
587 base::RecordAction(UserMetricsAction("Accel_Disable_Caps_Lock")); 574 base::RecordAction(UserMetricsAction("Accel_Disable_Caps_Lock"));
588 chromeos::input_method::InputMethodManager* ime = 575 chromeos::input_method::InputMethodManager* ime =
589 chromeos::input_method::InputMethodManager::Get(); 576 chromeos::input_method::InputMethodManager::Get();
590 ime->GetImeKeyboard()->SetCapsLockEnabled(false); 577 ime->GetImeKeyboard()->SetCapsLockEnabled(false);
591 } 578 }
592 579
593 void HandleKeyboardBrightnessDown(KeyboardBrightnessControlDelegate* delegate,
594 const ui::Accelerator& accelerator) {
595 if (delegate)
596 delegate->HandleKeyboardBrightnessDown(accelerator);
597 }
598
599 void HandleKeyboardBrightnessUp(KeyboardBrightnessControlDelegate* delegate,
600 const ui::Accelerator& accelerator) {
601 if (delegate)
602 delegate->HandleKeyboardBrightnessUp(accelerator);
603 }
604
605 bool CanHandleLock() { 580 bool CanHandleLock() {
606 return WmShell::Get()->GetSessionStateDelegate()->CanLockScreen(); 581 return WmShell::Get()->GetSessionStateDelegate()->CanLockScreen();
607 } 582 }
608 583
609 void HandleLock() { 584 void HandleLock() {
610 base::RecordAction(UserMetricsAction("Accel_LockScreen_L")); 585 base::RecordAction(UserMetricsAction("Accel_LockScreen_L"));
611 WmShell::Get()->GetSessionStateDelegate()->LockScreen(); 586 WmShell::Get()->GetSessionStateDelegate()->LockScreen();
612 } 587 }
613 588
614 void HandleSuspend() { 589 void HandleSuspend() {
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 return true; 775 return true;
801 } 776 }
802 return false; 777 return false;
803 } 778 }
804 779
805 AcceleratorController::AcceleratorProcessingRestriction 780 AcceleratorController::AcceleratorProcessingRestriction
806 AcceleratorController::GetCurrentAcceleratorRestriction() { 781 AcceleratorController::GetCurrentAcceleratorRestriction() {
807 return GetAcceleratorProcessingRestriction(-1); 782 return GetAcceleratorProcessingRestriction(-1);
808 } 783 }
809 784
810 void AcceleratorController::SetBrightnessControlDelegate(
811 std::unique_ptr<BrightnessControlDelegate> brightness_control_delegate) {
812 brightness_control_delegate_ = std::move(brightness_control_delegate);
813 }
814
815 void AcceleratorController::SetImeControlDelegate( 785 void AcceleratorController::SetImeControlDelegate(
816 std::unique_ptr<ImeControlDelegate> ime_control_delegate) { 786 std::unique_ptr<ImeControlDelegate> ime_control_delegate) {
817 ime_control_delegate_ = std::move(ime_control_delegate); 787 ime_control_delegate_ = std::move(ime_control_delegate);
818 } 788 }
819 789
820 void AcceleratorController::SetScreenshotDelegate( 790 void AcceleratorController::SetScreenshotDelegate(
821 std::unique_ptr<ScreenshotDelegate> screenshot_delegate) { 791 std::unique_ptr<ScreenshotDelegate> screenshot_delegate) {
822 screenshot_delegate_ = std::move(screenshot_delegate); 792 screenshot_delegate_ = std::move(screenshot_delegate);
823 } 793 }
824 794
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 RegisterAccelerators(kAcceleratorData, kAcceleratorDataLength); 891 RegisterAccelerators(kAcceleratorData, kAcceleratorDataLength);
922 892
923 RegisterDeprecatedAccelerators(); 893 RegisterDeprecatedAccelerators();
924 894
925 if (debug::DebugAcceleratorsEnabled()) { 895 if (debug::DebugAcceleratorsEnabled()) {
926 RegisterAccelerators(kDebugAcceleratorData, kDebugAcceleratorDataLength); 896 RegisterAccelerators(kDebugAcceleratorData, kDebugAcceleratorDataLength);
927 // All debug accelerators are reserved. 897 // All debug accelerators are reserved.
928 for (size_t i = 0; i < kDebugAcceleratorDataLength; ++i) 898 for (size_t i = 0; i < kDebugAcceleratorDataLength; ++i)
929 reserved_actions_.insert(kDebugAcceleratorData[i].action); 899 reserved_actions_.insert(kDebugAcceleratorData[i].action);
930 } 900 }
931
932 #if defined(OS_CHROMEOS)
933 keyboard_brightness_control_delegate_.reset(
934 new KeyboardBrightnessController());
935 #endif
936 } 901 }
937 902
938 void AcceleratorController::RegisterAccelerators( 903 void AcceleratorController::RegisterAccelerators(
939 const AcceleratorData accelerators[], 904 const AcceleratorData accelerators[],
940 size_t accelerators_length) { 905 size_t accelerators_length) {
941 for (size_t i = 0; i < accelerators_length; ++i) { 906 for (size_t i = 0; i < accelerators_length; ++i) {
942 ui::Accelerator accelerator = 907 ui::Accelerator accelerator =
943 CreateAccelerator(accelerators[i].keycode, accelerators[i].modifiers, 908 CreateAccelerator(accelerators[i].keycode, accelerators[i].modifiers,
944 accelerators[i].trigger_on_press); 909 accelerators[i].trigger_on_press);
945 Register(accelerator, this); 910 Register(accelerator, this);
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 case WINDOW_MINIMIZE: 1238 case WINDOW_MINIMIZE:
1274 HandleWindowMinimize(); 1239 HandleWindowMinimize();
1275 break; 1240 break;
1276 case WINDOW_POSITION_CENTER: 1241 case WINDOW_POSITION_CENTER:
1277 HandlePositionCenter(); 1242 HandlePositionCenter();
1278 break; 1243 break;
1279 case UNPIN: 1244 case UNPIN:
1280 HandleUnpin(); 1245 HandleUnpin();
1281 break; 1246 break;
1282 #if defined(OS_CHROMEOS) 1247 #if defined(OS_CHROMEOS)
1283 case BRIGHTNESS_DOWN: 1248 case BRIGHTNESS_DOWN: {
1284 HandleBrightnessDown(brightness_control_delegate_.get(), accelerator); 1249 BrightnessControlDelegate* delegate =
1250 WmShell::Get()->brightness_control_delegate();
1251 if (delegate)
1252 delegate->HandleBrightnessDown(accelerator);
1285 break; 1253 break;
1286 case BRIGHTNESS_UP: 1254 }
1287 HandleBrightnessUp(brightness_control_delegate_.get(), accelerator); 1255 case BRIGHTNESS_UP: {
1256 BrightnessControlDelegate* delegate =
1257 WmShell::Get()->brightness_control_delegate();
1258 if (delegate)
1259 delegate->HandleBrightnessUp(accelerator);
1288 break; 1260 break;
1261 }
1289 case DEBUG_ADD_REMOVE_DISPLAY: 1262 case DEBUG_ADD_REMOVE_DISPLAY:
1290 case DEBUG_SHOW_TOAST: 1263 case DEBUG_SHOW_TOAST:
1291 case DEBUG_TOGGLE_TOUCH_PAD: 1264 case DEBUG_TOGGLE_TOUCH_PAD:
1292 case DEBUG_TOGGLE_TOUCH_SCREEN: 1265 case DEBUG_TOGGLE_TOUCH_SCREEN:
1293 case DEBUG_TOGGLE_TOUCH_VIEW: 1266 case DEBUG_TOGGLE_TOUCH_VIEW:
1294 case DEBUG_TOGGLE_UNIFIED_DESKTOP: 1267 case DEBUG_TOGGLE_UNIFIED_DESKTOP:
1295 debug::PerformDebugActionIfEnabled(action); 1268 debug::PerformDebugActionIfEnabled(action);
1296 break; 1269 break;
1297 case DISABLE_CAPS_LOCK: 1270 case DISABLE_CAPS_LOCK:
1298 HandleDisableCapsLock(); 1271 HandleDisableCapsLock();
1299 break; 1272 break;
1300 case DISABLE_GPU_WATCHDOG: 1273 case DISABLE_GPU_WATCHDOG:
1301 Shell::GetInstance()->gpu_support()->DisableGpuWatchdog(); 1274 Shell::GetInstance()->gpu_support()->DisableGpuWatchdog();
1302 break; 1275 break;
1303 case KEYBOARD_BRIGHTNESS_DOWN: 1276 case KEYBOARD_BRIGHTNESS_DOWN: {
1304 HandleKeyboardBrightnessDown(keyboard_brightness_control_delegate_.get(), 1277 KeyboardBrightnessControlDelegate* delegate =
1305 accelerator); 1278 WmShell::Get()->keyboard_brightness_control_delegate();
1279 if (delegate)
1280 delegate->HandleKeyboardBrightnessDown(accelerator);
1306 break; 1281 break;
1307 case KEYBOARD_BRIGHTNESS_UP: 1282 }
1308 HandleKeyboardBrightnessUp(keyboard_brightness_control_delegate_.get(), 1283 case KEYBOARD_BRIGHTNESS_UP: {
1309 accelerator); 1284 KeyboardBrightnessControlDelegate* delegate =
1285 WmShell::Get()->keyboard_brightness_control_delegate();
1286 if (delegate)
1287 delegate->HandleKeyboardBrightnessUp(accelerator);
1310 break; 1288 break;
1289 }
1311 case LOCK_PRESSED: 1290 case LOCK_PRESSED:
1312 case LOCK_RELEASED: 1291 case LOCK_RELEASED:
1313 Shell::GetInstance()->power_button_controller()->OnLockButtonEvent( 1292 Shell::GetInstance()->power_button_controller()->OnLockButtonEvent(
1314 action == LOCK_PRESSED, base::TimeTicks()); 1293 action == LOCK_PRESSED, base::TimeTicks());
1315 break; 1294 break;
1316 case LOCK_SCREEN: 1295 case LOCK_SCREEN:
1317 HandleLock(); 1296 HandleLock();
1318 break; 1297 break;
1319 case OPEN_CROSH: 1298 case OPEN_CROSH:
1320 HandleCrosh(); 1299 HandleCrosh();
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1428 } 1407 }
1429 if (wm_shell->mru_window_tracker()->BuildMruWindowList().empty() && 1408 if (wm_shell->mru_window_tracker()->BuildMruWindowList().empty() &&
1430 actions_needing_window_.find(action) != actions_needing_window_.end()) { 1409 actions_needing_window_.find(action) != actions_needing_window_.end()) {
1431 wm_shell->GetAccessibilityDelegate()->TriggerAccessibilityAlert( 1410 wm_shell->GetAccessibilityDelegate()->TriggerAccessibilityAlert(
1432 A11Y_ALERT_WINDOW_NEEDED); 1411 A11Y_ALERT_WINDOW_NEEDED);
1433 return RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION; 1412 return RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION;
1434 } 1413 }
1435 return RESTRICTION_NONE; 1414 return RESTRICTION_NONE;
1436 } 1415 }
1437 1416
1438 void AcceleratorController::SetKeyboardBrightnessControlDelegate(
1439 std::unique_ptr<KeyboardBrightnessControlDelegate>
1440 keyboard_brightness_control_delegate) {
1441 keyboard_brightness_control_delegate_ =
1442 std::move(keyboard_brightness_control_delegate);
1443 }
1444
1445 } // namespace ash 1417 } // 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