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

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

Issue 10824142: Support toggling Wi-Fi with keyboard shortcut. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 4 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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 GetViewType() const = 0;
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 GetViewType() 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 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 TrayPopupHeaderButton* button_mobile_; 620 TrayPopupHeaderButton* button_mobile_;
605 views::View* view_mobile_account_; 621 views::View* view_mobile_account_;
606 views::View* setup_mobile_account_; 622 views::View* setup_mobile_account_;
607 TrayPopupTextButton* other_wifi_; 623 TrayPopupTextButton* other_wifi_;
608 TrayPopupTextButton* other_mobile_; 624 TrayPopupTextButton* other_mobile_;
609 TrayPopupTextButton* settings_; 625 TrayPopupTextButton* settings_;
610 TrayPopupTextButton* proxy_settings_; 626 TrayPopupTextButton* proxy_settings_;
611 627
612 views::BubbleDelegateView* info_bubble_; 628 views::BubbleDelegateView* info_bubble_;
613 629
614 DISALLOW_COPY_AND_ASSIGN(NetworkDetailedView); 630 DISALLOW_COPY_AND_ASSIGN(NetworkListDetailedView);
631 };
632
633 class NetworkWifiDetailedView : public NetworkDetailedView {
634 public:
635 explicit NetworkWifiDetailedView(bool wifi_enabled) {
636 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal,
637 kTrayPopupPaddingHorizontal,
638 10,
639 kTrayPopupPaddingBetweenItems));
640 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
641 views::ImageView* image = new views::ImageView;
642 const int image_id = wifi_enabled ?
643 IDR_AURA_UBER_TRAY_WIFI_ENABLED : IDR_AURA_UBER_TRAY_WIFI_DISABLED;
644 image->SetImage(bundle.GetImageNamed(image_id).ToImageSkia());
645 AddChildView(image);
646
647 const int string_id = wifi_enabled ?
648 IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED:
649 IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED;
650 views::Label* label =
651 new views::Label(bundle.GetLocalizedString(string_id));
652 label->SetMultiLine(true);
653 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
654 AddChildView(label);
655 }
656
657 virtual ~NetworkWifiDetailedView() {}
658
659 // Overridden from NetworkDetailedView:
660 virtual TrayNetwork::DetailedViewType GetViewType() const OVERRIDE {
661 return TrayNetwork::WIFI_VIEW;
662 }
663
664 virtual void Update() OVERRIDE {}
665
666 private:
667 DISALLOW_COPY_AND_ASSIGN(NetworkWifiDetailedView);
615 }; 668 };
616 669
617 class NetworkErrorView : public views::View, 670 class NetworkErrorView : public views::View,
618 public views::LinkListener { 671 public views::LinkListener {
619 public: 672 public:
620 NetworkErrorView(TrayNetwork* tray, 673 NetworkErrorView(TrayNetwork* tray,
621 TrayNetwork::ErrorType error_type, 674 TrayNetwork::ErrorType error_type,
622 const NetworkErrors::Message& error) 675 const NetworkErrors::Message& error)
623 : tray_(tray), 676 : tray_(tray),
624 error_type_(error_type) { 677 error_type_(error_type) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 DISALLOW_COPY_AND_ASSIGN(NetworkNotificationView); 761 DISALLOW_COPY_AND_ASSIGN(NetworkNotificationView);
709 }; 762 };
710 763
711 } // namespace tray 764 } // namespace tray
712 765
713 TrayNetwork::TrayNetwork() 766 TrayNetwork::TrayNetwork()
714 : tray_(NULL), 767 : tray_(NULL),
715 default_(NULL), 768 default_(NULL),
716 detailed_(NULL), 769 detailed_(NULL),
717 notification_(NULL), 770 notification_(NULL),
718 errors_(new tray::NetworkErrors()) { 771 errors_(new tray::NetworkErrors()),
772 request_wifi_view_(false) {
719 } 773 }
720 774
721 TrayNetwork::~TrayNetwork() { 775 TrayNetwork::~TrayNetwork() {
722 } 776 }
723 777
724 views::View* TrayNetwork::CreateTrayView(user::LoginStatus status) { 778 views::View* TrayNetwork::CreateTrayView(user::LoginStatus status) {
725 CHECK(tray_ == NULL); 779 CHECK(tray_ == NULL);
726 tray_ = new tray::NetworkTrayView(tray::LIGHT, true /*tray_icon*/); 780 tray_ = new tray::NetworkTrayView(tray::LIGHT, true /*tray_icon*/);
727 return tray_; 781 return tray_;
728 } 782 }
729 783
730 views::View* TrayNetwork::CreateDefaultView(user::LoginStatus status) { 784 views::View* TrayNetwork::CreateDefaultView(user::LoginStatus status) {
731 CHECK(default_ == NULL); 785 CHECK(default_ == NULL);
732 default_ = new tray::NetworkDefaultView(this); 786 default_ = new tray::NetworkDefaultView(this);
733 return default_; 787 return default_;
734 } 788 }
735 789
736 views::View* TrayNetwork::CreateDetailedView(user::LoginStatus status) { 790 views::View* TrayNetwork::CreateDetailedView(user::LoginStatus status) {
737 CHECK(detailed_ == NULL); 791 CHECK(detailed_ == NULL);
738 detailed_ = new tray::NetworkDetailedView(status); 792 if (request_wifi_view_) {
793 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate();
794 // The Wi-Fi state is not toggled yet at this point.
795 detailed_ = new tray::NetworkWifiDetailedView(!delegate->GetWifiEnabled());
796 request_wifi_view_ = false;
797 } else {
798 detailed_ = new tray::NetworkListDetailedView(status);
799 }
739 return detailed_; 800 return detailed_;
740 } 801 }
741 802
742 views::View* TrayNetwork::CreateNotificationView(user::LoginStatus status) { 803 views::View* TrayNetwork::CreateNotificationView(user::LoginStatus status) {
743 CHECK(notification_ == NULL); 804 CHECK(notification_ == NULL);
744 if (errors_->messages().empty()) 805 if (errors_->messages().empty())
745 return NULL; // Error has already been cleared. 806 return NULL; // Error has already been cleared.
746 notification_ = new tray::NetworkNotificationView(this); 807 notification_ = new tray::NetworkNotificationView(this);
747 return notification_; 808 return notification_;
748 } 809 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 if (notification_) 859 if (notification_)
799 HideNotificationView(); 860 HideNotificationView();
800 return; 861 return;
801 } 862 }
802 if (notification_) 863 if (notification_)
803 notification_->Update(); 864 notification_->Update();
804 else 865 else
805 ShowNotificationView(); 866 ShowNotificationView();
806 } 867 }
807 868
869 void TrayNetwork::OnWillToggleWifi() {
870 if (!detailed_ || detailed_->GetViewType() == WIFI_VIEW) {
871 request_wifi_view_ = true;
872 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false);
873 }
874 }
875
808 void TrayNetwork::LinkClicked(ErrorType error_type) { 876 void TrayNetwork::LinkClicked(ErrorType error_type) {
809 tray::NetworkErrors::ErrorMap::const_iterator iter = 877 tray::NetworkErrors::ErrorMap::const_iterator iter =
810 errors()->messages().find(error_type); 878 errors()->messages().find(error_type);
811 if (iter != errors()->messages().end() && iter->second.delegate) 879 if (iter != errors()->messages().end() && iter->second.delegate)
812 iter->second.delegate->NotificationLinkClicked(); 880 iter->second.delegate->NotificationLinkClicked();
813 } 881 }
814 882
815 } // namespace internal 883 } // namespace internal
816 } // namespace ash 884 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/network/tray_network.h ('k') | chrome/browser/chromeos/system/ash_system_tray_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698