OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "views/box_layout.h" | 5 #include "views/box_layout.h" |
6 | 6 |
7 namespace views { | 7 namespace views { |
8 | 8 |
9 BoxLayout::BoxLayout(BoxLayout::Orientation orientation, | 9 BoxLayout::BoxLayout(BoxLayout::Orientation orientation, |
10 int inside_border_spacing, | 10 int inside_border_horizontal_spacing, |
| 11 int inside_border_vertical_spacing, |
11 int between_child_spacing) | 12 int between_child_spacing) |
12 : orientation_(orientation), | 13 : orientation_(orientation), |
13 inside_border_spacing_(inside_border_spacing), | 14 inside_border_horizontal_spacing_(inside_border_horizontal_spacing), |
| 15 inside_border_vertical_spacing_(inside_border_vertical_spacing), |
14 between_child_spacing_(between_child_spacing) { | 16 between_child_spacing_(between_child_spacing) { |
15 } | 17 } |
16 | 18 |
17 void BoxLayout::Layout(View* host) { | 19 void BoxLayout::Layout(View* host) { |
18 gfx::Rect childArea(gfx::Rect(host->size())); | 20 gfx::Rect childArea(gfx::Rect(host->size())); |
19 childArea.Inset(host->GetInsets()); | 21 childArea.Inset(host->GetInsets()); |
20 childArea.Inset(inside_border_spacing_, inside_border_spacing_); | 22 childArea.Inset(inside_border_horizontal_spacing_, |
| 23 inside_border_vertical_spacing_); |
21 int x = childArea.x(); | 24 int x = childArea.x(); |
22 int y = childArea.y(); | 25 int y = childArea.y(); |
23 for (int i = 0; i < host->GetChildViewCount(); ++i) { | 26 for (int i = 0; i < host->GetChildViewCount(); ++i) { |
24 View* child = host->GetChildViewAt(i); | 27 View* child = host->GetChildViewAt(i); |
25 if (child->IsVisible()) { | 28 if (child->IsVisible()) { |
26 gfx::Rect bounds(x, y, childArea.width(), childArea.height()); | 29 gfx::Rect bounds(x, y, childArea.width(), childArea.height()); |
27 gfx::Size size(child->GetPreferredSize()); | 30 gfx::Size size(child->GetPreferredSize()); |
28 if (orientation_ == kHorizontal) { | 31 if (orientation_ == kHorizontal) { |
29 bounds.set_width(size.width()); | 32 bounds.set_width(size.width()); |
30 x += size.width() + between_child_spacing_; | 33 x += size.width() + between_child_spacing_; |
(...skipping 20 matching lines...) Expand all Loading... |
51 position += size.width(); | 54 position += size.width(); |
52 } else { | 55 } else { |
53 gfx::Rect child_bounds(0, position, size.width(), size.height()); | 56 gfx::Rect child_bounds(0, position, size.width(), size.height()); |
54 bounds = bounds.Union(child_bounds); | 57 bounds = bounds.Union(child_bounds); |
55 position += size.height(); | 58 position += size.height(); |
56 } | 59 } |
57 position += between_child_spacing_; | 60 position += between_child_spacing_; |
58 } | 61 } |
59 } | 62 } |
60 gfx::Insets insets(host->GetInsets()); | 63 gfx::Insets insets(host->GetInsets()); |
61 return | 64 return gfx::Size( |
62 gfx::Size(bounds.width() + insets.width() + 2 * inside_border_spacing_, | 65 bounds.width() + insets.width() + 2 * inside_border_horizontal_spacing_, |
63 bounds.height() + insets.height() + 2 * inside_border_spacing_); | 66 bounds.height() + insets.height() + 2 * inside_border_vertical_spacing_); |
64 } | 67 } |
65 | 68 |
66 } // namespace views | 69 } // namespace views |
OLD | NEW |