| 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/base/native_theme/native_theme_base.h" | 5 #include "ui/base/native_theme/native_theme_base.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "grit/ui_resources_standard.h" | 10 #include "grit/ui_resources_standard.h" |
| 11 #include "third_party/skia/include/effects/SkGradientShader.h" | 11 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 12 #include "ui/base/resource/resource_bundle.h" | 12 #include "ui/base/resource/resource_bundle.h" |
| 13 #include "ui/gfx/canvas.h" | 13 #include "ui/gfx/canvas.h" |
| 14 #include "ui/gfx/color_utils.h" | 14 #include "ui/gfx/color_utils.h" |
| 15 #include "ui/gfx/image/image_skia.h" |
| 15 #include "ui/gfx/rect.h" | 16 #include "ui/gfx/rect.h" |
| 16 #include "ui/gfx/size.h" | 17 #include "ui/gfx/size.h" |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 // These are the default dimensions of radio buttons and checkboxes. | 21 // These are the default dimensions of radio buttons and checkboxes. |
| 21 const int kCheckboxAndRadioWidth = 13; | 22 const int kCheckboxAndRadioWidth = 13; |
| 22 const int kCheckboxAndRadioHeight = 13; | 23 const int kCheckboxAndRadioHeight = 13; |
| 23 | 24 |
| 24 // These sizes match the sizes in Chromium Win. | 25 // These sizes match the sizes in Chromium Win. |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 paint); | 438 paint); |
| 438 } | 439 } |
| 439 } | 440 } |
| 440 } | 441 } |
| 441 | 442 |
| 442 void NativeThemeBase::PaintCheckbox(SkCanvas* canvas, | 443 void NativeThemeBase::PaintCheckbox(SkCanvas* canvas, |
| 443 State state, | 444 State state, |
| 444 const gfx::Rect& rect, | 445 const gfx::Rect& rect, |
| 445 const ButtonExtraParams& button) const { | 446 const ButtonExtraParams& button) const { |
| 446 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 447 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 447 SkBitmap* image = NULL; | 448 gfx::ImageSkia* image = NULL; |
| 448 if (button.indeterminate) { | 449 if (button.indeterminate) { |
| 449 image = state == kDisabled ? | 450 image = state == kDisabled ? |
| 450 rb.GetBitmapNamed(IDR_CHECKBOX_DISABLED_INDETERMINATE) : | 451 rb.GetImageSkiaNamed(IDR_CHECKBOX_DISABLED_INDETERMINATE) : |
| 451 rb.GetBitmapNamed(IDR_CHECKBOX_INDETERMINATE); | 452 rb.GetImageSkiaNamed(IDR_CHECKBOX_INDETERMINATE); |
| 452 } else if (button.checked) { | 453 } else if (button.checked) { |
| 453 image = state == kDisabled ? | 454 image = state == kDisabled ? |
| 454 rb.GetBitmapNamed(IDR_CHECKBOX_DISABLED_ON) : | 455 rb.GetImageSkiaNamed(IDR_CHECKBOX_DISABLED_ON) : |
| 455 rb.GetBitmapNamed(IDR_CHECKBOX_ON); | 456 rb.GetImageSkiaNamed(IDR_CHECKBOX_ON); |
| 456 } else { | 457 } else { |
| 457 image = state == kDisabled ? | 458 image = state == kDisabled ? |
| 458 rb.GetBitmapNamed(IDR_CHECKBOX_DISABLED_OFF) : | 459 rb.GetImageSkiaNamed(IDR_CHECKBOX_DISABLED_OFF) : |
| 459 rb.GetBitmapNamed(IDR_CHECKBOX_OFF); | 460 rb.GetImageSkiaNamed(IDR_CHECKBOX_OFF); |
| 460 } | 461 } |
| 461 | 462 |
| 462 gfx::Rect bounds = rect.Center(gfx::Size(image->width(), image->height())); | 463 gfx::Rect bounds = rect.Center(gfx::Size(image->width(), image->height())); |
| 463 DrawBitmapInt(canvas, *image, 0, 0, image->width(), image->height(), | 464 DrawBitmapInt(canvas, *image, 0, 0, image->width(), image->height(), |
| 464 bounds.x(), bounds.y(), bounds.width(), bounds.height()); | 465 bounds.x(), bounds.y(), bounds.width(), bounds.height()); |
| 465 } | 466 } |
| 466 | 467 |
| 467 void NativeThemeBase::PaintRadio(SkCanvas* canvas, | 468 void NativeThemeBase::PaintRadio(SkCanvas* canvas, |
| 468 State state, | 469 State state, |
| 469 const gfx::Rect& rect, | 470 const gfx::Rect& rect, |
| 470 const ButtonExtraParams& button) const { | 471 const ButtonExtraParams& button) const { |
| 471 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 472 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 472 SkBitmap* image = NULL; | 473 gfx::ImageSkia* image = NULL; |
| 473 if (state == kDisabled) { | 474 if (state == kDisabled) { |
| 474 image = button.checked ? | 475 image = button.checked ? |
| 475 rb.GetBitmapNamed(IDR_RADIO_DISABLED_ON) : | 476 rb.GetImageSkiaNamed(IDR_RADIO_DISABLED_ON) : |
| 476 rb.GetBitmapNamed(IDR_RADIO_DISABLED_OFF); | 477 rb.GetImageSkiaNamed(IDR_RADIO_DISABLED_OFF); |
| 477 } else { | 478 } else { |
| 478 image = button.checked ? | 479 image = button.checked ? |
| 479 rb.GetBitmapNamed(IDR_RADIO_ON) : | 480 rb.GetImageSkiaNamed(IDR_RADIO_ON) : |
| 480 rb.GetBitmapNamed(IDR_RADIO_OFF); | 481 rb.GetImageSkiaNamed(IDR_RADIO_OFF); |
| 481 } | 482 } |
| 482 | 483 |
| 483 gfx::Rect bounds = rect.Center(gfx::Size(image->width(), image->height())); | 484 gfx::Rect bounds = rect.Center(gfx::Size(image->width(), image->height())); |
| 484 DrawBitmapInt(canvas, *image, 0, 0, image->width(), image->height(), | 485 DrawBitmapInt(canvas, *image, 0, 0, image->width(), image->height(), |
| 485 bounds.x(), bounds.y(), bounds.width(), bounds.height()); | 486 bounds.x(), bounds.y(), bounds.width(), bounds.height()); |
| 486 } | 487 } |
| 487 | 488 |
| 488 void NativeThemeBase::PaintButton(SkCanvas* canvas, | 489 void NativeThemeBase::PaintButton(SkCanvas* canvas, |
| 489 State state, | 490 State state, |
| 490 const gfx::Rect& rect, | 491 const gfx::Rect& rect, |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 | 753 |
| 753 half.set_y(rect.y() + rect.height() / 2); | 754 half.set_y(rect.y() + rect.height() / 2); |
| 754 PaintArrowButton(canvas, half, kScrollbarDownArrow, south_state); | 755 PaintArrowButton(canvas, half, kScrollbarDownArrow, south_state); |
| 755 } | 756 } |
| 756 | 757 |
| 757 void NativeThemeBase::PaintProgressBar(SkCanvas* canvas, | 758 void NativeThemeBase::PaintProgressBar(SkCanvas* canvas, |
| 758 State state, | 759 State state, |
| 759 const gfx::Rect& rect, | 760 const gfx::Rect& rect, |
| 760 const ProgressBarExtraParams& progress_bar) const { | 761 const ProgressBarExtraParams& progress_bar) const { |
| 761 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 762 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 762 SkBitmap* bar_image = rb.GetBitmapNamed(IDR_PROGRESS_BAR); | 763 gfx::ImageSkia* bar_image = rb.GetImageSkiaNamed(IDR_PROGRESS_BAR); |
| 763 SkBitmap* left_border_image = rb.GetBitmapNamed(IDR_PROGRESS_BORDER_LEFT); | 764 gfx::ImageSkia* left_border_image = rb.GetImageSkiaNamed( |
| 764 SkBitmap* right_border_image = rb.GetBitmapNamed(IDR_PROGRESS_BORDER_RIGHT); | 765 IDR_PROGRESS_BORDER_LEFT); |
| 766 gfx::ImageSkia* right_border_image = rb.GetImageSkiaNamed( |
| 767 IDR_PROGRESS_BORDER_RIGHT); |
| 765 | 768 |
| 766 float tile_scale = static_cast<float>(rect.height()) / | 769 float tile_scale = static_cast<float>(rect.height()) / |
| 767 bar_image->height(); | 770 bar_image->height(); |
| 768 | 771 |
| 769 int new_tile_width = static_cast<int>(bar_image->width() * tile_scale); | 772 int new_tile_width = static_cast<int>(bar_image->width() * tile_scale); |
| 770 float tile_scale_x = static_cast<float>(new_tile_width) / | 773 float tile_scale_x = static_cast<float>(new_tile_width) / |
| 771 bar_image->width(); | 774 bar_image->width(); |
| 772 | 775 |
| 773 DrawTiledImage(canvas, *bar_image, 0, 0, tile_scale_x, tile_scale, | 776 DrawTiledImage(canvas, *bar_image, 0, 0, tile_scale_x, tile_scale, |
| 774 rect.x(), rect.y(), rect.width(), rect.height()); | 777 rect.x(), rect.y(), rect.width(), rect.height()); |
| 775 | 778 |
| 776 if (progress_bar.value_rect_width) { | 779 if (progress_bar.value_rect_width) { |
| 777 SkBitmap* value_image = rb.GetBitmapNamed(IDR_PROGRESS_VALUE); | 780 gfx::ImageSkia* value_image = rb.GetImageSkiaNamed(IDR_PROGRESS_VALUE); |
| 778 | 781 |
| 779 new_tile_width = static_cast<int>(value_image->width() * tile_scale); | 782 new_tile_width = static_cast<int>(value_image->width() * tile_scale); |
| 780 tile_scale_x = static_cast<float>(new_tile_width) / | 783 tile_scale_x = static_cast<float>(new_tile_width) / |
| 781 value_image->width(); | 784 value_image->width(); |
| 782 | 785 |
| 783 DrawTiledImage(canvas, *value_image, 0, 0, tile_scale_x, tile_scale, | 786 DrawTiledImage(canvas, *value_image, 0, 0, tile_scale_x, tile_scale, |
| 784 progress_bar.value_rect_x, | 787 progress_bar.value_rect_x, |
| 785 progress_bar.value_rect_y, | 788 progress_bar.value_rect_y, |
| 786 progress_bar.value_rect_width, | 789 progress_bar.value_rect_width, |
| 787 progress_bar.value_rect_height); | 790 progress_bar.value_rect_height); |
| 788 } | 791 } |
| 789 | 792 |
| 790 int dest_left_border_width = static_cast<int>(left_border_image->width() * | 793 int dest_left_border_width = static_cast<int>(left_border_image->width() * |
| 791 tile_scale); | 794 tile_scale); |
| 792 SkRect dest_rect; | 795 DrawBitmapInt(canvas, *left_border_image, 0, 0, left_border_image->width(), |
| 793 dest_rect.iset(rect.x(), rect.y(), rect.x() + dest_left_border_width, | 796 left_border_image->height(), rect.x(), rect.y(), dest_left_border_width, |
| 794 rect.bottom()); | 797 rect.height()); |
| 795 canvas->drawBitmapRect(*left_border_image, NULL, dest_rect); | |
| 796 | 798 |
| 797 int dest_right_border_width = static_cast<int>(right_border_image->width() * | 799 int dest_right_border_width = static_cast<int>(right_border_image->width() * |
| 798 tile_scale); | 800 tile_scale); |
| 799 dest_rect.iset(rect.right() - dest_right_border_width, rect.y(), rect.right(), | 801 int dest_x = rect.right() - dest_right_border_width; |
| 800 rect.bottom()); | 802 DrawBitmapInt(canvas, *right_border_image, 0, 0, right_border_image->width(), |
| 801 canvas->drawBitmapRect(*right_border_image, NULL, dest_rect); | 803 right_border_image->height(), dest_x, rect.y(), |
| 804 dest_right_border_width, rect.height()); |
| 802 } | 805 } |
| 803 | 806 |
| 804 bool NativeThemeBase::IntersectsClipRectInt(SkCanvas* canvas, | 807 bool NativeThemeBase::IntersectsClipRectInt(SkCanvas* canvas, |
| 805 int x, int y, int w, int h) const { | 808 int x, int y, int w, int h) const { |
| 806 SkRect clip; | 809 SkRect clip; |
| 807 return canvas->getClipBounds(&clip) && | 810 return canvas->getClipBounds(&clip) && |
| 808 clip.intersect(SkIntToScalar(x), SkIntToScalar(y), SkIntToScalar(x + w), | 811 clip.intersect(SkIntToScalar(x), SkIntToScalar(y), SkIntToScalar(x + w), |
| 809 SkIntToScalar(y + h)); | 812 SkIntToScalar(y + h)); |
| 810 } | 813 } |
| 811 | 814 |
| 812 void NativeThemeBase::DrawBitmapInt( | 815 void NativeThemeBase::DrawBitmapInt( |
| 813 SkCanvas* canvas, const SkBitmap& bitmap, | 816 SkCanvas* canvas, const gfx::ImageSkia& image, |
| 814 int src_x, int src_y, int src_w, int src_h, | 817 int src_x, int src_y, int src_w, int src_h, |
| 815 int dest_x, int dest_y, int dest_w, int dest_h) const { | 818 int dest_x, int dest_y, int dest_w, int dest_h) const { |
| 816 gfx::Canvas(canvas).DrawBitmapInt(bitmap, src_x, src_y, src_w, src_h, | 819 gfx::Canvas(canvas).DrawBitmapInt(image, src_x, src_y, src_w, src_h, |
| 817 dest_x, dest_y, dest_w, dest_h, true); | 820 dest_x, dest_y, dest_w, dest_h, true); |
| 818 } | 821 } |
| 819 | 822 |
| 820 void NativeThemeBase::DrawTiledImage(SkCanvas* canvas, | 823 void NativeThemeBase::DrawTiledImage(SkCanvas* canvas, |
| 821 const SkBitmap& bitmap, | 824 const gfx::ImageSkia& image, |
| 822 int src_x, int src_y, float tile_scale_x, float tile_scale_y, | 825 int src_x, int src_y, float tile_scale_x, float tile_scale_y, |
| 823 int dest_x, int dest_y, int w, int h) const { | 826 int dest_x, int dest_y, int w, int h) const { |
| 824 gfx::Canvas(canvas).TileImageInt(bitmap, src_x, src_y, tile_scale_x, | 827 gfx::Canvas(canvas).TileImageInt(image, src_x, src_y, tile_scale_x, |
| 825 tile_scale_y, dest_x, dest_y, w, h); | 828 tile_scale_y, dest_x, dest_y, w, h); |
| 826 } | 829 } |
| 827 | 830 |
| 828 SkColor NativeThemeBase::SaturateAndBrighten(SkScalar* hsv, | 831 SkColor NativeThemeBase::SaturateAndBrighten(SkScalar* hsv, |
| 829 SkScalar saturate_amount, | 832 SkScalar saturate_amount, |
| 830 SkScalar brighten_amount) const { | 833 SkScalar brighten_amount) const { |
| 831 SkScalar color[3]; | 834 SkScalar color[3]; |
| 832 color[0] = hsv[0]; | 835 color[0] = hsv[0]; |
| 833 color[1] = Clamp(hsv[1] + saturate_amount, 0.0, 1.0); | 836 color[1] = Clamp(hsv[1] + saturate_amount, 0.0, 1.0); |
| 834 color[2] = Clamp(hsv[2] + brighten_amount, 0.0, 1.0); | 837 color[2] = Clamp(hsv[2] + brighten_amount, 0.0, 1.0); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 SkScalar min_diff = Clamp((hsv1[1] + hsv2[1]) * 1.2f, 0.28f, 0.5f); | 906 SkScalar min_diff = Clamp((hsv1[1] + hsv2[1]) * 1.2f, 0.28f, 0.5f); |
| 904 SkScalar diff = Clamp(fabs(hsv1[2] - hsv2[2]) / 2, min_diff, 0.5f); | 907 SkScalar diff = Clamp(fabs(hsv1[2] - hsv2[2]) / 2, min_diff, 0.5f); |
| 905 | 908 |
| 906 if (hsv1[2] + hsv2[2] > 1.0) | 909 if (hsv1[2] + hsv2[2] > 1.0) |
| 907 diff = -diff; | 910 diff = -diff; |
| 908 | 911 |
| 909 return SaturateAndBrighten(hsv2, -0.2f, diff); | 912 return SaturateAndBrighten(hsv2, -0.2f, diff); |
| 910 } | 913 } |
| 911 | 914 |
| 912 } // namespace ui | 915 } // namespace ui |
| OLD | NEW |