OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/layout/box_layout.h" | 5 #include "views/layout/box_layout.h" |
6 | 6 |
7 #include "ui/gfx/insets.h" | 7 #include "ui/gfx/insets.h" |
8 #include "ui/gfx/rect.h" | 8 #include "ui/gfx/rect.h" |
9 #include "views/view.h" | 9 #include "views/view.h" |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... |
25 | 25 |
26 void BoxLayout::Layout(View* host) { | 26 void BoxLayout::Layout(View* host) { |
27 gfx::Rect child_area(host->GetLocalBounds()); | 27 gfx::Rect child_area(host->GetLocalBounds()); |
28 child_area.Inset(host->GetInsets()); | 28 child_area.Inset(host->GetInsets()); |
29 child_area.Inset(inside_border_horizontal_spacing_, | 29 child_area.Inset(inside_border_horizontal_spacing_, |
30 inside_border_vertical_spacing_); | 30 inside_border_vertical_spacing_); |
31 int x = child_area.x(); | 31 int x = child_area.x(); |
32 int y = child_area.y(); | 32 int y = child_area.y(); |
33 for (int i = 0; i < host->child_count(); ++i) { | 33 for (int i = 0; i < host->child_count(); ++i) { |
34 View* child = host->GetChildViewAt(i); | 34 View* child = host->GetChildViewAt(i); |
35 if (child->IsVisible()) { | 35 if (child->visible()) { |
36 gfx::Rect bounds(x, y, child_area.width(), child_area.height()); | 36 gfx::Rect bounds(x, y, child_area.width(), child_area.height()); |
37 gfx::Size size(child->GetPreferredSize()); | 37 gfx::Size size(child->GetPreferredSize()); |
38 if (orientation_ == kHorizontal) { | 38 if (orientation_ == kHorizontal) { |
39 bounds.set_width(size.width()); | 39 bounds.set_width(size.width()); |
40 x += size.width() + between_child_spacing_; | 40 x += size.width() + between_child_spacing_; |
41 } else { | 41 } else { |
42 bounds.set_height(size.height()); | 42 bounds.set_height(size.height()); |
43 y += size.height() + between_child_spacing_; | 43 y += size.height() + between_child_spacing_; |
44 } | 44 } |
45 // Clamp child view bounds to |child_area|. | 45 // Clamp child view bounds to |child_area|. |
46 child->SetBoundsRect(bounds.Intersect(child_area)); | 46 child->SetBoundsRect(bounds.Intersect(child_area)); |
47 } | 47 } |
48 } | 48 } |
49 } | 49 } |
50 | 50 |
51 gfx::Size BoxLayout::GetPreferredSize(View* host) { | 51 gfx::Size BoxLayout::GetPreferredSize(View* host) { |
52 gfx::Rect bounds; | 52 gfx::Rect bounds; |
53 int position = 0; | 53 int position = 0; |
54 for (int i = 0; i < host->child_count(); ++i) { | 54 for (int i = 0; i < host->child_count(); ++i) { |
55 View* child = host->GetChildViewAt(i); | 55 View* child = host->GetChildViewAt(i); |
56 if (child->IsVisible()) { | 56 if (child->visible()) { |
57 gfx::Size size(child->GetPreferredSize()); | 57 gfx::Size size(child->GetPreferredSize()); |
58 if (orientation_ == kHorizontal) { | 58 if (orientation_ == kHorizontal) { |
59 gfx::Rect child_bounds(position, 0, size.width(), size.height()); | 59 gfx::Rect child_bounds(position, 0, size.width(), size.height()); |
60 bounds = bounds.Union(child_bounds); | 60 bounds = bounds.Union(child_bounds); |
61 position += size.width(); | 61 position += size.width(); |
62 } else { | 62 } else { |
63 gfx::Rect child_bounds(0, position, size.width(), size.height()); | 63 gfx::Rect child_bounds(0, position, size.width(), size.height()); |
64 bounds = bounds.Union(child_bounds); | 64 bounds = bounds.Union(child_bounds); |
65 position += size.height(); | 65 position += size.height(); |
66 } | 66 } |
67 position += between_child_spacing_; | 67 position += between_child_spacing_; |
68 } | 68 } |
69 } | 69 } |
70 gfx::Insets insets(host->GetInsets()); | 70 gfx::Insets insets(host->GetInsets()); |
71 return gfx::Size( | 71 return gfx::Size( |
72 bounds.width() + insets.width() + 2 * inside_border_horizontal_spacing_, | 72 bounds.width() + insets.width() + 2 * inside_border_horizontal_spacing_, |
73 bounds.height() + insets.height() + 2 * inside_border_vertical_spacing_); | 73 bounds.height() + insets.height() + 2 * inside_border_vertical_spacing_); |
74 } | 74 } |
75 | 75 |
76 } // namespace views | 76 } // namespace views |
OLD | NEW |