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

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

Issue 10443004: Move common notification layout to base class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase 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/network/tray_network.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/system/locale/tray_locale.h" 5 #include "ash/system/locale/tray_locale.h"
6 6
7 #include "ash/system/tray/tray_constants.h"
7 #include "ash/system/tray/tray_views.h" 8 #include "ash/system/tray/tray_views.h"
8 #include "base/string16.h" 9 #include "base/string16.h"
9 #include "grit/ash_strings.h" 10 #include "grit/ash_strings.h"
10 #include "grit/ui_resources.h" 11 #include "grit/ui_resources.h"
11 #include "ui/base/l10n/l10n_util.h" 12 #include "ui/base/l10n/l10n_util.h"
13 #include "ui/base/resource/resource_bundle.h"
12 #include "ui/views/view.h" 14 #include "ui/views/view.h"
13 #include "ui/views/controls/label.h" 15 #include "ui/views/controls/label.h"
14 #include "ui/views/controls/link.h" 16 #include "ui/views/controls/link.h"
15 #include "ui/views/controls/link_listener.h" 17 #include "ui/views/controls/link_listener.h"
18 #include "ui/views/layout/box_layout.h"
16 19
17 namespace ash { 20 namespace ash {
18 namespace internal { 21 namespace internal {
19 22
20 namespace tray { 23 namespace tray {
21 24
22 class LocaleNotificationView : public TrayNotificationView, 25 class LocaleMessageView : public views::View,
23 public views::LinkListener { 26 public views::LinkListener {
24 public: 27 public:
25 LocaleNotificationView(TrayLocale* tray, 28 LocaleMessageView(LocaleObserver::Delegate* delegate,
26 LocaleObserver::Delegate* delegate, 29 const std::string& cur_locale,
27 const std::string& cur_locale, 30 const std::string& from_locale,
28 const std::string& from_locale, 31 const std::string& to_locale)
29 const std::string& to_locale) 32 : delegate_(delegate) {
30 : tray_(tray), 33 SetLayoutManager(
31 delegate_(delegate) { 34 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1));
35
32 string16 from = l10n_util::GetDisplayNameForLocale( 36 string16 from = l10n_util::GetDisplayNameForLocale(
33 from_locale, cur_locale, true); 37 from_locale, cur_locale, true);
34 string16 to = l10n_util::GetDisplayNameForLocale( 38 string16 to = l10n_util::GetDisplayNameForLocale(
35 to_locale, cur_locale, true); 39 to_locale, cur_locale, true);
36 40
37 views::View* container = new views::View;
38
39 views::Label* message = new views::Label( 41 views::Label* message = new views::Label(
40 l10n_util::GetStringFUTF16( 42 l10n_util::GetStringFUTF16(
41 IDS_ASH_STATUS_TRAY_LOCALE_CHANGE_MESSAGE, from, to)); 43 IDS_ASH_STATUS_TRAY_LOCALE_CHANGE_MESSAGE, from, to));
42 container->AddChildView(message); 44 message->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
45 message->SetMultiLine(true);
46 message->SizeToFit(kTrayNotificationContentsWidth);
47 AddChildView(message);
43 48
44 views::Link* revert = new views::Link( 49 views::Link* revert = new views::Link(
45 l10n_util::GetStringFUTF16( 50 l10n_util::GetStringFUTF16(
46 IDS_ASH_STATUS_TRAY_LOCALE_REVERT_MESSAGE, from)); 51 IDS_ASH_STATUS_TRAY_LOCALE_REVERT_MESSAGE, from));
47 container->AddChildView(revert); 52 revert->set_listener(this);
53 revert->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
54 revert->SetMultiLine(true);
55 revert->SizeToFit(kTrayNotificationContentsWidth);
56 AddChildView(revert);
57 }
48 58
49 InitView(container); 59 virtual ~LocaleMessageView() {}
50 }
51 60
52 // Overridden from views::LinkListener. 61 // Overridden from views::LinkListener.
53 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE { 62 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE {
54 if (delegate_) 63 if (delegate_)
55 delegate_->RevertLocaleChange(); 64 delegate_->RevertLocaleChange();
56 } 65 }
57 66
67 private:
68 LocaleObserver::Delegate* delegate_;
69
70 DISALLOW_COPY_AND_ASSIGN(LocaleMessageView);
71 };
72
73 class LocaleNotificationView : public TrayNotificationView {
74 public:
75 LocaleNotificationView(TrayLocale* tray,
76 LocaleObserver::Delegate* delegate,
77 const std::string& cur_locale,
78 const std::string& from_locale,
79 const std::string& to_locale)
80 : TrayNotificationView(IDR_AURA_UBER_TRAY_LOCALE),
81 tray_(tray),
82 delegate_(delegate) {
83 views::View* container = new LocaleMessageView(
84 delegate, cur_locale, from_locale, to_locale);
85 InitView(container);
86 }
87
88 void Update(LocaleObserver::Delegate* delegate,
89 const std::string& cur_locale,
90 const std::string& from_locale,
91 const std::string& to_locale) {
92 delegate_ = delegate;
93 views::View* container = new LocaleMessageView(
94 delegate, cur_locale, from_locale, to_locale);
95 UpdateView(container);
96 }
97
58 // Overridden from TrayNotificationView. 98 // Overridden from TrayNotificationView.
59 virtual void OnClose() OVERRIDE { 99 virtual void OnClose() OVERRIDE {
60 if (delegate_) 100 if (delegate_)
61 delegate_->AcceptLocaleChange(); 101 delegate_->AcceptLocaleChange();
62 tray_->HideNotificationView(); 102 tray_->HideNotificationView();
63 } 103 }
64 104
65 private: 105 private:
66 TrayLocale* tray_; 106 TrayLocale* tray_;
67 LocaleObserver::Delegate* delegate_; 107 LocaleObserver::Delegate* delegate_;
68 108
69 DISALLOW_COPY_AND_ASSIGN(LocaleNotificationView); 109 DISALLOW_COPY_AND_ASSIGN(LocaleNotificationView);
70 }; 110 };
71 111
72
73 } // namespace tray 112 } // namespace tray
74 113
75 TrayLocale::TrayLocale() 114 TrayLocale::TrayLocale()
76 : TrayImageItem(IDR_AURA_UBER_TRAY_LOCALE), 115 : notification_(NULL),
77 notification_(NULL),
78 delegate_(NULL) { 116 delegate_(NULL) {
79 } 117 }
80 118
81 TrayLocale::~TrayLocale() { 119 TrayLocale::~TrayLocale() {
82 } 120 }
83 121
84 bool TrayLocale::GetInitialVisibility() {
85 return notification_ != NULL;
86 }
87
88 views::View* TrayLocale::CreateNotificationView(user::LoginStatus status) { 122 views::View* TrayLocale::CreateNotificationView(user::LoginStatus status) {
89 if (!delegate_) 123 if (!delegate_)
90 return NULL; 124 return NULL;
91 CHECK(notification_ == NULL); 125 CHECK(notification_ == NULL);
92 notification_ = new tray::LocaleNotificationView( 126 notification_ = new tray::LocaleNotificationView(
93 this, delegate_, cur_locale_, from_locale_, to_locale_); 127 this, delegate_, cur_locale_, from_locale_, to_locale_);
94 return notification_; 128 return notification_;
95 } 129 }
96 130
97 void TrayLocale::DestroyNotificationView() { 131 void TrayLocale::DestroyNotificationView() {
98 notification_ = NULL; 132 notification_ = NULL;
99 } 133 }
100 134
101 void TrayLocale::OnLocaleChanged(LocaleObserver::Delegate* delegate, 135 void TrayLocale::OnLocaleChanged(LocaleObserver::Delegate* delegate,
102 const std::string& cur_locale, 136 const std::string& cur_locale,
103 const std::string& from_locale, 137 const std::string& from_locale,
104 const std::string& to_locale) { 138 const std::string& to_locale) {
105 if (notification_)
106 HideNotificationView();
107 delegate_ = delegate; 139 delegate_ = delegate;
108 cur_locale_ = cur_locale; 140 cur_locale_ = cur_locale;
109 from_locale_ = from_locale; 141 from_locale_ = from_locale;
110 to_locale_ = to_locale; 142 to_locale_ = to_locale;
111 ShowNotificationView(); 143 if (notification_)
144 notification_->Update(delegate, cur_locale_, from_locale_, to_locale_);
145 else
146 ShowNotificationView();
112 } 147 }
113 148
114 } // namespace internal 149 } // namespace internal
115 } // namespace ash 150 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/locale/tray_locale.h ('k') | ash/system/network/tray_network.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698