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

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

Issue 1202923002: Revert "Deprecating high-conflict accelerators" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <string> 9 #include <string>
10 10
(...skipping 20 matching lines...) Expand all
31 #include "ash/shelf/shelf.h" 31 #include "ash/shelf/shelf.h"
32 #include "ash/shelf/shelf_delegate.h" 32 #include "ash/shelf/shelf_delegate.h"
33 #include "ash/shelf/shelf_model.h" 33 #include "ash/shelf/shelf_model.h"
34 #include "ash/shelf/shelf_widget.h" 34 #include "ash/shelf/shelf_widget.h"
35 #include "ash/shell.h" 35 #include "ash/shell.h"
36 #include "ash/shell_delegate.h" 36 #include "ash/shell_delegate.h"
37 #include "ash/shell_window_ids.h" 37 #include "ash/shell_window_ids.h"
38 #include "ash/system/brightness_control_delegate.h" 38 #include "ash/system/brightness_control_delegate.h"
39 #include "ash/system/keyboard_brightness/keyboard_brightness_control_delegate.h" 39 #include "ash/system/keyboard_brightness/keyboard_brightness_control_delegate.h"
40 #include "ash/system/status_area_widget.h" 40 #include "ash/system/status_area_widget.h"
41 #include "ash/system/system_notifier.h"
42 #include "ash/system/tray/system_tray.h" 41 #include "ash/system/tray/system_tray.h"
43 #include "ash/system/tray/system_tray_delegate.h" 42 #include "ash/system/tray/system_tray_delegate.h"
44 #include "ash/system/tray/system_tray_notifier.h" 43 #include "ash/system/tray/system_tray_notifier.h"
45 #include "ash/system/web_notification/web_notification_tray.h" 44 #include "ash/system/web_notification/web_notification_tray.h"
46 #include "ash/touch/touch_hud_debug.h" 45 #include "ash/touch/touch_hud_debug.h"
47 #include "ash/utility/partial_screenshot_controller.h" 46 #include "ash/utility/partial_screenshot_controller.h"
48 #include "ash/volume_control_delegate.h" 47 #include "ash/volume_control_delegate.h"
49 #include "ash/wm/maximize_mode/maximize_mode_controller.h" 48 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
50 #include "ash/wm/mru_window_tracker.h" 49 #include "ash/wm/mru_window_tracker.h"
51 #include "ash/wm/overview/window_selector_controller.h" 50 #include "ash/wm/overview/window_selector_controller.h"
52 #include "ash/wm/power_button_controller.h" 51 #include "ash/wm/power_button_controller.h"
53 #include "ash/wm/window_cycle_controller.h" 52 #include "ash/wm/window_cycle_controller.h"
54 #include "ash/wm/window_state.h" 53 #include "ash/wm/window_state.h"
55 #include "ash/wm/window_util.h" 54 #include "ash/wm/window_util.h"
56 #include "ash/wm/wm_event.h" 55 #include "ash/wm/wm_event.h"
57 #include "base/bind.h" 56 #include "base/bind.h"
58 #include "base/command_line.h" 57 #include "base/command_line.h"
59 #include "base/metrics/histogram_macros.h"
60 #include "base/metrics/user_metrics.h" 58 #include "base/metrics/user_metrics.h"
61 #include "ui/aura/env.h" 59 #include "ui/aura/env.h"
62 #include "ui/base/accelerators/accelerator.h" 60 #include "ui/base/accelerators/accelerator.h"
63 #include "ui/base/accelerators/accelerator_manager.h" 61 #include "ui/base/accelerators/accelerator_manager.h"
64 #include "ui/base/l10n/l10n_util.h"
65 #include "ui/compositor/layer.h" 62 #include "ui/compositor/layer.h"
66 #include "ui/compositor/layer_animation_sequence.h" 63 #include "ui/compositor/layer_animation_sequence.h"
67 #include "ui/compositor/layer_animator.h" 64 #include "ui/compositor/layer_animator.h"
68 #include "ui/events/event.h" 65 #include "ui/events/event.h"
69 #include "ui/events/keycodes/keyboard_codes.h" 66 #include "ui/events/keycodes/keyboard_codes.h"
70 #include "ui/gfx/screen.h" 67 #include "ui/gfx/screen.h"
71 #include "ui/message_center/message_center.h"
72 #include "ui/message_center/notification.h"
73 #include "ui/message_center/notifier_settings.h"
74 #include "ui/views/controls/webview/webview.h" 68 #include "ui/views/controls/webview/webview.h"
75 69
76 #if defined(OS_CHROMEOS) 70 #if defined(OS_CHROMEOS)
77 #include "ash/system/chromeos/keyboard_brightness_controller.h" 71 #include "ash/system/chromeos/keyboard_brightness_controller.h"
78 #include "base/sys_info.h" 72 #include "base/sys_info.h"
79 #include "ui/base/ime/chromeos/ime_keyboard.h" 73 #include "ui/base/ime/chromeos/ime_keyboard.h"
80 #include "ui/base/ime/chromeos/input_method_manager.h" 74 #include "ui/base/ime/chromeos/input_method_manager.h"
81 #endif // defined(OS_CHROMEOS) 75 #endif // defined(OS_CHROMEOS)
82 76
83 namespace ash { 77 namespace ash {
84 namespace { 78 namespace {
85 79
86 using base::UserMetricsAction; 80 using base::UserMetricsAction;
87 81
88 inline ui::Accelerator CreateAccelerator(ui::KeyboardCode keycode,
89 int modifiers,
90 bool trigger_on_press) {
91 ui::Accelerator accelerator(keycode, modifiers);
92 accelerator.set_type(trigger_on_press ? ui::ET_KEY_PRESSED
93 : ui::ET_KEY_RELEASED);
94 return accelerator;
95 }
96
97 void ShowDeprecatedAcceleratorNotification(int message_id) {
98 const base::string16 message = l10n_util::GetStringUTF16(message_id);
99 scoped_ptr<message_center::Notification> notification(
100 new message_center::Notification(
101 message_center::NOTIFICATION_TYPE_SIMPLE,
102 kDeprecatedAcceleratorNotificationId, base::string16(), message,
103 gfx::Image(), base::string16(),
104 message_center::NotifierId(
105 message_center::NotifierId::SYSTEM_COMPONENT,
106 system_notifier::kNotifierDeprecatedAccelerator),
107 message_center::RichNotificationData(), nullptr));
108 message_center::MessageCenter::Get()->AddNotification(notification.Pass());
109 }
110
111 void RecordUmaHistogram(const char* histogram_name,
112 DeprecatedAcceleratorUsage sample) {
113 auto histogram = base::LinearHistogram::FactoryGet(
114 histogram_name, 1, DEPRECATED_USAGE_COUNT, DEPRECATED_USAGE_COUNT + 1,
115 base::HistogramBase::kUmaTargetedHistogramFlag);
116 histogram->Add(sample);
117 }
118
119 bool CanHandleAccessibleFocusCycle() { 82 bool CanHandleAccessibleFocusCycle() {
120 if (!Shell::GetInstance()->accessibility_delegate()-> 83 if (!Shell::GetInstance()->accessibility_delegate()->
121 IsSpokenFeedbackEnabled()) { 84 IsSpokenFeedbackEnabled()) {
122 return false; 85 return false;
123 } 86 }
124 aura::Window* active_window = ash::wm::GetActiveWindow(); 87 aura::Window* active_window = ash::wm::GetActiveWindow();
125 if (!active_window) 88 if (!active_window)
126 return false; 89 return false;
127 views::Widget* widget = 90 views::Widget* widget =
128 views::Widget::GetWidgetForNativeWindow(active_window); 91 views::Widget::GetWidgetForNativeWindow(active_window);
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 ime_control_delegate_->RemapAccelerator(accelerator) : accelerator; 751 ime_control_delegate_->RemapAccelerator(accelerator) : accelerator;
789 752
790 std::map<ui::Accelerator, AcceleratorAction>::const_iterator iter = 753 std::map<ui::Accelerator, AcceleratorAction>::const_iterator iter =
791 accelerators_.find(remapped_accelerator); 754 accelerators_.find(remapped_accelerator);
792 if (iter == accelerators_.end()) 755 if (iter == accelerators_.end())
793 return false; // not an accelerator. 756 return false; // not an accelerator.
794 757
795 return reserved_actions_.find(iter->second) != reserved_actions_.end(); 758 return reserved_actions_.find(iter->second) != reserved_actions_.end();
796 } 759 }
797 760
798 bool AcceleratorController::IsDeprecated(
799 const ui::Accelerator& accelerator) const {
800 return deprecated_accelerators_.count(accelerator) != 0;
801 }
802
803 bool AcceleratorController::PerformActionIfEnabled(AcceleratorAction action) { 761 bool AcceleratorController::PerformActionIfEnabled(AcceleratorAction action) {
804 if (CanPerformAction(action, ui::Accelerator())) { 762 if (CanPerformAction(action, ui::Accelerator())) {
805 PerformAction(action, ui::Accelerator()); 763 PerformAction(action, ui::Accelerator());
806 return true; 764 return true;
807 } 765 }
808 return false; 766 return false;
809 } 767 }
810 768
811 AcceleratorController::AcceleratorProcessingRestriction 769 AcceleratorController::AcceleratorProcessingRestriction
812 AcceleratorController::GetCurrentAcceleratorRestriction() { 770 AcceleratorController::GetCurrentAcceleratorRestriction() {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 reserved_actions_.insert(kReservedActions[i]); 826 reserved_actions_.insert(kReservedActions[i]);
869 for (size_t i = 0; i < kNonrepeatableActionsLength; ++i) 827 for (size_t i = 0; i < kNonrepeatableActionsLength; ++i)
870 nonrepeatable_actions_.insert(kNonrepeatableActions[i]); 828 nonrepeatable_actions_.insert(kNonrepeatableActions[i]);
871 for (size_t i = 0; i < kActionsAllowedInAppModeLength; ++i) 829 for (size_t i = 0; i < kActionsAllowedInAppModeLength; ++i)
872 actions_allowed_in_app_mode_.insert(kActionsAllowedInAppMode[i]); 830 actions_allowed_in_app_mode_.insert(kActionsAllowedInAppMode[i]);
873 for (size_t i = 0; i < kActionsNeedingWindowLength; ++i) 831 for (size_t i = 0; i < kActionsNeedingWindowLength; ++i)
874 actions_needing_window_.insert(kActionsNeedingWindow[i]); 832 actions_needing_window_.insert(kActionsNeedingWindow[i]);
875 833
876 RegisterAccelerators(kAcceleratorData, kAcceleratorDataLength); 834 RegisterAccelerators(kAcceleratorData, kAcceleratorDataLength);
877 835
878 #if defined(OS_CHROMEOS)
879 RegisterDeprecatedAccelerators(kDeprecatedAccelerators,
880 kDeprecatedAcceleratorsLength);
881 #endif // defined(OS_CHROMEOS)
882
883 if (debug::DebugAcceleratorsEnabled()) { 836 if (debug::DebugAcceleratorsEnabled()) {
884 RegisterAccelerators(kDebugAcceleratorData, kDebugAcceleratorDataLength); 837 RegisterAccelerators(kDebugAcceleratorData, kDebugAcceleratorDataLength);
885 // All debug accelerators are reserved. 838 // All debug accelerators are reserved.
886 for (size_t i = 0; i < kDebugAcceleratorDataLength; ++i) 839 for (size_t i = 0; i < kDebugAcceleratorDataLength; ++i)
887 reserved_actions_.insert(kDebugAcceleratorData[i].action); 840 reserved_actions_.insert(kDebugAcceleratorData[i].action);
888 } 841 }
889 842
890 #if defined(OS_CHROMEOS) 843 #if defined(OS_CHROMEOS)
891 keyboard_brightness_control_delegate_.reset( 844 keyboard_brightness_control_delegate_.reset(
892 new KeyboardBrightnessController()); 845 new KeyboardBrightnessController());
893 #endif 846 #endif
894 } 847 }
895 848
896 void AcceleratorController::RegisterAccelerators( 849 void AcceleratorController::RegisterAccelerators(
897 const AcceleratorData accelerators[], 850 const AcceleratorData accelerators[],
898 size_t accelerators_length) { 851 size_t accelerators_length) {
899 for (size_t i = 0; i < accelerators_length; ++i) { 852 for (size_t i = 0; i < accelerators_length; ++i) {
900 ui::Accelerator accelerator = 853 ui::Accelerator accelerator(accelerators[i].keycode,
901 CreateAccelerator(accelerators[i].keycode, accelerators[i].modifiers, 854 accelerators[i].modifiers);
902 accelerators[i].trigger_on_press); 855 accelerator.set_type(accelerators[i].trigger_on_press ?
856 ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED);
903 Register(accelerator, this); 857 Register(accelerator, this);
904 accelerators_.insert( 858 accelerators_.insert(
905 std::make_pair(accelerator, accelerators[i].action)); 859 std::make_pair(accelerator, accelerators[i].action));
906 } 860 }
907 } 861 }
908 862
909 void AcceleratorController::RegisterDeprecatedAccelerators(
910 const DeprecatedAcceleratorData deprecated_accelerators[],
911 size_t length) {
912 for (size_t i = 0; i < length; ++i) {
913 const DeprecatedAcceleratorData* data = &deprecated_accelerators[i];
914 const AcceleratorAction action = data->deprecated_accelerator.action;
915 const ui::Accelerator deprecated_accelerator =
916 CreateAccelerator(data->deprecated_accelerator.keycode,
917 data->deprecated_accelerator.modifiers,
918 data->deprecated_accelerator.trigger_on_press);
919
920 Register(deprecated_accelerator, this);
921 actions_with_deprecations_[action] = data;
922 accelerators_[deprecated_accelerator] = action;
923 deprecated_accelerators_.insert(deprecated_accelerator);
924 }
925 }
926
927 bool AcceleratorController::CanPerformAction( 863 bool AcceleratorController::CanPerformAction(
928 AcceleratorAction action, 864 AcceleratorAction action,
929 const ui::Accelerator& accelerator) { 865 const ui::Accelerator& accelerator) {
930 if (nonrepeatable_actions_.find(action) != nonrepeatable_actions_.end() && 866 if (nonrepeatable_actions_.find(action) != nonrepeatable_actions_.end() &&
931 accelerator.IsRepeat()) { 867 accelerator.IsRepeat()) {
932 return false; 868 return false;
933 } 869 }
934 870
935 // Handling the deprecated accelerators.
936 auto itr = actions_with_deprecations_.find(action);
937 if (itr != actions_with_deprecations_.end()) {
938 const DeprecatedAcceleratorData* data = itr->second;
939 if (deprecated_accelerators_.count(accelerator)) {
940 // This accelerator has been deprecated and should be treated according
941 // to its |DeprecatedAcceleratorData|.
942
943 // Record UMA stats.
944 RecordUmaHistogram(data->uma_histogram_name, DEPRECATED_USED);
945
946 // We always display the notification as long as this entry exists.
947 ShowDeprecatedAcceleratorNotification(data->notification_message_id);
948
949 if (!data->deprecated_enabled)
950 return false;
951 } else {
952 // This is a new accelerator replacing the old deprecated one.
953 // Record UMA stats and proceed normally.
954 RecordUmaHistogram(data->uma_histogram_name, NEW_USED);
955 }
956 }
957
958 AcceleratorProcessingRestriction restriction = 871 AcceleratorProcessingRestriction restriction =
959 GetAcceleratorProcessingRestriction(action); 872 GetAcceleratorProcessingRestriction(action);
960 if (restriction != RESTRICTION_NONE) 873 if (restriction != RESTRICTION_NONE)
961 return restriction == RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION; 874 return restriction == RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION;
962 875
963 const ui::Accelerator& previous_accelerator = 876 const ui::Accelerator& previous_accelerator =
964 accelerator_history_->previous_accelerator(); 877 accelerator_history_->previous_accelerator();
965 878
966 // True should be returned if running |action| does something. Otherwise, 879 // True should be returned if running |action| does something. Otherwise,
967 // false should be returned to give the web contents a chance at handling the 880 // false should be returned to give the web contents a chance at handling the
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
1415 } 1328 }
1416 1329
1417 void AcceleratorController::SetKeyboardBrightnessControlDelegate( 1330 void AcceleratorController::SetKeyboardBrightnessControlDelegate(
1418 scoped_ptr<KeyboardBrightnessControlDelegate> 1331 scoped_ptr<KeyboardBrightnessControlDelegate>
1419 keyboard_brightness_control_delegate) { 1332 keyboard_brightness_control_delegate) {
1420 keyboard_brightness_control_delegate_ = 1333 keyboard_brightness_control_delegate_ =
1421 keyboard_brightness_control_delegate.Pass(); 1334 keyboard_brightness_control_delegate.Pass();
1422 } 1335 }
1423 1336
1424 } // namespace ash 1337 } // 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