- add sources.
[platform/framework/web/crosswalk.git] / src / ui / views / controls / menu / menu_separator_win.cc
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 <windows.h>
8 #include <uxtheme.h>
9 #include <Vssym32.h>
10
11 #include "ui/gfx/canvas.h"
12 #include "ui/gfx/rect.h"
13 #include "ui/native_theme/native_theme.h"
14 #include "ui/views/controls/menu/menu_config.h"
15 #include "ui/views/controls/menu/menu_item_view.h"
16
17 #if defined(USE_AURA)
18 #include "ui/native_theme/native_theme_aura.h"
19 #endif
20
21 namespace views {
22
23 void MenuSeparator::OnPaint(gfx::Canvas* canvas) {
24   const MenuConfig& config = parent_menu_item_->GetMenuConfig();
25
26 #if defined(USE_AURA)
27   if (config.native_theme == ui::NativeThemeAura::instance()) {
28     OnPaintAura(canvas);
29     return;
30   }
31 #endif
32
33   int start_x = 0;
34   if (config.render_gutter) {
35     // If render_gutter is true, we're on Vista and need to render the
36     // gutter, then indent the separator from the gutter.
37     gfx::Rect gutter_bounds(MenuItemView::label_start() -
38         config.gutter_to_label - config.gutter_width, 0,
39         config.gutter_width, height());
40     ui::NativeTheme::ExtraParams extra;
41     config.native_theme->Paint(
42         canvas->sk_canvas(), ui::NativeTheme::kMenuPopupGutter,
43         ui::NativeTheme::kNormal, gutter_bounds, extra);
44     start_x = gutter_bounds.x() + config.gutter_width;
45   }
46
47   gfx::Rect separator_bounds(start_x, 0, width(), height());
48   ui::NativeTheme::ExtraParams extra;
49   extra.menu_separator.has_gutter = config.render_gutter;
50   config.native_theme->Paint(
51       canvas->sk_canvas(), ui::NativeTheme::kMenuPopupSeparator,
52       ui::NativeTheme::kNormal, separator_bounds, extra);
53 }
54
55 gfx::Size MenuSeparator::GetPreferredSize() {
56   const MenuConfig& config = parent_menu_item_->GetMenuConfig();
57
58 #if defined(USE_AURA)
59   if (config.native_theme == ui::NativeThemeAura::instance())
60     return GetPreferredSizeAura();
61 #endif
62
63   return gfx::Size(10,  // Just in case we're the only item in a menu.
64                    config.separator_height);
65 }
66
67 }  // namespace views