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

ash / system / hotspot / hotspot_detailed_view.h [blame]

// Copyright 2023 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_HOTSPOT_HOTSPOT_DETAILED_VIEW_H_
#define ASH_SYSTEM_HOTSPOT_HOTSPOT_DETAILED_VIEW_H_

#include "ash/ash_export.h"
#include "ash/system/hotspot/hotspot_icon_animation_observer.h"
#include "ash/system/tray/tray_detailed_view.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chromeos/ash/services/hotspot_config/public/mojom/cros_hotspot_config.mojom.h"
#include "ui/base/metadata/metadata_header_macros.h"

namespace views {
class Button;
class ImageView;
}  // namespace views

namespace ash {

class DetailedViewDelegate;
class HoverHighlightView;
class RoundedContainer;
class Switch;

// This class defines both the interface used to interact with the detailed
// Hotspot page within the quick settings. This class includes the declaration
// for the delegate interface it uses to propagate user interactions.
class ASH_EXPORT HotspotDetailedView : public TrayDetailedView,
                                       public HotspotIconAnimationObserver {
  METADATA_HEADER(HotspotDetailedView, TrayDetailedView)

 public:
  // This class defines the interface that HotspotDetailedView will use to
  // propagate user interactions.
  class Delegate {
   public:
    Delegate() = default;
    virtual ~Delegate() = default;

    virtual void OnToggleClicked(bool new_state) = 0;
  };

  HotspotDetailedView(DetailedViewDelegate* detailed_view_delegate,
                      Delegate* delegate);
  HotspotDetailedView(const HotspotDetailedView&) = delete;
  HotspotDetailedView& operator=(const HotspotDetailedView&) = delete;
  ~HotspotDetailedView() override;

  // Update the hotspot detailed view from the given `hotspot_info`.
  void UpdateViewForHotspot(hotspot_config::mojom::HotspotInfoPtr hotspot_info);

  // TrayDetailedView:
  void HandleViewClicked(views::View* view) override;
  void CreateExtraTitleRowButtons() override;

  // HotspotIconAnimationObserver:
  void HotspotIconChanged() override;

 private:
  friend class HotspotDetailedViewControllerTest;
  friend class HotspotDetailedViewTest;

  // Used for testing. Starts at 1 because view IDs should not be 0.
  enum class HotspotDetailedViewChildId {
    kInfoButton = 1,
    kSettingsButton = 2,
    kEntryRow = 3,
    kHotspotIcon = 4,
    kToggle = 5,
    kExtraIcon = 6,
  };

  // Creates the rounded container, which contains the main on/off toggle.
  void CreateContainer();

  // Attempts to close the quick settings and open the Hotspot subpage.
  void OnSettingsClicked();

  // Handles clicks on the Hotspot toggle button.
  void OnToggleClicked();

  // Handles toggling Hotspot via the UI to `new_state`.
  void ToggleHotspot(bool new_state);

  void UpdateIcon();
  void UpdateToggleState(
      const hotspot_config::mojom::HotspotState& state,
      const hotspot_config::mojom::HotspotAllowStatus& allow_status);
  void UpdateSubText(const hotspot_config::mojom::HotspotInfoPtr& hotspot_info);
  void UpdateExtraIcon(
      const hotspot_config::mojom::HotspotAllowStatus& allow_status);

  hotspot_config::mojom::HotspotState state_ =
      hotspot_config::mojom::HotspotState::kDisabled;
  hotspot_config::mojom::HotspotAllowStatus allow_status_ =
      hotspot_config::mojom::HotspotAllowStatus::kAllowed;

  const raw_ptr<Delegate> delegate_;

  // Owned by views hierarchy.
  raw_ptr<views::Button> settings_button_ = nullptr;
  raw_ptr<RoundedContainer> row_container_ = nullptr;
  raw_ptr<HoverHighlightView> entry_row_ = nullptr;
  raw_ptr<views::ImageView> hotspot_icon_ = nullptr;
  raw_ptr<Switch> toggle_ = nullptr;
  raw_ptr<views::ImageView> extra_icon_ = nullptr;

  base::WeakPtrFactory<HotspotDetailedView> weak_factory_{this};
};

}  // namespace ash

#endif  // ASH_SYSTEM_HOTSPOT_HOTSPOT_DETAILED_VIEW_H_