| 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/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "grit/ui_resources.h" | 8 #include "grit/ui_resources.h" |
| 9 #include "third_party/skia/include/effects/SkGradientShader.h" | 9 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 10 #include "ui/base/native_theme/native_theme.h" | 10 #include "ui/base/native_theme/native_theme.h" |
| 11 #include "ui/base/resource/resource_bundle.h" | 11 #include "ui/base/resource/resource_bundle.h" |
| 12 #include "ui/gfx/canvas.h" | 12 #include "ui/gfx/canvas.h" |
| 13 #include "ui/gfx/favicon_size.h" | 13 #include "ui/gfx/favicon_size.h" |
| 14 #include "ui/gfx/image/image.h" | 14 #include "ui/gfx/image/image.h" |
| 15 #include "ui/views/controls/menu/menu_config.h" | 15 #include "ui/views/controls/menu/menu_config.h" |
| 16 #include "ui/views/controls/menu/menu_image_util.h" | 16 #include "ui/views/controls/menu/menu_image_util.h" |
| 17 #include "ui/views/controls/menu/submenu_view.h" | 17 #include "ui/views/controls/menu/submenu_view.h" |
| 18 | 18 |
| 19 namespace views { | 19 namespace views { |
| 20 | 20 |
| 21 void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { | 21 void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { |
| 22 const MenuConfig& config = MenuConfig::instance(); | 22 const MenuConfig& config = MenuConfig::instance(); |
| 23 bool render_selection = | 23 bool render_selection = |
| 24 (mode == PB_NORMAL && IsSelected() && | 24 (mode == PB_NORMAL && IsSelected() && |
| 25 parent_menu_item_->GetSubmenu()->GetShowSelection(this) && | 25 parent_menu_item_->GetSubmenu()->GetShowSelection(this) && |
| 26 !has_children()); | 26 (NonIconChildViewsCount() == 0)); |
| 27 | 27 |
| 28 int icon_x = config.item_left_margin; | 28 int icon_x = config.item_left_margin; |
| 29 int top_margin = GetTopMargin(); | 29 int top_margin = GetTopMargin(); |
| 30 int bottom_margin = GetBottomMargin(); | 30 int bottom_margin = GetBottomMargin(); |
| 31 int icon_y = top_margin + (height() - config.item_top_margin - | 31 int icon_y = top_margin + (height() - config.item_top_margin - |
| 32 bottom_margin - config.check_height) / 2; | 32 bottom_margin - config.check_height) / 2; |
| 33 int icon_height = config.check_height; | 33 int icon_height = config.check_height; |
| 34 int available_height = height() - top_margin - bottom_margin; | 34 int available_height = height() - top_margin - bottom_margin; |
| 35 | 35 |
| 36 // Render the background. As MenuScrollViewContainer draws the background, we | 36 // Render the background. As MenuScrollViewContainer draws the background, we |
| (...skipping 28 matching lines...) Expand all Loading... |
| 65 } | 65 } |
| 66 | 66 |
| 67 // Render the foreground. | 67 // Render the foreground. |
| 68 SkColor fg_color = ui::NativeTheme::instance()->GetSystemColor( | 68 SkColor fg_color = ui::NativeTheme::instance()->GetSystemColor( |
| 69 enabled() ? ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor | 69 enabled() ? ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor |
| 70 : ui::NativeTheme::kColorId_DisabledMenuItemForegroundColor); | 70 : ui::NativeTheme::kColorId_DisabledMenuItemForegroundColor); |
| 71 | 71 |
| 72 const gfx::Font& font = GetFont(); | 72 const gfx::Font& font = GetFont(); |
| 73 int accel_width = parent_menu_item_->GetSubmenu()->max_accelerator_width(); | 73 int accel_width = parent_menu_item_->GetSubmenu()->max_accelerator_width(); |
| 74 int width = this->width() - item_right_margin_ - label_start_ - accel_width; | 74 int width = this->width() - item_right_margin_ - label_start_ - accel_width; |
| 75 gfx::Rect text_bounds(label_start_, top_margin + | 75 gfx::Rect text_bounds(label_start_, top_margin, width, available_height); |
| 76 (available_height - font.GetHeight() + 1) / 2, width, | |
| 77 font.GetHeight()); | |
| 78 text_bounds.set_x(GetMirroredXForRect(text_bounds)); | 76 text_bounds.set_x(GetMirroredXForRect(text_bounds)); |
| 79 int flags = GetRootMenuItem()->GetDrawStringFlags(); | 77 int flags = GetRootMenuItem()->GetDrawStringFlags() | |
| 78 gfx::Canvas::TEXT_VALIGN_MIDDLE; |
| 80 if (mode == PB_FOR_DRAG) | 79 if (mode == PB_FOR_DRAG) |
| 81 flags |= gfx::Canvas::NO_SUBPIXEL_RENDERING; | 80 flags |= gfx::Canvas::NO_SUBPIXEL_RENDERING; |
| 82 canvas->DrawStringInt(title(), font, fg_color, | 81 canvas->DrawStringInt(title(), font, fg_color, |
| 83 text_bounds.x(), text_bounds.y(), text_bounds.width(), | 82 text_bounds.x(), text_bounds.y(), text_bounds.width(), |
| 84 text_bounds.height(), flags); | 83 text_bounds.height(), flags); |
| 85 | 84 |
| 86 PaintAccelerator(canvas); | 85 PaintAccelerator(canvas); |
| 87 | 86 |
| 88 // Render the icon. | |
| 89 if (icon_.width() > 0) { | |
| 90 gfx::Rect icon_bounds(config.item_left_margin, | |
| 91 top_margin + (height() - top_margin - | |
| 92 bottom_margin - icon_.height()) / 2, | |
| 93 icon_.width(), | |
| 94 icon_.height()); | |
| 95 icon_bounds.set_x(GetMirroredXForRect(icon_bounds)); | |
| 96 if (!enabled()) { | |
| 97 SkPaint paint; | |
| 98 paint.setAlpha(120); | |
| 99 canvas->DrawImageInt(icon_, icon_bounds.x(), icon_bounds.y(), paint); | |
| 100 } else { | |
| 101 canvas->DrawImageInt(icon_, icon_bounds.x(), icon_bounds.y()); | |
| 102 } | |
| 103 } | |
| 104 | |
| 105 // Render the submenu indicator (arrow). | 87 // Render the submenu indicator (arrow). |
| 106 if (HasSubmenu()) { | 88 if (HasSubmenu()) { |
| 107 gfx::Rect arrow_bounds(this->width() - config.arrow_width - | 89 gfx::Rect arrow_bounds(this->width() - config.arrow_width - |
| 108 config.arrow_to_edge_padding, | 90 config.arrow_to_edge_padding, |
| 109 top_margin + (available_height - | 91 top_margin + (available_height - |
| 110 config.arrow_width) / 2, | 92 config.arrow_width) / 2, |
| 111 config.arrow_width, height()); | 93 config.arrow_width, height()); |
| 112 AdjustBoundsForRTLUI(&arrow_bounds); | 94 AdjustBoundsForRTLUI(&arrow_bounds); |
| 113 canvas->DrawImageInt(*GetSubmenuArrowImage(), | 95 canvas->DrawImageInt(*GetSubmenuArrowImage(), |
| 114 arrow_bounds.x(), arrow_bounds.y()); | 96 arrow_bounds.x(), arrow_bounds.y()); |
| 115 } | 97 } |
| 116 } | 98 } |
| 117 | 99 |
| 118 } // namespace views | 100 } // namespace views |
| OLD | NEW |