| OLD | NEW |
| 1 // Copyright (c) 2011 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/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
| 11 #include "ui/gfx/canvas_skia.h" | 11 #include "ui/gfx/canvas_skia.h" |
| 12 #include "ui/gfx/favicon_size.h" | 12 #include "ui/gfx/favicon_size.h" |
| 13 #include "ui/views/controls/button/text_button.h" | 13 #include "ui/gfx/native_theme.h" |
| 14 #include "ui/views/controls/menu/menu_config.h" | 14 #include "ui/views/controls/menu/menu_config.h" |
| 15 #include "ui/views/controls/menu/menu_image_util.h" | 15 #include "ui/views/controls/menu/menu_image_util.h" |
| 16 #include "ui/views/controls/menu/submenu_view.h" | 16 #include "ui/views/controls/menu/submenu_view.h" |
| 17 | 17 |
| 18 namespace views { | 18 namespace views { |
| 19 | 19 |
| 20 // Background color when the menu item is selected. | |
| 21 #if defined(OS_CHROMEOS) | |
| 22 static const SkColor kSelectedBackgroundColor = SkColorSetRGB(0xDC, 0xE4, 0xFA); | |
| 23 #else | |
| 24 static const SkColor kSelectedBackgroundColor = SkColorSetRGB(246, 249, 253); | |
| 25 #endif | |
| 26 | |
| 27 void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { | 20 void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { |
| 28 const MenuConfig& config = MenuConfig::instance(); | 21 const MenuConfig& config = MenuConfig::instance(); |
| 29 bool render_selection = | 22 bool render_selection = |
| 30 (mode == PB_NORMAL && IsSelected() && | 23 (mode == PB_NORMAL && IsSelected() && |
| 31 parent_menu_item_->GetSubmenu()->GetShowSelection(this) && | 24 parent_menu_item_->GetSubmenu()->GetShowSelection(this) && |
| 32 !has_children()); | 25 !has_children()); |
| 33 | 26 |
| 34 int icon_x = config.item_left_margin; | 27 int icon_x = config.item_left_margin; |
| 35 int top_margin = GetTopMargin(); | 28 int top_margin = GetTopMargin(); |
| 36 int bottom_margin = GetBottomMargin(); | 29 int bottom_margin = GetBottomMargin(); |
| 37 int icon_y = top_margin + (height() - config.item_top_margin - | 30 int icon_y = top_margin + (height() - config.item_top_margin - |
| 38 bottom_margin - config.check_height) / 2; | 31 bottom_margin - config.check_height) / 2; |
| 39 int icon_height = config.check_height; | 32 int icon_height = config.check_height; |
| 40 int available_height = height() - top_margin - bottom_margin; | 33 int available_height = height() - top_margin - bottom_margin; |
| 41 | 34 |
| 42 // Render the background. As MenuScrollViewContainer draws the background, we | 35 // Render the background. As MenuScrollViewContainer draws the background, we |
| 43 // only need the background when we want it to look different, as when we're | 36 // only need the background when we want it to look different, as when we're |
| 44 // selected. | 37 // selected. |
| 45 if (render_selection) | 38 if (render_selection) { |
| 46 canvas->GetSkCanvas()->drawColor(kSelectedBackgroundColor, | 39 SkColor bg_color = gfx::NativeTheme::instance()->GetSystemColor( |
| 47 SkXfermode::kSrc_Mode); | 40 gfx::NativeTheme::kColorId_FocusedMenuItemBackgroundColor); |
| 41 canvas->GetSkCanvas()->drawColor(bg_color, SkXfermode::kSrc_Mode); |
| 42 } |
| 48 | 43 |
| 49 // Render the check. | 44 // Render the check. |
| 50 if (type_ == CHECKBOX && GetDelegate()->IsItemChecked(GetCommand())) { | 45 if (type_ == CHECKBOX && GetDelegate()->IsItemChecked(GetCommand())) { |
| 51 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 46 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 52 SkBitmap* check = rb.GetBitmapNamed(IDR_MENU_CHECK); | 47 SkBitmap* check = rb.GetBitmapNamed(IDR_MENU_CHECK); |
| 53 // Don't use config.check_width here as it's padded to force more padding. | 48 // Don't use config.check_width here as it's padded to force more padding. |
| 54 gfx::Rect check_bounds(icon_x, icon_y, check->width(), icon_height); | 49 gfx::Rect check_bounds(icon_x, icon_y, check->width(), icon_height); |
| 55 AdjustBoundsForRTLUI(&check_bounds); | 50 AdjustBoundsForRTLUI(&check_bounds); |
| 56 canvas->DrawBitmapInt(*check, check_bounds.x(), check_bounds.y()); | 51 canvas->DrawBitmapInt(*check, check_bounds.x(), check_bounds.y()); |
| 57 } else if (type_ == RADIO) { | 52 } else if (type_ == RADIO) { |
| 58 const SkBitmap* image = | 53 const SkBitmap* image = |
| 59 GetRadioButtonImage(GetDelegate()->IsItemChecked(GetCommand())); | 54 GetRadioButtonImage(GetDelegate()->IsItemChecked(GetCommand())); |
| 60 gfx::Rect radio_bounds(icon_x, | 55 gfx::Rect radio_bounds(icon_x, |
| 61 top_margin + | 56 top_margin + |
| 62 (height() - top_margin - bottom_margin - | 57 (height() - top_margin - bottom_margin - |
| 63 image->height()) / 2, | 58 image->height()) / 2, |
| 64 image->width(), | 59 image->width(), |
| 65 image->height()); | 60 image->height()); |
| 66 AdjustBoundsForRTLUI(&radio_bounds); | 61 AdjustBoundsForRTLUI(&radio_bounds); |
| 67 canvas->DrawBitmapInt(*image, radio_bounds.x(), radio_bounds.y()); | 62 canvas->DrawBitmapInt(*image, radio_bounds.x(), radio_bounds.y()); |
| 68 } | 63 } |
| 69 | 64 |
| 70 // Render the foreground. | 65 // Render the foreground. |
| 71 #if defined(OS_CHROMEOS) | 66 SkColor fg_color = gfx::NativeTheme::instance()->GetSystemColor( |
| 72 SkColor fg_color = enabled() ? SK_ColorBLACK | 67 enabled() ? gfx::NativeTheme::kColorId_EnabledMenuItemForegroundColor |
| 73 : SkColorSetRGB(0x80, 0x80, 0x80); | 68 : gfx::NativeTheme::kColorId_DisabledMenuItemForegroundColor); |
| 74 #else | 69 |
| 75 SkColor fg_color = enabled() ? TextButton::kEnabledColor | |
| 76 : TextButton::kDisabledColor; | |
| 77 #endif | |
| 78 const gfx::Font& font = GetFont(); | 70 const gfx::Font& font = GetFont(); |
| 79 int accel_width = parent_menu_item_->GetSubmenu()->max_accelerator_width(); | 71 int accel_width = parent_menu_item_->GetSubmenu()->max_accelerator_width(); |
| 80 int width = this->width() - item_right_margin_ - label_start_ - accel_width; | 72 int width = this->width() - item_right_margin_ - label_start_ - accel_width; |
| 81 gfx::Rect text_bounds(label_start_, top_margin + | 73 gfx::Rect text_bounds(label_start_, top_margin + |
| 82 (available_height - font.GetHeight()) / 2, width, | 74 (available_height - font.GetHeight()) / 2, width, |
| 83 font.GetHeight()); | 75 font.GetHeight()); |
| 84 text_bounds.set_x(GetMirroredXForRect(text_bounds)); | 76 text_bounds.set_x(GetMirroredXForRect(text_bounds)); |
| 85 canvas->DrawStringInt(title(), font, fg_color, | 77 canvas->DrawStringInt(title(), font, fg_color, |
| 86 text_bounds.x(), text_bounds.y(), text_bounds.width(), | 78 text_bounds.x(), text_bounds.y(), text_bounds.width(), |
| 87 text_bounds.height(), | 79 text_bounds.height(), |
| (...skipping 19 matching lines...) Expand all Loading... |
| 107 top_margin + (available_height - | 99 top_margin + (available_height - |
| 108 config.arrow_width) / 2, | 100 config.arrow_width) / 2, |
| 109 config.arrow_width, height()); | 101 config.arrow_width, height()); |
| 110 AdjustBoundsForRTLUI(&arrow_bounds); | 102 AdjustBoundsForRTLUI(&arrow_bounds); |
| 111 canvas->DrawBitmapInt(*GetSubmenuArrowImage(), | 103 canvas->DrawBitmapInt(*GetSubmenuArrowImage(), |
| 112 arrow_bounds.x(), arrow_bounds.y()); | 104 arrow_bounds.x(), arrow_bounds.y()); |
| 113 } | 105 } |
| 114 } | 106 } |
| 115 | 107 |
| 116 } // namespace views | 108 } // namespace views |
| OLD | NEW |