OLD | NEW |
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 26 matching lines...) Expand all Loading... |
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* tray) |
55 : TrayItemMore(tray, true), | 54 : TrayItemMore(tray, 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*>(tray())->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 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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* tray) |
180 : tray_(tray) { | 176 : TrayDetailsView(tray) { |
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 = static_cast<TraySms*>(tray())->messages(); |
210 scroll_content()->RemoveAllChildViews(true); | 206 scroll_content()->RemoveAllChildViews(true); |
211 for (size_t index = 0; index < messages.GetSize(); ++index) { | 207 for (size_t index = 0; index < messages.GetSize(); ++index) { |
212 const base::DictionaryValue* message = NULL; | 208 const base::DictionaryValue* message = NULL; |
213 if (!messages.GetDictionary(index, &message)) { | 209 if (!messages.GetDictionary(index, &message)) { |
214 LOG(ERROR) << "SMS message not a dictionary at: " << index; | 210 LOG(ERROR) << "SMS message not a dictionary at: " << index; |
215 continue; | 211 continue; |
216 } | 212 } |
217 std::string number, text; | 213 std::string number, text; |
218 if (!GetMessageFromDictionary(message, &number, &text)) { | 214 if (!GetMessageFromDictionary(message, &number, &text)) { |
219 LOG(ERROR) << "Error parsing SMS message"; | 215 LOG(ERROR) << "Error parsing SMS message"; |
220 continue; | 216 continue; |
221 } | 217 } |
222 SmsMessageView* msgview = new SmsMessageView( | 218 SmsMessageView* msgview = new SmsMessageView( |
223 tray_, SmsMessageView::VIEW_DETAILED, index, number, text); | 219 static_cast<TraySms*>(tray()), SmsMessageView::VIEW_DETAILED, index, |
| 220 number, text); |
224 scroll_content()->AddChildView(msgview); | 221 scroll_content()->AddChildView(msgview); |
225 } | 222 } |
226 scroller()->Layout(); | 223 scroller()->Layout(); |
227 } | 224 } |
228 | 225 |
229 // Overridden from ViewClickListener. | 226 // Overridden from ViewClickListener. |
230 virtual void ClickedOn(views::View* sender) OVERRIDE { | 227 virtual void ClickedOn(views::View* sender) OVERRIDE { |
231 if (sender == footer()->content()) | 228 if (sender == footer()->content()) |
232 Shell::GetInstance()->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING); | 229 tray()->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING); |
233 } | 230 } |
234 | 231 |
235 TraySms* tray_; | |
236 | |
237 DISALLOW_COPY_AND_ASSIGN(SmsDetailedView); | 232 DISALLOW_COPY_AND_ASSIGN(SmsDetailedView); |
238 }; | 233 }; |
239 | 234 |
240 class TraySms::SmsNotificationView : public TrayNotificationView { | 235 class TraySms::SmsNotificationView : public TrayNotificationView { |
241 public: | 236 public: |
242 SmsNotificationView(TraySms* tray, | 237 SmsNotificationView(TraySms* tray, |
243 size_t message_index, | 238 size_t message_index, |
244 const std::string& number, | 239 const std::string& number, |
245 const std::string& text) | 240 const std::string& text) |
246 : TrayNotificationView(tray, IDR_AURA_UBER_TRAY_SMS), | 241 : TrayNotificationView(tray, IDR_AURA_UBER_TRAY_SMS), |
(...skipping 24 matching lines...) Expand all Loading... |
271 private: | 266 private: |
272 TraySms* tray_sms() { | 267 TraySms* tray_sms() { |
273 return static_cast<TraySms*>(tray()); | 268 return static_cast<TraySms*>(tray()); |
274 } | 269 } |
275 | 270 |
276 size_t message_index_; | 271 size_t message_index_; |
277 | 272 |
278 DISALLOW_COPY_AND_ASSIGN(SmsNotificationView); | 273 DISALLOW_COPY_AND_ASSIGN(SmsNotificationView); |
279 }; | 274 }; |
280 | 275 |
281 TraySms::TraySms() | 276 TraySms::TraySms(SystemTray* system_tray) |
282 : default_(NULL), | 277 : SystemTrayItem(system_tray), |
| 278 default_(NULL), |
283 detailed_(NULL), | 279 detailed_(NULL), |
284 notification_(NULL) { | 280 notification_(NULL) { |
285 } | 281 } |
286 | 282 |
287 TraySms::~TraySms() { | 283 TraySms::~TraySms() { |
288 } | 284 } |
289 | 285 |
290 views::View* TraySms::CreateDefaultView(user::LoginStatus status) { | 286 views::View* TraySms::CreateDefaultView(user::LoginStatus status) { |
291 CHECK(default_ == NULL); | 287 CHECK(default_ == NULL); |
292 default_ = new SmsDefaultView(this); | 288 default_ = new SmsDefaultView(this); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 if (GetLatestMessage(&index, &number, &text)) | 365 if (GetLatestMessage(&index, &number, &text)) |
370 notification_->Update(index, number, text); | 366 notification_->Update(index, number, text); |
371 } else if (notify) { | 367 } else if (notify) { |
372 ShowNotificationView(); | 368 ShowNotificationView(); |
373 } | 369 } |
374 } | 370 } |
375 } | 371 } |
376 | 372 |
377 } // namespace internal | 373 } // namespace internal |
378 } // namespace ash | 374 } // namespace ash |
OLD | NEW |