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
ash / assistant / ui / base / assistant_scroll_view.cc [blame]
// Copyright 2018 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/assistant/ui/base/assistant_scroll_view.h"
#include <memory>
#include <optional>
#include <utility>
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/views/controls/scroll_view.h"
#include "ui/views/controls/scrollbar/overlay_scroll_bar.h"
#include "ui/views/view.h"
namespace ash {
namespace {
// ContentView ----------------------------------------------------------------
class ContentView : public views::View, views::ViewObserver {
METADATA_HEADER(ContentView, views::View)
public:
ContentView() { AddObserver(this); }
ContentView(const ContentView&) = delete;
ContentView& operator=(const ContentView&) = delete;
~ContentView() override { RemoveObserver(this); }
// views::View:
void ChildPreferredSizeChanged(views::View* child) override {
PreferredSizeChanged();
}
void ChildVisibilityChanged(views::View* child) override {
PreferredSizeChanged();
}
// views::ViewObserver:
void OnChildViewAdded(views::View* view, views::View* child) override {
PreferredSizeChanged();
}
void OnChildViewRemoved(views::View* view, views::View* child) override {
PreferredSizeChanged();
}
};
BEGIN_METADATA(ContentView)
END_METADATA
} // namespace
// AssistantScrollView ---------------------------------------------------------
AssistantScrollView::AssistantScrollView() {
InitLayout();
}
AssistantScrollView::~AssistantScrollView() = default;
void AssistantScrollView::OnViewPreferredSizeChanged(views::View* view) {
DCHECK_EQ(content_view(), view);
for (auto& observer : observers_)
observer.OnContentsPreferredSizeChanged(content_view());
PreferredSizeChanged();
}
void AssistantScrollView::AddScrollViewObserver(Observer* observer) {
observers_.AddObserver(observer);
}
void AssistantScrollView::RemoveScrollViewObserver(Observer* observer) {
observers_.RemoveObserver(observer);
}
void AssistantScrollView::InitLayout() {
SetBackgroundColor(std::nullopt);
SetDrawOverflowIndicator(false);
// Content view.
content_view_observation_.Observe(
SetContents(std::make_unique<ContentView>()));
// Scroll bars.
SetVerticalScrollBarMode(views::ScrollView::ScrollBarMode::kHiddenButEnabled);
SetHorizontalScrollBarMode(
views::ScrollView::ScrollBarMode::kHiddenButEnabled);
}
BEGIN_METADATA(AssistantScrollView)
END_METADATA
} // namespace ash