forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcapture_mode_bar_view.cc
161 lines (134 loc) · 6.14 KB
/
capture_mode_bar_view.cc
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/capture_mode/capture_mode_bar_view.h"
#include <memory>
#include "ash/capture_mode/capture_mode_button.h"
#include "ash/capture_mode/capture_mode_constants.h"
#include "ash/capture_mode/capture_mode_controller.h"
#include "ash/capture_mode/capture_mode_metrics.h"
#include "ash/capture_mode/capture_mode_session.h"
#include "ash/capture_mode/capture_mode_source_view.h"
#include "ash/capture_mode/capture_mode_toggle_button.h"
#include "ash/capture_mode/capture_mode_type_view.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_layout_manager.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/style/ash_color_provider.h"
#include "base/bind.h"
#include "ui/aura/window.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/strings/grit/ui_strings.h"
#include "ui/views/background.h"
#include "ui/views/controls/separator.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/metadata/metadata_impl_macros.h"
#include "ui/views/style/platform_style.h"
namespace ash {
namespace {
constexpr gfx::Size kBarSize{376, 64};
constexpr gfx::Insets kBarPadding{/*vertical=*/14, /*horizontal=*/16};
constexpr gfx::RoundedCornersF kBorderRadius{20.f};
constexpr int kSeparatorHeight = 20;
// Distance from the bottom of the bar to the bottom of the display, top of the
// hotseat or top of the shelf depending on the shelf alignment or hotseat
// visibility.
constexpr int kDistanceFromShelfOrHotseatTopDp = 16;
} // namespace
CaptureModeBarView::CaptureModeBarView()
: capture_type_view_(AddChildView(std::make_unique<CaptureModeTypeView>())),
separator_1_(AddChildView(std::make_unique<views::Separator>())),
capture_source_view_(
AddChildView(std::make_unique<CaptureModeSourceView>())),
separator_2_(AddChildView(std::make_unique<views::Separator>())),
settings_button_(AddChildView(std::make_unique<CaptureModeToggleButton>(
base::BindRepeating(&CaptureModeBarView::OnSettingsButtonPressed,
base::Unretained(this)),
kCaptureModeSettingsIcon))),
close_button_(AddChildView(std::make_unique<CaptureModeButton>(
base::BindRepeating(&CaptureModeBarView::OnCloseButtonPressed,
base::Unretained(this)),
kCaptureModeCloseIcon))) {
SetPaintToLayer();
auto* color_provider = AshColorProvider::Get();
SkColor background_color = color_provider->GetBaseLayerColor(
AshColorProvider::BaseLayerType::kTransparent80);
SetBackground(views::CreateSolidBackground(background_color));
layer()->SetFillsBoundsOpaquely(false);
layer()->SetRoundedCornerRadius(kBorderRadius);
layer()->SetBackgroundBlur(
static_cast<float>(AshColorProvider::LayerBlurSigma::kBlurDefault));
layer()->SetBackdropFilterQuality(capture_mode::kBlurQuality);
auto* box_layout = SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal, kBarPadding,
capture_mode::kBetweenChildSpacing));
box_layout->set_cross_axis_alignment(
views::BoxLayout::CrossAxisAlignment::kCenter);
// Custom styling for the settings button, which has a dark background and a
// light colored icon when selected.
const auto normal_icon = gfx::CreateVectorIcon(
kCaptureModeSettingsIcon,
color_provider->GetContentLayerColor(
AshColorProvider::ContentLayerType::kButtonIconColor));
settings_button_->SetToggledImage(views::Button::STATE_NORMAL, &normal_icon);
settings_button_->set_toggled_background_color(
color_provider->GetControlsLayerColor(
AshColorProvider::ControlsLayerType::
kControlBackgroundColorInactive));
settings_button_->SetTooltipText(
l10n_util::GetStringUTF16(IDS_ASH_SCREEN_CAPTURE_TOOLTIP_SETTINGS));
const SkColor separator_color = color_provider->GetContentLayerColor(
AshColorProvider::ContentLayerType::kSeparatorColor);
separator_1_->SetColor(separator_color);
separator_1_->SetPreferredHeight(kSeparatorHeight);
separator_2_->SetColor(separator_color);
separator_2_->SetPreferredHeight(kSeparatorHeight);
close_button_->SetTooltipText(
l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE));
}
CaptureModeBarView::~CaptureModeBarView() = default;
// static
gfx::Rect CaptureModeBarView::GetBounds(aura::Window* root) {
DCHECK(root);
auto bounds = root->GetBoundsInScreen();
int bar_y = bounds.bottom();
Shelf* shelf = Shelf::ForWindow(root);
if (shelf->IsHorizontalAlignment()) {
// Get the widget which has the shelf icons. This is the hotseat widget if
// the hotseat is extended, shelf widget otherwise.
const bool hotseat_extended =
shelf->shelf_layout_manager()->hotseat_state() ==
HotseatState::kExtended;
views::Widget* shelf_widget =
hotseat_extended ? static_cast<views::Widget*>(shelf->hotseat_widget())
: static_cast<views::Widget*>(shelf->shelf_widget());
bar_y = shelf_widget->GetWindowBoundsInScreen().y();
}
bar_y -= (kDistanceFromShelfOrHotseatTopDp + kBarSize.height());
bounds.ClampToCenteredSize(kBarSize);
bounds.set_y(bar_y);
return bounds;
}
void CaptureModeBarView::OnCaptureSourceChanged(CaptureModeSource new_source) {
capture_source_view_->OnCaptureSourceChanged(new_source);
}
void CaptureModeBarView::OnCaptureTypeChanged(CaptureModeType new_type) {
capture_type_view_->OnCaptureTypeChanged(new_type);
capture_source_view_->OnCaptureTypeChanged(new_type);
}
void CaptureModeBarView::SetSettingsMenuShown(bool shown) {
settings_button_->SetToggled(shown);
}
void CaptureModeBarView::OnSettingsButtonPressed() {
CaptureModeController::Get()->capture_mode_session()->SetSettingsMenuShown(
!settings_button_->GetToggled());
}
void CaptureModeBarView::OnCloseButtonPressed() {
RecordCaptureModeBarButtonType(CaptureModeBarButtonType::kExit);
CaptureModeController::Get()->Stop();
}
BEGIN_METADATA(CaptureModeBarView, views::View)
END_METADATA
} // namespace ash