Home | History | Annotate | Download | only in menu
      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
      3 // found in the LICENSE file.
      4 
      5 #include "ui/views/controls/menu/menu_config.h"
      6 
      7 #include <windows.h>
      8 #include <uxtheme.h>
      9 #include <Vssym32.h>
     10 
     11 #include "base/logging.h"
     12 #include "base/win/scoped_gdi_object.h"
     13 #include "base/win/win_util.h"
     14 #include "ui/base/l10n/l10n_util_win.h"
     15 #include "ui/gfx/color_utils.h"
     16 #include "ui/native_theme/native_theme_aura.h"
     17 #include "ui/native_theme/native_theme_win.h"
     18 
     19 using ui::NativeTheme;
     20 using ui::NativeThemeWin;
     21 
     22 namespace views {
     23 
     24 void MenuConfig::Init(const NativeTheme* theme) {
     25   if (theme == ui::NativeThemeAura::instance()) {
     26     InitAura(theme);
     27     return;
     28   }
     29 
     30   arrow_color = color_utils::GetSysSkColor(COLOR_MENUTEXT);
     31 
     32   NONCLIENTMETRICS metrics;
     33   base::win::GetNonClientMetrics(&metrics);
     34   l10n_util::AdjustUIFont(&(metrics.lfMenuFont));
     35   {
     36     base::win::ScopedHFONT new_font(CreateFontIndirect(&metrics.lfMenuFont));
     37     DLOG_ASSERT(new_font.Get());
     38     font_list = gfx::FontList(gfx::Font(new_font));
     39   }
     40   NativeTheme::ExtraParams extra;
     41   extra.menu_check.is_radio = false;
     42   extra.menu_check.is_selected = false;
     43   gfx::Size check_size = NativeThemeWin::instance()->GetPartSize(
     44       NativeTheme::kMenuCheck, NativeTheme::kNormal, extra);
     45   if (!check_size.IsEmpty()) {
     46     check_width = check_size.width();
     47     check_height = check_size.height();
     48   } else {
     49     check_width = GetSystemMetrics(SM_CXMENUCHECK);
     50     check_height = GetSystemMetrics(SM_CYMENUCHECK);
     51   }
     52 
     53   extra.menu_check.is_radio = true;
     54   gfx::Size radio_size = NativeThemeWin::instance()->GetPartSize(
     55       NativeTheme::kMenuCheck, NativeTheme::kNormal, extra);
     56   if (!radio_size.IsEmpty())
     57     radio_width = radio_size.width();
     58   else
     59     radio_width = GetSystemMetrics(SM_CXMENUCHECK);
     60 
     61   gfx::Size arrow_size = NativeThemeWin::instance()->GetPartSize(
     62       NativeTheme::kMenuPopupArrow, NativeTheme::kNormal, extra);
     63   if (!arrow_size.IsEmpty()) {
     64     arrow_width = arrow_size.width();
     65   } else {
     66     // Sadly I didn't see a specify metrics for this.
     67     arrow_width = GetSystemMetrics(SM_CXMENUCHECK);
     68   }
     69 
     70   BOOL show_cues;
     71   show_mnemonics =
     72       (SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &show_cues, 0) &&
     73        show_cues == TRUE);
     74 
     75   SystemParametersInfo(SPI_GETMENUSHOWDELAY, 0, &show_delay, 0);
     76 
     77   separator_upper_height = 5;
     78   separator_lower_height = 7;
     79 }
     80 
     81 // static
     82 const MenuConfig& MenuConfig::instance(const ui::NativeTheme* theme) {
     83   // NOTE: |theme| may be NULL if used before the menu is running.
     84   if (!theme || theme == NativeThemeWin::instance()) {
     85     static MenuConfig* win_instance = NULL;
     86     if (!win_instance)
     87       win_instance = new MenuConfig(NativeThemeWin::instance());
     88     return *win_instance;
     89   }
     90   static MenuConfig* views_instance = NULL;
     91   if (!views_instance)
     92     views_instance = new MenuConfig(theme);
     93   return *views_instance;
     94 }
     95 
     96 }  // namespace views
     97