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
ash / style / style_viewer / system_ui_components_style_viewer_view.h [blame]
// 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_STYLE_STYLE_VIEWER_SYSTEM_UI_COMPONENTS_STYLE_VIEWER_VIEW_H_
#define ASH_STYLE_STYLE_VIEWER_SYSTEM_UI_COMPONENTS_STYLE_VIEWER_VIEW_H_
#include <string>
#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/views/widget/widget_delegate.h"
#include "ui/views/widget/widget_observer.h"
#include "ui/views/window/client_view.h"
namespace views {
class ScrollView;
class ClientView;
class Widget;
} // namespace views
namespace ash {
class SystemUIComponentsGridView;
// SystemUIComponentsStyleViewerView is the client view of the system components
// style viewer. It has two parts: (1) the menu scroll view contains a list of
// component buttons which can toggle the component instances, (2) the component
// instances scroll view lists the instances of current selected component. The
// layout is shown below:
// +----------------------+---------------------------------------+
// | Menu Scroll View | Component Instances Scroll View |
// | +------------------+ | |
// | | Component Button | | |
// | +------------------+ | |
// | | Component Button | | |
// | +------------------+ | |
// | | |
// +----------------------+---------------------------------------+
class SystemUIComponentsStyleViewerView : public views::WidgetDelegateView,
public views::WidgetObserver {
METADATA_HEADER(SystemUIComponentsStyleViewerView, views::WidgetDelegateView)
public:
// A view factory of `SystemUIComponentsGridView` that shows the UI component
// instances in a m x n grids.
using ComponentsGridViewFactory =
base::RepeatingCallback<std::unique_ptr<SystemUIComponentsGridView>(
void)>;
SystemUIComponentsStyleViewerView();
SystemUIComponentsStyleViewerView(const SystemUIComponentsStyleViewerView&) =
delete;
SystemUIComponentsStyleViewerView& operator=(
const SystemUIComponentsStyleViewerView&) = delete;
~SystemUIComponentsStyleViewerView() override;
// Creates a widget using the view as delegate and contents.
static void CreateAndShowWidget();
// Adds a new component with component name and grid view factory.
void AddComponent(const std::u16string& name,
ComponentsGridViewFactory grid_view_factory);
// Shows the instances of the UI component indicated by the given name.
void ShowComponentInstances(const std::u16string& name);
// views::WidgetDelegateView:
void Layout(PassKey) override;
std::u16string GetWindowTitle() const override;
views::ClientView* CreateClientView(views::Widget* widget) override;
// views::WidgetObserver:
void OnWidgetDestroyed(views::Widget* widget) override;
private:
// The button which is used to toggle the instances of corresponding
// component.
class ComponentButton;
// The scroll views.
raw_ptr<views::ScrollView> menu_scroll_view_;
raw_ptr<views::ScrollView> component_instances_scroll_view_;
// The contents of the scroll views.
raw_ptr<views::View> menu_contents_view_;
raw_ptr<views::View> components_grid_view_;
// Buttons used to toggle the component instances.
std::vector<raw_ptr<ComponentButton, VectorExperimental>> buttons_;
// Factories of `SystemUIComponentsGridView` for different
// UI components.
std::map<std::u16string, ComponentsGridViewFactory>
components_grid_view_factories_;
};
} // namespace ash
#endif // ASH_STYLE_STYLE_VIEWER_SYSTEM_UI_COMPONENTS_STYLE_VIEWER_VIEW_H_