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

Side by Side Diff: ash/system/tray_caps_lock.cc

Issue 2820443002: ash: Move "CAPS LOCK is on." bubble to the notification center. (Closed)
Patch Set: Address review comments. Created 3 years, 8 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
« no previous file with comments | « ash/system/tray_caps_lock.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/system/tray_caps_lock.h" 5 #include "ash/system/tray_caps_lock.h"
6 6
7 #include "ash/accessibility_delegate.h" 7 #include "ash/accessibility_delegate.h"
8 #include "ash/resources/grit/ash_resources.h" 8 #include "ash/resources/grit/ash_resources.h"
9 #include "ash/resources/vector_icons/vector_icons.h" 9 #include "ash/resources/vector_icons/vector_icons.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
11 #include "ash/shell_port.h" 11 #include "ash/shell_port.h"
12 #include "ash/strings/grit/ash_strings.h" 12 #include "ash/strings/grit/ash_strings.h"
13 #include "ash/system/system_notifier.h"
13 #include "ash/system/tray/actionable_view.h" 14 #include "ash/system/tray/actionable_view.h"
14 #include "ash/system/tray/system_tray_delegate.h" 15 #include "ash/system/tray/system_tray_delegate.h"
15 #include "ash/system/tray/tray_constants.h" 16 #include "ash/system/tray/tray_constants.h"
16 #include "ash/system/tray/tray_popup_item_style.h" 17 #include "ash/system/tray/tray_popup_item_style.h"
17 #include "ash/system/tray/tray_popup_utils.h" 18 #include "ash/system/tray/tray_popup_utils.h"
18 #include "ash/system/tray/tri_view.h" 19 #include "ash/system/tray/tri_view.h"
19 #include "base/sys_info.h" 20 #include "base/sys_info.h"
20 #include "ui/accessibility/ax_node_data.h" 21 #include "ui/accessibility/ax_node_data.h"
21 #include "ui/base/ime/chromeos/ime_keyboard.h" 22 #include "ui/base/ime/chromeos/ime_keyboard.h"
22 #include "ui/base/ime/chromeos/input_method_manager.h" 23 #include "ui/base/ime/chromeos/input_method_manager.h"
23 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/base/resource/resource_bundle.h" 25 #include "ui/base/resource/resource_bundle.h"
25 #include "ui/gfx/image/image.h" 26 #include "ui/gfx/image/image.h"
26 #include "ui/gfx/paint_vector_icon.h" 27 #include "ui/gfx/paint_vector_icon.h"
28 #include "ui/message_center/message_center.h"
29 #include "ui/message_center/notification.h"
27 #include "ui/views/border.h" 30 #include "ui/views/border.h"
28 #include "ui/views/controls/image_view.h" 31 #include "ui/views/controls/image_view.h"
29 #include "ui/views/controls/label.h" 32 #include "ui/views/controls/label.h"
30 #include "ui/views/layout/box_layout.h" 33 #include "ui/views/layout/box_layout.h"
31 #include "ui/views/layout/fill_layout.h" 34 #include "ui/views/layout/fill_layout.h"
32 #include "ui/views/widget/widget.h" 35 #include "ui/views/widget/widget.h"
33 36
37 using message_center::Notification;
38
34 namespace ash { 39 namespace ash {
35 namespace { 40 namespace {
36 41
37 // Padding used to position the caption in the caps lock default view row. 42 // Padding used to position the caption in the caps lock default view row.
38 const int kCaptionRightPadding = 6; 43 const int kCaptionRightPadding = 6;
39 44
45 const char kCapsLockNotificationId[] = "capslock";
46
40 bool CapsLockIsEnabled() { 47 bool CapsLockIsEnabled() {
41 chromeos::input_method::InputMethodManager* ime = 48 chromeos::input_method::InputMethodManager* ime =
42 chromeos::input_method::InputMethodManager::Get(); 49 chromeos::input_method::InputMethodManager::Get();
43 return (ime && ime->GetImeKeyboard()) 50 return (ime && ime->GetImeKeyboard())
44 ? ime->GetImeKeyboard()->CapsLockIsEnabled() 51 ? ime->GetImeKeyboard()->CapsLockIsEnabled()
45 : false; 52 : false;
46 } 53 }
54
55 std::unique_ptr<Notification> CreateNotification() {
56 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
57 const int string_id =
58 Shell::Get()->system_tray_delegate()->IsSearchKeyMappedToCapsLock()
59 ? IDS_ASH_STATUS_TRAY_CAPS_LOCK_CANCEL_BY_SEARCH
60 : IDS_ASH_STATUS_TRAY_CAPS_LOCK_CANCEL_BY_ALT_SEARCH;
61 std::unique_ptr<Notification> notification(new Notification(
62 message_center::NOTIFICATION_TYPE_SIMPLE, kCapsLockNotificationId,
63 base::string16(), bundle.GetLocalizedString(string_id),
64 gfx::Image(
65 gfx::CreateVectorIcon(kSystemMenuCapsLockIcon,
66 TrayPopupItemStyle::GetIconColor(
67 TrayPopupItemStyle::ColorStyle::ACTIVE))),
68 base::string16() /* display_source */, GURL(),
69 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT,
70 system_notifier::kNotifierCapsLock),
71 message_center::RichNotificationData(), nullptr));
72 return notification;
47 } 73 }
48 74
75 } // namespace
76
49 class CapsLockDefaultView : public ActionableView { 77 class CapsLockDefaultView : public ActionableView {
50 public: 78 public:
51 CapsLockDefaultView() 79 CapsLockDefaultView()
52 : ActionableView(nullptr, TrayPopupInkDropStyle::FILL_BOUNDS), 80 : ActionableView(nullptr, TrayPopupInkDropStyle::FILL_BOUNDS),
53 text_label_(TrayPopupUtils::CreateDefaultLabel()), 81 text_label_(TrayPopupUtils::CreateDefaultLabel()),
54 shortcut_label_(TrayPopupUtils::CreateDefaultLabel()) { 82 shortcut_label_(TrayPopupUtils::CreateDefaultLabel()) {
55 shortcut_label_->SetEnabled(false); 83 shortcut_label_->SetEnabled(false);
56 84
57 TriView* tri_view(TrayPopupUtils::CreateDefaultRowView()); 85 TriView* tri_view(TrayPopupUtils::CreateDefaultRowView());
58 SetLayoutManager(new views::FillLayout); 86 SetLayoutManager(new views::FillLayout);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 160
133 // It indicates the shortcut can be used to turn on or turn off Caps Lock. 161 // It indicates the shortcut can be used to turn on or turn off Caps Lock.
134 views::Label* shortcut_label_; 162 views::Label* shortcut_label_;
135 163
136 DISALLOW_COPY_AND_ASSIGN(CapsLockDefaultView); 164 DISALLOW_COPY_AND_ASSIGN(CapsLockDefaultView);
137 }; 165 };
138 166
139 TrayCapsLock::TrayCapsLock(SystemTray* system_tray) 167 TrayCapsLock::TrayCapsLock(SystemTray* system_tray)
140 : TrayImageItem(system_tray, kSystemTrayCapsLockIcon, UMA_CAPS_LOCK), 168 : TrayImageItem(system_tray, kSystemTrayCapsLockIcon, UMA_CAPS_LOCK),
141 default_(nullptr), 169 default_(nullptr),
142 detailed_(nullptr),
143 caps_lock_enabled_(CapsLockIsEnabled()), 170 caps_lock_enabled_(CapsLockIsEnabled()),
144 message_shown_(false) { 171 message_shown_(false) {
145 chromeos::input_method::InputMethodManager* ime = 172 chromeos::input_method::InputMethodManager* ime =
146 chromeos::input_method::InputMethodManager::Get(); 173 chromeos::input_method::InputMethodManager::Get();
147 if (ime && ime->GetImeKeyboard()) 174 if (ime && ime->GetImeKeyboard())
148 ime->GetImeKeyboard()->AddObserver(this); 175 ime->GetImeKeyboard()->AddObserver(this);
149 } 176 }
150 177
151 TrayCapsLock::~TrayCapsLock() { 178 TrayCapsLock::~TrayCapsLock() {
152 chromeos::input_method::InputMethodManager* ime = 179 chromeos::input_method::InputMethodManager* ime =
153 chromeos::input_method::InputMethodManager::Get(); 180 chromeos::input_method::InputMethodManager::Get();
154 if (ime && ime->GetImeKeyboard()) 181 if (ime && ime->GetImeKeyboard())
155 ime->GetImeKeyboard()->RemoveObserver(this); 182 ime->GetImeKeyboard()->RemoveObserver(this);
156 } 183 }
157 184
158 void TrayCapsLock::OnCapsLockChanged(bool enabled) { 185 void TrayCapsLock::OnCapsLockChanged(bool enabled) {
159 caps_lock_enabled_ = enabled; 186 caps_lock_enabled_ = enabled;
160 187
161 // Send an a11y alert. 188 // Send an a11y alert.
162 Shell::Get()->accessibility_delegate()->TriggerAccessibilityAlert( 189 Shell::Get()->accessibility_delegate()->TriggerAccessibilityAlert(
163 enabled ? A11Y_ALERT_CAPS_ON : A11Y_ALERT_CAPS_OFF); 190 enabled ? A11Y_ALERT_CAPS_ON : A11Y_ALERT_CAPS_OFF);
164 191
165 if (tray_view()) 192 if (tray_view())
166 tray_view()->SetVisible(caps_lock_enabled_); 193 tray_view()->SetVisible(caps_lock_enabled_);
167 194
168 if (default_) { 195 if (default_) {
169 default_->Update(caps_lock_enabled_); 196 default_->Update(caps_lock_enabled_);
170 } else { 197 } else {
198 message_center::MessageCenter* message_center =
199 message_center::MessageCenter::Get();
171 if (caps_lock_enabled_) { 200 if (caps_lock_enabled_) {
172 if (!message_shown_) { 201 if (!message_shown_) {
173 ShellPort::Get()->RecordUserMetricsAction( 202 ShellPort::Get()->RecordUserMetricsAction(
174 UMA_STATUS_AREA_CAPS_LOCK_POPUP); 203 UMA_STATUS_AREA_CAPS_LOCK_POPUP);
175 ShowDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); 204
205 message_center->AddNotification(CreateNotification());
176 message_shown_ = true; 206 message_shown_ = true;
177 } 207 }
178 } else if (detailed_) { 208 } else if (message_center->FindVisibleNotificationById(
179 detailed_->GetWidget()->Close(); 209 kCapsLockNotificationId)) {
210 message_center->RemoveNotification(kCapsLockNotificationId, false);
180 } 211 }
181 } 212 }
182 } 213 }
183 214
184 bool TrayCapsLock::GetInitialVisibility() { 215 bool TrayCapsLock::GetInitialVisibility() {
185 return CapsLockIsEnabled(); 216 return CapsLockIsEnabled();
186 } 217 }
187 218
188 views::View* TrayCapsLock::CreateDefaultView(LoginStatus status) { 219 views::View* TrayCapsLock::CreateDefaultView(LoginStatus status) {
189 if (!caps_lock_enabled_) 220 if (!caps_lock_enabled_)
190 return nullptr; 221 return nullptr;
191 DCHECK(!default_); 222 DCHECK(!default_);
192 default_ = new CapsLockDefaultView; 223 default_ = new CapsLockDefaultView;
193 default_->Update(caps_lock_enabled_); 224 default_->Update(caps_lock_enabled_);
194 return default_; 225 return default_;
195 } 226 }
196 227
197 views::View* TrayCapsLock::CreateDetailedView(LoginStatus status) {
198 DCHECK(!detailed_);
199 detailed_ = new views::View;
200
201 detailed_->SetLayoutManager(new views::BoxLayout(
202 views::BoxLayout::kHorizontal, kTrayPopupPaddingHorizontal, 10,
203 kTrayPopupPaddingBetweenItems));
204
205 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
206 views::ImageView* image = new views::ImageView;
207 image->SetImage(
208 CreateVectorIcon(kSystemMenuCapsLockIcon, kMenuIconSize, kMenuIconColor));
209 detailed_->AddChildView(image);
210
211 const int string_id =
212 Shell::Get()->system_tray_delegate()->IsSearchKeyMappedToCapsLock()
213 ? IDS_ASH_STATUS_TRAY_CAPS_LOCK_CANCEL_BY_SEARCH
214 : IDS_ASH_STATUS_TRAY_CAPS_LOCK_CANCEL_BY_ALT_SEARCH;
215 views::Label* label = TrayPopupUtils::CreateDefaultLabel();
216 label->SetText(bundle.GetLocalizedString(string_id));
217 label->SetMultiLine(true);
218 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
219 detailed_->AddChildView(label);
220 ShellPort::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_CAPS_LOCK_DETAILED);
221
222 return detailed_;
223 }
224
225 void TrayCapsLock::DestroyDefaultView() { 228 void TrayCapsLock::DestroyDefaultView() {
226 default_ = nullptr; 229 default_ = nullptr;
227 } 230 }
228 231
229 void TrayCapsLock::DestroyDetailedView() {
230 detailed_ = nullptr;
231 }
232
233 } // namespace ash 232 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/tray_caps_lock.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698