Chromium Code Reviews| Index: views/controls/menu/menu_item_view.cc |
| diff --git a/views/controls/menu/menu_item_view.cc b/views/controls/menu/menu_item_view.cc |
| index a47e5d32a1dfda8849dc44cce923b0f5453b88d1..8a9c203ebf4cfb3e84e65ec456e18b7f0bb67293 100644 |
| --- a/views/controls/menu/menu_item_view.cc |
| +++ b/views/controls/menu/menu_item_view.cc |
| @@ -484,14 +484,22 @@ void MenuItemView::Layout() { |
| if (!has_children()) |
| return; |
| - // Child views are laid out right aligned and given the full height. To right |
| - // align start with the last view and progress to the first. |
| - for (int i = child_count() - 1, x = width() - item_right_margin_; i >= 0; |
| - --i) { |
| - View* child = GetChildViewAt(i); |
| - int width = child->GetPreferredSize().width(); |
| - child->SetBounds(x - width, 0, width, height()); |
| - x -= width - kChildXPadding; |
| + if (child_count() == 1 && GetTitle().size() == 0) { |
| + // We only have one child and no title so let the view take over all the |
| + // space. |
| + View* child = GetChildViewAt(0); |
| + gfx::Size size = child->GetPreferredSize(); |
| + child->SetBounds(label_start_, GetTopMargin(), size.width(), size.height()); |
| + } else { |
| + // Child views are laid out right aligned and given the full height. To |
| + // right align start with the last view and progress to the first. |
| + for (int i = child_count() - 1, x = width() - item_right_margin_; i >= 0; |
| + --i) { |
| + View* child = GetChildViewAt(i); |
| + int width = child->GetPreferredSize().width(); |
| + child->SetBounds(x - width, 0, width, height()); |
| + x -= width - kChildXPadding; |
| + } |
| } |
| } |
| @@ -732,17 +740,22 @@ int MenuItemView::GetBottomMargin() { |
| MenuConfig::instance().item_no_icon_bottom_margin; |
| } |
| -int MenuItemView::GetChildPreferredWidth() { |
| +gfx::Size MenuItemView::GetChildPreferredSize() { |
| if (!has_children()) |
| - return 0; |
| + return gfx::Size(); |
| - int width = 0; |
| - for (int i = 0; i < child_count(); ++i) { |
| - if (i) |
| - width += kChildXPadding; |
| - width += GetChildViewAt(i)->GetPreferredSize().width(); |
| + if (GetTitle().size() == 0 && child_count() == 1) { |
| + View* child = GetChildViewAt(0); |
| + return child->GetPreferredSize(); |
| + } else { |
|
sky
2011/07/08 21:01:44
no else (since you returned early).
sail
2011/07/08 21:53:57
Done.
|
| + int width = 0; |
| + for (int i = 0; i < child_count(); ++i) { |
| + if (i) |
| + width += kChildXPadding; |
| + width += GetChildViewAt(i)->GetPreferredSize().width(); |
| + } |
| + return gfx::Size(width, 0); |
|
sky
2011/07/08 21:01:44
Document why its ok to return a height of 0 here.
sail
2011/07/08 21:53:57
Done.
|
| } |
| - return width; |
| } |
| string16 MenuItemView::GetAcceleratorText() { |