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
ash / wm / window_restore / informed_restore_contents_view.h [blame]
// Copyright 2023 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_WM_WINDOW_RESTORE_INFORMED_RESTORE_CONTENTS_VIEW_H_
#define ASH_WM_WINDOW_RESTORE_INFORMED_RESTORE_CONTENTS_VIEW_H_
#include <memory>
#include <string>
#include <vector>
#include "ash/ash_export.h"
#include "base/callback_list.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/views/layout/box_layout_view.h"
#include "ui/views/widget/widget.h"
namespace views {
class ImageButton;
class MenuModelAdapter;
class MenuRunner;
} // namespace views
namespace ash {
class InformedRestoreContextMenuModel;
// TODO(http://b/337339184): Change the layout when the display orientation
// changes.
class ASH_EXPORT InformedRestoreContentsView : public views::BoxLayoutView {
METADATA_HEADER(InformedRestoreContentsView, views::BoxLayoutView)
public:
InformedRestoreContentsView();
InformedRestoreContentsView(const InformedRestoreContentsView&) = delete;
InformedRestoreContentsView& operator=(const InformedRestoreContentsView&)
= delete;
~InformedRestoreContentsView() override;
static std::unique_ptr<views::Widget> Create(
const gfx::Rect& grid_bounds_in_screen);
// Removes all child views and remakes them in the correct orientation.
void UpdateOrientation();
// Update the contents of list view or the icon row of screenshot preview with
// the updated contents data.
void UpdateContents();
// Update the preferred width for the container which contains the restore,
// cancel and settings button. Its preferred width is smaller if the screen
// size is too small.
void UpdatePrimaryContainerPreferredWidth(aura::Window* root_window,
std::optional<bool> is_landscape);
private:
FRIEND_TEST_ALL_PREFIXES(InformedRestoreContextMenuModelTest,
ShowContextMenuOnSettingsButtonClicked);
// Callbacks for the buttons on the dialog.
void OnRestoreButtonPressed();
void OnCancelButtonPressed();
void OnSettingsButtonPressed();
// Creates a builder for the settings button that opens up a context menu.
views::Builder<views::ImageButton> CreateSettingsButtonBuilder();
// Creates a builder for the container of the "No thanks" and "Restore" pill
// buttons.
views::Builder<views::BoxLayoutView> CreateButtonContainerBuilder();
// Creates the child views based on the primary display orientation.
void CreateChildViews();
// Called when the pine context menu is closed. Used as a callback for
// `menu_model_adapter_`.
void OnMenuClosed();
void UpdateIconRowClipArea();
// views::View:
void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
// The context menu model and its adapter for `settings_button_view_`.
std::unique_ptr<InformedRestoreContextMenuModel> context_menu_model_;
std::unique_ptr<views::MenuModelAdapter> menu_model_adapter_;
// The menu runner that is responsible for the context menu.
std::unique_ptr<views::MenuRunner> menu_runner_;
// Container for the restore, cancel and settings button.
raw_ptr<views::BoxLayoutView> primary_container_view_;
raw_ptr<views::ImageButton> settings_button_ = nullptr;
// The container of the items list view or screenshot.
raw_ptr<views::BoxLayoutView> preview_container_view_;
// The items list containing the titles and icons of the items to be restored.
raw_ptr<views::View> items_container_view_;
// Contents of the preview when showing the screenshot.
raw_ptr<views::View> image_view_;
raw_ptr<views::BoxLayoutView> icon_row_container_;
raw_ptr<views::View> screenshot_icon_row_view_;
// Time `this` was created. Used for metrics.
const base::TimeTicks creation_time_;
bool showing_list_view_ = true;
bool close_metric_recorded_ = false;
base::CallbackListSubscription contents_data_updated_subscription_;
base::WeakPtrFactory<InformedRestoreContentsView> weak_ptr_factory_{this};
};
BEGIN_VIEW_BUILDER(/* no export */,
InformedRestoreContentsView,
views::BoxLayoutView)
END_VIEW_BUILDER
} // namespace ash
DEFINE_VIEW_BUILDER(/* no export */, ash::InformedRestoreContentsView)
#endif // ASH_WM_WINDOW_RESTORE_INFORMED_RESTORE_CONTENTS_VIEW_H_