| 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 // TODO(sky): this is a workaround until I figure out why font.height() | 29 // TODO(sky): this is a workaround until I figure out why font.height() |
| 30 // isn't returning the right thing. We really only want to include | 30 // isn't returning the right thing. We really only want to include |
| 31 // kFaviconSize if we're showing icons. | 31 // kFaviconSize if we're showing icons. |
| 32 int content_height = std::max(kFaviconSize, font.GetHeight()); | 32 int content_height = std::max(kFaviconSize, font.GetHeight()); |
| 33 return gfx::Size( | 33 return gfx::Size( |
| 34 font.GetStringWidth(title_) + label_start_ + | 34 font.GetStringWidth(title_) + label_start_ + |
| 35 item_right_margin_ + GetChildPreferredWidth(), | 35 item_right_margin_ + GetChildPreferredWidth(), |
| 36 content_height + GetBottomMargin() + GetTopMargin()); | 36 content_height + GetBottomMargin() + GetTopMargin()); |
| 37 } | 37 } |
| 38 | 38 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 } | 80 } |
| 81 | 81 |
| 82 // Render the foreground. | 82 // Render the foreground. |
| 83 #if defined(OS_CHROMEOS) | 83 #if defined(OS_CHROMEOS) |
| 84 SkColor fg_color = | 84 SkColor fg_color = |
| 85 IsEnabled() ? SK_ColorBLACK : SkColorSetRGB(0x80, 0x80, 0x80); | 85 IsEnabled() ? SK_ColorBLACK : SkColorSetRGB(0x80, 0x80, 0x80); |
| 86 #else | 86 #else |
| 87 SkColor fg_color = | 87 SkColor fg_color = |
| 88 IsEnabled() ? TextButton::kEnabledColor : TextButton::kDisabledColor; | 88 IsEnabled() ? TextButton::kEnabledColor : TextButton::kDisabledColor; |
| 89 #endif | 89 #endif |
| 90 const gfx::Font& font = MenuConfig::instance().font; | 90 const gfx::Font& font = GetFont(); |
| 91 int accel_width = parent_menu_item_->GetSubmenu()->max_accelerator_width(); | 91 int accel_width = parent_menu_item_->GetSubmenu()->max_accelerator_width(); |
| 92 int width = this->width() - item_right_margin_ - label_start_ - accel_width; | 92 int width = this->width() - item_right_margin_ - label_start_ - accel_width; |
| 93 gfx::Rect text_bounds(label_start_, top_margin + | 93 gfx::Rect text_bounds(label_start_, top_margin + |
| 94 (available_height - font.GetHeight()) / 2, width, | 94 (available_height - font.GetHeight()) / 2, width, |
| 95 font.GetHeight()); | 95 font.GetHeight()); |
| 96 text_bounds.set_x(GetMirroredXForRect(text_bounds)); | 96 text_bounds.set_x(GetMirroredXForRect(text_bounds)); |
| 97 canvas->DrawStringInt(WideToUTF16Hack(GetTitle()), font, fg_color, | 97 canvas->DrawStringInt(WideToUTF16Hack(GetTitle()), font, fg_color, |
| 98 text_bounds.x(), text_bounds.y(), text_bounds.width(), | 98 text_bounds.x(), text_bounds.y(), text_bounds.width(), |
| 99 text_bounds.height(), | 99 text_bounds.height(), |
| 100 GetRootMenuItem()->GetDrawStringFlags()); | 100 GetRootMenuItem()->GetDrawStringFlags()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 119 top_margin + (available_height - | 119 top_margin + (available_height - |
| 120 config.arrow_width) / 2, | 120 config.arrow_width) / 2, |
| 121 config.arrow_width, height()); | 121 config.arrow_width, height()); |
| 122 AdjustBoundsForRTLUI(&arrow_bounds); | 122 AdjustBoundsForRTLUI(&arrow_bounds); |
| 123 canvas->DrawBitmapInt(*GetSubmenuArrowImage(), | 123 canvas->DrawBitmapInt(*GetSubmenuArrowImage(), |
| 124 arrow_bounds.x(), arrow_bounds.y()); | 124 arrow_bounds.x(), arrow_bounds.y()); |
| 125 } | 125 } |
| 126 } | 126 } |
| 127 | 127 |
| 128 } // namespace views | 128 } // namespace views |
| OLD | NEW |