OLD | NEW |
---|---|
(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/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 LocaleChangeDelegate* 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 | |
sadrul
2012/05/17 03:15:44
-blank line
stevenjb
2012/05/17 16:58:57
Done.
| |
33 string16 from = l10n_util::GetDisplayNameForLocale( | |
34 from_locale, cur_locale, true); | |
35 string16 to = l10n_util::GetDisplayNameForLocale( | |
36 to_locale, cur_locale, true); | |
37 | |
38 views::View* container = new views::View; | |
39 | |
40 views::Label* message = new views::Label( | |
41 l10n_util::GetStringFUTF16( | |
42 IDS_ASH_STATUS_TRAY_LOCALE_CHANGE_MESSAGE, from, to)); | |
43 container->AddChildView(message); | |
44 | |
45 views::Link* revert = new views::Link( | |
46 l10n_util::GetStringFUTF16( | |
47 IDS_ASH_STATUS_TRAY_LOCALE_REVERT_MESSAGE, from)); | |
48 container->AddChildView(revert); | |
49 | |
50 InitView(container); | |
51 } | |
52 | |
53 // Overridden from views::LinkListener. | |
54 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE { | |
55 if (delegate_) | |
56 delegate_->RevertLocaleChange(); | |
57 } | |
58 | |
59 // 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.
| |
60 virtual void OnClose() OVERRIDE { | |
61 if (delegate_) | |
62 delegate_->AcceptLocaleChange(); | |
63 tray_->HideNotificationView(); | |
64 } | |
65 | |
66 private: | |
67 TrayLocale* tray_; | |
68 LocaleChangeDelegate* delegate_; | |
69 | |
70 DISALLOW_COPY_AND_ASSIGN(LocaleNotificationView); | |
71 }; | |
72 | |
73 | |
74 } // namespace tray | |
75 | |
76 TrayLocale::TrayLocale() | |
77 : TrayImageItem(IDR_AURA_UBER_TRAY_LOCALE), | |
78 notification_(NULL), | |
79 delegate_(NULL) { | |
80 } | |
81 | |
82 TrayLocale::~TrayLocale() { | |
83 } | |
84 | |
85 bool TrayLocale::GetInitialVisibility() { | |
86 return notification_ != NULL; | |
87 } | |
88 | |
89 views::View* TrayLocale::CreateNotificationView(user::LoginStatus status) { | |
90 if (!delegate_) | |
91 return NULL; | |
92 CHECK(notification_ == NULL); | |
93 notification_ = new tray::LocaleNotificationView( | |
94 this, delegate_, cur_locale_, from_locale_, to_locale_); | |
95 return notification_; | |
96 } | |
97 | |
98 void TrayLocale::DestroyNotificationView() { | |
99 notification_ = NULL; | |
100 } | |
101 | |
102 void TrayLocale::OnLocaleChanged(LocaleChangeDelegate* delegate, | |
103 const std::string& cur_locale, | |
104 const std::string& from_locale, | |
105 const std::string& to_locale) { | |
106 if (notification_) | |
107 HideNotificationView(); | |
108 delegate_ = delegate; | |
109 cur_locale_ = cur_locale; | |
110 from_locale_ = from_locale; | |
111 to_locale_ = to_locale; | |
112 ShowNotificationView(); | |
113 } | |
114 | |
115 } // namespace internal | |
116 } // namespace ash | |
OLD | NEW |