1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ash/system/tray/fixed_sized_scroll_view.h"
10 FixedSizedScrollView::FixedSizedScrollView() {
11 set_notify_enter_exit_on_child(true);
14 FixedSizedScrollView::~FixedSizedScrollView() {
17 void FixedSizedScrollView::SetContentsView(views::View
* view
) {
19 view
->SetBoundsRect(gfx::Rect(view
->GetPreferredSize()));
22 void FixedSizedScrollView::SetFixedSize(const gfx::Size
& size
) {
23 if (fixed_size_
== size
)
26 PreferredSizeChanged();
29 gfx::Size
FixedSizedScrollView::GetPreferredSize() {
30 gfx::Size size
= fixed_size_
.IsEmpty() ?
31 contents()->GetPreferredSize() : fixed_size_
;
32 gfx::Insets insets
= GetInsets();
33 size
.Enlarge(insets
.width(), insets
.height());
37 void FixedSizedScrollView::Layout() {
38 gfx::Rect bounds
= gfx::Rect(contents()->GetPreferredSize());
39 bounds
.set_width(std::max(0, width() - GetScrollBarWidth()));
40 contents()->SetBoundsRect(bounds
);
42 views::ScrollView::Layout();
43 if (!vertical_scroll_bar()->visible()) {
44 gfx::Rect bounds
= contents()->bounds();
45 bounds
.set_width(bounds
.width() + GetScrollBarWidth());
46 contents()->SetBoundsRect(bounds
);
50 void FixedSizedScrollView::OnBoundsChanged(const gfx::Rect
& previous_bounds
) {
51 gfx::Rect bounds
= gfx::Rect(contents()->GetPreferredSize());
52 bounds
.set_width(std::max(0, width() - GetScrollBarWidth()));
53 contents()->SetBoundsRect(bounds
);
56 void FixedSizedScrollView::OnPaintFocusBorder(gfx::Canvas
* canvas
) {
57 // Do not paint the focus border.
60 } // namespace internal