network_section_header_view.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. // Copyright 2018 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_SECTION_HEADER_VIEW_H_
  5. #define ASH_SYSTEM_NETWORK_NETWORK_SECTION_HEADER_VIEW_H_
  6. #include "ash/system/network/network_row_title_view.h"
  7. #include "ash/system/network/tray_network_state_observer.h"
  8. #include "ash/system/tray/tray_popup_utils.h"
  9. #include "ash/system/tray/tri_view.h"
  10. #include "base/memory/weak_ptr.h"
  11. #include "base/timer/timer.h"
  12. #include "chromeos/services/bluetooth_config/public/mojom/cros_bluetooth_config.mojom.h"
  13. #include "chromeos/services/network_config/public/mojom/cros_network_config.mojom-forward.h"
  14. #include "mojo/public/cpp/bindings/remote.h"
  15. #include "ui/views/controls/button/toggle_button.h"
  16. #include "ui/views/layout/fill_layout.h"
  17. #include "ui/views/view.h"
  18. namespace ash {
  19. class IconButton;
  20. class TrayNetworkStateModel;
  21. // A header row for sections in network detailed view which contains a title and
  22. // a toggle button to turn on/off the section. Subclasses are given the
  23. // opportunity to add extra buttons before the toggle button is added.
  24. class NetworkSectionHeaderView : public views::View {
  25. public:
  26. explicit NetworkSectionHeaderView(int title_id);
  27. NetworkSectionHeaderView(const NetworkSectionHeaderView&) = delete;
  28. NetworkSectionHeaderView& operator=(const NetworkSectionHeaderView&) = delete;
  29. ~NetworkSectionHeaderView() override = default;
  30. // Modify visibility of section toggle
  31. void SetToggleVisibility(bool visible);
  32. // Modify enabled/disabled and on/off state of toggle.
  33. virtual void SetToggleState(bool toggle_enabled, bool is_on);
  34. // views::View:
  35. const char* GetClassName() const override;
  36. protected:
  37. void Init(bool enabled);
  38. // This is called before the toggle button is added to give subclasses an
  39. // opportunity to add more buttons before the toggle button. Subclasses can
  40. // add buttons to container() using AddChildView().
  41. virtual void AddExtraButtons(bool enabled);
  42. // Called when |toggle_| is clicked and toggled. Subclasses can override to
  43. // enabled/disable their respective technology, for example.
  44. virtual void OnToggleToggled(bool is_on) = 0;
  45. TrayNetworkStateModel* model() { return model_; }
  46. TriView* container() const { return container_; }
  47. // views::View:
  48. int GetHeightForWidth(int width) const override;
  49. private:
  50. void InitializeLayout();
  51. void AddToggleButton(bool enabled);
  52. void ToggleButtonPressed();
  53. // Resource ID for the string to use as the title of the section and for the
  54. // accessible text on the section header toggle button.
  55. const int title_id_;
  56. TrayNetworkStateModel* model_;
  57. // View containing header row views, including title, toggle, and extra
  58. // buttons.
  59. TriView* container_ = nullptr;
  60. // View containing the header row view. Is a child of the CENTER of
  61. // |container_|.
  62. NetworkRowTitleView* network_row_title_view_ = nullptr;
  63. // ToggleButton to toggle section on or off.
  64. views::ToggleButton* toggle_ = nullptr;
  65. };
  66. // "Mobile Data" header row. Mobile Data reflects both Cellular state and
  67. // Tether state. When both technologies are available, Cellular state takes
  68. // precedence over Tether (but in some cases Tether state may be shown).
  69. class MobileSectionHeaderView : public NetworkSectionHeaderView,
  70. public TrayNetworkStateObserver {
  71. public:
  72. MobileSectionHeaderView();
  73. MobileSectionHeaderView(const MobileSectionHeaderView&) = delete;
  74. MobileSectionHeaderView& operator=(const MobileSectionHeaderView&) = delete;
  75. ~MobileSectionHeaderView() override;
  76. // Updates mobile toggle state and returns the id of the status message
  77. // that should be shown while connecting to a network. Returns zero when no
  78. // message should be shown.
  79. int UpdateToggleAndGetStatusMessage(bool mobile_has_networks,
  80. bool tether_has_networks);
  81. // views::View:
  82. const char* GetClassName() const override;
  83. private:
  84. // NetworkListView::NetworkSectionHeaderView:
  85. void OnToggleToggled(bool is_on) override;
  86. void AddExtraButtons(bool enabled) override;
  87. // TrayNetworkStateObserver:
  88. void DeviceStateListChanged() override;
  89. void GlobalPolicyChanged() override;
  90. void UpdateAddESimButtonVisibility();
  91. void AddCellularButtonPressed();
  92. // When Tether is disabled because Bluetooth is off, then enabling Bluetooth
  93. // will enable Tether. If enabling Bluetooth takes longer than some timeout
  94. // period, it is assumed that there was an error. In that case, Tether will
  95. // remain uninitialized and Mobile Data will remain toggled off.
  96. void EnableBluetooth();
  97. void OnEnableBluetoothTimeout();
  98. bool waiting_for_tether_initialize_ = false;
  99. base::OneShotTimer enable_bluetooth_timer_;
  100. // Button that navigates to the Settings mobile data subpage with the eSIM
  101. // setup dialog open. This is null when the device is not eSIM-capable.
  102. IconButton* add_esim_button_ = nullptr;
  103. // Indicates whether add_esim_button_ should be enabled when the device is
  104. // not inhibited.
  105. bool can_add_esim_button_be_enabled_ = false;
  106. // CrosBluetoothConfig remote that is only bound if the Bluetooth
  107. // Revamp flag is enabled.
  108. mojo::Remote<chromeos::bluetooth_config::mojom::CrosBluetoothConfig>
  109. remote_cros_bluetooth_config_;
  110. base::WeakPtrFactory<MobileSectionHeaderView> weak_ptr_factory_{this};
  111. };
  112. class WifiSectionHeaderView : public NetworkSectionHeaderView,
  113. public TrayNetworkStateObserver {
  114. public:
  115. WifiSectionHeaderView();
  116. WifiSectionHeaderView(const WifiSectionHeaderView&) = delete;
  117. WifiSectionHeaderView& operator=(const WifiSectionHeaderView&) = delete;
  118. ~WifiSectionHeaderView() override;
  119. // NetworkSectionHeaderView:
  120. void SetToggleState(bool toggle_enabled, bool is_on) override;
  121. // views::View:
  122. const char* GetClassName() const override;
  123. private:
  124. // TrayNetworkStateObserver:
  125. void DeviceStateListChanged() override;
  126. void GlobalPolicyChanged() override;
  127. // NetworkSectionHeaderView:
  128. void OnToggleToggled(bool is_on) override;
  129. void AddExtraButtons(bool enabled) override;
  130. void UpdateJoinButtonVisibility();
  131. void JoinButtonPressed();
  132. // A button to invoke "Join Wi-Fi network" dialog.
  133. IconButton* join_button_ = nullptr;
  134. };
  135. } // namespace ash
  136. #endif // ASH_SYSTEM_NETWORK_NETWORK_SECTION_HEADER_VIEW_H_