Chromium Code Reviews| Index: ui/views/layout/box_layout.cc |
| diff --git a/ui/views/layout/box_layout.cc b/ui/views/layout/box_layout.cc |
| index 319efa770c3677a9a9a97fa545f9854be201be17..3433683d3038bc12e979f6e37aa285f8053bacce 100644 |
| --- a/ui/views/layout/box_layout.cc |
| +++ b/ui/views/layout/box_layout.cc |
| @@ -40,10 +40,12 @@ void BoxLayout::Layout(View* host) { |
| View* child = host->child_at(i); |
| if (!child->visible()) |
| continue; |
| - if (orientation_ == kHorizontal) |
| + if (orientation_ == kHorizontal) { |
| total += child->GetPreferredSize().width() + between_child_spacing_; |
| - else |
| - total += child->GetPreferredSize().height() + between_child_spacing_; |
| + } else { |
| + total += child->GetHeightForWidth(child_area.width()) + |
| + between_child_spacing_; |
| + } |
| ++visible; |
| } |
| @@ -63,13 +65,12 @@ void BoxLayout::Layout(View* host) { |
| View* child = host->child_at(i); |
| if (child->visible()) { |
| gfx::Rect bounds(x, y, child_area.width(), child_area.height()); |
| - gfx::Size size(child->GetPreferredSize()); |
| if (orientation_ == kHorizontal) { |
| - bounds.set_width(size.width() + padding); |
| - x += size.width() + between_child_spacing_ + padding; |
| + bounds.set_width(child->GetPreferredSize().width() + padding); |
| + x += bounds.width() + between_child_spacing_; |
| } else { |
| - bounds.set_height(size.height() + padding); |
| - y += size.height() + between_child_spacing_ + padding; |
| + bounds.set_height(child->GetHeightForWidth(bounds.width()) + padding); |
| + y += bounds.height() + between_child_spacing_; |
| } |
| // Clamp child view bounds to |child_area|. |
| bounds.Intersect(child_area); |
| @@ -80,22 +81,42 @@ void BoxLayout::Layout(View* host) { |
| gfx::Size BoxLayout::GetPreferredSize(View* host) { |
|
sky
2013/03/13 14:03:03
You should also override GetPreferredSizeForWidth
Evan Stade
2013/03/13 23:49:56
done, although I didn't add an implementation for
|
| gfx::Rect bounds; |
| - int position = 0; |
| - for (int i = 0; i < host->child_count(); ++i) { |
| - View* child = host->child_at(i); |
| - if (child->visible()) { |
| + |
| + if (orientation_ == kHorizontal) { |
| + int position = 0; |
| + for (int i = 0; i < host->child_count(); ++i) { |
| + View* child = host->child_at(i); |
| + if (!child->visible()) |
| + continue; |
| + |
| gfx::Size size(child->GetPreferredSize()); |
| - if (orientation_ == kHorizontal) { |
| - gfx::Rect child_bounds(position, 0, size.width(), size.height()); |
| - bounds.Union(child_bounds); |
| - position += size.width(); |
| - } else { |
| - gfx::Rect child_bounds(0, position, size.width(), size.height()); |
| - bounds.Union(child_bounds); |
| - position += size.height(); |
| - } |
| - position += between_child_spacing_; |
| + gfx::Rect child_bounds(position, 0, size.width(), size.height()); |
| + bounds.Union(child_bounds); |
| + position += size.width() + between_child_spacing_; |
| + } |
| + } else { |
| + int width = 0; |
| + for (int i = 0; i < host->child_count(); ++i) { |
| + View* child = host->child_at(i); |
| + if (!child->visible()) |
| + continue; |
| + |
| + width = std::max(width, child->GetPreferredSize().width()); |
| } |
| + |
| + int height = 0; |
| + for (int i = 0; i < host->child_count(); ++i) { |
| + View* child = host->child_at(i); |
| + if (!child->visible()) |
| + continue; |
| + |
| + height += child->GetHeightForWidth(width); |
| + if (i != 0) |
| + height += between_child_spacing_; |
| + } |
| + |
| + bounds.set_width(width); |
| + bounds.set_height(height); |
| } |
| gfx::Insets insets(host->GetInsets()); |
| return gfx::Size( |