| 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/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 16 matching lines...) Expand all Loading... |
| 27 #include "ui/views/bubble/bubble_delegate.h" | 27 #include "ui/views/bubble/bubble_delegate.h" |
| 28 #include "ui/views/controls/button/button.h" | 28 #include "ui/views/controls/button/button.h" |
| 29 #include "ui/views/controls/button/image_button.h" | 29 #include "ui/views/controls/button/image_button.h" |
| 30 #include "ui/views/controls/image_view.h" | 30 #include "ui/views/controls/image_view.h" |
| 31 #include "ui/views/controls/label.h" | 31 #include "ui/views/controls/label.h" |
| 32 #include "ui/views/controls/link.h" | 32 #include "ui/views/controls/link.h" |
| 33 #include "ui/views/controls/link_listener.h" | 33 #include "ui/views/controls/link_listener.h" |
| 34 #include "ui/views/controls/scroll_view.h" | 34 #include "ui/views/controls/scroll_view.h" |
| 35 #include "ui/views/layout/box_layout.h" | 35 #include "ui/views/layout/box_layout.h" |
| 36 #include "ui/views/layout/fill_layout.h" | 36 #include "ui/views/layout/fill_layout.h" |
| 37 #include "ui/views/layout/grid_layout.h" | |
| 38 #include "ui/views/view.h" | 37 #include "ui/views/view.h" |
| 39 #include "ui/views/widget/widget.h" | 38 #include "ui/views/widget/widget.h" |
| 40 | 39 |
| 41 namespace { | 40 namespace { |
| 42 | 41 |
| 43 // Height of the list of networks in the popup. | 42 // Height of the list of networks in the popup. |
| 44 const int kNetworkListHeight = 203; | 43 const int kNetworkListHeight = 203; |
| 45 | 44 |
| 46 // Create a label with the font size and color used in the network info bubble. | 45 // Create a label with the font size and color used in the network info bubble. |
| 47 views::Label* CreateInfoBubbleLabel(const string16& text) { | 46 views::Label* CreateInfoBubbleLabel(const string16& text) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 virtual ~NonActivatableSettingsBubble() {} | 78 virtual ~NonActivatableSettingsBubble() {} |
| 80 | 79 |
| 81 virtual bool CanActivate() const OVERRIDE { | 80 virtual bool CanActivate() const OVERRIDE { |
| 82 return false; | 81 return false; |
| 83 } | 82 } |
| 84 | 83 |
| 85 private: | 84 private: |
| 86 DISALLOW_COPY_AND_ASSIGN(NonActivatableSettingsBubble); | 85 DISALLOW_COPY_AND_ASSIGN(NonActivatableSettingsBubble); |
| 87 }; | 86 }; |
| 88 | 87 |
| 88 using ash::internal::TrayNetwork; |
| 89 |
| 90 int GetErrorIcon(TrayNetwork::ErrorType error_type) { |
| 91 switch(error_type) { |
| 92 case TrayNetwork::ERROR_CONNECT_FAILED: |
| 93 return IDR_AURA_UBER_TRAY_NETWORK_FAILED; |
| 94 case TrayNetwork::ERROR_DATA_LOW: |
| 95 return IDR_AURA_UBER_TRAY_NETWORK_DATA_LOW; |
| 96 case TrayNetwork::ERROR_DATA_NONE: |
| 97 return IDR_AURA_UBER_TRAY_NETWORK_DATA_NONE; |
| 98 } |
| 99 NOTREACHED(); |
| 100 return 0; |
| 101 } |
| 102 |
| 89 } // namespace | 103 } // namespace |
| 90 | 104 |
| 91 namespace ash { | 105 namespace ash { |
| 92 namespace internal { | 106 namespace internal { |
| 93 | 107 |
| 94 namespace tray { | 108 namespace tray { |
| 95 | 109 |
| 96 enum ColorTheme { | 110 enum ColorTheme { |
| 97 LIGHT, | 111 LIGHT, |
| 98 DARK, | 112 DARK, |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 }; | 608 }; |
| 595 | 609 |
| 596 class NetworkErrorView : public views::View, | 610 class NetworkErrorView : public views::View, |
| 597 public views::LinkListener { | 611 public views::LinkListener { |
| 598 public: | 612 public: |
| 599 NetworkErrorView(TrayNetwork* tray, | 613 NetworkErrorView(TrayNetwork* tray, |
| 600 TrayNetwork::ErrorType error_type, | 614 TrayNetwork::ErrorType error_type, |
| 601 const NetworkErrors::Message& error) | 615 const NetworkErrors::Message& error) |
| 602 : tray_(tray), | 616 : tray_(tray), |
| 603 error_type_(error_type) { | 617 error_type_(error_type) { |
| 604 set_border(views::Border::CreateEmptyBorder( | 618 SetLayoutManager( |
| 605 kTrayPopupPaddingBetweenItems, kTrayPopupPaddingHorizontal, | 619 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); |
| 606 kTrayPopupPaddingBetweenItems, kTrayPopupPaddingHorizontal)); | |
| 607 | 620 |
| 608 const int msg_width = kTrayPopupWidth - kNotificationCloseButtonWidth - | |
| 609 kTrayPopupPaddingHorizontal - kNotificationIconWidth; | |
| 610 | |
| 611 views::ImageView* icon = new views::ImageView; | |
| 612 icon->SetImage(ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
| 613 GetErrorIcon(error_type))); | |
| 614 | |
| 615 int num_rows = 0; | |
| 616 views::Label* title = new views::Label(error.title); | 621 views::Label* title = new views::Label(error.title); |
| 617 title->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 622 title->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 618 title->SetFont(title->font().DeriveFont(0, gfx::Font::BOLD)); | 623 title->SetFont(title->font().DeriveFont(0, gfx::Font::BOLD)); |
| 619 ++num_rows; | 624 AddChildView(title); |
| 620 | 625 |
| 621 views::Label* message = new views::Label(error.message); | 626 views::Label* message = new views::Label(error.message); |
| 622 message->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 627 message->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 623 message->SetMultiLine(true); | 628 message->SetMultiLine(true); |
| 624 message->SizeToFit(msg_width); | 629 message->SizeToFit(kTrayNotificationContentsWidth); |
| 625 ++num_rows; | 630 AddChildView(message); |
| 626 | 631 |
| 627 views::Link* link = NULL; | |
| 628 if (!error.link_text.empty()) { | 632 if (!error.link_text.empty()) { |
| 629 link = new views::Link(error.link_text); | 633 views::Link* link = new views::Link(error.link_text); |
| 630 link->set_listener(this); | 634 link->set_listener(this); |
| 631 link->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 635 link->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 632 link->SetMultiLine(true); | 636 link->SetMultiLine(true); |
| 633 link->SizeToFit(msg_width); | 637 link->SizeToFit(kTrayNotificationContentsWidth); |
| 634 ++num_rows; | 638 AddChildView(link); |
| 635 } | 639 } |
| 636 | |
| 637 views::GridLayout* layout = new views::GridLayout(this); | |
| 638 SetLayoutManager(layout); | |
| 639 | |
| 640 views::ColumnSet* columns = layout->AddColumnSet(0); | |
| 641 | |
| 642 // Icon | |
| 643 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, | |
| 644 0 /* resize percent */, | |
| 645 views::GridLayout::FIXED, | |
| 646 kNotificationIconWidth, kNotificationIconWidth); | |
| 647 | |
| 648 columns->AddPaddingColumn(0, kTrayPopupPaddingHorizontal/2); | |
| 649 | |
| 650 // Title + message + link | |
| 651 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, | |
| 652 0 /* resize percent */, | |
| 653 views::GridLayout::FIXED, msg_width, msg_width); | |
| 654 | |
| 655 // Layout rows | |
| 656 layout->AddPaddingRow(0, kTrayPopupPaddingBetweenItems); | |
| 657 | |
| 658 layout->StartRow(0, 0); | |
| 659 layout->AddView(icon, 1, num_rows); | |
| 660 layout->AddView(title); | |
| 661 | |
| 662 layout->StartRow(0, 0); | |
| 663 layout->SkipColumns(1); | |
| 664 layout->AddView(message); | |
| 665 | |
| 666 if (link) { | |
| 667 layout->StartRow(0, 0); | |
| 668 layout->SkipColumns(1); | |
| 669 layout->AddView(link); | |
| 670 } | |
| 671 | |
| 672 layout->AddPaddingRow(0, kTrayPopupPaddingBetweenItems); | |
| 673 | |
| 674 } | 640 } |
| 675 | 641 |
| 676 virtual ~NetworkErrorView() { | 642 virtual ~NetworkErrorView() { |
| 677 } | 643 } |
| 678 | 644 |
| 679 // Overridden from views::LinkListener. | 645 // Overridden from views::LinkListener. |
| 680 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE { | 646 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE { |
| 681 tray_->LinkClicked(error_type_); | 647 tray_->LinkClicked(error_type_); |
| 682 } | 648 } |
| 683 | 649 |
| 684 TrayNetwork::ErrorType error_type() const { return error_type_; } | 650 TrayNetwork::ErrorType error_type() const { return error_type_; } |
| 685 | 651 |
| 686 private: | 652 private: |
| 687 int GetErrorIcon(TrayNetwork::ErrorType error_type) { | |
| 688 switch(error_type) { | |
| 689 case TrayNetwork::ERROR_CONNECT_FAILED: | |
| 690 return IDR_AURA_UBER_TRAY_NETWORK_FAILED; | |
| 691 case TrayNetwork::ERROR_DATA_LOW: | |
| 692 return IDR_AURA_UBER_TRAY_NETWORK_DATA_LOW; | |
| 693 case TrayNetwork::ERROR_DATA_NONE: | |
| 694 return IDR_AURA_UBER_TRAY_NETWORK_DATA_NONE; | |
| 695 } | |
| 696 NOTREACHED(); | |
| 697 return 0; | |
| 698 } | |
| 699 | |
| 700 TrayNetwork* tray_; | 653 TrayNetwork* tray_; |
| 701 TrayNetwork::ErrorType error_type_; | 654 TrayNetwork::ErrorType error_type_; |
| 702 | 655 |
| 703 DISALLOW_COPY_AND_ASSIGN(NetworkErrorView); | 656 DISALLOW_COPY_AND_ASSIGN(NetworkErrorView); |
| 704 }; | 657 }; |
| 705 | 658 |
| 706 class NetworkNotificationView : public TrayNotificationView { | 659 class NetworkNotificationView : public TrayNotificationView { |
| 707 public: | 660 public: |
| 708 explicit NetworkNotificationView(TrayNetwork* tray) | 661 explicit NetworkNotificationView(TrayNetwork* tray) |
| 709 : tray_(tray) { | 662 : TrayNotificationView(0), |
| 710 CreateView(); | 663 tray_(tray) { |
| 664 CreateErrorView(); |
| 665 InitView(network_error_view_); |
| 666 SetIconImage(*ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 667 GetErrorIcon(network_error_view_->error_type()))); |
| 711 } | 668 } |
| 712 | 669 |
| 713 // Overridden from TrayNotificationView. | 670 // Overridden from TrayNotificationView. |
| 714 virtual void OnClose() OVERRIDE { | 671 virtual void OnClose() OVERRIDE { |
| 715 tray_->ClearNetworkError(network_error_view_->error_type()); | 672 tray_->ClearNetworkError(network_error_view_->error_type()); |
| 716 } | 673 } |
| 717 | 674 |
| 718 // Overridden from views::View. | 675 // Overridden from views::View. |
| 719 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE { | 676 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE { |
| 720 tray_->PopupDetailedView(0, true); | 677 tray_->PopupDetailedView(0, true); |
| 721 return true; | 678 return true; |
| 722 } | 679 } |
| 723 | 680 |
| 724 void Update() { | 681 void Update() { |
| 725 RemoveAllChildViews(true); | 682 CreateErrorView(); |
| 726 CreateView(); | 683 UpdateViewAndImage(network_error_view_, |
| 727 Layout(); | 684 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 728 PreferredSizeChanged(); | 685 GetErrorIcon(network_error_view_->error_type()))); |
| 729 SchedulePaint(); | |
| 730 } | 686 } |
| 731 | 687 |
| 732 private: | 688 private: |
| 733 void CreateView() { | 689 void CreateErrorView() { |
| 734 // Display the first (highest priority) error. | 690 // Display the first (highest priority) error. |
| 735 CHECK(!tray_->errors()->messages().empty()); | 691 CHECK(!tray_->errors()->messages().empty()); |
| 736 NetworkErrors::ErrorMap::const_iterator iter = | 692 NetworkErrors::ErrorMap::const_iterator iter = |
| 737 tray_->errors()->messages().begin(); | 693 tray_->errors()->messages().begin(); |
| 738 network_error_view_ = | 694 network_error_view_ = |
| 739 new NetworkErrorView(tray_, iter->first, iter->second); | 695 new NetworkErrorView(tray_, iter->first, iter->second); |
| 740 InitView(network_error_view_); | |
| 741 } | 696 } |
| 742 | 697 |
| 743 TrayNetwork* tray_; | 698 TrayNetwork* tray_; |
| 744 tray::NetworkErrorView* network_error_view_; | 699 tray::NetworkErrorView* network_error_view_; |
| 745 | 700 |
| 746 DISALLOW_COPY_AND_ASSIGN(NetworkNotificationView); | 701 DISALLOW_COPY_AND_ASSIGN(NetworkNotificationView); |
| 747 }; | 702 }; |
| 748 | 703 |
| 749 } // namespace tray | 704 } // namespace tray |
| 750 | 705 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 | 794 |
| 840 void TrayNetwork::LinkClicked(ErrorType error_type) { | 795 void TrayNetwork::LinkClicked(ErrorType error_type) { |
| 841 tray::NetworkErrors::ErrorMap::const_iterator iter = | 796 tray::NetworkErrors::ErrorMap::const_iterator iter = |
| 842 errors()->messages().find(error_type); | 797 errors()->messages().find(error_type); |
| 843 if (iter != errors()->messages().end() && iter->second.delegate) | 798 if (iter != errors()->messages().end() && iter->second.delegate) |
| 844 iter->second.delegate->NotificationLinkClicked(); | 799 iter->second.delegate->NotificationLinkClicked(); |
| 845 } | 800 } |
| 846 | 801 |
| 847 } // namespace internal | 802 } // namespace internal |
| 848 } // namespace ash | 803 } // namespace ash |
| OLD | NEW |