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

Unified Diff: ash/system/tray_locale.cc

Issue 10391177: Add TrayLocale for locale change notifications. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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
Index: ash/system/tray_locale.cc
diff --git a/ash/system/tray_locale.cc b/ash/system/tray_locale.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ebf7a8ad302517fba6305627183c2f4321fdf39f
--- /dev/null
+++ b/ash/system/tray_locale.cc
@@ -0,0 +1,116 @@
+// 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/tray_locale.h"
+
+#include "ash/system/tray/tray_views.h"
+#include "base/string16.h"
+#include "grit/ash_strings.h"
+#include "grit/ui_resources.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/views/view.h"
+#include "ui/views/controls/label.h"
+#include "ui/views/controls/link.h"
+#include "ui/views/controls/link_listener.h"
+
+namespace ash {
+namespace internal {
+
+namespace tray {
+
+class LocaleNotificationView : public TrayNotificationView,
+ public views::LinkListener {
+ public:
+ LocaleNotificationView(TrayLocale* tray,
+ LocaleChangeDelegate* delegate,
+ const std::string& cur_locale,
+ const std::string& from_locale,
+ const std::string& to_locale)
+ : tray_(tray),
+ delegate_(delegate) {
+
sadrul 2012/05/17 03:15:44 -blank line
stevenjb 2012/05/17 16:58:57 Done.
+ string16 from = l10n_util::GetDisplayNameForLocale(
+ from_locale, cur_locale, true);
+ string16 to = l10n_util::GetDisplayNameForLocale(
+ to_locale, cur_locale, true);
+
+ views::View* container = new views::View;
+
+ views::Label* message = new views::Label(
+ l10n_util::GetStringFUTF16(
+ IDS_ASH_STATUS_TRAY_LOCALE_CHANGE_MESSAGE, from, to));
+ container->AddChildView(message);
+
+ views::Link* revert = new views::Link(
+ l10n_util::GetStringFUTF16(
+ IDS_ASH_STATUS_TRAY_LOCALE_REVERT_MESSAGE, from));
+ container->AddChildView(revert);
+
+ InitView(container);
+ }
+
+ // Overridden from views::LinkListener.
+ virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE {
+ if (delegate_)
+ delegate_->RevertLocaleChange();
+ }
+
+ // Overridden from TrayNotificationView:
sadrul 2012/05/17 03:15:44 '.' at the end (or ':' at the end in line 53)
stevenjb 2012/05/17 16:58:57 Done.
+ virtual void OnClose() OVERRIDE {
+ if (delegate_)
+ delegate_->AcceptLocaleChange();
+ tray_->HideNotificationView();
+ }
+
+ private:
+ TrayLocale* tray_;
+ LocaleChangeDelegate* delegate_;
+
+ DISALLOW_COPY_AND_ASSIGN(LocaleNotificationView);
+};
+
+
+} // namespace tray
+
+TrayLocale::TrayLocale()
+ : TrayImageItem(IDR_AURA_UBER_TRAY_LOCALE),
+ notification_(NULL),
+ delegate_(NULL) {
+}
+
+TrayLocale::~TrayLocale() {
+}
+
+bool TrayLocale::GetInitialVisibility() {
+ return notification_ != NULL;
+}
+
+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(LocaleChangeDelegate* delegate,
+ const std::string& cur_locale,
+ const std::string& from_locale,
+ const std::string& to_locale) {
+ if (notification_)
+ HideNotificationView();
+ delegate_ = delegate;
+ cur_locale_ = cur_locale;
+ from_locale_ = from_locale;
+ to_locale_ = to_locale;
+ ShowNotificationView();
+}
+
+} // namespace internal
+} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698