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

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

// Copyright 2020 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_TASK_CONTINUATION_VIEW_H_
#define ASH_SYSTEM_PHONEHUB_TASK_CONTINUATION_VIEW_H_

#include "ash/ash_export.h"
#include "base/gtest_prod_util.h"
#include "base/memory/raw_ptr.h"
#include "chromeos/ash/components/phonehub/phone_model.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 to pick up unfinished task left
// off from their phone, currently only support web browsing.
class ASH_EXPORT TaskContinuationView : public views::View,
                                        public phonehub::PhoneModel::Observer {
  METADATA_HEADER(TaskContinuationView, views::View)

 public:
  TaskContinuationView(phonehub::PhoneModel* phone_model,
                       phonehub::UserActionRecorder* user_action_recorder);
  ~TaskContinuationView() override;
  TaskContinuationView(TaskContinuationView&) = delete;
  TaskContinuationView operator=(TaskContinuationView&) = delete;

  // phonehub::PhoneHubModel::Observer:
  void OnModelChanged() override;

 private:
  FRIEND_TEST_ALL_PREFIXES(TaskContinuationViewTest, TaskChipsView);

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

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

    void AddTaskChip(views::View* task_chip);

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

    // Clear all existing tasks in the view and in |task_chips_|.
    void Reset();

   private:
    gfx::Point GetButtonPosition(int index);
    void CalculateIdealBounds();

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

  // Update the chips to display current phone status.
  void Update();

  raw_ptr<phonehub::PhoneModel> phone_model_ = nullptr;
  raw_ptr<phonehub::UserActionRecorder> user_action_recorder_ = nullptr;
  raw_ptr<TaskChipsView> chips_view_ = nullptr;
};

}  // namespace ash

#endif  // ASH_SYSTEM_PHONEHUB_TASK_CONTINUATION_VIEW_H_