Chromium Code Reviews| Index: ui/views/controls/menu/submenu_view.cc |
| diff --git a/ui/views/controls/menu/submenu_view.cc b/ui/views/controls/menu/submenu_view.cc |
| index a6ef56a888ece57b0970941da68335e37bed637d..454399436af34768f5ed84d3865ada55d744848c 100644 |
| --- a/ui/views/controls/menu/submenu_view.cc |
| +++ b/ui/views/controls/menu/submenu_view.cc |
| @@ -130,7 +130,11 @@ gfx::Size SubmenuView::GetPreferredSize() const { |
| int max_complex_width = 0; |
| // The max. width of items which contain a label and maybe an accelerator. |
| int max_simple_width = 0; |
| - int height = 0; |
| + |
| + // We perform the size calculation in two passes. In the first pass, we |
| + // calculate the width of the menu. In the second, we calculate the height |
| + // using that width. This allows views that have flexible widths to adjust |
| + // accordingly. |
| for (int i = 0; i < child_count(); ++i) { |
| const View* child = child_at(i); |
| if (!child->visible()) |
| @@ -145,25 +149,30 @@ gfx::Size SubmenuView::GetPreferredSize() const { |
| std::max(max_minor_text_width_, dimensions.minor_text_width); |
| max_complex_width = std::max(max_complex_width, |
| dimensions.standard_width + dimensions.children_width); |
| - height += dimensions.height; |
| } else { |
| - gfx::Size child_pref_size = |
| - child->visible() ? child->GetPreferredSize() : gfx::Size(); |
| - max_complex_width = std::max(max_complex_width, child_pref_size.width()); |
| - height += child_pref_size.height(); |
| + max_complex_width = std::max(max_complex_width, |
| + child->GetPreferredSize().width()); |
| } |
| } |
| if (max_minor_text_width_ > 0) { |
| max_minor_text_width_ += |
| GetMenuItem()->GetMenuConfig().label_to_minor_text_padding; |
| } |
| + // Finish calculating our optimum width. |
| gfx::Insets insets = GetInsets(); |
| - return gfx::Size( |
| - std::max(max_complex_width, |
| - std::max(max_simple_width + max_minor_text_width_ + |
| - insets.width(), |
| - minimum_preferred_width_ - 2 * insets.width())), |
| - height + insets.height()); |
| + int width = std::max(max_complex_width, |
| + std::max(max_simple_width + max_minor_text_width_ + |
| + insets.width(), |
| + minimum_preferred_width_ - 2 * insets.width())); |
| + |
| + // Then, the height for that width. |
| + int height = 0; |
| + for (int i = 0; i < child_count(); ++i) { |
| + const View* child = child_at(i); |
| + height += child->visible() ? child->GetHeightForWidth(width) : 0; |
| + } |
| + |
| + return gfx::Size(width, height + insets.height()); |
|
sky
2014/09/12 20:09:38
Can you write test coverage of this?
Devlin
2014/09/12 22:41:37
But of course! Done. :)
|
| } |
| void SubmenuView::GetAccessibleState(ui::AXViewState* state) { |