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 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
779 void AcceleratorController::SetImeControlDelegate( | 779 void AcceleratorController::SetImeControlDelegate( |
780 scoped_ptr<ImeControlDelegate> ime_control_delegate) { | 780 scoped_ptr<ImeControlDelegate> ime_control_delegate) { |
781 ime_control_delegate_ = ime_control_delegate.Pass(); | 781 ime_control_delegate_ = ime_control_delegate.Pass(); |
782 } | 782 } |
783 | 783 |
784 void AcceleratorController::SetScreenshotDelegate( | 784 void AcceleratorController::SetScreenshotDelegate( |
785 scoped_ptr<ScreenshotDelegate> screenshot_delegate) { | 785 scoped_ptr<ScreenshotDelegate> screenshot_delegate) { |
786 screenshot_delegate_ = screenshot_delegate.Pass(); | 786 screenshot_delegate_ = screenshot_delegate.Pass(); |
787 } | 787 } |
788 | 788 |
| 789 bool AcceleratorController::ShouldMenuBeKeptOpenForAccelerator( |
| 790 const ui::Accelerator& accelerator) const { |
| 791 auto itr = accelerators_.find(accelerator); |
| 792 if (itr == accelerators_.end()) |
| 793 return true; // Menu shouldn't be closed for an invalid accelerator. |
| 794 |
| 795 AcceleratorAction action = itr->second; |
| 796 if (actions_keeping_menu_open_.count(action)) |
| 797 return true; |
| 798 |
| 799 return false; |
| 800 } |
| 801 |
789 //////////////////////////////////////////////////////////////////////////////// | 802 //////////////////////////////////////////////////////////////////////////////// |
790 // AcceleratorController, ui::AcceleratorTarget implementation: | 803 // AcceleratorController, ui::AcceleratorTarget implementation: |
791 | 804 |
792 bool AcceleratorController::AcceleratorPressed( | 805 bool AcceleratorController::AcceleratorPressed( |
793 const ui::Accelerator& accelerator) { | 806 const ui::Accelerator& accelerator) { |
794 std::map<ui::Accelerator, AcceleratorAction>::const_iterator it = | 807 std::map<ui::Accelerator, AcceleratorAction>::const_iterator it = |
795 accelerators_.find(accelerator); | 808 accelerators_.find(accelerator); |
796 DCHECK(it != accelerators_.end()); | 809 DCHECK(it != accelerators_.end()); |
797 AcceleratorAction action = it->second; | 810 AcceleratorAction action = it->second; |
798 if (CanPerformAction(action, accelerator)) { | 811 if (CanPerformAction(action, accelerator)) { |
(...skipping 24 matching lines...) Expand all Loading... |
823 for (size_t i = 0; i < kPreferredActionsLength; ++i) | 836 for (size_t i = 0; i < kPreferredActionsLength; ++i) |
824 preferred_actions_.insert(kPreferredActions[i]); | 837 preferred_actions_.insert(kPreferredActions[i]); |
825 for (size_t i = 0; i < kReservedActionsLength; ++i) | 838 for (size_t i = 0; i < kReservedActionsLength; ++i) |
826 reserved_actions_.insert(kReservedActions[i]); | 839 reserved_actions_.insert(kReservedActions[i]); |
827 for (size_t i = 0; i < kNonrepeatableActionsLength; ++i) | 840 for (size_t i = 0; i < kNonrepeatableActionsLength; ++i) |
828 nonrepeatable_actions_.insert(kNonrepeatableActions[i]); | 841 nonrepeatable_actions_.insert(kNonrepeatableActions[i]); |
829 for (size_t i = 0; i < kActionsAllowedInAppModeLength; ++i) | 842 for (size_t i = 0; i < kActionsAllowedInAppModeLength; ++i) |
830 actions_allowed_in_app_mode_.insert(kActionsAllowedInAppMode[i]); | 843 actions_allowed_in_app_mode_.insert(kActionsAllowedInAppMode[i]); |
831 for (size_t i = 0; i < kActionsNeedingWindowLength; ++i) | 844 for (size_t i = 0; i < kActionsNeedingWindowLength; ++i) |
832 actions_needing_window_.insert(kActionsNeedingWindow[i]); | 845 actions_needing_window_.insert(kActionsNeedingWindow[i]); |
| 846 for (size_t i = 0; i < kActionsKeepingMenuOpenLength; ++i) |
| 847 actions_keeping_menu_open_.insert(kActionsKeepingMenuOpen[i]); |
833 | 848 |
834 RegisterAccelerators(kAcceleratorData, kAcceleratorDataLength); | 849 RegisterAccelerators(kAcceleratorData, kAcceleratorDataLength); |
835 | 850 |
836 if (debug::DebugAcceleratorsEnabled()) { | 851 if (debug::DebugAcceleratorsEnabled()) { |
837 RegisterAccelerators(kDebugAcceleratorData, kDebugAcceleratorDataLength); | 852 RegisterAccelerators(kDebugAcceleratorData, kDebugAcceleratorDataLength); |
838 // All debug accelerators are reserved. | 853 // All debug accelerators are reserved. |
839 for (size_t i = 0; i < kDebugAcceleratorDataLength; ++i) | 854 for (size_t i = 0; i < kDebugAcceleratorDataLength; ++i) |
840 reserved_actions_.insert(kDebugAcceleratorData[i].action); | 855 reserved_actions_.insert(kDebugAcceleratorData[i].action); |
841 } | 856 } |
842 | 857 |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1328 } | 1343 } |
1329 | 1344 |
1330 void AcceleratorController::SetKeyboardBrightnessControlDelegate( | 1345 void AcceleratorController::SetKeyboardBrightnessControlDelegate( |
1331 scoped_ptr<KeyboardBrightnessControlDelegate> | 1346 scoped_ptr<KeyboardBrightnessControlDelegate> |
1332 keyboard_brightness_control_delegate) { | 1347 keyboard_brightness_control_delegate) { |
1333 keyboard_brightness_control_delegate_ = | 1348 keyboard_brightness_control_delegate_ = |
1334 keyboard_brightness_control_delegate.Pass(); | 1349 keyboard_brightness_control_delegate.Pass(); |
1335 } | 1350 } |
1336 | 1351 |
1337 } // namespace ash | 1352 } // namespace ash |
OLD | NEW |