1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86

ash / system / phonehub / camera_roll_view.h [blame]

// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_SYSTEM_PHONEHUB_CAMERA_ROLL_VIEW_H_
#define ASH_SYSTEM_PHONEHUB_CAMERA_ROLL_VIEW_H_

#include "ash/ash_export.h"
#include "base/gtest_prod_util.h"
#include "base/memory/raw_ptr.h"
#include "chromeos/ash/components/phonehub/camera_roll_manager.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/views/view.h"
#include "ui/views/view_model.h"

namespace ash {

namespace phonehub {
class UserActionRecorder;
}

// A view in Phone Hub bubble that allows user view and access recently taken
// photos and videos from a connected device.
// Contains the header and one or more lines of clickable thumbnails.
// This view will automatically hide if no Camera Roll items are available.
class ASH_EXPORT CameraRollView : public views::View,
                                  public phonehub::CameraRollManager::Observer {
  METADATA_HEADER(CameraRollView, views::View)

 public:
  CameraRollView(phonehub::CameraRollManager* camera_roll_manager,
                 phonehub::UserActionRecorder* user_action_recorder);
  ~CameraRollView() override;
  CameraRollView(CameraRollView&) = delete;
  CameraRollView operator=(CameraRollView&) = delete;

  // phonehub::CameraRollManager::Observer:
  void OnCameraRollViewUiStateUpdated() override;

 private:
  friend class CameraRollViewTest;
  FRIEND_TEST_ALL_PREFIXES(CameraRollViewTest, OptInAlready);
  FRIEND_TEST_ALL_PREFIXES(CameraRollViewTest, ViewLayout);
  FRIEND_TEST_ALL_PREFIXES(CameraRollViewTest, ImageThumbnail);
  FRIEND_TEST_ALL_PREFIXES(CameraRollViewTest, VideoThumbnail);

  class CameraRollItemsView : public views::View {
    METADATA_HEADER(CameraRollItemsView, views::View)

   public:
    CameraRollItemsView();
    ~CameraRollItemsView() override;
    CameraRollItemsView(CameraRollItemsView&) = delete;
    CameraRollItemsView operator=(CameraRollItemsView&) = delete;

    void AddCameraRollItem(views::View* camera_roll_item);
    void Reset();

    // views::View:
    gfx::Size CalculatePreferredSize(
        const views::SizeBounds& available_size) const override;
    void Layout(PassKey) override;

   private:
    FRIEND_TEST_ALL_PREFIXES(CameraRollViewTest, ViewLayout);
    FRIEND_TEST_ALL_PREFIXES(CameraRollViewTest, ImageThumbnail);
    FRIEND_TEST_ALL_PREFIXES(CameraRollViewTest, VideoThumbnail);

    gfx::Point GetCameraRollItemPosition(int index);
    void CalculateIdealBounds();

    views::ViewModelT<views::View> camera_roll_items_;
  };

  // Update the camera roll section to display the latest items.
  void Update();

  raw_ptr<phonehub::CameraRollManager> camera_roll_manager_ = nullptr;
  raw_ptr<phonehub::UserActionRecorder> user_action_recorder_ = nullptr;
  raw_ptr<CameraRollItemsView> items_view_ = nullptr;
  bool content_present_metric_emitted_ = false;
};

}  // namespace ash

#endif  // ASH_SYSTEM_PHONEHUB_CAMERA_ROLL_VIEW_H_