summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ash/ash.gyp4
-rw-r--r--ash/shell.cc6
-rw-r--r--ash/shell.h4
-rw-r--r--ash/system/locale/locale_notification_controller.cc123
-rw-r--r--ash/system/locale/locale_notification_controller.h41
-rw-r--r--ash/system/locale/tray_locale.cc152
-rw-r--r--ash/system/locale/tray_locale.h50
-rw-r--r--ash/system/tray/system_tray.cc2
8 files changed, 176 insertions, 206 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp
index b53af60..c0bcecb 100644
--- a/ash/ash.gyp
+++ b/ash/ash.gyp
@@ -266,8 +266,8 @@
'system/ime/tray_ime.cc',
'system/ime/tray_ime.h',
'system/keyboard_brightness/keyboard_brightness_control_delegate.h',
- 'system/locale/tray_locale.cc',
- 'system/locale/tray_locale.h',
+ 'system/locale/locale_notification_controller.cc',
+ 'system/locale/locale_notification_controller.h',
'system/logout_button/logout_button_observer.h',
'system/logout_button/tray_logout_button.cc',
'system/logout_button/tray_logout_button.h',
diff --git a/ash/shell.cc b/ash/shell.cc
index 21d248e..0f641454 100644
--- a/ash/shell.cc
+++ b/ash/shell.cc
@@ -34,6 +34,7 @@
#include "ash/shell_delegate.h"
#include "ash/shell_factory.h"
#include "ash/shell_window_ids.h"
+#include "ash/system/locale/locale_notification_controller.h"
#include "ash/system/status_area_widget.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/system_tray_notifier.h"
@@ -279,6 +280,8 @@ Shell::~Shell() {
system_tray_delegate_->Shutdown();
system_tray_delegate_.reset();
+ locale_notification_controller_.reset();
+
// Destroy all child windows including widgets.
display_controller_->CloseChildWindows();
@@ -607,6 +610,9 @@ void Shell::Init() {
InitRootWindowController(root_window_controller,
delegate_->IsFirstRunAfterBoot());
+ locale_notification_controller_.reset(
+ new internal::LocaleNotificationController);
+
// Initialize system_tray_delegate_ after StatusAreaWidget is created.
system_tray_delegate_->Initialize();
diff --git a/ash/shell.h b/ash/shell.h
index 69b8970e..7f31c8d 100644
--- a/ash/shell.h
+++ b/ash/shell.h
@@ -111,6 +111,7 @@ class EventClientImpl;
class EventRewriterEventFilter;
class EventTransformationHandler;
class FocusCycler;
+class LocaleNotificationController;
class MouseCursorEventFilter;
class OutputConfiguratorAnimation;
class OverlayEventFilter;
@@ -583,6 +584,9 @@ class ASH_EXPORT Shell
scoped_ptr<internal::DisplayManager> display_manager_;
+ scoped_ptr<internal::LocaleNotificationController>
+ locale_notification_controller_;
+
#if defined(OS_CHROMEOS) && defined(USE_X11)
// Controls video output device state.
scoped_ptr<chromeos::OutputConfigurator> output_configurator_;
diff --git a/ash/system/locale/locale_notification_controller.cc b/ash/system/locale/locale_notification_controller.cc
new file mode 100644
index 0000000..bc515e9
--- /dev/null
+++ b/ash/system/locale/locale_notification_controller.cc
@@ -0,0 +1,123 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/system/locale/locale_notification_controller.h"
+
+#include "ash/shell.h"
+#include "ash/system/tray/system_tray_notifier.h"
+#include "base/strings/string16.h"
+#include "grit/ash_strings.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/message_center/message_center.h"
+#include "ui/message_center/notification.h"
+#include "ui/message_center/notification_delegate.h"
+#include "ui/message_center/notification_types.h"
+
+using message_center::Notification;
+
+namespace ash {
+namespace internal {
+namespace {
+
+const char kLocaleChangeNotificationId[] = "chrome://settings/locale";
+
+class LocaleNotificationDelegate : public message_center::NotificationDelegate {
+ public:
+ explicit LocaleNotificationDelegate(LocaleObserver::Delegate* delegate);
+
+ protected:
+ virtual ~LocaleNotificationDelegate();
+
+ // message_center::NotificationDelegate overrides:
+ virtual void Display() OVERRIDE;
+ virtual void Error() OVERRIDE;
+ virtual void Close(bool by_user) OVERRIDE;
+ virtual bool HasClickedListener() OVERRIDE;
+ virtual void Click() OVERRIDE;
+ virtual void ButtonClick(int button_index) OVERRIDE;
+
+ private:
+ LocaleObserver::Delegate* delegate_;
+
+ DISALLOW_COPY_AND_ASSIGN(LocaleNotificationDelegate);
+};
+
+LocaleNotificationDelegate::LocaleNotificationDelegate(
+ LocaleObserver::Delegate* delegate)
+ : delegate_(delegate) {
+ DCHECK(delegate_);
+}
+
+LocaleNotificationDelegate::~LocaleNotificationDelegate() {
+}
+
+void LocaleNotificationDelegate::Display() {
+}
+
+void LocaleNotificationDelegate::Error() {
+}
+
+void LocaleNotificationDelegate::Close(bool by_user) {
+ delegate_->AcceptLocaleChange();
+}
+
+bool LocaleNotificationDelegate::HasClickedListener() {
+ return false;
+}
+
+void LocaleNotificationDelegate::Click() {
+}
+
+void LocaleNotificationDelegate::ButtonClick(int button_index) {
+ DCHECK_EQ(0, button_index);
+ delegate_->RevertLocaleChange();
+}
+
+} // namespace
+
+LocaleNotificationController::LocaleNotificationController()
+ : delegate_(NULL) {
+ Shell::GetInstance()->system_tray_notifier()->AddLocaleObserver(this);
+}
+
+LocaleNotificationController::~LocaleNotificationController() {
+ Shell::GetInstance()->system_tray_notifier()->RemoveLocaleObserver(this);
+}
+
+void LocaleNotificationController::OnLocaleChanged(
+ LocaleObserver::Delegate* delegate,
+ const std::string& cur_locale,
+ const std::string& from_locale,
+ const std::string& to_locale) {
+ if (!delegate)
+ return;
+
+ base::string16 from = l10n_util::GetDisplayNameForLocale(
+ from_locale, cur_locale, true);
+ base::string16 to = l10n_util::GetDisplayNameForLocale(
+ to_locale, cur_locale, true);
+
+ message_center::RichNotificationData optional;
+ optional.buttons.push_back(message_center::ButtonInfo(
+ l10n_util::GetStringFUTF16(
+ IDS_ASH_STATUS_TRAY_LOCALE_REVERT_MESSAGE, from)));
+ optional.never_timeout = true;
+
+ scoped_ptr<Notification> notification(new Notification(
+ message_center::NOTIFICATION_TYPE_SIMPLE,
+ kLocaleChangeNotificationId,
+ l10n_util::GetStringFUTF16(
+ IDS_ASH_STATUS_TRAY_LOCALE_CHANGE_MESSAGE, from, to),
+ base::string16() /* message */,
+ // TODO(mukai): add the icon here. see crbug.com/262393
+ gfx::Image() /* icon */,
+ base::string16() /* display_source */,
+ std::string() /* extension_id */,
+ optional,
+ new LocaleNotificationDelegate(delegate)));
+ message_center::MessageCenter::Get()->AddNotification(notification.Pass());
+}
+
+} // namespace internal
+} // namespace ash
diff --git a/ash/system/locale/locale_notification_controller.h b/ash/system/locale/locale_notification_controller.h
new file mode 100644
index 0000000..d23895c
--- /dev/null
+++ b/ash/system/locale/locale_notification_controller.h
@@ -0,0 +1,41 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ASH_SYSTEM_LOCALE_LOCALE_NOTIFICATION_CONTROLLER_H_
+#define ASH_SYSTEM_LOCALE_LOCALE_NOTIFICATION_CONTROLLER_H_
+
+#include <string>
+
+#include "ash/system/locale/locale_observer.h"
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+
+namespace ash {
+namespace internal {
+
+// Observes the locale change and creates rich notification for the change.
+class LocaleNotificationController : public LocaleObserver {
+ public:
+ LocaleNotificationController();
+ virtual ~LocaleNotificationController();
+
+ private:
+ // Overridden from LocaleObserver.
+ virtual void OnLocaleChanged(LocaleObserver::Delegate* delegate,
+ const std::string& cur_locale,
+ const std::string& from_locale,
+ const std::string& to_locale) OVERRIDE;
+
+ LocaleObserver::Delegate* delegate_;
+ std::string cur_locale_;
+ std::string from_locale_;
+ std::string to_locale_;
+
+ DISALLOW_COPY_AND_ASSIGN(LocaleNotificationController);
+};
+
+} // namespace internal
+} // namespace ash
+
+#endif // ASH_SYSTEM_LOCALE_LOCALE_NOTIFICATION_CONTROLLER_H_
diff --git a/ash/system/locale/tray_locale.cc b/ash/system/locale/tray_locale.cc
deleted file mode 100644
index 8a59fcc..0000000
--- a/ash/system/locale/tray_locale.cc
+++ /dev/null
@@ -1,152 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "ash/system/locale/tray_locale.h"
-
-#include "ash/shell.h"
-#include "ash/system/tray/system_tray_notifier.h"
-#include "ash/system/tray/tray_constants.h"
-#include "ash/system/tray/tray_notification_view.h"
-#include "base/strings/string16.h"
-#include "grit/ash_resources.h"
-#include "grit/ash_strings.h"
-#include "ui/base/l10n/l10n_util.h"
-#include "ui/base/resource/resource_bundle.h"
-#include "ui/views/controls/label.h"
-#include "ui/views/controls/link.h"
-#include "ui/views/controls/link_listener.h"
-#include "ui/views/layout/box_layout.h"
-#include "ui/views/view.h"
-
-namespace ash {
-namespace internal {
-
-namespace tray {
-
-class LocaleMessageView : public views::View,
- public views::LinkListener {
- public:
- LocaleMessageView(LocaleObserver::Delegate* delegate,
- const std::string& cur_locale,
- const std::string& from_locale,
- const std::string& to_locale)
- : delegate_(delegate) {
- SetLayoutManager(
- new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1));
-
- base::string16 from = l10n_util::GetDisplayNameForLocale(
- from_locale, cur_locale, true);
- base::string16 to = l10n_util::GetDisplayNameForLocale(
- to_locale, cur_locale, true);
-
- views::Label* message = new views::Label(
- l10n_util::GetStringFUTF16(
- IDS_ASH_STATUS_TRAY_LOCALE_CHANGE_MESSAGE, from, to));
- message->SetHorizontalAlignment(gfx::ALIGN_LEFT);
- message->SetMultiLine(true);
- message->SizeToFit(kTrayNotificationContentsWidth);
- AddChildView(message);
-
- views::Link* revert = new views::Link(
- l10n_util::GetStringFUTF16(
- IDS_ASH_STATUS_TRAY_LOCALE_REVERT_MESSAGE, from));
- revert->set_listener(this);
- revert->SetHorizontalAlignment(gfx::ALIGN_LEFT);
- revert->SetMultiLine(true);
- revert->SizeToFit(kTrayNotificationContentsWidth);
- AddChildView(revert);
- }
-
- virtual ~LocaleMessageView() {}
-
- // Overridden from views::LinkListener.
- virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE {
- if (delegate_)
- delegate_->RevertLocaleChange();
- }
-
- private:
- LocaleObserver::Delegate* delegate_;
-
- DISALLOW_COPY_AND_ASSIGN(LocaleMessageView);
-};
-
-class LocaleNotificationView : public TrayNotificationView {
- public:
- LocaleNotificationView(TrayLocale* owner,
- LocaleObserver::Delegate* delegate,
- const std::string& cur_locale,
- const std::string& from_locale,
- const std::string& to_locale)
- : TrayNotificationView(owner, IDR_AURA_UBER_TRAY_LOCALE),
- delegate_(delegate) {
- views::View* container = new LocaleMessageView(
- delegate, cur_locale, from_locale, to_locale);
- InitView(container);
- }
-
- void Update(LocaleObserver::Delegate* delegate,
- const std::string& cur_locale,
- const std::string& from_locale,
- const std::string& to_locale) {
- delegate_ = delegate;
- views::View* container = new LocaleMessageView(
- delegate, cur_locale, from_locale, to_locale);
- UpdateView(container);
- }
-
- // Overridden from TrayNotificationView.
- virtual void OnClose() OVERRIDE {
- if (delegate_)
- delegate_->AcceptLocaleChange();
- }
-
- private:
- LocaleObserver::Delegate* delegate_;
-
- DISALLOW_COPY_AND_ASSIGN(LocaleNotificationView);
-};
-
-} // namespace tray
-
-TrayLocale::TrayLocale(SystemTray* system_tray)
- : SystemTrayItem(system_tray),
- notification_(NULL),
- delegate_(NULL) {
- Shell::GetInstance()->system_tray_notifier()->AddLocaleObserver(this);
-}
-
-TrayLocale::~TrayLocale() {
- Shell::GetInstance()->system_tray_notifier()->RemoveLocaleObserver(this);
-}
-
-views::View* TrayLocale::CreateNotificationView(user::LoginStatus status) {
- if (!delegate_)
- return NULL;
- CHECK(notification_ == NULL);
- notification_ = new tray::LocaleNotificationView(
- this, delegate_, cur_locale_, from_locale_, to_locale_);
- return notification_;
-}
-
-void TrayLocale::DestroyNotificationView() {
- notification_ = NULL;
-}
-
-void TrayLocale::OnLocaleChanged(LocaleObserver::Delegate* delegate,
- const std::string& cur_locale,
- const std::string& from_locale,
- const std::string& to_locale) {
- delegate_ = delegate;
- cur_locale_ = cur_locale;
- from_locale_ = from_locale;
- to_locale_ = to_locale;
- if (notification_)
- notification_->Update(delegate, cur_locale_, from_locale_, to_locale_);
- else
- ShowNotificationView();
-}
-
-} // namespace internal
-} // namespace ash
diff --git a/ash/system/locale/tray_locale.h b/ash/system/locale/tray_locale.h
deleted file mode 100644
index d4a6611..0000000
--- a/ash/system/locale/tray_locale.h
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef ASH_SYSTEM_LOCALE_TRAY_LOCALE_H_
-#define ASH_SYSTEM_LOCALE_TRAY_LOCALE_H_
-
-#include <string>
-
-#include "ash/system/locale/locale_observer.h"
-#include "ash/system/tray/system_tray_item.h"
-
-namespace ash {
-namespace internal {
-
-namespace tray {
-class LocaleNotificationView;
-}
-
-class TrayLocale : public SystemTrayItem,
- public LocaleObserver {
- public:
- explicit TrayLocale(SystemTray* system_tray);
- virtual ~TrayLocale();
-
- private:
- // Overridden from TrayImageItem.
- virtual views::View* CreateNotificationView(
- user::LoginStatus status) OVERRIDE;
- virtual void DestroyNotificationView() OVERRIDE;
-
- // Overridden from LocaleObserver.
- virtual void OnLocaleChanged(LocaleObserver::Delegate* delegate,
- const std::string& cur_locale,
- const std::string& from_locale,
- const std::string& to_locale) OVERRIDE;
-
- tray::LocaleNotificationView* notification_;
- LocaleObserver::Delegate* delegate_;
- std::string cur_locale_;
- std::string from_locale_;
- std::string to_locale_;
-
- DISALLOW_COPY_AND_ASSIGN(TrayLocale);
-};
-
-} // namespace internal
-} // namespace ash
-
-#endif // ASH_SYSTEM_LOCALE_TRAY_LOCALE_H_
diff --git a/ash/system/tray/system_tray.cc b/ash/system/tray/system_tray.cc
index fd70090..dcb0346 100644
--- a/ash/system/tray/system_tray.cc
+++ b/ash/system/tray/system_tray.cc
@@ -14,7 +14,6 @@
#include "ash/system/date/tray_date.h"
#include "ash/system/drive/tray_drive.h"
#include "ash/system/ime/tray_ime.h"
-#include "ash/system/locale/tray_locale.h"
#include "ash/system/logout_button/tray_logout_button.h"
#include "ash/system/monitor/tray_monitor.h"
#include "ash/system/session_length_limit/tray_session_length_limit.h"
@@ -179,7 +178,6 @@ void SystemTray::CreateItems(SystemTrayDelegate* delegate) {
AddTrayItem(new internal::TrayBluetooth(this));
#endif
AddTrayItem(new internal::TrayDrive(this));
- AddTrayItem(new internal::TrayLocale(this));
#if defined(OS_CHROMEOS)
AddTrayItem(new internal::TrayDisplay(this));
AddTrayItem(new internal::ScreenCaptureTrayItem(this));