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/ash_switches.h" |
7 #include "ash/shell.h" | 8 #include "ash/shell.h" |
8 #include "ash/system/chromeos/network/network_list_detailed_view_base.h" | 9 #include "ash/system/chromeos/network/network_list_detailed_view_base.h" |
| 10 #include "ash/system/chromeos/network/network_state_list_detailed_view.h" |
| 11 #include "ash/system/chromeos/network/tray_network_state_observer.h" |
9 #include "ash/system/tray/system_tray.h" | 12 #include "ash/system/tray/system_tray.h" |
10 #include "ash/system/tray/system_tray_delegate.h" | 13 #include "ash/system/tray/system_tray_delegate.h" |
11 #include "ash/system/tray/tray_constants.h" | 14 #include "ash/system/tray/tray_constants.h" |
12 #include "ash/system/tray/tray_item_more.h" | 15 #include "ash/system/tray/tray_item_more.h" |
13 #include "ash/system/tray/tray_item_view.h" | 16 #include "ash/system/tray/tray_item_view.h" |
14 #include "ash/system/tray/tray_notification_view.h" | 17 #include "ash/system/tray/tray_notification_view.h" |
| 18 #include "base/command_line.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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 78 |
73 MessageMap& messages() { return messages_; } | 79 MessageMap& messages() { return messages_; } |
74 const MessageMap& messages() const { return messages_; } | 80 const MessageMap& messages() const { return messages_; } |
75 | 81 |
76 private: | 82 private: |
77 MessageMap messages_; | 83 MessageMap messages_; |
78 }; | 84 }; |
79 | 85 |
80 class NetworkTrayView : public TrayItemView { | 86 class NetworkTrayView : public TrayItemView { |
81 public: | 87 public: |
82 NetworkTrayView(ColorTheme size, bool tray_icon) | 88 NetworkTrayView(ColorTheme size) |
83 : color_theme_(size), tray_icon_(tray_icon) { | 89 : color_theme_(size) { |
84 SetLayoutManager( | 90 SetLayoutManager( |
85 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); | 91 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); |
86 | 92 |
87 image_view_ = color_theme_ == DARK ? | 93 image_view_ = color_theme_ == DARK ? |
88 new FixedSizedImageView(0, kTrayPopupItemHeight) : | 94 new FixedSizedImageView(0, kTrayPopupItemHeight) : |
89 new views::ImageView; | 95 new views::ImageView; |
90 AddChildView(image_view_); | 96 AddChildView(image_view_); |
91 | 97 |
92 NetworkIconInfo info; | 98 NetworkIconInfo info; |
93 Shell::GetInstance()->tray_delegate()-> | 99 Shell::GetInstance()->tray_delegate()-> |
94 GetMostRelevantNetworkIcon(&info, false); | 100 GetMostRelevantNetworkIcon(&info, false); |
95 Update(info); | 101 Update(info); |
96 } | 102 } |
97 | 103 |
98 virtual ~NetworkTrayView() {} | 104 virtual ~NetworkTrayView() {} |
99 | 105 |
100 void Update(const NetworkIconInfo& info) { | 106 void Update(const NetworkIconInfo& info) { |
101 image_view_->SetImage(info.image); | 107 image_view_->SetImage(info.image); |
102 if (tray_icon_) | 108 SetVisible(info.tray_icon_visible); |
103 SetVisible(info.tray_icon_visible); | |
104 SchedulePaint(); | 109 SchedulePaint(); |
105 } | 110 } |
106 | 111 |
107 private: | 112 private: |
108 views::ImageView* image_view_; | 113 views::ImageView* image_view_; |
109 ColorTheme color_theme_; | 114 ColorTheme color_theme_; |
110 bool tray_icon_; | |
111 | 115 |
112 DISALLOW_COPY_AND_ASSIGN(NetworkTrayView); | 116 DISALLOW_COPY_AND_ASSIGN(NetworkTrayView); |
113 }; | 117 }; |
114 | 118 |
115 class NetworkDefaultView : public TrayItemMore { | 119 class NetworkDefaultView : public TrayItemMore { |
116 public: | 120 public: |
117 NetworkDefaultView(SystemTrayItem* owner, bool show_more) | 121 NetworkDefaultView(SystemTrayItem* owner, bool show_more) |
118 : TrayItemMore(owner, show_more) { | 122 : TrayItemMore(owner, show_more) { |
119 Update(); | 123 Update(); |
120 } | 124 } |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 | 391 |
388 // Overridden from NetworkDetailedView: | 392 // Overridden from NetworkDetailedView: |
389 | 393 |
390 virtual void Init() OVERRIDE { | 394 virtual void Init() OVERRIDE { |
391 } | 395 } |
392 | 396 |
393 virtual NetworkDetailedView::DetailedViewType GetViewType() const OVERRIDE { | 397 virtual NetworkDetailedView::DetailedViewType GetViewType() const OVERRIDE { |
394 return NetworkDetailedView::WIFI_VIEW; | 398 return NetworkDetailedView::WIFI_VIEW; |
395 } | 399 } |
396 | 400 |
397 virtual void Update() OVERRIDE {} | 401 virtual void ManagerChanged() OVERRIDE { |
| 402 } |
| 403 |
| 404 virtual void NetworkListChanged(const NetworkStateList& networks) OVERRIDE { |
| 405 } |
| 406 |
| 407 virtual void NetworkServiceChanged(const std::string& service_path) OVERRIDE { |
| 408 } |
398 | 409 |
399 private: | 410 private: |
400 DISALLOW_COPY_AND_ASSIGN(NetworkWifiDetailedView); | 411 DISALLOW_COPY_AND_ASSIGN(NetworkWifiDetailedView); |
401 }; | 412 }; |
402 | 413 |
403 class NetworkMessageView : public views::View, | 414 class NetworkMessageView : public views::View, |
404 public views::LinkListener { | 415 public views::LinkListener { |
405 public: | 416 public: |
406 NetworkMessageView(TrayNetwork* tray, | 417 NetworkMessageView(TrayNetwork* tray, |
407 TrayNetwork::MessageType message_type, | 418 TrayNetwork::MessageType message_type, |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 | 516 |
506 } // namespace tray | 517 } // namespace tray |
507 | 518 |
508 TrayNetwork::TrayNetwork() | 519 TrayNetwork::TrayNetwork() |
509 : tray_(NULL), | 520 : tray_(NULL), |
510 default_(NULL), | 521 default_(NULL), |
511 detailed_(NULL), | 522 detailed_(NULL), |
512 notification_(NULL), | 523 notification_(NULL), |
513 messages_(new tray::NetworkMessages()), | 524 messages_(new tray::NetworkMessages()), |
514 request_wifi_view_(false) { | 525 request_wifi_view_(false) { |
| 526 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 527 switches::kAshEnableNetworkStateHandler)) { |
| 528 network_state_observer_.reset(new TrayNetworkStateObserver(this)); |
| 529 } |
515 } | 530 } |
516 | 531 |
517 TrayNetwork::~TrayNetwork() { | 532 TrayNetwork::~TrayNetwork() { |
518 } | 533 } |
519 | 534 |
520 views::View* TrayNetwork::CreateTrayView(user::LoginStatus status) { | 535 views::View* TrayNetwork::CreateTrayView(user::LoginStatus status) { |
521 CHECK(tray_ == NULL); | 536 CHECK(tray_ == NULL); |
522 tray_ = new tray::NetworkTrayView(tray::LIGHT, true /*tray_icon*/); | 537 tray_ = new tray::NetworkTrayView(tray::LIGHT); |
523 return tray_; | 538 return tray_; |
524 } | 539 } |
525 | 540 |
526 views::View* TrayNetwork::CreateDefaultView(user::LoginStatus status) { | 541 views::View* TrayNetwork::CreateDefaultView(user::LoginStatus status) { |
527 CHECK(default_ == NULL); | 542 CHECK(default_ == NULL); |
528 default_ = | 543 default_ = |
529 new tray::NetworkDefaultView(this, status != user::LOGGED_IN_LOCKED); | 544 new tray::NetworkDefaultView(this, status != user::LOGGED_IN_LOCKED); |
530 return default_; | 545 return default_; |
531 } | 546 } |
532 | 547 |
533 views::View* TrayNetwork::CreateDetailedView(user::LoginStatus status) { | 548 views::View* TrayNetwork::CreateDetailedView(user::LoginStatus status) { |
534 CHECK(detailed_ == NULL); | 549 CHECK(detailed_ == NULL); |
535 // Clear any notifications when showing the detailed view. | 550 // Clear any notifications when showing the detailed view. |
536 messages_->messages().clear(); | 551 messages_->messages().clear(); |
537 HideNotificationView(); | 552 HideNotificationView(); |
538 if (request_wifi_view_) { | 553 if (request_wifi_view_) { |
539 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); | 554 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); |
540 // The Wi-Fi state is not toggled yet at this point. | 555 // The Wi-Fi state is not toggled yet at this point. |
541 detailed_ = new tray::NetworkWifiDetailedView(!delegate->GetWifiEnabled()); | 556 detailed_ = new tray::NetworkWifiDetailedView(!delegate->GetWifiEnabled()); |
542 request_wifi_view_ = false; | 557 request_wifi_view_ = false; |
543 } else { | 558 } else { |
544 detailed_ = new tray::NetworkListDetailedView( | 559 if (CommandLine::ForCurrentProcess()->HasSwitch( |
545 status, IDS_ASH_STATUS_TRAY_NETWORK); | 560 switches::kAshEnableNetworkStateHandler)) { |
| 561 detailed_ = new tray::NetworkStateListDetailedView(status); |
| 562 } else { |
| 563 detailed_ = new tray::NetworkListDetailedView( |
| 564 status, IDS_ASH_STATUS_TRAY_NETWORK); |
| 565 } |
546 detailed_->Init(); | 566 detailed_->Init(); |
547 } | 567 } |
548 return detailed_; | 568 return detailed_; |
549 } | 569 } |
550 | 570 |
551 views::View* TrayNetwork::CreateNotificationView(user::LoginStatus status) { | 571 views::View* TrayNetwork::CreateNotificationView(user::LoginStatus status) { |
552 CHECK(notification_ == NULL); | 572 CHECK(notification_ == NULL); |
553 if (messages_->messages().empty()) | 573 if (messages_->messages().empty()) |
554 return NULL; // Message has already been cleared. | 574 return NULL; // Message has already been cleared. |
555 notification_ = new tray::NetworkNotificationView(this); | 575 notification_ = new tray::NetworkNotificationView(this); |
(...skipping 22 matching lines...) Expand all Loading... |
578 void TrayNetwork::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { | 598 void TrayNetwork::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { |
579 SetTrayImageItemBorder(tray_, alignment); | 599 SetTrayImageItemBorder(tray_, alignment); |
580 } | 600 } |
581 | 601 |
582 void TrayNetwork::OnNetworkRefresh(const NetworkIconInfo& info) { | 602 void TrayNetwork::OnNetworkRefresh(const NetworkIconInfo& info) { |
583 if (tray_) | 603 if (tray_) |
584 tray_->Update(info); | 604 tray_->Update(info); |
585 if (default_) | 605 if (default_) |
586 default_->Update(); | 606 default_->Update(); |
587 if (detailed_) | 607 if (detailed_) |
588 detailed_->Update(); | 608 detailed_->ManagerChanged(); |
589 } | 609 } |
590 | 610 |
591 void TrayNetwork::SetNetworkMessage(NetworkTrayDelegate* delegate, | 611 void TrayNetwork::SetNetworkMessage(NetworkTrayDelegate* delegate, |
592 MessageType message_type, | 612 MessageType message_type, |
593 const string16& title, | 613 const string16& title, |
594 const string16& message, | 614 const string16& message, |
595 const std::vector<string16>& links) { | 615 const std::vector<string16>& links) { |
596 messages_->messages()[message_type] = | 616 messages_->messages()[message_type] = |
597 tray::NetworkMessages::Message(delegate, title, message, links); | 617 tray::NetworkMessages::Message(delegate, title, message, links); |
598 if (notification_) | 618 if (notification_) |
(...skipping 24 matching lines...) Expand all Loading... |
623 | 643 |
624 void TrayNetwork::LinkClicked(MessageType message_type, int link_id) { | 644 void TrayNetwork::LinkClicked(MessageType message_type, int link_id) { |
625 tray::NetworkMessages::MessageMap::const_iterator iter = | 645 tray::NetworkMessages::MessageMap::const_iterator iter = |
626 messages()->messages().find(message_type); | 646 messages()->messages().find(message_type); |
627 if (iter != messages()->messages().end() && iter->second.delegate) | 647 if (iter != messages()->messages().end() && iter->second.delegate) |
628 iter->second.delegate->NotificationLinkClicked(link_id); | 648 iter->second.delegate->NotificationLinkClicked(link_id); |
629 } | 649 } |
630 | 650 |
631 } // namespace internal | 651 } // namespace internal |
632 } // namespace ash | 652 } // namespace ash |
OLD | NEW |