| OLD | NEW |
| 1 // Copyright (c) 2012 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_config.h" | 5 #include "ui/views/controls/menu/menu_config.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <uxtheme.h> | 8 #include <uxtheme.h> |
| 9 #include <Vssym32.h> | 9 #include <Vssym32.h> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/win/scoped_gdi_object.h" | 12 #include "base/win/scoped_gdi_object.h" |
| 13 #include "base/win/win_util.h" | 13 #include "base/win/win_util.h" |
| 14 #include "ui/base/l10n/l10n_util_win.h" | 14 #include "ui/base/l10n/l10n_util_win.h" |
| 15 #include "ui/base/native_theme/native_theme_win.h" | 15 #include "ui/base/native_theme/native_theme_win.h" |
| 16 | 16 |
| 17 using ui::NativeTheme; | 17 using ui::NativeTheme; |
| 18 using ui::NativeThemeWin; | 18 using ui::NativeThemeWin; |
| 19 | 19 |
| 20 namespace views { | 20 namespace views { |
| 21 | 21 |
| 22 // static | 22 void MenuConfig::Init() { |
| 23 MenuConfig* MenuConfig::Create() { | 23 text_color = NativeThemeWin::instance()->GetThemeColorWithDefault( |
| 24 MenuConfig* config = new MenuConfig(); | |
| 25 | |
| 26 config->text_color = NativeThemeWin::instance()->GetThemeColorWithDefault( | |
| 27 NativeThemeWin::MENU, MENU_POPUPITEM, MPI_NORMAL, TMT_TEXTCOLOR, | 24 NativeThemeWin::MENU, MENU_POPUPITEM, MPI_NORMAL, TMT_TEXTCOLOR, |
| 28 COLOR_MENUTEXT); | 25 COLOR_MENUTEXT); |
| 29 | 26 |
| 30 NONCLIENTMETRICS metrics; | 27 NONCLIENTMETRICS metrics; |
| 31 base::win::GetNonClientMetrics(&metrics); | 28 base::win::GetNonClientMetrics(&metrics); |
| 32 l10n_util::AdjustUIFont(&(metrics.lfMenuFont)); | 29 l10n_util::AdjustUIFont(&(metrics.lfMenuFont)); |
| 33 { | 30 { |
| 34 base::win::ScopedHFONT font(CreateFontIndirect(&metrics.lfMenuFont)); | 31 base::win::ScopedHFONT new_font(CreateFontIndirect(&metrics.lfMenuFont)); |
| 35 DLOG_ASSERT(font.Get()); | 32 DLOG_ASSERT(new_font.Get()); |
| 36 config->font = gfx::Font(font); | 33 font = gfx::Font(new_font); |
| 37 } | 34 } |
| 38 NativeTheme::ExtraParams extra; | 35 NativeTheme::ExtraParams extra; |
| 39 extra.menu_check.is_radio = false; | 36 extra.menu_check.is_radio = false; |
| 40 extra.menu_check.is_selected = false; | 37 extra.menu_check.is_selected = false; |
| 41 gfx::Size check_size = NativeTheme::instance()->GetPartSize( | 38 gfx::Size check_size = NativeTheme::instance()->GetPartSize( |
| 42 NativeTheme::kMenuCheck, NativeTheme::kNormal, extra); | 39 NativeTheme::kMenuCheck, NativeTheme::kNormal, extra); |
| 43 if (!check_size.IsEmpty()) { | 40 if (!check_size.IsEmpty()) { |
| 44 config->check_width = check_size.width(); | 41 check_width = check_size.width(); |
| 45 config->check_height = check_size.height(); | 42 check_height = check_size.height(); |
| 46 } else { | 43 } else { |
| 47 config->check_width = GetSystemMetrics(SM_CXMENUCHECK); | 44 check_width = GetSystemMetrics(SM_CXMENUCHECK); |
| 48 config->check_height = GetSystemMetrics(SM_CYMENUCHECK); | 45 check_height = GetSystemMetrics(SM_CYMENUCHECK); |
| 49 } | 46 } |
| 50 | 47 |
| 51 extra.menu_check.is_radio = true; | 48 extra.menu_check.is_radio = true; |
| 52 gfx::Size radio_size = NativeTheme::instance()->GetPartSize( | 49 gfx::Size radio_size = NativeTheme::instance()->GetPartSize( |
| 53 NativeTheme::kMenuCheck, NativeTheme::kNormal, extra); | 50 NativeTheme::kMenuCheck, NativeTheme::kNormal, extra); |
| 54 if (!radio_size.IsEmpty()) { | 51 if (!radio_size.IsEmpty()) { |
| 55 config->radio_width = radio_size.width(); | 52 radio_width = radio_size.width(); |
| 56 config->radio_height = radio_size.height(); | 53 radio_height = radio_size.height(); |
| 57 } else { | 54 } else { |
| 58 config->radio_width = GetSystemMetrics(SM_CXMENUCHECK); | 55 radio_width = GetSystemMetrics(SM_CXMENUCHECK); |
| 59 config->radio_height = GetSystemMetrics(SM_CYMENUCHECK); | 56 radio_height = GetSystemMetrics(SM_CYMENUCHECK); |
| 60 } | 57 } |
| 61 | 58 |
| 62 gfx::Size arrow_size = NativeTheme::instance()->GetPartSize( | 59 gfx::Size arrow_size = NativeTheme::instance()->GetPartSize( |
| 63 NativeTheme::kMenuPopupArrow, NativeTheme::kNormal, extra); | 60 NativeTheme::kMenuPopupArrow, NativeTheme::kNormal, extra); |
| 64 if (!arrow_size.IsEmpty()) { | 61 if (!arrow_size.IsEmpty()) { |
| 65 config->arrow_width = arrow_size.width(); | 62 arrow_width = arrow_size.width(); |
| 66 config->arrow_height = arrow_size.height(); | 63 arrow_height = arrow_size.height(); |
| 67 } else { | 64 } else { |
| 68 // Sadly I didn't see a specify metrics for this. | 65 // Sadly I didn't see a specify metrics for this. |
| 69 config->arrow_width = GetSystemMetrics(SM_CXMENUCHECK); | 66 arrow_width = GetSystemMetrics(SM_CXMENUCHECK); |
| 70 config->arrow_height = GetSystemMetrics(SM_CYMENUCHECK); | 67 arrow_height = GetSystemMetrics(SM_CYMENUCHECK); |
| 71 } | 68 } |
| 72 | 69 |
| 73 gfx::Size gutter_size = NativeTheme::instance()->GetPartSize( | 70 gfx::Size gutter_size = NativeTheme::instance()->GetPartSize( |
| 74 NativeTheme::kMenuPopupGutter, NativeTheme::kNormal, extra); | 71 NativeTheme::kMenuPopupGutter, NativeTheme::kNormal, extra); |
| 75 if (!gutter_size.IsEmpty()) { | 72 if (!gutter_size.IsEmpty()) { |
| 76 config->gutter_width = gutter_size.width(); | 73 gutter_width = gutter_size.width(); |
| 77 config->render_gutter = true; | 74 render_gutter = true; |
| 78 } else { | 75 } else { |
| 79 config->gutter_width = 0; | 76 gutter_width = 0; |
| 80 config->render_gutter = false; | 77 render_gutter = false; |
| 81 } | 78 } |
| 82 | 79 |
| 83 gfx::Size separator_size = NativeTheme::instance()->GetPartSize( | 80 gfx::Size separator_size = NativeTheme::instance()->GetPartSize( |
| 84 NativeTheme::kMenuPopupSeparator, NativeTheme::kNormal, extra); | 81 NativeTheme::kMenuPopupSeparator, NativeTheme::kNormal, extra); |
| 85 if (!separator_size.IsEmpty()) { | 82 if (!separator_size.IsEmpty()) { |
| 86 config->separator_height = separator_size.height(); | 83 separator_height = separator_size.height(); |
| 87 } else { | 84 } else { |
| 88 // -1 makes separator centered. | 85 // -1 makes separator centered. |
| 89 config->separator_height = GetSystemMetrics(SM_CYMENU) / 2 - 1; | 86 separator_height = GetSystemMetrics(SM_CYMENU) / 2 - 1; |
| 90 } | 87 } |
| 91 | 88 |
| 92 // On Windows, having some menus use wider spacing than others looks wrong. | 89 // On Windows, having some menus use wider spacing than others looks wrong. |
| 93 // See http://crbug.com/88875 | 90 // See http://crbug.com/88875 |
| 94 config->item_no_icon_bottom_margin = config->item_bottom_margin; | 91 item_no_icon_bottom_margin = item_bottom_margin; |
| 95 config->item_no_icon_top_margin = config->item_top_margin; | 92 item_no_icon_top_margin = item_top_margin; |
| 96 | 93 |
| 97 BOOL show_cues; | 94 BOOL show_cues; |
| 98 config->show_mnemonics = | 95 show_mnemonics = |
| 99 (SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &show_cues, 0) && | 96 (SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &show_cues, 0) && |
| 100 show_cues == TRUE); | 97 show_cues == TRUE); |
| 101 return config; | |
| 102 } | 98 } |
| 103 | 99 |
| 104 } // namespace views | 100 } // namespace views |
| OLD | NEW |