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