Chromium Code Reviews| Index: ash/system/locale/tray_locale.cc |
| diff --git a/ash/system/locale/tray_locale.cc b/ash/system/locale/tray_locale.cc |
| index 61f80d7d87a108833effaf97a22d406b43e6b4d7..ccd85838cc4988794d0a66aaca9e346f7817e175 100644 |
| --- a/ash/system/locale/tray_locale.cc |
| +++ b/ash/system/locale/tray_locale.cc |
| @@ -4,57 +4,97 @@ |
| #include "ash/system/locale/tray_locale.h" |
| +#include "ash/system/tray/tray_constants.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/base/resource/resource_bundle.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" |
| +#include "ui/views/layout/box_layout.h" |
| namespace ash { |
| namespace internal { |
| namespace tray { |
| -class LocaleNotificationView : public TrayNotificationView, |
| - public views::LinkListener { |
| +class LocaleMessageView : public views::View, |
| + 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) { |
| + LocaleMessageView(LocaleObserver::Delegate* delegate, |
| + const std::string& cur_locale, |
|
jennyz
2012/05/24 16:55:15
Should this be aligned with the previous argument?
stevenjb
2012/05/24 16:58:30
Oops, thanks. Done.
|
| + const std::string& from_locale, |
| + const std::string& to_locale) |
| + : delegate_(delegate) { |
| + SetLayoutManager( |
| + new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); |
| + |
| 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); |
| + message->SetHorizontalAlignment(views::Label::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)); |
| - container->AddChildView(revert); |
| - |
| - InitView(container); |
| + revert->set_listener(this); |
| + revert->SetHorizontalAlignment(views::Label::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* tray, |
| + LocaleObserver::Delegate* delegate, |
| + const std::string& cur_locale, |
| + const std::string& from_locale, |
| + const std::string& to_locale) |
| + : TrayNotificationView(IDR_AURA_UBER_TRAY_LOCALE), |
| + tray_(tray), |
| + 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_) |
| @@ -69,12 +109,10 @@ class LocaleNotificationView : public TrayNotificationView, |
| DISALLOW_COPY_AND_ASSIGN(LocaleNotificationView); |
| }; |
| - |
| } // namespace tray |
| TrayLocale::TrayLocale() |
| - : TrayImageItem(IDR_AURA_UBER_TRAY_LOCALE), |
| - notification_(NULL), |
| + : notification_(NULL), |
| delegate_(NULL) { |
| } |
| @@ -102,13 +140,14 @@ 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(); |
| + if (notification_) |
| + notification_->Update(delegate, cur_locale_, from_locale_, to_locale_); |
| + else |
| + ShowNotificationView(); |
| } |
| } // namespace internal |