File: quick_settings_view.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 (141 lines) | stat: -rw-r--r-- 4,906 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
132
133
134
135
136
137
138
139
140
141
// 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_VIEW_H_
#define ASH_SYSTEM_UNIFIED_QUICK_SETTINGS_VIEW_H_

#include "ash/ash_export.h"
#include "ash/public/cpp/pagination/pagination_model_observer.h"
#include "ash/system/brightness/unified_brightness_view.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/views/view_utils.h"

namespace views {
class FlexLayoutView;
}  // namespace views

namespace ash {

class FeatureTile;
class FeatureTilesContainerView;
class PaginationView;
class QuickSettingsFooter;
class QuickSettingsHeader;
class QuickSettingsMediaViewContainer;
class UnifiedSystemTrayController;

// View class of the bubble in status area tray.
//
// The `QuickSettingsView` contains the quick settings controls
class ASH_EXPORT QuickSettingsView : public views::View,
                                     public PaginationModelObserver {
  METADATA_HEADER(QuickSettingsView, views::View)

 public:
  explicit QuickSettingsView(UnifiedSystemTrayController* controller);

  QuickSettingsView(const QuickSettingsView&) = delete;
  QuickSettingsView& operator=(const QuickSettingsView&) = delete;

  ~QuickSettingsView() override;

  // Sets the maximum height that the view can take.
  void SetMaxHeight(int max_height);

  // Adds tiles to the FeatureTile container view.
  void AddTiles(std::vector<std::unique_ptr<FeatureTile>> tiles);

  // Adds slider view.
  views::View* AddSliderView(std::unique_ptr<views::View> slider_view);

  // Adds media view to `media_view_container_`.
  void AddMediaView(std::unique_ptr<views::View> media_view);

  // Sets whether the quick settings view should show the media view.
  void SetShowMediaView(bool show_media_view);

  // Hides the main view and shows the given `detailed_view`.
  void SetDetailedView(std::unique_ptr<views::View> detailed_view);

  // Removes the detailed view set by SetDetailedView, and shows the main view.
  // It deletes `detailed_view` and children.
  void ResetDetailedView();

  // Saves and restores keyboard focus of the currently focused element. Called
  // before transitioning into a detailed view.
  void SaveFocus();
  void RestoreFocus();

  // Gets current height of the view (including the message center).
  int GetCurrentHeight() const;

  // Calculates how many rows to use based on the max available height.
  // FeatureTilesContainer can adjust it's height by reducing the number of rows
  // it uses.
  int CalculateHeightForFeatureTilesContainer();

  // Gets the accessible name for the currently shown detailed view.
  std::u16string GetDetailedViewAccessibleName() const;

  // Returns true if a detailed view is being shown in the tray. (e.g Bluetooth
  // Settings).
  bool IsDetailedViewShown() const;

  // PaginationModelObserver:
  void TotalPagesChanged(int previous_page_count, int new_page_count) override;

  FeatureTilesContainerView* feature_tiles_container() {
    return feature_tiles_container_;
  }
  views::View* detailed_view_container() { return detailed_view_container_; }

  // Returns the current tray detailed view.
  template <typename T>
  T* GetDetailedViewForTest() {
    CHECK(!detailed_view_container_->children().empty());
    views::View* view = detailed_view_container_->children()[0];
    CHECK(views::IsViewClass<T>(view));
    return static_cast<T*>(view);
  }

  PaginationView* pagination_view_for_test() { return pagination_view_; }

  QuickSettingsMediaViewContainer* media_view_container_for_testing() {
    return media_view_container_;
  }
  QuickSettingsHeader* header_for_testing() { return header_; }
  QuickSettingsFooter* footer_for_testing() { return footer_; }

  views::View* GetAccessibilityFocusHelperViewForTesting();

 private:
  class SystemTrayContainer;
  friend class UnifiedBrightnessViewTest;
  friend class UnifiedVolumeViewTest;

  // Owned by UnifiedSystemTrayBubble.
  const raw_ptr<UnifiedSystemTrayController> controller_;

  // Owned by views hierarchy.
  raw_ptr<views::FlexLayoutView> system_tray_container_ = nullptr;
  raw_ptr<QuickSettingsHeader> header_ = nullptr;
  raw_ptr<FeatureTilesContainerView> feature_tiles_container_ = nullptr;
  raw_ptr<PaginationView> pagination_view_ = nullptr;
  raw_ptr<views::FlexLayoutView> sliders_container_ = nullptr;
  raw_ptr<QuickSettingsFooter> footer_ = nullptr;
  raw_ptr<views::View> detailed_view_container_ = nullptr;
  raw_ptr<QuickSettingsMediaViewContainer> media_view_container_ = nullptr;

  // The maximum height available to the view.
  int max_height_ = 0;

  // The view that is saved by calling SaveFocus().
  raw_ptr<views::View> saved_focused_view_ = nullptr;

  const std::unique_ptr<ui::EventHandler> interacted_by_tap_recorder_;
};

}  // namespace ash

#endif  // ASH_SYSTEM_UNIFIED_QUICK_SETTINGS_VIEW_H_