| 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 "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 #include "third_party/skia/include/core/SkColor.h" | 8 #include "third_party/skia/include/core/SkColor.h" |
| 9 #include "ui/gfx/canvas.h" | 9 #include "ui/gfx/canvas.h" |
| 10 #include "ui/native_theme/native_theme.h" | 10 #include "ui/native_theme/native_theme.h" |
| 11 #include "ui/views/controls/menu/menu_config.h" | 11 #include "ui/views/controls/menu/menu_config.h" |
| 12 | 12 |
| 13 #if defined(OS_WIN) |
| 14 #include "ui/display/win/dpi.h" |
| 15 #endif |
| 16 |
| 13 namespace views { | 17 namespace views { |
| 14 | 18 |
| 15 #if !defined(OS_WIN) | |
| 16 void MenuSeparator::OnPaint(gfx::Canvas* canvas) { | 19 void MenuSeparator::OnPaint(gfx::Canvas* canvas) { |
| 17 canvas->FillRect(GetPaintBounds(), | 20 if (type_ == ui::SPACING_SEPARATOR) |
| 18 GetNativeTheme()->GetSystemColor( | 21 return; |
| 19 ui::NativeTheme::kColorId_MenuSeparatorColor)); | 22 |
| 23 const MenuConfig& menu_config = MenuConfig::instance(); |
| 24 int pos = 0; |
| 25 int separator_thickness = menu_config.separator_thickness; |
| 26 switch (type_) { |
| 27 case ui::LOWER_SEPARATOR: |
| 28 pos = height() - separator_thickness; |
| 29 break; |
| 30 case ui::UPPER_SEPARATOR: |
| 31 break; |
| 32 default: |
| 33 pos = height() / 2; |
| 34 break; |
| 35 } |
| 36 |
| 37 gfx::Rect paint_rect(0, pos, width(), separator_thickness); |
| 38 if (menu_config.use_outer_border) |
| 39 paint_rect.Inset(1, 0); |
| 40 |
| 41 #if defined(OS_WIN) |
| 42 // Hack to get the separator to display correctly on Windows where we may |
| 43 // have fractional scales. We move the separator 1 pixel down to ensure that |
| 44 // it falls within the clipping rect which is scaled up. |
| 45 float device_scale = display::win::GetDPIScale(); |
| 46 bool is_fractional_scale = |
| 47 (device_scale - static_cast<int>(device_scale) != 0); |
| 48 if (is_fractional_scale && paint_rect.y() == 0) |
| 49 paint_rect.set_y(1); |
| 50 #endif |
| 51 |
| 52 ui::NativeTheme::ExtraParams params; |
| 53 params.menu_separator.paint_rect = &paint_rect; |
| 54 params.menu_separator.type = type_; |
| 55 GetNativeTheme()->Paint( |
| 56 canvas->sk_canvas(), ui::NativeTheme::kMenuPopupSeparator, |
| 57 ui::NativeTheme::kNormal, gfx::Rect(bounds().size()), params); |
| 20 } | 58 } |
| 21 #endif | |
| 22 | 59 |
| 23 gfx::Size MenuSeparator::GetPreferredSize() const { | 60 gfx::Size MenuSeparator::GetPreferredSize() const { |
| 24 const MenuConfig& menu_config = MenuConfig::instance(); | 61 const MenuConfig& menu_config = MenuConfig::instance(); |
| 25 int height = menu_config.separator_height; | 62 int height = menu_config.separator_height; |
| 26 switch(type_) { | 63 switch (type_) { |
| 27 case ui::SPACING_SEPARATOR: | 64 case ui::SPACING_SEPARATOR: |
| 28 height = menu_config.separator_spacing_height; | 65 height = menu_config.separator_spacing_height; |
| 29 break; | 66 break; |
| 30 case ui::LOWER_SEPARATOR: | 67 case ui::LOWER_SEPARATOR: |
| 31 height = menu_config.separator_lower_height; | 68 height = menu_config.separator_lower_height; |
| 32 break; | 69 break; |
| 33 case ui::UPPER_SEPARATOR: | 70 case ui::UPPER_SEPARATOR: |
| 34 height = menu_config.separator_upper_height; | 71 height = menu_config.separator_upper_height; |
| 35 break; | 72 break; |
| 36 default: | 73 default: |
| 37 height = menu_config.separator_height; | 74 height = menu_config.separator_height; |
| 38 break; | 75 break; |
| 39 } | 76 } |
| 40 return gfx::Size(10, // Just in case we're the only item in a menu. | 77 return gfx::Size(10, // Just in case we're the only item in a menu. |
| 41 height); | 78 height); |
| 42 } | 79 } |
| 43 | 80 |
| 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 | 81 } // namespace views |
| OLD | NEW |