| 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/native_theme/common_theme.h" | 5 #include "ui/native_theme/common_theme.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "grit/ui_resources.h" | 8 #include "grit/ui_resources.h" |
| 9 #include "third_party/skia/include/core/SkCanvas.h" | 9 #include "third_party/skia/include/core/SkCanvas.h" |
| 10 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
| 11 #include "ui/gfx/color_utils.h" |
| 11 #include "ui/gfx/image/image_skia.h" | 12 #include "ui/gfx/image/image_skia.h" |
| 12 #include "ui/gfx/rect.h" | 13 #include "ui/gfx/rect.h" |
| 13 #include "ui/gfx/skia_util.h" | 14 #include "ui/gfx/skia_util.h" |
| 15 #include "ui/gfx/sys_color_change_listener.h" |
| 14 #include "ui/views/controls/menu/menu_config.h" | 16 #include "ui/views/controls/menu/menu_config.h" |
| 15 | 17 |
| 16 namespace { | 18 namespace { |
| 17 | 19 |
| 18 // Theme colors returned by GetSystemColor(). | 20 // Theme colors returned by GetSystemColor(). |
| 19 | 21 |
| 20 // MenuItem: | 22 // MenuItem: |
| 21 const SkColor kMenuBackgroundColor = SK_ColorWHITE; | 23 const SkColor kMenuBackgroundColor = SK_ColorWHITE; |
| 22 const SkColor kMenuHighlightBackgroundColor = SkColorSetA(SK_ColorBLACK, 15); | 24 const SkColor kMenuHighlightBackgroundColor = SkColorSetA(SK_ColorBLACK, 15); |
| 25 const SkColor kMenuInvertedSchemeHighlightBackgroundColor = |
| 26 SkColorSetRGB(48, 48, 48); |
| 23 const SkColor kMenuBorderColor = SkColorSetRGB(0xBA, 0xBA, 0xBA); | 27 const SkColor kMenuBorderColor = SkColorSetRGB(0xBA, 0xBA, 0xBA); |
| 24 const SkColor kMenuSeparatorColor = SkColorSetRGB(0xE9, 0xE9, 0xE9); | 28 const SkColor kMenuSeparatorColor = SkColorSetRGB(0xE9, 0xE9, 0xE9); |
| 25 const SkColor kEnabledMenuItemForegroundColor = SK_ColorBLACK; | 29 const SkColor kEnabledMenuItemForegroundColor = SK_ColorBLACK; |
| 26 const SkColor kDisabledMenuItemForegroundColor = SkColorSetRGB(161, 161, 146); | 30 const SkColor kDisabledMenuItemForegroundColor = SkColorSetRGB(161, 161, 146); |
| 27 | 31 |
| 28 } // namespace | 32 } // namespace |
| 29 | 33 |
| 30 namespace ui { | 34 namespace ui { |
| 31 | 35 |
| 32 bool CommonThemeGetSystemColor(NativeTheme::ColorId color_id, SkColor* color) { | 36 bool CommonThemeGetSystemColor(NativeTheme::ColorId color_id, SkColor* color) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 49 break; | 53 break; |
| 50 case NativeTheme::kColorId_DisabledMenuItemForegroundColor: | 54 case NativeTheme::kColorId_DisabledMenuItemForegroundColor: |
| 51 *color = kDisabledMenuItemForegroundColor; | 55 *color = kDisabledMenuItemForegroundColor; |
| 52 break; | 56 break; |
| 53 case NativeTheme::kColorId_TextButtonDisabledColor: | 57 case NativeTheme::kColorId_TextButtonDisabledColor: |
| 54 *color = kDisabledMenuItemForegroundColor; | 58 *color = kDisabledMenuItemForegroundColor; |
| 55 break; | 59 break; |
| 56 default: | 60 default: |
| 57 return false; | 61 return false; |
| 58 } | 62 } |
| 63 if (gfx::IsInvertedColorScheme()) { |
| 64 switch (color_id) { |
| 65 case NativeTheme::kColorId_FocusedMenuItemBackgroundColor: |
| 66 *color = kMenuInvertedSchemeHighlightBackgroundColor; |
| 67 break; |
| 68 default: |
| 69 *color = color_utils::InvertColor(*color); |
| 70 } |
| 71 } |
| 59 return true; | 72 return true; |
| 60 } | 73 } |
| 61 | 74 |
| 62 gfx::Size CommonThemeGetPartSize(NativeTheme::Part part, | 75 gfx::Size CommonThemeGetPartSize(NativeTheme::Part part, |
| 63 NativeTheme::State state, | 76 NativeTheme::State state, |
| 64 const NativeTheme::ExtraParams& extra) { | 77 const NativeTheme::ExtraParams& extra) { |
| 65 gfx::Size size; | 78 gfx::Size size; |
| 66 switch (part) { | 79 switch (part) { |
| 67 case NativeTheme::kMenuCheck: { | 80 case NativeTheme::kMenuCheck: { |
| 68 const gfx::ImageSkia* check = | 81 const gfx::ImageSkia* check = |
| 69 ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 82 ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 70 IDR_MENU_CHECK_CHECKED).ToImageSkia(); | 83 IDR_MENU_CHECK_CHECKED).ToImageSkia(); |
| 71 size.SetSize(check->width(), check->height()); | 84 size.SetSize(check->width(), check->height()); |
| 72 break; | 85 break; |
| 73 } | 86 } |
| 74 default: | 87 default: |
| 75 break; | 88 break; |
| 76 } | 89 } |
| 77 | 90 |
| 78 return size; | 91 return size; |
| 79 } | 92 } |
| 80 | 93 |
| 81 void CommonThemePaintMenuSeparator( | 94 void CommonThemePaintMenuSeparator( |
| 82 SkCanvas* canvas, | 95 SkCanvas* canvas, |
| 83 const gfx::Rect& rect, | 96 const gfx::Rect& rect, |
| 84 const NativeTheme::MenuSeparatorExtraParams& extra) { | 97 const NativeTheme::MenuSeparatorExtraParams& extra) { |
| 98 SkColor color; |
| 99 CommonThemeGetSystemColor(NativeTheme::kColorId_MenuSeparatorColor, &color); |
| 85 SkPaint paint; | 100 SkPaint paint; |
| 86 paint.setColor(kMenuSeparatorColor); | 101 paint.setColor(kMenuSeparatorColor); |
| 87 int position_y = rect.y() + rect.height() / 2; | 102 int position_y = rect.y() + rect.height() / 2; |
| 88 canvas->drawLine(rect.x(), position_y, rect.right(), position_y, paint); | 103 canvas->drawLine(rect.x(), position_y, rect.right(), position_y, paint); |
| 89 } | 104 } |
| 90 | 105 |
| 91 void CommonThemePaintMenuGutter(SkCanvas* canvas, const gfx::Rect& rect) { | 106 void CommonThemePaintMenuGutter(SkCanvas* canvas, const gfx::Rect& rect) { |
| 107 SkColor color; |
| 108 CommonThemeGetSystemColor(NativeTheme::kColorId_MenuSeparatorColor, &color); |
| 92 SkPaint paint; | 109 SkPaint paint; |
| 93 paint.setColor(kMenuSeparatorColor); | 110 paint.setColor(kMenuSeparatorColor); |
| 94 int position_x = rect.x() + rect.width() / 2; | 111 int position_x = rect.x() + rect.width() / 2; |
| 95 canvas->drawLine(position_x, rect.y(), position_x, rect.bottom(), paint); | 112 canvas->drawLine(position_x, rect.y(), position_x, rect.bottom(), paint); |
| 96 } | 113 } |
| 97 | 114 |
| 98 void CommonThemePaintMenuBackground(SkCanvas* canvas, const gfx::Rect& rect) { | 115 void CommonThemePaintMenuBackground(SkCanvas* canvas, const gfx::Rect& rect) { |
| 116 SkColor color; |
| 117 CommonThemeGetSystemColor(NativeTheme::kColorId_MenuBackgroundColor, &color); |
| 99 SkPaint paint; | 118 SkPaint paint; |
| 100 paint.setColor(kMenuBackgroundColor); | 119 paint.setColor(color); |
| 101 canvas->drawRect(gfx::RectToSkRect(rect), paint); | 120 canvas->drawRect(gfx::RectToSkRect(rect), paint); |
| 102 } | 121 } |
| 103 | 122 |
| 104 void CommonThemePaintMenuItemBackground(SkCanvas* canvas, | 123 void CommonThemePaintMenuItemBackground(SkCanvas* canvas, |
| 105 NativeTheme::State state, | 124 NativeTheme::State state, |
| 106 const gfx::Rect& rect) { | 125 const gfx::Rect& rect) { |
| 126 SkColor color; |
| 107 SkPaint paint; | 127 SkPaint paint; |
| 108 switch (state) { | 128 switch (state) { |
| 109 case NativeTheme::kNormal: | 129 case NativeTheme::kNormal: |
| 110 case NativeTheme::kDisabled: | 130 case NativeTheme::kDisabled: |
| 111 paint.setColor(kMenuBackgroundColor); | 131 CommonThemeGetSystemColor(NativeTheme::kColorId_MenuBackgroundColor, |
| 132 &color); |
| 133 paint.setColor(color); |
| 112 break; | 134 break; |
| 113 case NativeTheme::kHovered: | 135 case NativeTheme::kHovered: |
| 114 paint.setColor(kMenuHighlightBackgroundColor); | 136 CommonThemeGetSystemColor( |
| 137 NativeTheme::kColorId_FocusedMenuItemBackgroundColor, &color); |
| 138 paint.setColor(color); |
| 115 break; | 139 break; |
| 116 default: | 140 default: |
| 117 NOTREACHED() << "Invalid state " << state; | 141 NOTREACHED() << "Invalid state " << state; |
| 118 break; | 142 break; |
| 119 } | 143 } |
| 120 canvas->drawRect(gfx::RectToSkRect(rect), paint); | 144 canvas->drawRect(gfx::RectToSkRect(rect), paint); |
| 121 } | 145 } |
| 122 | 146 |
| 123 } // namespace ui | 147 } // namespace ui |
| OLD | NEW |