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/controls/menu/menu_item_view.h" | 5 #include "ui/views/controls/menu/menu_item_view.h" |
6 | 6 |
7 #include "base/i18n/case_conversion.h" | 7 #include "base/i18n/case_conversion.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "grit/ui_resources.h" | 10 #include "grit/ui_resources.h" |
(...skipping 1019 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1030 // Note that what child_count() returns is the number of children, | 1030 // Note that what child_count() returns is the number of children, |
1031 // not the number of menu items. | 1031 // not the number of menu items. |
1032 return child_count() - (icon_view_ ? 1 : 0); | 1032 return child_count() - (icon_view_ ? 1 : 0); |
1033 } | 1033 } |
1034 | 1034 |
1035 int MenuItemView::GetMaxIconViewWidth() const { | 1035 int MenuItemView::GetMaxIconViewWidth() const { |
1036 int width = 0; | 1036 int width = 0; |
1037 for (int i = 0; i < submenu_->GetMenuItemCount(); ++i) { | 1037 for (int i = 0; i < submenu_->GetMenuItemCount(); ++i) { |
1038 MenuItemView* menu_item = submenu_->GetMenuItemAt(i); | 1038 MenuItemView* menu_item = submenu_->GetMenuItemAt(i); |
1039 int temp_width = 0; | 1039 int temp_width = 0; |
1040 if (menu_item->HasSubmenu()) { | 1040 if (menu_item->GetType() == CHECKBOX || |
| 1041 menu_item->GetType() == RADIO) { |
| 1042 // If this item has a radio or checkbox, the icon will not affect |
| 1043 // alignment of other items. |
| 1044 continue; |
| 1045 } else if (menu_item->HasSubmenu()) { |
1041 temp_width = menu_item->GetMaxIconViewWidth(); | 1046 temp_width = menu_item->GetMaxIconViewWidth(); |
1042 } else if (menu_item->icon_view()) { | 1047 } else if (menu_item->icon_view()) { |
1043 temp_width = menu_item->icon_view()->GetPreferredSize().width(); | 1048 temp_width = menu_item->icon_view()->GetPreferredSize().width(); |
1044 } | 1049 } |
1045 width = std::max(width, temp_width); | 1050 width = std::max(width, temp_width); |
1046 } | 1051 } |
1047 return width; | 1052 return width; |
1048 } | 1053 } |
1049 | 1054 |
1050 bool MenuItemView::HasChecksOrRadioButtons() const { | 1055 bool MenuItemView::HasChecksOrRadioButtons() const { |
1051 for (int i = 0; i < submenu_->GetMenuItemCount(); ++i) { | 1056 for (int i = 0; i < submenu_->GetMenuItemCount(); ++i) { |
1052 MenuItemView* menu_item = submenu_->GetMenuItemAt(i); | 1057 MenuItemView* menu_item = submenu_->GetMenuItemAt(i); |
1053 if (menu_item->HasSubmenu()) { | 1058 if (menu_item->HasSubmenu()) { |
1054 if (menu_item->HasChecksOrRadioButtons()) | 1059 if (menu_item->HasChecksOrRadioButtons()) |
1055 return true; | 1060 return true; |
1056 } else { | 1061 } else { |
1057 const Type& type = menu_item->GetType(); | 1062 const Type& type = menu_item->GetType(); |
1058 if (type == CHECKBOX || type == RADIO) | 1063 if (type == CHECKBOX || type == RADIO) |
1059 return true; | 1064 return true; |
1060 } | 1065 } |
1061 } | 1066 } |
1062 return false; | 1067 return false; |
1063 } | 1068 } |
1064 | 1069 |
1065 } // namespace views | 1070 } // namespace views |
OLD | NEW |