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

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

Issue 11361274: Add NetworkStateListDetailedView (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years 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/chromeos/network/tray_network.h" 5 #include "ash/system/chromeos/network/tray_network.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/system/chromeos/network/network_list_detailed_view_base.h" 8 #include "ash/system/chromeos/network/network_list_detailed_view_base.h"
9 #include "ash/system/chromeos/network/network_state_list_detailed_view.h"
10 #include "ash/system/chromeos/network/tray_network_state_observer.h"
9 #include "ash/system/tray/system_tray.h" 11 #include "ash/system/tray/system_tray.h"
10 #include "ash/system/tray/system_tray_delegate.h" 12 #include "ash/system/tray/system_tray_delegate.h"
11 #include "ash/system/tray/tray_constants.h" 13 #include "ash/system/tray/tray_constants.h"
12 #include "ash/system/tray/tray_item_more.h" 14 #include "ash/system/tray/tray_item_more.h"
13 #include "ash/system/tray/tray_item_view.h" 15 #include "ash/system/tray/tray_item_view.h"
14 #include "ash/system/tray/tray_notification_view.h" 16 #include "ash/system/tray/tray_notification_view.h"
17 #include "base/command_line.h"
18 #include "chromeos/chromeos_switches.h"
19 #include "chromeos/network/network_state_handler.h"
15 #include "grit/ash_resources.h" 20 #include "grit/ash_resources.h"
16 #include "grit/ash_strings.h" 21 #include "grit/ash_strings.h"
22 #include "third_party/cros_system_api/dbus/service_constants.h"
17 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
18 #include "ui/base/resource/resource_bundle.h" 24 #include "ui/base/resource/resource_bundle.h"
19 #include "ui/views/controls/link.h" 25 #include "ui/views/controls/link.h"
20 #include "ui/views/controls/link_listener.h" 26 #include "ui/views/controls/link_listener.h"
21 #include "ui/views/layout/box_layout.h" 27 #include "ui/views/layout/box_layout.h"
22 28
23 namespace { 29 namespace {
24 30
25 using ash::internal::TrayNetwork; 31 using ash::internal::TrayNetwork;
26 32
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 82
77 MessageMap& messages() { return messages_; } 83 MessageMap& messages() { return messages_; }
78 const MessageMap& messages() const { return messages_; } 84 const MessageMap& messages() const { return messages_; }
79 85
80 private: 86 private:
81 MessageMap messages_; 87 MessageMap messages_;
82 }; 88 };
83 89
84 class NetworkTrayView : public TrayItemView { 90 class NetworkTrayView : public TrayItemView {
85 public: 91 public:
86 NetworkTrayView(SystemTrayItem* owner, ColorTheme size, bool tray_icon) 92 NetworkTrayView(SystemTrayItem* owner, ColorTheme size)
87 : TrayItemView(owner), color_theme_(size), tray_icon_(tray_icon) { 93 : TrayItemView(owner), color_theme_(size) {
88 SetLayoutManager( 94 SetLayoutManager(
89 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); 95 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0));
90 96
91 image_view_ = color_theme_ == DARK ? 97 image_view_ = color_theme_ == DARK ?
92 new FixedSizedImageView(0, kTrayPopupItemHeight) : 98 new FixedSizedImageView(0, kTrayPopupItemHeight) :
93 new views::ImageView; 99 new views::ImageView;
94 AddChildView(image_view_); 100 AddChildView(image_view_);
95 101
96 NetworkIconInfo info; 102 NetworkIconInfo info;
97 Shell::GetInstance()->tray_delegate()-> 103 Shell::GetInstance()->tray_delegate()->
98 GetMostRelevantNetworkIcon(&info, false); 104 GetMostRelevantNetworkIcon(&info, false);
99 Update(info); 105 Update(info);
100 } 106 }
101 107
102 virtual ~NetworkTrayView() {} 108 virtual ~NetworkTrayView() {}
103 109
104 void Update(const NetworkIconInfo& info) { 110 void Update(const NetworkIconInfo& info) {
105 image_view_->SetImage(info.image); 111 image_view_->SetImage(info.image);
106 if (tray_icon_) 112 SetVisible(info.tray_icon_visible);
107 SetVisible(info.tray_icon_visible);
108 SchedulePaint(); 113 SchedulePaint();
109 } 114 }
110 115
111 private: 116 private:
112 views::ImageView* image_view_; 117 views::ImageView* image_view_;
113 ColorTheme color_theme_; 118 ColorTheme color_theme_;
114 bool tray_icon_;
115 119
116 DISALLOW_COPY_AND_ASSIGN(NetworkTrayView); 120 DISALLOW_COPY_AND_ASSIGN(NetworkTrayView);
117 }; 121 };
118 122
119 class NetworkDefaultView : public TrayItemMore { 123 class NetworkDefaultView : public TrayItemMore {
120 public: 124 public:
121 NetworkDefaultView(SystemTrayItem* owner, bool show_more) 125 NetworkDefaultView(SystemTrayItem* owner, bool show_more)
122 : TrayItemMore(owner, show_more) { 126 : TrayItemMore(owner, show_more) {
123 Update(); 127 Update();
124 } 128 }
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 398
395 // Overridden from NetworkDetailedView: 399 // Overridden from NetworkDetailedView:
396 400
397 virtual void Init() OVERRIDE { 401 virtual void Init() OVERRIDE {
398 } 402 }
399 403
400 virtual NetworkDetailedView::DetailedViewType GetViewType() const OVERRIDE { 404 virtual NetworkDetailedView::DetailedViewType GetViewType() const OVERRIDE {
401 return NetworkDetailedView::WIFI_VIEW; 405 return NetworkDetailedView::WIFI_VIEW;
402 } 406 }
403 407
404 virtual void Update() OVERRIDE {} 408 virtual void ManagerChanged() OVERRIDE {
409 }
410
411 virtual void NetworkListChanged(const NetworkStateList& networks) OVERRIDE {
412 }
413
414 virtual void NetworkServiceChanged(
415 const chromeos::NetworkState* network) OVERRIDE {
416 }
405 417
406 private: 418 private:
407 DISALLOW_COPY_AND_ASSIGN(NetworkWifiDetailedView); 419 DISALLOW_COPY_AND_ASSIGN(NetworkWifiDetailedView);
408 }; 420 };
409 421
410 class NetworkMessageView : public views::View, 422 class NetworkMessageView : public views::View,
411 public views::LinkListener { 423 public views::LinkListener {
412 public: 424 public:
413 NetworkMessageView(TrayNetwork* owner, 425 NetworkMessageView(TrayNetwork* owner,
414 TrayNetwork::MessageType message_type, 426 TrayNetwork::MessageType message_type,
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 } // namespace tray 530 } // namespace tray
519 531
520 TrayNetwork::TrayNetwork(SystemTray* system_tray) 532 TrayNetwork::TrayNetwork(SystemTray* system_tray)
521 : SystemTrayItem(system_tray), 533 : SystemTrayItem(system_tray),
522 tray_(NULL), 534 tray_(NULL),
523 default_(NULL), 535 default_(NULL),
524 detailed_(NULL), 536 detailed_(NULL),
525 notification_(NULL), 537 notification_(NULL),
526 messages_(new tray::NetworkMessages()), 538 messages_(new tray::NetworkMessages()),
527 request_wifi_view_(false) { 539 request_wifi_view_(false) {
540 if (CommandLine::ForCurrentProcess()->HasSwitch(
541 chromeos::switches::kEnableNewNetworkHandlers)) {
542 network_state_observer_.reset(new TrayNetworkStateObserver(this));
543 }
528 } 544 }
529 545
530 TrayNetwork::~TrayNetwork() { 546 TrayNetwork::~TrayNetwork() {
531 } 547 }
532 548
533 views::View* TrayNetwork::CreateTrayView(user::LoginStatus status) { 549 views::View* TrayNetwork::CreateTrayView(user::LoginStatus status) {
534 CHECK(tray_ == NULL); 550 CHECK(tray_ == NULL);
535 tray_ = new tray::NetworkTrayView(this, tray::LIGHT, true /*tray_icon*/); 551 tray_ = new tray::NetworkTrayView(this, tray::LIGHT);
536 return tray_; 552 return tray_;
537 } 553 }
538 554
539 views::View* TrayNetwork::CreateDefaultView(user::LoginStatus status) { 555 views::View* TrayNetwork::CreateDefaultView(user::LoginStatus status) {
540 CHECK(default_ == NULL); 556 CHECK(default_ == NULL);
541 default_ = 557 default_ =
542 new tray::NetworkDefaultView(this, status != user::LOGGED_IN_LOCKED); 558 new tray::NetworkDefaultView(this, status != user::LOGGED_IN_LOCKED);
543 return default_; 559 return default_;
544 } 560 }
545 561
546 views::View* TrayNetwork::CreateDetailedView(user::LoginStatus status) { 562 views::View* TrayNetwork::CreateDetailedView(user::LoginStatus status) {
547 CHECK(detailed_ == NULL); 563 CHECK(detailed_ == NULL);
548 // Clear any notifications when showing the detailed view. 564 // Clear any notifications when showing the detailed view.
549 messages_->messages().clear(); 565 messages_->messages().clear();
550 HideNotificationView(); 566 HideNotificationView();
551 if (request_wifi_view_) { 567 if (request_wifi_view_) {
552 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); 568 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate();
553 // The Wi-Fi state is not toggled yet at this point. 569 // The Wi-Fi state is not toggled yet at this point.
554 detailed_ = new tray::NetworkWifiDetailedView(this, 570 detailed_ = new tray::NetworkWifiDetailedView(this,
555 !delegate->GetWifiEnabled()); 571 !delegate->GetWifiEnabled());
556 request_wifi_view_ = false; 572 request_wifi_view_ = false;
557 } else { 573 } else {
558 detailed_ = new tray::NetworkListDetailedView( 574 if (CommandLine::ForCurrentProcess()->HasSwitch(
559 this, status, IDS_ASH_STATUS_TRAY_NETWORK); 575 chromeos::switches::kEnableNewNetworkHandlers)) {
576 detailed_ = new tray::NetworkStateListDetailedView(this, status);
577 } else {
578 detailed_ = new tray::NetworkListDetailedView(
579 this, status, IDS_ASH_STATUS_TRAY_NETWORK);
580 }
560 detailed_->Init(); 581 detailed_->Init();
561 } 582 }
562 return detailed_; 583 return detailed_;
563 } 584 }
564 585
565 views::View* TrayNetwork::CreateNotificationView(user::LoginStatus status) { 586 views::View* TrayNetwork::CreateNotificationView(user::LoginStatus status) {
566 CHECK(notification_ == NULL); 587 CHECK(notification_ == NULL);
567 if (messages_->messages().empty()) 588 if (messages_->messages().empty())
568 return NULL; // Message has already been cleared. 589 return NULL; // Message has already been cleared.
569 notification_ = new tray::NetworkNotificationView(this); 590 notification_ = new tray::NetworkNotificationView(this);
(...skipping 22 matching lines...) Expand all
592 void TrayNetwork::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { 613 void TrayNetwork::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {
593 SetTrayImageItemBorder(tray_, alignment); 614 SetTrayImageItemBorder(tray_, alignment);
594 } 615 }
595 616
596 void TrayNetwork::OnNetworkRefresh(const NetworkIconInfo& info) { 617 void TrayNetwork::OnNetworkRefresh(const NetworkIconInfo& info) {
597 if (tray_) 618 if (tray_)
598 tray_->Update(info); 619 tray_->Update(info);
599 if (default_) 620 if (default_)
600 default_->Update(); 621 default_->Update();
601 if (detailed_) 622 if (detailed_)
602 detailed_->Update(); 623 detailed_->ManagerChanged();
603 } 624 }
604 625
605 void TrayNetwork::SetNetworkMessage(NetworkTrayDelegate* delegate, 626 void TrayNetwork::SetNetworkMessage(NetworkTrayDelegate* delegate,
606 MessageType message_type, 627 MessageType message_type,
607 NetworkType network_type, 628 NetworkType network_type,
608 const string16& title, 629 const string16& title,
609 const string16& message, 630 const string16& message,
610 const std::vector<string16>& links) { 631 const std::vector<string16>& links) {
611 messages_->messages()[message_type] = tray::NetworkMessages::Message( 632 messages_->messages()[message_type] = tray::NetworkMessages::Message(
612 delegate, network_type, title, message, links); 633 delegate, network_type, title, message, links);
613 if (notification_) 634 if (notification_)
614 notification_->Update(); 635 notification_->Update();
615 else 636 else
616 ShowNotificationView(); 637 ShowNotificationView();
617 } 638 }
618 639
619 void TrayNetwork::ClearNetworkMessage(MessageType message_type) { 640 void TrayNetwork::ClearNetworkMessage(MessageType message_type) {
620 messages_->messages().erase(message_type); 641 messages_->messages().erase(message_type);
621 if (messages_->messages().empty()) { 642 if (messages_->messages().empty()) {
622 HideNotificationView(); 643 HideNotificationView();
623 return; 644 return;
624 } 645 }
625 if (notification_) 646 if (notification_)
626 notification_->Update(); 647 notification_->Update();
627 else 648 else
628 ShowNotificationView(); 649 ShowNotificationView();
629 } 650 }
630 651
631 void TrayNetwork::OnWillToggleWifi() { 652 void TrayNetwork::OnWillToggleWifi() {
653 if (CommandLine::ForCurrentProcess()->HasSwitch(
654 chromeos::switches::kEnableNewNetworkHandlers)) {
655 return; // Handled in TrayNetworkStateObserver::NetworkManagerChanged()
656 }
632 if (!detailed_ || 657 if (!detailed_ ||
633 detailed_->GetViewType() == tray::NetworkDetailedView::WIFI_VIEW) { 658 detailed_->GetViewType() == tray::NetworkDetailedView::WIFI_VIEW) {
634 request_wifi_view_ = true; 659 request_wifi_view_ = true;
635 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); 660 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false);
636 } 661 }
637 } 662 }
638 663
639 void TrayNetwork::LinkClicked(MessageType message_type, int link_id) { 664 void TrayNetwork::LinkClicked(MessageType message_type, int link_id) {
640 tray::NetworkMessages::MessageMap::const_iterator iter = 665 tray::NetworkMessages::MessageMap::const_iterator iter =
641 messages()->messages().find(message_type); 666 messages()->messages().find(message_type);
642 if (iter != messages()->messages().end() && iter->second.delegate) 667 if (iter != messages()->messages().end() && iter->second.delegate)
643 iter->second.delegate->NotificationLinkClicked(link_id); 668 iter->second.delegate->NotificationLinkClicked(link_id);
644 } 669 }
645 670
646 } // namespace internal 671 } // namespace internal
647 } // namespace ash 672 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/chromeos/network/tray_network.h ('k') | ash/system/chromeos/network/tray_network_state_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698