| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/common/system/tray/fixed_sized_scroll_view.h" | 5 #include "ash/common/system/tray/fixed_sized_scroll_view.h" |
| 6 | 6 |
| 7 #include "ash/common/material_design/material_design_controller.h" | 7 #include "ash/common/material_design/material_design_controller.h" |
| 8 #include "ui/views/background.h" | 8 #include "ui/views/background.h" |
| 9 #include "ui/views/controls/scrollbar/overlay_scroll_bar.h" | 9 #include "ui/views/controls/scrollbar/overlay_scroll_bar.h" |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 FixedSizedScrollView::FixedSizedScrollView() { | 21 FixedSizedScrollView::FixedSizedScrollView() { |
| 22 set_notify_enter_exit_on_child(true); | 22 set_notify_enter_exit_on_child(true); |
| 23 if (UseMd()) | 23 if (UseMd()) |
| 24 SetVerticalScrollBar(new views::OverlayScrollBar(false)); | 24 SetVerticalScrollBar(new views::OverlayScrollBar(false)); |
| 25 } | 25 } |
| 26 | 26 |
| 27 FixedSizedScrollView::~FixedSizedScrollView() {} | 27 FixedSizedScrollView::~FixedSizedScrollView() {} |
| 28 | 28 |
| 29 void FixedSizedScrollView::SetContentsView(views::View* view) { | 29 void FixedSizedScrollView::SetContentsView(views::View* view) { |
| 30 SetContents(view); | 30 SetContents(view); |
| 31 view->SetBoundsRect(gfx::Rect(view->GetPreferredSize())); | 31 if (!UseMd()) |
| 32 view->SetBoundsRect(gfx::Rect(view->GetPreferredSize())); |
| 32 } | 33 } |
| 33 | 34 |
| 34 void FixedSizedScrollView::SetFixedSize(const gfx::Size& size) { | 35 void FixedSizedScrollView::SetFixedSize(const gfx::Size& size) { |
| 35 DCHECK(!UseMd()); | 36 DCHECK(!UseMd()); |
| 36 if (fixed_size_ == size) | 37 if (fixed_size_ == size) |
| 37 return; | 38 return; |
| 38 fixed_size_ = size; | 39 fixed_size_ = size; |
| 39 PreferredSizeChanged(); | 40 PreferredSizeChanged(); |
| 40 } | 41 } |
| 41 | 42 |
| 42 void FixedSizedScrollView::set_fixed_size(const gfx::Size& size) { | 43 void FixedSizedScrollView::set_fixed_size(const gfx::Size& size) { |
| 43 DCHECK(!UseMd()); | 44 DCHECK(!UseMd()); |
| 44 fixed_size_ = size; | 45 fixed_size_ = size; |
| 45 } | 46 } |
| 46 | 47 |
| 47 gfx::Size FixedSizedScrollView::GetPreferredSize() const { | 48 gfx::Size FixedSizedScrollView::GetPreferredSize() const { |
| 49 if (UseMd()) |
| 50 return views::View::GetPreferredSize(); |
| 51 |
| 48 gfx::Size size = | 52 gfx::Size size = |
| 49 fixed_size_.IsEmpty() ? contents()->GetPreferredSize() : fixed_size_; | 53 fixed_size_.IsEmpty() ? contents()->GetPreferredSize() : fixed_size_; |
| 50 gfx::Insets insets = GetInsets(); | 54 gfx::Insets insets = GetInsets(); |
| 51 size.Enlarge(insets.width(), insets.height()); | 55 size.Enlarge(insets.width(), insets.height()); |
| 52 return size; | 56 return size; |
| 53 } | 57 } |
| 54 | 58 |
| 55 void FixedSizedScrollView::Layout() { | 59 void FixedSizedScrollView::Layout() { |
| 56 if (UseMd()) { | 60 if (UseMd()) |
| 57 views::ScrollView::Layout(); | 61 return views::ScrollView::Layout(); |
| 58 return; | |
| 59 } | |
| 60 | 62 |
| 61 gfx::Rect bounds = gfx::Rect(contents()->GetPreferredSize()); | 63 gfx::Rect bounds = gfx::Rect(contents()->GetPreferredSize()); |
| 62 bounds.set_width(std::max(0, width() - GetScrollBarWidth())); | 64 bounds.set_width(std::max(0, width() - GetScrollBarWidth())); |
| 63 // Keep the origin of the contents unchanged so that the list will not scroll | 65 // Keep the origin of the contents unchanged so that the list will not scroll |
| 64 // away from the current visible region user is viewing. ScrollView::Layout() | 66 // away from the current visible region user is viewing. ScrollView::Layout() |
| 65 // will make sure the contents line up with its viewport properly if | 67 // will make sure the contents line up with its viewport properly if |
| 66 // the contents moves out of the viewport region. | 68 // the contents moves out of the viewport region. |
| 67 bounds.set_origin(contents()->bounds().origin()); | 69 bounds.set_origin(contents()->bounds().origin()); |
| 68 contents()->SetBoundsRect(bounds); | 70 contents()->SetBoundsRect(bounds); |
| 69 | 71 |
| 70 views::ScrollView::Layout(); | 72 views::ScrollView::Layout(); |
| 71 if (!vertical_scroll_bar()->visible()) { | 73 if (!vertical_scroll_bar()->visible()) { |
| 72 gfx::Rect bounds = contents()->bounds(); | 74 gfx::Rect bounds = contents()->bounds(); |
| 73 bounds.set_width(bounds.width() + GetScrollBarWidth()); | 75 bounds.set_width(bounds.width() + GetScrollBarWidth()); |
| 74 contents()->SetBoundsRect(bounds); | 76 contents()->SetBoundsRect(bounds); |
| 75 } | 77 } |
| 76 } | 78 } |
| 77 | 79 |
| 78 void FixedSizedScrollView::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 80 void FixedSizedScrollView::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
| 79 if (UseMd()) | 81 if (UseMd()) |
| 80 return; | 82 return; |
| 81 | 83 |
| 82 gfx::Rect bounds = gfx::Rect(contents()->GetPreferredSize()); | 84 gfx::Rect bounds = gfx::Rect(contents()->GetPreferredSize()); |
| 83 bounds.set_width(std::max(0, width() - GetScrollBarWidth())); | 85 bounds.set_width(std::max(0, width() - GetScrollBarWidth())); |
| 84 contents()->SetBoundsRect(bounds); | 86 contents()->SetBoundsRect(bounds); |
| 85 } | 87 } |
| 86 | 88 |
| 87 } // namespace ash | 89 } // namespace ash |
| OLD | NEW |