network_detailed_view.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // Copyright 2022 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef ASH_SYSTEM_NETWORK_NETWORK_DETAILED_VIEW_H_
  5. #define ASH_SYSTEM_NETWORK_NETWORK_DETAILED_VIEW_H_
  6. #include "ash/ash_export.h"
  7. #include "ash/login_status.h"
  8. #include "ash/system/network/network_info_bubble.h"
  9. #include "ash/system/tray/tray_detailed_view.h"
  10. #include "base/memory/weak_ptr.h"
  11. #include "chromeos/services/network_config/public/mojom/cros_network_config.mojom.h"
  12. namespace views {
  13. class View;
  14. } // namespace views
  15. namespace ash {
  16. class TrayNetworkStateModel;
  17. class DetailedViewDelegate;
  18. class Button;
  19. // This class defines both the interface used to interact with the detailed
  20. // Network page within the quick settings, including the view responsible for
  21. // containing the network list. This class includes the declaration for the
  22. // delegate interface it uses to propagate user interactions.
  23. class ASH_EXPORT NetworkDetailedView : public TrayDetailedView,
  24. public NetworkInfoBubble::Delegate {
  25. public:
  26. // This class defines the interface that NetworkDetailedView will use to
  27. // propagate user interactions.
  28. class Delegate {
  29. public:
  30. Delegate() = default;
  31. virtual ~Delegate() = default;
  32. virtual void OnNetworkListItemSelected(
  33. const chromeos::network_config::mojom::NetworkStatePropertiesPtr&
  34. network) = 0;
  35. };
  36. NetworkDetailedView(const NetworkDetailedView&) = delete;
  37. NetworkDetailedView& operator=(const NetworkDetailedView&) = delete;
  38. ~NetworkDetailedView() override;
  39. protected:
  40. enum ListType { LIST_TYPE_NETWORK, LIST_TYPE_VPN };
  41. NetworkDetailedView(DetailedViewDelegate* detailed_view_delegate,
  42. Delegate* delegate,
  43. ListType list_type);
  44. Delegate* delegate() { return delegate_; }
  45. private:
  46. friend class NetworkDetailedViewTest;
  47. // Used for testing. Starts at 1 because view IDs should not be 0.
  48. enum class NetworkDetailedViewChildId {
  49. kInfoButton = 1,
  50. kSettingsButton = 2,
  51. };
  52. void CreateTitleRowButtons();
  53. void OnInfoClicked();
  54. bool CloseInfoBubble();
  55. void OnSettingsClicked();
  56. // TrayDetailedView:
  57. void HandleViewClicked(views::View* view) override;
  58. // NetworkInfoBubble::Delegate:
  59. bool ShouldIncludeDeviceAddresses() override;
  60. void OnInfoBubbleDestroyed() override;
  61. // Type of list (all non-VPN netwoks, or only VPN networks).
  62. const ListType list_type_;
  63. // Used to cache the login status on creation.
  64. const LoginStatus login_;
  65. TrayNetworkStateModel* model_;
  66. views::Button* info_button_ = nullptr;
  67. views::Button* settings_button_ = nullptr;
  68. // A small bubble for displaying network info.
  69. NetworkInfoBubble* info_bubble_ = nullptr;
  70. Delegate* delegate_;
  71. base::WeakPtrFactory<NetworkDetailedView> weak_ptr_factory_{this};
  72. };
  73. } // namespace ash
  74. #endif // ASH_SYSTEM_NETWORK_NETWORK_DETAILED_VIEW_H_