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