OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/views/layout/box_layout.h" | 5 #include "ui/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 "ui/views/view.h" | 9 #include "ui/views/view.h" |
10 | 10 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 gfx::Rect bounds(x, y, child_area.width(), child_area.height()); | 65 gfx::Rect bounds(x, y, child_area.width(), child_area.height()); |
66 gfx::Size size(child->GetPreferredSize()); | 66 gfx::Size size(child->GetPreferredSize()); |
67 if (orientation_ == kHorizontal) { | 67 if (orientation_ == kHorizontal) { |
68 bounds.set_width(size.width() + padding); | 68 bounds.set_width(size.width() + padding); |
69 x += size.width() + between_child_spacing_ + padding; | 69 x += size.width() + between_child_spacing_ + padding; |
70 } else { | 70 } else { |
71 bounds.set_height(size.height() + padding); | 71 bounds.set_height(size.height() + padding); |
72 y += size.height() + between_child_spacing_ + padding; | 72 y += size.height() + between_child_spacing_ + padding; |
73 } | 73 } |
74 // Clamp child view bounds to |child_area|. | 74 // Clamp child view bounds to |child_area|. |
75 child->SetBoundsRect(bounds.Intersect(child_area)); | 75 bounds.Intersect(child_area); |
| 76 child->SetBoundsRect(bounds); |
76 } | 77 } |
77 } | 78 } |
78 } | 79 } |
79 | 80 |
80 gfx::Size BoxLayout::GetPreferredSize(View* host) { | 81 gfx::Size BoxLayout::GetPreferredSize(View* host) { |
81 gfx::Rect bounds; | 82 gfx::Rect bounds; |
82 int position = 0; | 83 int position = 0; |
83 for (int i = 0; i < host->child_count(); ++i) { | 84 for (int i = 0; i < host->child_count(); ++i) { |
84 View* child = host->child_at(i); | 85 View* child = host->child_at(i); |
85 if (child->visible()) { | 86 if (child->visible()) { |
86 gfx::Size size(child->GetPreferredSize()); | 87 gfx::Size size(child->GetPreferredSize()); |
87 if (orientation_ == kHorizontal) { | 88 if (orientation_ == kHorizontal) { |
88 gfx::Rect child_bounds(position, 0, size.width(), size.height()); | 89 gfx::Rect child_bounds(position, 0, size.width(), size.height()); |
89 bounds = bounds.Union(child_bounds); | 90 bounds.Union(child_bounds); |
90 position += size.width(); | 91 position += size.width(); |
91 } else { | 92 } else { |
92 gfx::Rect child_bounds(0, position, size.width(), size.height()); | 93 gfx::Rect child_bounds(0, position, size.width(), size.height()); |
93 bounds = bounds.Union(child_bounds); | 94 bounds.Union(child_bounds); |
94 position += size.height(); | 95 position += size.height(); |
95 } | 96 } |
96 position += between_child_spacing_; | 97 position += between_child_spacing_; |
97 } | 98 } |
98 } | 99 } |
99 gfx::Insets insets(host->GetInsets()); | 100 gfx::Insets insets(host->GetInsets()); |
100 return gfx::Size( | 101 return gfx::Size( |
101 bounds.width() + insets.width() + 2 * inside_border_horizontal_spacing_, | 102 bounds.width() + insets.width() + 2 * inside_border_horizontal_spacing_, |
102 bounds.height() + insets.height() + 2 * inside_border_vertical_spacing_); | 103 bounds.height() + insets.height() + 2 * inside_border_vertical_spacing_); |
103 } | 104 } |
104 | 105 |
105 } // namespace views | 106 } // namespace views |
OLD | NEW |