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

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

Issue 1177773002: Deprecating high-conflict accelerators (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added deprecation for the Shift+Esc 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"
41 #include "ash/system/tray/system_tray.h" 42 #include "ash/system/tray/system_tray.h"
42 #include "ash/system/tray/system_tray_delegate.h" 43 #include "ash/system/tray/system_tray_delegate.h"
43 #include "ash/system/tray/system_tray_notifier.h" 44 #include "ash/system/tray/system_tray_notifier.h"
44 #include "ash/system/web_notification/web_notification_tray.h" 45 #include "ash/system/web_notification/web_notification_tray.h"
45 #include "ash/touch/touch_hud_debug.h" 46 #include "ash/touch/touch_hud_debug.h"
46 #include "ash/utility/partial_screenshot_controller.h" 47 #include "ash/utility/partial_screenshot_controller.h"
47 #include "ash/volume_control_delegate.h" 48 #include "ash/volume_control_delegate.h"
48 #include "ash/wm/maximize_mode/maximize_mode_controller.h" 49 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
49 #include "ash/wm/mru_window_tracker.h" 50 #include "ash/wm/mru_window_tracker.h"
50 #include "ash/wm/overview/window_selector_controller.h" 51 #include "ash/wm/overview/window_selector_controller.h"
51 #include "ash/wm/power_button_controller.h" 52 #include "ash/wm/power_button_controller.h"
52 #include "ash/wm/window_cycle_controller.h" 53 #include "ash/wm/window_cycle_controller.h"
53 #include "ash/wm/window_state.h" 54 #include "ash/wm/window_state.h"
54 #include "ash/wm/window_util.h" 55 #include "ash/wm/window_util.h"
55 #include "ash/wm/wm_event.h" 56 #include "ash/wm/wm_event.h"
56 #include "base/bind.h" 57 #include "base/bind.h"
57 #include "base/command_line.h" 58 #include "base/command_line.h"
59 #include "base/metrics/histogram_macros.h"
58 #include "base/metrics/user_metrics.h" 60 #include "base/metrics/user_metrics.h"
59 #include "ui/aura/env.h" 61 #include "ui/aura/env.h"
60 #include "ui/base/accelerators/accelerator.h" 62 #include "ui/base/accelerators/accelerator.h"
61 #include "ui/base/accelerators/accelerator_manager.h" 63 #include "ui/base/accelerators/accelerator_manager.h"
64 #include "ui/base/l10n/l10n_util.h"
62 #include "ui/compositor/layer.h" 65 #include "ui/compositor/layer.h"
63 #include "ui/compositor/layer_animation_sequence.h" 66 #include "ui/compositor/layer_animation_sequence.h"
64 #include "ui/compositor/layer_animator.h" 67 #include "ui/compositor/layer_animator.h"
65 #include "ui/events/event.h" 68 #include "ui/events/event.h"
66 #include "ui/events/keycodes/keyboard_codes.h" 69 #include "ui/events/keycodes/keyboard_codes.h"
67 #include "ui/gfx/screen.h" 70 #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"
68 #include "ui/views/controls/webview/webview.h" 74 #include "ui/views/controls/webview/webview.h"
69 75
70 #if defined(OS_CHROMEOS) 76 #if defined(OS_CHROMEOS)
71 #include "ash/system/chromeos/keyboard_brightness_controller.h" 77 #include "ash/system/chromeos/keyboard_brightness_controller.h"
72 #include "base/sys_info.h" 78 #include "base/sys_info.h"
73 #include "ui/base/ime/chromeos/ime_keyboard.h" 79 #include "ui/base/ime/chromeos/ime_keyboard.h"
74 #include "ui/base/ime/chromeos/input_method_manager.h" 80 #include "ui/base/ime/chromeos/input_method_manager.h"
75 #endif // defined(OS_CHROMEOS) 81 #endif // defined(OS_CHROMEOS)
76 82
77 namespace ash { 83 namespace ash {
78 namespace { 84 namespace {
79 85
80 using base::UserMetricsAction; 86 using base::UserMetricsAction;
81 87
88 const char kDeprecatedAcceleratorId[] = "deprecated_accelerator";
89
90 inline ui::Accelerator CreateAccelerator(ui::KeyboardCode keycode,
91 int modifiers,
92 bool trigger_on_press) {
93 ui::Accelerator accelerator(keycode, modifiers);
94 accelerator.set_type(trigger_on_press ? ui::ET_KEY_PRESSED
95 : ui::ET_KEY_RELEASED);
96 return accelerator;
97 }
98
99 void ShowDeprecatedAcceleratorNotification(int message_id) {
100 const base::string16 message = l10n_util::GetStringUTF16(message_id);
101 scoped_ptr<message_center::Notification> notification(
102 new message_center::Notification(
103 message_center::NOTIFICATION_TYPE_SIMPLE, kDeprecatedAcceleratorId,
104 base::string16(), message, gfx::Image(), base::string16(),
105 message_center::NotifierId(
106 message_center::NotifierId::SYSTEM_COMPONENT,
107 system_notifier::kNotifierAcceleratorController),
108 message_center::RichNotificationData(), nullptr));
109 message_center::MessageCenter::Get()->AddNotification(notification.Pass());
110 }
111
112 void RecordUmaHistogram(const char* histogram_name,
113 DeprecatedAcceleratorUsage sample) {
114 auto histogram = base::LinearHistogram::FactoryGet(
115 histogram_name, 1, DEPRECATED_USAGE_COUNT, DEPRECATED_USAGE_COUNT + 1,
116 base::HistogramBase::kUmaTargetedHistogramFlag);
117 histogram->Add(sample);
118 }
119
82 bool CanHandleAccessibleFocusCycle() { 120 bool CanHandleAccessibleFocusCycle() {
83 if (!Shell::GetInstance()->accessibility_delegate()-> 121 if (!Shell::GetInstance()->accessibility_delegate()->
84 IsSpokenFeedbackEnabled()) { 122 IsSpokenFeedbackEnabled()) {
85 return false; 123 return false;
86 } 124 }
87 aura::Window* active_window = ash::wm::GetActiveWindow(); 125 aura::Window* active_window = ash::wm::GetActiveWindow();
88 if (!active_window) 126 if (!active_window)
89 return false; 127 return false;
90 views::Widget* widget = 128 views::Widget* widget =
91 views::Widget::GetWidgetForNativeWindow(active_window); 129 views::Widget::GetWidgetForNativeWindow(active_window);
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 reserved_actions_.insert(kReservedActions[i]); 864 reserved_actions_.insert(kReservedActions[i]);
827 for (size_t i = 0; i < kNonrepeatableActionsLength; ++i) 865 for (size_t i = 0; i < kNonrepeatableActionsLength; ++i)
828 nonrepeatable_actions_.insert(kNonrepeatableActions[i]); 866 nonrepeatable_actions_.insert(kNonrepeatableActions[i]);
829 for (size_t i = 0; i < kActionsAllowedInAppModeLength; ++i) 867 for (size_t i = 0; i < kActionsAllowedInAppModeLength; ++i)
830 actions_allowed_in_app_mode_.insert(kActionsAllowedInAppMode[i]); 868 actions_allowed_in_app_mode_.insert(kActionsAllowedInAppMode[i]);
831 for (size_t i = 0; i < kActionsNeedingWindowLength; ++i) 869 for (size_t i = 0; i < kActionsNeedingWindowLength; ++i)
832 actions_needing_window_.insert(kActionsNeedingWindow[i]); 870 actions_needing_window_.insert(kActionsNeedingWindow[i]);
833 871
834 RegisterAccelerators(kAcceleratorData, kAcceleratorDataLength); 872 RegisterAccelerators(kAcceleratorData, kAcceleratorDataLength);
835 873
874 RegisterDeprecatedAccelerators(kDeprecatedAccelerators,
875 kDeprecatedAcceleratorsLength);
876
836 if (debug::DebugAcceleratorsEnabled()) { 877 if (debug::DebugAcceleratorsEnabled()) {
837 RegisterAccelerators(kDebugAcceleratorData, kDebugAcceleratorDataLength); 878 RegisterAccelerators(kDebugAcceleratorData, kDebugAcceleratorDataLength);
838 // All debug accelerators are reserved. 879 // All debug accelerators are reserved.
839 for (size_t i = 0; i < kDebugAcceleratorDataLength; ++i) 880 for (size_t i = 0; i < kDebugAcceleratorDataLength; ++i)
840 reserved_actions_.insert(kDebugAcceleratorData[i].action); 881 reserved_actions_.insert(kDebugAcceleratorData[i].action);
841 } 882 }
842 883
843 #if defined(OS_CHROMEOS) 884 #if defined(OS_CHROMEOS)
844 keyboard_brightness_control_delegate_.reset( 885 keyboard_brightness_control_delegate_.reset(
845 new KeyboardBrightnessController()); 886 new KeyboardBrightnessController());
846 #endif 887 #endif
847 } 888 }
848 889
849 void AcceleratorController::RegisterAccelerators( 890 void AcceleratorController::RegisterAccelerators(
850 const AcceleratorData accelerators[], 891 const AcceleratorData accelerators[],
851 size_t accelerators_length) { 892 size_t accelerators_length) {
852 for (size_t i = 0; i < accelerators_length; ++i) { 893 for (size_t i = 0; i < accelerators_length; ++i) {
853 ui::Accelerator accelerator(accelerators[i].keycode, 894 ui::Accelerator accelerator =
854 accelerators[i].modifiers); 895 CreateAccelerator(accelerators[i].keycode, accelerators[i].modifiers,
855 accelerator.set_type(accelerators[i].trigger_on_press ? 896 accelerators[i].trigger_on_press);
856 ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED);
857 Register(accelerator, this); 897 Register(accelerator, this);
858 accelerators_.insert( 898 accelerators_.insert(
859 std::make_pair(accelerator, accelerators[i].action)); 899 std::make_pair(accelerator, accelerators[i].action));
860 } 900 }
861 } 901 }
862 902
903 void AcceleratorController::RegisterDeprecatedAccelerators(
904 const DeprecatedAcceleratorData deprecated_accelerators[],
905 size_t length) {
906 for (size_t i = 0; i < length; ++i) {
907 const DeprecatedAcceleratorData* data = &deprecated_accelerators[i];
908 CHECK(data->deprecated_accelerator.action == data->new_accelerator.action);
909 const AcceleratorAction action = data->deprecated_accelerator.action;
910 const ui::Accelerator deprecated_accelerator =
911 CreateAccelerator(data->deprecated_accelerator.keycode,
912 data->deprecated_accelerator.modifiers,
913 data->deprecated_accelerator.trigger_on_press);
914 const ui::Accelerator new_accelerator = CreateAccelerator(
915 data->new_accelerator.keycode, data->new_accelerator.modifiers,
916 data->new_accelerator.trigger_on_press);
917
918 Register(deprecated_accelerator, this);
919 Register(new_accelerator, this);
920 actions_with_deprecations_[action] = data;
921 deprecated_accelerators_.insert(deprecated_accelerator);
922 accelerators_[deprecated_accelerator] = action;
923 accelerators_[new_accelerator] = action;
924 }
925 }
926
863 bool AcceleratorController::CanPerformAction( 927 bool AcceleratorController::CanPerformAction(
864 AcceleratorAction action, 928 AcceleratorAction action,
865 const ui::Accelerator& accelerator) { 929 const ui::Accelerator& accelerator) {
866 if (nonrepeatable_actions_.find(action) != nonrepeatable_actions_.end() && 930 if (nonrepeatable_actions_.find(action) != nonrepeatable_actions_.end() &&
867 accelerator.IsRepeat()) { 931 accelerator.IsRepeat()) {
868 return false; 932 return false;
869 } 933 }
870 934
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 if (data->should_show_notification)
947 ShowDeprecatedAcceleratorNotification(data->notification_message_id);
948
949 if (!data->deprecated_enabled)
950 return false;
951 } else {
952 // Record UMA stats and proceed normally.
953 RecordUmaHistogram(data->uma_histogram_name, NEW_USED);
954 }
955 }
956
871 AcceleratorProcessingRestriction restriction = 957 AcceleratorProcessingRestriction restriction =
872 GetAcceleratorProcessingRestriction(action); 958 GetAcceleratorProcessingRestriction(action);
873 if (restriction != RESTRICTION_NONE) 959 if (restriction != RESTRICTION_NONE)
874 return restriction == RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION; 960 return restriction == RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION;
875 961
876 const ui::Accelerator& previous_accelerator = 962 const ui::Accelerator& previous_accelerator =
877 accelerator_history_->previous_accelerator(); 963 accelerator_history_->previous_accelerator();
878 964
879 // True should be returned if running |action| does something. Otherwise, 965 // True should be returned if running |action| does something. Otherwise,
880 // false should be returned to give the web contents a chance at handling the 966 // 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
1328 } 1414 }
1329 1415
1330 void AcceleratorController::SetKeyboardBrightnessControlDelegate( 1416 void AcceleratorController::SetKeyboardBrightnessControlDelegate(
1331 scoped_ptr<KeyboardBrightnessControlDelegate> 1417 scoped_ptr<KeyboardBrightnessControlDelegate>
1332 keyboard_brightness_control_delegate) { 1418 keyboard_brightness_control_delegate) {
1333 keyboard_brightness_control_delegate_ = 1419 keyboard_brightness_control_delegate_ =
1334 keyboard_brightness_control_delegate.Pass(); 1420 keyboard_brightness_control_delegate.Pass();
1335 } 1421 }
1336 1422
1337 } // namespace ash 1423 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698