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

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: oshima's comments Created 5 years, 3 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 18 matching lines...) Expand all
29 #include "ash/shelf/shelf.h" 29 #include "ash/shelf/shelf.h"
30 #include "ash/shelf/shelf_delegate.h" 30 #include "ash/shelf/shelf_delegate.h"
31 #include "ash/shelf/shelf_model.h" 31 #include "ash/shelf/shelf_model.h"
32 #include "ash/shelf/shelf_widget.h" 32 #include "ash/shelf/shelf_widget.h"
33 #include "ash/shell.h" 33 #include "ash/shell.h"
34 #include "ash/shell_delegate.h" 34 #include "ash/shell_delegate.h"
35 #include "ash/shell_window_ids.h" 35 #include "ash/shell_window_ids.h"
36 #include "ash/system/brightness_control_delegate.h" 36 #include "ash/system/brightness_control_delegate.h"
37 #include "ash/system/keyboard_brightness/keyboard_brightness_control_delegate.h" 37 #include "ash/system/keyboard_brightness/keyboard_brightness_control_delegate.h"
38 #include "ash/system/status_area_widget.h" 38 #include "ash/system/status_area_widget.h"
39 #include "ash/system/system_notifier.h"
39 #include "ash/system/tray/system_tray.h" 40 #include "ash/system/tray/system_tray.h"
40 #include "ash/system/tray/system_tray_delegate.h" 41 #include "ash/system/tray/system_tray_delegate.h"
41 #include "ash/system/tray/system_tray_notifier.h" 42 #include "ash/system/tray/system_tray_notifier.h"
42 #include "ash/system/web_notification/web_notification_tray.h" 43 #include "ash/system/web_notification/web_notification_tray.h"
43 #include "ash/touch/touch_hud_debug.h" 44 #include "ash/touch/touch_hud_debug.h"
44 #include "ash/utility/partial_screenshot_controller.h" 45 #include "ash/utility/partial_screenshot_controller.h"
45 #include "ash/volume_control_delegate.h" 46 #include "ash/volume_control_delegate.h"
46 #include "ash/wm/maximize_mode/maximize_mode_controller.h" 47 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
47 #include "ash/wm/mru_window_tracker.h" 48 #include "ash/wm/mru_window_tracker.h"
48 #include "ash/wm/overview/window_selector_controller.h" 49 #include "ash/wm/overview/window_selector_controller.h"
49 #include "ash/wm/power_button_controller.h" 50 #include "ash/wm/power_button_controller.h"
50 #include "ash/wm/window_cycle_controller.h" 51 #include "ash/wm/window_cycle_controller.h"
51 #include "ash/wm/window_state.h" 52 #include "ash/wm/window_state.h"
52 #include "ash/wm/window_util.h" 53 #include "ash/wm/window_util.h"
53 #include "ash/wm/wm_event.h" 54 #include "ash/wm/wm_event.h"
54 #include "base/bind.h" 55 #include "base/bind.h"
55 #include "base/command_line.h" 56 #include "base/command_line.h"
57 #include "base/metrics/histogram_macros.h"
56 #include "base/metrics/user_metrics.h" 58 #include "base/metrics/user_metrics.h"
57 #include "ui/aura/env.h" 59 #include "ui/aura/env.h"
58 #include "ui/base/accelerators/accelerator.h" 60 #include "ui/base/accelerators/accelerator.h"
59 #include "ui/base/accelerators/accelerator_manager.h" 61 #include "ui/base/accelerators/accelerator_manager.h"
62 #include "ui/base/l10n/l10n_util.h"
63 #include "ui/base/resource/resource_bundle.h"
60 #include "ui/compositor/layer.h" 64 #include "ui/compositor/layer.h"
61 #include "ui/compositor/layer_animation_sequence.h" 65 #include "ui/compositor/layer_animation_sequence.h"
62 #include "ui/compositor/layer_animator.h" 66 #include "ui/compositor/layer_animator.h"
63 #include "ui/events/event.h" 67 #include "ui/events/event.h"
64 #include "ui/events/keycodes/keyboard_codes.h" 68 #include "ui/events/keycodes/keyboard_codes.h"
65 #include "ui/gfx/screen.h" 69 #include "ui/gfx/screen.h"
70 #include "ui/message_center/message_center.h"
71 #include "ui/message_center/notification.h"
72 #include "ui/message_center/notifier_settings.h"
66 #include "ui/views/controls/webview/webview.h" 73 #include "ui/views/controls/webview/webview.h"
67 74
68 #if defined(OS_CHROMEOS) 75 #if defined(OS_CHROMEOS)
69 #include "ash/system/chromeos/keyboard_brightness_controller.h" 76 #include "ash/system/chromeos/keyboard_brightness_controller.h"
70 #include "base/sys_info.h" 77 #include "base/sys_info.h"
71 #include "ui/base/ime/chromeos/ime_keyboard.h" 78 #include "ui/base/ime/chromeos/ime_keyboard.h"
72 #include "ui/base/ime/chromeos/input_method_manager.h" 79 #include "ui/base/ime/chromeos/input_method_manager.h"
73 #endif // defined(OS_CHROMEOS) 80 #endif // defined(OS_CHROMEOS)
74 81
75 namespace ash { 82 namespace ash {
76 namespace { 83 namespace {
77 84
78 using base::UserMetricsAction; 85 using base::UserMetricsAction;
79 86
87 // The notification delegate that will be used to open the keyboard shortcut
88 // help page when the notification is clicked.
89 class DeprecatedAcceleratorNotificationDelegate
90 : public message_center::NotificationDelegate {
91 public:
92 DeprecatedAcceleratorNotificationDelegate() {}
93
94 // message_center::NotificationDelegate:
95 bool HasClickedListener() override { return true; }
96
97 void Click() override {
98 Shell::GetInstance()->delegate()->OpenKeyboardShortcutHelpPage();
99 }
100
101 private:
102 // Private destructor since NotificationDelegate is ref-counted.
103 ~DeprecatedAcceleratorNotificationDelegate() override {}
104
105 DISALLOW_COPY_AND_ASSIGN(DeprecatedAcceleratorNotificationDelegate);
106 };
107
108 ui::Accelerator CreateAccelerator(ui::KeyboardCode keycode,
109 int modifiers,
110 bool trigger_on_press) {
111 ui::Accelerator accelerator(keycode, modifiers);
112 accelerator.set_type(trigger_on_press ? ui::ET_KEY_PRESSED
113 : ui::ET_KEY_RELEASED);
114 return accelerator;
115 }
116
117 void ShowDeprecatedAcceleratorNotification(const char* const notification_id,
118 int message_id) {
119 const base::string16 message = l10n_util::GetStringUTF16(message_id);
120 scoped_ptr<message_center::Notification> notification(
121 new message_center::Notification(
122 message_center::NOTIFICATION_TYPE_SIMPLE, notification_id,
123 base::string16(), message,
124 Shell::GetInstance()->delegate()->GetDeprecatedAcceleratorImage(),
125 base::string16(), GURL(),
126 message_center::NotifierId(
127 message_center::NotifierId::SYSTEM_COMPONENT,
128 system_notifier::kNotifierDeprecatedAccelerator),
129 message_center::RichNotificationData(),
130 new DeprecatedAcceleratorNotificationDelegate));
131 message_center::MessageCenter::Get()->AddNotification(notification.Pass());
132 }
133
134 void RecordUmaHistogram(const char* histogram_name,
135 DeprecatedAcceleratorUsage sample) {
136 auto histogram = base::LinearHistogram::FactoryGet(
137 histogram_name, 1, DEPRECATED_USAGE_COUNT, DEPRECATED_USAGE_COUNT + 1,
138 base::HistogramBase::kUmaTargetedHistogramFlag);
139 histogram->Add(sample);
140 }
141
80 void HandleCycleBackwardMRU(const ui::Accelerator& accelerator) { 142 void HandleCycleBackwardMRU(const ui::Accelerator& accelerator) {
81 if (accelerator.key_code() == ui::VKEY_TAB) 143 if (accelerator.key_code() == ui::VKEY_TAB)
82 base::RecordAction(base::UserMetricsAction("Accel_PrevWindow_Tab")); 144 base::RecordAction(base::UserMetricsAction("Accel_PrevWindow_Tab"));
83 145
84 Shell::GetInstance()->window_cycle_controller()->HandleCycleWindow( 146 Shell::GetInstance()->window_cycle_controller()->HandleCycleWindow(
85 WindowCycleController::BACKWARD); 147 WindowCycleController::BACKWARD);
86 } 148 }
87 149
88 void HandleCycleForwardMRU(const ui::Accelerator& accelerator) { 150 void HandleCycleForwardMRU(const ui::Accelerator& accelerator) {
89 if (accelerator.key_code() == ui::VKEY_TAB) 151 if (accelerator.key_code() == ui::VKEY_TAB)
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 ime_control_delegate_->RemapAccelerator(accelerator) : accelerator; 747 ime_control_delegate_->RemapAccelerator(accelerator) : accelerator;
686 748
687 std::map<ui::Accelerator, AcceleratorAction>::const_iterator iter = 749 std::map<ui::Accelerator, AcceleratorAction>::const_iterator iter =
688 accelerators_.find(remapped_accelerator); 750 accelerators_.find(remapped_accelerator);
689 if (iter == accelerators_.end()) 751 if (iter == accelerators_.end())
690 return false; // not an accelerator. 752 return false; // not an accelerator.
691 753
692 return reserved_actions_.find(iter->second) != reserved_actions_.end(); 754 return reserved_actions_.find(iter->second) != reserved_actions_.end();
693 } 755 }
694 756
757 bool AcceleratorController::IsDeprecated(
758 const ui::Accelerator& accelerator) const {
759 return deprecated_accelerators_.count(accelerator) != 0;
760 }
761
695 bool AcceleratorController::PerformActionIfEnabled(AcceleratorAction action) { 762 bool AcceleratorController::PerformActionIfEnabled(AcceleratorAction action) {
696 if (CanPerformAction(action, ui::Accelerator())) { 763 if (CanPerformAction(action, ui::Accelerator())) {
697 PerformAction(action, ui::Accelerator()); 764 PerformAction(action, ui::Accelerator());
698 return true; 765 return true;
699 } 766 }
700 return false; 767 return false;
701 } 768 }
702 769
703 AcceleratorController::AcceleratorProcessingRestriction 770 AcceleratorController::AcceleratorProcessingRestriction
704 AcceleratorController::GetCurrentAcceleratorRestriction() { 771 AcceleratorController::GetCurrentAcceleratorRestriction() {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 reserved_actions_.insert(kReservedActions[i]); 827 reserved_actions_.insert(kReservedActions[i]);
761 for (size_t i = 0; i < kNonrepeatableActionsLength; ++i) 828 for (size_t i = 0; i < kNonrepeatableActionsLength; ++i)
762 nonrepeatable_actions_.insert(kNonrepeatableActions[i]); 829 nonrepeatable_actions_.insert(kNonrepeatableActions[i]);
763 for (size_t i = 0; i < kActionsAllowedInAppModeLength; ++i) 830 for (size_t i = 0; i < kActionsAllowedInAppModeLength; ++i)
764 actions_allowed_in_app_mode_.insert(kActionsAllowedInAppMode[i]); 831 actions_allowed_in_app_mode_.insert(kActionsAllowedInAppMode[i]);
765 for (size_t i = 0; i < kActionsNeedingWindowLength; ++i) 832 for (size_t i = 0; i < kActionsNeedingWindowLength; ++i)
766 actions_needing_window_.insert(kActionsNeedingWindow[i]); 833 actions_needing_window_.insert(kActionsNeedingWindow[i]);
767 834
768 RegisterAccelerators(kAcceleratorData, kAcceleratorDataLength); 835 RegisterAccelerators(kAcceleratorData, kAcceleratorDataLength);
769 836
837 RegisterDeprecatedAccelerators();
838
770 if (debug::DebugAcceleratorsEnabled()) { 839 if (debug::DebugAcceleratorsEnabled()) {
771 RegisterAccelerators(kDebugAcceleratorData, kDebugAcceleratorDataLength); 840 RegisterAccelerators(kDebugAcceleratorData, kDebugAcceleratorDataLength);
772 // All debug accelerators are reserved. 841 // All debug accelerators are reserved.
773 for (size_t i = 0; i < kDebugAcceleratorDataLength; ++i) 842 for (size_t i = 0; i < kDebugAcceleratorDataLength; ++i)
774 reserved_actions_.insert(kDebugAcceleratorData[i].action); 843 reserved_actions_.insert(kDebugAcceleratorData[i].action);
775 } 844 }
776 845
777 #if defined(OS_CHROMEOS) 846 #if defined(OS_CHROMEOS)
778 keyboard_brightness_control_delegate_.reset( 847 keyboard_brightness_control_delegate_.reset(
779 new KeyboardBrightnessController()); 848 new KeyboardBrightnessController());
780 #endif 849 #endif
781 } 850 }
782 851
783 void AcceleratorController::RegisterAccelerators( 852 void AcceleratorController::RegisterAccelerators(
784 const AcceleratorData accelerators[], 853 const AcceleratorData accelerators[],
785 size_t accelerators_length) { 854 size_t accelerators_length) {
786 for (size_t i = 0; i < accelerators_length; ++i) { 855 for (size_t i = 0; i < accelerators_length; ++i) {
787 ui::Accelerator accelerator(accelerators[i].keycode, 856 ui::Accelerator accelerator =
788 accelerators[i].modifiers); 857 CreateAccelerator(accelerators[i].keycode, accelerators[i].modifiers,
789 accelerator.set_type(accelerators[i].trigger_on_press ? 858 accelerators[i].trigger_on_press);
790 ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED);
791 Register(accelerator, this); 859 Register(accelerator, this);
792 accelerators_.insert( 860 accelerators_.insert(
793 std::make_pair(accelerator, accelerators[i].action)); 861 std::make_pair(accelerator, accelerators[i].action));
794 } 862 }
795 } 863 }
796 864
865 void AcceleratorController::RegisterDeprecatedAccelerators() {
866 #if defined(OS_CHROMEOS)
867 for (size_t i = 0; i < kDeprecatedAcceleratorsLength; ++i) {
868 const DeprecatedAcceleratorData* data = &kDeprecatedAccelerators[i];
869 const AcceleratorAction action = data->deprecated_accelerator.action;
870 const ui::Accelerator deprecated_accelerator =
871 CreateAccelerator(data->deprecated_accelerator.keycode,
872 data->deprecated_accelerator.modifiers,
873 data->deprecated_accelerator.trigger_on_press);
874
875 Register(deprecated_accelerator, this);
876 actions_with_deprecations_[action] = data;
877 accelerators_[deprecated_accelerator] = action;
878 deprecated_accelerators_.insert(deprecated_accelerator);
879 }
880 #endif // defined(OS_CHROMEOS)
881 }
882
797 bool AcceleratorController::CanPerformAction( 883 bool AcceleratorController::CanPerformAction(
798 AcceleratorAction action, 884 AcceleratorAction action,
799 const ui::Accelerator& accelerator) { 885 const ui::Accelerator& accelerator) {
800 if (nonrepeatable_actions_.find(action) != nonrepeatable_actions_.end() && 886 if (nonrepeatable_actions_.find(action) != nonrepeatable_actions_.end() &&
801 accelerator.IsRepeat()) { 887 accelerator.IsRepeat()) {
802 return false; 888 return false;
803 } 889 }
804 890
891 // Handling the deprecated accelerators.
892 auto itr = actions_with_deprecations_.find(action);
893 if (itr != actions_with_deprecations_.end()) {
894 const DeprecatedAcceleratorData* data = itr->second;
895 if (deprecated_accelerators_.count(accelerator)) {
896 // This accelerator has been deprecated and should be treated according
897 // to its |DeprecatedAcceleratorData|.
898
899 // Record UMA stats.
900 RecordUmaHistogram(data->uma_histogram_name, DEPRECATED_USED);
901
902 // We always display the notification as long as this entry exists.
903 ShowDeprecatedAcceleratorNotification(data->uma_histogram_name,
904 data->notification_message_id);
905
906 if (!data->deprecated_enabled)
907 return false;
908 } else {
909 // This is a new accelerator replacing the old deprecated one.
910 // Record UMA stats and proceed normally.
911 RecordUmaHistogram(data->uma_histogram_name, NEW_USED);
912 }
913 }
914
805 AcceleratorProcessingRestriction restriction = 915 AcceleratorProcessingRestriction restriction =
806 GetAcceleratorProcessingRestriction(action); 916 GetAcceleratorProcessingRestriction(action);
807 if (restriction != RESTRICTION_NONE) 917 if (restriction != RESTRICTION_NONE)
808 return restriction == RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION; 918 return restriction == RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION;
809 919
810 const ui::Accelerator& previous_accelerator = 920 const ui::Accelerator& previous_accelerator =
811 accelerator_history_->previous_accelerator(); 921 accelerator_history_->previous_accelerator();
812 922
813 // True should be returned if running |action| does something. Otherwise, 923 // True should be returned if running |action| does something. Otherwise,
814 // false should be returned to give the web contents a chance at handling the 924 // false should be returned to give the web contents a chance at handling the
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 } 1366 }
1257 1367
1258 void AcceleratorController::SetKeyboardBrightnessControlDelegate( 1368 void AcceleratorController::SetKeyboardBrightnessControlDelegate(
1259 scoped_ptr<KeyboardBrightnessControlDelegate> 1369 scoped_ptr<KeyboardBrightnessControlDelegate>
1260 keyboard_brightness_control_delegate) { 1370 keyboard_brightness_control_delegate) {
1261 keyboard_brightness_control_delegate_ = 1371 keyboard_brightness_control_delegate_ =
1262 keyboard_brightness_control_delegate.Pass(); 1372 keyboard_brightness_control_delegate.Pass();
1263 } 1373 }
1264 1374
1265 } // namespace ash 1375 } // 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