| 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/common/accelerators/accelerator_controller.h" | 5 #include "ash/common/accelerators/accelerator_controller.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "ash/common/accelerators/accelerator_commands.h" | 9 #include "ash/common/accelerators/accelerator_commands.h" |
| 10 #include "ash/common/accelerators/accelerator_controller_delegate.h" | 10 #include "ash/common/accelerators/accelerator_controller_delegate.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 #include "ash/common/wm/window_state.h" | 39 #include "ash/common/wm/window_state.h" |
| 40 #include "ash/common/wm/wm_event.h" | 40 #include "ash/common/wm/wm_event.h" |
| 41 #include "ash/common/wm_shell.h" | 41 #include "ash/common/wm_shell.h" |
| 42 #include "ash/common/wm_window.h" | 42 #include "ash/common/wm_window.h" |
| 43 #include "ash/resources/vector_icons/vector_icons.h" | 43 #include "ash/resources/vector_icons/vector_icons.h" |
| 44 #include "ash/root_window_controller.h" | 44 #include "ash/root_window_controller.h" |
| 45 #include "ash/shell.h" | 45 #include "ash/shell.h" |
| 46 #include "ash/strings/grit/ash_strings.h" | 46 #include "ash/strings/grit/ash_strings.h" |
| 47 #include "base/metrics/histogram_macros.h" | 47 #include "base/metrics/histogram_macros.h" |
| 48 #include "base/metrics/user_metrics.h" | 48 #include "base/metrics/user_metrics.h" |
| 49 #include "base/strings/string_split.h" |
| 50 #include "base/strings/utf_string_conversions.h" |
| 49 #include "chromeos/dbus/dbus_thread_manager.h" | 51 #include "chromeos/dbus/dbus_thread_manager.h" |
| 50 #include "chromeos/dbus/power_manager_client.h" | 52 #include "chromeos/dbus/power_manager_client.h" |
| 51 #include "ui/base/accelerators/accelerator.h" | 53 #include "ui/base/accelerators/accelerator.h" |
| 52 #include "ui/base/accelerators/accelerator_manager.h" | 54 #include "ui/base/accelerators/accelerator_manager.h" |
| 53 #include "ui/base/ime/chromeos/ime_keyboard.h" | 55 #include "ui/base/ime/chromeos/ime_keyboard.h" |
| 54 #include "ui/base/ime/chromeos/input_method_manager.h" | 56 #include "ui/base/ime/chromeos/input_method_manager.h" |
| 55 #include "ui/base/l10n/l10n_util.h" | 57 #include "ui/base/l10n/l10n_util.h" |
| 56 #include "ui/gfx/paint_vector_icon.h" | 58 #include "ui/gfx/paint_vector_icon.h" |
| 57 #include "ui/keyboard/keyboard_controller.h" | 59 #include "ui/keyboard/keyboard_controller.h" |
| 58 #include "ui/message_center/message_center.h" | 60 #include "ui/message_center/message_center.h" |
| 59 | 61 |
| 60 namespace ash { | 62 namespace ash { |
| 61 namespace { | 63 namespace { |
| 62 | 64 |
| 63 using base::UserMetricsAction; | 65 using base::UserMetricsAction; |
| 64 using message_center::Notification; | 66 using message_center::Notification; |
| 65 | 67 |
| 66 // Identifier for the high contrast toggle accelerator notification. | 68 // Identifier for the high contrast toggle accelerator notification. |
| 67 const char kHighContrastToggleAccelNotificationId[] = | 69 const char kHighContrastToggleAccelNotificationId[] = |
| 68 "chrome://settings/accessibility/highcontrast"; | 70 "chrome://settings/accessibility/highcontrast"; |
| 69 | 71 |
| 72 // The notification delegate that will be used to open the keyboard shortcut |
| 73 // help page when the notification is clicked. |
| 74 class DeprecatedAcceleratorNotificationDelegate |
| 75 : public message_center::NotificationDelegate { |
| 76 public: |
| 77 DeprecatedAcceleratorNotificationDelegate() {} |
| 78 |
| 79 // message_center::NotificationDelegate: |
| 80 bool HasClickedListener() override { return true; } |
| 81 |
| 82 void Click() override { |
| 83 if (!WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked()) |
| 84 Shell::Get()->shell_delegate()->OpenKeyboardShortcutHelpPage(); |
| 85 } |
| 86 |
| 87 private: |
| 88 // Private destructor since NotificationDelegate is ref-counted. |
| 89 ~DeprecatedAcceleratorNotificationDelegate() override {} |
| 90 |
| 91 DISALLOW_COPY_AND_ASSIGN(DeprecatedAcceleratorNotificationDelegate); |
| 92 }; |
| 93 |
| 94 // Ensures that there are no word breaks at the "+"s in the shortcut texts such |
| 95 // as "Ctrl+Shift+Space". |
| 96 void EnsureNoWordBreaks(base::string16* shortcut_text) { |
| 97 std::vector<base::string16> keys = |
| 98 base::SplitString(*shortcut_text, base::ASCIIToUTF16("+"), |
| 99 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 100 |
| 101 if (keys.size() < 2U) |
| 102 return; |
| 103 |
| 104 // The plus sign surrounded by the word joiner to guarantee an non-breaking |
| 105 // shortcut. |
| 106 const base::string16 non_breaking_plus = |
| 107 base::UTF8ToUTF16("\xe2\x81\xa0+\xe2\x81\xa0"); |
| 108 shortcut_text->clear(); |
| 109 for (size_t i = 0; i < keys.size() - 1; ++i) { |
| 110 *shortcut_text += keys[i]; |
| 111 *shortcut_text += non_breaking_plus; |
| 112 } |
| 113 |
| 114 *shortcut_text += keys.back(); |
| 115 } |
| 116 |
| 117 // Gets the notification message after it formats it in such a way that there |
| 118 // are no line breaks in the middle of the shortcut texts. |
| 119 base::string16 GetNotificationText(int message_id, |
| 120 int old_shortcut_id, |
| 121 int new_shortcut_id) { |
| 122 base::string16 old_shortcut = l10n_util::GetStringUTF16(old_shortcut_id); |
| 123 base::string16 new_shortcut = l10n_util::GetStringUTF16(new_shortcut_id); |
| 124 EnsureNoWordBreaks(&old_shortcut); |
| 125 EnsureNoWordBreaks(&new_shortcut); |
| 126 |
| 127 return l10n_util::GetStringFUTF16(message_id, new_shortcut, old_shortcut); |
| 128 } |
| 129 |
| 130 // Shows a warning the user is using a deprecated accelerator. |
| 131 void ShowDeprecatedAcceleratorNotification(const char* const notification_id, |
| 132 int message_id, |
| 133 int old_shortcut_id, |
| 134 int new_shortcut_id) { |
| 135 const base::string16 message = |
| 136 GetNotificationText(message_id, old_shortcut_id, new_shortcut_id); |
| 137 std::unique_ptr<Notification> notification(new Notification( |
| 138 message_center::NOTIFICATION_TYPE_SIMPLE, notification_id, |
| 139 base::string16(), message, |
| 140 Shell::Get()->shell_delegate()->GetDeprecatedAcceleratorImage(), |
| 141 base::string16(), GURL(), |
| 142 message_center::NotifierId( |
| 143 message_center::NotifierId::SYSTEM_COMPONENT, |
| 144 system_notifier::kNotifierDeprecatedAccelerator), |
| 145 message_center::RichNotificationData(), |
| 146 new DeprecatedAcceleratorNotificationDelegate)); |
| 147 message_center::MessageCenter::Get()->AddNotification( |
| 148 std::move(notification)); |
| 149 } |
| 150 |
| 70 ui::Accelerator CreateAccelerator(ui::KeyboardCode keycode, | 151 ui::Accelerator CreateAccelerator(ui::KeyboardCode keycode, |
| 71 int modifiers, | 152 int modifiers, |
| 72 bool trigger_on_press) { | 153 bool trigger_on_press) { |
| 73 ui::Accelerator accelerator(keycode, modifiers); | 154 ui::Accelerator accelerator(keycode, modifiers); |
| 74 accelerator.set_type(trigger_on_press ? ui::ET_KEY_PRESSED | 155 accelerator.set_type(trigger_on_press ? ui::ET_KEY_PRESSED |
| 75 : ui::ET_KEY_RELEASED); | 156 : ui::ET_KEY_RELEASED); |
| 76 return accelerator; | 157 return accelerator; |
| 77 } | 158 } |
| 78 | 159 |
| 79 void RecordUmaHistogram(const char* histogram_name, | 160 void RecordUmaHistogram(const char* histogram_name, |
| (...skipping 1088 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1168 RecordUmaHistogram(data->uma_histogram_name, NEW_USED); | 1249 RecordUmaHistogram(data->uma_histogram_name, NEW_USED); |
| 1169 return AcceleratorProcessingStatus::PROCEED; | 1250 return AcceleratorProcessingStatus::PROCEED; |
| 1170 } | 1251 } |
| 1171 | 1252 |
| 1172 // This accelerator has been deprecated and should be treated according | 1253 // This accelerator has been deprecated and should be treated according |
| 1173 // to its |DeprecatedAcceleratorData|. | 1254 // to its |DeprecatedAcceleratorData|. |
| 1174 | 1255 |
| 1175 // Record UMA stats. | 1256 // Record UMA stats. |
| 1176 RecordUmaHistogram(data->uma_histogram_name, DEPRECATED_USED); | 1257 RecordUmaHistogram(data->uma_histogram_name, DEPRECATED_USED); |
| 1177 | 1258 |
| 1178 if (delegate_) { | 1259 // We always display the notification as long as this |data| entry exists. |
| 1179 // We always display the notification as long as this |data| entry exists. | 1260 ShowDeprecatedAcceleratorNotification( |
| 1180 delegate_->ShowDeprecatedAcceleratorNotification( | 1261 data->uma_histogram_name, data->notification_message_id, |
| 1181 data->uma_histogram_name, data->notification_message_id, | 1262 data->old_shortcut_id, data->new_shortcut_id); |
| 1182 data->old_shortcut_id, data->new_shortcut_id); | |
| 1183 } | |
| 1184 | 1263 |
| 1185 if (!data->deprecated_enabled) | 1264 if (!data->deprecated_enabled) |
| 1186 return AcceleratorProcessingStatus::STOP; | 1265 return AcceleratorProcessingStatus::STOP; |
| 1187 | 1266 |
| 1188 return AcceleratorProcessingStatus::PROCEED; | 1267 return AcceleratorProcessingStatus::PROCEED; |
| 1189 } | 1268 } |
| 1190 | 1269 |
| 1191 } // namespace ash | 1270 } // namespace ash |
| OLD | NEW |