Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/common/system/chromeos/network/vpn_list_view.h" | 5 #include "ash/common/system/chromeos/network/vpn_list_view.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 DISALLOW_COPY_AND_ASSIGN(VPNListProviderEntry); | 103 DISALLOW_COPY_AND_ASSIGN(VPNListProviderEntry); |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 // A list entry that represents a VPN provider with Material Design. | 106 // A list entry that represents a VPN provider with Material Design. |
| 107 class VPNListProviderEntryMd : public views::ButtonListener, | 107 class VPNListProviderEntryMd : public views::ButtonListener, |
| 108 public views::View { | 108 public views::View { |
| 109 public: | 109 public: |
| 110 VPNListProviderEntryMd(ViewClickListener* parent, | 110 VPNListProviderEntryMd(ViewClickListener* parent, |
| 111 const std::string& name, | 111 const std::string& name, |
| 112 int button_accessible_name_id) | 112 int button_accessible_name_id) |
| 113 : parent_(parent) { | 113 : parent_(parent), tri_view_(nullptr) { |
| 114 // TODO(varkha): Make this a sticky section header. | |
| 114 SetLayoutManager(new views::FillLayout); | 115 SetLayoutManager(new views::FillLayout); |
| 115 TriView* tri_view = TrayPopupUtils::CreateDefaultRowView(); | 116 tri_view_ = TrayPopupUtils::CreateSubHeaderRowView(); |
| 116 tri_view->SetContainerVisible(TriView::Container::START, false); | 117 AddChildView(tri_view_); |
| 117 AddChildView(tri_view); | |
| 118 | 118 |
| 119 views::Label* label = TrayPopupUtils::CreateDefaultLabel(); | 119 views::Label* label = TrayPopupUtils::CreateDefaultLabel(); |
| 120 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::SUB_HEADER); | 120 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::SUB_HEADER); |
| 121 style.SetupLabel(label); | 121 style.SetupLabel(label); |
| 122 label->SetText(base::ASCIIToUTF16(name)); | 122 label->SetText(base::ASCIIToUTF16(name)); |
| 123 tri_view->AddView(TriView::Container::CENTER, label); | 123 tri_view_->AddView(TriView::Container::CENTER, label); |
| 124 | 124 |
| 125 gfx::ImageSkia icon = gfx::CreateVectorIcon(kSystemMenuAddConnectionIcon, | 125 gfx::ImageSkia icon = gfx::CreateVectorIcon(kSystemMenuAddConnectionIcon, |
| 126 style.GetIconColor()); | 126 style.GetIconColor()); |
| 127 SystemMenuButton* add_vpn_button = | 127 SystemMenuButton* add_vpn_button = |
| 128 new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED, icon, | 128 new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED, icon, |
| 129 icon, button_accessible_name_id); | 129 icon, button_accessible_name_id); |
| 130 add_vpn_button->SetInkDropColor(style.GetIconColor()); | 130 add_vpn_button->SetInkDropColor(style.GetIconColor()); |
| 131 add_vpn_button->SetEnabled(true); | 131 add_vpn_button->SetEnabled(true); |
| 132 tri_view->AddView(TriView::Container::END, add_vpn_button); | 132 tri_view_->AddView(TriView::Container::END, add_vpn_button); |
| 133 } | |
| 134 | |
| 135 // Sets up the border. When the provider header is the first item in the | |
| 136 // list (i.e. when the list was empty before adding the provider row) there is | |
| 137 // already |kMenuSeparatorVerticalPadding| padding at the top of the scroll | |
| 138 // contents, so only add that padding when the list was not |empty|. | |
| 139 // TODO(varkha): Remove this special handling when this header becomes sticky. | |
| 140 void SetBorderForHeader(bool empty) { | |
| 141 tri_view_->SetBorder(views::CreateEmptyBorder( | |
|
bruthig
2016/11/28 21:43:12
How much of this is going to live and how much is
varkha
2016/11/28 22:48:25
It is manipulated depending on whether it is the f
| |
| 142 empty ? 0 : kMenuSeparatorVerticalPadding, kTrayPopupPaddingHorizontal, | |
| 143 kMenuSeparatorVerticalPadding, 0)); | |
| 133 } | 144 } |
| 134 | 145 |
| 135 protected: | 146 protected: |
| 136 // views::ButtonListener: | 147 // views::ButtonListener: |
| 137 void ButtonPressed(views::Button* sender, const ui::Event& event) override { | 148 void ButtonPressed(views::Button* sender, const ui::Event& event) override { |
| 138 parent_->OnViewClicked(this); | 149 parent_->OnViewClicked(this); |
| 139 } | 150 } |
| 140 | 151 |
| 141 private: | 152 private: |
| 142 // Our parent to handle events. | 153 // Our parent to handle events. |
| 143 ViewClickListener* parent_; | 154 ViewClickListener* parent_; |
| 144 | 155 |
| 156 // Container that owns the child controls. | |
| 157 TriView* tri_view_; | |
| 158 | |
| 145 DISALLOW_COPY_AND_ASSIGN(VPNListProviderEntryMd); | 159 DISALLOW_COPY_AND_ASSIGN(VPNListProviderEntryMd); |
| 146 }; | 160 }; |
| 147 | 161 |
| 148 // A list entry that represents a network. If the network is currently | 162 // A list entry that represents a network. If the network is currently |
| 149 // connecting, the icon shown by this list entry will be animated. If the | 163 // connecting, the icon shown by this list entry will be animated. If the |
| 150 // network is currently connected, a disconnect button will be shown next to its | 164 // network is currently connected, a disconnect button will be shown next to its |
| 151 // name. | 165 // name. |
| 152 class VPNListNetworkEntry : public VPNListEntryBase, | 166 class VPNListNetworkEntry : public VPNListEntryBase, |
| 153 public network_icon::AnimationObserver { | 167 public network_icon::AnimationObserver { |
| 154 public: | 168 public: |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 442 views::View* entry(new VPNListNetworkEntry(this, network)); | 456 views::View* entry(new VPNListNetworkEntry(this, network)); |
| 443 container()->AddChildView(entry); | 457 container()->AddChildView(entry); |
| 444 network_view_service_path_map_[entry] = network->path(); | 458 network_view_service_path_map_[entry] = network->path(); |
| 445 list_empty_ = false; | 459 list_empty_ = false; |
| 446 } | 460 } |
| 447 | 461 |
| 448 void VPNListView::AddProviderAndNetworks( | 462 void VPNListView::AddProviderAndNetworks( |
| 449 const VPNProvider& vpn_provider, | 463 const VPNProvider& vpn_provider, |
| 450 const chromeos::NetworkStateHandler::NetworkStateList& networks) { | 464 const chromeos::NetworkStateHandler::NetworkStateList& networks) { |
| 451 // Add a visual separator, unless this is the topmost entry in the list. | 465 // Add a visual separator, unless this is the topmost entry in the list. |
| 452 if (!list_empty_) { | 466 if (!list_empty_) |
| 453 views::Separator* const separator = | 467 container()->AddChildView(TrayPopupUtils::CreateListSubHeaderSeparator()); |
| 454 new views::Separator(views::Separator::HORIZONTAL); | |
| 455 separator->SetColor(kBorderLightColor); | |
| 456 container()->AddChildView(separator); | |
| 457 } else { | |
| 458 list_empty_ = false; | |
| 459 } | |
| 460 std::string vpn_name = | 468 std::string vpn_name = |
| 461 vpn_provider.third_party | 469 vpn_provider.third_party |
| 462 ? vpn_provider.third_party_provider_name | 470 ? vpn_provider.third_party_provider_name |
| 463 : l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_VPN_BUILT_IN_PROVIDER); | 471 : l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_VPN_BUILT_IN_PROVIDER); |
| 464 | 472 |
| 465 // Add a list entry for the VPN provider. | 473 // Add a list entry for the VPN provider. |
| 466 views::View* provider_view = nullptr; | 474 views::View* view = nullptr; |
| 467 if (UseMd()) { | 475 if (UseMd()) { |
| 468 provider_view = new VPNListProviderEntryMd( | 476 VPNListProviderEntryMd* provider_view = new VPNListProviderEntryMd( |
| 469 this, vpn_name, IDS_ASH_STATUS_TRAY_ADD_CONNECTION); | 477 this, vpn_name, IDS_ASH_STATUS_TRAY_ADD_CONNECTION); |
| 478 provider_view->SetBorderForHeader(list_empty_); | |
| 479 view = provider_view; | |
| 470 } else { | 480 } else { |
| 471 provider_view = new VPNListProviderEntry(this, vpn_name); | 481 view = new VPNListProviderEntry(this, vpn_name); |
| 472 } | 482 } |
| 473 container()->AddChildView(provider_view); | 483 container()->AddChildView(view); |
| 474 provider_view_map_[provider_view] = vpn_provider; | 484 provider_view_map_[view] = vpn_provider; |
| 485 list_empty_ = false; | |
| 475 // Add the networks belonging to this provider, in the priority order returned | 486 // Add the networks belonging to this provider, in the priority order returned |
| 476 // by shill. | 487 // by shill. |
| 477 for (const chromeos::NetworkState* const& network : networks) { | 488 for (const chromeos::NetworkState* const& network : networks) { |
| 478 if (VpnProviderMatchesNetwork(vpn_provider, *network)) | 489 if (VpnProviderMatchesNetwork(vpn_provider, *network)) |
| 479 AddNetwork(network); | 490 AddNetwork(network); |
| 480 } | 491 } |
| 481 } | 492 } |
| 482 | 493 |
| 483 void VPNListView::AddProvidersAndNetworks( | 494 void VPNListView::AddProvidersAndNetworks( |
| 484 const chromeos::NetworkStateHandler::NetworkStateList& networks) { | 495 const chromeos::NetworkStateHandler::NetworkStateList& networks) { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 500 } | 511 } |
| 501 } | 512 } |
| 502 | 513 |
| 503 // Add providers without any configured networks, in the order that the | 514 // Add providers without any configured networks, in the order that the |
| 504 // providers were returned by the extensions system. | 515 // providers were returned by the extensions system. |
| 505 for (const VPNProvider& provider : providers) | 516 for (const VPNProvider& provider : providers) |
| 506 AddProviderAndNetworks(provider, networks); | 517 AddProviderAndNetworks(provider, networks); |
| 507 } | 518 } |
| 508 | 519 |
| 509 } // namespace ash | 520 } // namespace ash |
| OLD | NEW |