| OLD | NEW |
| (Empty) |
| 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/base/native_theme/native_theme_aura.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "grit/gfx_resources.h" | |
| 9 #include "ui/base/resource/resource_bundle.h" | |
| 10 #include "ui/gfx/rect.h" | |
| 11 #include "ui/gfx/size.h" | |
| 12 #include "ui/gfx/skbitmap_operations.h" | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 const SkColor kMenuBackgroundColor = SK_ColorWHITE; | |
| 17 | |
| 18 // Theme colors returned by GetSystemColor(). | |
| 19 const SkColor kInvalidColorIdColor = SkColorSetRGB(255, 0, 128); | |
| 20 // Dialogs: | |
| 21 const SkColor kDialogBackgroundColor = SK_ColorWHITE; | |
| 22 // FocusableBorder: | |
| 23 const SkColor kFocusedBorderColor = SkColorSetRGB(0x4D, 0x90, 0xFE); | |
| 24 const SkColor kUnfocusedBorderColor = SkColorSetRGB(0xD9, 0xD9, 0xD9); | |
| 25 // TextButton: | |
| 26 const SkColor kTextButtonBackgroundColor = SkColorSetRGB(0xDE, 0xDE, 0xDE); | |
| 27 const SkColor kTextButtonEnabledColor = SkColorSetRGB(0x22, 0x22, 0x22); | |
| 28 const SkColor kTextButtonDisabledColor = SkColorSetRGB(0x99, 0x99, 0x99); | |
| 29 const SkColor kTextButtonHighlightColor = SkColorSetRGB(0, 0, 0); | |
| 30 const SkColor kTextButtonHoverColor = kTextButtonEnabledColor; | |
| 31 // MenuItem: | |
| 32 const SkColor kEnabledMenuItemForegroundColor = kTextButtonEnabledColor; | |
| 33 const SkColor kDisabledMenuItemForegroundColor = kTextButtonDisabledColor; | |
| 34 const SkColor kFocusedMenuItemBackgroundColor = SkColorSetRGB(0xF1, 0xF1, 0xF1); | |
| 35 const SkColor kMenuSeparatorColor = SkColorSetRGB(0xDA, 0xDA, 0xDA); | |
| 36 // Label: | |
| 37 const SkColor kLabelEnabledColor = kTextButtonEnabledColor; | |
| 38 const SkColor kLabelDisabledColor = kTextButtonDisabledColor; | |
| 39 const SkColor kLabelBackgroundColor = SK_ColorWHITE; | |
| 40 // Textfield: | |
| 41 const SkColor kTextfieldDefaultColor = SK_ColorBLACK; | |
| 42 const SkColor kTextfieldDefaultBackground = SK_ColorWHITE; | |
| 43 const SkColor kTextfieldSelectionBackgroundFocused = | |
| 44 SkColorSetARGB(0x54, 0x60, 0xA8, 0xEB); | |
| 45 const SkColor kTextfieldSelectionBackgroundUnfocused = SK_ColorLTGRAY; | |
| 46 const SkColor kTextfieldSelectionColor = | |
| 47 color_utils::AlphaBlend(SK_ColorBLACK, | |
| 48 kTextfieldSelectionBackgroundFocused, 0xdd); | |
| 49 | |
| 50 } // namespace | |
| 51 | |
| 52 namespace ui { | |
| 53 | |
| 54 // static | |
| 55 const NativeTheme* NativeTheme::instance() { | |
| 56 return NativeThemeAura::instance(); | |
| 57 } | |
| 58 | |
| 59 // static | |
| 60 const NativeThemeAura* NativeThemeAura::instance() { | |
| 61 CR_DEFINE_STATIC_LOCAL(NativeThemeAura, s_native_theme, ()); | |
| 62 return &s_native_theme; | |
| 63 } | |
| 64 | |
| 65 NativeThemeAura::NativeThemeAura() { | |
| 66 // We don't draw scrollbar buttons. | |
| 67 set_scrollbar_button_length(0); | |
| 68 } | |
| 69 | |
| 70 NativeThemeAura::~NativeThemeAura() { | |
| 71 } | |
| 72 | |
| 73 SkColor NativeThemeAura::GetSystemColor(ColorId color_id) const { | |
| 74 // This implementation returns hardcoded colors. | |
| 75 switch (color_id) { | |
| 76 | |
| 77 // Dialogs | |
| 78 case kColorId_DialogBackground: | |
| 79 return kDialogBackgroundColor; | |
| 80 | |
| 81 // FocusableBorder | |
| 82 case kColorId_FocusedBorderColor: | |
| 83 return kFocusedBorderColor; | |
| 84 case kColorId_UnfocusedBorderColor: | |
| 85 return kUnfocusedBorderColor; | |
| 86 | |
| 87 // TextButton | |
| 88 case kColorId_TextButtonBackgroundColor: | |
| 89 return kTextButtonBackgroundColor; | |
| 90 case kColorId_TextButtonEnabledColor: | |
| 91 return kTextButtonEnabledColor; | |
| 92 case kColorId_TextButtonDisabledColor: | |
| 93 return kTextButtonDisabledColor; | |
| 94 case kColorId_TextButtonHighlightColor: | |
| 95 return kTextButtonHighlightColor; | |
| 96 case kColorId_TextButtonHoverColor: | |
| 97 return kTextButtonHoverColor; | |
| 98 | |
| 99 // MenuItem | |
| 100 case kColorId_EnabledMenuItemForegroundColor: | |
| 101 return kEnabledMenuItemForegroundColor; | |
| 102 case kColorId_DisabledMenuItemForegroundColor: | |
| 103 return kDisabledMenuItemForegroundColor; | |
| 104 case kColorId_FocusedMenuItemBackgroundColor: | |
| 105 return kFocusedMenuItemBackgroundColor; | |
| 106 case kColorId_MenuSeparatorColor: | |
| 107 return kMenuSeparatorColor; | |
| 108 | |
| 109 // Label | |
| 110 case kColorId_LabelEnabledColor: | |
| 111 return kLabelEnabledColor; | |
| 112 case kColorId_LabelDisabledColor: | |
| 113 return kLabelDisabledColor; | |
| 114 case kColorId_LabelBackgroundColor: | |
| 115 return kLabelBackgroundColor; | |
| 116 | |
| 117 // Textfield | |
| 118 case kColorId_TextfieldDefaultColor: | |
| 119 return kTextfieldDefaultColor; | |
| 120 case kColorId_TextfieldDefaultBackground: | |
| 121 return kTextfieldDefaultBackground; | |
| 122 case kColorId_TextfieldSelectionColor: | |
| 123 return kTextfieldSelectionColor; | |
| 124 case kColorId_TextfieldSelectionBackgroundFocused: | |
| 125 return kTextfieldSelectionBackgroundFocused; | |
| 126 case kColorId_TextfieldSelectionBackgroundUnfocused: | |
| 127 return kTextfieldSelectionBackgroundUnfocused; | |
| 128 | |
| 129 default: | |
| 130 NOTREACHED() << "Invalid color_id: " << color_id; | |
| 131 break; | |
| 132 } | |
| 133 | |
| 134 return kInvalidColorIdColor; | |
| 135 } | |
| 136 | |
| 137 void NativeThemeAura::PaintMenuPopupBackground(SkCanvas* canvas, | |
| 138 const gfx::Size& size) const { | |
| 139 canvas->drawColor(kMenuBackgroundColor, SkXfermode::kSrc_Mode); | |
| 140 } | |
| 141 | |
| 142 void NativeThemeAura::PaintScrollbarTrack( | |
| 143 SkCanvas* canvas, | |
| 144 Part part, | |
| 145 State state, | |
| 146 const ScrollbarTrackExtraParams& extra_params, | |
| 147 const gfx::Rect& rect) const { | |
| 148 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 149 if (part == kScrollbarVerticalTrack) { | |
| 150 int center_offset = 0; | |
| 151 int center_height = rect.height(); | |
| 152 | |
| 153 if (rect.y() == extra_params.track_y) { | |
| 154 // TODO(derat): Honor |state| instead of only using the highlighted images | |
| 155 // after updating WebKit so we can draw the entire track in one go instead | |
| 156 // of as two separate pieces: otherwise, only the portion of the scrollbar | |
| 157 // that the mouse is over gets the highlighted state. | |
| 158 SkBitmap* top = rb.GetBitmapNamed(IDR_SCROLL_BASE_VERTICAL_TOP_H); | |
| 159 DrawTiledImage(canvas, *top, | |
| 160 0, 0, 1.0, 1.0, | |
| 161 rect.x(), rect.y(), top->width(), top->height()); | |
| 162 center_offset += top->height(); | |
| 163 center_height -= top->height(); | |
| 164 } | |
| 165 | |
| 166 if (rect.y() + rect.height() == | |
| 167 extra_params.track_y + extra_params.track_height) { | |
| 168 SkBitmap* bottom = rb.GetBitmapNamed(IDR_SCROLL_BASE_VERTICAL_BOTTOM_H); | |
| 169 DrawTiledImage(canvas, *bottom, | |
| 170 0, 0, 1.0, 1.0, | |
| 171 rect.x(), rect.y() + rect.height() - bottom->height(), | |
| 172 bottom->width(), bottom->height()); | |
| 173 center_height -= bottom->height(); | |
| 174 } | |
| 175 | |
| 176 if (center_height > 0) { | |
| 177 SkBitmap* center = rb.GetBitmapNamed(IDR_SCROLL_BASE_VERTICAL_CENTER_H); | |
| 178 DrawTiledImage(canvas, *center, | |
| 179 0, 0, 1.0, 1.0, | |
| 180 rect.x(), rect.y() + center_offset, | |
| 181 center->width(), center_height); | |
| 182 } | |
| 183 } else { | |
| 184 int center_offset = 0; | |
| 185 int center_width = rect.width(); | |
| 186 | |
| 187 if (rect.x() == extra_params.track_x) { | |
| 188 SkBitmap* left = rb.GetBitmapNamed(IDR_SCROLL_BASE_HORIZONTAL_LEFT_H); | |
| 189 DrawTiledImage(canvas, *left, | |
| 190 0, 0, 1.0, 1.0, | |
| 191 rect.x(), rect.y(), left->width(), left->height()); | |
| 192 center_offset += left->width(); | |
| 193 center_width -= left->width(); | |
| 194 } | |
| 195 | |
| 196 if (rect.x() + rect.width() == | |
| 197 extra_params.track_x + extra_params.track_width) { | |
| 198 SkBitmap* right = rb.GetBitmapNamed(IDR_SCROLL_BASE_HORIZONTAL_RIGHT_H); | |
| 199 DrawTiledImage(canvas, *right, | |
| 200 0, 0, 1.0, 1.0, | |
| 201 rect.x() + rect.width() - right->width(), rect.y(), | |
| 202 right->width(), right->height()); | |
| 203 center_width -= right->width(); | |
| 204 } | |
| 205 | |
| 206 if (center_width > 0) { | |
| 207 SkBitmap* center = rb.GetBitmapNamed(IDR_SCROLL_BASE_HORIZONTAL_CENTER_H); | |
| 208 DrawTiledImage(canvas, *center, | |
| 209 0, 0, 1.0, 1.0, | |
| 210 rect.x() + center_offset, rect.y(), | |
| 211 center_width, center->height()); | |
| 212 } | |
| 213 } | |
| 214 } | |
| 215 | |
| 216 void NativeThemeAura::PaintArrowButton(SkCanvas* canvas, | |
| 217 const gfx::Rect& rect, | |
| 218 Part part, | |
| 219 State state) const { | |
| 220 DCHECK(rect.IsEmpty()); | |
| 221 } | |
| 222 | |
| 223 void NativeThemeAura::PaintScrollbarThumb(SkCanvas* canvas, | |
| 224 Part part, | |
| 225 State state, | |
| 226 const gfx::Rect& rect) const { | |
| 227 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 228 if (part == kScrollbarVerticalThumb) { | |
| 229 int top_resource_id = | |
| 230 state == kHovered ? IDR_SCROLL_THUMB_VERTICAL_TOP_H : | |
| 231 state == kPressed ? IDR_SCROLL_THUMB_VERTICAL_TOP_P : | |
| 232 IDR_SCROLL_THUMB_VERTICAL_TOP; | |
| 233 SkBitmap* top = rb.GetBitmapNamed(top_resource_id); | |
| 234 DrawTiledImage(canvas, *top, | |
| 235 0, 0, 1.0, 1.0, | |
| 236 rect.x(), rect.y(), top->width(), top->height()); | |
| 237 | |
| 238 int bottom_resource_id = | |
| 239 state == kHovered ? IDR_SCROLL_THUMB_VERTICAL_BOTTOM_H : | |
| 240 state == kPressed ? IDR_SCROLL_THUMB_VERTICAL_BOTTOM_P : | |
| 241 IDR_SCROLL_THUMB_VERTICAL_BOTTOM; | |
| 242 SkBitmap* bottom = rb.GetBitmapNamed(bottom_resource_id); | |
| 243 DrawTiledImage(canvas, *bottom, | |
| 244 0, 0, 1.0, 1.0, | |
| 245 rect.x(), rect.y() + rect.height() - bottom->height(), | |
| 246 bottom->width(), bottom->height()); | |
| 247 | |
| 248 if (rect.height() > top->height() + bottom->height()) { | |
| 249 int center_resource_id = | |
| 250 state == kHovered ? IDR_SCROLL_THUMB_VERTICAL_CENTER_H : | |
| 251 state == kPressed ? IDR_SCROLL_THUMB_VERTICAL_CENTER_P : | |
| 252 IDR_SCROLL_THUMB_VERTICAL_CENTER; | |
| 253 SkBitmap* center = rb.GetBitmapNamed(center_resource_id); | |
| 254 DrawTiledImage(canvas, *center, | |
| 255 0, 0, 1.0, 1.0, | |
| 256 rect.x(), rect.y() + top->height(), | |
| 257 center->width(), | |
| 258 rect.height() - top->height() - bottom->height()); | |
| 259 } | |
| 260 } else { | |
| 261 int left_resource_id = | |
| 262 state == kHovered ? IDR_SCROLL_THUMB_HORIZONTAL_LEFT_H : | |
| 263 state == kPressed ? IDR_SCROLL_THUMB_HORIZONTAL_LEFT_P : | |
| 264 IDR_SCROLL_THUMB_HORIZONTAL_LEFT; | |
| 265 SkBitmap* left = rb.GetBitmapNamed(left_resource_id); | |
| 266 DrawTiledImage(canvas, *left, | |
| 267 0, 0, 1.0, 1.0, | |
| 268 rect.x(), rect.y(), left->width(), left->height()); | |
| 269 | |
| 270 int right_resource_id = | |
| 271 state == kHovered ? IDR_SCROLL_THUMB_HORIZONTAL_RIGHT_H : | |
| 272 state == kPressed ? IDR_SCROLL_THUMB_HORIZONTAL_RIGHT_P : | |
| 273 IDR_SCROLL_THUMB_HORIZONTAL_RIGHT; | |
| 274 SkBitmap* right = rb.GetBitmapNamed(right_resource_id); | |
| 275 DrawTiledImage(canvas, *right, | |
| 276 0, 0, 1.0, 1.0, | |
| 277 rect.x() + rect.width() - right->width(), rect.y(), | |
| 278 right->width(), right->height()); | |
| 279 | |
| 280 if (rect.width() > left->width() + right->width()) { | |
| 281 int center_resource_id = | |
| 282 state == kHovered ? IDR_SCROLL_THUMB_HORIZONTAL_CENTER_H : | |
| 283 state == kPressed ? IDR_SCROLL_THUMB_HORIZONTAL_CENTER_P : | |
| 284 IDR_SCROLL_THUMB_HORIZONTAL_CENTER; | |
| 285 SkBitmap* center = rb.GetBitmapNamed(center_resource_id); | |
| 286 DrawTiledImage(canvas, *center, | |
| 287 0, 0, 1.0, 1.0, | |
| 288 rect.x() + left->width(), rect.y(), | |
| 289 rect.width() - left->width() - right->width(), | |
| 290 center->height()); | |
| 291 } | |
| 292 } | |
| 293 } | |
| 294 | |
| 295 } // namespace ui | |
| OLD | NEW |