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