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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
ash / quick_insert / views / quick_insert_contents_view.cc [blame]
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/quick_insert/views/quick_insert_contents_view.h"
#include <limits>
#include <memory>
#include <optional>
#include <utility>
#include "ash/controls/rounded_scroll_bar.h"
#include "ash/quick_insert/views/quick_insert_style.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/compositor/layer.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/views/border.h"
#include "ui/views/controls/scroll_view.h"
#include "ui/views/controls/scrollbar/scroll_bar.h"
#include "ui/views/layout/box_layout_view.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/layout/layout_types.h"
#include "ui/views/view_class_properties.h"
namespace ash {
namespace {
gfx::Insets GetScrollViewContentsBorderInsets(
QuickInsertLayoutType layout_type) {
switch (layout_type) {
case QuickInsertLayoutType::kMainResultsBelowSearchField:
return gfx::Insets::TLBR(0, 0, 8, 0);
case QuickInsertLayoutType::kMainResultsAboveSearchField:
return gfx::Insets::TLBR(8, 0, 8, 0);
}
}
gfx::Insets GetQuickInsertScrollBarInsets(QuickInsertLayoutType layout_type) {
switch (layout_type) {
case QuickInsertLayoutType::kMainResultsBelowSearchField:
return gfx::Insets::TLBR(1, 0, 12, 0);
case QuickInsertLayoutType::kMainResultsAboveSearchField:
return gfx::Insets::TLBR(12, 0, 1, 0);
}
}
// Scroll view to contain the main Quick Insert contents.
class QuickInsertScrollView : public views::ScrollView {
METADATA_HEADER(QuickInsertScrollView, views::ScrollView)
public:
QuickInsertScrollView()
: views::ScrollView(views::ScrollView::ScrollWithLayers::kEnabled) {
views::Builder<views::ScrollView>(this)
.ClipHeightTo(0, std::numeric_limits<int>::max())
.SetDrawOverflowIndicator(false)
.SetBackgroundColor(std::nullopt)
.SetHorizontalScrollBarMode(views::ScrollView::ScrollBarMode::kDisabled)
.BuildChildren();
}
QuickInsertScrollView(const QuickInsertScrollView&) = delete;
QuickInsertScrollView& operator=(const QuickInsertScrollView&) = delete;
~QuickInsertScrollView() override = default;
};
BEGIN_METADATA(QuickInsertScrollView)
END_METADATA
} // namespace
QuickInsertContentsView::QuickInsertContentsView(
QuickInsertLayoutType layout_type) {
SetLayoutManager(std::make_unique<views::FillLayout>());
auto* scroll_view = AddChildView(std::make_unique<QuickInsertScrollView>());
auto vertical_scroll_bar = std::make_unique<RoundedScrollBar>(
views::ScrollBar::Orientation::kVertical);
vertical_scroll_bar->SetInsets(GetQuickInsertScrollBarInsets(layout_type));
vertical_scroll_bar->SetAlwaysShowThumb(true);
scroll_view->SetVerticalScrollBar(std::move(vertical_scroll_bar));
page_container_ = scroll_view->SetContents(
views::Builder<views::BoxLayoutView>()
.SetOrientation(views::LayoutOrientation::kVertical)
.SetCrossAxisAlignment(views::LayoutAlignment::kStretch)
.SetInsideBorderInsets(GetScrollViewContentsBorderInsets(layout_type))
.Build());
}
QuickInsertContentsView::~QuickInsertContentsView() = default;
void QuickInsertContentsView::SetActivePage(views::View* view) {
for (views::View* child : page_container_->children()) {
child->SetVisible(child == view);
}
}
BEGIN_METADATA(QuickInsertContentsView)
END_METADATA
} // namespace ash