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

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

Issue 2095193002: clang-format all of //ash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 } 233 }
234 234
235 void HandleLaunchLastApp() { 235 void HandleLaunchLastApp() {
236 base::RecordAction(UserMetricsAction("Accel_Launch_Last_App")); 236 base::RecordAction(UserMetricsAction("Accel_Launch_Last_App"));
237 Shelf::ForPrimaryDisplay()->LaunchAppIndexAt(-1); 237 Shelf::ForPrimaryDisplay()->LaunchAppIndexAt(-1);
238 } 238 }
239 239
240 bool CanHandleMagnifyScreen() { 240 bool CanHandleMagnifyScreen() {
241 Shell* shell = Shell::GetInstance(); 241 Shell* shell = Shell::GetInstance();
242 return shell->magnification_controller()->IsEnabled() || 242 return shell->magnification_controller()->IsEnabled() ||
243 shell->partial_magnification_controller()->is_enabled(); 243 shell->partial_magnification_controller()->is_enabled();
244 } 244 }
245 245
246 // Magnify the screen 246 // Magnify the screen
247 void HandleMagnifyScreen(int delta_index) { 247 void HandleMagnifyScreen(int delta_index) {
248 if (ash::Shell::GetInstance()->magnification_controller()->IsEnabled()) { 248 if (ash::Shell::GetInstance()->magnification_controller()->IsEnabled()) {
249 // TODO(yoshiki): Move the following logic to MagnificationController. 249 // TODO(yoshiki): Move the following logic to MagnificationController.
250 float scale = 250 float scale =
251 ash::Shell::GetInstance()->magnification_controller()->GetScale(); 251 ash::Shell::GetInstance()->magnification_controller()->GetScale();
252 // Calculate rounded logarithm (base kMagnificationScaleFactor) of scale. 252 // Calculate rounded logarithm (base kMagnificationScaleFactor) of scale.
253 int scale_index = 253 int scale_index =
254 std::floor(std::log(scale) / std::log(kMagnificationScaleFactor) + 0.5); 254 std::floor(std::log(scale) / std::log(kMagnificationScaleFactor) + 0.5);
255 255
256 int new_scale_index = std::max(0, std::min(8, scale_index + delta_index)); 256 int new_scale_index = std::max(0, std::min(8, scale_index + delta_index));
257 257
258 ash::Shell::GetInstance()->magnification_controller()->SetScale( 258 ash::Shell::GetInstance()->magnification_controller()->SetScale(
259 std::pow(kMagnificationScaleFactor, new_scale_index), true); 259 std::pow(kMagnificationScaleFactor, new_scale_index), true);
260 } else if (ash::Shell::GetInstance()-> 260 } else if (ash::Shell::GetInstance()
261 partial_magnification_controller()->is_enabled()) { 261 ->partial_magnification_controller()
262 ->is_enabled()) {
262 float scale = delta_index > 0 ? kDefaultPartialMagnifiedScale : 1; 263 float scale = delta_index > 0 ? kDefaultPartialMagnifiedScale : 1;
263 ash::Shell::GetInstance()->partial_magnification_controller()-> 264 ash::Shell::GetInstance()->partial_magnification_controller()->SetScale(
264 SetScale(scale); 265 scale);
265 } 266 }
266 } 267 }
267 268
268 void HandleMediaNextTrack() { 269 void HandleMediaNextTrack() {
269 Shell::GetInstance()->media_delegate()->HandleMediaNextTrack(); 270 Shell::GetInstance()->media_delegate()->HandleMediaNextTrack();
270 } 271 }
271 272
272 void HandleMediaPlayPause() { 273 void HandleMediaPlayPause() {
273 Shell::GetInstance()->media_delegate()->HandleMediaPlayPause(); 274 Shell::GetInstance()->media_delegate()->HandleMediaPlayPause();
274 } 275 }
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 384
384 // Rotate the active window. 385 // Rotate the active window.
385 void HandleRotateActiveWindow() { 386 void HandleRotateActiveWindow() {
386 base::RecordAction(UserMetricsAction("Accel_Rotate_Window")); 387 base::RecordAction(UserMetricsAction("Accel_Rotate_Window"));
387 aura::Window* active_window = wm::GetActiveWindow(); 388 aura::Window* active_window = wm::GetActiveWindow();
388 if (active_window) { 389 if (active_window) {
389 // The rotation animation bases its target transform on the current 390 // The rotation animation bases its target transform on the current
390 // rotation and position. Since there could be an animation in progress 391 // rotation and position. Since there could be an animation in progress
391 // right now, queue this animation so when it starts it picks up a neutral 392 // right now, queue this animation so when it starts it picks up a neutral
392 // rotation and position. Use replace so we only enqueue one at a time. 393 // rotation and position. Use replace so we only enqueue one at a time.
393 active_window->layer()->GetAnimator()-> 394 active_window->layer()->GetAnimator()->set_preemption_strategy(
394 set_preemption_strategy(ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); 395 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
395 active_window->layer()->GetAnimator()->StartAnimation( 396 active_window->layer()->GetAnimator()->StartAnimation(
396 new ui::LayerAnimationSequence( 397 new ui::LayerAnimationSequence(
397 new ash::WindowRotation(360, active_window->layer()))); 398 new ash::WindowRotation(360, active_window->layer())));
398 } 399 }
399 } 400 }
400 401
401 void HandleShowKeyboardOverlay() { 402 void HandleShowKeyboardOverlay() {
402 base::RecordAction(UserMetricsAction("Accel_Show_Keyboard_Overlay")); 403 base::RecordAction(UserMetricsAction("Accel_Show_Keyboard_Overlay"));
403 ash::Shell::GetInstance()->new_window_delegate()->ShowKeyboardOverlay(); 404 ash::Shell::GetInstance()->new_window_delegate()->ShowKeyboardOverlay();
404 } 405 }
(...skipping 30 matching lines...) Expand all
435 } 436 }
436 437
437 void HandleShowTaskManager() { 438 void HandleShowTaskManager() {
438 base::RecordAction(UserMetricsAction("Accel_Show_Task_Manager")); 439 base::RecordAction(UserMetricsAction("Accel_Show_Task_Manager"));
439 Shell::GetInstance()->new_window_delegate()->ShowTaskManager(); 440 Shell::GetInstance()->new_window_delegate()->ShowTaskManager();
440 } 441 }
441 442
442 bool CanHandleSwitchIme(ImeControlDelegate* ime_control_delegate, 443 bool CanHandleSwitchIme(ImeControlDelegate* ime_control_delegate,
443 const ui::Accelerator& accelerator) { 444 const ui::Accelerator& accelerator) {
444 return ime_control_delegate && 445 return ime_control_delegate &&
445 ime_control_delegate->CanSwitchIme(accelerator); 446 ime_control_delegate->CanSwitchIme(accelerator);
446 } 447 }
447 448
448 void HandleSwitchIme(ImeControlDelegate* ime_control_delegate, 449 void HandleSwitchIme(ImeControlDelegate* ime_control_delegate,
449 const ui::Accelerator& accelerator) { 450 const ui::Accelerator& accelerator) {
450 base::RecordAction(UserMetricsAction("Accel_Switch_Ime")); 451 base::RecordAction(UserMetricsAction("Accel_Switch_Ime"));
451 ime_control_delegate->HandleSwitchIme(accelerator); 452 ime_control_delegate->HandleSwitchIme(accelerator);
452 } 453 }
453 454
454 void HandleTakeWindowScreenshot(ScreenshotDelegate* screenshot_delegate) { 455 void HandleTakeWindowScreenshot(ScreenshotDelegate* screenshot_delegate) {
455 base::RecordAction(UserMetricsAction("Accel_Take_Window_Screenshot")); 456 base::RecordAction(UserMetricsAction("Accel_Take_Window_Screenshot"));
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 return (window_state && window_state->IsUserPositionable() && 520 return (window_state && window_state->IsUserPositionable() &&
520 !window_state->IsFullscreen()); 521 !window_state->IsFullscreen());
521 } 522 }
522 523
523 void HandleWindowSnapOrDock(AcceleratorAction action) { 524 void HandleWindowSnapOrDock(AcceleratorAction action) {
524 if (action == WINDOW_CYCLE_SNAP_DOCK_LEFT) 525 if (action == WINDOW_CYCLE_SNAP_DOCK_LEFT)
525 base::RecordAction(UserMetricsAction("Accel_Window_Snap_Left")); 526 base::RecordAction(UserMetricsAction("Accel_Window_Snap_Left"));
526 else 527 else
527 base::RecordAction(UserMetricsAction("Accel_Window_Snap_Right")); 528 base::RecordAction(UserMetricsAction("Accel_Window_Snap_Right"));
528 529
529 const wm::WMEvent event(action == WINDOW_CYCLE_SNAP_DOCK_LEFT ? 530 const wm::WMEvent event(action == WINDOW_CYCLE_SNAP_DOCK_LEFT
530 wm::WM_EVENT_CYCLE_SNAP_DOCK_LEFT : 531 ? wm::WM_EVENT_CYCLE_SNAP_DOCK_LEFT
531 wm::WM_EVENT_CYCLE_SNAP_DOCK_RIGHT); 532 : wm::WM_EVENT_CYCLE_SNAP_DOCK_RIGHT);
532 wm::GetActiveWindowState()->OnWMEvent(&event); 533 wm::GetActiveWindowState()->OnWMEvent(&event);
533 } 534 }
534 535
535 void HandleWindowMinimize() { 536 void HandleWindowMinimize() {
536 base::RecordAction( 537 base::RecordAction(base::UserMetricsAction("Accel_Toggle_Minimized_Minus"));
537 base::UserMetricsAction("Accel_Toggle_Minimized_Minus"));
538 accelerators::ToggleMinimized(); 538 accelerators::ToggleMinimized();
539 } 539 }
540 540
541 bool CanHandlePositionCenter() { 541 bool CanHandlePositionCenter() {
542 // Docked windows do not support centering. 542 // Docked windows do not support centering.
543 wm::WindowState* window_state = wm::GetActiveWindowState(); 543 wm::WindowState* window_state = wm::GetActiveWindowState();
544 return (window_state && !window_state->IsDocked()); 544 return (window_state && !window_state->IsDocked());
545 } 545 }
546 546
547 void HandlePositionCenter() { 547 void HandlePositionCenter() {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 639
640 void HandleSwapPrimaryDisplay() { 640 void HandleSwapPrimaryDisplay() {
641 base::RecordAction(UserMetricsAction("Accel_Swap_Primary_Display")); 641 base::RecordAction(UserMetricsAction("Accel_Swap_Primary_Display"));
642 Shell::GetInstance()->display_configuration_controller()->SetPrimaryDisplayId( 642 Shell::GetInstance()->display_configuration_controller()->SetPrimaryDisplayId(
643 ScreenUtil::GetSecondaryDisplay().id(), true /* user_action */); 643 ScreenUtil::GetSecondaryDisplay().id(), true /* user_action */);
644 } 644 }
645 645
646 bool CanHandleCycleUser() { 646 bool CanHandleCycleUser() {
647 Shell* shell = Shell::GetInstance(); 647 Shell* shell = Shell::GetInstance();
648 return shell->delegate()->IsMultiProfilesEnabled() && 648 return shell->delegate()->IsMultiProfilesEnabled() &&
649 shell->session_state_delegate()->NumberOfLoggedInUsers() > 1; 649 shell->session_state_delegate()->NumberOfLoggedInUsers() > 1;
650 } 650 }
651 651
652 void HandleCycleUser(SessionStateDelegate::CycleUser cycle_user) { 652 void HandleCycleUser(SessionStateDelegate::CycleUser cycle_user) {
653 MultiProfileUMA::RecordSwitchActiveUser( 653 MultiProfileUMA::RecordSwitchActiveUser(
654 MultiProfileUMA::SWITCH_ACTIVE_USER_BY_ACCELERATOR); 654 MultiProfileUMA::SWITCH_ACTIVE_USER_BY_ACCELERATOR);
655 switch (cycle_user) { 655 switch (cycle_user) {
656 case SessionStateDelegate::CYCLE_TO_NEXT_USER: 656 case SessionStateDelegate::CYCLE_TO_NEXT_USER:
657 base::RecordAction(UserMetricsAction("Accel_Switch_To_Next_User")); 657 base::RecordAction(UserMetricsAction("Accel_Switch_To_Next_User"));
658 break; 658 break;
659 case SessionStateDelegate::CYCLE_TO_PREVIOUS_USER: 659 case SessionStateDelegate::CYCLE_TO_PREVIOUS_USER:
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 742
743 //////////////////////////////////////////////////////////////////////////////// 743 ////////////////////////////////////////////////////////////////////////////////
744 // AcceleratorController, public: 744 // AcceleratorController, public:
745 745
746 AcceleratorController::AcceleratorController() 746 AcceleratorController::AcceleratorController()
747 : accelerator_manager_(new ui::AcceleratorManager), 747 : accelerator_manager_(new ui::AcceleratorManager),
748 accelerator_history_(new ui::AcceleratorHistory) { 748 accelerator_history_(new ui::AcceleratorHistory) {
749 Init(); 749 Init();
750 } 750 }
751 751
752 AcceleratorController::~AcceleratorController() { 752 AcceleratorController::~AcceleratorController() {}
753 }
754 753
755 void AcceleratorController::Register(const ui::Accelerator& accelerator, 754 void AcceleratorController::Register(const ui::Accelerator& accelerator,
756 ui::AcceleratorTarget* target) { 755 ui::AcceleratorTarget* target) {
757 accelerator_manager_->Register(accelerator, 756 accelerator_manager_->Register(
758 ui::AcceleratorManager::kNormalPriority, 757 accelerator, ui::AcceleratorManager::kNormalPriority, target);
759 target);
760 } 758 }
761 759
762 void AcceleratorController::Unregister(const ui::Accelerator& accelerator, 760 void AcceleratorController::Unregister(const ui::Accelerator& accelerator,
763 ui::AcceleratorTarget* target) { 761 ui::AcceleratorTarget* target) {
764 accelerator_manager_->Unregister(accelerator, target); 762 accelerator_manager_->Unregister(accelerator, target);
765 } 763 }
766 764
767 void AcceleratorController::UnregisterAll(ui::AcceleratorTarget* target) { 765 void AcceleratorController::UnregisterAll(ui::AcceleratorTarget* target) {
768 accelerator_manager_->UnregisterAll(target); 766 accelerator_manager_->UnregisterAll(target);
769 } 767 }
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 } 942 }
945 943
946 void AcceleratorController::RegisterAccelerators( 944 void AcceleratorController::RegisterAccelerators(
947 const AcceleratorData accelerators[], 945 const AcceleratorData accelerators[],
948 size_t accelerators_length) { 946 size_t accelerators_length) {
949 for (size_t i = 0; i < accelerators_length; ++i) { 947 for (size_t i = 0; i < accelerators_length; ++i) {
950 ui::Accelerator accelerator = 948 ui::Accelerator accelerator =
951 CreateAccelerator(accelerators[i].keycode, accelerators[i].modifiers, 949 CreateAccelerator(accelerators[i].keycode, accelerators[i].modifiers,
952 accelerators[i].trigger_on_press); 950 accelerators[i].trigger_on_press);
953 Register(accelerator, this); 951 Register(accelerator, this);
954 accelerators_.insert( 952 accelerators_.insert(std::make_pair(accelerator, accelerators[i].action));
955 std::make_pair(accelerator, accelerators[i].action));
956 } 953 }
957 } 954 }
958 955
959 void AcceleratorController::RegisterDeprecatedAccelerators() { 956 void AcceleratorController::RegisterDeprecatedAccelerators() {
960 #if defined(OS_CHROMEOS) 957 #if defined(OS_CHROMEOS)
961 for (size_t i = 0; i < kDeprecatedAcceleratorsDataLength; ++i) { 958 for (size_t i = 0; i < kDeprecatedAcceleratorsDataLength; ++i) {
962 const DeprecatedAcceleratorData* data = &kDeprecatedAcceleratorsData[i]; 959 const DeprecatedAcceleratorData* data = &kDeprecatedAcceleratorsData[i];
963 actions_with_deprecations_[data->action] = data; 960 actions_with_deprecations_[data->action] = data;
964 } 961 }
965 962
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
1314 case KEYBOARD_BRIGHTNESS_DOWN: 1311 case KEYBOARD_BRIGHTNESS_DOWN:
1315 HandleKeyboardBrightnessDown(keyboard_brightness_control_delegate_.get(), 1312 HandleKeyboardBrightnessDown(keyboard_brightness_control_delegate_.get(),
1316 accelerator); 1313 accelerator);
1317 break; 1314 break;
1318 case KEYBOARD_BRIGHTNESS_UP: 1315 case KEYBOARD_BRIGHTNESS_UP:
1319 HandleKeyboardBrightnessUp(keyboard_brightness_control_delegate_.get(), 1316 HandleKeyboardBrightnessUp(keyboard_brightness_control_delegate_.get(),
1320 accelerator); 1317 accelerator);
1321 break; 1318 break;
1322 case LOCK_PRESSED: 1319 case LOCK_PRESSED:
1323 case LOCK_RELEASED: 1320 case LOCK_RELEASED:
1324 Shell::GetInstance()->power_button_controller()-> 1321 Shell::GetInstance()->power_button_controller()->OnLockButtonEvent(
1325 OnLockButtonEvent(action == LOCK_PRESSED, base::TimeTicks()); 1322 action == LOCK_PRESSED, base::TimeTicks());
1326 break; 1323 break;
1327 case LOCK_SCREEN: 1324 case LOCK_SCREEN:
1328 HandleLock(); 1325 HandleLock();
1329 break; 1326 break;
1330 case OPEN_CROSH: 1327 case OPEN_CROSH:
1331 HandleCrosh(); 1328 HandleCrosh();
1332 break; 1329 break;
1333 case OPEN_FILE_MANAGER: 1330 case OPEN_FILE_MANAGER:
1334 HandleFileManager(); 1331 HandleFileManager();
1335 break; 1332 break;
1336 case OPEN_GET_HELP: 1333 case OPEN_GET_HELP:
1337 HandleGetHelp(); 1334 HandleGetHelp();
1338 break; 1335 break;
1339 case POWER_PRESSED: // fallthrough 1336 case POWER_PRESSED: // fallthrough
1340 case POWER_RELEASED: 1337 case POWER_RELEASED:
1341 if (!base::SysInfo::IsRunningOnChromeOS()) { 1338 if (!base::SysInfo::IsRunningOnChromeOS()) {
1342 // There is no powerd, the Chrome OS power manager, in linux desktop, 1339 // There is no powerd, the Chrome OS power manager, in linux desktop,
1343 // so call the PowerButtonController here. 1340 // so call the PowerButtonController here.
1344 Shell::GetInstance()->power_button_controller()-> 1341 Shell::GetInstance()->power_button_controller()->OnPowerButtonEvent(
1345 OnPowerButtonEvent(action == POWER_PRESSED, base::TimeTicks()); 1342 action == POWER_PRESSED, base::TimeTicks());
1346 } 1343 }
1347 // We don't do anything with these at present on the device, 1344 // We don't do anything with these at present on the device,
1348 // (power button events are reported to us from powerm via 1345 // (power button events are reported to us from powerm via
1349 // D-BUS), but we consume them to prevent them from getting 1346 // D-BUS), but we consume them to prevent them from getting
1350 // passed to apps -- see http://crbug.com/146609. 1347 // passed to apps -- see http://crbug.com/146609.
1351 break; 1348 break;
1352 case SUSPEND: 1349 case SUSPEND:
1353 HandleSuspend(); 1350 HandleSuspend();
1354 break; 1351 break;
1355 case SWAP_PRIMARY_DISPLAY: 1352 case SWAP_PRIMARY_DISPLAY:
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1447 } 1444 }
1448 1445
1449 void AcceleratorController::SetKeyboardBrightnessControlDelegate( 1446 void AcceleratorController::SetKeyboardBrightnessControlDelegate(
1450 std::unique_ptr<KeyboardBrightnessControlDelegate> 1447 std::unique_ptr<KeyboardBrightnessControlDelegate>
1451 keyboard_brightness_control_delegate) { 1448 keyboard_brightness_control_delegate) {
1452 keyboard_brightness_control_delegate_ = 1449 keyboard_brightness_control_delegate_ =
1453 std::move(keyboard_brightness_control_delegate); 1450 std::move(keyboard_brightness_control_delegate);
1454 } 1451 }
1455 1452
1456 } // namespace ash 1453 } // 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