| OLD | NEW |
| (Empty) |
| 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_separator.h" | |
| 6 | |
| 7 #include "build/build_config.h" | |
| 8 #include "third_party/skia/include/core/SkColor.h" | |
| 9 #include "ui/gfx/canvas.h" | |
| 10 #include "ui/native_theme/native_theme.h" | |
| 11 #include "ui/views/controls/menu/menu_config.h" | |
| 12 | |
| 13 namespace views { | |
| 14 | |
| 15 #if !defined(OS_WIN) | |
| 16 void MenuSeparator::OnPaint(gfx::Canvas* canvas) { | |
| 17 canvas->FillRect(GetPaintBounds(), | |
| 18 GetNativeTheme()->GetSystemColor( | |
| 19 ui::NativeTheme::kColorId_MenuSeparatorColor)); | |
| 20 } | |
| 21 #endif | |
| 22 | |
| 23 gfx::Size MenuSeparator::GetPreferredSize() const { | |
| 24 const MenuConfig& menu_config = MenuConfig::instance(); | |
| 25 int height = menu_config.separator_height; | |
| 26 switch(type_) { | |
| 27 case ui::SPACING_SEPARATOR: | |
| 28 height = menu_config.separator_spacing_height; | |
| 29 break; | |
| 30 case ui::LOWER_SEPARATOR: | |
| 31 height = menu_config.separator_lower_height; | |
| 32 break; | |
| 33 case ui::UPPER_SEPARATOR: | |
| 34 height = menu_config.separator_upper_height; | |
| 35 break; | |
| 36 default: | |
| 37 height = menu_config.separator_height; | |
| 38 break; | |
| 39 } | |
| 40 return gfx::Size(10, // Just in case we're the only item in a menu. | |
| 41 height); | |
| 42 } | |
| 43 | |
| 44 gfx::Rect MenuSeparator::GetPaintBounds() { | |
| 45 int pos = 0; | |
| 46 const MenuConfig& menu_config = MenuConfig::instance(); | |
| 47 int separator_thickness = menu_config.separator_thickness; | |
| 48 switch (type_) { | |
| 49 case ui::LOWER_SEPARATOR: | |
| 50 pos = height() - separator_thickness; | |
| 51 break; | |
| 52 case ui::SPACING_SEPARATOR: | |
| 53 return gfx::Rect(); | |
| 54 case ui::UPPER_SEPARATOR: | |
| 55 break; | |
| 56 default: | |
| 57 pos = height() / 2; | |
| 58 break; | |
| 59 } | |
| 60 | |
| 61 gfx::Rect paint_rect(0, pos, width(), separator_thickness); | |
| 62 if (menu_config.use_outer_border) | |
| 63 paint_rect.Inset(1, 0); | |
| 64 return paint_rect; | |
| 65 } | |
| 66 | |
| 67 } // namespace views | |
| OLD | NEW |