| OLD | NEW |
| 1 // Copyright (c) 2011 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 "views/controls/menu/menu_item_view.h" | 5 #include "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/app_resources.h" | 8 #include "grit/app_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 "views/controls/button/text_button.h" | 13 #include "views/controls/button/text_button.h" |
| 14 #include "views/controls/menu/menu_config.h" | 14 #include "views/controls/menu/menu_config.h" |
| 15 #include "views/controls/menu/menu_image_util_gtk.h" | 15 #include "views/controls/menu/menu_image_util_gtk.h" |
| 16 #include "views/controls/menu/submenu_view.h" | 16 #include "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. | 20 // Background color when the menu item is selected. |
| 21 #if defined(OS_CHROMEOS) | 21 #if defined(OS_CHROMEOS) |
| 22 static const SkColor kSelectedBackgroundColor = SkColorSetRGB(0xDC, 0xE4, 0xFA); | 22 static const SkColor kSelectedBackgroundColor = SkColorSetRGB(0xDC, 0xE4, 0xFA); |
| 23 #else | 23 #else |
| 24 static const SkColor kSelectedBackgroundColor = SkColorSetRGB(246, 249, 253); | 24 static const SkColor kSelectedBackgroundColor = SkColorSetRGB(246, 249, 253); |
| 25 #endif | 25 #endif |
| 26 | 26 |
| 27 gfx::Size MenuItemView::CalculatePreferredSize() { | 27 gfx::Size MenuItemView::CalculatePreferredSize() { |
| 28 const gfx::Font& font = MenuConfig::instance().font; | 28 const gfx::Font& font = GetFont(); |
| 29 return gfx::Size( | 29 return gfx::Size( |
| 30 font.GetStringWidth(title_) + label_start_ + | 30 font.GetStringWidth(title_) + label_start_ + |
| 31 item_right_margin_ + GetChildPreferredWidth(), | 31 item_right_margin_ + GetChildPreferredWidth(), |
| 32 font.GetHeight() + GetBottomMargin() + GetTopMargin()); | 32 font.GetHeight() + GetBottomMargin() + GetTopMargin()); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { | 35 void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { |
| 36 const MenuConfig& config = MenuConfig::instance(); | 36 const MenuConfig& config = MenuConfig::instance(); |
| 37 bool render_selection = | 37 bool render_selection = |
| 38 (mode == PB_NORMAL && IsSelected() && | 38 (mode == PB_NORMAL && IsSelected() && |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 } | 76 } |
| 77 | 77 |
| 78 // Render the foreground. | 78 // Render the foreground. |
| 79 #if defined(OS_CHROMEOS) | 79 #if defined(OS_CHROMEOS) |
| 80 SkColor fg_color = | 80 SkColor fg_color = |
| 81 IsEnabled() ? SK_ColorBLACK : SkColorSetRGB(0x80, 0x80, 0x80); | 81 IsEnabled() ? SK_ColorBLACK : SkColorSetRGB(0x80, 0x80, 0x80); |
| 82 #else | 82 #else |
| 83 SkColor fg_color = | 83 SkColor fg_color = |
| 84 IsEnabled() ? TextButton::kEnabledColor : TextButton::kDisabledColor; | 84 IsEnabled() ? TextButton::kEnabledColor : TextButton::kDisabledColor; |
| 85 #endif | 85 #endif |
| 86 const gfx::Font& font = MenuConfig::instance().font; | 86 const gfx::Font& font = GetFont(); |
| 87 int accel_width = parent_menu_item_->GetSubmenu()->max_accelerator_width(); | 87 int accel_width = parent_menu_item_->GetSubmenu()->max_accelerator_width(); |
| 88 int width = this->width() - item_right_margin_ - label_start_ - accel_width; | 88 int width = this->width() - item_right_margin_ - label_start_ - accel_width; |
| 89 gfx::Rect text_bounds(label_start_, top_margin + | 89 gfx::Rect text_bounds(label_start_, top_margin + |
| 90 (available_height - font.GetHeight()) / 2, width, | 90 (available_height - font.GetHeight()) / 2, width, |
| 91 font.GetHeight()); | 91 font.GetHeight()); |
| 92 text_bounds.set_x(GetMirroredXForRect(text_bounds)); | 92 text_bounds.set_x(GetMirroredXForRect(text_bounds)); |
| 93 canvas->DrawStringInt(WideToUTF16Hack(GetTitle()), font, fg_color, | 93 canvas->DrawStringInt(WideToUTF16Hack(GetTitle()), font, fg_color, |
| 94 text_bounds.x(), text_bounds.y(), text_bounds.width(), | 94 text_bounds.x(), text_bounds.y(), text_bounds.width(), |
| 95 text_bounds.height(), | 95 text_bounds.height(), |
| 96 GetRootMenuItem()->GetDrawStringFlags()); | 96 GetRootMenuItem()->GetDrawStringFlags()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 115 top_margin + (available_height - | 115 top_margin + (available_height - |
| 116 config.arrow_width) / 2, | 116 config.arrow_width) / 2, |
| 117 config.arrow_width, height()); | 117 config.arrow_width, height()); |
| 118 AdjustBoundsForRTLUI(&arrow_bounds); | 118 AdjustBoundsForRTLUI(&arrow_bounds); |
| 119 canvas->DrawBitmapInt(*GetSubmenuArrowImage(), | 119 canvas->DrawBitmapInt(*GetSubmenuArrowImage(), |
| 120 arrow_bounds.x(), arrow_bounds.y()); | 120 arrow_bounds.x(), arrow_bounds.y()); |
| 121 } | 121 } |
| 122 } | 122 } |
| 123 | 123 |
| 124 } // namespace views | 124 } // namespace views |
| OLD | NEW |