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

Side by Side Diff: ash/system/chromeos/network/tray_sms.cc

Issue 11415014: Stop using shell::GetInstance()->system_tray() in system tray items (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix single-letter typo :(. Created 8 years 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/chromeos/network/tray_sms.h ('k') | ash/system/chromeos/network/tray_vpn.h » ('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/chromeos/network/tray_sms.h" 5 #include "ash/system/chromeos/network/tray_sms.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/shell.h"
9 #include "ash/system/tray/system_tray.h" 8 #include "ash/system/tray/system_tray.h"
10 #include "ash/system/tray/tray_constants.h" 9 #include "ash/system/tray/tray_constants.h"
11 #include "ash/system/tray/tray_details_view.h" 10 #include "ash/system/tray/tray_details_view.h"
12 #include "ash/system/tray/tray_item_more.h" 11 #include "ash/system/tray/tray_item_more.h"
13 #include "ash/system/tray/tray_item_view.h" 12 #include "ash/system/tray/tray_item_view.h"
14 #include "ash/system/tray/tray_notification_view.h" 13 #include "ash/system/tray/tray_notification_view.h"
15 #include "ash/system/tray/tray_views.h" 14 #include "ash/system/tray/tray_views.h"
16 #include "base/command_line.h" 15 #include "base/command_line.h"
17 #include "base/string_number_conversions.h" 16 #include "base/string_number_conversions.h"
18 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
(...skipping 25 matching lines...) Expand all
44 return true; 43 return true;
45 } 44 }
46 45
47 } // namespace 46 } // namespace
48 47
49 namespace ash { 48 namespace ash {
50 namespace internal { 49 namespace internal {
51 50
52 class TraySms::SmsDefaultView : public TrayItemMore { 51 class TraySms::SmsDefaultView : public TrayItemMore {
53 public: 52 public:
54 explicit SmsDefaultView(TraySms* tray) 53 explicit SmsDefaultView(TraySms* owner)
55 : TrayItemMore(tray, true), 54 : TrayItemMore(owner, true) {
56 tray_(tray) {
57 SetImage(ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 55 SetImage(ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
58 IDR_AURA_UBER_TRAY_SMS)); 56 IDR_AURA_UBER_TRAY_SMS));
59 Update(); 57 Update();
60 } 58 }
61 59
62 virtual ~SmsDefaultView() {} 60 virtual ~SmsDefaultView() {}
63 61
64 void Update() { 62 void Update() {
65 int message_count = tray_->messages().GetSize(); 63 int message_count = static_cast<TraySms*>(owner())->messages().GetSize();
66 string16 label = l10n_util::GetStringFUTF16( 64 string16 label = l10n_util::GetStringFUTF16(
67 IDS_ASH_STATUS_TRAY_SMS_MESSAGES, base::IntToString16(message_count)); 65 IDS_ASH_STATUS_TRAY_SMS_MESSAGES, base::IntToString16(message_count));
68 SetLabel(label); 66 SetLabel(label);
69 SetAccessibleName(label); 67 SetAccessibleName(label);
70 } 68 }
71 69
72 private: 70 private:
73 TraySms* tray_;
74
75 DISALLOW_COPY_AND_ASSIGN(SmsDefaultView); 71 DISALLOW_COPY_AND_ASSIGN(SmsDefaultView);
76 }; 72 };
77 73
78 // An entry (row) in SmsDetailedView or NotificationView. 74 // An entry (row) in SmsDetailedView or NotificationView.
79 class TraySms::SmsMessageView : public views::View, 75 class TraySms::SmsMessageView : public views::View,
80 public views::ButtonListener { 76 public views::ButtonListener {
81 public: 77 public:
82 enum ViewType { 78 enum ViewType {
83 VIEW_DETAILED, 79 VIEW_DETAILED,
84 VIEW_NOTIFICATION 80 VIEW_NOTIFICATION
85 }; 81 };
86 82
87 SmsMessageView(TraySms* tray, 83 SmsMessageView(TraySms* owner,
88 ViewType view_type, 84 ViewType view_type,
89 size_t index, 85 size_t index,
90 const std::string& number, 86 const std::string& number,
91 const std::string& message) 87 const std::string& message)
92 : tray_(tray), 88 : owner_(owner),
93 index_(index) { 89 index_(index) {
94 number_label_ = new views::Label( 90 number_label_ = new views::Label(
95 l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_SMS_NUMBER, 91 l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_SMS_NUMBER,
96 UTF8ToUTF16(number))); 92 UTF8ToUTF16(number)));
97 number_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 93 number_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
98 number_label_->SetFont( 94 number_label_->SetFont(
99 number_label_->font().DeriveFont(0, gfx::Font::BOLD)); 95 number_label_->font().DeriveFont(0, gfx::Font::BOLD));
100 96
101 message_label_ = new views::Label(UTF8ToUTF16(message)); 97 message_label_ = new views::Label(UTF8ToUTF16(message));
102 message_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 98 message_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
103 message_label_->SetMultiLine(true); 99 message_label_->SetMultiLine(true);
104 100
105 if (view_type == VIEW_DETAILED) 101 if (view_type == VIEW_DETAILED)
106 LayoutDetailedView(); 102 LayoutDetailedView();
107 else 103 else
108 LayoutNotificationView(); 104 LayoutNotificationView();
109 } 105 }
110 106
111 virtual ~SmsMessageView() { 107 virtual ~SmsMessageView() {
112 } 108 }
113 109
114 // Overridden from ButtonListener. 110 // Overridden from ButtonListener.
115 virtual void ButtonPressed(views::Button* sender, 111 virtual void ButtonPressed(views::Button* sender,
116 const ui::Event& event) OVERRIDE { 112 const ui::Event& event) OVERRIDE {
117 tray_->RemoveMessage(index_); 113 owner_->RemoveMessage(index_);
118 tray_->Update(false); 114 owner_->Update(false);
119 } 115 }
120 116
121 private: 117 private:
122 void LayoutDetailedView() { 118 void LayoutDetailedView() {
123 views::ImageButton* close_button = new views::ImageButton(this); 119 views::ImageButton* close_button = new views::ImageButton(this);
124 close_button->SetImage(views::CustomButton::STATE_NORMAL, 120 close_button->SetImage(views::CustomButton::STATE_NORMAL,
125 ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 121 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
126 IDR_AURA_WINDOW_CLOSE)); 122 IDR_AURA_WINDOW_CLOSE));
127 123
128 int msg_width = kTrayPopupWidth - kNotificationIconWidth - 124 int msg_width = kTrayPopupWidth - kNotificationIconWidth -
(...skipping 29 matching lines...) Expand all
158 } 154 }
159 155
160 void LayoutNotificationView() { 156 void LayoutNotificationView() {
161 SetLayoutManager( 157 SetLayoutManager(
162 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); 158 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1));
163 AddChildView(number_label_); 159 AddChildView(number_label_);
164 message_label_->SizeToFit(kTrayNotificationContentsWidth); 160 message_label_->SizeToFit(kTrayNotificationContentsWidth);
165 AddChildView(message_label_); 161 AddChildView(message_label_);
166 } 162 }
167 163
168 TraySms* tray_; 164 TraySms* owner_;
169 size_t index_; 165 size_t index_;
170 views::Label* number_label_; 166 views::Label* number_label_;
171 views::Label* message_label_; 167 views::Label* message_label_;
172 168
173 DISALLOW_COPY_AND_ASSIGN(SmsMessageView); 169 DISALLOW_COPY_AND_ASSIGN(SmsMessageView);
174 }; 170 };
175 171
176 class TraySms::SmsDetailedView : public TrayDetailsView, 172 class TraySms::SmsDetailedView : public TrayDetailsView,
177 public ViewClickListener { 173 public ViewClickListener {
178 public: 174 public:
179 explicit SmsDetailedView(TraySms* tray) 175 explicit SmsDetailedView(TraySms* owner)
180 : tray_(tray) { 176 : TrayDetailsView(owner) {
181 Init(); 177 Init();
182 Update(); 178 Update();
183 } 179 }
184 180
185 virtual ~SmsDetailedView() { 181 virtual ~SmsDetailedView() {
186 } 182 }
187 183
188 void Init() { 184 void Init() {
189 CreateScrollableList(); 185 CreateScrollableList();
190 CreateSpecialRow(IDS_ASH_STATUS_TRAY_SMS, this); 186 CreateSpecialRow(IDS_ASH_STATUS_TRAY_SMS, this);
191 } 187 }
192 188
193 void Update() { 189 void Update() {
194 UpdateMessageList(); 190 UpdateMessageList();
195 Layout(); 191 Layout();
196 SchedulePaint(); 192 SchedulePaint();
197 } 193 }
198 194
199 // Overridden from views::View. 195 // Overridden from views::View.
200 gfx::Size GetPreferredSize() { 196 gfx::Size GetPreferredSize() {
201 gfx::Size preferred_size = TrayDetailsView::GetPreferredSize(); 197 gfx::Size preferred_size = TrayDetailsView::GetPreferredSize();
202 if (preferred_size.height() < kMessageListMinHeight) 198 if (preferred_size.height() < kMessageListMinHeight)
203 preferred_size.set_height(kMessageListMinHeight); 199 preferred_size.set_height(kMessageListMinHeight);
204 return preferred_size; 200 return preferred_size;
205 } 201 }
206 202
207 private: 203 private:
208 void UpdateMessageList() { 204 void UpdateMessageList() {
209 const base::ListValue& messages = tray_->messages(); 205 const base::ListValue& messages =
206 static_cast<TraySms*>(owner())->messages();
210 scroll_content()->RemoveAllChildViews(true); 207 scroll_content()->RemoveAllChildViews(true);
211 for (size_t index = 0; index < messages.GetSize(); ++index) { 208 for (size_t index = 0; index < messages.GetSize(); ++index) {
212 const base::DictionaryValue* message = NULL; 209 const base::DictionaryValue* message = NULL;
213 if (!messages.GetDictionary(index, &message)) { 210 if (!messages.GetDictionary(index, &message)) {
214 LOG(ERROR) << "SMS message not a dictionary at: " << index; 211 LOG(ERROR) << "SMS message not a dictionary at: " << index;
215 continue; 212 continue;
216 } 213 }
217 std::string number, text; 214 std::string number, text;
218 if (!GetMessageFromDictionary(message, &number, &text)) { 215 if (!GetMessageFromDictionary(message, &number, &text)) {
219 LOG(ERROR) << "Error parsing SMS message"; 216 LOG(ERROR) << "Error parsing SMS message";
220 continue; 217 continue;
221 } 218 }
222 SmsMessageView* msgview = new SmsMessageView( 219 SmsMessageView* msgview = new SmsMessageView(
223 tray_, SmsMessageView::VIEW_DETAILED, index, number, text); 220 static_cast<TraySms*>(owner()), SmsMessageView::VIEW_DETAILED, index,
221 number, text);
224 scroll_content()->AddChildView(msgview); 222 scroll_content()->AddChildView(msgview);
225 } 223 }
226 scroller()->Layout(); 224 scroller()->Layout();
227 } 225 }
228 226
229 // Overridden from ViewClickListener. 227 // Overridden from ViewClickListener.
230 virtual void ClickedOn(views::View* sender) OVERRIDE { 228 virtual void ClickedOn(views::View* sender) OVERRIDE {
231 if (sender == footer()->content()) 229 if (sender == footer()->content())
232 Shell::GetInstance()->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING); 230 owner()->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING);
233 } 231 }
234 232
235 TraySms* tray_;
236
237 DISALLOW_COPY_AND_ASSIGN(SmsDetailedView); 233 DISALLOW_COPY_AND_ASSIGN(SmsDetailedView);
238 }; 234 };
239 235
240 class TraySms::SmsNotificationView : public TrayNotificationView { 236 class TraySms::SmsNotificationView : public TrayNotificationView {
241 public: 237 public:
242 SmsNotificationView(TraySms* tray, 238 SmsNotificationView(TraySms* owner,
243 size_t message_index, 239 size_t message_index,
244 const std::string& number, 240 const std::string& number,
245 const std::string& text) 241 const std::string& text)
246 : TrayNotificationView(tray, IDR_AURA_UBER_TRAY_SMS), 242 : TrayNotificationView(owner, IDR_AURA_UBER_TRAY_SMS),
247 message_index_(message_index) { 243 message_index_(message_index) {
248 SmsMessageView* message_view = new SmsMessageView( 244 SmsMessageView* message_view = new SmsMessageView(
249 tray, SmsMessageView::VIEW_NOTIFICATION, message_index_, number, text); 245 owner, SmsMessageView::VIEW_NOTIFICATION, message_index_, number, text);
250 InitView(message_view); 246 InitView(message_view);
251 } 247 }
252 248
253 void Update(size_t message_index, 249 void Update(size_t message_index,
254 const std::string& number, 250 const std::string& number,
255 const std::string& text) { 251 const std::string& text) {
256 SmsMessageView* message_view = new SmsMessageView( 252 SmsMessageView* message_view = new SmsMessageView(
257 tray_sms(), SmsMessageView::VIEW_NOTIFICATION, 253 tray_sms(), SmsMessageView::VIEW_NOTIFICATION,
258 message_index_, number, text); 254 message_index_, number, text);
259 UpdateView(message_view); 255 UpdateView(message_view);
260 } 256 }
261 257
262 // Overridden from TrayNotificationView: 258 // Overridden from TrayNotificationView:
263 virtual void OnClose() OVERRIDE { 259 virtual void OnClose() OVERRIDE {
264 tray_sms()->RemoveMessage(message_index_); 260 tray_sms()->RemoveMessage(message_index_);
265 } 261 }
266 262
267 virtual void OnClickAction() OVERRIDE { 263 virtual void OnClickAction() OVERRIDE {
268 tray()->PopupDetailedView(0, true); 264 owner()->PopupDetailedView(0, true);
269 } 265 }
270 266
271 private: 267 private:
272 TraySms* tray_sms() { 268 TraySms* tray_sms() {
273 return static_cast<TraySms*>(tray()); 269 return static_cast<TraySms*>(owner());
274 } 270 }
275 271
276 size_t message_index_; 272 size_t message_index_;
277 273
278 DISALLOW_COPY_AND_ASSIGN(SmsNotificationView); 274 DISALLOW_COPY_AND_ASSIGN(SmsNotificationView);
279 }; 275 };
280 276
281 TraySms::TraySms() 277 TraySms::TraySms(SystemTray* system_tray)
282 : default_(NULL), 278 : SystemTrayItem(system_tray),
279 default_(NULL),
283 detailed_(NULL), 280 detailed_(NULL),
284 notification_(NULL) { 281 notification_(NULL) {
285 } 282 }
286 283
287 TraySms::~TraySms() { 284 TraySms::~TraySms() {
288 } 285 }
289 286
290 views::View* TraySms::CreateDefaultView(user::LoginStatus status) { 287 views::View* TraySms::CreateDefaultView(user::LoginStatus status) {
291 CHECK(default_ == NULL); 288 CHECK(default_ == NULL);
292 default_ = new SmsDefaultView(this); 289 default_ = new SmsDefaultView(this);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 if (GetLatestMessage(&index, &number, &text)) 366 if (GetLatestMessage(&index, &number, &text))
370 notification_->Update(index, number, text); 367 notification_->Update(index, number, text);
371 } else if (notify) { 368 } else if (notify) {
372 ShowNotificationView(); 369 ShowNotificationView();
373 } 370 }
374 } 371 }
375 } 372 }
376 373
377 } // namespace internal 374 } // namespace internal
378 } // namespace ash 375 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/chromeos/network/tray_sms.h ('k') | ash/system/chromeos/network/tray_vpn.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698