Skip to content

Commit

Permalink
Implement qs revamped network sub page
Browse files Browse the repository at this point in the history
The padding of this is not the final version yet. We will need to add
buttons to each header in the next cl.

The ui for Ethernet and warning message is not done from the UX side.
So they are added on the most top for now.

Screenshot:
https://screenshot.googleplex.com/66EMBMMa49XxMhY

Bug: b/253086997
Change-Id: I6b938d32eddcfea6481930d81530b5d2cc174ae1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4108931
Reviewed-by: Alex Newcomer <newcomer@chromium.org>
Commit-Queue: Jiaming Cheng <jiamingc@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1084522}
  • Loading branch information
Jiaming Cheng authored and Chromium LUCI CQ committed Dec 16, 2022
1 parent ff447b5 commit a0347a7
Show file tree
Hide file tree
Showing 9 changed files with 532 additions and 267 deletions.
12 changes: 8 additions & 4 deletions ash/system/network/fake_network_detailed_network_view.cc
Expand Up @@ -15,6 +15,10 @@

namespace ash {

namespace {
using ::chromeos::network_config::mojom::NetworkType;
}

FakeNetworkDetailedNetworkView::FakeNetworkDetailedNetworkView(
Delegate* delegate)
: NetworkDetailedNetworkView(delegate),
Expand All @@ -26,7 +30,7 @@ void FakeNetworkDetailedNetworkView::NotifyNetworkListChanged() {
notify_network_list_changed_call_count_++;
}

views::View* FakeNetworkDetailedNetworkView::network_list() {
views::View* FakeNetworkDetailedNetworkView::GetNetworkList(NetworkType type) {
return network_list_.get();
}

Expand All @@ -38,10 +42,10 @@ void FakeNetworkDetailedNetworkView::OnViewClicked(views::View* view) {
last_clicked_network_list_item_ = static_cast<NetworkListItemView*>(view);
}

NetworkListNetworkItemView*
FakeNetworkDetailedNetworkView::AddNetworkListItem() {
NetworkListNetworkItemView* FakeNetworkDetailedNetworkView::AddNetworkListItem(
NetworkType type) {
return network_list_->AddChildView(
new NetworkListNetworkItemView(/*listener=*/nullptr));
std::make_unique<NetworkListNetworkItemView>(/*listener=*/nullptr));
}

NetworkListWifiHeaderView*
Expand Down
10 changes: 8 additions & 2 deletions ash/system/network/fake_network_detailed_network_view.h
Expand Up @@ -38,16 +38,22 @@ class ASH_EXPORT FakeNetworkDetailedNetworkView
return last_clicked_network_list_item_;
}

views::View* network_list() override;
views::View* GetNetworkList(
chromeos::network_config::mojom::NetworkType type) override;

private:
// NetworkDetailedNetworkView:
void NotifyNetworkListChanged() override;
views::View* GetAsView() override;
NetworkListNetworkItemView* AddNetworkListItem() override;
NetworkListNetworkItemView* AddNetworkListItem(
chromeos::network_config::mojom::NetworkType type) override;
NetworkListWifiHeaderView* AddWifiSectionHeader() override;
NetworkListMobileHeaderView* AddMobileSectionHeader() override;
void UpdateScanningBarVisibility(bool visible) override;
void ReorderNetworkTopContainer(size_t index) override {}
void ReorderNetworkListView(size_t index) override {}
void ReorderMobileTopContainer(size_t index) override {}
void ReorderMobileListView(size_t index) override {}

// ViewClickListener:
void OnViewClicked(views::View* view) override;
Expand Down
12 changes: 10 additions & 2 deletions ash/system/network/network_detailed_network_view.h
Expand Up @@ -67,7 +67,8 @@ class ASH_EXPORT NetworkDetailedNetworkView {
// Creates, adds and returns a new network list item. The client is
// expected to use the returned pointer for removing and rearranging
// the list item.
virtual NetworkListNetworkItemView* AddNetworkListItem() = 0;
virtual NetworkListNetworkItemView* AddNetworkListItem(
chromeos::network_config::mojom::NetworkType type) = 0;

// Creates, adds and returns a Wifi sticky sub-header to the end of the
// network list. The client is expected to use the returned pointer for
Expand All @@ -83,7 +84,14 @@ class ASH_EXPORT NetworkDetailedNetworkView {
virtual void UpdateScanningBarVisibility(bool visible) = 0;

// Returns the network list.
virtual views::View* network_list() = 0;
virtual views::View* GetNetworkList(
chromeos::network_config::mojom::NetworkType type) = 0;

// Reorder the container or list view based on the index.
virtual void ReorderNetworkTopContainer(size_t index) = 0;
virtual void ReorderNetworkListView(size_t index) = 0;
virtual void ReorderMobileTopContainer(size_t index) = 0;
virtual void ReorderMobileListView(size_t index) = 0;

protected:
explicit NetworkDetailedNetworkView(Delegate* delegate);
Expand Down
108 changes: 97 additions & 11 deletions ash/system/network/network_detailed_network_view_impl.cc
Expand Up @@ -7,16 +7,27 @@
#include "ash/constants/ash_features.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shell.h"
#include "ash/style/rounded_container.h"
#include "ash/system/network/network_detailed_view.h"
#include "ash/system/network/network_list_mobile_header_view_impl.h"
#include "ash/system/network/network_list_network_item_view.h"
#include "ash/system/network/network_list_wifi_header_view_impl.h"
#include "ash/system/network/network_utils.h"
#include "ash/system/network/tray_network_state_model.h"
#include "ash/system/tray/detailed_view_delegate.h"
#include "base/notreached.h"
#include "chromeos/services/network_config/public/mojom/network_types.mojom-shared.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/views/view.h"
#include "ui/views/view_class_properties.h"

namespace ash {
namespace {
using chromeos::network_config::mojom::NetworkType;

constexpr auto kMainContainerMargins = gfx::Insets::TLBR(2, 0, 0, 0);
constexpr auto kTopContainerBorder = gfx::Insets::TLBR(8, 0, 8, 4);
} // namespace

NetworkDetailedNetworkViewImpl::NetworkDetailedNetworkViewImpl(
DetailedViewDelegate* detailed_view_delegate,
Expand All @@ -35,8 +46,9 @@ void NetworkDetailedNetworkViewImpl::NotifyNetworkListChanged() {
scroll_content()->InvalidateLayout();
Layout();

if (!settings_button())
if (!settings_button()) {
return;
}

if (Shell::Get()->session_controller()->login_status() ==
LoginStatus::NOT_LOGGED_IN) {
Expand All @@ -56,26 +68,100 @@ views::View* NetworkDetailedNetworkViewImpl::GetAsView() {
return this;
}

NetworkListNetworkItemView*
NetworkDetailedNetworkViewImpl::AddNetworkListItem() {
return scroll_content()->AddChildView(
new NetworkListNetworkItemView(/*listener=*/this));
NetworkListNetworkItemView* NetworkDetailedNetworkViewImpl::AddNetworkListItem(
NetworkType type) {
return GetNetworkList(type)->AddChildView(
std::make_unique<NetworkListNetworkItemView>(/*listener=*/this));
}

NetworkListWifiHeaderView*
NetworkDetailedNetworkViewImpl::AddWifiSectionHeader() {
return scroll_content()->AddChildView(
new NetworkListWifiHeaderViewImpl(/*delegate=*/this));
if (!wifi_top_container_ && features::IsQsRevampEnabled()) {
wifi_top_container_ =
scroll_content()->AddChildView(std::make_unique<RoundedContainer>(
RoundedContainer::Behavior::kTopRounded));
wifi_top_container_->SetBorderInsets(kTopContainerBorder);
wifi_top_container_->SetProperty(views::kMarginsKey,
gfx::Insets::TLBR(6, 0, 0, 0));
}
return (features::IsQsRevampEnabled() ? wifi_top_container_
: scroll_content())
->AddChildView(
std::make_unique<NetworkListWifiHeaderViewImpl>(/*delegate=*/this));
}

NetworkListMobileHeaderView*
NetworkDetailedNetworkViewImpl::AddMobileSectionHeader() {
return scroll_content()->AddChildView(
new NetworkListMobileHeaderViewImpl(/*delegate=*/this));
if (!mobile_top_container_ && features::IsQsRevampEnabled()) {
mobile_top_container_ =
scroll_content()->AddChildView(std::make_unique<RoundedContainer>(
RoundedContainer::Behavior::kTopRounded));
mobile_top_container_->SetBorderInsets(kTopContainerBorder);
}
return (features::IsQsRevampEnabled() ? mobile_top_container_
: scroll_content())
->AddChildView(
std::make_unique<NetworkListMobileHeaderViewImpl>(/*delegate=*/this));
}

views::View* NetworkDetailedNetworkViewImpl::GetNetworkList(NetworkType type) {
if (!features::IsQsRevampEnabled()) {
return scroll_content();
}

switch (type) {
case NetworkType::kWiFi:
if (!wifi_network_list_view_) {
wifi_network_list_view_ =
scroll_content()->AddChildView(std::make_unique<RoundedContainer>(
RoundedContainer::Behavior::kBottomRounded));

// Add a small empty space, like a separator, between the containers.
wifi_network_list_view_->SetProperty(views::kMarginsKey,
kMainContainerMargins);
}
return wifi_network_list_view_;
case NetworkType::kMobile:
case NetworkType::kTether:
case NetworkType::kCellular:
if (!mobile_network_list_view_) {
mobile_network_list_view_ =
scroll_content()->AddChildView(std::make_unique<RoundedContainer>(
RoundedContainer::Behavior::kBottomRounded));

// Add a small empty space, like a separator, between the containers.
mobile_network_list_view_->SetProperty(views::kMarginsKey,
kMainContainerMargins);
}
return mobile_network_list_view_;
default:
return scroll_content();
}
NOTREACHED();
}

views::View* NetworkDetailedNetworkViewImpl::network_list() {
return scroll_content();
void NetworkDetailedNetworkViewImpl::ReorderNetworkTopContainer(size_t index) {
if (wifi_top_container_) {
scroll_content()->ReorderChildView(wifi_top_container_, index);
}
}

void NetworkDetailedNetworkViewImpl::ReorderNetworkListView(size_t index) {
if (wifi_network_list_view_) {
scroll_content()->ReorderChildView(wifi_network_list_view_, index);
}
}

void NetworkDetailedNetworkViewImpl::ReorderMobileTopContainer(size_t index) {
if (mobile_top_container_) {
scroll_content()->ReorderChildView(mobile_top_container_, index);
}
}

void NetworkDetailedNetworkViewImpl::ReorderMobileListView(size_t index) {
if (mobile_network_list_view_) {
scroll_content()->ReorderChildView(mobile_network_list_view_, index);
}
}

void NetworkDetailedNetworkViewImpl::OnMobileToggleClicked(bool new_state) {
Expand Down
20 changes: 18 additions & 2 deletions ash/system/network/network_detailed_network_view_impl.h
Expand Up @@ -7,6 +7,7 @@

#include "ash/ash_export.h"

#include "ash/style/rounded_container.h"
#include "ash/system/network/network_detailed_network_view.h"
#include "ash/system/network/network_list_mobile_header_view_impl.h"
#include "ash/system/network/network_list_network_item_view.h"
Expand Down Expand Up @@ -41,15 +42,30 @@ class ASH_EXPORT NetworkDetailedNetworkViewImpl
// NetworkDetailedNetworkView:
void NotifyNetworkListChanged() override;
views::View* GetAsView() override;
NetworkListNetworkItemView* AddNetworkListItem() override;
NetworkListNetworkItemView* AddNetworkListItem(
chromeos::network_config::mojom::NetworkType type) override;
NetworkListMobileHeaderView* AddMobileSectionHeader() override;
NetworkListWifiHeaderView* AddWifiSectionHeader() override;
void UpdateScanningBarVisibility(bool visible) override;
views::View* network_list() override;
views::View* GetNetworkList(
chromeos::network_config::mojom::NetworkType type) override;
void ReorderNetworkTopContainer(size_t index) override;
void ReorderNetworkListView(size_t index) override;
void ReorderMobileTopContainer(size_t index) override;
void ReorderMobileListView(size_t index) override;

// NetworkListNetworkHeaderView::Delegate:
void OnMobileToggleClicked(bool new_state) override;
void OnWifiToggleClicked(bool new_state) override;

// Owned by views hierarchy. These are the containers to carry the mobile
// header, mobile network entries, wifi header, and wifi network entries.
// These containers are only used and added to the `network_list_` when the
// `features::IsQsRevampEnabled()` is true.
RoundedContainer* mobile_top_container_ = nullptr;
RoundedContainer* mobile_network_list_view_ = nullptr;
RoundedContainer* wifi_top_container_ = nullptr;
RoundedContainer* wifi_network_list_view_ = nullptr;
};

} // namespace ash
Expand Down
12 changes: 7 additions & 5 deletions ash/system/network/network_detailed_network_view_unittest.cc
Expand Up @@ -19,6 +19,7 @@
#include "base/test/scoped_feature_list.h"
#include "chromeos/services/network_config/public/cpp/cros_network_config_test_helper.h"
#include "chromeos/services/network_config/public/mojom/cros_network_config.mojom.h"
#include "chromeos/services/network_config/public/mojom/network_types.mojom-shared.h"
#include "third_party/cros_system_api/dbus/shill/dbus-constants.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/events/event_utils.h"
Expand All @@ -29,7 +30,6 @@
namespace ash {

namespace {

using chromeos::network_config::CrosNetworkConfigTestHelper;

using chromeos::network_config::mojom::ConnectionStateType;
Expand Down Expand Up @@ -159,8 +159,8 @@ class NetworkDetailedNetworkViewTest : public AshTestBase {
base::RunLoop().RunUntilIdle();
}

NetworkListNetworkItemView* AddNetworkListItem() {
return network_detailed_network_view()->AddNetworkListItem();
NetworkListNetworkItemView* AddNetworkListItem(NetworkType type) {
return network_detailed_network_view()->AddNetworkListItem(type);
}

void NotifyNetworkListChanged() {
Expand Down Expand Up @@ -217,7 +217,8 @@ class NetworkDetailedNetworkViewTest : public AshTestBase {
};

TEST_F(NetworkDetailedNetworkViewTest, ViewsAreCreated) {
NetworkListNetworkItemView* network_list_item = AddNetworkListItem();
NetworkListNetworkItemView* network_list_item =
AddNetworkListItem(NetworkType::kWiFi);
ASSERT_NE(nullptr, network_list_item);
EXPECT_STREQ("NetworkListNetworkItemView", network_list_item->GetClassName());

Expand Down Expand Up @@ -248,7 +249,8 @@ TEST_F(NetworkDetailedNetworkViewTest, ToggleInteractions) {

TEST_F(NetworkDetailedNetworkViewTest, ListItemClicked) {
EXPECT_EQ(0u, delegate()->network_list_item_selected_count());
NetworkListNetworkItemView* network_list_item = AddNetworkListItem();
NetworkListNetworkItemView* network_list_item =
AddNetworkListItem(NetworkType::kWiFi);
ASSERT_NE(nullptr, network_list_item);
NotifyNetworkListChanged();
LeftClickOn(network_list_item);
Expand Down
1 change: 1 addition & 0 deletions ash/system/network/network_list_mobile_header_view_impl.h
Expand Up @@ -29,6 +29,7 @@ class ASH_EXPORT NetworkListMobileHeaderViewImpl

private:
friend class NetworkListMobileHeaderViewTest;
friend class NetworkListViewControllerTest;

// Used for testing.
static constexpr int kAddESimButtonId =
Expand Down

0 comments on commit a0347a7

Please sign in to comment.