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

Side by Side Diff: ash/system/locale/tray_locale.cc

Issue 10391177: Add TrayLocale for locale change notifications. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase w/ icons in tot 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/system/locale/tray_locale.h ('k') | ash/system/tray/system_tray.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ash/system/locale/tray_locale.h"
6
7 #include "ash/system/tray/tray_views.h"
8 #include "base/string16.h"
9 #include "grit/ash_strings.h"
10 #include "grit/ui_resources.h"
11 #include "ui/base/l10n/l10n_util.h"
12 #include "ui/views/view.h"
13 #include "ui/views/controls/label.h"
14 #include "ui/views/controls/link.h"
15 #include "ui/views/controls/link_listener.h"
16
17 namespace ash {
18 namespace internal {
19
20 namespace tray {
21
22 class LocaleNotificationView : public TrayNotificationView,
23 public views::LinkListener {
24 public:
25 LocaleNotificationView(TrayLocale* tray,
26 LocaleObserver::Delegate* delegate,
27 const std::string& cur_locale,
28 const std::string& from_locale,
29 const std::string& to_locale)
30 : tray_(tray),
31 delegate_(delegate) {
32 string16 from = l10n_util::GetDisplayNameForLocale(
33 from_locale, cur_locale, true);
34 string16 to = l10n_util::GetDisplayNameForLocale(
35 to_locale, cur_locale, true);
36
37 views::View* container = new views::View;
38
39 views::Label* message = new views::Label(
40 l10n_util::GetStringFUTF16(
41 IDS_ASH_STATUS_TRAY_LOCALE_CHANGE_MESSAGE, from, to));
42 container->AddChildView(message);
43
44 views::Link* revert = new views::Link(
45 l10n_util::GetStringFUTF16(
46 IDS_ASH_STATUS_TRAY_LOCALE_REVERT_MESSAGE, from));
47 container->AddChildView(revert);
48
49 InitView(container);
50 }
51
52 // Overridden from views::LinkListener.
53 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE {
54 if (delegate_)
55 delegate_->RevertLocaleChange();
56 }
57
58 // Overridden from TrayNotificationView.
59 virtual void OnClose() OVERRIDE {
60 if (delegate_)
61 delegate_->AcceptLocaleChange();
62 tray_->HideNotificationView();
63 }
64
65 private:
66 TrayLocale* tray_;
67 LocaleObserver::Delegate* delegate_;
68
69 DISALLOW_COPY_AND_ASSIGN(LocaleNotificationView);
70 };
71
72
73 } // namespace tray
74
75 TrayLocale::TrayLocale()
76 : TrayImageItem(IDR_AURA_UBER_TRAY_LOCALE),
77 notification_(NULL),
78 delegate_(NULL) {
79 }
80
81 TrayLocale::~TrayLocale() {
82 }
83
84 bool TrayLocale::GetInitialVisibility() {
85 return notification_ != NULL;
86 }
87
88 views::View* TrayLocale::CreateNotificationView(user::LoginStatus status) {
89 if (!delegate_)
90 return NULL;
91 CHECK(notification_ == NULL);
92 notification_ = new tray::LocaleNotificationView(
93 this, delegate_, cur_locale_, from_locale_, to_locale_);
94 return notification_;
95 }
96
97 void TrayLocale::DestroyNotificationView() {
98 notification_ = NULL;
99 }
100
101 void TrayLocale::OnLocaleChanged(LocaleObserver::Delegate* delegate,
102 const std::string& cur_locale,
103 const std::string& from_locale,
104 const std::string& to_locale) {
105 if (notification_)
106 HideNotificationView();
107 delegate_ = delegate;
108 cur_locale_ = cur_locale;
109 from_locale_ = from_locale;
110 to_locale_ = to_locale;
111 ShowNotificationView();
112 }
113
114 } // namespace internal
115 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/locale/tray_locale.h ('k') | ash/system/tray/system_tray.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698