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/rect.h" | 7 #include "ui/gfx/rect.h" |
8 #include "ui/views/view.h" | 8 #include "ui/views/view.h" |
9 | 9 |
10 namespace views { | 10 namespace views { |
11 | 11 |
12 BoxLayout::BoxLayout(BoxLayout::Orientation orientation, | 12 BoxLayout::BoxLayout(BoxLayout::Orientation orientation, |
13 int inside_border_horizontal_spacing, | 13 int inside_border_horizontal_spacing, |
14 int inside_border_vertical_spacing, | 14 int inside_border_vertical_spacing, |
15 int between_child_spacing) | 15 int between_child_spacing) |
16 : orientation_(orientation), | 16 : orientation_(orientation), |
17 inside_border_insets_(inside_border_vertical_spacing, | 17 inside_border_insets_(inside_border_vertical_spacing, |
18 inside_border_horizontal_spacing, | 18 inside_border_horizontal_spacing, |
19 inside_border_vertical_spacing, | 19 inside_border_vertical_spacing, |
20 inside_border_horizontal_spacing), | 20 inside_border_horizontal_spacing), |
21 between_child_spacing_(between_child_spacing), | 21 between_child_spacing_(between_child_spacing), |
22 main_axis_alignment_(MAIN_AXIS_ALIGNMENT_START), | 22 main_axis_alignment_(MAIN_AXIS_ALIGNMENT_START), |
23 cross_axis_alignment_(CROSS_AXIS_ALIGNMENT_STRETCH), | 23 cross_axis_alignment_(CROSS_AXIS_ALIGNMENT_STRETCH), |
24 default_flex_(0), | 24 default_flex_(0), |
| 25 minimum_cross_axis_size_(0), |
25 host_(NULL) { | 26 host_(NULL) { |
26 } | 27 } |
27 | 28 |
28 BoxLayout::~BoxLayout() { | 29 BoxLayout::~BoxLayout() { |
29 } | 30 } |
30 | 31 |
31 void BoxLayout::SetFlexForView(const View* view, int flex_weight) { | 32 void BoxLayout::SetFlexForView(const View* view, int flex_weight) { |
32 DCHECK(host_); | 33 DCHECK(host_); |
33 DCHECK(view); | 34 DCHECK(view); |
34 DCHECK_EQ(host_, view->parent()); | 35 DCHECK_EQ(host_, view->parent()); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 // Calculate the child views' preferred width. | 156 // Calculate the child views' preferred width. |
156 int width = 0; | 157 int width = 0; |
157 if (orientation_ == kVertical) { | 158 if (orientation_ == kVertical) { |
158 for (int i = 0; i < host->child_count(); ++i) { | 159 for (int i = 0; i < host->child_count(); ++i) { |
159 const View* child = host->child_at(i); | 160 const View* child = host->child_at(i); |
160 if (!child->visible()) | 161 if (!child->visible()) |
161 continue; | 162 continue; |
162 | 163 |
163 width = std::max(width, child->GetPreferredSize().width()); | 164 width = std::max(width, child->GetPreferredSize().width()); |
164 } | 165 } |
| 166 width = std::max(width, minimum_cross_axis_size_); |
165 } | 167 } |
166 | 168 |
167 return GetPreferredSizeForChildWidth(host, width); | 169 return GetPreferredSizeForChildWidth(host, width); |
168 } | 170 } |
169 | 171 |
170 int BoxLayout::GetPreferredHeightForWidth(const View* host, int width) const { | 172 int BoxLayout::GetPreferredHeightForWidth(const View* host, int width) const { |
171 DCHECK_EQ(host_, host); | 173 DCHECK_EQ(host_, host); |
172 int child_width = width - NonChildSize(host).width(); | 174 int child_width = width - NonChildSize(host).width(); |
173 return GetPreferredSizeForChildWidth(host, child_width).height(); | 175 return GetPreferredSizeForChildWidth(host, child_width).height(); |
174 } | 176 } |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 continue; | 273 continue; |
272 | 274 |
273 gfx::Size size(child->GetPreferredSize()); | 275 gfx::Size size(child->GetPreferredSize()); |
274 if (size.IsEmpty()) | 276 if (size.IsEmpty()) |
275 continue; | 277 continue; |
276 | 278 |
277 gfx::Rect child_bounds(position, 0, size.width(), size.height()); | 279 gfx::Rect child_bounds(position, 0, size.width(), size.height()); |
278 child_area_bounds.Union(child_bounds); | 280 child_area_bounds.Union(child_bounds); |
279 position += size.width() + between_child_spacing_; | 281 position += size.width() + between_child_spacing_; |
280 } | 282 } |
| 283 child_area_bounds.set_height( |
| 284 std::max(child_area_bounds.height(), minimum_cross_axis_size_)); |
281 } else { | 285 } else { |
282 int height = 0; | 286 int height = 0; |
283 for (int i = 0; i < host->child_count(); ++i) { | 287 for (int i = 0; i < host->child_count(); ++i) { |
284 const View* child = host->child_at(i); | 288 const View* child = host->child_at(i); |
285 if (!child->visible()) | 289 if (!child->visible()) |
286 continue; | 290 continue; |
287 | 291 |
288 // Use the child area width for getting the height if the child is | 292 // Use the child area width for getting the height if the child is |
289 // supposed to stretch. Use its preferred size otherwise. | 293 // supposed to stretch. Use its preferred size otherwise. |
290 int extra_height = MainAxisSizeForView(child, child_area_width); | 294 int extra_height = MainAxisSizeForView(child, child_area_width); |
(...skipping 12 matching lines...) Expand all Loading... |
303 child_area_bounds.height() + non_child_size.height()); | 307 child_area_bounds.height() + non_child_size.height()); |
304 } | 308 } |
305 | 309 |
306 gfx::Size BoxLayout::NonChildSize(const View* host) const { | 310 gfx::Size BoxLayout::NonChildSize(const View* host) const { |
307 gfx::Insets insets(host->GetInsets()); | 311 gfx::Insets insets(host->GetInsets()); |
308 return gfx::Size(insets.width() + inside_border_insets_.width(), | 312 return gfx::Size(insets.width() + inside_border_insets_.width(), |
309 insets.height() + inside_border_insets_.height()); | 313 insets.height() + inside_border_insets_.height()); |
310 } | 314 } |
311 | 315 |
312 } // namespace views | 316 } // namespace views |
OLD | NEW |