| 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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 for (const std::pair<const views::View*, std::string>& entry : | 262 for (const std::pair<const views::View*, std::string>& entry : |
| 263 network_view_service_path_map_) { | 263 network_view_service_path_map_) { |
| 264 if (static_cast<const HoverHighlightView*>(entry.first)->hover()) { | 264 if (static_cast<const HoverHighlightView*>(entry.first)->hover()) { |
| 265 hovered_network_service_path = entry.second; | 265 hovered_network_service_path = entry.second; |
| 266 break; | 266 break; |
| 267 } | 267 } |
| 268 } | 268 } |
| 269 } | 269 } |
| 270 | 270 |
| 271 // Clear the list. | 271 // Clear the list. |
| 272 container_->RemoveAllChildViews(true); | 272 container()->RemoveAllChildViews(true); |
| 273 provider_view_key_map_.clear(); | 273 provider_view_key_map_.clear(); |
| 274 network_view_service_path_map_.clear(); | 274 network_view_service_path_map_.clear(); |
| 275 list_empty_ = true; | 275 list_empty_ = true; |
| 276 container_->SetLayoutManager( | 276 container()->SetLayoutManager( |
| 277 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 277 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
| 278 | 278 |
| 279 // Get the list of available VPN networks, in shill's priority order. | 279 // Get the list of available VPN networks, in shill's priority order. |
| 280 chromeos::NetworkStateHandler::NetworkStateList networks; | 280 chromeos::NetworkStateHandler::NetworkStateList networks; |
| 281 chromeos::NetworkHandler::Get() | 281 chromeos::NetworkHandler::Get() |
| 282 ->network_state_handler() | 282 ->network_state_handler() |
| 283 ->GetVisibleNetworkListByType(chromeos::NetworkTypePattern::VPN(), | 283 ->GetVisibleNetworkListByType(chromeos::NetworkTypePattern::VPN(), |
| 284 &networks); | 284 &networks); |
| 285 | 285 |
| 286 if (!networks.empty() && IsConnectedOrConnecting(networks.front())) { | 286 if (!networks.empty() && IsConnectedOrConnecting(networks.front())) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 308 for (const std::pair<const views::View*, std::string>& entry : | 308 for (const std::pair<const views::View*, std::string>& entry : |
| 309 network_view_service_path_map_) { | 309 network_view_service_path_map_) { |
| 310 if (entry.second == hovered_network_service_path) { | 310 if (entry.second == hovered_network_service_path) { |
| 311 scroll_to_show_view = entry.first; | 311 scroll_to_show_view = entry.first; |
| 312 break; | 312 break; |
| 313 } | 313 } |
| 314 } | 314 } |
| 315 } | 315 } |
| 316 | 316 |
| 317 // Layout the updated list. | 317 // Layout the updated list. |
| 318 container_->SizeToPreferredSize(); | 318 container()->SizeToPreferredSize(); |
| 319 delegate_->RelayoutScrollList(); | 319 delegate_->RelayoutScrollList(); |
| 320 | 320 |
| 321 if (scroll_to_show_view) { | 321 if (scroll_to_show_view) { |
| 322 // Scroll the list so that |scroll_to_show_view| is in view. | 322 // Scroll the list so that |scroll_to_show_view| is in view. |
| 323 container_->ScrollRectToVisible(scroll_to_show_view->bounds()); | 323 container()->ScrollRectToVisible(scroll_to_show_view->bounds()); |
| 324 } | 324 } |
| 325 } | 325 } |
| 326 | 326 |
| 327 bool VPNListView::IsNetworkEntry(views::View* view, | 327 bool VPNListView::IsNetworkEntry(views::View* view, |
| 328 std::string* service_path) const { | 328 std::string* service_path) const { |
| 329 const auto& entry = network_view_service_path_map_.find(view); | 329 const auto& entry = network_view_service_path_map_.find(view); |
| 330 if (entry == network_view_service_path_map_.end()) | 330 if (entry == network_view_service_path_map_.end()) |
| 331 return false; | 331 return false; |
| 332 *service_path = entry->second; | 332 *service_path = entry->second; |
| 333 return true; | 333 return true; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 351 } | 351 } |
| 352 | 352 |
| 353 // If the user clicked on a network entry, let the |delegate_| trigger a | 353 // If the user clicked on a network entry, let the |delegate_| trigger a |
| 354 // connection attempt (if the network is currently disconnected) or show a | 354 // connection attempt (if the network is currently disconnected) or show a |
| 355 // configuration dialog (if the network is currently connected or connecting). | 355 // configuration dialog (if the network is currently connected or connecting). |
| 356 delegate_->OnNetworkEntryClicked(sender); | 356 delegate_->OnNetworkEntryClicked(sender); |
| 357 } | 357 } |
| 358 | 358 |
| 359 void VPNListView::AddNetwork(const chromeos::NetworkState* network) { | 359 void VPNListView::AddNetwork(const chromeos::NetworkState* network) { |
| 360 views::View* entry(new VPNListNetworkEntry(this, network)); | 360 views::View* entry(new VPNListNetworkEntry(this, network)); |
| 361 container_->AddChildView(entry); | 361 container()->AddChildView(entry); |
| 362 network_view_service_path_map_[entry] = network->path(); | 362 network_view_service_path_map_[entry] = network->path(); |
| 363 list_empty_ = false; | 363 list_empty_ = false; |
| 364 } | 364 } |
| 365 | 365 |
| 366 void VPNListView::AddProviderAndNetworks( | 366 void VPNListView::AddProviderAndNetworks( |
| 367 const VPNProvider::Key& key, | 367 const VPNProvider::Key& key, |
| 368 const std::string& name, | 368 const std::string& name, |
| 369 const chromeos::NetworkStateHandler::NetworkStateList& networks) { | 369 const chromeos::NetworkStateHandler::NetworkStateList& networks) { |
| 370 // Add a visual separator, unless this is the topmost entry in the list. | 370 // Add a visual separator, unless this is the topmost entry in the list. |
| 371 if (!list_empty_) { | 371 if (!list_empty_) { |
| 372 views::Separator* const separator = | 372 views::Separator* const separator = |
| 373 new views::Separator(views::Separator::HORIZONTAL); | 373 new views::Separator(views::Separator::HORIZONTAL); |
| 374 separator->SetColor(kBorderLightColor); | 374 separator->SetColor(kBorderLightColor); |
| 375 container_->AddChildView(separator); | 375 container()->AddChildView(separator); |
| 376 } else { | 376 } else { |
| 377 list_empty_ = false; | 377 list_empty_ = false; |
| 378 } | 378 } |
| 379 // Add a list entry for the VPN provider. | 379 // Add a list entry for the VPN provider. |
| 380 views::View* provider(new VPNListProviderEntry(this, name)); | 380 views::View* provider(new VPNListProviderEntry(this, name)); |
| 381 container_->AddChildView(provider); | 381 container()->AddChildView(provider); |
| 382 provider_view_key_map_[provider] = key; | 382 provider_view_key_map_[provider] = key; |
| 383 // Add the networks belonging to this provider, in the priority order returned | 383 // Add the networks belonging to this provider, in the priority order returned |
| 384 // by shill. | 384 // by shill. |
| 385 for (const chromeos::NetworkState* const& network : networks) { | 385 for (const chromeos::NetworkState* const& network : networks) { |
| 386 if (key.MatchesNetwork(*network)) | 386 if (key.MatchesNetwork(*network)) |
| 387 AddNetwork(network); | 387 AddNetwork(network); |
| 388 } | 388 } |
| 389 } | 389 } |
| 390 | 390 |
| 391 void VPNListView::AddProvidersAndNetworks( | 391 void VPNListView::AddProvidersAndNetworks( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 410 } | 410 } |
| 411 } | 411 } |
| 412 | 412 |
| 413 // Add providers without any configured networks, in the order that the | 413 // Add providers without any configured networks, in the order that the |
| 414 // providers were returned by the extensions system. | 414 // providers were returned by the extensions system. |
| 415 for (const VPNProvider& provider : providers) | 415 for (const VPNProvider& provider : providers) |
| 416 AddProviderAndNetworks(provider.key, provider.name, networks); | 416 AddProviderAndNetworks(provider.key, provider.name, networks); |
| 417 } | 417 } |
| 418 | 418 |
| 419 } // namespace ash | 419 } // namespace ash |
| OLD | NEW |