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 "grit/ui_resources.h"
      8 #include "ui/base/layout.h"
      9 #include "ui/base/resource/resource_bundle.h"
     10 #include "ui/gfx/image/image.h"
     11 #include "ui/gfx/image/image_skia.h"
     12 #include "ui/native_theme/native_theme_aura.h"
     13 #include "ui/views/controls/menu/menu_image_util.h"
     14 
     15 namespace views {
     16 
     17 namespace {
     18 #if defined(OS_CHROMEOS)
     19 static const int kMenuCornerRadiusForAura = 2;
     20 #else
     21 static const int kMenuCornerRadiusForAura = 0;
     22 #endif
     23 }  // namespace
     24 
     25 #if !defined(OS_WIN)
     26 void MenuConfig::Init(const ui::NativeTheme* theme) {
     27   if (theme == ui::NativeThemeAura::instance())
     28     InitAura(theme);
     29 }
     30 #endif
     31 
     32 void MenuConfig::InitAura(const ui::NativeTheme* theme) {
     33   text_color = theme->GetSystemColor(
     34       ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor);
     35   submenu_horizontal_inset = 1;
     36   arrow_to_edge_padding = 20;
     37   ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
     38   arrow_width =
     39       rb.GetImageNamed(IDR_MENU_HIERARCHY_ARROW).ToImageSkia()->width();
     40   gfx::ImageSkia check = GetMenuCheckImage(false);
     41   check_height = check.height();
     42   item_min_height = 29;
     43   separator_spacing_height = 7;
     44   separator_lower_height = 8;
     45   separator_upper_height = 8;
     46   font = rb.GetFont(ResourceBundle::BaseFont);
     47   label_to_arrow_padding = 20;
     48   label_to_minor_text_padding = 20;
     49   always_use_icon_to_label_padding = true;
     50   align_arrow_and_shortcut = true;
     51   offset_context_menus = true;
     52   corner_radius = kMenuCornerRadiusForAura;
     53 }
     54 
     55 #if !defined(OS_WIN)
     56 // static
     57 const MenuConfig& MenuConfig::instance(const ui::NativeTheme* theme) {
     58   static MenuConfig* views_instance = NULL;
     59   if (!views_instance)
     60     views_instance = new MenuConfig(theme ?
     61         theme : ui::NativeTheme::instance());
     62   return *views_instance;
     63 }
     64 #endif
     65 
     66 }  // namespace views
     67