Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / views / controls / menu / menu_separator_views.cc
blobc61cc594e926fe03c9e86cafb49bc08a005dfa66
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.
5 #include "ui/views/controls/menu/menu_separator.h"
7 #include "third_party/skia/include/core/SkColor.h"
8 #include "ui/gfx/canvas.h"
9 #include "ui/native_theme/native_theme.h"
10 #include "ui/views/controls/menu/menu_config.h"
11 #include "ui/views/controls/menu/menu_item_view.h"
13 namespace {
15 const int kSeparatorHeight = 1;
17 } // namespace
19 namespace views {
21 #if !defined(OS_WIN)
22 void MenuSeparator::OnPaint(gfx::Canvas* canvas) {
23 OnPaintAura(canvas);
25 #endif
27 gfx::Size MenuSeparator::GetPreferredSize() const {
28 const MenuConfig& menu_config = parent_menu_item_->GetMenuConfig();
29 int height = menu_config.separator_height;
30 switch(type_) {
31 case ui::SPACING_SEPARATOR:
32 height = menu_config.separator_spacing_height;
33 break;
34 case ui::LOWER_SEPARATOR:
35 height = menu_config.separator_lower_height;
36 break;
37 case ui::UPPER_SEPARATOR:
38 height = menu_config.separator_upper_height;
39 break;
40 default:
41 height = menu_config.separator_height;
42 break;
44 return gfx::Size(10, // Just in case we're the only item in a menu.
45 height);
48 gfx::Rect MenuSeparator::GetPaintBounds() {
49 int pos = 0;
50 switch (type_) {
51 case ui::LOWER_SEPARATOR:
52 pos = height() - kSeparatorHeight;
53 break;
54 case ui::SPACING_SEPARATOR:
55 return gfx::Rect();
56 case ui::UPPER_SEPARATOR:
57 break;
58 default:
59 pos = height() / 2;
60 break;
63 gfx::Rect paint_rect(0, pos, width(), kSeparatorHeight);
64 if (parent_menu_item_->GetMenuConfig().use_outer_border)
65 paint_rect.Inset(1, 0);
66 return paint_rect;
69 void MenuSeparator::OnPaintAura(gfx::Canvas* canvas) {
70 canvas->FillRect(GetPaintBounds(),
71 GetNativeTheme()->GetSystemColor(
72 ui::NativeTheme::kColorId_MenuSeparatorColor));
75 } // namespace views