| 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/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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 87 |
| 82 MessageMap& messages() { return messages_; } | 88 MessageMap& messages() { return messages_; } |
| 83 const MessageMap& messages() const { return messages_; } | 89 const MessageMap& messages() const { return messages_; } |
| 84 | 90 |
| 85 private: | 91 private: |
| 86 MessageMap messages_; | 92 MessageMap messages_; |
| 87 }; | 93 }; |
| 88 | 94 |
| 89 class NetworkTrayView : public TrayItemView { | 95 class NetworkTrayView : public TrayItemView { |
| 90 public: | 96 public: |
| 91 NetworkTrayView(SystemTrayItem* owner, ColorTheme size, bool tray_icon) | 97 NetworkTrayView(SystemTrayItem* owner, ColorTheme size) |
| 92 : TrayItemView(owner), color_theme_(size), tray_icon_(tray_icon) { | 98 : TrayItemView(owner), color_theme_(size) { |
| 93 SetLayoutManager( | 99 SetLayoutManager( |
| 94 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); | 100 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); |
| 95 | 101 |
| 96 image_view_ = color_theme_ == DARK ? | 102 image_view_ = color_theme_ == DARK ? |
| 97 new FixedSizedImageView(0, kTrayPopupItemHeight) : | 103 new FixedSizedImageView(0, kTrayPopupItemHeight) : |
| 98 new views::ImageView; | 104 new views::ImageView; |
| 99 AddChildView(image_view_); | 105 AddChildView(image_view_); |
| 100 | 106 |
| 101 NetworkIconInfo info; | 107 NetworkIconInfo info; |
| 102 Shell::GetInstance()->tray_delegate()-> | 108 Shell::GetInstance()->tray_delegate()-> |
| 103 GetMostRelevantNetworkIcon(&info, false); | 109 GetMostRelevantNetworkIcon(&info, false); |
| 104 Update(info); | 110 Update(info); |
| 105 } | 111 } |
| 106 | 112 |
| 107 virtual ~NetworkTrayView() {} | 113 virtual ~NetworkTrayView() {} |
| 108 | 114 |
| 109 void Update(const NetworkIconInfo& info) { | 115 void Update(const NetworkIconInfo& info) { |
| 110 image_view_->SetImage(info.image); | 116 image_view_->SetImage(info.image); |
| 111 if (tray_icon_) | 117 SetVisible(info.tray_icon_visible); |
| 112 SetVisible(info.tray_icon_visible); | |
| 113 SchedulePaint(); | 118 SchedulePaint(); |
| 114 } | 119 } |
| 115 | 120 |
| 116 private: | 121 private: |
| 117 views::ImageView* image_view_; | 122 views::ImageView* image_view_; |
| 118 ColorTheme color_theme_; | 123 ColorTheme color_theme_; |
| 119 bool tray_icon_; | |
| 120 | 124 |
| 121 DISALLOW_COPY_AND_ASSIGN(NetworkTrayView); | 125 DISALLOW_COPY_AND_ASSIGN(NetworkTrayView); |
| 122 }; | 126 }; |
| 123 | 127 |
| 124 class NetworkDefaultView : public TrayItemMore { | 128 class NetworkDefaultView : public TrayItemMore { |
| 125 public: | 129 public: |
| 126 NetworkDefaultView(SystemTrayItem* owner, bool show_more) | 130 NetworkDefaultView(SystemTrayItem* owner, bool show_more) |
| 127 : TrayItemMore(owner, show_more) { | 131 : TrayItemMore(owner, show_more) { |
| 128 Update(); | 132 Update(); |
| 129 } | 133 } |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 | 403 |
| 400 // Overridden from NetworkDetailedView: | 404 // Overridden from NetworkDetailedView: |
| 401 | 405 |
| 402 virtual void Init() OVERRIDE { | 406 virtual void Init() OVERRIDE { |
| 403 } | 407 } |
| 404 | 408 |
| 405 virtual NetworkDetailedView::DetailedViewType GetViewType() const OVERRIDE { | 409 virtual NetworkDetailedView::DetailedViewType GetViewType() const OVERRIDE { |
| 406 return NetworkDetailedView::WIFI_VIEW; | 410 return NetworkDetailedView::WIFI_VIEW; |
| 407 } | 411 } |
| 408 | 412 |
| 409 virtual void Update() OVERRIDE {} | 413 virtual void ManagerChanged() OVERRIDE { |
| 414 } |
| 415 |
| 416 virtual void NetworkListChanged(const NetworkStateList& networks) OVERRIDE { |
| 417 } |
| 418 |
| 419 virtual void NetworkServiceChanged(const std::string& service_path) OVERRIDE { |
| 420 } |
| 410 | 421 |
| 411 private: | 422 private: |
| 412 DISALLOW_COPY_AND_ASSIGN(NetworkWifiDetailedView); | 423 DISALLOW_COPY_AND_ASSIGN(NetworkWifiDetailedView); |
| 413 }; | 424 }; |
| 414 | 425 |
| 415 class NetworkMessageView : public views::View, | 426 class NetworkMessageView : public views::View, |
| 416 public views::LinkListener { | 427 public views::LinkListener { |
| 417 public: | 428 public: |
| 418 NetworkMessageView(TrayNetwork* owner, | 429 NetworkMessageView(TrayNetwork* owner, |
| 419 TrayNetwork::MessageType message_type, | 430 TrayNetwork::MessageType message_type, |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 } // namespace tray | 534 } // namespace tray |
| 524 | 535 |
| 525 TrayNetwork::TrayNetwork(SystemTray* system_tray) | 536 TrayNetwork::TrayNetwork(SystemTray* system_tray) |
| 526 : SystemTrayItem(system_tray), | 537 : SystemTrayItem(system_tray), |
| 527 tray_(NULL), | 538 tray_(NULL), |
| 528 default_(NULL), | 539 default_(NULL), |
| 529 detailed_(NULL), | 540 detailed_(NULL), |
| 530 notification_(NULL), | 541 notification_(NULL), |
| 531 messages_(new tray::NetworkMessages()), | 542 messages_(new tray::NetworkMessages()), |
| 532 request_wifi_view_(false) { | 543 request_wifi_view_(false) { |
| 544 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 545 chromeos::switches::kEnableNewNetworkHandlers)) { |
| 546 network_state_observer_.reset(new TrayNetworkStateObserver(this)); |
| 547 } |
| 533 } | 548 } |
| 534 | 549 |
| 535 TrayNetwork::~TrayNetwork() { | 550 TrayNetwork::~TrayNetwork() { |
| 536 } | 551 } |
| 537 | 552 |
| 538 views::View* TrayNetwork::CreateTrayView(user::LoginStatus status) { | 553 views::View* TrayNetwork::CreateTrayView(user::LoginStatus status) { |
| 539 CHECK(tray_ == NULL); | 554 CHECK(tray_ == NULL); |
| 540 tray_ = new tray::NetworkTrayView(this, tray::LIGHT, true /*tray_icon*/); | 555 tray_ = new tray::NetworkTrayView(this, tray::LIGHT); |
| 541 return tray_; | 556 return tray_; |
| 542 } | 557 } |
| 543 | 558 |
| 544 views::View* TrayNetwork::CreateDefaultView(user::LoginStatus status) { | 559 views::View* TrayNetwork::CreateDefaultView(user::LoginStatus status) { |
| 545 CHECK(default_ == NULL); | 560 CHECK(default_ == NULL); |
| 546 default_ = | 561 default_ = |
| 547 new tray::NetworkDefaultView(this, status != user::LOGGED_IN_LOCKED); | 562 new tray::NetworkDefaultView(this, status != user::LOGGED_IN_LOCKED); |
| 548 return default_; | 563 return default_; |
| 549 } | 564 } |
| 550 | 565 |
| 551 views::View* TrayNetwork::CreateDetailedView(user::LoginStatus status) { | 566 views::View* TrayNetwork::CreateDetailedView(user::LoginStatus status) { |
| 552 CHECK(detailed_ == NULL); | 567 CHECK(detailed_ == NULL); |
| 553 // Clear any notifications when showing the detailed view. | 568 // Clear any notifications when showing the detailed view. |
| 554 messages_->messages().clear(); | 569 messages_->messages().clear(); |
| 555 HideNotificationView(); | 570 HideNotificationView(); |
| 556 if (request_wifi_view_) { | 571 if (request_wifi_view_) { |
| 557 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); | 572 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); |
| 558 // The Wi-Fi state is not toggled yet at this point. | 573 // The Wi-Fi state is not toggled yet at this point. |
| 559 detailed_ = new tray::NetworkWifiDetailedView(this, | 574 detailed_ = new tray::NetworkWifiDetailedView(this, |
| 560 !delegate->GetWifiEnabled()); | 575 !delegate->GetWifiEnabled()); |
| 561 request_wifi_view_ = false; | 576 request_wifi_view_ = false; |
| 562 } else { | 577 } else { |
| 563 detailed_ = new tray::NetworkListDetailedView( | 578 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 564 this, status, IDS_ASH_STATUS_TRAY_NETWORK); | 579 chromeos::switches::kEnableNewNetworkHandlers)) { |
| 580 detailed_ = new tray::NetworkStateListDetailedView(this, status); |
| 581 } else { |
| 582 detailed_ = new tray::NetworkListDetailedView( |
| 583 this, status, IDS_ASH_STATUS_TRAY_NETWORK); |
| 584 } |
| 565 detailed_->Init(); | 585 detailed_->Init(); |
| 566 } | 586 } |
| 567 return detailed_; | 587 return detailed_; |
| 568 } | 588 } |
| 569 | 589 |
| 570 views::View* TrayNetwork::CreateNotificationView(user::LoginStatus status) { | 590 views::View* TrayNetwork::CreateNotificationView(user::LoginStatus status) { |
| 571 CHECK(notification_ == NULL); | 591 CHECK(notification_ == NULL); |
| 572 if (messages_->messages().empty()) | 592 if (messages_->messages().empty()) |
| 573 return NULL; // Message has already been cleared. | 593 return NULL; // Message has already been cleared. |
| 574 notification_ = new tray::NetworkNotificationView(this); | 594 notification_ = new tray::NetworkNotificationView(this); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 597 void TrayNetwork::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { | 617 void TrayNetwork::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { |
| 598 SetTrayImageItemBorder(tray_, alignment); | 618 SetTrayImageItemBorder(tray_, alignment); |
| 599 } | 619 } |
| 600 | 620 |
| 601 void TrayNetwork::OnNetworkRefresh(const NetworkIconInfo& info) { | 621 void TrayNetwork::OnNetworkRefresh(const NetworkIconInfo& info) { |
| 602 if (tray_) | 622 if (tray_) |
| 603 tray_->Update(info); | 623 tray_->Update(info); |
| 604 if (default_) | 624 if (default_) |
| 605 default_->Update(); | 625 default_->Update(); |
| 606 if (detailed_) | 626 if (detailed_) |
| 607 detailed_->Update(); | 627 detailed_->ManagerChanged(); |
| 608 } | 628 } |
| 609 | 629 |
| 610 void TrayNetwork::SetNetworkMessage(NetworkTrayDelegate* delegate, | 630 void TrayNetwork::SetNetworkMessage(NetworkTrayDelegate* delegate, |
| 611 MessageType message_type, | 631 MessageType message_type, |
| 612 NetworkType network_type, | 632 NetworkType network_type, |
| 613 const string16& title, | 633 const string16& title, |
| 614 const string16& message, | 634 const string16& message, |
| 615 const std::vector<string16>& links) { | 635 const std::vector<string16>& links) { |
| 616 messages_->messages()[message_type] = tray::NetworkMessages::Message( | 636 messages_->messages()[message_type] = tray::NetworkMessages::Message( |
| 617 delegate, network_type, title, message, links); | 637 delegate, network_type, title, message, links); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 643 | 663 |
| 644 void TrayNetwork::LinkClicked(MessageType message_type, int link_id) { | 664 void TrayNetwork::LinkClicked(MessageType message_type, int link_id) { |
| 645 tray::NetworkMessages::MessageMap::const_iterator iter = | 665 tray::NetworkMessages::MessageMap::const_iterator iter = |
| 646 messages()->messages().find(message_type); | 666 messages()->messages().find(message_type); |
| 647 if (iter != messages()->messages().end() && iter->second.delegate) | 667 if (iter != messages()->messages().end() && iter->second.delegate) |
| 648 iter->second.delegate->NotificationLinkClicked(link_id); | 668 iter->second.delegate->NotificationLinkClicked(link_id); |
| 649 } | 669 } |
| 650 | 670 |
| 651 } // namespace internal | 671 } // namespace internal |
| 652 } // namespace ash | 672 } // namespace ash |
| OLD | NEW |