1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SYSTEM_NETWORK_NETWORK_DETAILED_NETWORK_VIEW_H_
#define ASH_SYSTEM_NETWORK_NETWORK_DETAILED_NETWORK_VIEW_H_
#include "ash/ash_export.h"
#include "ash/system/network/network_detailed_view.h"
#include "ash/system/network/network_list_mobile_header_view.h"
#include "ash/system/network/network_list_network_header_view.h"
#include "ash/system/network/network_list_network_item_view.h"
#include "ash/system/network/network_list_tether_hosts_header_view.h"
#include "ash/system/network/network_list_wifi_header_view.h"
#include "ash/system/tray/hover_highlight_view.h"
#include "base/memory/raw_ptr.h"
#include "ui/views/view.h"
namespace ash {
namespace {
using chromeos::network_config::mojom::NetworkType;
} // namespace
class DetailedViewDelegate;
// This class defines both the interface used to interact with the
// NetworkDetailedView and declares delegate interface it uses to propagate user
// interactions. It also defines the factory used to create instances of
// implementations of this class.
class ASH_EXPORT NetworkDetailedNetworkView {
public:
// This class defines the interface that NetworkDetailedNetworkView will use
// to propagate user interactions.
class Delegate : public NetworkDetailedView::Delegate {
public:
Delegate() = default;
~Delegate() override;
virtual void OnWifiToggleClicked(bool new_state) = 0;
virtual void OnMobileToggleClicked(bool new_state) = 0;
};
class Factory {
public:
Factory(const Factory&) = delete;
const Factory& operator=(const Factory&) = delete;
virtual ~Factory() = default;
static std::unique_ptr<NetworkDetailedNetworkView> Create(
DetailedViewDelegate* detailed_view_delegate,
Delegate* delegate);
static void SetFactoryForTesting(Factory* test_factory);
protected:
Factory() = default;
virtual std::unique_ptr<NetworkDetailedNetworkView> CreateForTesting(
Delegate* delegate) = 0;
};
NetworkDetailedNetworkView(const NetworkDetailedNetworkView&) = delete;
NetworkDetailedNetworkView& operator=(const NetworkDetailedNetworkView&) =
delete;
virtual ~NetworkDetailedNetworkView() = default;
// Notifies that the network list has changed and the layout is invalid.
virtual void NotifyNetworkListChanged() = 0;
// Returns the implementation casted to views::View*. This may be |nullptr|
// when testing, where the implementation might not inherit from views::View.
virtual views::View* GetAsView() = 0;
// 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(NetworkType type) = 0;
// Creates, adds and returns a `HoverHighlightView`, which is the "Join Wifi
// network" entry for the Wifi section if `NetworkType::kWiFi` is passed in or
// the "Add eSIM" entry for the Mobile data section if `NetworkType::kMobile`
// is passed in. The client is expected to use the returned pointer for
// removing and rearranging this entry.
virtual HoverHighlightView* AddConfigureNetworkEntry(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
// removing and rearranging the sub-header.
virtual NetworkListWifiHeaderView* AddWifiSectionHeader() = 0;
// Creates, adds and returns a Mobile sticky sub-header to the end of the
// network list. The client is expected to use the returned pointer for
// removing and rearranging the sub-header.
virtual NetworkListMobileHeaderView* AddMobileSectionHeader() = 0;
// Creates, adds and returns a Tether Hosts sticky sub-header to the end
// of the network list. The client is expected to use the returned pointer
// for removing and rearranging the sub-header.
virtual NetworkListTetherHostsHeaderView* AddTetherHostsSectionHeader(
NetworkListTetherHostsHeaderView::OnExpandedStateToggle callback) = 0;
// Updates the scanning bar visibility.
virtual void UpdateScanningBarVisibility(bool visible) = 0;
// Returns the network list.
virtual views::View* GetNetworkList(NetworkType type) = 0;
// Reorders the container or list view based on the index.
virtual void ReorderFirstListView(size_t index) = 0;
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;
virtual void ReorderTetherHostsListView(size_t index) = 0;
// Removes the first list view if there's no child views in it.
virtual void MaybeRemoveFirstListView() = 0;
// Updates the containers, shows or hides the corresponding list view.
virtual void UpdateWifiStatus(bool enabled) = 0;
virtual void UpdateMobileStatus(bool enabled) = 0;
virtual void UpdateTetherHostsStatus(bool enabled) = 0;
// Provides some virtual methods to get and set the scroll view's position
// before and after reordering the network list.
virtual void ScrollToPosition(int position) {}
virtual int GetScrollPosition();
protected:
explicit NetworkDetailedNetworkView(Delegate* delegate);
Delegate* delegate() { return delegate_; }
private:
raw_ptr<Delegate> delegate_;
};
} // namespace ash
#endif // ASH_SYSTEM_NETWORK_NETWORK_DETAILED_NETWORK_VIEW_H_
|