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

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

Issue 2095193002: clang-format all of //ash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
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/common/system/tray/fixed_sized_scroll_view.h" 7 #include "ash/common/system/tray/fixed_sized_scroll_view.h"
8 #include "ash/common/system/tray/system_tray_bubble.h" 8 #include "ash/common/system/tray/system_tray_bubble.h"
9 #include "ash/common/system/tray/tray_constants.h" 9 #include "ash/common/system/tray/tray_constants.h"
10 #include "ash/common/system/tray/tray_details_view.h" 10 #include "ash/common/system/tray/tray_details_view.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 return false; 49 return false;
50 return true; 50 return true;
51 } 51 }
52 52
53 } // namespace 53 } // namespace
54 54
55 namespace ash { 55 namespace ash {
56 56
57 class TraySms::SmsDefaultView : public TrayItemMore { 57 class TraySms::SmsDefaultView : public TrayItemMore {
58 public: 58 public:
59 explicit SmsDefaultView(TraySms* owner) 59 explicit SmsDefaultView(TraySms* owner) : TrayItemMore(owner, true) {
60 : TrayItemMore(owner, true) {
61 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 60 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
62 IDR_AURA_UBER_TRAY_SMS)); 61 IDR_AURA_UBER_TRAY_SMS));
63 Update(); 62 Update();
64 } 63 }
65 64
66 ~SmsDefaultView() override {} 65 ~SmsDefaultView() override {}
67 66
68 void Update() { 67 void Update() {
69 int message_count = static_cast<TraySms*>(owner())->messages().GetSize(); 68 int message_count = static_cast<TraySms*>(owner())->messages().GetSize();
70 // TODO(jshin): Currently, a tabular format is used ("SMS Messages: 69 // TODO(jshin): Currently, a tabular format is used ("SMS Messages:
71 // <count>"). Check with UX if '<count> SMS messages' with a proper plural 70 // <count>"). Check with UX if '<count> SMS messages' with a proper plural
72 // support is desired. 71 // support is desired.
73 base::string16 label = l10n_util::GetStringFUTF16Int( 72 base::string16 label = l10n_util::GetStringFUTF16Int(
74 IDS_ASH_STATUS_TRAY_SMS_MESSAGES, message_count); 73 IDS_ASH_STATUS_TRAY_SMS_MESSAGES, message_count);
75 SetLabel(label); 74 SetLabel(label);
76 SetAccessibleName(label); 75 SetAccessibleName(label);
77 } 76 }
78 77
79 private: 78 private:
80 DISALLOW_COPY_AND_ASSIGN(SmsDefaultView); 79 DISALLOW_COPY_AND_ASSIGN(SmsDefaultView);
81 }; 80 };
82 81
83 // An entry (row) in SmsDetailedView or NotificationView. 82 // An entry (row) in SmsDetailedView or NotificationView.
84 class TraySms::SmsMessageView : public views::View, 83 class TraySms::SmsMessageView : public views::View,
85 public views::ButtonListener { 84 public views::ButtonListener {
86 public: 85 public:
87 enum ViewType { 86 enum ViewType { VIEW_DETAILED, VIEW_NOTIFICATION };
88 VIEW_DETAILED,
89 VIEW_NOTIFICATION
90 };
91 87
92 SmsMessageView(TraySms* owner, 88 SmsMessageView(TraySms* owner,
93 ViewType view_type, 89 ViewType view_type,
94 size_t index, 90 size_t index,
95 const std::string& number, 91 const std::string& number,
96 const std::string& message) 92 const std::string& message)
97 : owner_(owner), 93 : owner_(owner), index_(index) {
98 index_(index) {
99 // TODO(jshin): Convert ASCII digits in |number| (phone number) to native 94 // TODO(jshin): Convert ASCII digits in |number| (phone number) to native
100 // digits if necessary. |number| can contain non-digit characters and may 95 // digits if necessary. |number| can contain non-digit characters and may
101 // have to be converted one-by-one or use libphonenumber's formating API. 96 // have to be converted one-by-one or use libphonenumber's formating API.
102 number_label_ = new views::Label( 97 number_label_ = new views::Label(
103 l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_SMS_NUMBER, 98 l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_SMS_NUMBER,
104 base::UTF8ToUTF16(number)), 99 base::UTF8ToUTF16(number)),
105 ui::ResourceBundle::GetSharedInstance().GetFontList( 100 ui::ResourceBundle::GetSharedInstance().GetFontList(
106 ui::ResourceBundle::BoldFont)); 101 ui::ResourceBundle::BoldFont));
107 number_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 102 number_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
108 103
(...skipping 15 matching lines...) Expand all
124 owner_->Update(false); 119 owner_->Update(false);
125 } 120 }
126 121
127 private: 122 private:
128 void LayoutDetailedView() { 123 void LayoutDetailedView() {
129 views::ImageButton* close_button = new views::ImageButton(this); 124 views::ImageButton* close_button = new views::ImageButton(this);
130 close_button->SetImage( 125 close_button->SetImage(
131 views::CustomButton::STATE_NORMAL, 126 views::CustomButton::STATE_NORMAL,
132 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 127 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
133 IDR_AURA_UBER_TRAY_SMS_DISMISS)); 128 IDR_AURA_UBER_TRAY_SMS_DISMISS));
134 const int msg_width = owner_->system_tray()->GetSystemBubble()-> 129 const int msg_width =
135 bubble_view()->GetPreferredSize().width() - 130 owner_->system_tray()
136 (kNotificationIconWidth + kTrayPopupPaddingHorizontal * 2); 131 ->GetSystemBubble()
132 ->bubble_view()
133 ->GetPreferredSize()
134 .width() -
135 (kNotificationIconWidth + kTrayPopupPaddingHorizontal * 2);
137 message_label_->SizeToFit(msg_width); 136 message_label_->SizeToFit(msg_width);
138 137
139 views::GridLayout* layout = new views::GridLayout(this); 138 views::GridLayout* layout = new views::GridLayout(this);
140 SetLayoutManager(layout); 139 SetLayoutManager(layout);
141 140
142 views::ColumnSet* columns = layout->AddColumnSet(0); 141 views::ColumnSet* columns = layout->AddColumnSet(0);
143 142
144 // Message 143 // Message
145 columns->AddPaddingColumn(0, kTrayPopupPaddingHorizontal); 144 columns->AddPaddingColumn(0, kTrayPopupPaddingHorizontal);
146 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 145 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
147 0 /* resize percent */, 146 0 /* resize percent */, views::GridLayout::FIXED,
148 views::GridLayout::FIXED, msg_width, msg_width); 147 msg_width, msg_width);
149 148
150 // Close button 149 // Close button
151 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 150 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
152 0, /* resize percent */ 151 0, /* resize percent */
153 views::GridLayout::FIXED, 152 views::GridLayout::FIXED, kNotificationIconWidth,
154 kNotificationIconWidth, kNotificationIconWidth); 153 kNotificationIconWidth);
155
156 154
157 layout->AddPaddingRow(0, kPaddingVertical); 155 layout->AddPaddingRow(0, kPaddingVertical);
158 layout->StartRow(0, 0); 156 layout->StartRow(0, 0);
159 layout->AddView(number_label_); 157 layout->AddView(number_label_);
160 layout->AddView(close_button, 1, 2); // 2 rows for icon 158 layout->AddView(close_button, 1, 2); // 2 rows for icon
161 layout->StartRow(0, 0); 159 layout->StartRow(0, 0);
162 layout->AddView(message_label_); 160 layout->AddView(message_label_);
163 161
164 layout->AddPaddingRow(0, kPaddingVertical); 162 layout->AddPaddingRow(0, kPaddingVertical);
165 } 163 }
(...skipping 10 matching lines...) Expand all
176 size_t index_; 174 size_t index_;
177 views::Label* number_label_; 175 views::Label* number_label_;
178 views::Label* message_label_; 176 views::Label* message_label_;
179 177
180 DISALLOW_COPY_AND_ASSIGN(SmsMessageView); 178 DISALLOW_COPY_AND_ASSIGN(SmsMessageView);
181 }; 179 };
182 180
183 class TraySms::SmsDetailedView : public TrayDetailsView, 181 class TraySms::SmsDetailedView : public TrayDetailsView,
184 public ViewClickListener { 182 public ViewClickListener {
185 public: 183 public:
186 explicit SmsDetailedView(TraySms* owner) 184 explicit SmsDetailedView(TraySms* owner) : TrayDetailsView(owner) {
187 : TrayDetailsView(owner) {
188 Init(); 185 Init();
189 Update(); 186 Update();
190 } 187 }
191 188
192 ~SmsDetailedView() override {} 189 ~SmsDetailedView() override {}
193 190
194 void Init() { 191 void Init() {
195 CreateScrollableList(); 192 CreateScrollableList();
196 CreateSpecialRow(IDS_ASH_STATUS_TRAY_SMS, this); 193 CreateSpecialRow(IDS_ASH_STATUS_TRAY_SMS, this);
197 } 194 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 : TrayNotificationView(owner, IDR_AURA_UBER_TRAY_SMS), 249 : TrayNotificationView(owner, IDR_AURA_UBER_TRAY_SMS),
253 message_index_(message_index) { 250 message_index_(message_index) {
254 SmsMessageView* message_view = new SmsMessageView( 251 SmsMessageView* message_view = new SmsMessageView(
255 owner, SmsMessageView::VIEW_NOTIFICATION, message_index_, number, text); 252 owner, SmsMessageView::VIEW_NOTIFICATION, message_index_, number, text);
256 InitView(message_view); 253 InitView(message_view);
257 } 254 }
258 255
259 void Update(size_t message_index, 256 void Update(size_t message_index,
260 const std::string& number, 257 const std::string& number,
261 const std::string& text) { 258 const std::string& text) {
262 SmsMessageView* message_view = new SmsMessageView( 259 SmsMessageView* message_view =
263 tray_sms(), SmsMessageView::VIEW_NOTIFICATION, 260 new SmsMessageView(tray_sms(), SmsMessageView::VIEW_NOTIFICATION,
264 message_index_, number, text); 261 message_index_, number, text);
265 UpdateView(message_view); 262 UpdateView(message_view);
266 } 263 }
267 264
268 // Overridden from TrayNotificationView: 265 // Overridden from TrayNotificationView:
269 void OnClose() override { tray_sms()->RemoveMessage(message_index_); } 266 void OnClose() override { tray_sms()->RemoveMessage(message_index_); }
270 267
271 void OnClickAction() override { owner()->PopupDetailedView(0, true); } 268 void OnClickAction() override { owner()->PopupDetailedView(0, true); }
272 269
273 private: 270 private:
274 TraySms* tray_sms() { 271 TraySms* tray_sms() { return static_cast<TraySms*>(owner()); }
275 return static_cast<TraySms*>(owner());
276 }
277 272
278 size_t message_index_; 273 size_t message_index_;
279 274
280 DISALLOW_COPY_AND_ASSIGN(SmsNotificationView); 275 DISALLOW_COPY_AND_ASSIGN(SmsNotificationView);
281 }; 276 };
282 277
283 TraySms::TraySms(SystemTray* system_tray) 278 TraySms::TraySms(SystemTray* system_tray)
284 : SystemTrayItem(system_tray), 279 : SystemTrayItem(system_tray),
285 default_(NULL), 280 default_(NULL),
286 detailed_(NULL), 281 detailed_(NULL),
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 327
333 void TraySms::DestroyDetailedView() { 328 void TraySms::DestroyDetailedView() {
334 detailed_ = NULL; 329 detailed_ = NULL;
335 } 330 }
336 331
337 void TraySms::DestroyNotificationView() { 332 void TraySms::DestroyNotificationView() {
338 notification_ = NULL; 333 notification_ = NULL;
339 } 334 }
340 335
341 void TraySms::MessageReceived(const base::DictionaryValue& message) { 336 void TraySms::MessageReceived(const base::DictionaryValue& message) {
342
343 std::string message_text; 337 std::string message_text;
344 if (!message.GetStringWithoutPathExpansion( 338 if (!message.GetStringWithoutPathExpansion(
345 chromeos::NetworkSmsHandler::kTextKey, &message_text)) { 339 chromeos::NetworkSmsHandler::kTextKey, &message_text)) {
346 NET_LOG_ERROR("SMS message contains no content.", ""); 340 NET_LOG_ERROR("SMS message contains no content.", "");
347 return; 341 return;
348 } 342 }
349 // TODO(armansito): A message might be due to a special "Message Waiting" 343 // TODO(armansito): A message might be due to a special "Message Waiting"
350 // state that the message is in. Once SMS handling moves to shill, such 344 // state that the message is in. Once SMS handling moves to shill, such
351 // messages should be filtered there so that this check becomes unnecessary. 345 // messages should be filtered there so that this check becomes unnecessary.
352 if (message_text.empty()) { 346 if (message_text.empty()) {
353 NET_LOG_DEBUG("SMS has empty content text. Ignoring.", ""); 347 NET_LOG_DEBUG("SMS has empty content text. Ignoring.", "");
354 return; 348 return;
355 } 349 }
356 std::string message_number; 350 std::string message_number;
357 if (!message.GetStringWithoutPathExpansion( 351 if (!message.GetStringWithoutPathExpansion(
358 chromeos::NetworkSmsHandler::kNumberKey, &message_number)) { 352 chromeos::NetworkSmsHandler::kNumberKey, &message_number)) {
359 NET_LOG_DEBUG("SMS contains no number. Ignoring.", ""); 353 NET_LOG_DEBUG("SMS contains no number. Ignoring.", "");
360 return; 354 return;
361 } 355 }
362 356
363 NET_LOG_DEBUG("Received SMS from: " + message_number + " with text: " + 357 NET_LOG_DEBUG(
364 message_text, ""); 358 "Received SMS from: " + message_number + " with text: " + message_text,
359 "");
365 360
366 base::DictionaryValue* dict = new base::DictionaryValue(); 361 base::DictionaryValue* dict = new base::DictionaryValue();
367 dict->SetString(kSmsNumberKey, message_number); 362 dict->SetString(kSmsNumberKey, message_number);
368 dict->SetString(kSmsTextKey, message_text); 363 dict->SetString(kSmsTextKey, message_text);
369 messages_.Append(dict); 364 messages_.Append(dict);
370 Update(true); 365 Update(true);
371 } 366 }
372 367
373 bool TraySms::GetLatestMessage(size_t* index, 368 bool TraySms::GetLatestMessage(size_t* index,
374 std::string* number, 369 std::string* number,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 std::string number, text; 404 std::string number, text;
410 if (GetLatestMessage(&index, &number, &text)) 405 if (GetLatestMessage(&index, &number, &text))
411 notification_->Update(index, number, text); 406 notification_->Update(index, number, text);
412 } else if (notify) { 407 } else if (notify) {
413 ShowNotificationView(); 408 ShowNotificationView();
414 } 409 }
415 } 410 }
416 } 411 }
417 412
418 } // namespace ash 413 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/chromeos/network/network_state_list_detailed_view.cc ('k') | ash/system/chromeos/network/tray_vpn.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698