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

ash / system / phonehub / quick_action_item.h [blame]

// Copyright 2020 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_PHONEHUB_QUICK_ACTION_ITEM_H_
#define ASH_SYSTEM_PHONEHUB_QUICK_ACTION_ITEM_H_

#include "ash/ash_export.h"
#include "ash/system/unified/feature_pod_button.h"
#include "base/memory/raw_ptr.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/views/view.h"

namespace views {
class Label;
}

namespace ash {

// A toggle button with labels used in the quick action view.
class ASH_EXPORT QuickActionItem : public views::View {
  METADATA_HEADER(QuickActionItem, views::View)

 public:
  class Delegate {
   public:
    // Called when the button of the quick action item is clicked.
    virtual void OnButtonPressed(bool is_now_enabled) = 0;
  };

  // If only one icon is supplied, it will be used in both cases.
  QuickActionItem(Delegate* delegate,
                  int label_id,
                  const gfx::VectorIcon& icon);

  ~QuickActionItem() override;
  QuickActionItem(QuickActionItem&) = delete;
  QuickActionItem operator=(QuickActionItem&) = delete;

  // Set the text of sub-label shown below the label.
  void SetSubLabel(const std::u16string& sub_label);

  // Set the color of sub-label shown below the label.
  void SetSubLabelColor(SkColor color);

  // Set the tooltip text of the icon button.
  void SetTooltip(const std::u16string& text);

  // Change the toggled state. If toggled, the background color of the circle
  // will change.
  void SetToggled(bool toggled);
  bool IsToggled() const;

  // Get the title/label text of the item.
  const std::u16string& GetItemLabel() const;

  // Set the item to be enabled or disabled. When disabled, the button cannot be
  // clicked and the labels are greyed out.
  void SetEnabled(bool enabled);

  // views::View:
  bool HasFocus() const override;
  void RequestFocus() override;

  FeaturePodIconButton* icon_button() const { return icon_button_; }

 private:
  // Owned by views hierarchy.
  raw_ptr<FeaturePodIconButton> icon_button_ = nullptr;
  raw_ptr<views::Label> label_ = nullptr;
  raw_ptr<views::Label> sub_label_ = nullptr;

  // Enabled color of the sub label.
  SkColor sub_label_color_;
};

}  // namespace ash

#endif  // ASH_SYSTEM_PHONEHUB_QUICK_ACTION_ITEM_H_