| 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 "ui/accessibility/ax_view_state.h" | 10 #include "ui/accessibility/ax_view_state.h" |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 const base::string16& minor_text, | 233 const base::string16& minor_text, |
| 234 const gfx::ImageSkia& icon, | 234 const gfx::ImageSkia& icon, |
| 235 Type type, | 235 Type type, |
| 236 ui::MenuSeparatorType separator_style) { | 236 ui::MenuSeparatorType separator_style) { |
| 237 DCHECK_NE(type, EMPTY); | 237 DCHECK_NE(type, EMPTY); |
| 238 DCHECK_LE(0, index); | 238 DCHECK_LE(0, index); |
| 239 if (!submenu_) | 239 if (!submenu_) |
| 240 CreateSubmenu(); | 240 CreateSubmenu(); |
| 241 DCHECK_GE(submenu_->child_count(), index); | 241 DCHECK_GE(submenu_->child_count(), index); |
| 242 if (type == SEPARATOR) { | 242 if (type == SEPARATOR) { |
| 243 submenu_->AddChildViewAt(new MenuSeparator(separator_style), index); | 243 submenu_->AddChildViewAt(new MenuSeparator(this, separator_style), index); |
| 244 return NULL; | 244 return NULL; |
| 245 } | 245 } |
| 246 MenuItemView* item = new MenuItemView(this, item_id, type); | 246 MenuItemView* item = new MenuItemView(this, item_id, type); |
| 247 if (label.empty() && GetDelegate()) | 247 if (label.empty() && GetDelegate()) |
| 248 item->SetTitle(GetDelegate()->GetLabel(item_id)); | 248 item->SetTitle(GetDelegate()->GetLabel(item_id)); |
| 249 else | 249 else |
| 250 item->SetTitle(label); | 250 item->SetTitle(label); |
| 251 item->SetSubtitle(sublabel); | 251 item->SetSubtitle(sublabel); |
| 252 item->SetMinorText(minor_text); | 252 item->SetMinorText(minor_text); |
| 253 if (!icon.isNull()) | 253 if (!icon.isNull()) |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 dimensions.height); | 411 dimensions.height); |
| 412 } | 412 } |
| 413 | 413 |
| 414 int MenuItemView::GetHeightForWidth(int width) const { | 414 int MenuItemView::GetHeightForWidth(int width) const { |
| 415 // If this isn't a container, we can just use the preferred size's height. | 415 // If this isn't a container, we can just use the preferred size's height. |
| 416 if (!IsContainer()) | 416 if (!IsContainer()) |
| 417 return GetPreferredSize().height(); | 417 return GetPreferredSize().height(); |
| 418 | 418 |
| 419 int height = child_at(0)->GetHeightForWidth(width); | 419 int height = child_at(0)->GetHeightForWidth(width); |
| 420 if (!icon_view_ && GetRootMenuItem()->has_icons()) | 420 if (!icon_view_ && GetRootMenuItem()->has_icons()) |
| 421 height = std::max(height, MenuConfig::instance().check_height); | 421 height = std::max(height, GetMenuConfig().check_height); |
| 422 height += GetBottomMargin() + GetTopMargin(); | 422 height += GetBottomMargin() + GetTopMargin(); |
| 423 | 423 |
| 424 return height; | 424 return height; |
| 425 } | 425 } |
| 426 | 426 |
| 427 const MenuItemView::MenuItemDimensions& MenuItemView::GetDimensions() const { | 427 const MenuItemView::MenuItemDimensions& MenuItemView::GetDimensions() const { |
| 428 if (!is_dimensions_valid()) | 428 if (!is_dimensions_valid()) |
| 429 dimensions_ = CalculateDimensions(); | 429 dimensions_ = CalculateDimensions(); |
| 430 DCHECK(is_dimensions_valid()); | 430 DCHECK(is_dimensions_valid()); |
| 431 return dimensions_; | 431 return dimensions_; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 int x = width() - (use_right_margin_ ? item_right_margin_ : 0); | 538 int x = width() - (use_right_margin_ ? item_right_margin_ : 0); |
| 539 for (int i = child_count() - 1; i >= 0; --i) { | 539 for (int i = child_count() - 1; i >= 0; --i) { |
| 540 View* child = child_at(i); | 540 View* child = child_at(i); |
| 541 if (icon_view_ && (icon_view_ == child)) | 541 if (icon_view_ && (icon_view_ == child)) |
| 542 continue; | 542 continue; |
| 543 int width = child->GetPreferredSize().width(); | 543 int width = child->GetPreferredSize().width(); |
| 544 child->SetBounds(x - width, 0, width, height()); | 544 child->SetBounds(x - width, 0, width, height()); |
| 545 x -= width - kChildXPadding; | 545 x -= width - kChildXPadding; |
| 546 } | 546 } |
| 547 // Position |icon_view|. | 547 // Position |icon_view|. |
| 548 const MenuConfig& config = MenuConfig::instance(); | 548 const MenuConfig& config = GetMenuConfig(); |
| 549 if (icon_view_) { | 549 if (icon_view_) { |
| 550 icon_view_->SizeToPreferredSize(); | 550 icon_view_->SizeToPreferredSize(); |
| 551 gfx::Size size = icon_view_->GetPreferredSize(); | 551 gfx::Size size = icon_view_->GetPreferredSize(); |
| 552 int x = config.item_left_margin + left_icon_margin_ + | 552 int x = config.item_left_margin + left_icon_margin_ + |
| 553 (icon_area_width_ - size.width()) / 2; | 553 (icon_area_width_ - size.width()) / 2; |
| 554 if (config.icons_in_label || type_ == CHECKBOX || type_ == RADIO) | 554 if (config.icons_in_label || type_ == CHECKBOX || type_ == RADIO) |
| 555 x = label_start_; | 555 x = label_start_; |
| 556 int y = | 556 int y = |
| 557 (height() + GetTopMargin() - GetBottomMargin() - size.height()) / 2; | 557 (height() + GetTopMargin() - GetBottomMargin() - size.height()) / 2; |
| 558 icon_view_->SetPosition(gfx::Point(x, y)); | 558 icon_view_->SetPosition(gfx::Point(x, y)); |
| 559 } | 559 } |
| 560 } | 560 } |
| 561 } | 561 } |
| 562 | 562 |
| 563 void MenuItemView::SetMargins(int top_margin, int bottom_margin) { | 563 void MenuItemView::SetMargins(int top_margin, int bottom_margin) { |
| 564 top_margin_ = top_margin; | 564 top_margin_ = top_margin; |
| 565 bottom_margin_ = bottom_margin; | 565 bottom_margin_ = bottom_margin; |
| 566 | 566 |
| 567 invalidate_dimensions(); | 567 invalidate_dimensions(); |
| 568 } | 568 } |
| 569 | 569 |
| 570 const MenuConfig& MenuItemView::GetMenuConfig() const { |
| 571 return MenuConfig::instance(GetNativeTheme()); |
| 572 } |
| 573 |
| 570 MenuItemView::MenuItemView(MenuItemView* parent, | 574 MenuItemView::MenuItemView(MenuItemView* parent, |
| 571 int command, | 575 int command, |
| 572 MenuItemView::Type type) | 576 MenuItemView::Type type) |
| 573 : delegate_(NULL), | 577 : delegate_(NULL), |
| 574 controller_(NULL), | 578 controller_(NULL), |
| 575 canceled_(false), | 579 canceled_(false), |
| 576 parent_menu_item_(parent), | 580 parent_menu_item_(parent), |
| 577 type_(type), | 581 type_(type), |
| 578 selected_(false), | 582 selected_(false), |
| 579 command_(command), | 583 command_(command), |
| (...skipping 18 matching lines...) Expand all Loading... |
| 598 } | 602 } |
| 599 | 603 |
| 600 const char* MenuItemView::GetClassName() const { | 604 const char* MenuItemView::GetClassName() const { |
| 601 return kViewClassName; | 605 return kViewClassName; |
| 602 } | 606 } |
| 603 | 607 |
| 604 // Calculates all sizes that we can from the OS. | 608 // Calculates all sizes that we can from the OS. |
| 605 // | 609 // |
| 606 // This is invoked prior to Running a menu. | 610 // This is invoked prior to Running a menu. |
| 607 void MenuItemView::UpdateMenuPartSizes() { | 611 void MenuItemView::UpdateMenuPartSizes() { |
| 608 const MenuConfig& config = MenuConfig::instance(); | 612 const MenuConfig& config = GetMenuConfig(); |
| 609 | 613 |
| 610 item_right_margin_ = config.label_to_arrow_padding + config.arrow_width + | 614 item_right_margin_ = config.label_to_arrow_padding + config.arrow_width + |
| 611 config.arrow_to_edge_padding; | 615 config.arrow_to_edge_padding; |
| 612 icon_area_width_ = config.check_width; | 616 icon_area_width_ = config.check_width; |
| 613 if (has_icons_) | 617 if (has_icons_) |
| 614 icon_area_width_ = std::max(icon_area_width_, GetMaxIconViewWidth()); | 618 icon_area_width_ = std::max(icon_area_width_, GetMaxIconViewWidth()); |
| 615 | 619 |
| 616 label_start_ = config.item_left_margin + icon_area_width_; | 620 label_start_ = config.item_left_margin + icon_area_width_; |
| 617 int padding = 0; | 621 int padding = 0; |
| 618 if (config.always_use_icon_to_label_padding) { | 622 if (config.always_use_icon_to_label_padding) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 } | 680 } |
| 677 | 681 |
| 678 int MenuItemView::GetDrawStringFlags() { | 682 int MenuItemView::GetDrawStringFlags() { |
| 679 int flags = 0; | 683 int flags = 0; |
| 680 if (base::i18n::IsRTL()) | 684 if (base::i18n::IsRTL()) |
| 681 flags |= gfx::Canvas::TEXT_ALIGN_RIGHT; | 685 flags |= gfx::Canvas::TEXT_ALIGN_RIGHT; |
| 682 else | 686 else |
| 683 flags |= gfx::Canvas::TEXT_ALIGN_LEFT; | 687 flags |= gfx::Canvas::TEXT_ALIGN_LEFT; |
| 684 | 688 |
| 685 if (GetRootMenuItem()->has_mnemonics_) { | 689 if (GetRootMenuItem()->has_mnemonics_) { |
| 686 if (MenuConfig::instance().show_mnemonics || | 690 if (GetMenuConfig().show_mnemonics || GetRootMenuItem()->show_mnemonics_) { |
| 687 GetRootMenuItem()->show_mnemonics_) { | |
| 688 flags |= gfx::Canvas::SHOW_PREFIX; | 691 flags |= gfx::Canvas::SHOW_PREFIX; |
| 689 } else { | 692 } else { |
| 690 flags |= gfx::Canvas::HIDE_PREFIX; | 693 flags |= gfx::Canvas::HIDE_PREFIX; |
| 691 } | 694 } |
| 692 } | 695 } |
| 693 return flags; | 696 return flags; |
| 694 } | 697 } |
| 695 | 698 |
| 696 const gfx::FontList& MenuItemView::GetFontList() const { | 699 const gfx::FontList& MenuItemView::GetFontList() const { |
| 697 const MenuDelegate* delegate = GetDelegate(); | 700 const MenuDelegate* delegate = GetDelegate(); |
| 698 if (delegate) { | 701 if (delegate) { |
| 699 const gfx::FontList* font_list = delegate->GetLabelFontList(GetCommand()); | 702 const gfx::FontList* font_list = delegate->GetLabelFontList(GetCommand()); |
| 700 if (font_list) | 703 if (font_list) |
| 701 return *font_list; | 704 return *font_list; |
| 702 } | 705 } |
| 703 return MenuConfig::instance().font_list; | 706 return GetMenuConfig().font_list; |
| 704 } | 707 } |
| 705 | 708 |
| 706 void MenuItemView::AddEmptyMenus() { | 709 void MenuItemView::AddEmptyMenus() { |
| 707 DCHECK(HasSubmenu()); | 710 DCHECK(HasSubmenu()); |
| 708 if (!submenu_->has_children()) { | 711 if (!submenu_->has_children()) { |
| 709 submenu_->AddChildViewAt(new EmptyMenuMenuItem(this), 0); | 712 submenu_->AddChildViewAt(new EmptyMenuMenuItem(this), 0); |
| 710 } else { | 713 } else { |
| 711 for (int i = 0, item_count = submenu_->GetMenuItemCount(); i < item_count; | 714 for (int i = 0, item_count = submenu_->GetMenuItemCount(); i < item_count; |
| 712 ++i) { | 715 ++i) { |
| 713 MenuItemView* child = submenu_->GetMenuItemAt(i); | 716 MenuItemView* child = submenu_->GetMenuItemAt(i); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 733 child = NULL; | 736 child = NULL; |
| 734 } | 737 } |
| 735 } | 738 } |
| 736 } | 739 } |
| 737 | 740 |
| 738 void MenuItemView::AdjustBoundsForRTLUI(gfx::Rect* rect) const { | 741 void MenuItemView::AdjustBoundsForRTLUI(gfx::Rect* rect) const { |
| 739 rect->set_x(GetMirroredXForRect(*rect)); | 742 rect->set_x(GetMirroredXForRect(*rect)); |
| 740 } | 743 } |
| 741 | 744 |
| 742 void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { | 745 void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { |
| 743 const MenuConfig& config = MenuConfig::instance(); | 746 const MenuConfig& config = GetMenuConfig(); |
| 744 bool render_selection = | 747 bool render_selection = |
| 745 (mode == PB_NORMAL && IsSelected() && | 748 (mode == PB_NORMAL && IsSelected() && |
| 746 parent_menu_item_->GetSubmenu()->GetShowSelection(this) && | 749 parent_menu_item_->GetSubmenu()->GetShowSelection(this) && |
| 747 (NonIconChildViewsCount() == 0)); | 750 (NonIconChildViewsCount() == 0)); |
| 748 | 751 |
| 749 MenuDelegate *delegate = GetDelegate(); | 752 MenuDelegate *delegate = GetDelegate(); |
| 750 // Render the background. As MenuScrollViewContainer draws the background, we | 753 // Render the background. As MenuScrollViewContainer draws the background, we |
| 751 // only need the background when we want it to look different, as when we're | 754 // only need the background when we want it to look different, as when we're |
| 752 // selected. | 755 // selected. |
| 753 ui::NativeTheme* native_theme = GetNativeTheme(); | 756 ui::NativeTheme* native_theme = GetNativeTheme(); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 | 862 |
| 860 void MenuItemView::PaintMinorText(gfx::Canvas* canvas, | 863 void MenuItemView::PaintMinorText(gfx::Canvas* canvas, |
| 861 bool render_selection) { | 864 bool render_selection) { |
| 862 base::string16 minor_text = GetMinorText(); | 865 base::string16 minor_text = GetMinorText(); |
| 863 if (minor_text.empty()) | 866 if (minor_text.empty()) |
| 864 return; | 867 return; |
| 865 | 868 |
| 866 int available_height = height() - GetTopMargin() - GetBottomMargin(); | 869 int available_height = height() - GetTopMargin() - GetBottomMargin(); |
| 867 int max_accel_width = | 870 int max_accel_width = |
| 868 parent_menu_item_->GetSubmenu()->max_minor_text_width(); | 871 parent_menu_item_->GetSubmenu()->max_minor_text_width(); |
| 869 const MenuConfig& config = MenuConfig::instance(); | 872 const MenuConfig& config = GetMenuConfig(); |
| 870 int accel_right_margin = config.align_arrow_and_shortcut ? | 873 int accel_right_margin = config.align_arrow_and_shortcut ? |
| 871 config.arrow_to_edge_padding : item_right_margin_; | 874 config.arrow_to_edge_padding : item_right_margin_; |
| 872 gfx::Rect accel_bounds(width() - accel_right_margin - max_accel_width, | 875 gfx::Rect accel_bounds(width() - accel_right_margin - max_accel_width, |
| 873 GetTopMargin(), max_accel_width, available_height); | 876 GetTopMargin(), max_accel_width, available_height); |
| 874 accel_bounds.set_x(GetMirroredXForRect(accel_bounds)); | 877 accel_bounds.set_x(GetMirroredXForRect(accel_bounds)); |
| 875 int flags = GetDrawStringFlags(); | 878 int flags = GetDrawStringFlags(); |
| 876 flags &= ~(gfx::Canvas::TEXT_ALIGN_RIGHT | gfx::Canvas::TEXT_ALIGN_LEFT); | 879 flags &= ~(gfx::Canvas::TEXT_ALIGN_RIGHT | gfx::Canvas::TEXT_ALIGN_LEFT); |
| 877 if (base::i18n::IsRTL()) | 880 if (base::i18n::IsRTL()) |
| 878 flags |= gfx::Canvas::TEXT_ALIGN_LEFT; | 881 flags |= gfx::Canvas::TEXT_ALIGN_LEFT; |
| 879 else | 882 else |
| (...skipping 18 matching lines...) Expand all Loading... |
| 898 submenu_->GetMenuItemAt(i)->DestroyAllMenuHosts(); | 901 submenu_->GetMenuItemAt(i)->DestroyAllMenuHosts(); |
| 899 } | 902 } |
| 900 } | 903 } |
| 901 | 904 |
| 902 int MenuItemView::GetTopMargin() const { | 905 int MenuItemView::GetTopMargin() const { |
| 903 if (top_margin_ >= 0) | 906 if (top_margin_ >= 0) |
| 904 return top_margin_; | 907 return top_margin_; |
| 905 | 908 |
| 906 const MenuItemView* root = GetRootMenuItem(); | 909 const MenuItemView* root = GetRootMenuItem(); |
| 907 return root && root->has_icons_ | 910 return root && root->has_icons_ |
| 908 ? MenuConfig::instance().item_top_margin | 911 ? GetMenuConfig().item_top_margin : |
| 909 : MenuConfig::instance().item_no_icon_top_margin; | 912 GetMenuConfig().item_no_icon_top_margin; |
| 910 } | 913 } |
| 911 | 914 |
| 912 int MenuItemView::GetBottomMargin() const { | 915 int MenuItemView::GetBottomMargin() const { |
| 913 if (bottom_margin_ >= 0) | 916 if (bottom_margin_ >= 0) |
| 914 return bottom_margin_; | 917 return bottom_margin_; |
| 915 | 918 |
| 916 const MenuItemView* root = GetRootMenuItem(); | 919 const MenuItemView* root = GetRootMenuItem(); |
| 917 return root && root->has_icons_ | 920 return root && root->has_icons_ |
| 918 ? MenuConfig::instance().item_bottom_margin | 921 ? GetMenuConfig().item_bottom_margin : |
| 919 : MenuConfig::instance().item_no_icon_bottom_margin; | 922 GetMenuConfig().item_no_icon_bottom_margin; |
| 920 } | 923 } |
| 921 | 924 |
| 922 gfx::Size MenuItemView::GetChildPreferredSize() const { | 925 gfx::Size MenuItemView::GetChildPreferredSize() const { |
| 923 if (!has_children()) | 926 if (!has_children()) |
| 924 return gfx::Size(); | 927 return gfx::Size(); |
| 925 | 928 |
| 926 if (IsContainer()) | 929 if (IsContainer()) |
| 927 return child_at(0)->GetPreferredSize(); | 930 return child_at(0)->GetPreferredSize(); |
| 928 | 931 |
| 929 int width = 0; | 932 int width = 0; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 947 MenuItemView::MenuItemDimensions MenuItemView::CalculateDimensions() const { | 950 MenuItemView::MenuItemDimensions MenuItemView::CalculateDimensions() const { |
| 948 gfx::Size child_size = GetChildPreferredSize(); | 951 gfx::Size child_size = GetChildPreferredSize(); |
| 949 | 952 |
| 950 MenuItemDimensions dimensions; | 953 MenuItemDimensions dimensions; |
| 951 // Get the container height. | 954 // Get the container height. |
| 952 dimensions.children_width = child_size.width(); | 955 dimensions.children_width = child_size.width(); |
| 953 dimensions.height = child_size.height(); | 956 dimensions.height = child_size.height(); |
| 954 // Adjust item content height if menu has both items with and without icons. | 957 // Adjust item content height if menu has both items with and without icons. |
| 955 // This way all menu items will have the same height. | 958 // This way all menu items will have the same height. |
| 956 if (!icon_view_ && GetRootMenuItem()->has_icons()) { | 959 if (!icon_view_ && GetRootMenuItem()->has_icons()) { |
| 957 dimensions.height = | 960 dimensions.height = std::max(dimensions.height, |
| 958 std::max(dimensions.height, MenuConfig::instance().check_height); | 961 GetMenuConfig().check_height); |
| 959 } | 962 } |
| 960 dimensions.height += GetBottomMargin() + GetTopMargin(); | 963 dimensions.height += GetBottomMargin() + GetTopMargin(); |
| 961 | 964 |
| 962 // In case of a container, only the container size needs to be filled. | 965 // In case of a container, only the container size needs to be filled. |
| 963 if (IsContainer()) | 966 if (IsContainer()) |
| 964 return dimensions; | 967 return dimensions; |
| 965 | 968 |
| 966 // Determine the length of the label text. | 969 // Determine the length of the label text. |
| 967 const gfx::FontList& font_list = GetFontList(); | 970 const gfx::FontList& font_list = GetFontList(); |
| 968 | 971 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 990 // Determine the length of the right-side text. | 993 // Determine the length of the right-side text. |
| 991 base::string16 minor_text = GetMinorText(); | 994 base::string16 minor_text = GetMinorText(); |
| 992 dimensions.minor_text_width = | 995 dimensions.minor_text_width = |
| 993 minor_text.empty() ? 0 : gfx::GetStringWidth(minor_text, font_list); | 996 minor_text.empty() ? 0 : gfx::GetStringWidth(minor_text, font_list); |
| 994 | 997 |
| 995 // Determine the height to use. | 998 // Determine the height to use. |
| 996 dimensions.height = | 999 dimensions.height = |
| 997 std::max(dimensions.height, | 1000 std::max(dimensions.height, |
| 998 (subtitle_.empty() ? 0 : font_list.GetHeight()) + | 1001 (subtitle_.empty() ? 0 : font_list.GetHeight()) + |
| 999 font_list.GetHeight() + GetBottomMargin() + GetTopMargin()); | 1002 font_list.GetHeight() + GetBottomMargin() + GetTopMargin()); |
| 1000 dimensions.height = | 1003 dimensions.height = std::max(dimensions.height, |
| 1001 std::max(dimensions.height, MenuConfig::instance().item_min_height); | 1004 GetMenuConfig().item_min_height); |
| 1002 return dimensions; | 1005 return dimensions; |
| 1003 } | 1006 } |
| 1004 | 1007 |
| 1005 int MenuItemView::GetLabelStartForThisItem() const { | 1008 int MenuItemView::GetLabelStartForThisItem() const { |
| 1006 const MenuConfig& config = MenuConfig::instance(); | 1009 const MenuConfig& config = GetMenuConfig(); |
| 1007 int label_start = label_start_ + left_icon_margin_ + right_icon_margin_; | 1010 int label_start = label_start_ + left_icon_margin_ + right_icon_margin_; |
| 1008 if ((config.icons_in_label || type_ == CHECKBOX || type_ == RADIO) && | 1011 if ((config.icons_in_label || type_ == CHECKBOX || type_ == RADIO) && |
| 1009 icon_view_) | 1012 icon_view_) |
| 1010 label_start += icon_view_->size().width() + config.icon_to_label_padding; | 1013 label_start += icon_view_->size().width() + config.icon_to_label_padding; |
| 1011 | 1014 |
| 1012 return label_start; | 1015 return label_start; |
| 1013 } | 1016 } |
| 1014 | 1017 |
| 1015 base::string16 MenuItemView::GetMinorText() const { | 1018 base::string16 MenuItemView::GetMinorText() const { |
| 1016 if (id() == kEmptyMenuItemViewID) { | 1019 if (id() == kEmptyMenuItemViewID) { |
| 1017 // Don't query the delegate for menus that represent no children. | 1020 // Don't query the delegate for menus that represent no children. |
| 1018 return base::string16(); | 1021 return base::string16(); |
| 1019 } | 1022 } |
| 1020 | 1023 |
| 1021 ui::Accelerator accelerator; | 1024 ui::Accelerator accelerator; |
| 1022 if (MenuConfig::instance().show_accelerators && GetDelegate() && | 1025 if (GetMenuConfig().show_accelerators && GetDelegate() && GetCommand() && |
| 1023 GetCommand() && | 1026 GetDelegate()->GetAccelerator(GetCommand(), &accelerator)) { |
| 1024 GetDelegate()->GetAccelerator(GetCommand(), &accelerator)) { | |
| 1025 return accelerator.GetShortcutText(); | 1027 return accelerator.GetShortcutText(); |
| 1026 } | 1028 } |
| 1027 | 1029 |
| 1028 return minor_text_; | 1030 return minor_text_; |
| 1029 } | 1031 } |
| 1030 | 1032 |
| 1031 bool MenuItemView::IsContainer() const { | 1033 bool MenuItemView::IsContainer() const { |
| 1032 // Let the first child take over |this| when we only have one child and no | 1034 // Let the first child take over |this| when we only have one child and no |
| 1033 // title. | 1035 // title. |
| 1034 return (NonIconChildViewsCount() == 1) && title_.empty(); | 1036 return (NonIconChildViewsCount() == 1) && title_.empty(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1045 for (int i = 0; i < submenu_->GetMenuItemCount(); ++i) { | 1047 for (int i = 0; i < submenu_->GetMenuItemCount(); ++i) { |
| 1046 MenuItemView* menu_item = submenu_->GetMenuItemAt(i); | 1048 MenuItemView* menu_item = submenu_->GetMenuItemAt(i); |
| 1047 int temp_width = 0; | 1049 int temp_width = 0; |
| 1048 if (menu_item->GetType() == CHECKBOX || | 1050 if (menu_item->GetType() == CHECKBOX || |
| 1049 menu_item->GetType() == RADIO) { | 1051 menu_item->GetType() == RADIO) { |
| 1050 // If this item has a radio or checkbox, the icon will not affect | 1052 // If this item has a radio or checkbox, the icon will not affect |
| 1051 // alignment of other items. | 1053 // alignment of other items. |
| 1052 continue; | 1054 continue; |
| 1053 } else if (menu_item->HasSubmenu()) { | 1055 } else if (menu_item->HasSubmenu()) { |
| 1054 temp_width = menu_item->GetMaxIconViewWidth(); | 1056 temp_width = menu_item->GetMaxIconViewWidth(); |
| 1055 } else if (menu_item->icon_view() && | 1057 } else if (menu_item->icon_view() && !GetMenuConfig().icons_in_label) { |
| 1056 !MenuConfig::instance().icons_in_label) { | |
| 1057 temp_width = menu_item->icon_view()->GetPreferredSize().width(); | 1058 temp_width = menu_item->icon_view()->GetPreferredSize().width(); |
| 1058 } | 1059 } |
| 1059 width = std::max(width, temp_width); | 1060 width = std::max(width, temp_width); |
| 1060 } | 1061 } |
| 1061 return width; | 1062 return width; |
| 1062 } | 1063 } |
| 1063 | 1064 |
| 1064 bool MenuItemView::HasChecksOrRadioButtons() const { | 1065 bool MenuItemView::HasChecksOrRadioButtons() const { |
| 1065 for (int i = 0; i < submenu_->GetMenuItemCount(); ++i) { | 1066 for (int i = 0; i < submenu_->GetMenuItemCount(); ++i) { |
| 1066 MenuItemView* menu_item = submenu_->GetMenuItemAt(i); | 1067 MenuItemView* menu_item = submenu_->GetMenuItemAt(i); |
| 1067 if (menu_item->HasSubmenu()) { | 1068 if (menu_item->HasSubmenu()) { |
| 1068 if (menu_item->HasChecksOrRadioButtons()) | 1069 if (menu_item->HasChecksOrRadioButtons()) |
| 1069 return true; | 1070 return true; |
| 1070 } else { | 1071 } else { |
| 1071 const Type& type = menu_item->GetType(); | 1072 const Type& type = menu_item->GetType(); |
| 1072 if (type == CHECKBOX || type == RADIO) | 1073 if (type == CHECKBOX || type == RADIO) |
| 1073 return true; | 1074 return true; |
| 1074 } | 1075 } |
| 1075 } | 1076 } |
| 1076 return false; | 1077 return false; |
| 1077 } | 1078 } |
| 1078 | 1079 |
| 1079 } // namespace views | 1080 } // namespace views |
| OLD | NEW |