capture_mode_source_view.cc 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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_source_view.h"
  5. #include <memory>
  6. #include "ash/capture_mode/capture_mode_constants.h"
  7. #include "ash/capture_mode/capture_mode_controller.h"
  8. #include "ash/capture_mode/capture_mode_metrics.h"
  9. #include "ash/capture_mode/capture_mode_toggle_button.h"
  10. #include "ash/resources/vector_icons/vector_icons.h"
  11. #include "ash/strings/grit/ash_strings.h"
  12. #include "base/bind.h"
  13. #include "ui/base/l10n/l10n_util.h"
  14. #include "ui/base/metadata/metadata_impl_macros.h"
  15. #include "ui/views/layout/box_layout.h"
  16. namespace ash {
  17. CaptureModeSourceView::CaptureModeSourceView()
  18. : fullscreen_toggle_button_(
  19. AddChildView(std::make_unique<CaptureModeToggleButton>(
  20. base::BindRepeating(&CaptureModeSourceView::OnFullscreenToggle,
  21. base::Unretained(this)),
  22. kCaptureModeFullscreenIcon))),
  23. region_toggle_button_(
  24. AddChildView(std::make_unique<CaptureModeToggleButton>(
  25. base::BindRepeating(&CaptureModeSourceView::OnRegionToggle,
  26. base::Unretained(this)),
  27. kCaptureModeRegionIcon))),
  28. window_toggle_button_(
  29. AddChildView(std::make_unique<CaptureModeToggleButton>(
  30. base::BindRepeating(&CaptureModeSourceView::OnWindowToggle,
  31. base::Unretained(this)),
  32. kCaptureModeWindowIcon))) {
  33. auto* box_layout = SetLayoutManager(std::make_unique<views::BoxLayout>(
  34. views::BoxLayout::Orientation::kHorizontal, gfx::Insets(),
  35. capture_mode::kBetweenChildSpacing));
  36. box_layout->set_cross_axis_alignment(
  37. views::BoxLayout::CrossAxisAlignment::kCenter);
  38. auto* controller = CaptureModeController::Get();
  39. OnCaptureSourceChanged(controller->source());
  40. OnCaptureTypeChanged(controller->type());
  41. }
  42. CaptureModeSourceView::~CaptureModeSourceView() = default;
  43. void CaptureModeSourceView::OnCaptureSourceChanged(
  44. CaptureModeSource new_source) {
  45. fullscreen_toggle_button_->SetToggled(new_source ==
  46. CaptureModeSource::kFullscreen);
  47. region_toggle_button_->SetToggled(new_source == CaptureModeSource::kRegion);
  48. window_toggle_button_->SetToggled(new_source == CaptureModeSource::kWindow);
  49. }
  50. void CaptureModeSourceView::OnCaptureTypeChanged(CaptureModeType new_type) {
  51. const bool is_capturing_image = new_type == CaptureModeType::kImage;
  52. fullscreen_toggle_button_->SetTooltipText(l10n_util::GetStringUTF16(
  53. is_capturing_image ? IDS_ASH_SCREEN_CAPTURE_TOOLTIP_FULLSCREEN_SCREENSHOT
  54. : IDS_ASH_SCREEN_CAPTURE_TOOLTIP_FULLSCREEN_RECORD));
  55. region_toggle_button_->SetTooltipText(l10n_util::GetStringUTF16(
  56. is_capturing_image ? IDS_ASH_SCREEN_CAPTURE_TOOLTIP_REGION_SCREENSHOT
  57. : IDS_ASH_SCREEN_CAPTURE_TOOLTIP_REGION_RECORD));
  58. window_toggle_button_->SetTooltipText(l10n_util::GetStringUTF16(
  59. is_capturing_image ? IDS_ASH_SCREEN_CAPTURE_TOOLTIP_WINDOW_SCREENSHOT
  60. : IDS_ASH_SCREEN_CAPTURE_TOOLTIP_WINDOW_RECORD));
  61. }
  62. void CaptureModeSourceView::OnFullscreenToggle() {
  63. RecordCaptureModeBarButtonType(CaptureModeBarButtonType::kFull);
  64. CaptureModeController::Get()->SetSource(CaptureModeSource::kFullscreen);
  65. }
  66. void CaptureModeSourceView::OnRegionToggle() {
  67. RecordCaptureModeBarButtonType(CaptureModeBarButtonType::kRegion);
  68. CaptureModeController::Get()->SetSource(CaptureModeSource::kRegion);
  69. }
  70. void CaptureModeSourceView::OnWindowToggle() {
  71. RecordCaptureModeBarButtonType(CaptureModeBarButtonType::kWindow);
  72. CaptureModeController::Get()->SetSource(CaptureModeSource::kWindow);
  73. }
  74. BEGIN_METADATA(CaptureModeSourceView, views::View)
  75. END_METADATA
  76. } // namespace ash