| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/i18n/case_conversion.h" | 9 #include "base/i18n/case_conversion.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 } | 746 } |
| 747 | 747 |
| 748 void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { | 748 void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { |
| 749 const MenuConfig& config = MenuConfig::instance(); | 749 const MenuConfig& config = MenuConfig::instance(); |
| 750 bool render_selection = | 750 bool render_selection = |
| 751 (mode == PB_NORMAL && IsSelected() && | 751 (mode == PB_NORMAL && IsSelected() && |
| 752 parent_menu_item_->GetSubmenu()->GetShowSelection(this) && | 752 parent_menu_item_->GetSubmenu()->GetShowSelection(this) && |
| 753 (NonIconChildViewsCount() == 0)); | 753 (NonIconChildViewsCount() == 0)); |
| 754 | 754 |
| 755 MenuDelegate *delegate = GetDelegate(); | 755 MenuDelegate *delegate = GetDelegate(); |
| 756 bool emphasized = |
| 757 delegate && delegate->GetShouldUseNormalForegroundColor(GetCommand()); |
| 756 // Render the background. As MenuScrollViewContainer draws the background, we | 758 // Render the background. As MenuScrollViewContainer draws the background, we |
| 757 // only need the background when we want it to look different, as when we're | 759 // only need the background when we want it to look different, as when we're |
| 758 // selected. | 760 // selected. |
| 759 ui::NativeTheme* native_theme = GetNativeTheme(); | 761 ui::NativeTheme* native_theme = GetNativeTheme(); |
| 760 if (render_selection) { | 762 if (render_selection) { |
| 761 gfx::Rect item_bounds(0, 0, width(), height()); | 763 gfx::Rect item_bounds(0, 0, width(), height()); |
| 762 AdjustBoundsForRTLUI(&item_bounds); | 764 AdjustBoundsForRTLUI(&item_bounds); |
| 763 | 765 |
| 764 native_theme->Paint(canvas->sk_canvas(), | 766 native_theme->Paint(canvas->sk_canvas(), |
| 765 ui::NativeTheme::kMenuItemBackground, | 767 ui::NativeTheme::kMenuItemBackground, |
| 766 ui::NativeTheme::kHovered, | 768 ui::NativeTheme::kHovered, |
| 767 item_bounds, | 769 item_bounds, |
| 768 ui::NativeTheme::ExtraParams()); | 770 ui::NativeTheme::ExtraParams()); |
| 769 } | 771 } |
| 770 | 772 |
| 771 const int icon_x = config.item_left_margin + left_icon_margin_; | 773 const int icon_x = config.item_left_margin + left_icon_margin_; |
| 772 const int top_margin = GetTopMargin(); | 774 const int top_margin = GetTopMargin(); |
| 773 const int bottom_margin = GetBottomMargin(); | 775 const int bottom_margin = GetBottomMargin(); |
| 774 const int available_height = height() - top_margin - bottom_margin; | 776 const int available_height = height() - top_margin - bottom_margin; |
| 775 | 777 |
| 776 // Calculate some colors. | 778 // Calculate some colors. |
| 777 ui::NativeTheme::ColorId color_id; | 779 SkColor fg_color = GetTextColor(false, render_selection, emphasized); |
| 778 if (enabled()) { | |
| 779 color_id = render_selection ? | |
| 780 ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor: | |
| 781 ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor; | |
| 782 } else { | |
| 783 bool emphasized = | |
| 784 delegate && delegate->GetShouldUseNormalForegroundColor(GetCommand()); | |
| 785 color_id = emphasized | |
| 786 ? ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor | |
| 787 : ui::NativeTheme::kColorId_DisabledMenuItemForegroundColor; | |
| 788 } | |
| 789 SkColor fg_color = native_theme->GetSystemColor(color_id); | |
| 790 SkColor icon_color = color_utils::DeriveDefaultIconColor(fg_color); | 780 SkColor icon_color = color_utils::DeriveDefaultIconColor(fg_color); |
| 791 | 781 |
| 792 // Render the check. | 782 // Render the check. |
| 793 if (type_ == CHECKBOX && delegate->IsItemChecked(GetCommand())) { | 783 if (type_ == CHECKBOX && delegate->IsItemChecked(GetCommand())) { |
| 794 gfx::ImageSkia check = GetMenuCheckImage(icon_color); | 784 gfx::ImageSkia check = GetMenuCheckImage(icon_color); |
| 795 // Don't use config.check_width here as it's padded | 785 // Don't use config.check_width here as it's padded |
| 796 // to force more padding (AURA). | 786 // to force more padding (AURA). |
| 797 gfx::Rect check_bounds(icon_x, | 787 gfx::Rect check_bounds(icon_x, |
| 798 top_margin + (available_height - check.height()) / 2, | 788 top_margin + (available_height - check.height()) / 2, |
| 799 check.width(), | 789 check.width(), |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 if (!subtitle_.empty()) { | 822 if (!subtitle_.empty()) { |
| 833 canvas->DrawStringRectWithFlags( | 823 canvas->DrawStringRectWithFlags( |
| 834 subtitle_, | 824 subtitle_, |
| 835 font_list, | 825 font_list, |
| 836 GetNativeTheme()->GetSystemColor( | 826 GetNativeTheme()->GetSystemColor( |
| 837 ui::NativeTheme::kColorId_MenuItemSubtitleColor), | 827 ui::NativeTheme::kColorId_MenuItemSubtitleColor), |
| 838 text_bounds + gfx::Vector2d(0, font_list.GetHeight()), | 828 text_bounds + gfx::Vector2d(0, font_list.GetHeight()), |
| 839 flags); | 829 flags); |
| 840 } | 830 } |
| 841 | 831 |
| 842 PaintMinorText(canvas, render_selection); | 832 PaintMinorText(canvas, GetTextColor(true, render_selection, emphasized)); |
| 843 | 833 |
| 844 // Render the submenu indicator (arrow). | 834 // Render the submenu indicator (arrow). |
| 845 if (HasSubmenu()) { | 835 if (HasSubmenu()) { |
| 846 gfx::ImageSkia arrow = GetSubmenuArrowImage(icon_color); | 836 gfx::ImageSkia arrow = GetSubmenuArrowImage(icon_color); |
| 847 gfx::Rect arrow_bounds(this->width() - config.arrow_width - | 837 gfx::Rect arrow_bounds(this->width() - config.arrow_width - |
| 848 config.arrow_to_edge_padding, | 838 config.arrow_to_edge_padding, |
| 849 top_margin + (available_height - arrow.height()) / 2, | 839 top_margin + (available_height - arrow.height()) / 2, |
| 850 config.arrow_width, | 840 config.arrow_width, |
| 851 arrow.height()); | 841 arrow.height()); |
| 852 AdjustBoundsForRTLUI(&arrow_bounds); | 842 AdjustBoundsForRTLUI(&arrow_bounds); |
| 853 canvas->DrawImageInt(arrow, arrow_bounds.x(), arrow_bounds.y()); | 843 canvas->DrawImageInt(arrow, arrow_bounds.x(), arrow_bounds.y()); |
| 854 } | 844 } |
| 855 } | 845 } |
| 856 | 846 |
| 857 void MenuItemView::PaintMinorText(gfx::Canvas* canvas, | 847 void MenuItemView::PaintMinorText(gfx::Canvas* canvas, SkColor color) { |
| 858 bool render_selection) { | |
| 859 base::string16 minor_text = GetMinorText(); | 848 base::string16 minor_text = GetMinorText(); |
| 860 if (minor_text.empty()) | 849 if (minor_text.empty()) |
| 861 return; | 850 return; |
| 862 | 851 |
| 863 int available_height = height() - GetTopMargin() - GetBottomMargin(); | 852 int available_height = height() - GetTopMargin() - GetBottomMargin(); |
| 864 int max_accel_width = | 853 int max_accel_width = |
| 865 parent_menu_item_->GetSubmenu()->max_minor_text_width(); | 854 parent_menu_item_->GetSubmenu()->max_minor_text_width(); |
| 866 const MenuConfig& config = MenuConfig::instance(); | 855 const MenuConfig& config = MenuConfig::instance(); |
| 867 int accel_right_margin = config.align_arrow_and_shortcut ? | 856 int accel_right_margin = config.align_arrow_and_shortcut ? |
| 868 config.arrow_to_edge_padding : item_right_margin_; | 857 config.arrow_to_edge_padding : item_right_margin_; |
| 869 gfx::Rect accel_bounds(width() - accel_right_margin - max_accel_width, | 858 gfx::Rect accel_bounds(width() - accel_right_margin - max_accel_width, |
| 870 GetTopMargin(), max_accel_width, available_height); | 859 GetTopMargin(), max_accel_width, available_height); |
| 871 accel_bounds.set_x(GetMirroredXForRect(accel_bounds)); | 860 accel_bounds.set_x(GetMirroredXForRect(accel_bounds)); |
| 872 int flags = GetDrawStringFlags(); | 861 int flags = GetDrawStringFlags(); |
| 873 flags &= ~(gfx::Canvas::TEXT_ALIGN_RIGHT | gfx::Canvas::TEXT_ALIGN_LEFT); | 862 flags &= ~(gfx::Canvas::TEXT_ALIGN_RIGHT | gfx::Canvas::TEXT_ALIGN_LEFT); |
| 874 if (base::i18n::IsRTL()) | 863 if (base::i18n::IsRTL()) |
| 875 flags |= gfx::Canvas::TEXT_ALIGN_LEFT; | 864 flags |= gfx::Canvas::TEXT_ALIGN_LEFT; |
| 876 else | 865 else |
| 877 flags |= gfx::Canvas::TEXT_ALIGN_RIGHT; | 866 flags |= gfx::Canvas::TEXT_ALIGN_RIGHT; |
| 878 canvas->DrawStringRectWithFlags( | 867 canvas->DrawStringRectWithFlags(minor_text, GetFontList(), color, |
| 879 minor_text, | 868 accel_bounds, flags); |
| 880 GetFontList(), | 869 } |
| 881 GetNativeTheme()->GetSystemColor(render_selection ? | 870 |
| 882 ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor : | 871 SkColor MenuItemView::GetTextColor(bool minor, |
| 883 ui::NativeTheme::kColorId_MenuItemSubtitleColor), | 872 bool render_selection, |
| 884 accel_bounds, | 873 bool emphasized) const { |
| 885 flags); | 874 ui::NativeTheme::ColorId color_id = |
| 875 minor ? ui::NativeTheme::kColorId_MenuItemSubtitleColor |
| 876 : ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor; |
| 877 if (enabled()) { |
| 878 if (render_selection) |
| 879 color_id = ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor; |
| 880 } else { |
| 881 if (!emphasized) |
| 882 color_id = ui::NativeTheme::kColorId_DisabledMenuItemForegroundColor; |
| 883 } |
| 884 return GetNativeTheme()->GetSystemColor(color_id); |
| 886 } | 885 } |
| 887 | 886 |
| 888 void MenuItemView::DestroyAllMenuHosts() { | 887 void MenuItemView::DestroyAllMenuHosts() { |
| 889 if (!HasSubmenu()) | 888 if (!HasSubmenu()) |
| 890 return; | 889 return; |
| 891 | 890 |
| 892 submenu_->Close(); | 891 submenu_->Close(); |
| 893 for (int i = 0, item_count = submenu_->GetMenuItemCount(); i < item_count; | 892 for (int i = 0, item_count = submenu_->GetMenuItemCount(); i < item_count; |
| 894 ++i) { | 893 ++i) { |
| 895 submenu_->GetMenuItemAt(i)->DestroyAllMenuHosts(); | 894 submenu_->GetMenuItemAt(i)->DestroyAllMenuHosts(); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1067 } else { | 1066 } else { |
| 1068 const Type& type = menu_item->GetType(); | 1067 const Type& type = menu_item->GetType(); |
| 1069 if (type == CHECKBOX || type == RADIO) | 1068 if (type == CHECKBOX || type == RADIO) |
| 1070 return true; | 1069 return true; |
| 1071 } | 1070 } |
| 1072 } | 1071 } |
| 1073 return false; | 1072 return false; |
| 1074 } | 1073 } |
| 1075 | 1074 |
| 1076 } // namespace views | 1075 } // namespace views |
| OLD | NEW |