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_win.h"
     17 
     18 #if defined(USE_AURA)
     19 #include "ui/native_theme/native_theme_aura.h"
     20 #endif
     21 
     22 using ui::NativeTheme;
     23 using ui::NativeThemeWin;
     24 
     25 namespace views {
     26 
     27 void MenuConfig::Init(const NativeTheme* theme) {
     28 #if defined(USE_AURA)
     29   if (theme == ui::NativeThemeAura::instance()) {
     30     InitAura(theme);
     31     return;
     32   }
     33 #endif
     34   text_color = NativeThemeWin::instance()->GetThemeColorWithDefault(
     35       NativeThemeWin::MENU, MENU_POPUPITEM, MPI_NORMAL, TMT_TEXTCOLOR,
     36       COLOR_MENUTEXT);
     37 
     38   arrow_color = color_utils::GetSysSkColor(COLOR_MENUTEXT);
     39 
     40   NONCLIENTMETRICS metrics;
     41   base::win::GetNonClientMetrics(&metrics);
     42   l10n_util::AdjustUIFont(&(metrics.lfMenuFont));
     43   {
     44     base::win::ScopedHFONT new_font(CreateFontIndirect(&metrics.lfMenuFont));
     45     DLOG_ASSERT(new_font.Get());
     46     font = gfx::Font(new_font);
     47   }
     48   NativeTheme::ExtraParams extra;
     49   extra.menu_check.is_radio = false;
     50   extra.menu_check.is_selected = false;
     51   gfx::Size check_size = NativeThemeWin::instance()->GetPartSize(
     52       NativeTheme::kMenuCheck, NativeTheme::kNormal, extra);
     53   if (!check_size.IsEmpty()) {
     54     check_width = check_size.width();
     55     check_height = check_size.height();
     56   } else {
     57     check_width = GetSystemMetrics(SM_CXMENUCHECK);
     58     check_height = GetSystemMetrics(SM_CYMENUCHECK);
     59   }
     60 
     61   extra.menu_check.is_radio = true;
     62   gfx::Size radio_size = NativeThemeWin::instance()->GetPartSize(
     63       NativeTheme::kMenuCheck, NativeTheme::kNormal, extra);
     64   if (!radio_size.IsEmpty()) {
     65     radio_width = radio_size.width();
     66     radio_height = radio_size.height();
     67   } else {
     68     radio_width = GetSystemMetrics(SM_CXMENUCHECK);
     69     radio_height = GetSystemMetrics(SM_CYMENUCHECK);
     70   }
     71 
     72   gfx::Size arrow_size = NativeThemeWin::instance()->GetPartSize(
     73       NativeTheme::kMenuPopupArrow, NativeTheme::kNormal, extra);
     74   if (!arrow_size.IsEmpty()) {
     75     arrow_width = arrow_size.width();
     76     arrow_height = arrow_size.height();
     77   } else {
     78     // Sadly I didn't see a specify metrics for this.
     79     arrow_width = GetSystemMetrics(SM_CXMENUCHECK);
     80     arrow_height = GetSystemMetrics(SM_CYMENUCHECK);
     81   }
     82 
     83   BOOL show_cues;
     84   show_mnemonics =
     85       (SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &show_cues, 0) &&
     86        show_cues == TRUE);
     87 
     88   SystemParametersInfo(SPI_GETMENUSHOWDELAY, 0, &show_delay, 0);
     89 }
     90 
     91 // static
     92 const MenuConfig& MenuConfig::instance(const ui::NativeTheme* theme) {
     93   // NOTE: |theme| may be NULL if used before the menu is running.
     94   if (!theme || theme == NativeThemeWin::instance()) {
     95     static MenuConfig* win_instance = NULL;
     96     if (!win_instance)
     97       win_instance = new MenuConfig(NativeThemeWin::instance());
     98     return *win_instance;
     99   }
    100   static MenuConfig* views_instance = NULL;
    101   if (!views_instance)
    102     views_instance = new MenuConfig(theme);
    103   return *views_instance;
    104 }
    105 
    106 }  // namespace views
    107