File: quick_settings_slider.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 (119 lines) | stat: -rw-r--r-- 4,421 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
// 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_SLIDER_H_
#define ASH_SYSTEM_UNIFIED_QUICK_SETTINGS_SLIDER_H_

#include "ash/ash_export.h"
#include "ui/views/controls/slider.h"

namespace gfx {
class Canvas;
}  // namespace gfx

namespace views {
class View;
}  // namespace views

namespace ui {
class Event;
}  // namespace ui

namespace ash {

// This slider view is used in quick settings in the status area. It will be
// used in the `QuickSettingsView` and `TrayBubbleView`. This slider view
// supports different styles. `kDefault` slider is used in `QuickSettingsView`
// and in `TrayBubbleView`. `kRadioActive` slider will be used for the active
// input/output device in `AudioDetailedView`. `kRadioInactive` slider will be
// used for the inactive device in `AudioDetailedView`.
class ASH_EXPORT QuickSettingsSlider : public views::Slider {
  METADATA_HEADER(QuickSettingsSlider, views::Slider)

 public:
  // Represents the style of the slider.
  enum class Style {
    // Represents the slider where the full part is a rounded corner rectangle
    // with a height of `kFullSliderThickness`, and the empty part is a rounded
    // corner rectangle with a height of `kEmptySliderThickness`. These two
    // parts are center-aligned horizontally. The ends of both parts have fully
    // rounded corners.
    kDefault,
    // Same style as `kDefault`, except for the thumb and trough are in gray for
    // the muted default sliders.
    kDefaultMuted,
    // Represents the style where both the full part and the empty part of the
    // slider have a height of `kFullSliderThickness`. The ends are fully
    // rounded.
    kRadioActive,
    // Same style as `kRadioActive`, except for the thumb and trough are in
    // gray for the muted radio sliders. Only the active radio sliders will have
    // the muted state.
    kRadioActiveMuted,
    // Represents the style where the full part and the empty part also have the
    // same height of `kFullSliderThickness`, except that the ends are not fully
    // rounded but have a radius of `kInactiveRadioSliderRoundedRadius`.
    kRadioInactive
  };

  QuickSettingsSlider(views::SliderListener* listener, Style slider_style);
  QuickSettingsSlider(const QuickSettingsSlider&) = delete;
  QuickSettingsSlider& operator=(const QuickSettingsSlider&) = delete;
  ~QuickSettingsSlider() override;

  // Setter and Getter of the slider style. Schedules paint after setting the
  // style since styles and colors may change for the radio sliders because of
  // the active status change. If the slider is the `kRadioInactive`, also
  // disables the focus behavior for it.
  void SetSliderStyle(Style style);
  Style slider_style() const { return slider_style_; }

  // Gets the bounds and rounded corner radius for `kRadioInactive` to draw the
  // focus ring around it in `AudioDetailedView`.
  gfx::Rect GetInactiveRadioSliderRect();
  int GetInactiveRadioSliderRoundedCornerRadius();

  void SetIsToggleableVolumeSlider(bool is_toggleable_volume_slider);

  bool is_toggleable_volume_slider() { return is_toggleable_volume_slider_; }

 private:
  // views::Slider:
  SkColor GetThumbColor() const override;
  SkColor GetTroughColor() const override;
  void AddedToWidget() override;
  void UpdateAccessibleValue() override;

  // views::View:
  void OnPaint(gfx::Canvas* canvas) override;
  void OnThemeChanged() override;

  // The style of the slider.
  Style slider_style_;

  // Indicates if the slider can be toggled to mute/unmute volume. Used for
  // additional accessibility warnings to make sure a user cannot accidentally
  // turn off volume.
  bool is_toggleable_volume_slider_ = false;
};

// A slider that ignores inputs. This will be used in the
// `UnifiedKeyboardBrightnessView` and `UnifiedKeyboardBacklightToggleView`.
class ASH_EXPORT ReadOnlySlider : public QuickSettingsSlider {
  METADATA_HEADER(ReadOnlySlider, QuickSettingsSlider)

 public:
  explicit ReadOnlySlider(Style slider_style);
  ReadOnlySlider(const ReadOnlySlider&) = delete;
  ReadOnlySlider& operator=(const ReadOnlySlider&) = delete;
  ~ReadOnlySlider() override;

 private:
  // views::View:
  bool CanAcceptEvent(const ui::Event& event) override;
};

}  // namespace ash

#endif  // ASH_SYSTEM_UNIFIED_QUICK_SETTINGS_SLIDER_H_