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. 4 5#include "ash/system/tray/fixed_sized_scroll_view.h" 6 7namespace ash { 8 9FixedSizedScrollView::FixedSizedScrollView() { 10 set_notify_enter_exit_on_child(true); 11} 12 13FixedSizedScrollView::~FixedSizedScrollView() { 14} 15 16void FixedSizedScrollView::SetContentsView(views::View* view) { 17 SetContents(view); 18 view->SetBoundsRect(gfx::Rect(view->GetPreferredSize())); 19} 20 21void FixedSizedScrollView::SetFixedSize(const gfx::Size& size) { 22 if (fixed_size_ == size) 23 return; 24 fixed_size_ = size; 25 PreferredSizeChanged(); 26} 27 28gfx::Size FixedSizedScrollView::GetPreferredSize() const { 29 gfx::Size size = fixed_size_.IsEmpty() ? 30 contents()->GetPreferredSize() : fixed_size_; 31 gfx::Insets insets = GetInsets(); 32 size.Enlarge(insets.width(), insets.height()); 33 return size; 34} 35 36void FixedSizedScrollView::Layout() { 37 gfx::Rect bounds = gfx::Rect(contents()->GetPreferredSize()); 38 bounds.set_width(std::max(0, width() - GetScrollBarWidth())); 39 contents()->SetBoundsRect(bounds); 40 41 views::ScrollView::Layout(); 42 if (!vertical_scroll_bar()->visible()) { 43 gfx::Rect bounds = contents()->bounds(); 44 bounds.set_width(bounds.width() + GetScrollBarWidth()); 45 contents()->SetBoundsRect(bounds); 46 } 47} 48 49void FixedSizedScrollView::OnBoundsChanged(const gfx::Rect& previous_bounds) { 50 gfx::Rect bounds = gfx::Rect(contents()->GetPreferredSize()); 51 bounds.set_width(std::max(0, width() - GetScrollBarWidth())); 52 contents()->SetBoundsRect(bounds); 53} 54 55} // namespace ash 56