| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/controls/menu/menu_separator.h" | 5 #include "ui/views/controls/menu/menu_separator.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <uxtheme.h> | 8 #include <uxtheme.h> |
| 9 #include <Vssym32.h> | 9 #include <Vssym32.h> |
| 10 | 10 |
| 11 #include "ui/gfx/canvas.h" | 11 #include "ui/gfx/canvas.h" |
| 12 #include "ui/gfx/rect.h" | 12 #include "ui/gfx/rect.h" |
| 13 #include "ui/native_theme/native_theme.h" | 13 #include "ui/native_theme/native_theme.h" |
| 14 #include "ui/native_theme/native_theme_aura.h" | 14 #include "ui/native_theme/native_theme_aura.h" |
| 15 #include "ui/views/controls/menu/menu_config.h" | 15 #include "ui/views/controls/menu/menu_config.h" |
| 16 #include "ui/views/controls/menu/menu_item_view.h" | 16 #include "ui/views/controls/menu/menu_item_view.h" |
| 17 | 17 |
| 18 namespace views { | 18 namespace views { |
| 19 | 19 |
| 20 void MenuSeparator::OnPaint(gfx::Canvas* canvas) { | 20 void MenuSeparator::OnPaint(gfx::Canvas* canvas) { |
| 21 const MenuConfig& config = parent_menu_item_->GetMenuConfig(); | 21 const MenuConfig& config = parent_menu_item_->GetMenuConfig(); |
| 22 | 22 |
| 23 if (config.native_theme == ui::NativeThemeAura::instance()) { | 23 if (config.native_theme == ui::NativeThemeAura::instance()) { |
| 24 OnPaintAura(canvas); | 24 OnPaintAura(canvas); |
| 25 return; | 25 return; |
| 26 } | 26 } |
| 27 | 27 |
| 28 int start_x = 0; | 28 gfx::Rect separator_bounds = GetPaintBounds(); |
| 29 if (config.render_gutter) { | 29 if (config.render_gutter) { |
| 30 // If render_gutter is true, we're on Vista and need to render the | 30 // If render_gutter is true, we're on Vista and need to render the |
| 31 // gutter, then indent the separator from the gutter. | 31 // gutter, then indent the separator from the gutter. |
| 32 gfx::Rect gutter_bounds(MenuItemView::label_start() - | 32 gfx::Rect gutter_bounds(MenuItemView::label_start() - |
| 33 config.gutter_to_label - config.gutter_width, 0, | 33 config.gutter_to_label - config.gutter_width, 0, |
| 34 config.gutter_width, height()); | 34 config.gutter_width, height()); |
| 35 ui::NativeTheme::ExtraParams extra; | 35 ui::NativeTheme::ExtraParams extra; |
| 36 config.native_theme->Paint( | 36 config.native_theme->Paint( |
| 37 canvas->sk_canvas(), ui::NativeTheme::kMenuPopupGutter, | 37 canvas->sk_canvas(), ui::NativeTheme::kMenuPopupGutter, |
| 38 ui::NativeTheme::kNormal, gutter_bounds, extra); | 38 ui::NativeTheme::kNormal, gutter_bounds, extra); |
| 39 start_x = gutter_bounds.x() + config.gutter_width; | 39 separator_bounds.set_x(gutter_bounds.x() + config.gutter_width); |
| 40 } | 40 } |
| 41 | 41 |
| 42 gfx::Rect separator_bounds(start_x, 0, width(), height()); | |
| 43 ui::NativeTheme::ExtraParams extra; | 42 ui::NativeTheme::ExtraParams extra; |
| 44 extra.menu_separator.has_gutter = config.render_gutter; | 43 extra.menu_separator.has_gutter = config.render_gutter; |
| 45 config.native_theme->Paint( | 44 config.native_theme->Paint( |
| 46 canvas->sk_canvas(), ui::NativeTheme::kMenuPopupSeparator, | 45 canvas->sk_canvas(), ui::NativeTheme::kMenuPopupSeparator, |
| 47 ui::NativeTheme::kNormal, separator_bounds, extra); | 46 ui::NativeTheme::kNormal, separator_bounds, extra); |
| 48 } | 47 } |
| 49 | 48 |
| 50 gfx::Size MenuSeparator::GetPreferredSize() const { | |
| 51 const MenuConfig& config = parent_menu_item_->GetMenuConfig(); | |
| 52 | |
| 53 if (config.native_theme == ui::NativeThemeAura::instance()) | |
| 54 return GetPreferredSizeAura(); | |
| 55 | |
| 56 return gfx::Size(10, // Just in case we're the only item in a menu. | |
| 57 config.separator_height); | |
| 58 } | |
| 59 | |
| 60 } // namespace views | 49 } // namespace views |
| OLD | NEW |