| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 virtual bool CanActivate() const OVERRIDE { | 83 virtual bool CanActivate() const OVERRIDE { |
| 84 return false; | 84 return false; |
| 85 } | 85 } |
| 86 | 86 |
| 87 private: | 87 private: |
| 88 DISALLOW_COPY_AND_ASSIGN(NonActivatableSettingsBubble); | 88 DISALLOW_COPY_AND_ASSIGN(NonActivatableSettingsBubble); |
| 89 }; | 89 }; |
| 90 | 90 |
| 91 using ash::internal::TrayNetwork; | 91 using ash::internal::TrayNetwork; |
| 92 | 92 |
| 93 int GetErrorIcon(TrayNetwork::ErrorType error_type) { | 93 int GetMessageIcon(TrayNetwork::MessageType message_type) { |
| 94 switch(error_type) { | 94 switch(message_type) { |
| 95 case TrayNetwork::ERROR_CONNECT_FAILED: | 95 case TrayNetwork::ERROR_CONNECT_FAILED: |
| 96 return IDR_AURA_UBER_TRAY_NETWORK_FAILED; | 96 return IDR_AURA_UBER_TRAY_NETWORK_FAILED; |
| 97 case TrayNetwork::ERROR_DATA_LOW: | 97 case TrayNetwork::MESSAGE_DATA_LOW: |
| 98 return IDR_AURA_UBER_TRAY_NETWORK_DATA_LOW; | 98 return IDR_AURA_UBER_TRAY_NETWORK_DATA_LOW; |
| 99 case TrayNetwork::ERROR_DATA_NONE: | 99 case TrayNetwork::MESSAGE_DATA_NONE: |
| 100 return IDR_AURA_UBER_TRAY_NETWORK_DATA_NONE; | 100 return IDR_AURA_UBER_TRAY_NETWORK_DATA_NONE; |
| 101 case TrayNetwork::MESSAGE_DATA_PROMO: |
| 102 return IDR_AURA_UBER_TRAY_NOTIFICATION_3G; |
| 101 } | 103 } |
| 102 NOTREACHED(); | 104 NOTREACHED(); |
| 103 return 0; | 105 return 0; |
| 104 } | 106 } |
| 105 | 107 |
| 106 } // namespace | 108 } // namespace |
| 107 | 109 |
| 108 namespace ash { | 110 namespace ash { |
| 109 namespace internal { | 111 namespace internal { |
| 110 | 112 |
| 111 namespace tray { | 113 namespace tray { |
| 112 | 114 |
| 113 enum ColorTheme { | 115 enum ColorTheme { |
| 114 LIGHT, | 116 LIGHT, |
| 115 DARK, | 117 DARK, |
| 116 }; | 118 }; |
| 117 | 119 |
| 118 class NetworkErrors { | 120 class NetworkMessages { |
| 119 public: | 121 public: |
| 120 struct Message { | 122 struct Message { |
| 121 Message() : delegate(NULL) {} | 123 Message() : delegate(NULL) {} |
| 122 Message(NetworkTrayDelegate* in_delegate, | 124 Message(NetworkTrayDelegate* in_delegate, |
| 123 const string16& in_title, | 125 const string16& in_title, |
| 124 const string16& in_message, | 126 const string16& in_message, |
| 125 const string16& in_link_text) : | 127 const std::vector<string16>& in_links) : |
| 126 delegate(in_delegate), | 128 delegate(in_delegate), |
| 127 title(in_title), | 129 title(in_title), |
| 128 message(in_message), | 130 message(in_message), |
| 129 link_text(in_link_text) {} | 131 links(in_links) {} |
| 130 NetworkTrayDelegate* delegate; | 132 NetworkTrayDelegate* delegate; |
| 131 string16 title; | 133 string16 title; |
| 132 string16 message; | 134 string16 message; |
| 133 string16 link_text; | 135 std::vector<string16> links; |
| 134 }; | 136 }; |
| 135 typedef std::map<TrayNetwork::ErrorType, Message> ErrorMap; | 137 typedef std::map<TrayNetwork::MessageType, Message> MessageMap; |
| 136 | 138 |
| 137 ErrorMap& messages() { return messages_; } | 139 MessageMap& messages() { return messages_; } |
| 138 const ErrorMap& messages() const { return messages_; } | 140 const MessageMap& messages() const { return messages_; } |
| 139 | 141 |
| 140 private: | 142 private: |
| 141 ErrorMap messages_; | 143 MessageMap messages_; |
| 142 }; | 144 }; |
| 143 | 145 |
| 144 class NetworkTrayView : public TrayItemView { | 146 class NetworkTrayView : public TrayItemView { |
| 145 public: | 147 public: |
| 146 NetworkTrayView(ColorTheme size, bool tray_icon) | 148 NetworkTrayView(ColorTheme size, bool tray_icon) |
| 147 : color_theme_(size), tray_icon_(tray_icon) { | 149 : color_theme_(size), tray_icon_(tray_icon) { |
| 148 SetLayoutManager( | 150 SetLayoutManager( |
| 149 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); | 151 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); |
| 150 | 152 |
| 151 image_view_ = color_theme_ == DARK ? | 153 image_view_ = color_theme_ == DARK ? |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 virtual TrayNetwork::DetailedViewType GetViewType() const OVERRIDE { | 720 virtual TrayNetwork::DetailedViewType GetViewType() const OVERRIDE { |
| 719 return TrayNetwork::WIFI_VIEW; | 721 return TrayNetwork::WIFI_VIEW; |
| 720 } | 722 } |
| 721 | 723 |
| 722 virtual void Update() OVERRIDE {} | 724 virtual void Update() OVERRIDE {} |
| 723 | 725 |
| 724 private: | 726 private: |
| 725 DISALLOW_COPY_AND_ASSIGN(NetworkWifiDetailedView); | 727 DISALLOW_COPY_AND_ASSIGN(NetworkWifiDetailedView); |
| 726 }; | 728 }; |
| 727 | 729 |
| 728 class NetworkErrorView : public views::View, | 730 class NetworkMessageView : public views::View, |
| 729 public views::LinkListener { | 731 public views::LinkListener { |
| 730 public: | 732 public: |
| 731 NetworkErrorView(TrayNetwork* tray, | 733 NetworkMessageView(TrayNetwork* tray, |
| 732 TrayNetwork::ErrorType error_type, | 734 TrayNetwork::MessageType message_type, |
| 733 const NetworkErrors::Message& error) | 735 const NetworkMessages::Message& network_msg) |
| 734 : tray_(tray), | 736 : tray_(tray), |
| 735 error_type_(error_type) { | 737 message_type_(message_type) { |
| 736 SetLayoutManager( | 738 SetLayoutManager( |
| 737 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); | 739 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); |
| 738 | 740 |
| 739 views::Label* title = new views::Label(error.title); | 741 if (!network_msg.title.empty()) { |
| 740 title->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 742 views::Label* title = new views::Label(network_msg.title); |
| 741 title->SetFont(title->font().DeriveFont(0, gfx::Font::BOLD)); | 743 title->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 742 AddChildView(title); | 744 title->SetFont(title->font().DeriveFont(0, gfx::Font::BOLD)); |
| 745 AddChildView(title); |
| 746 } |
| 743 | 747 |
| 744 views::Label* message = new views::Label(error.message); | 748 if (!network_msg.message.empty()) { |
| 745 message->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 749 views::Label* message = new views::Label(network_msg.message); |
| 746 message->SetMultiLine(true); | 750 message->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 747 message->SizeToFit(kTrayNotificationContentsWidth); | 751 message->SetMultiLine(true); |
| 748 AddChildView(message); | 752 message->SizeToFit(kTrayNotificationContentsWidth); |
| 753 AddChildView(message); |
| 754 } |
| 749 | 755 |
| 750 if (!error.link_text.empty()) { | 756 if (!network_msg.links.empty()) { |
| 751 views::Link* link = new views::Link(error.link_text); | 757 for (size_t i = 0; i < network_msg.links.size(); ++i) { |
| 752 link->set_listener(this); | 758 views::Link* link = new views::Link(network_msg.links[i]); |
| 753 link->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 759 link->set_id(i); |
| 754 link->SetMultiLine(true); | 760 link->set_listener(this); |
| 755 link->SizeToFit(kTrayNotificationContentsWidth); | 761 link->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 756 AddChildView(link); | 762 link->SetMultiLine(true); |
| 763 link->SizeToFit(kTrayNotificationContentsWidth); |
| 764 AddChildView(link); |
| 765 } |
| 757 } | 766 } |
| 758 } | 767 } |
| 759 | 768 |
| 760 virtual ~NetworkErrorView() { | 769 virtual ~NetworkMessageView() { |
| 761 } | 770 } |
| 762 | 771 |
| 763 // Overridden from views::LinkListener. | 772 // Overridden from views::LinkListener. |
| 764 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE { | 773 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE { |
| 765 tray_->LinkClicked(error_type_); | 774 tray_->LinkClicked(message_type_, source->id()); |
| 766 } | 775 } |
| 767 | 776 |
| 768 TrayNetwork::ErrorType error_type() const { return error_type_; } | 777 TrayNetwork::MessageType message_type() const { return message_type_; } |
| 769 | 778 |
| 770 private: | 779 private: |
| 771 TrayNetwork* tray_; | 780 TrayNetwork* tray_; |
| 772 TrayNetwork::ErrorType error_type_; | 781 TrayNetwork::MessageType message_type_; |
| 773 | 782 |
| 774 DISALLOW_COPY_AND_ASSIGN(NetworkErrorView); | 783 DISALLOW_COPY_AND_ASSIGN(NetworkMessageView); |
| 775 }; | 784 }; |
| 776 | 785 |
| 777 class NetworkNotificationView : public TrayNotificationView { | 786 class NetworkNotificationView : public TrayNotificationView { |
| 778 public: | 787 public: |
| 779 explicit NetworkNotificationView(TrayNetwork* tray) | 788 explicit NetworkNotificationView(TrayNetwork* tray) |
| 780 : TrayNotificationView(tray, 0) { | 789 : TrayNotificationView(tray, 0) { |
| 781 CreateErrorView(); | 790 CreateMessageView(); |
| 782 InitView(network_error_view_); | 791 InitView(network_message_view_); |
| 783 SetIconImage(*ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 792 SetIconImage(*ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 784 GetErrorIcon(network_error_view_->error_type()))); | 793 GetMessageIcon(network_message_view_->message_type()))); |
| 785 } | 794 } |
| 786 | 795 |
| 787 // Overridden from TrayNotificationView. | 796 // Overridden from TrayNotificationView. |
| 788 virtual void OnClose() OVERRIDE { | 797 virtual void OnClose() OVERRIDE { |
| 789 tray_network()->ClearNetworkError(network_error_view_->error_type()); | 798 tray_network()->ClearNetworkMessage(network_message_view_->message_type()); |
| 790 } | 799 } |
| 791 | 800 |
| 792 virtual void OnClickAction() OVERRIDE { | 801 virtual void OnClickAction() OVERRIDE { |
| 793 tray()->PopupDetailedView(0, true); | 802 if (network_message_view_->message_type() != |
| 803 TrayNetwork::MESSAGE_DATA_PROMO) |
| 804 tray()->PopupDetailedView(0, true); |
| 794 } | 805 } |
| 795 | 806 |
| 796 void Update() { | 807 void Update() { |
| 797 CreateErrorView(); | 808 CreateMessageView(); |
| 798 UpdateViewAndImage(network_error_view_, | 809 UpdateViewAndImage(network_message_view_, |
| 799 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 810 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 800 GetErrorIcon(network_error_view_->error_type()))); | 811 GetMessageIcon(network_message_view_->message_type()))); |
| 801 } | 812 } |
| 802 | 813 |
| 803 private: | 814 private: |
| 804 TrayNetwork* tray_network() { | 815 TrayNetwork* tray_network() { |
| 805 return static_cast<TrayNetwork*>(tray()); | 816 return static_cast<TrayNetwork*>(tray()); |
| 806 } | 817 } |
| 807 | 818 |
| 808 void CreateErrorView() { | 819 void CreateMessageView() { |
| 809 // Display the first (highest priority) error. | 820 // Display the first (highest priority) message. |
| 810 CHECK(!tray_network()->errors()->messages().empty()); | 821 CHECK(!tray_network()->messages()->messages().empty()); |
| 811 NetworkErrors::ErrorMap::const_iterator iter = | 822 NetworkMessages::MessageMap::const_iterator iter = |
| 812 tray_network()->errors()->messages().begin(); | 823 tray_network()->messages()->messages().begin(); |
| 813 network_error_view_ = | 824 network_message_view_ = |
| 814 new NetworkErrorView(tray_network(), iter->first, iter->second); | 825 new NetworkMessageView(tray_network(), iter->first, iter->second); |
| 815 } | 826 } |
| 816 | 827 |
| 817 tray::NetworkErrorView* network_error_view_; | 828 tray::NetworkMessageView* network_message_view_; |
| 818 | 829 |
| 819 DISALLOW_COPY_AND_ASSIGN(NetworkNotificationView); | 830 DISALLOW_COPY_AND_ASSIGN(NetworkNotificationView); |
| 820 }; | 831 }; |
| 821 | 832 |
| 822 } // namespace tray | 833 } // namespace tray |
| 823 | 834 |
| 824 TrayNetwork::TrayNetwork() | 835 TrayNetwork::TrayNetwork() |
| 825 : tray_(NULL), | 836 : tray_(NULL), |
| 826 default_(NULL), | 837 default_(NULL), |
| 827 detailed_(NULL), | 838 detailed_(NULL), |
| 828 notification_(NULL), | 839 notification_(NULL), |
| 829 errors_(new tray::NetworkErrors()), | 840 messages_(new tray::NetworkMessages()), |
| 830 request_wifi_view_(false) { | 841 request_wifi_view_(false) { |
| 831 } | 842 } |
| 832 | 843 |
| 833 TrayNetwork::~TrayNetwork() { | 844 TrayNetwork::~TrayNetwork() { |
| 834 } | 845 } |
| 835 | 846 |
| 836 views::View* TrayNetwork::CreateTrayView(user::LoginStatus status) { | 847 views::View* TrayNetwork::CreateTrayView(user::LoginStatus status) { |
| 837 CHECK(tray_ == NULL); | 848 CHECK(tray_ == NULL); |
| 838 tray_ = new tray::NetworkTrayView(tray::LIGHT, true /*tray_icon*/); | 849 tray_ = new tray::NetworkTrayView(tray::LIGHT, true /*tray_icon*/); |
| 839 return tray_; | 850 return tray_; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 853 detailed_ = new tray::NetworkWifiDetailedView(!delegate->GetWifiEnabled()); | 864 detailed_ = new tray::NetworkWifiDetailedView(!delegate->GetWifiEnabled()); |
| 854 request_wifi_view_ = false; | 865 request_wifi_view_ = false; |
| 855 } else { | 866 } else { |
| 856 detailed_ = new tray::NetworkListDetailedView(status); | 867 detailed_ = new tray::NetworkListDetailedView(status); |
| 857 } | 868 } |
| 858 return detailed_; | 869 return detailed_; |
| 859 } | 870 } |
| 860 | 871 |
| 861 views::View* TrayNetwork::CreateNotificationView(user::LoginStatus status) { | 872 views::View* TrayNetwork::CreateNotificationView(user::LoginStatus status) { |
| 862 CHECK(notification_ == NULL); | 873 CHECK(notification_ == NULL); |
| 863 if (errors_->messages().empty()) | 874 if (messages_->messages().empty()) |
| 864 return NULL; // Error has already been cleared. | 875 return NULL; // Message has already been cleared. |
| 865 notification_ = new tray::NetworkNotificationView(this); | 876 notification_ = new tray::NetworkNotificationView(this); |
| 866 return notification_; | 877 return notification_; |
| 867 } | 878 } |
| 868 | 879 |
| 869 void TrayNetwork::DestroyTrayView() { | 880 void TrayNetwork::DestroyTrayView() { |
| 870 tray_ = NULL; | 881 tray_ = NULL; |
| 871 } | 882 } |
| 872 | 883 |
| 873 void TrayNetwork::DestroyDefaultView() { | 884 void TrayNetwork::DestroyDefaultView() { |
| 874 default_ = NULL; | 885 default_ = NULL; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 891 | 902 |
| 892 void TrayNetwork::OnNetworkRefresh(const NetworkIconInfo& info) { | 903 void TrayNetwork::OnNetworkRefresh(const NetworkIconInfo& info) { |
| 893 if (tray_) | 904 if (tray_) |
| 894 tray_->Update(info); | 905 tray_->Update(info); |
| 895 if (default_) | 906 if (default_) |
| 896 default_->Update(); | 907 default_->Update(); |
| 897 if (detailed_) | 908 if (detailed_) |
| 898 detailed_->Update(); | 909 detailed_->Update(); |
| 899 } | 910 } |
| 900 | 911 |
| 901 void TrayNetwork::SetNetworkError(NetworkTrayDelegate* delegate, | 912 void TrayNetwork::SetNetworkMessage(NetworkTrayDelegate* delegate, |
| 902 ErrorType error_type, | 913 MessageType message_type, |
| 903 const string16& title, | 914 const string16& title, |
| 904 const string16& message, | 915 const string16& message, |
| 905 const string16& link_text) { | 916 const std::vector<string16>& links) { |
| 906 errors_->messages()[error_type] = | 917 messages_->messages()[message_type] = |
| 907 tray::NetworkErrors::Message(delegate, title, message, link_text); | 918 tray::NetworkMessages::Message(delegate, title, message, links); |
| 908 if (notification_) | 919 if (notification_) |
| 909 notification_->Update(); | 920 notification_->Update(); |
| 910 else | 921 else |
| 911 ShowNotificationView(); | 922 ShowNotificationView(); |
| 912 } | 923 } |
| 913 | 924 |
| 914 void TrayNetwork::ClearNetworkError(ErrorType error_type) { | 925 void TrayNetwork::ClearNetworkMessage(MessageType message_type) { |
| 915 errors_->messages().erase(error_type); | 926 messages_->messages().erase(message_type); |
| 916 if (errors_->messages().empty()) { | 927 if (messages_->messages().empty()) { |
| 917 if (notification_) | 928 if (notification_) |
| 918 HideNotificationView(); | 929 HideNotificationView(); |
| 919 return; | 930 return; |
| 920 } | 931 } |
| 921 if (notification_) | 932 if (notification_) |
| 922 notification_->Update(); | 933 notification_->Update(); |
| 923 else | 934 else |
| 924 ShowNotificationView(); | 935 ShowNotificationView(); |
| 925 } | 936 } |
| 926 | 937 |
| 927 void TrayNetwork::OnWillToggleWifi() { | 938 void TrayNetwork::OnWillToggleWifi() { |
| 928 if (!detailed_ || detailed_->GetViewType() == WIFI_VIEW) { | 939 if (!detailed_ || detailed_->GetViewType() == WIFI_VIEW) { |
| 929 request_wifi_view_ = true; | 940 request_wifi_view_ = true; |
| 930 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); | 941 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); |
| 931 } | 942 } |
| 932 } | 943 } |
| 933 | 944 |
| 934 void TrayNetwork::LinkClicked(ErrorType error_type) { | 945 void TrayNetwork::LinkClicked(MessageType message_type, int link_id) { |
| 935 tray::NetworkErrors::ErrorMap::const_iterator iter = | 946 tray::NetworkMessages::MessageMap::const_iterator iter = |
| 936 errors()->messages().find(error_type); | 947 messages()->messages().find(message_type); |
| 937 if (iter != errors()->messages().end() && iter->second.delegate) | 948 if (iter != messages()->messages().end() && iter->second.delegate) |
| 938 iter->second.delegate->NotificationLinkClicked(); | 949 iter->second.delegate->NotificationLinkClicked(link_id); |
| 939 } | 950 } |
| 940 | 951 |
| 941 } // namespace internal | 952 } // namespace internal |
| 942 } // namespace ash | 953 } // namespace ash |
| OLD | NEW |