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

Side by Side Diff: ash/system/network/tray_network.cc

Issue 10907224: Data promo notification should follow the normal ash notifications theme. This (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: patch Created 8 years, 3 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 | Annotate | Revision Log
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/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
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 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 virtual TrayNetwork::DetailedViewType GetViewType() const OVERRIDE { 731 virtual TrayNetwork::DetailedViewType GetViewType() const OVERRIDE {
730 return TrayNetwork::WIFI_VIEW; 732 return TrayNetwork::WIFI_VIEW;
731 } 733 }
732 734
733 virtual void Update() OVERRIDE {} 735 virtual void Update() OVERRIDE {}
734 736
735 private: 737 private:
736 DISALLOW_COPY_AND_ASSIGN(NetworkWifiDetailedView); 738 DISALLOW_COPY_AND_ASSIGN(NetworkWifiDetailedView);
737 }; 739 };
738 740
739 class NetworkErrorView : public views::View, 741 class NetworkMessageView : public views::View,
740 public views::LinkListener { 742 public views::LinkListener {
741 public: 743 public:
742 NetworkErrorView(TrayNetwork* tray, 744 NetworkMessageView(TrayNetwork* tray,
743 TrayNetwork::ErrorType error_type, 745 TrayNetwork::MessageType message_type,
744 const NetworkErrors::Message& error) 746 const NetworkMessages::Message& network_msg)
745 : tray_(tray), 747 : tray_(tray),
746 error_type_(error_type) { 748 message_type_(message_type) {
747 SetLayoutManager( 749 SetLayoutManager(
748 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); 750 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1));
749 751
750 views::Label* title = new views::Label(error.title); 752 if (!network_msg.title.empty()) {
751 title->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 753 views::Label* title = new views::Label(network_msg.title);
752 title->SetFont(title->font().DeriveFont(0, gfx::Font::BOLD)); 754 title->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
753 AddChildView(title); 755 title->SetFont(title->font().DeriveFont(0, gfx::Font::BOLD));
756 AddChildView(title);
757 }
754 758
755 views::Label* message = new views::Label(error.message); 759 if (!network_msg.message.empty()) {
756 message->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 760 views::Label* message = new views::Label(network_msg.message);
757 message->SetMultiLine(true); 761 message->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
758 message->SizeToFit(kTrayNotificationContentsWidth); 762 message->SetMultiLine(true);
759 AddChildView(message); 763 message->SizeToFit(kTrayNotificationContentsWidth);
764 AddChildView(message);
765 }
760 766
761 if (!error.link_text.empty()) { 767 if (!network_msg.links.empty()) {
762 views::Link* link = new views::Link(error.link_text); 768 for (size_t i = 0; i < network_msg.links.size(); ++i) {
763 link->set_listener(this); 769 views::Link* link = new views::Link(network_msg.links[i]);
764 link->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 770 link->set_id(i);
765 link->SetMultiLine(true); 771 link->set_listener(this);
766 link->SizeToFit(kTrayNotificationContentsWidth); 772 link->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
767 AddChildView(link); 773 link->SetMultiLine(true);
774 link->SizeToFit(kTrayNotificationContentsWidth);
775 AddChildView(link);
776 }
768 } 777 }
769 } 778 }
770 779
771 virtual ~NetworkErrorView() { 780 virtual ~NetworkMessageView() {
772 } 781 }
773 782
774 // Overridden from views::LinkListener. 783 // Overridden from views::LinkListener.
775 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE { 784 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE {
776 tray_->LinkClicked(error_type_); 785 tray_->LinkClicked(message_type_, source->id());
777 } 786 }
778 787
779 TrayNetwork::ErrorType error_type() const { return error_type_; } 788 TrayNetwork::MessageType message_type() const { return message_type_; }
780 789
781 private: 790 private:
782 TrayNetwork* tray_; 791 TrayNetwork* tray_;
783 TrayNetwork::ErrorType error_type_; 792 TrayNetwork::MessageType message_type_;
784 793
785 DISALLOW_COPY_AND_ASSIGN(NetworkErrorView); 794 DISALLOW_COPY_AND_ASSIGN(NetworkMessageView);
786 }; 795 };
787 796
788 class NetworkNotificationView : public TrayNotificationView { 797 class NetworkNotificationView : public TrayNotificationView {
789 public: 798 public:
790 explicit NetworkNotificationView(TrayNetwork* tray) 799 explicit NetworkNotificationView(TrayNetwork* tray)
791 : TrayNotificationView(tray, 0) { 800 : TrayNotificationView(tray, 0) {
792 CreateErrorView(); 801 CreateMessageView();
793 InitView(network_error_view_); 802 InitView(network_message_view_);
794 SetIconImage(*ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 803 SetIconImage(*ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
795 GetErrorIcon(network_error_view_->error_type()))); 804 GetMessageIcon(network_message_view_->message_type())));
796 } 805 }
797 806
798 // Overridden from TrayNotificationView. 807 // Overridden from TrayNotificationView.
799 virtual void OnClose() OVERRIDE { 808 virtual void OnClose() OVERRIDE {
800 tray_network()->ClearNetworkError(network_error_view_->error_type()); 809 tray_network()->ClearNetworkMessage(network_message_view_->message_type());
801 } 810 }
802 811
803 virtual void OnClickAction() OVERRIDE { 812 virtual void OnClickAction() OVERRIDE {
804 tray()->PopupDetailedView(0, true); 813 if (network_message_view_->message_type() !=
814 TrayNetwork::MESSAGE_DATA_PROMO)
815 tray()->PopupDetailedView(0, true);
805 } 816 }
806 817
807 void Update() { 818 void Update() {
808 CreateErrorView(); 819 CreateMessageView();
809 UpdateViewAndImage(network_error_view_, 820 UpdateViewAndImage(network_message_view_,
810 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 821 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
811 GetErrorIcon(network_error_view_->error_type()))); 822 GetMessageIcon(network_message_view_->message_type())));
812 } 823 }
813 824
814 private: 825 private:
815 TrayNetwork* tray_network() { 826 TrayNetwork* tray_network() {
816 return static_cast<TrayNetwork*>(tray()); 827 return static_cast<TrayNetwork*>(tray());
817 } 828 }
818 829
819 void CreateErrorView() { 830 void CreateMessageView() {
820 // Display the first (highest priority) error. 831 // Display the first (highest priority) message.
821 CHECK(!tray_network()->errors()->messages().empty()); 832 CHECK(!tray_network()->messages()->messages().empty());
822 NetworkErrors::ErrorMap::const_iterator iter = 833 NetworkMessages::MessageMap::const_iterator iter =
823 tray_network()->errors()->messages().begin(); 834 tray_network()->messages()->messages().begin();
824 network_error_view_ = 835 network_message_view_ =
825 new NetworkErrorView(tray_network(), iter->first, iter->second); 836 new NetworkMessageView(tray_network(), iter->first, iter->second);
826 } 837 }
827 838
828 tray::NetworkErrorView* network_error_view_; 839 tray::NetworkMessageView* network_message_view_;
829 840
830 DISALLOW_COPY_AND_ASSIGN(NetworkNotificationView); 841 DISALLOW_COPY_AND_ASSIGN(NetworkNotificationView);
831 }; 842 };
832 843
833 } // namespace tray 844 } // namespace tray
834 845
835 TrayNetwork::TrayNetwork() 846 TrayNetwork::TrayNetwork()
836 : tray_(NULL), 847 : tray_(NULL),
837 default_(NULL), 848 default_(NULL),
838 detailed_(NULL), 849 detailed_(NULL),
839 notification_(NULL), 850 notification_(NULL),
840 errors_(new tray::NetworkErrors()), 851 messages_(new tray::NetworkMessages()),
841 request_wifi_view_(false) { 852 request_wifi_view_(false) {
842 } 853 }
843 854
844 TrayNetwork::~TrayNetwork() { 855 TrayNetwork::~TrayNetwork() {
845 } 856 }
846 857
847 views::View* TrayNetwork::CreateTrayView(user::LoginStatus status) { 858 views::View* TrayNetwork::CreateTrayView(user::LoginStatus status) {
848 CHECK(tray_ == NULL); 859 CHECK(tray_ == NULL);
849 tray_ = new tray::NetworkTrayView(tray::LIGHT, true /*tray_icon*/); 860 tray_ = new tray::NetworkTrayView(tray::LIGHT, true /*tray_icon*/);
850 return tray_; 861 return tray_;
(...skipping 13 matching lines...) Expand all
864 detailed_ = new tray::NetworkWifiDetailedView(!delegate->GetWifiEnabled()); 875 detailed_ = new tray::NetworkWifiDetailedView(!delegate->GetWifiEnabled());
865 request_wifi_view_ = false; 876 request_wifi_view_ = false;
866 } else { 877 } else {
867 detailed_ = new tray::NetworkListDetailedView(status); 878 detailed_ = new tray::NetworkListDetailedView(status);
868 } 879 }
869 return detailed_; 880 return detailed_;
870 } 881 }
871 882
872 views::View* TrayNetwork::CreateNotificationView(user::LoginStatus status) { 883 views::View* TrayNetwork::CreateNotificationView(user::LoginStatus status) {
873 CHECK(notification_ == NULL); 884 CHECK(notification_ == NULL);
874 if (errors_->messages().empty()) 885 if (messages_->messages().empty())
875 return NULL; // Error has already been cleared. 886 return NULL; // Message has already been cleared.
876 notification_ = new tray::NetworkNotificationView(this); 887 notification_ = new tray::NetworkNotificationView(this);
877 return notification_; 888 return notification_;
878 } 889 }
879 890
880 void TrayNetwork::DestroyTrayView() { 891 void TrayNetwork::DestroyTrayView() {
881 tray_ = NULL; 892 tray_ = NULL;
882 } 893 }
883 894
884 void TrayNetwork::DestroyDefaultView() { 895 void TrayNetwork::DestroyDefaultView() {
885 default_ = NULL; 896 default_ = NULL;
(...skipping 16 matching lines...) Expand all
902 913
903 void TrayNetwork::OnNetworkRefresh(const NetworkIconInfo& info) { 914 void TrayNetwork::OnNetworkRefresh(const NetworkIconInfo& info) {
904 if (tray_) 915 if (tray_)
905 tray_->Update(info); 916 tray_->Update(info);
906 if (default_) 917 if (default_)
907 default_->Update(); 918 default_->Update();
908 if (detailed_) 919 if (detailed_)
909 detailed_->Update(); 920 detailed_->Update();
910 } 921 }
911 922
912 void TrayNetwork::SetNetworkError(NetworkTrayDelegate* delegate, 923 void TrayNetwork::SetNetworkMessage(NetworkTrayDelegate* delegate,
913 ErrorType error_type, 924 MessageType message_type,
914 const string16& title, 925 const string16& title,
915 const string16& message, 926 const string16& message,
916 const string16& link_text) { 927 const std::vector<string16>& links) {
917 errors_->messages()[error_type] = 928 messages_->messages()[message_type] =
918 tray::NetworkErrors::Message(delegate, title, message, link_text); 929 tray::NetworkMessages::Message(delegate, title, message, links);
919 if (notification_) 930 if (notification_)
920 notification_->Update(); 931 notification_->Update();
921 else 932 else
922 ShowNotificationView(); 933 ShowNotificationView();
923 } 934 }
924 935
925 void TrayNetwork::ClearNetworkError(ErrorType error_type) { 936 void TrayNetwork::ClearNetworkMessage(MessageType message_type) {
926 errors_->messages().erase(error_type); 937 messages_->messages().erase(message_type);
927 if (errors_->messages().empty()) { 938 if (messages_->messages().empty()) {
928 if (notification_) 939 if (notification_)
929 HideNotificationView(); 940 HideNotificationView();
930 return; 941 return;
931 } 942 }
932 if (notification_) 943 if (notification_)
933 notification_->Update(); 944 notification_->Update();
934 else 945 else
935 ShowNotificationView(); 946 ShowNotificationView();
936 } 947 }
937 948
938 void TrayNetwork::OnWillToggleWifi() { 949 void TrayNetwork::OnWillToggleWifi() {
939 if (!detailed_ || detailed_->GetViewType() == WIFI_VIEW) { 950 if (!detailed_ || detailed_->GetViewType() == WIFI_VIEW) {
940 request_wifi_view_ = true; 951 request_wifi_view_ = true;
941 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); 952 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false);
942 } 953 }
943 } 954 }
944 955
945 void TrayNetwork::LinkClicked(ErrorType error_type) { 956 void TrayNetwork::LinkClicked(MessageType message_type, int link_id) {
946 tray::NetworkErrors::ErrorMap::const_iterator iter = 957 tray::NetworkMessages::MessageMap::const_iterator iter =
947 errors()->messages().find(error_type); 958 messages()->messages().find(message_type);
948 if (iter != errors()->messages().end() && iter->second.delegate) 959 if (iter != messages()->messages().end() && iter->second.delegate)
949 iter->second.delegate->NotificationLinkClicked(); 960 iter->second.delegate->NotificationLinkClicked(link_id);
950 } 961 }
951 962
952 } // namespace internal 963 } // namespace internal
953 } // namespace ash 964 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698