| 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" | |
| 11 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
| 12 #include "ui/gfx/canvas.h" | 11 #include "ui/gfx/canvas.h" |
| 13 #include "ui/gfx/favicon_size.h" | 12 #include "ui/gfx/favicon_size.h" |
| 14 #include "ui/gfx/image/image.h" | 13 #include "ui/gfx/image/image.h" |
| 14 #include "ui/gfx/native_theme.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 !has_children()); |
| 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 |
| 37 // only need the background when we want it to look different, as when we're | 37 // only need the background when we want it to look different, as when we're |
| 38 // selected. | 38 // selected. |
| 39 if (render_selection) { | 39 if (render_selection) { |
| 40 SkColor bg_color = ui::NativeTheme::instance()->GetSystemColor( | 40 SkColor bg_color = gfx::NativeTheme::instance()->GetSystemColor( |
| 41 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor); | 41 gfx::NativeTheme::kColorId_FocusedMenuItemBackgroundColor); |
| 42 canvas->DrawColor(bg_color, SkXfermode::kSrc_Mode); | 42 canvas->DrawColor(bg_color, SkXfermode::kSrc_Mode); |
| 43 } | 43 } |
| 44 | 44 |
| 45 // Render the check. | 45 // Render the check. |
| 46 if (type_ == CHECKBOX && GetDelegate()->IsItemChecked(GetCommand())) { | 46 if (type_ == CHECKBOX && GetDelegate()->IsItemChecked(GetCommand())) { |
| 47 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 47 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 48 const SkBitmap* check = rb.GetImageNamed(IDR_MENU_CHECK).ToSkBitmap(); | 48 const SkBitmap* check = rb.GetImageNamed(IDR_MENU_CHECK).ToSkBitmap(); |
| 49 // Don't use config.check_width here as it's padded to force more padding. | 49 // Don't use config.check_width here as it's padded to force more padding. |
| 50 gfx::Rect check_bounds(icon_x, icon_y, check->width(), icon_height); | 50 gfx::Rect check_bounds(icon_x, icon_y, check->width(), icon_height); |
| 51 AdjustBoundsForRTLUI(&check_bounds); | 51 AdjustBoundsForRTLUI(&check_bounds); |
| 52 canvas->DrawBitmapInt(*check, check_bounds.x(), check_bounds.y()); | 52 canvas->DrawBitmapInt(*check, check_bounds.x(), check_bounds.y()); |
| 53 } else if (type_ == RADIO) { | 53 } else if (type_ == RADIO) { |
| 54 const SkBitmap* image = | 54 const SkBitmap* image = |
| 55 GetRadioButtonImage(GetDelegate()->IsItemChecked(GetCommand())); | 55 GetRadioButtonImage(GetDelegate()->IsItemChecked(GetCommand())); |
| 56 gfx::Rect radio_bounds(icon_x, | 56 gfx::Rect radio_bounds(icon_x, |
| 57 top_margin + | 57 top_margin + |
| 58 (height() - top_margin - bottom_margin - | 58 (height() - top_margin - bottom_margin - |
| 59 image->height()) / 2, | 59 image->height()) / 2, |
| 60 image->width(), | 60 image->width(), |
| 61 image->height()); | 61 image->height()); |
| 62 AdjustBoundsForRTLUI(&radio_bounds); | 62 AdjustBoundsForRTLUI(&radio_bounds); |
| 63 canvas->DrawBitmapInt(*image, radio_bounds.x(), radio_bounds.y()); | 63 canvas->DrawBitmapInt(*image, radio_bounds.x(), radio_bounds.y()); |
| 64 } | 64 } |
| 65 | 65 |
| 66 // Render the foreground. | 66 // Render the foreground. |
| 67 SkColor fg_color = ui::NativeTheme::instance()->GetSystemColor( | 67 SkColor fg_color = gfx::NativeTheme::instance()->GetSystemColor( |
| 68 enabled() ? ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor | 68 enabled() ? gfx::NativeTheme::kColorId_EnabledMenuItemForegroundColor |
| 69 : ui::NativeTheme::kColorId_DisabledMenuItemForegroundColor); | 69 : gfx::NativeTheme::kColorId_DisabledMenuItemForegroundColor); |
| 70 | 70 |
| 71 const gfx::Font& font = GetFont(); | 71 const gfx::Font& font = GetFont(); |
| 72 int accel_width = parent_menu_item_->GetSubmenu()->max_accelerator_width(); | 72 int accel_width = parent_menu_item_->GetSubmenu()->max_accelerator_width(); |
| 73 int width = this->width() - item_right_margin_ - label_start_ - accel_width; | 73 int width = this->width() - item_right_margin_ - label_start_ - accel_width; |
| 74 gfx::Rect text_bounds(label_start_, top_margin + | 74 gfx::Rect text_bounds(label_start_, top_margin + |
| 75 (available_height - font.GetHeight() + 1) / 2, width, | 75 (available_height - font.GetHeight() + 1) / 2, width, |
| 76 font.GetHeight()); | 76 font.GetHeight()); |
| 77 text_bounds.set_x(GetMirroredXForRect(text_bounds)); | 77 text_bounds.set_x(GetMirroredXForRect(text_bounds)); |
| 78 int flags = GetRootMenuItem()->GetDrawStringFlags(); | 78 int flags = GetRootMenuItem()->GetDrawStringFlags(); |
| 79 if (mode == PB_FOR_DRAG) | 79 if (mode == PB_FOR_DRAG) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 108 top_margin + (available_height - | 108 top_margin + (available_height - |
| 109 config.arrow_width) / 2, | 109 config.arrow_width) / 2, |
| 110 config.arrow_width, height()); | 110 config.arrow_width, height()); |
| 111 AdjustBoundsForRTLUI(&arrow_bounds); | 111 AdjustBoundsForRTLUI(&arrow_bounds); |
| 112 canvas->DrawBitmapInt(*GetSubmenuArrowImage(), | 112 canvas->DrawBitmapInt(*GetSubmenuArrowImage(), |
| 113 arrow_bounds.x(), arrow_bounds.y()); | 113 arrow_bounds.x(), arrow_bounds.y()); |
| 114 } | 114 } |
| 115 } | 115 } |
| 116 | 116 |
| 117 } // namespace views | 117 } // namespace views |
| OLD | NEW |