capture_mode_ash_notification_view.cc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright 2021 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_ash_notification_view.h"
  5. #include "ash/capture_mode/capture_mode_util.h"
  6. #include "ash/public/cpp/assistant/assistant_state.h"
  7. #include "ash/shell.h"
  8. #include "ui/base/l10n/l10n_util.h"
  9. #include "ui/views/background.h"
  10. #include "ui/views/view.h"
  11. namespace ash {
  12. CaptureModeAshNotificationView::CaptureModeAshNotificationView(
  13. const message_center::Notification& notification,
  14. CaptureModeType capture_type,
  15. bool shown_in_popup)
  16. : AshNotificationView(notification, shown_in_popup),
  17. capture_type_(capture_type) {
  18. UpdateWithNotification(notification);
  19. }
  20. CaptureModeAshNotificationView::~CaptureModeAshNotificationView() = default;
  21. // static
  22. std::unique_ptr<message_center::MessageView>
  23. CaptureModeAshNotificationView::CreateForImage(
  24. const message_center::Notification& notification,
  25. bool shown_in_popup) {
  26. return std::make_unique<CaptureModeAshNotificationView>(
  27. notification, CaptureModeType::kImage, shown_in_popup);
  28. }
  29. // static
  30. std::unique_ptr<message_center::MessageView>
  31. CaptureModeAshNotificationView::CreateForVideo(
  32. const message_center::Notification& notification,
  33. bool shown_in_popup) {
  34. return std::make_unique<CaptureModeAshNotificationView>(
  35. notification, CaptureModeType::kVideo, shown_in_popup);
  36. }
  37. void CaptureModeAshNotificationView::UpdateWithNotification(
  38. const message_center::Notification& notification) {
  39. // Re-create a new extra view in all circumstances to make sure that the view
  40. // is the last child of image container.
  41. delete extra_view_;
  42. extra_view_ = nullptr;
  43. NotificationViewBase::UpdateWithNotification(notification);
  44. if (!notification.image().IsEmpty())
  45. CreateExtraView();
  46. }
  47. void CaptureModeAshNotificationView::Layout() {
  48. AshNotificationView::Layout();
  49. if (!extra_view_)
  50. return;
  51. gfx::Rect extra_view_bounds = image_container_view()->GetContentsBounds();
  52. if (capture_type_ == CaptureModeType::kImage) {
  53. // The extra view in this case is a banner laid out at the bottom of the
  54. // image container.
  55. extra_view_bounds.set_y(extra_view_bounds.bottom() -
  56. capture_mode_util::kBannerHeightDip);
  57. extra_view_bounds.set_height(capture_mode_util::kBannerHeightDip);
  58. } else {
  59. DCHECK_EQ(capture_type_, CaptureModeType::kVideo);
  60. // The extra view in this case is a play icon centered in the view.
  61. extra_view_bounds.ClampToCenteredSize(capture_mode_util::kPlayIconViewSize);
  62. }
  63. extra_view_->SetBoundsRect(extra_view_bounds);
  64. }
  65. void CaptureModeAshNotificationView::CreateExtraView() {
  66. DCHECK(image_container_view());
  67. DCHECK(!image_container_view()->children().empty());
  68. DCHECK(!extra_view_);
  69. extra_view_ = image_container_view()->AddChildView(
  70. capture_type_ == CaptureModeType::kImage
  71. ? capture_mode_util::CreateBannerView()
  72. : capture_mode_util::CreatePlayIconView());
  73. }
  74. } // namespace ash