capture_mode_bar_view.cc 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/capture_mode/capture_mode_bar_view.h"
  5. #include <memory>
  6. #include "ash/capture_mode/capture_mode_button.h"
  7. #include "ash/capture_mode/capture_mode_constants.h"
  8. #include "ash/capture_mode/capture_mode_controller.h"
  9. #include "ash/capture_mode/capture_mode_metrics.h"
  10. #include "ash/capture_mode/capture_mode_session.h"
  11. #include "ash/capture_mode/capture_mode_source_view.h"
  12. #include "ash/capture_mode/capture_mode_toggle_button.h"
  13. #include "ash/capture_mode/capture_mode_type_view.h"
  14. #include "ash/constants/ash_features.h"
  15. #include "ash/public/cpp/style/color_provider.h"
  16. #include "ash/resources/vector_icons/vector_icons.h"
  17. #include "ash/shelf/shelf.h"
  18. #include "ash/shelf/shelf_layout_manager.h"
  19. #include "ash/strings/grit/ash_strings.h"
  20. #include "ash/style/ash_color_provider.h"
  21. #include "ash/style/system_shadow.h"
  22. #include "base/bind.h"
  23. #include "ui/aura/window.h"
  24. #include "ui/base/l10n/l10n_util.h"
  25. #include "ui/base/metadata/metadata_impl_macros.h"
  26. #include "ui/color/color_id.h"
  27. #include "ui/compositor/layer.h"
  28. #include "ui/gfx/geometry/size.h"
  29. #include "ui/gfx/paint_vector_icon.h"
  30. #include "ui/strings/grit/ui_strings.h"
  31. #include "ui/views/background.h"
  32. #include "ui/views/controls/separator.h"
  33. #include "ui/views/highlight_border.h"
  34. #include "ui/views/layout/box_layout.h"
  35. #include "ui/views/style/platform_style.h"
  36. namespace ash {
  37. namespace {
  38. // Full size of capture mode bar view, the width of which will be
  39. // adjusted in projector mode.
  40. constexpr gfx::Size kFullBarSize{376, 64};
  41. constexpr auto kBarPadding = gfx::Insets::VH(14, 16);
  42. constexpr int kBorderRadius = 20;
  43. constexpr int kSeparatorHeight = 20;
  44. // Distance from the bottom of the bar to the bottom of the display, top of the
  45. // hotseat or top of the shelf depending on the shelf alignment or hotseat
  46. // visibility.
  47. constexpr int kDistanceFromShelfOrHotseatTopDp = 16;
  48. } // namespace
  49. CaptureModeBarView::CaptureModeBarView(bool projector_mode)
  50. : capture_type_view_(
  51. AddChildView(std::make_unique<CaptureModeTypeView>(projector_mode))),
  52. separator_1_(AddChildView(std::make_unique<views::Separator>())),
  53. capture_source_view_(
  54. AddChildView(std::make_unique<CaptureModeSourceView>())),
  55. separator_2_(AddChildView(std::make_unique<views::Separator>())),
  56. settings_button_(AddChildView(std::make_unique<CaptureModeToggleButton>(
  57. base::BindRepeating(&CaptureModeBarView::OnSettingsButtonPressed,
  58. base::Unretained(this)),
  59. kCaptureModeSettingsIcon))),
  60. close_button_(AddChildView(std::make_unique<CaptureModeButton>(
  61. base::BindRepeating(&CaptureModeBarView::OnCloseButtonPressed,
  62. base::Unretained(this)),
  63. kCaptureModeCloseIcon))),
  64. shadow_(SystemShadow::CreateShadowOnNinePatchLayerForView(
  65. this,
  66. SystemShadow::Type::kElevation12)) {
  67. SetPaintToLayer();
  68. auto* color_provider = AshColorProvider::Get();
  69. SkColor background_color = color_provider->GetBaseLayerColor(
  70. AshColorProvider::BaseLayerType::kTransparent80);
  71. SetBackground(views::CreateSolidBackground(background_color));
  72. layer()->SetFillsBoundsOpaquely(false);
  73. layer()->SetRoundedCornerRadius(gfx::RoundedCornersF(kBorderRadius));
  74. layer()->SetBackgroundBlur(ColorProvider::kBackgroundBlurSigma);
  75. layer()->SetBackdropFilterQuality(ColorProvider::kBackgroundBlurQuality);
  76. auto* box_layout = SetLayoutManager(std::make_unique<views::BoxLayout>(
  77. views::BoxLayout::Orientation::kHorizontal, kBarPadding,
  78. capture_mode::kBetweenChildSpacing));
  79. box_layout->set_cross_axis_alignment(
  80. views::BoxLayout::CrossAxisAlignment::kCenter);
  81. // Custom styling for the settings button, which has a dark background and a
  82. // light colored icon when selected.
  83. const auto normal_icon = gfx::CreateVectorIcon(
  84. kCaptureModeSettingsIcon,
  85. color_provider->GetContentLayerColor(
  86. AshColorProvider::ContentLayerType::kButtonIconColor));
  87. settings_button_->SetToggledImage(views::Button::STATE_NORMAL, &normal_icon);
  88. settings_button_->set_toggled_background_color(
  89. color_provider->GetControlsLayerColor(
  90. AshColorProvider::ControlsLayerType::
  91. kControlBackgroundColorInactive));
  92. settings_button_->SetTooltipText(
  93. l10n_util::GetStringUTF16(IDS_ASH_SCREEN_CAPTURE_TOOLTIP_SETTINGS));
  94. separator_1_->SetColorId(ui::kColorAshSystemUIMenuSeparator);
  95. separator_1_->SetPreferredLength(kSeparatorHeight);
  96. separator_2_->SetColorId(ui::kColorAshSystemUIMenuSeparator);
  97. separator_2_->SetPreferredLength(kSeparatorHeight);
  98. close_button_->SetTooltipText(
  99. l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE));
  100. if (features::IsDarkLightModeEnabled()) {
  101. SetBorder(std::make_unique<views::HighlightBorder>(
  102. kBorderRadius, views::HighlightBorder::Type::kHighlightBorder2,
  103. /*use_light_colors=*/false));
  104. }
  105. shadow_->SetRoundedCornerRadius(kBorderRadius);
  106. }
  107. CaptureModeBarView::~CaptureModeBarView() = default;
  108. // static
  109. gfx::Rect CaptureModeBarView::GetBounds(aura::Window* root,
  110. bool is_in_projector_mode) {
  111. DCHECK(root);
  112. auto bounds = root->GetBoundsInScreen();
  113. int bar_y = bounds.bottom();
  114. Shelf* shelf = Shelf::ForWindow(root);
  115. if (shelf->IsHorizontalAlignment()) {
  116. // Get the widget which has the shelf icons. This is the hotseat widget if
  117. // the hotseat is extended, shelf widget otherwise.
  118. const bool hotseat_extended =
  119. shelf->shelf_layout_manager()->hotseat_state() ==
  120. HotseatState::kExtended;
  121. views::Widget* shelf_widget =
  122. hotseat_extended ? static_cast<views::Widget*>(shelf->hotseat_widget())
  123. : static_cast<views::Widget*>(shelf->shelf_widget());
  124. bar_y = shelf_widget->GetWindowBoundsInScreen().y();
  125. }
  126. gfx::Size bar_size = kFullBarSize;
  127. if (is_in_projector_mode) {
  128. bar_size.set_width(kFullBarSize.width() -
  129. capture_mode::kButtonSize.width() -
  130. capture_mode::kSpaceBetweenCaptureModeTypeButtons);
  131. }
  132. bar_y -= (kDistanceFromShelfOrHotseatTopDp + bar_size.height());
  133. bounds.ClampToCenteredSize(bar_size);
  134. bounds.set_y(bar_y);
  135. return bounds;
  136. }
  137. void CaptureModeBarView::OnCaptureSourceChanged(CaptureModeSource new_source) {
  138. capture_source_view_->OnCaptureSourceChanged(new_source);
  139. }
  140. void CaptureModeBarView::OnCaptureTypeChanged(CaptureModeType new_type) {
  141. capture_type_view_->OnCaptureTypeChanged(new_type);
  142. capture_source_view_->OnCaptureTypeChanged(new_type);
  143. }
  144. void CaptureModeBarView::SetSettingsMenuShown(bool shown) {
  145. settings_button_->SetToggled(shown);
  146. }
  147. void CaptureModeBarView::OnSettingsButtonPressed() {
  148. CaptureModeController::Get()->capture_mode_session()->SetSettingsMenuShown(
  149. !settings_button_->GetToggled());
  150. }
  151. void CaptureModeBarView::OnCloseButtonPressed() {
  152. RecordCaptureModeBarButtonType(CaptureModeBarButtonType::kExit);
  153. CaptureModeController::Get()->Stop();
  154. }
  155. BEGIN_METADATA(CaptureModeBarView, views::View)
  156. END_METADATA
  157. } // namespace ash