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

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

Issue 2748173002: chromeos: Show deprecated accelerator notifications in mash (Closed)
Patch Set: rebase Created 3 years, 9 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_delegate_aura.h" 5 #include "ash/accelerators/accelerator_controller_delegate_aura.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 11
12 #include "ash/accelerators/accelerator_commands_aura.h" 12 #include "ash/accelerators/accelerator_commands_aura.h"
13 #include "ash/common/accelerators/debug_commands.h" 13 #include "ash/common/accelerators/debug_commands.h"
14 #include "ash/common/accessibility_types.h" 14 #include "ash/common/accessibility_types.h"
15 #include "ash/common/session/session_state_delegate.h"
16 #include "ash/common/shelf/wm_shelf.h" 15 #include "ash/common/shelf/wm_shelf.h"
17 #include "ash/common/shell_delegate.h"
18 #include "ash/common/system/system_notifier.h" 16 #include "ash/common/system/system_notifier.h"
19 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" 17 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h"
20 #include "ash/common/wm/window_state.h" 18 #include "ash/common/wm/window_state.h"
21 #include "ash/common/wm/wm_event.h" 19 #include "ash/common/wm/wm_event.h"
22 #include "ash/common/wm_shell.h" 20 #include "ash/common/wm_shell.h"
23 #include "ash/debug.h" 21 #include "ash/debug.h"
24 #include "ash/display/display_configuration_controller.h" 22 #include "ash/display/display_configuration_controller.h"
25 #include "ash/display/window_tree_host_manager.h" 23 #include "ash/display/window_tree_host_manager.h"
26 #include "ash/host/ash_window_tree_host.h" 24 #include "ash/host/ash_window_tree_host.h"
27 #include "ash/magnifier/magnification_controller.h" 25 #include "ash/magnifier/magnification_controller.h"
28 #include "ash/public/cpp/shell_window_ids.h" 26 #include "ash/public/cpp/shell_window_ids.h"
29 #include "ash/root_window_controller.h" 27 #include "ash/root_window_controller.h"
30 #include "ash/rotator/window_rotation.h" 28 #include "ash/rotator/window_rotation.h"
31 #include "ash/screenshot_delegate.h" 29 #include "ash/screenshot_delegate.h"
32 #include "ash/shell.h" 30 #include "ash/shell.h"
33 #include "ash/touch/touch_hud_debug.h" 31 #include "ash/touch/touch_hud_debug.h"
34 #include "ash/utility/screenshot_controller.h" 32 #include "ash/utility/screenshot_controller.h"
35 #include "ash/wm/power_button_controller.h" 33 #include "ash/wm/power_button_controller.h"
36 #include "ash/wm/window_state_aura.h" 34 #include "ash/wm/window_state_aura.h"
37 #include "ash/wm/window_util.h" 35 #include "ash/wm/window_util.h"
38 #include "base/memory/ptr_util.h" 36 #include "base/memory/ptr_util.h"
39 #include "base/metrics/histogram_macros.h" 37 #include "base/metrics/histogram_macros.h"
40 #include "base/metrics/user_metrics.h" 38 #include "base/metrics/user_metrics.h"
41 #include "base/strings/string_split.h"
42 #include "base/strings/utf_string_conversions.h"
43 #include "base/sys_info.h" 39 #include "base/sys_info.h"
44 #include "third_party/skia/include/core/SkColor.h" 40 #include "third_party/skia/include/core/SkColor.h"
45 #include "ui/base/accelerators/accelerator.h" 41 #include "ui/base/accelerators/accelerator.h"
46 #include "ui/base/l10n/l10n_util.h"
47 #include "ui/compositor/layer.h" 42 #include "ui/compositor/layer.h"
48 #include "ui/compositor/layer_animation_sequence.h" 43 #include "ui/compositor/layer_animation_sequence.h"
49 #include "ui/compositor/layer_animator.h" 44 #include "ui/compositor/layer_animator.h"
50 #include "ui/display/manager/display_manager.h" 45 #include "ui/display/manager/display_manager.h"
51 #include "ui/display/screen.h" 46 #include "ui/display/screen.h"
52 #include "ui/events/event.h" 47 #include "ui/events/event.h"
53 #include "ui/events/keycodes/keyboard_codes.h" 48 #include "ui/events/keycodes/keyboard_codes.h"
54 #include "ui/message_center/message_center.h"
55 #include "ui/message_center/notification.h"
56 #include "ui/message_center/notifier_settings.h"
57 49
58 namespace ash { 50 namespace ash {
59 namespace { 51 namespace {
60 52
61 using base::UserMetricsAction; 53 using base::UserMetricsAction;
62 54
63 // The notification delegate that will be used to open the keyboard shortcut
64 // help page when the notification is clicked.
65 class DeprecatedAcceleratorNotificationDelegate
66 : public message_center::NotificationDelegate {
67 public:
68 DeprecatedAcceleratorNotificationDelegate() {}
69
70 // message_center::NotificationDelegate:
71 bool HasClickedListener() override { return true; }
72
73 void Click() override {
74 if (!WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked())
75 Shell::Get()->shell_delegate()->OpenKeyboardShortcutHelpPage();
76 }
77
78 private:
79 // Private destructor since NotificationDelegate is ref-counted.
80 ~DeprecatedAcceleratorNotificationDelegate() override {}
81
82 DISALLOW_COPY_AND_ASSIGN(DeprecatedAcceleratorNotificationDelegate);
83 };
84
85 // Ensures that there are no word breaks at the "+"s in the shortcut texts such
86 // as "Ctrl+Shift+Space".
87 void EnsureNoWordBreaks(base::string16* shortcut_text) {
88 std::vector<base::string16> keys =
89 base::SplitString(*shortcut_text, base::ASCIIToUTF16("+"),
90 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
91
92 if (keys.size() < 2U)
93 return;
94
95 // The plus sign surrounded by the word joiner to guarantee an non-breaking
96 // shortcut.
97 const base::string16 non_breaking_plus =
98 base::UTF8ToUTF16("\xe2\x81\xa0+\xe2\x81\xa0");
99 shortcut_text->clear();
100 for (size_t i = 0; i < keys.size() - 1; ++i) {
101 *shortcut_text += keys[i];
102 *shortcut_text += non_breaking_plus;
103 }
104
105 *shortcut_text += keys.back();
106 }
107
108 // Gets the notification message after it formats it in such a way that there
109 // are no line breaks in the middle of the shortcut texts.
110 base::string16 GetNotificationText(int message_id,
111 int old_shortcut_id,
112 int new_shortcut_id) {
113 base::string16 old_shortcut = l10n_util::GetStringUTF16(old_shortcut_id);
114 base::string16 new_shortcut = l10n_util::GetStringUTF16(new_shortcut_id);
115 EnsureNoWordBreaks(&old_shortcut);
116 EnsureNoWordBreaks(&new_shortcut);
117
118 return l10n_util::GetStringFUTF16(message_id, new_shortcut, old_shortcut);
119 }
120
121 bool CanHandleMagnifyScreen() { 55 bool CanHandleMagnifyScreen() {
122 return Shell::GetInstance()->magnification_controller()->IsEnabled(); 56 return Shell::GetInstance()->magnification_controller()->IsEnabled();
123 } 57 }
124 58
125 // Magnify the screen 59 // Magnify the screen
126 void HandleMagnifyScreen(int delta_index) { 60 void HandleMagnifyScreen(int delta_index) {
127 if (Shell::GetInstance()->magnification_controller()->IsEnabled()) { 61 if (Shell::GetInstance()->magnification_controller()->IsEnabled()) {
128 // TODO(yoshiki): Move the following logic to MagnificationController. 62 // TODO(yoshiki): Move the following logic to MagnificationController.
129 float scale = Shell::GetInstance()->magnification_controller()->GetScale(); 63 float scale = Shell::GetInstance()->magnification_controller()->GetScale();
130 // Calculate rounded logarithm (base kMagnificationScaleFactor) of scale. 64 // Calculate rounded logarithm (base kMagnificationScaleFactor) of scale.
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 accelerators::ToggleTouchHudProjection(); 374 accelerators::ToggleTouchHudProjection();
441 break; 375 break;
442 case UNPIN: 376 case UNPIN:
443 accelerators::Unpin(); 377 accelerators::Unpin();
444 break; 378 break;
445 default: 379 default:
446 break; 380 break;
447 } 381 }
448 } 382 }
449 383
450 void AcceleratorControllerDelegateAura::ShowDeprecatedAcceleratorNotification(
451 const char* const notification_id,
452 int message_id,
453 int old_shortcut_id,
454 int new_shortcut_id) {
455 const base::string16 message =
456 GetNotificationText(message_id, old_shortcut_id, new_shortcut_id);
457 std::unique_ptr<message_center::Notification> notification(
458 new message_center::Notification(
459 message_center::NOTIFICATION_TYPE_SIMPLE, notification_id,
460 base::string16(), message,
461 Shell::Get()->shell_delegate()->GetDeprecatedAcceleratorImage(),
462 base::string16(), GURL(),
463 message_center::NotifierId(
464 message_center::NotifierId::SYSTEM_COMPONENT,
465 system_notifier::kNotifierDeprecatedAccelerator),
466 message_center::RichNotificationData(),
467 new DeprecatedAcceleratorNotificationDelegate));
468 message_center::MessageCenter::Get()->AddNotification(
469 std::move(notification));
470 }
471
472 } // namespace ash 384 } // namespace ash
OLDNEW
« no previous file with comments | « ash/accelerators/accelerator_controller_delegate_aura.h ('k') | ash/common/accelerators/accelerator_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698