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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/system/tray_caps_lock.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/system/tray_caps_lock.cc
diff --git a/ash/system/tray_caps_lock.cc b/ash/system/tray_caps_lock.cc
index 2471888f8b5b59caf939e9e791e4926260d19551..f9461174dfa1fa0cab8d425e844e354d1cdb630a 100644
--- a/ash/system/tray_caps_lock.cc
+++ b/ash/system/tray_caps_lock.cc
@@ -10,6 +10,7 @@
#include "ash/shell.h"
#include "ash/shell_port.h"
#include "ash/strings/grit/ash_strings.h"
+#include "ash/system/system_notifier.h"
#include "ash/system/tray/actionable_view.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/tray_constants.h"
@@ -24,6 +25,8 @@
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/paint_vector_icon.h"
+#include "ui/message_center/message_center.h"
+#include "ui/message_center/notification.h"
#include "ui/views/border.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
@@ -31,12 +34,16 @@
#include "ui/views/layout/fill_layout.h"
#include "ui/views/widget/widget.h"
+using message_center::Notification;
+
namespace ash {
namespace {
// Padding used to position the caption in the caps lock default view row.
const int kCaptionRightPadding = 6;
+const char kCapsLockNotificationId[] = "capslock";
+
bool CapsLockIsEnabled() {
chromeos::input_method::InputMethodManager* ime =
chromeos::input_method::InputMethodManager::Get();
@@ -44,8 +51,29 @@ bool CapsLockIsEnabled() {
? ime->GetImeKeyboard()->CapsLockIsEnabled()
: false;
}
+
+std::unique_ptr<Notification> CreateNotification() {
+ ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
+ const int string_id =
+ Shell::Get()->system_tray_delegate()->IsSearchKeyMappedToCapsLock()
+ ? IDS_ASH_STATUS_TRAY_CAPS_LOCK_CANCEL_BY_SEARCH
+ : IDS_ASH_STATUS_TRAY_CAPS_LOCK_CANCEL_BY_ALT_SEARCH;
+ std::unique_ptr<Notification> notification(new Notification(
+ message_center::NOTIFICATION_TYPE_SIMPLE, kCapsLockNotificationId,
+ base::string16(), bundle.GetLocalizedString(string_id),
+ gfx::Image(
+ gfx::CreateVectorIcon(kSystemMenuCapsLockIcon,
+ TrayPopupItemStyle::GetIconColor(
+ TrayPopupItemStyle::ColorStyle::ACTIVE))),
+ base::string16() /* display_source */, GURL(),
+ message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT,
+ system_notifier::kNotifierCapsLock),
+ message_center::RichNotificationData(), nullptr));
+ return notification;
}
+} // namespace
+
class CapsLockDefaultView : public ActionableView {
public:
CapsLockDefaultView()
@@ -139,7 +167,6 @@ class CapsLockDefaultView : public ActionableView {
TrayCapsLock::TrayCapsLock(SystemTray* system_tray)
: TrayImageItem(system_tray, kSystemTrayCapsLockIcon, UMA_CAPS_LOCK),
default_(nullptr),
- detailed_(nullptr),
caps_lock_enabled_(CapsLockIsEnabled()),
message_shown_(false) {
chromeos::input_method::InputMethodManager* ime =
@@ -168,15 +195,19 @@ void TrayCapsLock::OnCapsLockChanged(bool enabled) {
if (default_) {
default_->Update(caps_lock_enabled_);
} else {
+ message_center::MessageCenter* message_center =
+ message_center::MessageCenter::Get();
if (caps_lock_enabled_) {
if (!message_shown_) {
ShellPort::Get()->RecordUserMetricsAction(
UMA_STATUS_AREA_CAPS_LOCK_POPUP);
- ShowDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false);
+
+ message_center->AddNotification(CreateNotification());
message_shown_ = true;
}
- } else if (detailed_) {
- detailed_->GetWidget()->Close();
+ } else if (message_center->FindVisibleNotificationById(
+ kCapsLockNotificationId)) {
+ message_center->RemoveNotification(kCapsLockNotificationId, false);
}
}
}
@@ -194,40 +225,8 @@ views::View* TrayCapsLock::CreateDefaultView(LoginStatus status) {
return default_;
}
-views::View* TrayCapsLock::CreateDetailedView(LoginStatus status) {
- DCHECK(!detailed_);
- detailed_ = new views::View;
-
- detailed_->SetLayoutManager(new views::BoxLayout(
- views::BoxLayout::kHorizontal, kTrayPopupPaddingHorizontal, 10,
- kTrayPopupPaddingBetweenItems));
-
- ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
- views::ImageView* image = new views::ImageView;
- image->SetImage(
- CreateVectorIcon(kSystemMenuCapsLockIcon, kMenuIconSize, kMenuIconColor));
- detailed_->AddChildView(image);
-
- const int string_id =
- Shell::Get()->system_tray_delegate()->IsSearchKeyMappedToCapsLock()
- ? IDS_ASH_STATUS_TRAY_CAPS_LOCK_CANCEL_BY_SEARCH
- : IDS_ASH_STATUS_TRAY_CAPS_LOCK_CANCEL_BY_ALT_SEARCH;
- views::Label* label = TrayPopupUtils::CreateDefaultLabel();
- label->SetText(bundle.GetLocalizedString(string_id));
- label->SetMultiLine(true);
- label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
- detailed_->AddChildView(label);
- ShellPort::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_CAPS_LOCK_DETAILED);
-
- return detailed_;
-}
-
void TrayCapsLock::DestroyDefaultView() {
default_ = nullptr;
}
-void TrayCapsLock::DestroyDetailedView() {
- detailed_ = nullptr;
-}
-
} // namespace ash
« 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