diff options
author | stevenjb@google.com <stevenjb@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-17 18:48:37 +0000 |
---|---|---|
committer | stevenjb@google.com <stevenjb@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-17 18:48:37 +0000 |
commit | 56dbdd015fb53a095b2fa598650239f75c2cf5b2 (patch) | |
tree | 60b5758f96bde48fbe8f397e73492cdb93783db6 /ash/system/locale | |
parent | 89019d6a0e32e517da3aa7f84125ff3bcd69109f (diff) | |
download | chromium_src-56dbdd015fb53a095b2fa598650239f75c2cf5b2.zip chromium_src-56dbdd015fb53a095b2fa598650239f75c2cf5b2.tar.gz chromium_src-56dbdd015fb53a095b2fa598650239f75c2cf5b2.tar.bz2 |
Add TrayLocale for locale change notifications.
TBR=ben for ash/ string changes
BUG=124726
TEST=On a device wuth ash-notify enabled in about:flags, change the locale and re-login. Notification should appear. Revert should revert the change after re-login. If ignored, the notification should appear again after re-login. Closing the notification should clear it.
Review URL: https://chromiumcodereview.appspot.com/10391177
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137700 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/system/locale')
-rw-r--r-- | ash/system/locale/locale_observer.h | 33 | ||||
-rw-r--r-- | ash/system/locale/tray_locale.cc | 115 | ||||
-rw-r--r-- | ash/system/locale/tray_locale.h | 52 |
3 files changed, 200 insertions, 0 deletions
diff --git a/ash/system/locale/locale_observer.h b/ash/system/locale/locale_observer.h new file mode 100644 index 0000000..cec29d1 --- /dev/null +++ b/ash/system/locale/locale_observer.h @@ -0,0 +1,33 @@ +// 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_LOCALE_OBSERVER_H_ +#define ASH_SYSTEM_LOCALE_LOCALE_OBSERVER_H_ +#pragma once + +#include "ash/ash_export.h" + +namespace ash { + +class ASH_EXPORT LocaleObserver { + public: + class Delegate { + public: + virtual ~Delegate() {} + + virtual void AcceptLocaleChange() = 0; + virtual void RevertLocaleChange() = 0; + }; + + virtual ~LocaleObserver() {} + + virtual void OnLocaleChanged(Delegate* delegate, + const std::string& cur_locale, + const std::string& from_locale, + const std::string& to_locale) = 0; +}; + +} // namespace ash + +#endif // ASH_SYSTEM_LOCALE_LOCALE_OBSERVER_H_ diff --git a/ash/system/locale/tray_locale.cc b/ash/system/locale/tray_locale.cc new file mode 100644 index 0000000..61f80d7 --- /dev/null +++ b/ash/system/locale/tray_locale.cc @@ -0,0 +1,115 @@ +// 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/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, + LocaleObserver::Delegate* delegate, + const std::string& cur_locale, + const std::string& from_locale, + const std::string& to_locale) + : tray_(tray), + delegate_(delegate) { + 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. + virtual void OnClose() OVERRIDE { + if (delegate_) + delegate_->AcceptLocaleChange(); + tray_->HideNotificationView(); + } + + private: + TrayLocale* tray_; + LocaleObserver::Delegate* 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(LocaleObserver::Delegate* 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 diff --git a/ash/system/locale/tray_locale.h b/ash/system/locale/tray_locale.h new file mode 100644 index 0000000..c0d114c --- /dev/null +++ b/ash/system/locale/tray_locale.h @@ -0,0 +1,52 @@ +// 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_ +#pragma once + +#include <string> + +#include "ash/system/locale/locale_observer.h" +#include "ash/system/tray/tray_image_item.h" + +namespace ash { +namespace internal { + +namespace tray { +class LocaleNotificationView; +} + +class TrayLocale : public TrayImageItem, + public LocaleObserver { + public: + TrayLocale(); + virtual ~TrayLocale(); + + private: + // Overridden from TrayImageItem. + virtual bool GetInitialVisibility() OVERRIDE; + 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_ |