Chromium Code Reviews| 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" |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 GetMostRelevantNetworkIcon(&info, true); | 190 GetMostRelevantNetworkIcon(&info, true); |
| 191 SetImage(&info.image); | 191 SetImage(&info.image); |
| 192 SetLabel(info.description); | 192 SetLabel(info.description); |
| 193 SetAccessibleName(info.description); | 193 SetAccessibleName(info.description); |
| 194 } | 194 } |
| 195 | 195 |
| 196 private: | 196 private: |
| 197 DISALLOW_COPY_AND_ASSIGN(NetworkDefaultView); | 197 DISALLOW_COPY_AND_ASSIGN(NetworkDefaultView); |
| 198 }; | 198 }; |
| 199 | 199 |
| 200 class NetworkDetailedView : public TrayDetailsView, | 200 class NetworkDetailedView : public TrayDetailsView { |
| 201 public views::ButtonListener, | |
| 202 public ViewClickListener { | |
| 203 public: | 201 public: |
| 204 explicit NetworkDetailedView(user::LoginStatus login) | 202 NetworkDetailedView() {} |
| 203 | |
| 204 virtual ~NetworkDetailedView() {} | |
| 205 | |
| 206 virtual TrayNetwork::DetailedViewType view_type() const = 0; | |
|
stevenjb
2012/08/02 19:55:56
nit: I think this should be named GetViewType() si
mazda
2012/08/02 21:01:48
Done.
| |
| 207 | |
| 208 virtual void Update() = 0; | |
| 209 }; | |
| 210 | |
| 211 class NetworkListDetailedView : public NetworkDetailedView, | |
| 212 public views::ButtonListener, | |
| 213 public ViewClickListener { | |
| 214 public: | |
| 215 NetworkListDetailedView(user::LoginStatus login) | |
| 205 : login_(login), | 216 : login_(login), |
| 206 airplane_(NULL), | 217 airplane_(NULL), |
| 207 info_icon_(NULL), | 218 info_icon_(NULL), |
| 208 button_wifi_(NULL), | 219 button_wifi_(NULL), |
| 209 button_mobile_(NULL), | 220 button_mobile_(NULL), |
| 210 view_mobile_account_(NULL), | 221 view_mobile_account_(NULL), |
| 211 setup_mobile_account_(NULL), | 222 setup_mobile_account_(NULL), |
| 212 other_wifi_(NULL), | 223 other_wifi_(NULL), |
| 213 other_mobile_(NULL), | 224 other_mobile_(NULL), |
| 214 settings_(NULL), | 225 settings_(NULL), |
| 215 proxy_settings_(NULL), | 226 proxy_settings_(NULL), |
| 216 info_bubble_(NULL) { | 227 info_bubble_(NULL) { |
| 217 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); | 228 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); |
| 218 delegate->RequestNetworkScan(); | 229 delegate->RequestNetworkScan(); |
| 219 CreateItems(); | 230 CreateItems(); |
| 220 Update(); | 231 Update(); |
| 221 } | 232 } |
| 222 | 233 |
| 223 virtual ~NetworkDetailedView() { | 234 virtual ~NetworkListDetailedView() { |
| 224 if (info_bubble_) | 235 if (info_bubble_) |
| 225 info_bubble_->GetWidget()->CloseNow(); | 236 info_bubble_->GetWidget()->CloseNow(); |
| 226 } | 237 } |
| 227 | 238 |
| 228 void CreateItems() { | 239 void CreateItems() { |
| 229 RemoveAllChildViews(true); | 240 RemoveAllChildViews(true); |
| 230 | 241 |
| 231 airplane_ = NULL; | 242 airplane_ = NULL; |
| 232 info_icon_ = NULL; | 243 info_icon_ = NULL; |
| 233 button_wifi_ = NULL; | 244 button_wifi_ = NULL; |
| 234 button_mobile_ = NULL; | 245 button_mobile_ = NULL; |
| 235 view_mobile_account_ = NULL; | 246 view_mobile_account_ = NULL; |
| 236 setup_mobile_account_ = NULL; | 247 setup_mobile_account_ = NULL; |
| 237 other_wifi_ = NULL; | 248 other_wifi_ = NULL; |
| 238 other_mobile_ = NULL; | 249 other_mobile_ = NULL; |
| 239 settings_ = NULL; | 250 settings_ = NULL; |
| 240 proxy_settings_ = NULL; | 251 proxy_settings_ = NULL; |
| 241 | 252 |
| 242 AppendNetworkEntries(); | 253 AppendNetworkEntries(); |
| 243 AppendNetworkExtra(); | 254 AppendNetworkExtra(); |
| 244 AppendHeaderEntry(); | 255 AppendHeaderEntry(); |
| 245 AppendHeaderButtons(); | 256 AppendHeaderButtons(); |
| 246 | 257 |
| 247 Update(); | 258 Update(); |
| 248 } | 259 } |
| 249 | 260 |
| 250 void Update() { | 261 // Overridden from NetworkDetailedView: |
| 262 virtual TrayNetwork::DetailedViewType view_type() const OVERRIDE { | |
| 263 return TrayNetwork::LIST_VIEW; | |
| 264 } | |
| 265 | |
| 266 virtual void Update() OVERRIDE { | |
| 251 UpdateHeaderButtons(); | 267 UpdateHeaderButtons(); |
| 252 UpdateNetworkEntries(); | 268 UpdateNetworkEntries(); |
| 253 UpdateNetworkExtra(); | 269 UpdateNetworkExtra(); |
| 254 | 270 |
| 255 Layout(); | 271 Layout(); |
| 256 } | 272 } |
| 257 | 273 |
| 258 private: | 274 private: |
| 259 void AppendHeaderEntry() { | 275 void AppendHeaderEntry() { |
| 260 CreateSpecialRow(IDS_ASH_STATUS_TRAY_NETWORK, this); | 276 CreateSpecialRow(IDS_ASH_STATUS_TRAY_NETWORK, this); |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 601 TrayPopupHeaderButton* button_mobile_; | 617 TrayPopupHeaderButton* button_mobile_; |
| 602 views::View* view_mobile_account_; | 618 views::View* view_mobile_account_; |
| 603 views::View* setup_mobile_account_; | 619 views::View* setup_mobile_account_; |
| 604 TrayPopupTextButton* other_wifi_; | 620 TrayPopupTextButton* other_wifi_; |
| 605 TrayPopupTextButton* other_mobile_; | 621 TrayPopupTextButton* other_mobile_; |
| 606 TrayPopupTextButton* settings_; | 622 TrayPopupTextButton* settings_; |
| 607 TrayPopupTextButton* proxy_settings_; | 623 TrayPopupTextButton* proxy_settings_; |
| 608 | 624 |
| 609 views::BubbleDelegateView* info_bubble_; | 625 views::BubbleDelegateView* info_bubble_; |
| 610 | 626 |
| 611 DISALLOW_COPY_AND_ASSIGN(NetworkDetailedView); | 627 DISALLOW_COPY_AND_ASSIGN(NetworkListDetailedView); |
| 628 }; | |
| 629 | |
| 630 class NetworkWifiDetailedView : public NetworkDetailedView { | |
| 631 public: | |
| 632 explicit NetworkWifiDetailedView(bool wifi_enabled) { | |
| 633 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, | |
| 634 kTrayPopupPaddingHorizontal, | |
| 635 10, | |
| 636 kTrayPopupPaddingBetweenItems)); | |
| 637 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | |
| 638 views::ImageView* image = new views::ImageView; | |
| 639 const int image_id = wifi_enabled ? | |
| 640 IDR_AURA_UBER_TRAY_WIFI_ENABLED : IDR_AURA_UBER_TRAY_WIFI_DISABLED; | |
| 641 image->SetImage(bundle.GetImageNamed(image_id).ToImageSkia()); | |
| 642 AddChildView(image); | |
| 643 | |
| 644 const int string_id = wifi_enabled ? | |
| 645 IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED: | |
| 646 IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED; | |
| 647 views::Label* label = | |
| 648 new views::Label(bundle.GetLocalizedString(string_id)); | |
| 649 label->SetMultiLine(true); | |
| 650 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | |
| 651 AddChildView(label); | |
| 652 } | |
| 653 | |
| 654 virtual ~NetworkWifiDetailedView() {} | |
| 655 | |
| 656 // Overridden from NetworkDetailedView: | |
| 657 virtual TrayNetwork::DetailedViewType view_type() const OVERRIDE { | |
| 658 return TrayNetwork::WIFI_VIEW; | |
| 659 } | |
| 660 | |
| 661 virtual void Update() OVERRIDE {} | |
| 662 | |
| 663 private: | |
| 664 DISALLOW_COPY_AND_ASSIGN(NetworkWifiDetailedView); | |
| 612 }; | 665 }; |
| 613 | 666 |
| 614 class NetworkErrorView : public views::View, | 667 class NetworkErrorView : public views::View, |
| 615 public views::LinkListener { | 668 public views::LinkListener { |
| 616 public: | 669 public: |
| 617 NetworkErrorView(TrayNetwork* tray, | 670 NetworkErrorView(TrayNetwork* tray, |
| 618 TrayNetwork::ErrorType error_type, | 671 TrayNetwork::ErrorType error_type, |
| 619 const NetworkErrors::Message& error) | 672 const NetworkErrors::Message& error) |
| 620 : tray_(tray), | 673 : tray_(tray), |
| 621 error_type_(error_type) { | 674 error_type_(error_type) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 705 DISALLOW_COPY_AND_ASSIGN(NetworkNotificationView); | 758 DISALLOW_COPY_AND_ASSIGN(NetworkNotificationView); |
| 706 }; | 759 }; |
| 707 | 760 |
| 708 } // namespace tray | 761 } // namespace tray |
| 709 | 762 |
| 710 TrayNetwork::TrayNetwork() | 763 TrayNetwork::TrayNetwork() |
| 711 : tray_(NULL), | 764 : tray_(NULL), |
| 712 default_(NULL), | 765 default_(NULL), |
| 713 detailed_(NULL), | 766 detailed_(NULL), |
| 714 notification_(NULL), | 767 notification_(NULL), |
| 715 errors_(new tray::NetworkErrors()) { | 768 errors_(new tray::NetworkErrors()), |
| 769 request_wifi_view_(false) { | |
| 716 } | 770 } |
| 717 | 771 |
| 718 TrayNetwork::~TrayNetwork() { | 772 TrayNetwork::~TrayNetwork() { |
| 719 } | 773 } |
| 720 | 774 |
| 721 views::View* TrayNetwork::CreateTrayView(user::LoginStatus status) { | 775 views::View* TrayNetwork::CreateTrayView(user::LoginStatus status) { |
| 722 CHECK(tray_ == NULL); | 776 CHECK(tray_ == NULL); |
| 723 tray_ = new tray::NetworkTrayView(tray::LIGHT, true /*tray_icon*/); | 777 tray_ = new tray::NetworkTrayView(tray::LIGHT, true /*tray_icon*/); |
| 724 return tray_; | 778 return tray_; |
| 725 } | 779 } |
| 726 | 780 |
| 727 views::View* TrayNetwork::CreateDefaultView(user::LoginStatus status) { | 781 views::View* TrayNetwork::CreateDefaultView(user::LoginStatus status) { |
| 728 CHECK(default_ == NULL); | 782 CHECK(default_ == NULL); |
| 729 default_ = new tray::NetworkDefaultView(this); | 783 default_ = new tray::NetworkDefaultView(this); |
| 730 return default_; | 784 return default_; |
| 731 } | 785 } |
| 732 | 786 |
| 733 views::View* TrayNetwork::CreateDetailedView(user::LoginStatus status) { | 787 views::View* TrayNetwork::CreateDetailedView(user::LoginStatus status) { |
| 734 CHECK(detailed_ == NULL); | 788 CHECK(detailed_ == NULL); |
| 735 detailed_ = new tray::NetworkDetailedView(status); | 789 if (request_wifi_view_) { |
| 790 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); | |
| 791 // The Wi-Fi state is not toggled yet at this point. | |
| 792 detailed_ = new tray::NetworkWifiDetailedView(!delegate->GetWifiEnabled()); | |
| 793 request_wifi_view_ = false; | |
| 794 } else { | |
| 795 detailed_ = new tray::NetworkListDetailedView(status); | |
| 796 } | |
| 736 return detailed_; | 797 return detailed_; |
| 737 } | 798 } |
| 738 | 799 |
| 739 views::View* TrayNetwork::CreateNotificationView(user::LoginStatus status) { | 800 views::View* TrayNetwork::CreateNotificationView(user::LoginStatus status) { |
| 740 CHECK(notification_ == NULL); | 801 CHECK(notification_ == NULL); |
| 741 if (errors_->messages().empty()) | 802 if (errors_->messages().empty()) |
| 742 return NULL; // Error has already been cleared. | 803 return NULL; // Error has already been cleared. |
| 743 notification_ = new tray::NetworkNotificationView(this); | 804 notification_ = new tray::NetworkNotificationView(this); |
| 744 return notification_; | 805 return notification_; |
| 745 } | 806 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 795 if (notification_) | 856 if (notification_) |
| 796 HideNotificationView(); | 857 HideNotificationView(); |
| 797 return; | 858 return; |
| 798 } | 859 } |
| 799 if (notification_) | 860 if (notification_) |
| 800 notification_->Update(); | 861 notification_->Update(); |
| 801 else | 862 else |
| 802 ShowNotificationView(); | 863 ShowNotificationView(); |
| 803 } | 864 } |
| 804 | 865 |
| 866 void TrayNetwork::OnWillToggleWifi() { | |
| 867 if (!detailed_ || detailed_->view_type() == WIFI_VIEW) { | |
| 868 request_wifi_view_ = true; | |
| 869 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); | |
| 870 } | |
| 871 } | |
| 872 | |
| 805 void TrayNetwork::LinkClicked(ErrorType error_type) { | 873 void TrayNetwork::LinkClicked(ErrorType error_type) { |
| 806 tray::NetworkErrors::ErrorMap::const_iterator iter = | 874 tray::NetworkErrors::ErrorMap::const_iterator iter = |
| 807 errors()->messages().find(error_type); | 875 errors()->messages().find(error_type); |
| 808 if (iter != errors()->messages().end() && iter->second.delegate) | 876 if (iter != errors()->messages().end() && iter->second.delegate) |
| 809 iter->second.delegate->NotificationLinkClicked(); | 877 iter->second.delegate->NotificationLinkClicked(); |
| 810 } | 878 } |
| 811 | 879 |
| 812 } // namespace internal | 880 } // namespace internal |
| 813 } // namespace ash | 881 } // namespace ash |
| OLD | NEW |