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 namespace ash { | 7 namespace ash { |
8 | 8 |
9 FixedSizedScrollView::FixedSizedScrollView() { | 9 FixedSizedScrollView::FixedSizedScrollView() { |
10 set_notify_enter_exit_on_child(true); | 10 set_notify_enter_exit_on_child(true); |
11 } | 11 } |
12 | 12 |
13 FixedSizedScrollView::~FixedSizedScrollView() { | 13 FixedSizedScrollView::~FixedSizedScrollView() {} |
14 } | |
15 | 14 |
16 void FixedSizedScrollView::SetContentsView(views::View* view) { | 15 void FixedSizedScrollView::SetContentsView(views::View* view) { |
17 SetContents(view); | 16 SetContents(view); |
18 view->SetBoundsRect(gfx::Rect(view->GetPreferredSize())); | 17 view->SetBoundsRect(gfx::Rect(view->GetPreferredSize())); |
19 } | 18 } |
20 | 19 |
21 void FixedSizedScrollView::SetFixedSize(const gfx::Size& size) { | 20 void FixedSizedScrollView::SetFixedSize(const gfx::Size& size) { |
22 if (fixed_size_ == size) | 21 if (fixed_size_ == size) |
23 return; | 22 return; |
24 fixed_size_ = size; | 23 fixed_size_ = size; |
25 PreferredSizeChanged(); | 24 PreferredSizeChanged(); |
26 } | 25 } |
27 | 26 |
28 gfx::Size FixedSizedScrollView::GetPreferredSize() const { | 27 gfx::Size FixedSizedScrollView::GetPreferredSize() const { |
29 gfx::Size size = fixed_size_.IsEmpty() ? | 28 gfx::Size size = |
30 contents()->GetPreferredSize() : fixed_size_; | 29 fixed_size_.IsEmpty() ? contents()->GetPreferredSize() : fixed_size_; |
31 gfx::Insets insets = GetInsets(); | 30 gfx::Insets insets = GetInsets(); |
32 size.Enlarge(insets.width(), insets.height()); | 31 size.Enlarge(insets.width(), insets.height()); |
33 return size; | 32 return size; |
34 } | 33 } |
35 | 34 |
36 void FixedSizedScrollView::Layout() { | 35 void FixedSizedScrollView::Layout() { |
37 gfx::Rect bounds = gfx::Rect(contents()->GetPreferredSize()); | 36 gfx::Rect bounds = gfx::Rect(contents()->GetPreferredSize()); |
38 bounds.set_width(std::max(0, width() - GetScrollBarWidth())); | 37 bounds.set_width(std::max(0, width() - GetScrollBarWidth())); |
39 // Keep the origin of the contents unchanged so that the list will not scroll | 38 // Keep the origin of the contents unchanged so that the list will not scroll |
40 // away from the current visible region user is viewing. ScrollView::Layout() | 39 // away from the current visible region user is viewing. ScrollView::Layout() |
(...skipping 10 matching lines...) Expand all Loading... |
51 } | 50 } |
52 } | 51 } |
53 | 52 |
54 void FixedSizedScrollView::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 53 void FixedSizedScrollView::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
55 gfx::Rect bounds = gfx::Rect(contents()->GetPreferredSize()); | 54 gfx::Rect bounds = gfx::Rect(contents()->GetPreferredSize()); |
56 bounds.set_width(std::max(0, width() - GetScrollBarWidth())); | 55 bounds.set_width(std::max(0, width() - GetScrollBarWidth())); |
57 contents()->SetBoundsRect(bounds); | 56 contents()->SetBoundsRect(bounds); |
58 } | 57 } |
59 | 58 |
60 } // namespace ash | 59 } // namespace ash |
OLD | NEW |