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/network/tray_network.h" | 5 #include "ash/system/network/tray_network.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/shell_window_ids.h" | 8 #include "ash/shell_window_ids.h" |
9 #include "ash/system/tray/system_tray.h" | 9 #include "ash/system/tray/system_tray.h" |
10 #include "ash/system/tray/system_tray_delegate.h" | 10 #include "ash/system/tray/system_tray_delegate.h" |
11 #include "ash/system/tray/tray_constants.h" | 11 #include "ash/system/tray/tray_constants.h" |
| 12 #include "ash/system/tray/tray_details_view.h" |
12 #include "ash/system/tray/tray_item_more.h" | 13 #include "ash/system/tray/tray_item_more.h" |
13 #include "ash/system/tray/tray_item_view.h" | 14 #include "ash/system/tray/tray_item_view.h" |
14 #include "ash/system/tray/tray_views.h" | 15 #include "ash/system/tray/tray_views.h" |
15 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
16 #include "grit/ash_strings.h" | 17 #include "grit/ash_strings.h" |
17 #include "grit/ui_resources.h" | 18 #include "grit/ui_resources.h" |
18 #include "third_party/skia/include/core/SkColor.h" | 19 #include "third_party/skia/include/core/SkColor.h" |
19 #include "ui/aura/window.h" | 20 #include "ui/aura/window.h" |
20 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
21 #include "ui/gfx/canvas.h" | 22 #include "ui/gfx/canvas.h" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 GetMostRelevantNetworkIcon(&info, true); | 144 GetMostRelevantNetworkIcon(&info, true); |
144 SetImage(&info.image); | 145 SetImage(&info.image); |
145 SetLabel(info.description); | 146 SetLabel(info.description); |
146 SetAccessibleName(info.description); | 147 SetAccessibleName(info.description); |
147 } | 148 } |
148 | 149 |
149 private: | 150 private: |
150 DISALLOW_COPY_AND_ASSIGN(NetworkDefaultView); | 151 DISALLOW_COPY_AND_ASSIGN(NetworkDefaultView); |
151 }; | 152 }; |
152 | 153 |
153 class NetworkDetailedView : public views::View, | 154 class NetworkDetailedView : public TrayDetailsView, |
154 public views::ButtonListener, | 155 public views::ButtonListener, |
155 public ViewClickListener { | 156 public ViewClickListener { |
156 public: | 157 public: |
157 explicit NetworkDetailedView(user::LoginStatus login) | 158 explicit NetworkDetailedView(user::LoginStatus login) |
158 : login_(login), | 159 : login_(login), |
159 header_(NULL), | |
160 airplane_(NULL), | 160 airplane_(NULL), |
161 info_icon_(NULL), | 161 info_icon_(NULL), |
162 button_wifi_(NULL), | 162 button_wifi_(NULL), |
163 button_cellular_(NULL), | 163 button_cellular_(NULL), |
164 view_mobile_account_(NULL), | 164 view_mobile_account_(NULL), |
165 setup_mobile_account_(NULL), | 165 setup_mobile_account_(NULL), |
166 networks_list_(NULL), | |
167 scroller_(NULL), | |
168 other_wifi_(NULL), | 166 other_wifi_(NULL), |
169 other_mobile_(NULL), | 167 other_mobile_(NULL), |
170 settings_(NULL), | 168 settings_(NULL), |
171 proxy_settings_(NULL), | 169 proxy_settings_(NULL), |
172 info_bubble_(NULL) { | 170 info_bubble_(NULL) { |
173 SetLayoutManager(new views::BoxLayout( | |
174 views::BoxLayout::kVertical, 0, 0, 0)); | |
175 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); | |
176 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); | 171 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); |
177 delegate->RequestNetworkScan(); | 172 delegate->RequestNetworkScan(); |
178 CreateItems(); | 173 CreateItems(); |
179 Update(); | 174 Update(); |
180 } | 175 } |
181 | 176 |
182 virtual ~NetworkDetailedView() { | 177 virtual ~NetworkDetailedView() { |
183 if (info_bubble_) | 178 if (info_bubble_) |
184 info_bubble_->GetWidget()->CloseNow(); | 179 info_bubble_->GetWidget()->CloseNow(); |
185 } | 180 } |
186 | 181 |
187 void CreateItems() { | 182 void CreateItems() { |
188 RemoveAllChildViews(true); | 183 RemoveAllChildViews(true); |
189 | 184 |
190 header_ = NULL; | |
191 airplane_ = NULL; | 185 airplane_ = NULL; |
192 info_icon_ = NULL; | 186 info_icon_ = NULL; |
193 button_wifi_ = NULL; | 187 button_wifi_ = NULL; |
194 button_cellular_ = NULL; | 188 button_cellular_ = NULL; |
195 view_mobile_account_ = NULL; | 189 view_mobile_account_ = NULL; |
196 setup_mobile_account_ = NULL; | 190 setup_mobile_account_ = NULL; |
197 networks_list_ = NULL; | |
198 scroller_ = NULL; | |
199 other_wifi_ = NULL; | 191 other_wifi_ = NULL; |
200 other_mobile_ = NULL; | 192 other_mobile_ = NULL; |
201 settings_ = NULL; | 193 settings_ = NULL; |
202 proxy_settings_ = NULL; | 194 proxy_settings_ = NULL; |
203 | 195 |
204 AppendNetworkEntries(); | 196 AppendNetworkEntries(); |
205 AppendNetworkExtra(); | 197 AppendNetworkExtra(); |
206 AppendHeaderEntry(); | 198 AppendHeaderEntry(); |
207 AppendHeaderButtons(); | 199 AppendHeaderButtons(); |
208 | 200 |
209 Update(); | 201 Update(); |
210 } | 202 } |
211 | 203 |
212 void Update() { | 204 void Update() { |
213 UpdateHeaderButtons(); | 205 UpdateHeaderButtons(); |
214 UpdateNetworkEntries(); | 206 UpdateNetworkEntries(); |
215 UpdateNetworkExtra(); | 207 UpdateNetworkExtra(); |
216 | 208 |
217 Layout(); | 209 Layout(); |
218 } | 210 } |
219 | 211 |
220 private: | 212 private: |
221 void AppendHeaderEntry() { | 213 void AppendHeaderEntry() { |
222 header_ = new SpecialPopupRow(); | 214 CreateSpecialRow(IDS_ASH_STATUS_TRAY_NETWORK, this); |
223 header_->SetTextLabel(IDS_ASH_STATUS_TRAY_NETWORK, this); | |
224 AddChildView(header_); | |
225 } | 215 } |
226 | 216 |
227 void AppendHeaderButtons() { | 217 void AppendHeaderButtons() { |
228 button_wifi_ = new TrayPopupHeaderButton(this, | 218 button_wifi_ = new TrayPopupHeaderButton(this, |
229 IDR_AURA_UBER_TRAY_WIFI_ENABLED, | 219 IDR_AURA_UBER_TRAY_WIFI_ENABLED, |
230 IDR_AURA_UBER_TRAY_WIFI_DISABLED, | 220 IDR_AURA_UBER_TRAY_WIFI_DISABLED, |
231 IDR_AURA_UBER_TRAY_WIFI_ENABLED_HOVER, | 221 IDR_AURA_UBER_TRAY_WIFI_ENABLED_HOVER, |
232 IDR_AURA_UBER_TRAY_WIFI_DISABLED_HOVER); | 222 IDR_AURA_UBER_TRAY_WIFI_DISABLED_HOVER); |
233 header_->AddButton(button_wifi_); | 223 footer()->AddButton(button_wifi_); |
234 | 224 |
235 button_cellular_ = new TrayPopupHeaderButton(this, | 225 button_cellular_ = new TrayPopupHeaderButton(this, |
236 IDR_AURA_UBER_TRAY_CELLULAR_ENABLED, | 226 IDR_AURA_UBER_TRAY_CELLULAR_ENABLED, |
237 IDR_AURA_UBER_TRAY_CELLULAR_DISABLED, | 227 IDR_AURA_UBER_TRAY_CELLULAR_DISABLED, |
238 IDR_AURA_UBER_TRAY_CELLULAR_ENABLED_HOVER, | 228 IDR_AURA_UBER_TRAY_CELLULAR_ENABLED_HOVER, |
239 IDR_AURA_UBER_TRAY_CELLULAR_DISABLED_HOVER); | 229 IDR_AURA_UBER_TRAY_CELLULAR_DISABLED_HOVER); |
240 header_->AddButton(button_cellular_); | 230 footer()->AddButton(button_cellular_); |
241 | 231 |
242 info_icon_ = new TrayPopupHeaderButton(this, | 232 info_icon_ = new TrayPopupHeaderButton(this, |
243 IDR_AURA_UBER_TRAY_NETWORK_INFO, | 233 IDR_AURA_UBER_TRAY_NETWORK_INFO, |
244 IDR_AURA_UBER_TRAY_NETWORK_INFO, | 234 IDR_AURA_UBER_TRAY_NETWORK_INFO, |
245 IDR_AURA_UBER_TRAY_NETWORK_INFO_HOVER, | 235 IDR_AURA_UBER_TRAY_NETWORK_INFO_HOVER, |
246 IDR_AURA_UBER_TRAY_NETWORK_INFO_HOVER); | 236 IDR_AURA_UBER_TRAY_NETWORK_INFO_HOVER); |
247 header_->AddButton(info_icon_); | 237 footer()->AddButton(info_icon_); |
248 } | 238 } |
249 | 239 |
250 void UpdateHeaderButtons() { | 240 void UpdateHeaderButtons() { |
251 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); | 241 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); |
252 button_wifi_->SetToggled(!delegate->GetWifiEnabled()); | 242 button_wifi_->SetToggled(!delegate->GetWifiEnabled()); |
253 button_cellular_->SetToggled(!delegate->GetCellularEnabled()); | 243 button_cellular_->SetToggled(!delegate->GetCellularEnabled()); |
254 button_cellular_->SetVisible(delegate->GetCellularAvailable()); | 244 button_cellular_->SetVisible(delegate->GetCellularAvailable()); |
255 } | 245 } |
256 | 246 |
257 void AppendNetworkEntries() { | 247 void AppendNetworkEntries() { |
258 FixedSizedScrollView* scroller = new FixedSizedScrollView; | 248 CreateScrollableList(); |
259 networks_list_ = new views::View; | |
260 networks_list_->SetLayoutManager(new views::BoxLayout( | |
261 views::BoxLayout::kVertical, 0, 0, 1)); | |
262 | 249 |
263 HoverHighlightView* container = new HoverHighlightView(this); | 250 HoverHighlightView* container = new HoverHighlightView(this); |
264 container->set_fixed_height(kTrayPopupItemHeight); | 251 container->set_fixed_height(kTrayPopupItemHeight); |
265 container->AddLabel(ui::ResourceBundle::GetSharedInstance(). | 252 container->AddLabel(ui::ResourceBundle::GetSharedInstance(). |
266 GetLocalizedString(IDS_ASH_STATUS_TRAY_MOBILE_VIEW_ACCOUNT), | 253 GetLocalizedString(IDS_ASH_STATUS_TRAY_MOBILE_VIEW_ACCOUNT), |
267 gfx::Font::NORMAL); | 254 gfx::Font::NORMAL); |
268 AddChildView(container); | 255 AddChildView(container); |
269 view_mobile_account_ = container; | 256 view_mobile_account_ = container; |
270 | 257 |
271 container = new HoverHighlightView(this); | 258 container = new HoverHighlightView(this); |
272 container->set_fixed_height(kTrayPopupItemHeight); | 259 container->set_fixed_height(kTrayPopupItemHeight); |
273 container->AddLabel(ui::ResourceBundle::GetSharedInstance(). | 260 container->AddLabel(ui::ResourceBundle::GetSharedInstance(). |
274 GetLocalizedString(IDS_ASH_STATUS_TRAY_SETUP_MOBILE), | 261 GetLocalizedString(IDS_ASH_STATUS_TRAY_SETUP_MOBILE), |
275 gfx::Font::NORMAL); | 262 gfx::Font::NORMAL); |
276 AddChildView(container); | 263 AddChildView(container); |
277 setup_mobile_account_ = container; | 264 setup_mobile_account_ = container; |
278 | |
279 scroller->set_border(views::Border::CreateSolidSidedBorder(1, 0, 1, 0, | |
280 SkColorSetARGB(25, 0, 0, 0))); | |
281 scroller->set_fixed_size( | |
282 gfx::Size(networks_list_->GetPreferredSize().width() + | |
283 scroller->GetScrollBarWidth(), | |
284 kNetworkListHeight)); | |
285 scroller->SetContentsView(networks_list_); | |
286 AddChildView(scroller); | |
287 scroller_ = scroller; | |
288 } | 265 } |
289 | 266 |
290 void UpdateNetworkEntries() { | 267 void UpdateNetworkEntries() { |
291 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); | 268 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); |
292 std::vector<NetworkIconInfo> list; | 269 std::vector<NetworkIconInfo> list; |
293 delegate->GetAvailableNetworks(&list); | 270 delegate->GetAvailableNetworks(&list); |
294 | 271 |
295 network_map_.clear(); | 272 network_map_.clear(); |
296 networks_list_->RemoveAllChildViews(true); | 273 scroll_content()->RemoveAllChildViews(true); |
297 views::View* highlighted_view = NULL; | 274 views::View* highlighted_view = NULL; |
298 for (size_t i = 0; i < list.size(); i++) { | 275 for (size_t i = 0; i < list.size(); i++) { |
299 HoverHighlightView* container = new HoverHighlightView(this); | 276 HoverHighlightView* container = new HoverHighlightView(this); |
300 container->set_fixed_height(kTrayPopupItemHeight); | 277 container->set_fixed_height(kTrayPopupItemHeight); |
301 container->AddIconAndLabel(list[i].image, | 278 container->AddIconAndLabel(list[i].image, |
302 list[i].description.empty() ? list[i].name : list[i].description, | 279 list[i].description.empty() ? list[i].name : list[i].description, |
303 list[i].highlight ? gfx::Font::BOLD : gfx::Font::NORMAL); | 280 list[i].highlight ? gfx::Font::BOLD : gfx::Font::NORMAL); |
304 networks_list_->AddChildView(container); | 281 scroll_content()->AddChildView(container); |
305 if (list[i].highlight) | 282 if (list[i].highlight) |
306 highlighted_view = container; | 283 highlighted_view = container; |
307 container->set_border(views::Border::CreateEmptyBorder(0, | 284 container->set_border(views::Border::CreateEmptyBorder(0, |
308 kTrayPopupDetailsIconWidth, 0, 0)); | 285 kTrayPopupDetailsIconWidth, 0, 0)); |
309 network_map_[container] = list[i].service_path; | 286 network_map_[container] = list[i].service_path; |
310 } | 287 } |
311 networks_list_->SizeToPreferredSize(); | 288 scroll_content()->SizeToPreferredSize(); |
312 scroller_->Layout(); | 289 static_cast<views::View*>(scroller())->Layout(); |
313 if (highlighted_view) | 290 if (highlighted_view) |
314 networks_list_->ScrollRectToVisible(highlighted_view->bounds()); | 291 scroll_content()->ScrollRectToVisible(highlighted_view->bounds()); |
315 | 292 |
316 view_mobile_account_->SetVisible(false); | 293 view_mobile_account_->SetVisible(false); |
317 setup_mobile_account_->SetVisible(false); | 294 setup_mobile_account_->SetVisible(false); |
318 | 295 |
319 if (login_ == user::LOGGED_IN_NONE) | 296 if (login_ == user::LOGGED_IN_NONE) |
320 return; | 297 return; |
321 | 298 |
322 std::string carrier_id, topup_url, setup_url; | 299 std::string carrier_id, topup_url, setup_url; |
323 if (delegate->GetCellularCarrierInfo(&carrier_id, | 300 if (delegate->GetCellularCarrierInfo(&carrier_id, |
324 &topup_url, | 301 &topup_url, |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 } | 461 } |
485 | 462 |
486 // Overridden from ViewClickListener. | 463 // Overridden from ViewClickListener. |
487 virtual void ClickedOn(views::View* sender) OVERRIDE { | 464 virtual void ClickedOn(views::View* sender) OVERRIDE { |
488 ash::SystemTrayDelegate* delegate = | 465 ash::SystemTrayDelegate* delegate = |
489 ash::Shell::GetInstance()->tray_delegate(); | 466 ash::Shell::GetInstance()->tray_delegate(); |
490 // If the info bubble was visible, close it when some other item is clicked | 467 // If the info bubble was visible, close it when some other item is clicked |
491 // on. | 468 // on. |
492 ResetInfoBubble(); | 469 ResetInfoBubble(); |
493 | 470 |
494 if (sender == header_->content()) | 471 if (sender == footer()->content()) |
495 Shell::GetInstance()->tray()->ShowDefaultView(); | 472 Shell::GetInstance()->tray()->ShowDefaultView(BUBBLE_USE_EXISTING); |
496 | 473 |
497 if (login_ == user::LOGGED_IN_LOCKED) | 474 if (login_ == user::LOGGED_IN_LOCKED) |
498 return; | 475 return; |
499 | 476 |
500 if (sender == view_mobile_account_) { | 477 if (sender == view_mobile_account_) { |
501 delegate->ShowCellularURL(topup_url_); | 478 delegate->ShowCellularURL(topup_url_); |
502 } else if (sender == setup_mobile_account_) { | 479 } else if (sender == setup_mobile_account_) { |
503 delegate->ShowCellularURL(setup_url_); | 480 delegate->ShowCellularURL(setup_url_); |
504 } else if (sender == airplane_) { | 481 } else if (sender == airplane_) { |
505 delegate->ToggleAirplaneMode(); | 482 delegate->ToggleAirplaneMode(); |
506 } else { | 483 } else { |
507 std::map<views::View*, std::string>::iterator find; | 484 std::map<views::View*, std::string>::iterator find; |
508 find = network_map_.find(sender); | 485 find = network_map_.find(sender); |
509 if (find != network_map_.end()) { | 486 if (find != network_map_.end()) { |
510 std::string network_id = find->second; | 487 std::string network_id = find->second; |
511 delegate->ConnectToNetwork(network_id); | 488 delegate->ConnectToNetwork(network_id); |
512 } | 489 } |
513 } | 490 } |
514 } | 491 } |
515 | 492 |
516 std::string carrier_id_; | 493 std::string carrier_id_; |
517 std::string topup_url_; | 494 std::string topup_url_; |
518 std::string setup_url_; | 495 std::string setup_url_; |
519 | 496 |
520 user::LoginStatus login_; | 497 user::LoginStatus login_; |
521 std::map<views::View*, std::string> network_map_; | 498 std::map<views::View*, std::string> network_map_; |
522 SpecialPopupRow* header_; | |
523 views::View* airplane_; | 499 views::View* airplane_; |
524 TrayPopupHeaderButton* info_icon_; | 500 TrayPopupHeaderButton* info_icon_; |
525 TrayPopupHeaderButton* button_wifi_; | 501 TrayPopupHeaderButton* button_wifi_; |
526 TrayPopupHeaderButton* button_cellular_; | 502 TrayPopupHeaderButton* button_cellular_; |
527 views::View* view_mobile_account_; | 503 views::View* view_mobile_account_; |
528 views::View* setup_mobile_account_; | 504 views::View* setup_mobile_account_; |
529 views::View* networks_list_; | |
530 views::View* scroller_; | |
531 TrayPopupTextButton* other_wifi_; | 505 TrayPopupTextButton* other_wifi_; |
532 TrayPopupTextButton* other_mobile_; | 506 TrayPopupTextButton* other_mobile_; |
533 TrayPopupTextButton* settings_; | 507 TrayPopupTextButton* settings_; |
534 TrayPopupTextButton* proxy_settings_; | 508 TrayPopupTextButton* proxy_settings_; |
535 | 509 |
536 views::BubbleDelegateView* info_bubble_; | 510 views::BubbleDelegateView* info_bubble_; |
537 | 511 |
538 DISALLOW_COPY_AND_ASSIGN(NetworkDetailedView); | 512 DISALLOW_COPY_AND_ASSIGN(NetworkDetailedView); |
539 }; | 513 }; |
540 | 514 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 if (tray_) | 560 if (tray_) |
587 tray_->Update(info); | 561 tray_->Update(info); |
588 if (default_) | 562 if (default_) |
589 default_->Update(); | 563 default_->Update(); |
590 if (detailed_) | 564 if (detailed_) |
591 detailed_->Update(); | 565 detailed_->Update(); |
592 } | 566 } |
593 | 567 |
594 } // namespace internal | 568 } // namespace internal |
595 } // namespace ash | 569 } // namespace ash |
OLD | NEW |