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

Side by Side Diff: ash/system/network/network_list.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/network_list.h ('k') | ash/system/network/network_list_view_base.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/network_list.h" 5 #include "ash/system/network/network_list.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "ash/public/cpp/config.h"
10 #include "ash/shell.h" 9 #include "ash/shell.h"
11 #include "ash/shell_port.h" 10 #include "ash/shell_port.h"
12 #include "ash/strings/grit/ash_strings.h" 11 #include "ash/strings/grit/ash_strings.h"
13 #include "ash/system/network/network_icon.h" 12 #include "ash/system/network/network_icon.h"
14 #include "ash/system/network/network_icon_animation.h" 13 #include "ash/system/network/network_icon_animation.h"
15 #include "ash/system/network/network_info.h" 14 #include "ash/system/network/network_info.h"
16 #include "ash/system/network/network_state_list_detailed_view.h" 15 #include "ash/system/network/network_state_list_detailed_view.h"
17 #include "ash/system/networking_config_delegate.h" 16 #include "ash/system/networking_config_delegate.h"
18 #include "ash/system/tray/fixed_sized_image_view.h" 17
19 #include "ash/system/tray/hover_highlight_view.h" 18 #include "ash/system/tray/hover_highlight_view.h"
20 #include "ash/system/tray/system_menu_button.h" 19 #include "ash/system/tray/system_menu_button.h"
21 #include "ash/system/tray/system_tray_controller.h" 20 #include "ash/system/tray/system_tray_controller.h"
22 #include "ash/system/tray/system_tray_delegate.h" 21 #include "ash/system/tray/system_tray_delegate.h"
23 #include "ash/system/tray/throbber_view.h" 22 #include "ash/system/tray/throbber_view.h"
24 #include "ash/system/tray/tray_constants.h" 23 #include "ash/system/tray/tray_constants.h"
25 #include "ash/system/tray/tray_popup_item_style.h" 24 #include "ash/system/tray/tray_popup_item_style.h"
26 #include "ash/system/tray/tray_popup_utils.h" 25 #include "ash/system/tray/tray_popup_utils.h"
27 #include "ash/system/tray/tri_view.h" 26 #include "ash/system/tray/tri_view.h"
28 #include "base/memory/ptr_util.h" 27 #include "base/memory/ptr_util.h"
29 #include "base/strings/string16.h" 28 #include "base/strings/string16.h"
30 #include "base/strings/utf_string_conversions.h" 29 #include "base/strings/utf_string_conversions.h"
31 #include "chromeos/dbus/dbus_thread_manager.h" 30 #include "chromeos/dbus/dbus_thread_manager.h"
32 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h"
33 #include "chromeos/dbus/power_manager_client.h"
34 #include "chromeos/login/login_state.h" 31 #include "chromeos/login/login_state.h"
35 #include "chromeos/network/managed_network_configuration_handler.h" 32 #include "chromeos/network/managed_network_configuration_handler.h"
36 #include "chromeos/network/network_state.h" 33 #include "chromeos/network/network_state.h"
37 #include "chromeos/network/network_state_handler.h" 34 #include "chromeos/network/network_state_handler.h"
38 #include "chromeos/network/network_state_handler_observer.h"
39 #include "chromeos/network/proxy/ui_proxy_config_service.h" 35 #include "chromeos/network/proxy/ui_proxy_config_service.h"
40 #include "components/device_event_log/device_event_log.h" 36 #include "components/device_event_log/device_event_log.h"
37 #include "third_party/cros_system_api/dbus/service_constants.h"
41 #include "third_party/skia/include/core/SkColor.h" 38 #include "third_party/skia/include/core/SkColor.h"
42 #include "ui/base/l10n/l10n_util.h" 39 #include "ui/base/l10n/l10n_util.h"
43 #include "ui/base/resource/resource_bundle.h"
44 #include "ui/gfx/color_palette.h"
45 #include "ui/gfx/font.h" 40 #include "ui/gfx/font.h"
46 #include "ui/gfx/image/image_skia.h" 41 #include "ui/gfx/image/image_skia.h"
47 #include "ui/gfx/paint_vector_icon.h" 42 #include "ui/gfx/paint_vector_icon.h"
48 #include "ui/gfx/text_constants.h" 43 #include "ui/gfx/text_constants.h"
49 #include "ui/views/background.h" 44 #include "ui/views/background.h"
50 #include "ui/views/border.h" 45 #include "ui/views/border.h"
51 #include "ui/views/controls/button/toggle_button.h" 46 #include "ui/views/controls/button/toggle_button.h"
52 #include "ui/views/controls/image_view.h" 47 #include "ui/views/controls/image_view.h"
53 #include "ui/views/controls/label.h" 48 #include "ui/views/controls/label.h"
49 #include "ui/views/controls/scroll_view.h"
54 #include "ui/views/controls/separator.h" 50 #include "ui/views/controls/separator.h"
55 #include "ui/views/layout/box_layout.h"
56 #include "ui/views/layout/fill_layout.h" 51 #include "ui/views/layout/fill_layout.h"
57 #include "ui/views/painter.h" 52
58 #include "ui/views/view.h" 53 #include "ui/views/view.h"
59 54
60 using chromeos::LoginState; 55 using chromeos::LoginState;
61 using chromeos::NetworkHandler; 56 using chromeos::NetworkHandler;
62 using chromeos::NetworkStateHandler; 57 using chromeos::NetworkStateHandler;
63 using chromeos::ManagedNetworkConfigurationHandler; 58 using chromeos::ManagedNetworkConfigurationHandler;
64 using chromeos::NetworkTypePattern; 59 using chromeos::NetworkTypePattern;
65 60
66 namespace ash { 61 namespace ash {
67 62 namespace tray {
68 namespace { 63 namespace {
69 64
70 bool IsProhibitedByPolicy(const chromeos::NetworkState* network) { 65 bool IsProhibitedByPolicy(const chromeos::NetworkState* network) {
71 if (!NetworkTypePattern::WiFi().MatchesType(network->type())) 66 if (!NetworkTypePattern::WiFi().MatchesType(network->type()))
72 return false; 67 return false;
73 if (!LoginState::IsInitialized() || !LoginState::Get()->IsUserLoggedIn()) 68 if (!LoginState::IsInitialized() || !LoginState::Get()->IsUserLoggedIn())
74 return false; 69 return false;
75 ManagedNetworkConfigurationHandler* managed_configuration_handler = 70 ManagedNetworkConfigurationHandler* managed_configuration_handler =
76 NetworkHandler::Get()->managed_network_configuration_handler(); 71 NetworkHandler::Get()->managed_network_configuration_handler();
77 const base::DictionaryValue* global_network_config = 72 const base::DictionaryValue* global_network_config =
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 // A button to invoke "Join Wi-Fi network" dialog. 313 // A button to invoke "Join Wi-Fi network" dialog.
319 SystemMenuButton* join_; 314 SystemMenuButton* join_;
320 315
321 DISALLOW_COPY_AND_ASSIGN(WifiHeaderRowView); 316 DISALLOW_COPY_AND_ASSIGN(WifiHeaderRowView);
322 }; 317 };
323 318
324 } // namespace 319 } // namespace
325 320
326 // NetworkListView: 321 // NetworkListView:
327 322
328 NetworkListView::NetworkListView( 323 NetworkListView::NetworkListView(SystemTrayItem* owner, LoginStatus login)
329 tray::NetworkStateListDetailedView* detailed_view) 324 : NetworkStateListDetailedView(owner, LIST_TYPE_NETWORK, login),
330 : NetworkListViewBase(detailed_view),
331 needs_relayout_(false), 325 needs_relayout_(false),
332 no_wifi_networks_view_(nullptr), 326 no_wifi_networks_view_(nullptr),
333 no_cellular_networks_view_(nullptr), 327 no_cellular_networks_view_(nullptr),
334 cellular_header_view_(nullptr), 328 cellular_header_view_(nullptr),
335 tether_header_view_(nullptr), 329 tether_header_view_(nullptr),
336 wifi_header_view_(nullptr), 330 wifi_header_view_(nullptr),
337 cellular_separator_view_(nullptr), 331 cellular_separator_view_(nullptr),
338 tether_separator_view_(nullptr), 332 tether_separator_view_(nullptr),
339 wifi_separator_view_(nullptr), 333 wifi_separator_view_(nullptr),
340 connection_warning_(nullptr) {} 334 connection_warning_(nullptr) {}
341 335
342 NetworkListView::~NetworkListView() { 336 NetworkListView::~NetworkListView() {
343 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); 337 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
344 } 338 }
345 339
346 void NetworkListView::Update() { 340 void NetworkListView::UpdateNetworkList() {
347 CHECK(container()); 341 CHECK(scroll_content());
348 342
349 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); 343 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
350 344
351 NetworkStateHandler::NetworkStateList network_list; 345 NetworkStateHandler::NetworkStateList network_list;
352 handler->GetVisibleNetworkList(&network_list); 346 handler->GetVisibleNetworkList(&network_list);
353 UpdateNetworks(network_list); 347 UpdateNetworks(network_list);
354 348
355 // Add Tether networks. 349 // Add Tether networks.
356 NetworkStateHandler::NetworkStateList tether_network_list; 350 NetworkStateHandler::NetworkStateList tether_network_list;
357 handler->GetVisibleNetworkListByType(NetworkTypePattern::Tether(), 351 handler->GetVisibleNetworkListByType(NetworkTypePattern::Tether(),
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 if (!needs_relayout_) 500 if (!needs_relayout_)
507 return; 501 return;
508 502
509 views::View* selected_view = nullptr; 503 views::View* selected_view = nullptr;
510 for (const auto& iter : network_guid_map_) { 504 for (const auto& iter : network_guid_map_) {
511 if (iter.second->IsMouseHovered()) { 505 if (iter.second->IsMouseHovered()) {
512 selected_view = iter.second; 506 selected_view = iter.second;
513 break; 507 break;
514 } 508 }
515 } 509 }
516 container()->SizeToPreferredSize(); 510 scroll_content()->SizeToPreferredSize();
517 detailed_view()->RelayoutScrollList(); 511 scroller()->Layout();
518 if (selected_view) 512 if (selected_view)
519 container()->ScrollRectToVisible(selected_view->bounds()); 513 scroll_content()->ScrollRectToVisible(selected_view->bounds());
520 } 514 }
521 515
522 std::unique_ptr<std::set<std::string>> 516 std::unique_ptr<std::set<std::string>>
523 NetworkListView::UpdateNetworkListEntries() { 517 NetworkListView::UpdateNetworkListEntries() {
524 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); 518 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
525 519
526 // Keep an index where the next child should be inserted. 520 // Keep an index where the next child should be inserted.
527 int index = 0; 521 int index = 0;
528 522
529 // Show a warning that the connection might be monitored if connected to a VPN 523 // Show a warning that the connection might be monitored if connected to a VPN
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 if (index == 0) { 612 if (index == 0) {
619 UpdateInfoLabel(IDS_ASH_STATUS_TRAY_NO_NETWORKS, index, 613 UpdateInfoLabel(IDS_ASH_STATUS_TRAY_NO_NETWORKS, index,
620 &no_wifi_networks_view_); 614 &no_wifi_networks_view_);
621 } 615 }
622 616
623 return new_guids; 617 return new_guids;
624 } 618 }
625 619
626 HoverHighlightView* NetworkListView::CreateViewForNetwork( 620 HoverHighlightView* NetworkListView::CreateViewForNetwork(
627 const NetworkInfo& info) { 621 const NetworkInfo& info) {
628 HoverHighlightView* container = new HoverHighlightView(detailed_view()); 622 HoverHighlightView* container = new HoverHighlightView(this);
629 if (info.connected) 623 if (info.connected)
630 SetupConnectedItem(container, info.label, info.image); 624 SetupConnectedItem(container, info.label, info.image);
631 else if (info.connecting) 625 else if (info.connecting)
632 SetupConnectingItem(container, info.label, info.image); 626 SetupConnectingItem(container, info.label, info.image);
633 else 627 else
634 container->AddIconAndLabel(info.image, info.label); 628 container->AddIconAndLabel(info.image, info.label);
635 container->SetTooltipText(info.tooltip); 629 container->SetTooltipText(info.tooltip);
636 views::View* controlled_icon = CreateControlledByExtensionView(info); 630 views::View* controlled_icon = CreateControlledByExtensionView(info);
637 if (controlled_icon) 631 if (controlled_icon)
638 container->AddRightView(controlled_icon); 632 container->AddRightView(controlled_icon);
639 return container; 633 return container;
640 } 634 }
641 635
642 void NetworkListView::UpdateViewForNetwork(HoverHighlightView* view, 636 void NetworkListView::UpdateViewForNetwork(HoverHighlightView* view,
643 const NetworkInfo& info) { 637 const NetworkInfo& info) {
644 DCHECK(!view->has_children()); 638 DCHECK(!view->is_populated());
645 if (info.connected) 639 if (info.connected)
646 SetupConnectedItem(view, info.label, info.image); 640 SetupConnectedItem(view, info.label, info.image);
647 else if (info.connecting) 641 else if (info.connecting)
648 SetupConnectingItem(view, info.label, info.image); 642 SetupConnectingItem(view, info.label, info.image);
649 else 643 else
650 view->AddIconAndLabel(info.image, info.label); 644 view->AddIconAndLabel(info.image, info.label);
651 views::View* controlled_icon = CreateControlledByExtensionView(info); 645 views::View* controlled_icon = CreateControlledByExtensionView(info);
652 view->SetTooltipText(info.tooltip); 646 view->SetTooltipText(info.tooltip);
653 if (controlled_icon) 647 if (controlled_icon)
654 view->AddChildView(controlled_icon); 648 view->AddChildView(controlled_icon);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 } 697 }
704 } 698 }
705 PlaceViewAtIndex(network_view, index); 699 PlaceViewAtIndex(network_view, index);
706 if (info->disable) 700 if (info->disable)
707 network_view->SetEnabled(false); 701 network_view->SetEnabled(false);
708 network_map_[network_view] = info->guid; 702 network_map_[network_view] = info->guid;
709 network_guid_map_[info->guid] = network_view; 703 network_guid_map_[info->guid] = network_view;
710 } 704 }
711 705
712 void NetworkListView::PlaceViewAtIndex(views::View* view, int index) { 706 void NetworkListView::PlaceViewAtIndex(views::View* view, int index) {
713 if (view->parent() != container()) { 707 if (view->parent() != scroll_content()) {
714 container()->AddChildViewAt(view, index); 708 scroll_content()->AddChildViewAt(view, index);
715 } else { 709 } else {
716 if (container()->child_at(index) == view) 710 if (scroll_content()->child_at(index) == view)
717 return; 711 return;
718 container()->ReorderChildView(view, index); 712 scroll_content()->ReorderChildView(view, index);
719 } 713 }
720 needs_relayout_ = true; 714 needs_relayout_ = true;
721 } 715 }
722 716
723 void NetworkListView::UpdateInfoLabel(int message_id, 717 void NetworkListView::UpdateInfoLabel(int message_id,
724 int insertion_index, 718 int insertion_index,
725 views::Label** label_ptr) { 719 views::Label** label_ptr) {
726 views::Label* label = *label_ptr; 720 views::Label* label = *label_ptr;
727 if (!message_id) { 721 if (!message_id) {
728 if (label) { 722 if (label) {
729 needs_relayout_ = true; 723 needs_relayout_ = true;
730 delete label; 724 delete label;
731 *label_ptr = nullptr; 725 *label_ptr = nullptr;
732 } 726 }
733 return; 727 return;
734 } 728 }
735 base::string16 text = 729 base::string16 text = l10n_util::GetStringUTF16(message_id);
736 ui::ResourceBundle::GetSharedInstance().GetLocalizedString(message_id);
737 if (!label) { 730 if (!label) {
738 // TODO(mohsen): Update info label to follow MD specs. See 731 // TODO(mohsen): Update info label to follow MD specs. See
739 // https://crbug.com/687778. 732 // https://crbug.com/687778.
740 label = new views::Label(); 733 label = new views::Label();
741 label->SetBorder(views::CreateEmptyBorder( 734 label->SetBorder(views::CreateEmptyBorder(
742 kTrayPopupPaddingBetweenItems, kTrayPopupPaddingHorizontal, 735 kTrayPopupPaddingBetweenItems, kTrayPopupPaddingHorizontal,
743 kTrayPopupPaddingBetweenItems, 0)); 736 kTrayPopupPaddingBetweenItems, 0));
744 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 737 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
745 label->SetEnabledColor(SkColorSetARGB(192, 0, 0, 0)); 738 label->SetEnabledColor(SkColorSetARGB(192, 0, 0, 0));
746 } 739 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 views::Background::CreateSolidBackground(SK_ColorTRANSPARENT)); 813 views::Background::CreateSolidBackground(SK_ColorTRANSPARENT));
821 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL); 814 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL);
822 style.SetupLabel(label); 815 style.SetupLabel(label);
823 connection_warning->AddView(TriView::Container::CENTER, label); 816 connection_warning->AddView(TriView::Container::CENTER, label);
824 817
825 // Nothing to the right of the text. 818 // Nothing to the right of the text.
826 connection_warning->SetContainerVisible(TriView::Container::END, false); 819 connection_warning->SetContainerVisible(TriView::Container::END, false);
827 return connection_warning; 820 return connection_warning;
828 } 821 }
829 822
823 } // namespace tray
830 } // namespace ash 824 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/network/network_list.h ('k') | ash/system/network/network_list_view_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698