OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/chromeos/native_theme_chromeos.h" | 5 #include "chrome/browser/chromeos/native_theme_chromeos.h" |
6 | 6 |
7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "gfx/insets.h" | 9 #include "gfx/insets.h" |
10 #include "gfx/rect.h" | 10 #include "gfx/rect.h" |
11 #include "gfx/size.h" | 11 #include "gfx/size.h" |
12 #include "gfx/skbitmap_operations.h" | 12 #include "gfx/skbitmap_operations.h" |
13 #include "grit/theme_resources.h" | 13 #include "grit/theme_resources.h" |
| 14 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 15 #include "third_party/skia/include/core/SkPaint.h" |
| 16 #include "third_party/skia/include/core/SkPath.h" |
14 #include "third_party/skia/include/core/SkShader.h" | 17 #include "third_party/skia/include/core/SkShader.h" |
15 | 18 |
| 19 namespace { |
| 20 |
| 21 // Color constants. See theme_draw for details. |
| 22 |
| 23 // Border color used for many widgets. |
| 24 const SkColor kBaseStroke = SkColorSetRGB(0x8F, 0x8F, 0x8F); |
| 25 |
| 26 // Disabled border color used for many widgets. |
| 27 const SkColor kDisabledBaseStroke = SkColorSetRGB(0xB7, 0xB7, 0xB7); |
| 28 |
| 29 // Common gradient stop and colors. |
| 30 const SkColor kBaseGradient0 = SkColorSetRGB(255, 255, 255); |
| 31 const SkColor kBaseGradient1 = SkColorSetRGB(255, 255, 255); |
| 32 const SkColor kBaseGradient2 = SkColorSetRGB(0xD8, 0xD8, 0xD8); |
| 33 |
| 34 const SkColor kPressedGradient0 = SkColorSetRGB(0x95, 0x95, 0x95); |
| 35 const SkColor kPressedGradient1 = SkColorSetRGB(0xE3, 0xE3, 0xE3); |
| 36 |
| 37 const SkColor kIndicatorStrokeDisabledColor = SkColorSetRGB(0xB4, 0xB4, 0xB4); |
| 38 // TODO: these are wrong, what should they be? |
| 39 const SkColor kIndicatorStrokePressedColor = SkColorSetRGB(0, 0, 0); |
| 40 const SkColor kIndicatorStrokeColor = SkColorSetRGB(0, 0, 0); |
| 41 |
| 42 const SkColor kRadioIndicatorGradient0 = SkColorSetRGB(0, 0, 0); |
| 43 const SkColor kRadioIndicatorGradient1 = SkColorSetRGB(0x83, 0x83, 0x83); |
| 44 |
| 45 const SkColor kRadioIndicatorDisabledGradient0 = |
| 46 SkColorSetRGB(0xB4, 0xB4, 0xB4); |
| 47 const SkColor kRadioIndicatorDisabledGradient1 = |
| 48 SkColorSetRGB(0xB7, 0xB7, 0xB7); |
| 49 |
| 50 // Progressbar colors |
| 51 const SkColor kProgressBarBackgroundGradient0 = SkColorSetRGB(0xBB, 0xBB, 0xBB); |
| 52 const SkColor kProgressBarBackgroundGradient1 = SkColorSetRGB(0xE7, 0xE7, 0xE7); |
| 53 const SkColor kProgressBarBackgroundGradient2 = SkColorSetRGB(0xFE, 0xFE, 0xFE); |
| 54 const SkColor kProgressBarBorderStroke = SkColorSetRGB(0xA1, 0xA1, 0xA1); |
| 55 |
| 56 const SkColor kProgressBarIndicatorGradient0 = SkColorSetRGB(100, 116, 147); |
| 57 const SkColor kProgressBarIndicatorGradient1 = SkColorSetRGB(65, 73, 87); |
| 58 |
| 59 const SkColor kProgressBarIndicatorDisabledGradient0 = |
| 60 SkColorSetRGB(229, 232, 237); |
| 61 const SkColor kProgressBarIndicatorDisabledGradient1 = |
| 62 SkColorSetRGB(224, 225, 227); |
| 63 |
| 64 const SkColor kProgressBarIndicatorStroke = SkColorSetRGB(0x4A, 0x4A, 0x4A); |
| 65 const SkColor kProgressBarIndicatorDisabledStroke = |
| 66 SkColorSetARGB(0x80, 0x4A, 0x4A, 0x4A); |
| 67 |
| 68 const SkColor kProgressBarIndicatorInnerStroke = |
| 69 SkColorSetARGB(0x3F, 0xFF, 0xFF, 0xFF); // 0.25 white |
| 70 const SkColor kProgressBarIndicatorInnerShadow = |
| 71 SkColorSetARGB(0x54, 0xFF, 0xFF, 0xFF); // 0.33 white |
| 72 |
| 73 // Geometry constants |
| 74 |
| 75 const int kBorderCornerRadius = 3; |
| 76 |
| 77 const int kRadioIndicatorSize = 7; |
| 78 |
| 79 const int kSliderThumbWidth = 16; |
| 80 const int kSliderThumbHeight = 16; |
| 81 const int kSliderTrackSize = 6; |
| 82 |
| 83 void GetRoundRectPathWithPadding(const gfx::Rect rect, |
| 84 int corner_radius, |
| 85 SkScalar padding, |
| 86 SkPath* path) { |
| 87 SkRect bounds = { SkDoubleToScalar(rect.x()) + padding, |
| 88 SkDoubleToScalar(rect.y()) + padding, |
| 89 SkDoubleToScalar(rect.right()) - padding, |
| 90 SkDoubleToScalar(rect.bottom()) - padding }; |
| 91 path->addRoundRect(bounds, |
| 92 SkIntToScalar(corner_radius) - padding, |
| 93 SkIntToScalar(corner_radius) - padding); |
| 94 } |
| 95 |
| 96 void GetRoundRectPath(const gfx::Rect rect, |
| 97 int corner_radius, |
| 98 SkPath* path) { |
| 99 // Add 0.5 pixel padding so that antialias paint does not touch extra pixels. |
| 100 GetRoundRectPathWithPadding(rect, corner_radius, SkIntToScalar(1) / 2, |
| 101 path); |
| 102 } |
| 103 |
| 104 void GetGradientPaintForRect(const gfx::Rect& rect, |
| 105 const SkColor* colors, |
| 106 const SkScalar* stops, |
| 107 int count, |
| 108 SkPaint* paint) { |
| 109 paint->setStyle(SkPaint::kFill_Style); |
| 110 paint->setAntiAlias(true); |
| 111 |
| 112 SkPoint points[2]; |
| 113 points[0].set(SkIntToScalar(rect.x()), SkIntToScalar(rect.y())); |
| 114 points[1].set(SkIntToScalar(rect.x()), SkIntToScalar(rect.bottom())); |
| 115 |
| 116 SkShader* shader = SkGradientShader::CreateLinear(points, |
| 117 colors, stops, count, SkShader::kClamp_TileMode); |
| 118 |
| 119 paint->setShader(shader); |
| 120 // Unref shader after paint takes ownership, otherwise never deleted. |
| 121 shader->unref(); |
| 122 } |
| 123 |
| 124 void GetGradientPaintForRect(const gfx::Rect& rect, |
| 125 SkColor start_color, |
| 126 SkColor end_color, |
| 127 SkPaint* paint) { |
| 128 SkColor colors[2] = { start_color, end_color }; |
| 129 GetGradientPaintForRect(rect, colors, NULL, 2, paint); |
| 130 } |
| 131 |
| 132 void GetButtonGradientPaint(const gfx::Rect bounds, |
| 133 gfx::NativeThemeLinux::State state, |
| 134 SkPaint* paint) { |
| 135 if (state == gfx::NativeThemeLinux::kPressed) { |
| 136 static const SkColor kGradientColors[2] = { |
| 137 kPressedGradient0, |
| 138 kPressedGradient1 |
| 139 }; |
| 140 |
| 141 static const SkScalar kGradientPoints[2] = { |
| 142 SkIntToScalar(0), |
| 143 SkIntToScalar(1) |
| 144 }; |
| 145 |
| 146 GetGradientPaintForRect(bounds, |
| 147 kGradientColors, kGradientPoints, arraysize(kGradientPoints), |
| 148 paint); |
| 149 } else { |
| 150 static const SkColor kGradientColors[3] = { |
| 151 kBaseGradient0, |
| 152 kBaseGradient1, |
| 153 kBaseGradient2 |
| 154 }; |
| 155 |
| 156 static const SkScalar kGradientPoints[3] = { |
| 157 SkIntToScalar(0), |
| 158 SkDoubleToScalar(0.5), |
| 159 SkIntToScalar(1) |
| 160 }; |
| 161 |
| 162 GetGradientPaintForRect(bounds, |
| 163 kGradientColors, kGradientPoints, arraysize(kGradientPoints), |
| 164 paint); |
| 165 } |
| 166 } |
| 167 |
| 168 void GetStrokePaint(SkColor color, SkPaint* paint) { |
| 169 paint->setStyle(SkPaint::kStroke_Style); |
| 170 paint->setAntiAlias(true); |
| 171 paint->setColor(color); |
| 172 } |
| 173 |
| 174 void GetStrokePaint(gfx::NativeThemeLinux::State state, SkPaint* paint) { |
| 175 |
| 176 if (state == gfx::NativeThemeLinux::kDisabled) |
| 177 GetStrokePaint(kDisabledBaseStroke, paint); |
| 178 else |
| 179 GetStrokePaint(kBaseStroke, paint); |
| 180 } |
| 181 |
| 182 void GetIndicatorStrokePaint(gfx::NativeThemeLinux::State state, |
| 183 SkPaint* paint) { |
| 184 paint->setStyle(SkPaint::kStroke_Style); |
| 185 paint->setAntiAlias(true); |
| 186 |
| 187 if (state == gfx::NativeThemeLinux::kDisabled) |
| 188 paint->setColor(kIndicatorStrokeDisabledColor); |
| 189 else if (state == gfx::NativeThemeLinux::kPressed) |
| 190 paint->setColor(kIndicatorStrokePressedColor); |
| 191 else |
| 192 paint->setColor(kIndicatorStrokeColor); |
| 193 } |
| 194 |
| 195 void GetRadioIndicatorGradientPaint(const gfx::Rect bounds, |
| 196 gfx::NativeThemeLinux::State state, |
| 197 SkPaint* paint) { |
| 198 paint->setStyle(SkPaint::kFill_Style); |
| 199 paint->setAntiAlias(true); |
| 200 |
| 201 SkPoint points[2]; |
| 202 points[0].set(SkIntToScalar(bounds.x()), SkIntToScalar(bounds.y())); |
| 203 points[1].set(SkIntToScalar(bounds.x()), SkIntToScalar(bounds.bottom())); |
| 204 |
| 205 static const SkScalar kGradientPoints[2] = { |
| 206 SkIntToScalar(0), |
| 207 SkIntToScalar(1) |
| 208 }; |
| 209 |
| 210 if (state == gfx::NativeThemeLinux::kDisabled) { |
| 211 static const SkColor kGradientColors[2] = { |
| 212 kRadioIndicatorDisabledGradient0, |
| 213 kRadioIndicatorDisabledGradient1 |
| 214 }; |
| 215 |
| 216 GetGradientPaintForRect(bounds, |
| 217 kGradientColors, kGradientPoints, arraysize(kGradientPoints), |
| 218 paint); |
| 219 } else { |
| 220 static const SkColor kGradientColors[2] = { |
| 221 kRadioIndicatorGradient0, |
| 222 kRadioIndicatorGradient1 |
| 223 }; |
| 224 |
| 225 GetGradientPaintForRect(bounds, |
| 226 kGradientColors, kGradientPoints, arraysize(kGradientPoints), |
| 227 paint); |
| 228 } |
| 229 } |
| 230 |
| 231 } |
| 232 |
16 /* static */ | 233 /* static */ |
17 gfx::NativeThemeLinux* gfx::NativeThemeLinux::instance() { | 234 gfx::NativeThemeLinux* gfx::NativeThemeLinux::instance() { |
18 // The global NativeThemeChromeos instance. | 235 // The global NativeThemeChromeos instance. |
19 static NativeThemeChromeos s_native_theme; | 236 static NativeThemeChromeos s_native_theme; |
20 return &s_native_theme; | 237 return &s_native_theme; |
21 } | 238 } |
22 | 239 |
23 NativeThemeChromeos::NativeThemeChromeos() { | 240 NativeThemeChromeos::NativeThemeChromeos() { |
24 } | 241 } |
25 | 242 |
(...skipping 28 matching lines...) Expand all Loading... |
54 case kScrollbarVerticalTrack: | 271 case kScrollbarVerticalTrack: |
55 width = scrollbar_width; | 272 width = scrollbar_width; |
56 height = 0; | 273 height = 0; |
57 break; | 274 break; |
58 case kScrollbarHorizontalThumb: | 275 case kScrollbarHorizontalThumb: |
59 case kScrollbarVerticalThumb: | 276 case kScrollbarVerticalThumb: |
60 // allow thumb to be square but no shorter. | 277 // allow thumb to be square but no shorter. |
61 width = scrollbar_width; | 278 width = scrollbar_width; |
62 height = scrollbar_width; | 279 height = scrollbar_width; |
63 break; | 280 break; |
| 281 case kSliderThumb: |
| 282 width = kSliderThumbWidth; |
| 283 height = kSliderThumbHeight; |
| 284 break; |
| 285 case kInnerSpinButton: |
| 286 return gfx::Size(scrollbar_width, 0); |
64 default: | 287 default: |
65 return NativeThemeLinux::GetPartSize(part); | 288 return NativeThemeLinux::GetPartSize(part); |
66 } | 289 } |
67 return gfx::Size(width, height); | 290 return gfx::Size(width, height); |
68 } | 291 } |
69 | 292 |
70 void NativeThemeChromeos::PaintScrollbarTrack(skia::PlatformCanvas* canvas, | 293 void NativeThemeChromeos::PaintScrollbarTrack(skia::PlatformCanvas* canvas, |
71 Part part, State state, | 294 Part part, State state, |
72 const ScrollbarTrackExtraParams& extra_params, const gfx::Rect& rect) { | 295 const ScrollbarTrackExtraParams& extra_params, const gfx::Rect& rect) { |
73 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 296 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 IDR_SCROLL_ARROW_UP : IDR_SCROLL_ARROW_DOWN; | 389 IDR_SCROLL_ARROW_UP : IDR_SCROLL_ARROW_DOWN; |
167 if (state == kHovered) | 390 if (state == kHovered) |
168 resource_id++; | 391 resource_id++; |
169 else if (state == kPressed) | 392 else if (state == kPressed) |
170 resource_id += 2; | 393 resource_id += 2; |
171 SkBitmap* bitmap; | 394 SkBitmap* bitmap; |
172 if (part == kScrollbarUpArrow || part == kScrollbarDownArrow) | 395 if (part == kScrollbarUpArrow || part == kScrollbarDownArrow) |
173 bitmap = rb.GetBitmapNamed(resource_id); | 396 bitmap = rb.GetBitmapNamed(resource_id); |
174 else | 397 else |
175 bitmap = GetHorizontalBitmapNamed(resource_id); | 398 bitmap = GetHorizontalBitmapNamed(resource_id); |
176 canvas->drawBitmap(*bitmap, rect.x(), rect.y()); | 399 DrawBitmapInt(canvas, *bitmap, |
| 400 0, 0, bitmap->width(), bitmap->height(), |
| 401 rect.x(), rect.y(), rect.width(), rect.height()); |
| 402 } |
| 403 |
| 404 void NativeThemeChromeos::PaintCheckbox(skia::PlatformCanvas* canvas, |
| 405 State state, const gfx::Rect& rect, |
| 406 const ButtonExtraParams& button) { |
| 407 PaintButtonLike(canvas, state, rect, button); |
| 408 |
| 409 if (button.checked) { |
| 410 SkPaint indicator_paint; |
| 411 GetIndicatorStrokePaint(state, &indicator_paint); |
| 412 indicator_paint.setStrokeWidth(2); |
| 413 |
| 414 const int kMidX = rect.x() + rect.width() / 2; |
| 415 const int kMidY = rect.y() + rect.height() / 2; |
| 416 canvas->drawLine(SkIntToScalar(rect.x() + 3), SkIntToScalar(kMidY), |
| 417 SkIntToScalar(kMidX - 1), SkIntToScalar(rect.bottom() - 3), |
| 418 indicator_paint); |
| 419 canvas->drawLine(SkIntToScalar(kMidX - 1), SkIntToScalar(rect.bottom() - 3), |
| 420 SkIntToScalar(rect.right() - 3), SkIntToScalar(rect.y() + 3), |
| 421 indicator_paint); |
| 422 } |
| 423 } |
| 424 |
| 425 void NativeThemeChromeos::PaintRadio(skia::PlatformCanvas* canvas, |
| 426 State state, |
| 427 const gfx::Rect& rect, |
| 428 const ButtonExtraParams& button) { |
| 429 gfx::Point center = rect.CenterPoint(); |
| 430 SkPath border; |
| 431 border.addCircle(SkIntToScalar(center.x()), SkIntToScalar(center.y()), |
| 432 SkDoubleToScalar(rect.width() / 2.0)); |
| 433 |
| 434 SkPaint fill_paint; |
| 435 GetButtonGradientPaint(rect, state, &fill_paint); |
| 436 canvas->drawPath(border, fill_paint); |
| 437 |
| 438 SkPaint stroke_paint; |
| 439 GetStrokePaint(state, &stroke_paint); |
| 440 canvas->drawPath(border, stroke_paint); |
| 441 |
| 442 if (button.checked) { |
| 443 SkPath indicator_border; |
| 444 indicator_border.addCircle(SkIntToScalar(center.x()), |
| 445 SkIntToScalar(center.y()), |
| 446 SkDoubleToScalar(kRadioIndicatorSize / 2.0)); |
| 447 |
| 448 SkPaint indicator_fill_paint; |
| 449 GetRadioIndicatorGradientPaint(rect, state, &indicator_fill_paint); |
| 450 canvas->drawPath(indicator_border, indicator_fill_paint); |
| 451 |
| 452 SkPaint indicator_paint; |
| 453 GetIndicatorStrokePaint(state, &indicator_paint); |
| 454 canvas->drawPath(indicator_border, indicator_paint); |
| 455 } |
| 456 } |
| 457 |
| 458 void NativeThemeChromeos::PaintButton(skia::PlatformCanvas* canvas, |
| 459 State state, |
| 460 const gfx::Rect& rect, |
| 461 const ButtonExtraParams& button) { |
| 462 PaintButtonLike(canvas, state, rect, button); |
| 463 } |
| 464 |
| 465 void NativeThemeChromeos::PaintTextField(skia::PlatformCanvas* canvas, |
| 466 State state, |
| 467 const gfx::Rect& rect, |
| 468 const TextFieldExtraParams& text) { |
| 469 if (rect.height() == 0) |
| 470 return; |
| 471 |
| 472 SkColor background_color = text.background_color; |
| 473 |
| 474 SkPaint fill_paint; |
| 475 fill_paint.setStyle(SkPaint::kFill_Style); |
| 476 if (state == kDisabled) { |
| 477 fill_paint.setColor(background_color); |
| 478 } else { |
| 479 SkScalar base_hsv[3]; |
| 480 SkColorToHSV(background_color, base_hsv); |
| 481 |
| 482 const SkColor gradient_colors[3] = { |
| 483 SaturateAndBrighten(base_hsv, 0, -0.18), |
| 484 background_color, |
| 485 background_color |
| 486 }; |
| 487 |
| 488 const SkScalar gradient_points[3] = { |
| 489 SkIntToScalar(0), |
| 490 SkDoubleToScalar(4.0 / rect.height()), |
| 491 SkIntToScalar(1) |
| 492 }; |
| 493 |
| 494 SkPoint points[2]; |
| 495 points[0].set(SkIntToScalar(rect.x()), SkIntToScalar(rect.y())); |
| 496 points[1].set(SkIntToScalar(rect.x()), SkIntToScalar(rect.bottom())); |
| 497 |
| 498 GetGradientPaintForRect(rect, |
| 499 gradient_colors, gradient_points, arraysize(gradient_points), |
| 500 &fill_paint); |
| 501 } |
| 502 |
| 503 SkPath border; |
| 504 GetRoundRectPath(rect, kBorderCornerRadius, &border); |
| 505 canvas->drawPath(border, fill_paint); |
| 506 |
| 507 SkPaint stroke_paint; |
| 508 GetStrokePaint(state, &stroke_paint); |
| 509 canvas->drawPath(border, stroke_paint); |
| 510 } |
| 511 |
| 512 void NativeThemeChromeos::PaintSliderTrack(skia::PlatformCanvas* canvas, |
| 513 State state, |
| 514 const gfx::Rect& rect, |
| 515 const SliderExtraParams& slider) { |
| 516 const int kMidX = rect.x() + rect.width() / 2; |
| 517 const int kMidY = rect.y() + rect.height() / 2; |
| 518 |
| 519 gfx::Rect track_bounds; |
| 520 if (slider.vertical) { |
| 521 track_bounds.SetRect(std::max(rect.x(), kMidX - kSliderTrackSize / 2), |
| 522 rect.y(), |
| 523 std::min(rect.width(), kSliderTrackSize), |
| 524 rect.height()); |
| 525 } else { |
| 526 track_bounds.SetRect(rect.x(), |
| 527 std::max(rect.y(), kMidY - kSliderTrackSize / 2), |
| 528 rect.width(), |
| 529 std::min(rect.height(), kSliderTrackSize)); |
| 530 } |
| 531 |
| 532 SkPath border; |
| 533 GetRoundRectPath(track_bounds, kBorderCornerRadius, &border); |
| 534 |
| 535 SkPaint fill_paint; |
| 536 // Use normal button background. |
| 537 GetButtonGradientPaint(rect, kNormal, &fill_paint); |
| 538 canvas->drawPath(border, fill_paint); |
| 539 |
| 540 SkPaint stroke_paint; |
| 541 GetStrokePaint(state, &stroke_paint); |
| 542 canvas->drawPath(border, stroke_paint); |
| 543 } |
| 544 |
| 545 void NativeThemeChromeos::PaintSliderThumb(skia::PlatformCanvas* canvas, |
| 546 State state, |
| 547 const gfx::Rect& rect, |
| 548 const SliderExtraParams& slider) { |
| 549 if (state != kDisabled && slider.in_drag) |
| 550 state = kPressed; |
| 551 |
| 552 ButtonExtraParams button = { 0 }; |
| 553 PaintButtonLike(canvas, state, rect, button); |
| 554 } |
| 555 |
| 556 void NativeThemeChromeos::PaintInnerSpinButton(skia::PlatformCanvas* canvas, |
| 557 State state, |
| 558 const gfx::Rect& rect, |
| 559 const InnerSpinButtonExtraParams& spin_button) { |
| 560 // Adjust bounds to compensate the overridden "2px inset" parent border. |
| 561 gfx::Rect bounds = rect; |
| 562 bounds.Inset(0, -1, -1, -1); |
| 563 |
| 564 NativeThemeLinux::PaintInnerSpinButton(canvas, state, bounds, spin_button); |
| 565 } |
| 566 |
| 567 void NativeThemeChromeos::PaintProgressBar(skia::PlatformCanvas* canvas, |
| 568 State state, |
| 569 const gfx::Rect& rect, |
| 570 const ProgressBarExtraParams& progress_bar) { |
| 571 static const int kBorderWidth = 1; |
| 572 static const SkColor kBackgroundColors[] = { |
| 573 kProgressBarBackgroundGradient0, |
| 574 kProgressBarBackgroundGradient1, |
| 575 kProgressBarBackgroundGradient2 |
| 576 }; |
| 577 |
| 578 static const SkScalar kBackgroundPoints[] = { |
| 579 SkDoubleToScalar(0), |
| 580 SkDoubleToScalar(0.1), |
| 581 SkDoubleToScalar(1) |
| 582 }; |
| 583 static const SkColor kBackgroundBorderColor = kProgressBarBorderStroke; |
| 584 |
| 585 // Draw background. |
| 586 SkPath border; |
| 587 GetRoundRectPath(rect, kBorderCornerRadius, &border); |
| 588 |
| 589 SkPaint fill_paint; |
| 590 GetGradientPaintForRect(rect, |
| 591 kBackgroundColors, kBackgroundPoints, arraysize(kBackgroundPoints), |
| 592 &fill_paint); |
| 593 canvas->drawPath(border, fill_paint); |
| 594 |
| 595 SkPaint stroke_paint; |
| 596 GetStrokePaint(kBackgroundBorderColor, &stroke_paint); |
| 597 canvas->drawPath(border, stroke_paint); |
| 598 |
| 599 if (progress_bar.value_rect_width > 1) { |
| 600 bool enabled = state != kDisabled; |
| 601 gfx::Rect value_rect(progress_bar.value_rect_x, |
| 602 progress_bar.value_rect_y, |
| 603 progress_bar.value_rect_width, |
| 604 progress_bar.value_rect_height); |
| 605 |
| 606 const SkColor bar_color_start = enabled ? |
| 607 kProgressBarIndicatorGradient0 : |
| 608 kProgressBarIndicatorDisabledGradient0; |
| 609 const SkColor bar_color_end = enabled ? |
| 610 kProgressBarIndicatorGradient1 : |
| 611 kProgressBarIndicatorDisabledGradient1; |
| 612 |
| 613 const SkColor bar_outer_color = enabled ? |
| 614 kProgressBarIndicatorStroke : |
| 615 kProgressBarIndicatorDisabledStroke; |
| 616 |
| 617 const SkColor bar_inner_border_color = kProgressBarIndicatorInnerStroke; |
| 618 const SkColor bar_inner_shadow_color = kProgressBarIndicatorInnerShadow; |
| 619 |
| 620 // Draw bar background |
| 621 SkPath value_border; |
| 622 GetRoundRectPath(value_rect, kBorderCornerRadius, &value_border); |
| 623 |
| 624 SkPaint value_fill_paint; |
| 625 GetGradientPaintForRect(rect,bar_color_start, bar_color_end, |
| 626 &value_fill_paint); |
| 627 canvas->drawPath(value_border, value_fill_paint); |
| 628 |
| 629 // Draw inner stroke and shadow if wide enough. |
| 630 if (progress_bar.value_rect_width > 2 * kBorderWidth) { |
| 631 canvas->save(); |
| 632 |
| 633 SkPath inner_path; |
| 634 GetRoundRectPathWithPadding(value_rect, kBorderCornerRadius, |
| 635 SkIntToScalar(kBorderWidth), &inner_path); |
| 636 canvas->clipPath(inner_path); |
| 637 |
| 638 // Draw bar inner stroke |
| 639 gfx::Rect inner_stroke_rect = value_rect; |
| 640 inner_stroke_rect.Inset(kBorderWidth, kBorderWidth); |
| 641 |
| 642 SkPath inner_stroke_path; |
| 643 GetRoundRectPath(inner_stroke_rect, kBorderCornerRadius - kBorderWidth, |
| 644 &inner_stroke_path); |
| 645 |
| 646 SkPaint inner_stroke_paint; |
| 647 GetStrokePaint(bar_inner_border_color, &inner_stroke_paint); |
| 648 |
| 649 canvas->drawPath(inner_stroke_path, inner_stroke_paint); |
| 650 |
| 651 // Draw bar inner shadow |
| 652 gfx::Rect inner_shadow_rect(progress_bar.value_rect_x, |
| 653 progress_bar.value_rect_y + kBorderWidth, |
| 654 progress_bar.value_rect_width, |
| 655 progress_bar.value_rect_height); |
| 656 SkPath inner_shadow_path; |
| 657 GetRoundRectPath(inner_shadow_rect, kBorderCornerRadius, |
| 658 &inner_shadow_path); |
| 659 |
| 660 SkPaint inner_shadow_paint; |
| 661 GetStrokePaint(bar_inner_shadow_color, &inner_shadow_paint); |
| 662 |
| 663 canvas->drawPath(inner_shadow_path, inner_shadow_paint); |
| 664 |
| 665 canvas->restore(); |
| 666 } |
| 667 |
| 668 // Draw bar stroke |
| 669 SkPaint value_stroke_paint; |
| 670 GetStrokePaint(bar_outer_color, &value_stroke_paint); |
| 671 canvas->drawPath(value_border, value_stroke_paint); |
| 672 } |
177 } | 673 } |
178 | 674 |
179 SkBitmap* NativeThemeChromeos::GetHorizontalBitmapNamed(int resource_id) { | 675 SkBitmap* NativeThemeChromeos::GetHorizontalBitmapNamed(int resource_id) { |
180 SkImageMap::const_iterator found = horizontal_bitmaps_.find(resource_id); | 676 SkImageMap::const_iterator found = horizontal_bitmaps_.find(resource_id); |
181 if (found != horizontal_bitmaps_.end()) | 677 if (found != horizontal_bitmaps_.end()) |
182 return found->second; | 678 return found->second; |
183 | 679 |
184 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 680 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
185 SkBitmap* vertical_bitmap = rb.GetBitmapNamed(resource_id); | 681 SkBitmap* vertical_bitmap = rb.GetBitmapNamed(resource_id); |
186 | 682 |
187 if (vertical_bitmap) { | 683 if (vertical_bitmap) { |
188 SkBitmap transposed_bitmap = | 684 SkBitmap transposed_bitmap = |
189 SkBitmapOperations::CreateTransposedBtmap(*vertical_bitmap); | 685 SkBitmapOperations::CreateTransposedBtmap(*vertical_bitmap); |
190 SkBitmap* horizontal_bitmap = new SkBitmap(transposed_bitmap); | 686 SkBitmap* horizontal_bitmap = new SkBitmap(transposed_bitmap); |
191 | 687 |
192 horizontal_bitmaps_[resource_id] = horizontal_bitmap; | 688 horizontal_bitmaps_[resource_id] = horizontal_bitmap; |
193 return horizontal_bitmap; | 689 return horizontal_bitmap; |
194 } | 690 } |
195 return NULL; | 691 return NULL; |
196 } | 692 } |
| 693 |
| 694 void NativeThemeChromeos::PaintButtonLike(skia::PlatformCanvas* canvas, |
| 695 State state, const gfx::Rect& rect, |
| 696 const ButtonExtraParams& button) { |
| 697 SkPath border; |
| 698 GetRoundRectPath(rect, kBorderCornerRadius, &border); |
| 699 |
| 700 SkPaint fill_paint; |
| 701 GetButtonGradientPaint(rect, state, &fill_paint); |
| 702 canvas->drawPath(border, fill_paint); |
| 703 |
| 704 SkPaint stroke_paint; |
| 705 GetStrokePaint(state, &stroke_paint); |
| 706 canvas->drawPath(border, stroke_paint); |
| 707 } |
OLD | NEW |