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

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: moving IsDeprecated() to c/b/ui/ash 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 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::kNotifierAcceleratorController),
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
82 bool CanHandleAccessibleFocusCycle() { 119 bool CanHandleAccessibleFocusCycle() {
83 if (!Shell::GetInstance()->accessibility_delegate()-> 120 if (!Shell::GetInstance()->accessibility_delegate()->
84 IsSpokenFeedbackEnabled()) { 121 IsSpokenFeedbackEnabled()) {
85 return false; 122 return false;
86 } 123 }
87 aura::Window* active_window = ash::wm::GetActiveWindow(); 124 aura::Window* active_window = ash::wm::GetActiveWindow();
88 if (!active_window) 125 if (!active_window)
89 return false; 126 return false;
90 views::Widget* widget = 127 views::Widget* widget =
91 views::Widget::GetWidgetForNativeWindow(active_window); 128 views::Widget::GetWidgetForNativeWindow(active_window);
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 ime_control_delegate_->RemapAccelerator(accelerator) : accelerator; 788 ime_control_delegate_->RemapAccelerator(accelerator) : accelerator;
752 789
753 std::map<ui::Accelerator, AcceleratorAction>::const_iterator iter = 790 std::map<ui::Accelerator, AcceleratorAction>::const_iterator iter =
754 accelerators_.find(remapped_accelerator); 791 accelerators_.find(remapped_accelerator);
755 if (iter == accelerators_.end()) 792 if (iter == accelerators_.end())
756 return false; // not an accelerator. 793 return false; // not an accelerator.
757 794
758 return reserved_actions_.find(iter->second) != reserved_actions_.end(); 795 return reserved_actions_.find(iter->second) != reserved_actions_.end();
759 } 796 }
760 797
798 bool AcceleratorController::IsDeprecated(
799 const ui::Accelerator& accelerator) const {
800 return deprecated_accelerators_.count(accelerator) != 0;
801 }
802
761 bool AcceleratorController::PerformActionIfEnabled(AcceleratorAction action) { 803 bool AcceleratorController::PerformActionIfEnabled(AcceleratorAction action) {
762 if (CanPerformAction(action, ui::Accelerator())) { 804 if (CanPerformAction(action, ui::Accelerator())) {
763 PerformAction(action, ui::Accelerator()); 805 PerformAction(action, ui::Accelerator());
764 return true; 806 return true;
765 } 807 }
766 return false; 808 return false;
767 } 809 }
768 810
769 AcceleratorController::AcceleratorProcessingRestriction 811 AcceleratorController::AcceleratorProcessingRestriction
770 AcceleratorController::GetCurrentAcceleratorRestriction() { 812 AcceleratorController::GetCurrentAcceleratorRestriction() {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 reserved_actions_.insert(kReservedActions[i]); 868 reserved_actions_.insert(kReservedActions[i]);
827 for (size_t i = 0; i < kNonrepeatableActionsLength; ++i) 869 for (size_t i = 0; i < kNonrepeatableActionsLength; ++i)
828 nonrepeatable_actions_.insert(kNonrepeatableActions[i]); 870 nonrepeatable_actions_.insert(kNonrepeatableActions[i]);
829 for (size_t i = 0; i < kActionsAllowedInAppModeLength; ++i) 871 for (size_t i = 0; i < kActionsAllowedInAppModeLength; ++i)
830 actions_allowed_in_app_mode_.insert(kActionsAllowedInAppMode[i]); 872 actions_allowed_in_app_mode_.insert(kActionsAllowedInAppMode[i]);
831 for (size_t i = 0; i < kActionsNeedingWindowLength; ++i) 873 for (size_t i = 0; i < kActionsNeedingWindowLength; ++i)
832 actions_needing_window_.insert(kActionsNeedingWindow[i]); 874 actions_needing_window_.insert(kActionsNeedingWindow[i]);
833 875
834 RegisterAccelerators(kAcceleratorData, kAcceleratorDataLength); 876 RegisterAccelerators(kAcceleratorData, kAcceleratorDataLength);
835 877
878 RegisterDeprecatedAccelerators(kDeprecatedAccelerators,
879 kDeprecatedAcceleratorsLength);
880
836 if (debug::DebugAcceleratorsEnabled()) { 881 if (debug::DebugAcceleratorsEnabled()) {
837 RegisterAccelerators(kDebugAcceleratorData, kDebugAcceleratorDataLength); 882 RegisterAccelerators(kDebugAcceleratorData, kDebugAcceleratorDataLength);
838 // All debug accelerators are reserved. 883 // All debug accelerators are reserved.
839 for (size_t i = 0; i < kDebugAcceleratorDataLength; ++i) 884 for (size_t i = 0; i < kDebugAcceleratorDataLength; ++i)
840 reserved_actions_.insert(kDebugAcceleratorData[i].action); 885 reserved_actions_.insert(kDebugAcceleratorData[i].action);
841 } 886 }
842 887
843 #if defined(OS_CHROMEOS) 888 #if defined(OS_CHROMEOS)
844 keyboard_brightness_control_delegate_.reset( 889 keyboard_brightness_control_delegate_.reset(
845 new KeyboardBrightnessController()); 890 new KeyboardBrightnessController());
846 #endif 891 #endif
847 } 892 }
848 893
849 void AcceleratorController::RegisterAccelerators( 894 void AcceleratorController::RegisterAccelerators(
850 const AcceleratorData accelerators[], 895 const AcceleratorData accelerators[],
851 size_t accelerators_length) { 896 size_t accelerators_length) {
852 for (size_t i = 0; i < accelerators_length; ++i) { 897 for (size_t i = 0; i < accelerators_length; ++i) {
853 ui::Accelerator accelerator(accelerators[i].keycode, 898 ui::Accelerator accelerator =
854 accelerators[i].modifiers); 899 CreateAccelerator(accelerators[i].keycode, accelerators[i].modifiers,
855 accelerator.set_type(accelerators[i].trigger_on_press ? 900 accelerators[i].trigger_on_press);
856 ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED);
857 Register(accelerator, this); 901 Register(accelerator, this);
858 accelerators_.insert( 902 accelerators_.insert(
859 std::make_pair(accelerator, accelerators[i].action)); 903 std::make_pair(accelerator, accelerators[i].action));
860 } 904 }
861 } 905 }
862 906
907 void AcceleratorController::RegisterDeprecatedAccelerators(
908 const DeprecatedAcceleratorData deprecated_accelerators[],
909 size_t length) {
910 for (size_t i = 0; i < length; ++i) {
911 const DeprecatedAcceleratorData* data = &deprecated_accelerators[i];
912 const AcceleratorAction action = data->deprecated_accelerator.action;
913 const ui::Accelerator deprecated_accelerator =
914 CreateAccelerator(data->deprecated_accelerator.keycode,
915 data->deprecated_accelerator.modifiers,
916 data->deprecated_accelerator.trigger_on_press);
917
918 Register(deprecated_accelerator, this);
919 actions_with_deprecations_[action] = data;
920 accelerators_[deprecated_accelerator] = action;
921 deprecated_accelerators_.insert(deprecated_accelerator);
922 }
923 }
924
863 bool AcceleratorController::CanPerformAction( 925 bool AcceleratorController::CanPerformAction(
864 AcceleratorAction action, 926 AcceleratorAction action,
865 const ui::Accelerator& accelerator) { 927 const ui::Accelerator& accelerator) {
866 if (nonrepeatable_actions_.find(action) != nonrepeatable_actions_.end() && 928 if (nonrepeatable_actions_.find(action) != nonrepeatable_actions_.end() &&
867 accelerator.IsRepeat()) { 929 accelerator.IsRepeat()) {
868 return false; 930 return false;
869 } 931 }
870 932
933 // Handling the deprecated accelerators.
934 auto itr = actions_with_deprecations_.find(action);
935 if (itr != actions_with_deprecations_.end()) {
936 const DeprecatedAcceleratorData* data = itr->second;
937 if (deprecated_accelerators_.count(accelerator)) {
938 // This accelerator has been deprecated and should be treated according
939 // to its |DeprecatedAcceleratorData|.
940
941 // Record UMA stats.
942 RecordUmaHistogram(data->uma_histogram_name, DEPRECATED_USED);
943
944 // We always display the notification as long as this entry exists.
945 ShowDeprecatedAcceleratorNotification(data->notification_message_id);
946
947 if (!data->deprecated_enabled)
948 return false;
949 } else {
950 // This is a new accelerator replacing the old deprecated one.
951 // Record UMA stats and proceed normally.
952 RecordUmaHistogram(data->uma_histogram_name, NEW_USED);
953 }
954 }
955
871 AcceleratorProcessingRestriction restriction = 956 AcceleratorProcessingRestriction restriction =
872 GetAcceleratorProcessingRestriction(action); 957 GetAcceleratorProcessingRestriction(action);
873 if (restriction != RESTRICTION_NONE) 958 if (restriction != RESTRICTION_NONE)
874 return restriction == RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION; 959 return restriction == RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION;
875 960
876 const ui::Accelerator& previous_accelerator = 961 const ui::Accelerator& previous_accelerator =
877 accelerator_history_->previous_accelerator(); 962 accelerator_history_->previous_accelerator();
878 963
879 // True should be returned if running |action| does something. Otherwise, 964 // 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 965 // 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 } 1413 }
1329 1414
1330 void AcceleratorController::SetKeyboardBrightnessControlDelegate( 1415 void AcceleratorController::SetKeyboardBrightnessControlDelegate(
1331 scoped_ptr<KeyboardBrightnessControlDelegate> 1416 scoped_ptr<KeyboardBrightnessControlDelegate>
1332 keyboard_brightness_control_delegate) { 1417 keyboard_brightness_control_delegate) {
1333 keyboard_brightness_control_delegate_ = 1418 keyboard_brightness_control_delegate_ =
1334 keyboard_brightness_control_delegate.Pass(); 1419 keyboard_brightness_control_delegate.Pass();
1335 } 1420 }
1336 1421
1337 } // namespace ash 1422 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698