Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: ash/system/network/vpn_list_view.cc

Issue 2869053002: Merge NetworkListViewBase hierarchy and NetworkStateListDetailedView (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/system/network/vpn_list_view.h ('k') | ash/system/tray/hover_highlight_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/system/network/vpn_list_view.h" 5 #include "ash/system/network/vpn_list_view.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility>
9 #include <vector> 8 #include <vector>
10 9
11 #include "ash/ash_view_ids.h"
12 #include "ash/resources/vector_icons/vector_icons.h" 10 #include "ash/resources/vector_icons/vector_icons.h"
13 #include "ash/shell.h" 11 #include "ash/shell.h"
14 #include "ash/shell_port.h" 12 #include "ash/shell_port.h"
15 #include "ash/strings/grit/ash_strings.h" 13 #include "ash/strings/grit/ash_strings.h"
16 #include "ash/system/network/network_icon.h" 14 #include "ash/system/network/network_icon.h"
17 #include "ash/system/network/network_icon_animation.h" 15 #include "ash/system/network/network_icon_animation.h"
18 #include "ash/system/network/network_icon_animation_observer.h" 16 #include "ash/system/network/network_icon_animation_observer.h"
19 #include "ash/system/network/network_state_list_detailed_view.h"
20 #include "ash/system/network/vpn_list.h" 17 #include "ash/system/network/vpn_list.h"
21 #include "ash/system/tray/hover_highlight_view.h" 18 #include "ash/system/tray/hover_highlight_view.h"
22 #include "ash/system/tray/system_menu_button.h" 19 #include "ash/system/tray/system_menu_button.h"
23 #include "ash/system/tray/system_tray_controller.h" 20 #include "ash/system/tray/system_tray_controller.h"
24 #include "ash/system/tray/throbber_view.h" 21 #include "ash/system/tray/throbber_view.h"
25 #include "ash/system/tray/tray_constants.h" 22 #include "ash/system/tray/tray_constants.h"
26 #include "ash/system/tray/tray_popup_utils.h" 23 #include "ash/system/tray/tray_popup_utils.h"
27 #include "ash/system/tray/tri_view.h" 24 #include "ash/system/tray/tri_view.h"
28 #include "ash/system/tray/view_click_listener.h" 25 #include "ash/system/tray/view_click_listener.h"
29 #include "base/bind.h"
30 #include "base/bind_helpers.h"
31 #include "base/logging.h"
32 #include "base/strings/utf_string_conversions.h" 26 #include "base/strings/utf_string_conversions.h"
33 #include "base/values.h"
34 #include "chromeos/network/network_connect.h" 27 #include "chromeos/network/network_connect.h"
35 #include "chromeos/network/network_handler.h" 28 #include "chromeos/network/network_handler.h"
36 #include "chromeos/network/network_state.h" 29 #include "chromeos/network/network_state.h"
37 #include "chromeos/network/network_type_pattern.h" 30 #include "chromeos/network/network_type_pattern.h"
38 #include "third_party/cros_system_api/dbus/service_constants.h" 31 #include "third_party/cros_system_api/dbus/service_constants.h"
39 #include "ui/base/l10n/l10n_util.h" 32 #include "ui/base/l10n/l10n_util.h"
40 #include "ui/base/resource/resource_bundle.h"
41 #include "ui/gfx/geometry/rect.h"
42 #include "ui/gfx/image/image_skia.h" 33 #include "ui/gfx/image/image_skia.h"
43 #include "ui/gfx/paint_vector_icon.h" 34 #include "ui/gfx/paint_vector_icon.h"
44 #include "ui/gfx/text_constants.h"
45 #include "ui/views/border.h" 35 #include "ui/views/border.h"
46 #include "ui/views/controls/button/button.h" 36 #include "ui/views/controls/button/button.h"
47 #include "ui/views/controls/button/label_button.h" 37 #include "ui/views/controls/button/label_button.h"
48 #include "ui/views/controls/label.h" 38 #include "ui/views/controls/label.h"
39 #include "ui/views/controls/scroll_view.h"
49 #include "ui/views/controls/separator.h" 40 #include "ui/views/controls/separator.h"
50 #include "ui/views/layout/fill_layout.h" 41 #include "ui/views/layout/fill_layout.h"
51 #include "ui/views/view.h" 42 #include "ui/views/view.h"
52 43
53 namespace ash { 44 namespace ash {
54 45 namespace tray {
55 namespace { 46 namespace {
56 47
57 // Indicates whether |network| belongs to this VPN provider. 48 // Indicates whether |network| belongs to this VPN provider.
58 bool VpnProviderMatchesNetwork(const VPNProvider& provider, 49 bool VpnProviderMatchesNetwork(const VPNProvider& provider,
59 const chromeos::NetworkState& network) { 50 const chromeos::NetworkState& network) {
60 if (network.type() != shill::kTypeVPN) 51 if (network.type() != shill::kTypeVPN)
61 return false; 52 return false;
62 const bool network_uses_third_party_provider = 53 const bool network_uses_third_party_provider =
63 network.vpn_provider_type() == shill::kProviderThirdPartyVpn; 54 network.vpn_provider_type() == shill::kProviderThirdPartyVpn;
64 if (!provider.third_party) 55 if (!provider.third_party)
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 AddIconAndLabels( 228 AddIconAndLabels(
238 image, text, 229 image, text,
239 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTING)); 230 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTING));
240 ThrobberView* throbber = new ThrobberView; 231 ThrobberView* throbber = new ThrobberView;
241 throbber->Start(); 232 throbber->Start();
242 AddRightView(throbber); 233 AddRightView(throbber);
243 } 234 }
244 235
245 } // namespace 236 } // namespace
246 237
247 VPNListView::VPNListView(tray::NetworkStateListDetailedView* detailed_view) 238 VPNListView::VPNListView(SystemTrayItem* owner, LoginStatus login)
248 : NetworkListViewBase(detailed_view) { 239 : NetworkStateListDetailedView(owner, LIST_TYPE_VPN, login) {
249 Shell::Get()->vpn_list()->AddObserver(this); 240 Shell::Get()->vpn_list()->AddObserver(this);
250 } 241 }
251 242
252 VPNListView::~VPNListView() { 243 VPNListView::~VPNListView() {
253 Shell::Get()->vpn_list()->RemoveObserver(this); 244 Shell::Get()->vpn_list()->RemoveObserver(this);
254 } 245 }
255 246
256 void VPNListView::Update() { 247 void VPNListView::UpdateNetworkList() {
257 // Before updating the list, determine whether the user was hovering over one 248 // Before updating the list, determine whether the user was hovering over one
258 // of the VPN provider or network entries. 249 // of the VPN provider or network entries.
259 std::unique_ptr<VPNProvider> hovered_provider; 250 std::unique_ptr<VPNProvider> hovered_provider;
260 std::string hovered_network_guid; 251 std::string hovered_network_guid;
261 for (const std::pair<const views::View* const, VPNProvider>& provider : 252 for (const std::pair<const views::View* const, VPNProvider>& provider :
262 provider_view_map_) { 253 provider_view_map_) {
263 if (provider.first->IsMouseHovered()) { 254 if (provider.first->IsMouseHovered()) {
264 hovered_provider.reset(new VPNProvider(provider.second)); 255 hovered_provider.reset(new VPNProvider(provider.second));
265 break; 256 break;
266 } 257 }
267 } 258 }
268 if (!hovered_provider) { 259 if (!hovered_provider) {
269 for (const std::pair<const views::View*, std::string>& entry : 260 for (const std::pair<const views::View*, std::string>& entry :
270 network_view_guid_map_) { 261 network_view_guid_map_) {
271 if (entry.first->IsMouseHovered()) { 262 if (entry.first->IsMouseHovered()) {
272 hovered_network_guid = entry.second; 263 hovered_network_guid = entry.second;
273 break; 264 break;
274 } 265 }
275 } 266 }
276 } 267 }
277 268
278 // Clear the list. 269 // Clear the list.
279 container()->RemoveAllChildViews(true); 270 scroll_content()->RemoveAllChildViews(true);
280 provider_view_map_.clear(); 271 provider_view_map_.clear();
281 network_view_guid_map_.clear(); 272 network_view_guid_map_.clear();
282 list_empty_ = true; 273 list_empty_ = true;
283 274
284 // Get the list of available VPN networks, in shill's priority order. 275 // Get the list of available VPN networks, in shill's priority order.
285 chromeos::NetworkStateHandler::NetworkStateList networks; 276 chromeos::NetworkStateHandler::NetworkStateList networks;
286 chromeos::NetworkHandler::Get() 277 chromeos::NetworkHandler::Get()
287 ->network_state_handler() 278 ->network_state_handler()
288 ->GetVisibleNetworkListByType(chromeos::NetworkTypePattern::VPN(), 279 ->GetVisibleNetworkListByType(chromeos::NetworkTypePattern::VPN(),
289 &networks); 280 &networks);
(...skipping 17 matching lines...) Expand all
307 for (const std::pair<const views::View*, std::string>& entry : 298 for (const std::pair<const views::View*, std::string>& entry :
308 network_view_guid_map_) { 299 network_view_guid_map_) {
309 if (entry.second == hovered_network_guid) { 300 if (entry.second == hovered_network_guid) {
310 scroll_to_show_view = entry.first; 301 scroll_to_show_view = entry.first;
311 break; 302 break;
312 } 303 }
313 } 304 }
314 } 305 }
315 306
316 // Layout the updated list. 307 // Layout the updated list.
317 container()->SizeToPreferredSize(); 308 scroll_content()->SizeToPreferredSize();
318 detailed_view()->RelayoutScrollList(); 309 scroller()->Layout();
319 310
320 if (scroll_to_show_view) { 311 if (scroll_to_show_view) {
321 // Scroll the list so that |scroll_to_show_view| is in view. 312 // Scroll the list so that |scroll_to_show_view| is in view.
322 container()->ScrollRectToVisible(scroll_to_show_view->bounds()); 313 scroll_content()->ScrollRectToVisible(scroll_to_show_view->bounds());
323 } 314 }
324 } 315 }
325 316
326 bool VPNListView::IsNetworkEntry(views::View* view, std::string* guid) const { 317 bool VPNListView::IsNetworkEntry(views::View* view, std::string* guid) const {
327 const auto& entry = network_view_guid_map_.find(view); 318 const auto& entry = network_view_guid_map_.find(view);
328 if (entry == network_view_guid_map_.end()) 319 if (entry == network_view_guid_map_.end())
329 return false; 320 return false;
330 *guid = entry->second; 321 *guid = entry->second;
331 return true; 322 return true;
332 } 323 }
333 324
334 void VPNListView::OnVPNProvidersChanged() { 325 void VPNListView::OnVPNProvidersChanged() {
335 Update(); 326 UpdateNetworkList();
336 } 327 }
337 328
338 void VPNListView::AddNetwork(const chromeos::NetworkState* network) { 329 void VPNListView::AddNetwork(const chromeos::NetworkState* network) {
339 views::View* entry(new VPNListNetworkEntry(detailed_view(), network)); 330 views::View* entry(new VPNListNetworkEntry(this, network));
340 container()->AddChildView(entry); 331 scroll_content()->AddChildView(entry);
341 network_view_guid_map_[entry] = network->guid(); 332 network_view_guid_map_[entry] = network->guid();
342 list_empty_ = false; 333 list_empty_ = false;
343 } 334 }
344 335
345 void VPNListView::AddProviderAndNetworks( 336 void VPNListView::AddProviderAndNetworks(
346 const VPNProvider& vpn_provider, 337 const VPNProvider& vpn_provider,
347 const chromeos::NetworkStateHandler::NetworkStateList& networks) { 338 const chromeos::NetworkStateHandler::NetworkStateList& networks) {
348 // Add a visual separator, unless this is the topmost entry in the list. 339 // Add a visual separator, unless this is the topmost entry in the list.
349 if (!list_empty_) 340 if (!list_empty_) {
350 container()->AddChildView(TrayPopupUtils::CreateListSubHeaderSeparator()); 341 scroll_content()->AddChildView(
342 TrayPopupUtils::CreateListSubHeaderSeparator());
343 }
351 std::string vpn_name = 344 std::string vpn_name =
352 vpn_provider.third_party 345 vpn_provider.third_party
353 ? vpn_provider.third_party_provider_name 346 ? vpn_provider.third_party_provider_name
354 : l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_VPN_BUILT_IN_PROVIDER); 347 : l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_VPN_BUILT_IN_PROVIDER);
355 348
356 // Add a list entry for the VPN provider. 349 // Add a list entry for the VPN provider.
357 views::View* provider_view = nullptr; 350 views::View* provider_view = nullptr;
358 provider_view = new VPNListProviderEntry(vpn_provider, list_empty_, vpn_name, 351 provider_view = new VPNListProviderEntry(vpn_provider, list_empty_, vpn_name,
359 IDS_ASH_STATUS_TRAY_ADD_CONNECTION); 352 IDS_ASH_STATUS_TRAY_ADD_CONNECTION);
360 container()->AddChildView(provider_view); 353 scroll_content()->AddChildView(provider_view);
361 provider_view_map_[provider_view] = vpn_provider; 354 provider_view_map_[provider_view] = vpn_provider;
362 list_empty_ = false; 355 list_empty_ = false;
363 // Add the networks belonging to this provider, in the priority order returned 356 // Add the networks belonging to this provider, in the priority order returned
364 // by shill. 357 // by shill.
365 for (const chromeos::NetworkState* const& network : networks) { 358 for (const chromeos::NetworkState* const& network : networks) {
366 if (VpnProviderMatchesNetwork(vpn_provider, *network)) 359 if (VpnProviderMatchesNetwork(vpn_provider, *network))
367 AddNetwork(network); 360 AddNetwork(network);
368 } 361 }
369 } 362 }
370 363
(...skipping 16 matching lines...) Expand all
387 break; 380 break;
388 } 381 }
389 } 382 }
390 383
391 // Add providers without any configured networks, in the order that the 384 // Add providers without any configured networks, in the order that the
392 // providers were returned by the extensions system. 385 // providers were returned by the extensions system.
393 for (const VPNProvider& provider : providers) 386 for (const VPNProvider& provider : providers)
394 AddProviderAndNetworks(provider, networks); 387 AddProviderAndNetworks(provider, networks);
395 } 388 }
396 389
390 } // namespace tray
397 } // namespace ash 391 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/network/vpn_list_view.h ('k') | ash/system/tray/hover_highlight_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698