Home | History | Annotate | Download | only in tray
      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 
      7 namespace ash {
      8 namespace internal {
      9 
     10 FixedSizedScrollView::FixedSizedScrollView() {
     11   set_notify_enter_exit_on_child(true);
     12 }
     13 
     14 FixedSizedScrollView::~FixedSizedScrollView() {
     15 }
     16 
     17 void FixedSizedScrollView::SetContentsView(views::View* view) {
     18   SetContents(view);
     19   view->SetBoundsRect(gfx::Rect(view->GetPreferredSize()));
     20 }
     21 
     22 void FixedSizedScrollView::SetFixedSize(const gfx::Size& size) {
     23   if (fixed_size_ == size)
     24     return;
     25   fixed_size_ = size;
     26   PreferredSizeChanged();
     27 }
     28 
     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());
     34   return size;
     35 }
     36 
     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);
     41 
     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);
     47   }
     48 }
     49 
     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);
     54 }
     55 
     56 void FixedSizedScrollView::OnPaintFocusBorder(gfx::Canvas* canvas) {
     57   // Do not paint the focus border.
     58 }
     59 
     60 }  // namespace internal
     61 }  // namespace ash
     62