stop_recording_button_tray.cc 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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/stop_recording_button_tray.h"
  5. #include "ash/capture_mode/capture_mode_controller.h"
  6. #include "ash/capture_mode/capture_mode_metrics.h"
  7. #include "ash/public/cpp/shelf_config.h"
  8. #include "ash/resources/vector_icons/vector_icons.h"
  9. #include "ash/strings/grit/ash_strings.h"
  10. #include "ash/system/tray/tray_constants.h"
  11. #include "ash/system/tray/tray_container.h"
  12. #include "base/metrics/user_metrics.h"
  13. #include "base/metrics/user_metrics_action.h"
  14. #include "ui/base/l10n/l10n_util.h"
  15. #include "ui/gfx/paint_vector_icon.h"
  16. #include "ui/views/controls/image_view.h"
  17. namespace ash {
  18. StopRecordingButtonTray::StopRecordingButtonTray(Shelf* shelf)
  19. : TrayBackgroundView(shelf),
  20. image_view_(tray_container()->AddChildView(
  21. std::make_unique<views::ImageView>())) {
  22. image_view_->SetTooltipText(GetAccessibleNameForTray());
  23. image_view_->SetHorizontalAlignment(views::ImageView::Alignment::kCenter);
  24. image_view_->SetVerticalAlignment(views::ImageView::Alignment::kCenter);
  25. image_view_->SetPreferredSize(gfx::Size(kTrayItemSize, kTrayItemSize));
  26. }
  27. StopRecordingButtonTray::~StopRecordingButtonTray() = default;
  28. bool StopRecordingButtonTray::PerformAction(const ui::Event& event) {
  29. DCHECK(event.type() == ui::ET_MOUSE_RELEASED ||
  30. event.type() == ui::ET_GESTURE_TAP ||
  31. event.type() == ui::ET_KEY_PRESSED);
  32. base::RecordAction(base::UserMetricsAction("Tray_StopRecording"));
  33. CaptureModeController::Get()->EndVideoRecording(
  34. EndRecordingReason::kStopRecordingButton);
  35. return true;
  36. }
  37. std::u16string StopRecordingButtonTray::GetAccessibleNameForTray() {
  38. return l10n_util::GetStringUTF16(
  39. IDS_ASH_STATUS_AREA_STOP_RECORDING_BUTTON_ACCESSIBLE_NAME);
  40. }
  41. void StopRecordingButtonTray::OnThemeChanged() {
  42. TrayBackgroundView::OnThemeChanged();
  43. image_view_->SetImage(gfx::CreateVectorIcon(
  44. kCaptureModeCircleStopIcon,
  45. AshColorProvider::Get()->GetContentLayerColor(
  46. AshColorProvider::ContentLayerType::kIconColorAlert)));
  47. }
  48. } // namespace ash