blob: a3539f9975d72c7314baa0e063df3426b0a77d68 (
plain)
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
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/tray/fixed_sized_scroll_view.h"
namespace ash {
FixedSizedScrollView::FixedSizedScrollView() {
set_notify_enter_exit_on_child(true);
}
FixedSizedScrollView::~FixedSizedScrollView() {
}
void FixedSizedScrollView::SetContentsView(views::View* view) {
SetContents(view);
view->SetBoundsRect(gfx::Rect(view->GetPreferredSize()));
}
void FixedSizedScrollView::SetFixedSize(const gfx::Size& size) {
if (fixed_size_ == size)
return;
fixed_size_ = size;
PreferredSizeChanged();
}
gfx::Size FixedSizedScrollView::GetPreferredSize() const {
gfx::Size size = fixed_size_.IsEmpty() ?
contents()->GetPreferredSize() : fixed_size_;
gfx::Insets insets = GetInsets();
size.Enlarge(insets.width(), insets.height());
return size;
}
void FixedSizedScrollView::Layout() {
gfx::Rect bounds = gfx::Rect(contents()->GetPreferredSize());
bounds.set_width(std::max(0, width() - GetScrollBarWidth()));
// Keep the origin of the contents unchanged so that the list will not scroll
// away from the current visible region user is viewing. ScrollView::Layout()
// will make sure the contents line up with its viewport properly if
// the contents moves out of the viewport region.
bounds.set_origin(contents()->bounds().origin());
contents()->SetBoundsRect(bounds);
views::ScrollView::Layout();
if (!vertical_scroll_bar()->visible()) {
gfx::Rect bounds = contents()->bounds();
bounds.set_width(bounds.width() + GetScrollBarWidth());
contents()->SetBoundsRect(bounds);
}
}
void FixedSizedScrollView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
gfx::Rect bounds = gfx::Rect(contents()->GetPreferredSize());
bounds.set_width(std::max(0, width() - GetScrollBarWidth()));
contents()->SetBoundsRect(bounds);
}
} // namespace ash
|