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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 bool top_item, | 111 bool top_item, |
112 const std::string& name, | 112 const std::string& name, |
113 int button_accessible_name_id) | 113 int button_accessible_name_id) |
114 : parent_(parent) { | 114 : parent_(parent) { |
115 // TODO(varkha): Make this a sticky section header. | 115 TrayPopupUtils::ConfigureAsStickyHeader(this); |
116 SetLayoutManager(new views::FillLayout); | 116 SetLayoutManager(new views::FillLayout); |
117 TriView* tri_view = TrayPopupUtils::CreateSubHeaderRowView(); | 117 TriView* tri_view = TrayPopupUtils::CreateSubHeaderRowView(); |
118 AddChildView(tri_view); | 118 AddChildView(tri_view); |
119 | 119 |
120 // Sets up the border. When the provider header is the first item in the | |
121 // list (i.e. when the list was empty before adding the provider row) there | |
122 // is already |kMenuSeparatorVerticalPadding| padding at the top of the | |
123 // scroll contents, so only add that padding when the list was not |empty|. | |
124 // TODO(varkha): Delete this special handling when we allow the header to be | |
125 // sticky and just use ConfigureAsStickyHeader() instead. | |
126 tri_view->SetBorder( | |
127 views::CreateEmptyBorder(top_item ? 0 : kMenuSeparatorVerticalPadding, | |
128 0, kMenuSeparatorVerticalPadding, 0)); | |
129 | |
130 views::Label* label = TrayPopupUtils::CreateDefaultLabel(); | 120 views::Label* label = TrayPopupUtils::CreateDefaultLabel(); |
131 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::SUB_HEADER); | 121 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::SUB_HEADER); |
132 style.SetupLabel(label); | 122 style.SetupLabel(label); |
133 label->SetText(base::ASCIIToUTF16(name)); | 123 label->SetText(base::ASCIIToUTF16(name)); |
134 tri_view->AddView(TriView::Container::CENTER, label); | 124 tri_view->AddView(TriView::Container::CENTER, label); |
135 | 125 |
136 gfx::ImageSkia icon = gfx::CreateVectorIcon(kSystemMenuAddConnectionIcon, | 126 gfx::ImageSkia icon = gfx::CreateVectorIcon(kSystemMenuAddConnectionIcon, |
137 style.GetIconColor()); | 127 style.GetIconColor()); |
138 SystemMenuButton* add_vpn_button = | 128 SystemMenuButton* add_vpn_button = |
139 new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED, icon, | 129 new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED, icon, |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 353 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
364 } | 354 } |
365 | 355 |
366 // Get the list of available VPN networks, in shill's priority order. | 356 // Get the list of available VPN networks, in shill's priority order. |
367 chromeos::NetworkStateHandler::NetworkStateList networks; | 357 chromeos::NetworkStateHandler::NetworkStateList networks; |
368 chromeos::NetworkHandler::Get() | 358 chromeos::NetworkHandler::Get() |
369 ->network_state_handler() | 359 ->network_state_handler() |
370 ->GetVisibleNetworkListByType(chromeos::NetworkTypePattern::VPN(), | 360 ->GetVisibleNetworkListByType(chromeos::NetworkTypePattern::VPN(), |
371 &networks); | 361 &networks); |
372 | 362 |
373 if (!networks.empty() && IsConnectedOrConnecting(networks.front())) { | |
374 // If there is a connected or connecting network, show that network first. | |
375 AddNetwork(networks.front()); | |
376 networks.erase(networks.begin()); | |
377 } | |
378 | |
379 // Show all VPN providers and all networks that are currently disconnected. | 363 // Show all VPN providers and all networks that are currently disconnected. |
380 AddProvidersAndNetworks(networks); | 364 AddProvidersAndNetworks(networks); |
381 | 365 |
382 // Determine whether one of the new list entries corresponds to the entry that | 366 // Determine whether one of the new list entries corresponds to the entry that |
383 // the user was previously hovering over. If such an entry is found, the list | 367 // the user was previously hovering over. If such an entry is found, the list |
384 // will be scrolled to ensure the entry is visible. | 368 // will be scrolled to ensure the entry is visible. |
385 const views::View* scroll_to_show_view = nullptr; | 369 const views::View* scroll_to_show_view = nullptr; |
386 if (hovered_provider) { | 370 if (hovered_provider) { |
387 for (const std::pair<const views::View* const, VPNProvider>& provider : | 371 for (const std::pair<const views::View* const, VPNProvider>& provider : |
388 provider_view_map_) { | 372 provider_view_map_) { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 } | 490 } |
507 } | 491 } |
508 | 492 |
509 // Add providers without any configured networks, in the order that the | 493 // Add providers without any configured networks, in the order that the |
510 // providers were returned by the extensions system. | 494 // providers were returned by the extensions system. |
511 for (const VPNProvider& provider : providers) | 495 for (const VPNProvider& provider : providers) |
512 AddProviderAndNetworks(provider, networks); | 496 AddProviderAndNetworks(provider, networks); |
513 } | 497 } |
514 | 498 |
515 } // namespace ash | 499 } // namespace ash |
OLD | NEW |