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