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

ash / quick_insert / views / quick_insert_main_container_view.h [blame]

// Copyright 2024 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_QUICK_INSERT_VIEWS_QUICK_INSERT_MAIN_CONTAINER_VIEW_H_
#define ASH_QUICK_INSERT_VIEWS_QUICK_INSERT_MAIN_CONTAINER_VIEW_H_

#include <memory>
#include <utility>

#include "ash/ash_export.h"
#include "ash/quick_insert/views/quick_insert_contents_view.h"
#include "ash/quick_insert/views/quick_insert_traversable_item_container.h"
#include "base/memory/raw_ptr.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/views/view.h"

namespace ash {

enum class QuickInsertLayoutType;
class QuickInsertSearchFieldView;
class QuickInsertPageView;
class SystemShadow;

// View for the main Quick Insert container, which consists of the search field
// and the main contents (e.g. search results page).
class ASH_EXPORT QuickInsertMainContainerView
    : public views::View,
      public QuickInsertTraversableItemContainer {
  METADATA_HEADER(QuickInsertMainContainerView, views::View)

 public:
  QuickInsertMainContainerView();
  QuickInsertMainContainerView(const QuickInsertMainContainerView&) = delete;
  QuickInsertMainContainerView& operator=(const QuickInsertMainContainerView&) =
      delete;
  ~QuickInsertMainContainerView() override;

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

  // QuickInsertTraversableItemContainer:
  views::View* GetTopItem() override;
  views::View* GetBottomItem() override;
  views::View* GetItemAbove(views::View* item) override;
  views::View* GetItemBelow(views::View* item) override;
  views::View* GetItemLeftOf(views::View* item) override;
  views::View* GetItemRightOf(views::View* item) override;
  bool ContainsItem(views::View* item) override;

  QuickInsertSearchFieldView* AddSearchFieldView(
      std::unique_ptr<QuickInsertSearchFieldView> search_field_view);

  // Creates and adds the contents view, which will contain the main contents of
  // the container (e.g. search results page).
  QuickInsertContentsView* AddContentsView(QuickInsertLayoutType layout_type);

  template <typename T>
  T* AddPage(std::unique_ptr<T> view) {
    return contents_view_->AddPage(std::move(view));
  }

  QuickInsertPageView* active_page() { return active_page_; }
  void SetActivePage(QuickInsertPageView* page_view);

 private:
  std::unique_ptr<SystemShadow> shadow_;

  raw_ptr<QuickInsertSearchFieldView> search_field_view_ = nullptr;
  raw_ptr<QuickInsertContentsView> contents_view_ = nullptr;

  // The currently visible page of `contents_view_`, or nullptr if there is no
  // such page.
  raw_ptr<QuickInsertPageView> active_page_ = nullptr;
};

}  // namespace ash

#endif  // ASH_QUICK_INSERT_VIEWS_QUICK_INSERT_MAIN_CONTAINER_VIEW_H_