| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <uxtheme.h> | 7 #include <uxtheme.h> |
| 8 #include <Vssym32.h> | 8 #include <Vssym32.h> |
| 9 | 9 |
| 10 #include "gfx/canvas_skia.h" | 10 #include "gfx/canvas_skia.h" |
| 11 #include "gfx/native_theme_win.h" | 11 #include "gfx/native_theme_win.h" |
| 12 #include "grit/app_strings.h" | 12 #include "grit/app_strings.h" |
| 13 #include "views/controls/menu/menu_config.h" | 13 #include "views/controls/menu/menu_config.h" |
| 14 #include "views/controls/menu/submenu_view.h" | 14 #include "views/controls/menu/submenu_view.h" |
| 15 | 15 |
| 16 using gfx::NativeTheme; | 16 using gfx::NativeTheme; |
| 17 | 17 |
| 18 namespace views { | 18 namespace views { |
| 19 | 19 |
| 20 gfx::Size MenuItemView::GetPreferredSize() { | 20 gfx::Size MenuItemView::GetPreferredSize() { |
| 21 const gfx::Font& font = MenuConfig::instance().font; | 21 const gfx::Font& font = MenuConfig::instance().font; |
| 22 return gfx::Size( | 22 return gfx::Size( |
| 23 font.GetStringWidth(title_) + label_start_ + item_right_margin_ + | 23 font.GetStringWidth(title_) + label_start_ + item_right_margin_ + |
| 24 GetChildPreferredWidth(), | 24 GetChildPreferredWidth(), |
| 25 font.height() + GetBottomMargin() + GetTopMargin()); | 25 font.GetHeight() + GetBottomMargin() + GetTopMargin()); |
| 26 } | 26 } |
| 27 | 27 |
| 28 void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) { | 28 void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) { |
| 29 const MenuConfig& config = MenuConfig::instance(); | 29 const MenuConfig& config = MenuConfig::instance(); |
| 30 bool render_selection = | 30 bool render_selection = |
| 31 (!for_drag && IsSelected() && | 31 (!for_drag && IsSelected() && |
| 32 parent_menu_item_->GetSubmenu()->GetShowSelection(this) && | 32 parent_menu_item_->GetSubmenu()->GetShowSelection(this) && |
| 33 GetChildViewCount() == 0); | 33 GetChildViewCount() == 0); |
| 34 int state = render_selection ? MPI_HOT : | 34 int state = render_selection ? MPI_HOT : |
| 35 (IsEnabled() ? MPI_NORMAL : MPI_DISABLED); | 35 (IsEnabled() ? MPI_NORMAL : MPI_DISABLED); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 // Menu color is specific to Vista, fallback to classic colors if can't | 80 // Menu color is specific to Vista, fallback to classic colors if can't |
| 81 // get color. | 81 // get color. |
| 82 int default_sys_color = render_selection ? COLOR_HIGHLIGHTTEXT : | 82 int default_sys_color = render_selection ? COLOR_HIGHLIGHTTEXT : |
| 83 (IsEnabled() ? COLOR_MENUTEXT : COLOR_GRAYTEXT); | 83 (IsEnabled() ? COLOR_MENUTEXT : COLOR_GRAYTEXT); |
| 84 SkColor fg_color = NativeTheme::instance()->GetThemeColorWithDefault( | 84 SkColor fg_color = NativeTheme::instance()->GetThemeColorWithDefault( |
| 85 NativeTheme::MENU, MENU_POPUPITEM, state, TMT_TEXTCOLOR, | 85 NativeTheme::MENU, MENU_POPUPITEM, state, TMT_TEXTCOLOR, |
| 86 default_sys_color); | 86 default_sys_color); |
| 87 const gfx::Font& font = MenuConfig::instance().font; | 87 const gfx::Font& font = MenuConfig::instance().font; |
| 88 int accel_width = parent_menu_item_->GetSubmenu()->max_accelerator_width(); | 88 int accel_width = parent_menu_item_->GetSubmenu()->max_accelerator_width(); |
| 89 int width = this->width() - item_right_margin_ - label_start_ - accel_width; | 89 int width = this->width() - item_right_margin_ - label_start_ - accel_width; |
| 90 gfx::Rect text_bounds(label_start_, top_margin, width, font.height()); | 90 gfx::Rect text_bounds(label_start_, top_margin, width, font.GetHeight()); |
| 91 text_bounds.set_x(MirroredLeftPointForRect(text_bounds)); | 91 text_bounds.set_x(MirroredLeftPointForRect(text_bounds)); |
| 92 if (for_drag) { | 92 if (for_drag) { |
| 93 // With different themes, it's difficult to tell what the correct | 93 // With different themes, it's difficult to tell what the correct |
| 94 // foreground and background colors are for the text to draw the correct | 94 // foreground and background colors are for the text to draw the correct |
| 95 // halo. Instead, just draw black on white, which will look good in most | 95 // halo. Instead, just draw black on white, which will look good in most |
| 96 // cases. | 96 // cases. |
| 97 canvas->AsCanvasSkia()->DrawStringWithHalo( | 97 canvas->AsCanvasSkia()->DrawStringWithHalo( |
| 98 GetTitle(), font, 0x00000000, 0xFFFFFFFF, text_bounds.x(), | 98 GetTitle(), font, 0x00000000, 0xFFFFFFFF, text_bounds.x(), |
| 99 text_bounds.y(), text_bounds.width(), text_bounds.height(), | 99 text_bounds.y(), text_bounds.width(), text_bounds.height(), |
| 100 GetRootMenuItem()->GetDrawStringFlags()); | 100 GetRootMenuItem()->GetDrawStringFlags()); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 // And the check. | 162 // And the check. |
| 163 gfx::Rect icon_bounds(icon_x / 2, icon_y, icon_width, icon_height); | 163 gfx::Rect icon_bounds(icon_x / 2, icon_y, icon_width, icon_height); |
| 164 AdjustBoundsForRTLUI(&icon_bounds); | 164 AdjustBoundsForRTLUI(&icon_bounds); |
| 165 RECT icon_rect = icon_bounds.ToRECT(); | 165 RECT icon_rect = icon_bounds.ToRECT(); |
| 166 NativeTheme::instance()->PaintMenuCheck( | 166 NativeTheme::instance()->PaintMenuCheck( |
| 167 NativeTheme::MENU, dc, MENU_POPUPCHECK, state_id, &icon_rect, | 167 NativeTheme::MENU, dc, MENU_POPUPCHECK, state_id, &icon_rect, |
| 168 control_state); | 168 control_state); |
| 169 } | 169 } |
| 170 | 170 |
| 171 } // namespace views | 171 } // namespace views |
| OLD | NEW |