File: quick_settings_footer.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (131 lines) | stat: -rw-r--r-- 4,531 bytes parent folder | download | duplicates (6)
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
// 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_UNIFIED_QUICK_SETTINGS_FOOTER_H_
#define ASH_SYSTEM_UNIFIED_QUICK_SETTINGS_FOOTER_H_

#include "ash/ash_export.h"
#include "ash/style/pill_button.h"
#include "ash/system/power/power_status.h"
#include "ash/system/unified/power_button.h"
#include "base/memory/raw_ptr.h"
#include "components/prefs/pref_change_registrar.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/views/view.h"

class PrefRegistrySimple;

namespace ash {

class IconButton;
class PillButton;
class UnifiedSystemTrayController;

// A base class for both `QsBatteryLabelView` and `QsBatteryIconView`. This view
// is a Jellyroll `PillButton` component that has a different icon label spacing
// and right padding than `BatteryInfoViewBase`. It updates by observing
// `PowerStatus`.
class ASH_EXPORT QsBatteryInfoViewBase : public PillButton,
                                         public PowerStatus::Observer {
  METADATA_HEADER(QsBatteryInfoViewBase, PillButton)

 public:
  explicit QsBatteryInfoViewBase(UnifiedSystemTrayController* controller,
                                 const Type type = Type::kFloatingWithoutIcon,
                                 gfx::VectorIcon* icon = nullptr);
  QsBatteryInfoViewBase(const QsBatteryInfoViewBase&) = delete;
  QsBatteryInfoViewBase& operator=(const QsBatteryInfoViewBase&) = delete;
  ~QsBatteryInfoViewBase() override;

  // Updates the subclass view's ui including button text/background color, text
  // content, icons, etc.It can be applied to changes such as theme change,
  // power status change,etc.
  virtual void Update() = 0;
  // Updates battery icon and text with battery saver mode check.
  void UpdateIconAndText(bool bsm_active = false);
  // Builds the battery icon image.
  void ConfigureIcon(bool bsm_active = false);

 private:
  void ChildPreferredSizeChanged(views::View* child) override;
  void ChildVisibilityChanged(views::View* child) override;

  // PowerStatus::Observer:
  void OnPowerStatusChanged() override;

  // PillButton:
  void OnThemeChanged() override;
};

// A view that shows battery status.
class ASH_EXPORT QsBatteryLabelView : public QsBatteryInfoViewBase {
  METADATA_HEADER(QsBatteryLabelView, QsBatteryInfoViewBase)

 public:
  explicit QsBatteryLabelView(UnifiedSystemTrayController* controller);
  QsBatteryLabelView(const QsBatteryLabelView&) = delete;
  QsBatteryLabelView& operator=(const QsBatteryLabelView&) = delete;
  ~QsBatteryLabelView() override;

 private:
  // QsBatteryInfoViewBase:
  void Update() override;
};

// A view that shows battery icon and charging state when smart charging is
// enabled.
class ASH_EXPORT QsBatteryIconView : public QsBatteryInfoViewBase {
  METADATA_HEADER(QsBatteryIconView, QsBatteryInfoViewBase)

 public:
  explicit QsBatteryIconView(UnifiedSystemTrayController* controller);
  QsBatteryIconView(const QsBatteryIconView&) = delete;
  QsBatteryIconView& operator=(const QsBatteryIconView&) = delete;
  ~QsBatteryIconView() override;

 private:
  // QsBatteryInfoViewBase:
  void Update() override;
};

// The footer view shown on the the bottom of the `QuickSettingsView`.
class ASH_EXPORT QuickSettingsFooter : public views::View {
  METADATA_HEADER(QuickSettingsFooter, views::View)

 public:
  explicit QuickSettingsFooter(UnifiedSystemTrayController* controller);
  QuickSettingsFooter(const QuickSettingsFooter&) = delete;
  QuickSettingsFooter& operator=(const QuickSettingsFooter&) = delete;
  ~QuickSettingsFooter() override;

  // Registers preferences used by this class in the provided `registry`.
  static void RegisterLocalStatePrefs(PrefRegistrySimple* registry);

  PowerButton* power_button_for_testing() { return power_button_; }

 private:
  friend class QuickSettingsFooterTest;

  // Disables/Enables the `settings_button_` based on `kSettingsIconEnabled`
  // pref.
  void UpdateSettingsButtonState();

  // Creates the container to carry the battery and settings button if there's
  // any.
  views::View* CreateEndContainer();

  // Owned.
  raw_ptr<IconButton> settings_button_ = nullptr;

  // Owned by views hierarchy.
  raw_ptr<PowerButton> power_button_ = nullptr;
  raw_ptr<PillButton> sign_out_button_ = nullptr;

  // The registrar used to watch prefs changes.
  PrefChangeRegistrar local_state_pref_change_registrar_;
};

}  // namespace ash

#endif  // ASH_SYSTEM_UNIFIED_QUICK_SETTINGS_FOOTER_H_