1 // Copyright 2019 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 
5 #ifndef ASH_AMBIENT_UI_PHOTO_VIEW_H_
6 #define ASH_AMBIENT_UI_PHOTO_VIEW_H_
7 
8 #include <memory>
9 
10 #include "ash/ambient/model/ambient_backend_model_observer.h"
11 #include "ash/ambient/ui/ambient_background_image_view.h"
12 #include "ash/ash_export.h"
13 #include "base/macros.h"
14 #include "ui/compositor/layer_animation_observer.h"
15 #include "ui/views/view.h"
16 
17 namespace gfx {
18 class ImageSkia;
19 }  // namespace gfx
20 
21 namespace ash {
22 
23 class AmbientBackgroundImageView;
24 class AmbientViewDelegate;
25 struct PhotoWithDetails;
26 
27 // View to display photos in ambient mode.
28 class ASH_EXPORT PhotoView : public views::View,
29                              public AmbientBackendModelObserver,
30                              public ui::ImplicitAnimationObserver {
31  public:
32   explicit PhotoView(AmbientViewDelegate* delegate);
33   PhotoView(const PhotoView&) = delete;
34   PhotoView& operator=(PhotoView&) = delete;
35   ~PhotoView() override;
36 
37   // views::View:
38   const char* GetClassName() const override;
39 
40   // AmbientBackendModelObserver:
41   void OnImagesChanged() override;
42 
43   // ui::ImplicitAnimationObserver:
44   void OnImplicitAnimationsCompleted() override;
45 
46  private:
47   friend class AmbientAshTestBase;
48 
49   void Init();
50 
51   void UpdateImage(const PhotoWithDetails& image);
52 
53   void StartTransitionAnimation();
54 
55   // Return if can start transition animation.
56   bool NeedToAnimateTransition() const;
57 
58   const gfx::ImageSkia& GetCurrentImagesForTesting();
59 
60   // Note that we should be careful when using |delegate_|, as there is no
61   // strong guarantee on the life cycle.
62   AmbientViewDelegate* const delegate_ = nullptr;
63 
64   // Image containers used for animation. Owned by view hierarchy.
65   AmbientBackgroundImageView* image_views_[2]{nullptr, nullptr};
66 
67   // The index of |image_views_| to update the next image.
68   int image_index_ = 0;
69 };
70 
71 }  // namespace ash
72 
73 #endif  // ASH_AMBIENT_UI_PHOTO_VIEW_H_
74