ambient_background_image_view.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. #ifndef ASH_AMBIENT_UI_AMBIENT_BACKGROUND_IMAGE_VIEW_H_
  5. #define ASH_AMBIENT_UI_AMBIENT_BACKGROUND_IMAGE_VIEW_H_
  6. #include <string>
  7. #include "ash/ambient/ui/ambient_view_delegate.h"
  8. #include "ash/ash_export.h"
  9. #include "ash/public/cpp/ambient/ambient_backend_controller.h"
  10. #include "base/memory/raw_ptr.h"
  11. #include "base/scoped_multi_source_observation.h"
  12. #include "ui/base/metadata/metadata_header_macros.h"
  13. #include "ui/views/controls/image_view.h"
  14. #include "ui/views/layout/flex_layout.h"
  15. #include "ui/views/view.h"
  16. #include "ui/views/view_observer.h"
  17. namespace ash {
  18. class AmbientInfoView;
  19. class JitterCalculator;
  20. class MediaStringView;
  21. // AmbientBackgroundImageView--------------------------------------------------
  22. // A custom ImageView to display photo image and details information on ambient.
  23. // It also handles specific mouse/gesture events to dismiss ambient when user
  24. // interacts with the background photos.
  25. class ASH_EXPORT AmbientBackgroundImageView : public views::View,
  26. public views::ViewObserver {
  27. public:
  28. METADATA_HEADER(AmbientBackgroundImageView);
  29. AmbientBackgroundImageView(
  30. AmbientViewDelegate* delegate,
  31. JitterCalculator* glanceable_info_jitter_calculator);
  32. AmbientBackgroundImageView(const AmbientBackgroundImageView&) = delete;
  33. AmbientBackgroundImageView& operator=(const AmbientBackgroundImageView&) =
  34. delete;
  35. ~AmbientBackgroundImageView() override;
  36. // views::View:
  37. void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
  38. // views::ViewObserver:
  39. void OnViewBoundsChanged(views::View* observed_view) override;
  40. // Updates the display images.
  41. void UpdateImage(const gfx::ImageSkia& image,
  42. const gfx::ImageSkia& related_image,
  43. bool is_portrait,
  44. ::ambient::TopicType type);
  45. // Updates the details for the currently displayed image(s).
  46. void UpdateImageDetails(const std::u16string& details,
  47. const std::u16string& related_details);
  48. gfx::ImageSkia GetCurrentImage();
  49. gfx::Rect GetImageBoundsInScreenForTesting() const;
  50. gfx::Rect GetRelatedImageBoundsInScreenForTesting() const;
  51. void ResetRelatedImageForTesting();
  52. private:
  53. void InitLayout();
  54. void UpdateGlanceableInfoPosition();
  55. void UpdateLayout();
  56. bool UpdateRelatedImageViewVisibility();
  57. void SetResizedImage(views::ImageView* image_view,
  58. const gfx::ImageSkia& image_unscaled);
  59. // When show paired images:
  60. // 1. The device is in landscape mode and the images are portrait.
  61. // 2. The device is in portrait mode and the images are landscape.
  62. bool MustShowPairs() const;
  63. bool HasPairedImages() const;
  64. // Owned by |AmbientController| and should always outlive |this|.
  65. AmbientViewDelegate* delegate_ = nullptr;
  66. const base::raw_ptr<JitterCalculator> glanceable_info_jitter_calculator_;
  67. // View to display current image(s) on ambient. Owned by the view hierarchy.
  68. views::View* image_container_ = nullptr;
  69. views::FlexLayout* image_layout_ = nullptr;
  70. views::ImageView* image_view_ = nullptr;
  71. views::ImageView* related_image_view_ = nullptr;
  72. // The unscaled images used for scaling and displaying in different bounds.
  73. gfx::ImageSkia image_unscaled_;
  74. gfx::ImageSkia related_image_unscaled_;
  75. std::u16string details_;
  76. std::u16string related_details_;
  77. bool is_portrait_ = false;
  78. ::ambient::TopicType topic_type_ = ::ambient::TopicType::kOther;
  79. AmbientInfoView* ambient_info_view_ = nullptr;
  80. MediaStringView* media_string_view_ = nullptr;
  81. base::ScopedMultiSourceObservation<views::View, views::ViewObserver>
  82. observed_views_{this};
  83. };
  84. } // namespace ash
  85. #endif // ASH_AMBIENT_UI_AMBIENT_BACKGROUND_IMAGE_VIEW_H_