| OLD | NEW |
| (Empty) |
| 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/common/system/tray/fixed_sized_scroll_view.h" | |
| 6 | |
| 7 #include "ash/common/material_design/material_design_controller.h" | |
| 8 | |
| 9 namespace ash { | |
| 10 | |
| 11 namespace { | |
| 12 | |
| 13 bool UseMd() { | |
| 14 return MaterialDesignController::IsSystemTrayMenuMaterial(); | |
| 15 } | |
| 16 | |
| 17 } // namespace | |
| 18 | |
| 19 FixedSizedScrollView::FixedSizedScrollView() { | |
| 20 set_notify_enter_exit_on_child(true); | |
| 21 } | |
| 22 | |
| 23 FixedSizedScrollView::~FixedSizedScrollView() {} | |
| 24 | |
| 25 void FixedSizedScrollView::SetContentsView(views::View* view) { | |
| 26 SetContents(view); | |
| 27 if (!UseMd()) | |
| 28 view->SetBoundsRect(gfx::Rect(view->GetPreferredSize())); | |
| 29 } | |
| 30 | |
| 31 void FixedSizedScrollView::SetFixedSize(const gfx::Size& size) { | |
| 32 DCHECK(!UseMd()); | |
| 33 if (fixed_size_ == size) | |
| 34 return; | |
| 35 fixed_size_ = size; | |
| 36 PreferredSizeChanged(); | |
| 37 } | |
| 38 | |
| 39 void FixedSizedScrollView::set_fixed_size(const gfx::Size& size) { | |
| 40 DCHECK(!UseMd()); | |
| 41 fixed_size_ = size; | |
| 42 } | |
| 43 | |
| 44 gfx::Size FixedSizedScrollView::GetPreferredSize() const { | |
| 45 if (UseMd()) | |
| 46 return views::View::GetPreferredSize(); | |
| 47 | |
| 48 gfx::Size size = | |
| 49 fixed_size_.IsEmpty() ? contents()->GetPreferredSize() : fixed_size_; | |
| 50 gfx::Insets insets = GetInsets(); | |
| 51 size.Enlarge(insets.width(), insets.height()); | |
| 52 return size; | |
| 53 } | |
| 54 | |
| 55 void FixedSizedScrollView::Layout() { | |
| 56 if (UseMd()) | |
| 57 return views::ScrollView::Layout(); | |
| 58 | |
| 59 gfx::Rect bounds = gfx::Rect(contents()->GetPreferredSize()); | |
| 60 bounds.set_width(std::max(0, width() - GetScrollBarLayoutWidth())); | |
| 61 // Keep the origin of the contents unchanged so that the list will not scroll | |
| 62 // away from the current visible region user is viewing. ScrollView::Layout() | |
| 63 // will make sure the contents line up with its viewport properly if | |
| 64 // the contents moves out of the viewport region. | |
| 65 bounds.set_origin(contents()->origin()); | |
| 66 contents()->SetBoundsRect(bounds); | |
| 67 | |
| 68 views::ScrollView::Layout(); | |
| 69 if (!vertical_scroll_bar()->visible()) { | |
| 70 gfx::Rect bounds = contents()->bounds(); | |
| 71 bounds.set_width(bounds.width() + GetScrollBarLayoutWidth()); | |
| 72 contents()->SetBoundsRect(bounds); | |
| 73 } | |
| 74 } | |
| 75 | |
| 76 void FixedSizedScrollView::OnBoundsChanged(const gfx::Rect& previous_bounds) { | |
| 77 if (UseMd()) | |
| 78 return; | |
| 79 | |
| 80 gfx::Rect bounds = gfx::Rect(contents()->GetPreferredSize()); | |
| 81 bounds.set_width(std::max(0, width() - GetScrollBarLayoutWidth())); | |
| 82 contents()->SetBoundsRect(bounds); | |
| 83 } | |
| 84 | |
| 85 } // namespace ash | |
| OLD | NEW |