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

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: Change the key conbination and messages for popup 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 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 tray_network()->errors()->messages().begin(); 698 tray_network()->errors()->messages().begin();
699 network_error_view_ = 699 network_error_view_ =
700 new NetworkErrorView(tray_network(), iter->first, iter->second); 700 new NetworkErrorView(tray_network(), iter->first, iter->second);
701 } 701 }
702 702
703 tray::NetworkErrorView* network_error_view_; 703 tray::NetworkErrorView* network_error_view_;
704 704
705 DISALLOW_COPY_AND_ASSIGN(NetworkNotificationView); 705 DISALLOW_COPY_AND_ASSIGN(NetworkNotificationView);
706 }; 706 };
707 707
708 class NetworkWifiDetailedView : public TrayDetailsView {
709 public:
710 explicit NetworkWifiDetailedView(bool wifi_enabled) {
711 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal,
712 kTrayPopupPaddingHorizontal,
713 10,
714 kTrayPopupPaddingBetweenItems));
715
716 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
717 views::ImageView* image = new views::ImageView;
718 const int image_id = wifi_enabled ?
719 IDR_AURA_UBER_TRAY_WIFI_ENABLED : IDR_AURA_UBER_TRAY_WIFI_DISABLED;
720 image->SetImage(bundle.GetImageNamed(image_id).ToImageSkia());
721 AddChildView(image);
722
723 const int string_id = wifi_enabled ?
724 IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED:
725 IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED;
726 views::Label* label =
727 new views::Label(bundle.GetLocalizedString(string_id));
728 label->SetMultiLine(true);
729 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
730 AddChildView(label);
731 }
732
733 virtual ~NetworkWifiDetailedView() {}
734
735 private:
736 DISALLOW_COPY_AND_ASSIGN(NetworkWifiDetailedView);
737 };
738
708 } // namespace tray 739 } // namespace tray
709 740
710 TrayNetwork::TrayNetwork() 741 TrayNetwork::TrayNetwork()
711 : tray_(NULL), 742 : tray_(NULL),
712 default_(NULL), 743 default_(NULL),
713 detailed_(NULL), 744 detailed_(NULL),
745 wifi_view_(NULL),
714 notification_(NULL), 746 notification_(NULL),
715 errors_(new tray::NetworkErrors()) { 747 errors_(new tray::NetworkErrors()) {
716 } 748 }
717 749
718 TrayNetwork::~TrayNetwork() { 750 TrayNetwork::~TrayNetwork() {
719 } 751 }
720 752
721 views::View* TrayNetwork::CreateTrayView(user::LoginStatus status) { 753 views::View* TrayNetwork::CreateTrayView(user::LoginStatus status) {
722 CHECK(tray_ == NULL); 754 CHECK(tray_ == NULL);
723 tray_ = new tray::NetworkTrayView(tray::LIGHT, true /*tray_icon*/); 755 tray_ = new tray::NetworkTrayView(tray::LIGHT, true /*tray_icon*/);
724 return tray_; 756 return tray_;
725 } 757 }
726 758
727 views::View* TrayNetwork::CreateDefaultView(user::LoginStatus status) { 759 views::View* TrayNetwork::CreateDefaultView(user::LoginStatus status) {
728 CHECK(default_ == NULL); 760 CHECK(default_ == NULL);
729 default_ = new tray::NetworkDefaultView(this); 761 default_ = new tray::NetworkDefaultView(this);
730 return default_; 762 return default_;
731 } 763 }
732 764
733 views::View* TrayNetwork::CreateDetailedView(user::LoginStatus status) { 765 views::View* TrayNetwork::CreateDetailedView(user::LoginStatus status) {
766 if (wifi_view_) {
767 views::View* returned_view = wifi_view_;
768 wifi_view_ = NULL;
769 return returned_view;
stevenjb 2012/08/02 17:47:16 This logic is pretty confusing. I think we would b
mazda 2012/08/02 19:49:16 Done.
770 }
771
734 CHECK(detailed_ == NULL); 772 CHECK(detailed_ == NULL);
735 detailed_ = new tray::NetworkDetailedView(status); 773 detailed_ = new tray::NetworkDetailedView(status);
736 return detailed_; 774 return detailed_;
737 } 775 }
738 776
739 views::View* TrayNetwork::CreateNotificationView(user::LoginStatus status) { 777 views::View* TrayNetwork::CreateNotificationView(user::LoginStatus status) {
740 CHECK(notification_ == NULL); 778 CHECK(notification_ == NULL);
741 if (errors_->messages().empty()) 779 if (errors_->messages().empty())
742 return NULL; // Error has already been cleared. 780 return NULL; // Error has already been cleared.
743 notification_ = new tray::NetworkNotificationView(this); 781 notification_ = new tray::NetworkNotificationView(this);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 if (notification_) 833 if (notification_)
796 HideNotificationView(); 834 HideNotificationView();
797 return; 835 return;
798 } 836 }
799 if (notification_) 837 if (notification_)
800 notification_->Update(); 838 notification_->Update();
801 else 839 else
802 ShowNotificationView(); 840 ShowNotificationView();
803 } 841 }
804 842
843 void TrayNetwork::OnWifiToggled(bool wifi_enabled) {
844 if (!detailed_) {
845 wifi_view_ = new tray::NetworkWifiDetailedView(wifi_enabled);
846 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false);
847 }
848 }
849
805 void TrayNetwork::LinkClicked(ErrorType error_type) { 850 void TrayNetwork::LinkClicked(ErrorType error_type) {
806 tray::NetworkErrors::ErrorMap::const_iterator iter = 851 tray::NetworkErrors::ErrorMap::const_iterator iter =
807 errors()->messages().find(error_type); 852 errors()->messages().find(error_type);
808 if (iter != errors()->messages().end() && iter->second.delegate) 853 if (iter != errors()->messages().end() && iter->second.delegate)
809 iter->second.delegate->NotificationLinkClicked(); 854 iter->second.delegate->NotificationLinkClicked();
810 } 855 }
811 856
812 } // namespace internal 857 } // namespace internal
813 } // namespace ash 858 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698