| OLD | NEW |
| 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 | 10 |
| (...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 void AcceleratorController::SetImeControlDelegate( | 780 void AcceleratorController::SetImeControlDelegate( |
| 781 scoped_ptr<ImeControlDelegate> ime_control_delegate) { | 781 scoped_ptr<ImeControlDelegate> ime_control_delegate) { |
| 782 ime_control_delegate_ = ime_control_delegate.Pass(); | 782 ime_control_delegate_ = ime_control_delegate.Pass(); |
| 783 } | 783 } |
| 784 | 784 |
| 785 void AcceleratorController::SetScreenshotDelegate( | 785 void AcceleratorController::SetScreenshotDelegate( |
| 786 scoped_ptr<ScreenshotDelegate> screenshot_delegate) { | 786 scoped_ptr<ScreenshotDelegate> screenshot_delegate) { |
| 787 screenshot_delegate_ = screenshot_delegate.Pass(); | 787 screenshot_delegate_ = screenshot_delegate.Pass(); |
| 788 } | 788 } |
| 789 | 789 |
| 790 bool AcceleratorController::ShouldCloseMenuAndRepostAccelerator( |
| 791 const ui::Accelerator& accelerator) const { |
| 792 auto itr = accelerators_.find(accelerator); |
| 793 if (itr == accelerators_.end()) |
| 794 return false; // Menu shouldn't be closed for an invalid accelerator. |
| 795 |
| 796 AcceleratorAction action = itr->second; |
| 797 return actions_keeping_menu_open_.count(action) == 0; |
| 798 } |
| 799 |
| 790 //////////////////////////////////////////////////////////////////////////////// | 800 //////////////////////////////////////////////////////////////////////////////// |
| 791 // AcceleratorController, ui::AcceleratorTarget implementation: | 801 // AcceleratorController, ui::AcceleratorTarget implementation: |
| 792 | 802 |
| 793 bool AcceleratorController::AcceleratorPressed( | 803 bool AcceleratorController::AcceleratorPressed( |
| 794 const ui::Accelerator& accelerator) { | 804 const ui::Accelerator& accelerator) { |
| 795 std::map<ui::Accelerator, AcceleratorAction>::const_iterator it = | 805 std::map<ui::Accelerator, AcceleratorAction>::const_iterator it = |
| 796 accelerators_.find(accelerator); | 806 accelerators_.find(accelerator); |
| 797 DCHECK(it != accelerators_.end()); | 807 DCHECK(it != accelerators_.end()); |
| 798 AcceleratorAction action = it->second; | 808 AcceleratorAction action = it->second; |
| 799 if (CanPerformAction(action, accelerator)) { | 809 if (CanPerformAction(action, accelerator)) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 824 for (size_t i = 0; i < kPreferredActionsLength; ++i) | 834 for (size_t i = 0; i < kPreferredActionsLength; ++i) |
| 825 preferred_actions_.insert(kPreferredActions[i]); | 835 preferred_actions_.insert(kPreferredActions[i]); |
| 826 for (size_t i = 0; i < kReservedActionsLength; ++i) | 836 for (size_t i = 0; i < kReservedActionsLength; ++i) |
| 827 reserved_actions_.insert(kReservedActions[i]); | 837 reserved_actions_.insert(kReservedActions[i]); |
| 828 for (size_t i = 0; i < kNonrepeatableActionsLength; ++i) | 838 for (size_t i = 0; i < kNonrepeatableActionsLength; ++i) |
| 829 nonrepeatable_actions_.insert(kNonrepeatableActions[i]); | 839 nonrepeatable_actions_.insert(kNonrepeatableActions[i]); |
| 830 for (size_t i = 0; i < kActionsAllowedInAppModeLength; ++i) | 840 for (size_t i = 0; i < kActionsAllowedInAppModeLength; ++i) |
| 831 actions_allowed_in_app_mode_.insert(kActionsAllowedInAppMode[i]); | 841 actions_allowed_in_app_mode_.insert(kActionsAllowedInAppMode[i]); |
| 832 for (size_t i = 0; i < kActionsNeedingWindowLength; ++i) | 842 for (size_t i = 0; i < kActionsNeedingWindowLength; ++i) |
| 833 actions_needing_window_.insert(kActionsNeedingWindow[i]); | 843 actions_needing_window_.insert(kActionsNeedingWindow[i]); |
| 844 for (size_t i = 0; i < kActionsKeepingMenuOpenLength; ++i) |
| 845 actions_keeping_menu_open_.insert(kActionsKeepingMenuOpen[i]); |
| 834 | 846 |
| 835 RegisterAccelerators(kAcceleratorData, kAcceleratorDataLength); | 847 RegisterAccelerators(kAcceleratorData, kAcceleratorDataLength); |
| 836 | 848 |
| 837 RegisterDeprecatedAccelerators(); | 849 RegisterDeprecatedAccelerators(); |
| 838 | 850 |
| 839 if (debug::DebugAcceleratorsEnabled()) { | 851 if (debug::DebugAcceleratorsEnabled()) { |
| 840 RegisterAccelerators(kDebugAcceleratorData, kDebugAcceleratorDataLength); | 852 RegisterAccelerators(kDebugAcceleratorData, kDebugAcceleratorDataLength); |
| 841 // All debug accelerators are reserved. | 853 // All debug accelerators are reserved. |
| 842 for (size_t i = 0; i < kDebugAcceleratorDataLength; ++i) | 854 for (size_t i = 0; i < kDebugAcceleratorDataLength; ++i) |
| 843 reserved_actions_.insert(kDebugAcceleratorData[i].action); | 855 reserved_actions_.insert(kDebugAcceleratorData[i].action); |
| (...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1366 } | 1378 } |
| 1367 | 1379 |
| 1368 void AcceleratorController::SetKeyboardBrightnessControlDelegate( | 1380 void AcceleratorController::SetKeyboardBrightnessControlDelegate( |
| 1369 scoped_ptr<KeyboardBrightnessControlDelegate> | 1381 scoped_ptr<KeyboardBrightnessControlDelegate> |
| 1370 keyboard_brightness_control_delegate) { | 1382 keyboard_brightness_control_delegate) { |
| 1371 keyboard_brightness_control_delegate_ = | 1383 keyboard_brightness_control_delegate_ = |
| 1372 keyboard_brightness_control_delegate.Pass(); | 1384 keyboard_brightness_control_delegate.Pass(); |
| 1373 } | 1385 } |
| 1374 | 1386 |
| 1375 } // namespace ash | 1387 } // namespace ash |
| OLD | NEW |