| 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_android.h" | 5 #include "ui/base/native_theme/native_theme_android.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 path.close(); | 272 path.close(); |
| 273 | 273 |
| 274 canvas->drawPath(path, paint); | 274 canvas->drawPath(path, paint); |
| 275 } | 275 } |
| 276 | 276 |
| 277 void NativeThemeAndroid::PaintCheckbox(SkCanvas* canvas, | 277 void NativeThemeAndroid::PaintCheckbox(SkCanvas* canvas, |
| 278 State state, | 278 State state, |
| 279 const gfx::Rect& rect, | 279 const gfx::Rect& rect, |
| 280 const ButtonExtraParams& button) const { | 280 const ButtonExtraParams& button) const { |
| 281 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 281 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 282 SkBitmap* image = NULL; | 282 gfx::ImageSkia* image = NULL; |
| 283 if (button.indeterminate) { | 283 if (button.indeterminate) { |
| 284 image = state == kDisabled ? | 284 image = state == kDisabled ? |
| 285 rb.GetBitmapNamed(IDR_CHECKBOX_DISABLED_INDETERMINATE) : | 285 rb.GetImageSkiaNamed(IDR_CHECKBOX_DISABLED_INDETERMINATE) : |
| 286 rb.GetBitmapNamed(IDR_CHECKBOX_INDETERMINATE); | 286 rb.GetImageSkiaNamed(IDR_CHECKBOX_INDETERMINATE); |
| 287 } else if (button.checked) { | 287 } else if (button.checked) { |
| 288 image = state == kDisabled ? | 288 image = state == kDisabled ? |
| 289 rb.GetBitmapNamed(IDR_CHECKBOX_DISABLED_ON) : | 289 rb.GetImageSkiaNamed(IDR_CHECKBOX_DISABLED_ON) : |
| 290 rb.GetBitmapNamed(IDR_CHECKBOX_ON); | 290 rb.GetImageSkiaNamed(IDR_CHECKBOX_ON); |
| 291 } else { | 291 } else { |
| 292 image = state == kDisabled ? | 292 image = state == kDisabled ? |
| 293 rb.GetBitmapNamed(IDR_CHECKBOX_DISABLED_OFF) : | 293 rb.GetImageSkiaNamed(IDR_CHECKBOX_DISABLED_OFF) : |
| 294 rb.GetBitmapNamed(IDR_CHECKBOX_OFF); | 294 rb.GetImageSkiaNamed(IDR_CHECKBOX_OFF); |
| 295 } | 295 } |
| 296 | 296 |
| 297 gfx::Rect bounds = rect.Center(gfx::Size(image->width(), image->height())); | 297 gfx::Rect bounds = rect.Center(gfx::Size(image->width(), image->height())); |
| 298 DrawBitmapInt(canvas, *image, 0, 0, image->width(), image->height(), | 298 DrawBitmapInt(canvas, *image, 0, 0, image->width(), image->height(), |
| 299 bounds.x(), bounds.y(), bounds.width(), bounds.height()); | 299 bounds.x(), bounds.y(), bounds.width(), bounds.height()); |
| 300 } | 300 } |
| 301 | 301 |
| 302 void NativeThemeAndroid::PaintRadio(SkCanvas* canvas, | 302 void NativeThemeAndroid::PaintRadio(SkCanvas* canvas, |
| 303 State state, | 303 State state, |
| 304 const gfx::Rect& rect, | 304 const gfx::Rect& rect, |
| 305 const ButtonExtraParams& button) const { | 305 const ButtonExtraParams& button) const { |
| 306 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 306 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 307 SkBitmap* image = NULL; | 307 gfx::ImageSkia* image = NULL; |
| 308 if (state == kDisabled) { | 308 if (state == kDisabled) { |
| 309 image = button.checked ? | 309 image = button.checked ? |
| 310 rb.GetBitmapNamed(IDR_RADIO_DISABLED_ON) : | 310 rb.GetImageSkiaNamed(IDR_RADIO_DISABLED_ON) : |
| 311 rb.GetBitmapNamed(IDR_RADIO_DISABLED_OFF); | 311 rb.GetImageSkiaNamed(IDR_RADIO_DISABLED_OFF); |
| 312 } else { | 312 } else { |
| 313 image = button.checked ? | 313 image = button.checked ? |
| 314 rb.GetBitmapNamed(IDR_RADIO_ON) : | 314 rb.GetImageSkiaNamed(IDR_RADIO_ON) : |
| 315 rb.GetBitmapNamed(IDR_RADIO_OFF); | 315 rb.GetImageSkiaNamed(IDR_RADIO_OFF); |
| 316 } | 316 } |
| 317 | 317 |
| 318 gfx::Rect bounds = rect.Center(gfx::Size(image->width(), image->height())); | 318 gfx::Rect bounds = rect.Center(gfx::Size(image->width(), image->height())); |
| 319 DrawBitmapInt(canvas, *image, 0, 0, image->width(), image->height(), | 319 DrawBitmapInt(canvas, *image, 0, 0, image->width(), image->height(), |
| 320 bounds.x(), bounds.y(), bounds.width(), bounds.height()); | 320 bounds.x(), bounds.y(), bounds.width(), bounds.height()); |
| 321 } | 321 } |
| 322 | 322 |
| 323 void NativeThemeAndroid::PaintButton(SkCanvas* canvas, | 323 void NativeThemeAndroid::PaintButton(SkCanvas* canvas, |
| 324 State state, | 324 State state, |
| 325 const gfx::Rect& rect, | 325 const gfx::Rect& rect, |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 half.set_y(rect.y() + rect.height() / 2); | 592 half.set_y(rect.y() + rect.height() / 2); |
| 593 PaintArrowButton(canvas, half, kScrollbarDownArrow, south_state); | 593 PaintArrowButton(canvas, half, kScrollbarDownArrow, south_state); |
| 594 } | 594 } |
| 595 | 595 |
| 596 void NativeThemeAndroid::PaintProgressBar( | 596 void NativeThemeAndroid::PaintProgressBar( |
| 597 SkCanvas* canvas, | 597 SkCanvas* canvas, |
| 598 State state, | 598 State state, |
| 599 const gfx::Rect& rect, | 599 const gfx::Rect& rect, |
| 600 const ProgressBarExtraParams& progress_bar) const { | 600 const ProgressBarExtraParams& progress_bar) const { |
| 601 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 601 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 602 SkBitmap* bar_image = rb.GetBitmapNamed(IDR_PROGRESS_BAR); | 602 gfx::ImageSkia* bar_image = rb.GetImageSkiaNamed(IDR_PROGRESS_BAR); |
| 603 SkBitmap* left_border_image = rb.GetBitmapNamed(IDR_PROGRESS_BORDER_LEFT); | 603 gfx::ImageSkia* left_border_image = rb.GetImageSkiaNamed( |
| 604 SkBitmap* right_border_image = rb.GetBitmapNamed(IDR_PROGRESS_BORDER_RIGHT); | 604 IDR_PROGRESS_BORDER_LEFT); |
| 605 gfx::ImageSkia* right_border_image = rb.GetImageSkiaNamed( |
| 606 IDR_PROGRESS_BORDER_RIGHT); |
| 605 | 607 |
| 606 float tile_scale = static_cast<float>(rect.height()) / | 608 float tile_scale = static_cast<float>(rect.height()) / |
| 607 bar_image->height(); | 609 bar_image->height(); |
| 608 | 610 |
| 609 int new_tile_width = static_cast<int>(bar_image->width() * tile_scale); | 611 int new_tile_width = static_cast<int>(bar_image->width() * tile_scale); |
| 610 float tile_scale_x = static_cast<float>(new_tile_width) / | 612 float tile_scale_x = static_cast<float>(new_tile_width) / |
| 611 bar_image->width(); | 613 bar_image->width(); |
| 612 | 614 |
| 613 DrawTiledImage(canvas, *bar_image, 0, 0, tile_scale_x, tile_scale, | 615 DrawTiledImage(canvas, *bar_image, 0, 0, tile_scale_x, tile_scale, |
| 614 rect.x(), rect.y(), rect.width(), rect.height()); | 616 rect.x(), rect.y(), rect.width(), rect.height()); |
| 615 | 617 |
| 616 if (progress_bar.value_rect_width) { | 618 if (progress_bar.value_rect_width) { |
| 617 SkBitmap* value_image = rb.GetBitmapNamed(IDR_PROGRESS_VALUE); | 619 gfx::ImageSkia* value_image = rb.GetImageSkiaNamed(IDR_PROGRESS_VALUE); |
| 618 | 620 |
| 619 new_tile_width = static_cast<int>(value_image->width() * tile_scale); | 621 new_tile_width = static_cast<int>(value_image->width() * tile_scale); |
| 620 tile_scale_x = static_cast<float>(new_tile_width) / | 622 tile_scale_x = static_cast<float>(new_tile_width) / |
| 621 value_image->width(); | 623 value_image->width(); |
| 622 | 624 |
| 623 DrawTiledImage(canvas, *value_image, 0, 0, tile_scale_x, tile_scale, | 625 DrawTiledImage(canvas, *value_image, 0, 0, tile_scale_x, tile_scale, |
| 624 progress_bar.value_rect_x, | 626 progress_bar.value_rect_x, |
| 625 progress_bar.value_rect_y, | 627 progress_bar.value_rect_y, |
| 626 progress_bar.value_rect_width, | 628 progress_bar.value_rect_width, |
| 627 progress_bar.value_rect_height); | 629 progress_bar.value_rect_height); |
| 628 } | 630 } |
| 629 | 631 |
| 630 int dest_left_border_width = static_cast<int>(left_border_image->width() * | 632 int dest_left_border_width = static_cast<int>(left_border_image->width() * |
| 631 tile_scale); | 633 tile_scale); |
| 632 SkRect dest_rect; | 634 DrawBitmapInt(canvas, *left_border_image, 0, 0, left_border_image->width(), |
| 633 dest_rect.iset(rect.x(), rect.y(), rect.x() + dest_left_border_width, | 635 left_border_image->height(), rect.x(), rect.y(), dest_left_border_width, |
| 634 rect.bottom()); | 636 rect.height()); |
| 635 canvas->drawBitmapRect(*left_border_image, NULL, dest_rect); | |
| 636 | 637 |
| 637 int dest_right_border_width = static_cast<int>(right_border_image->width() * | 638 int dest_right_border_width = static_cast<int>(right_border_image->width() * |
| 638 tile_scale); | 639 tile_scale); |
| 639 dest_rect.iset(rect.right() - dest_right_border_width, rect.y(), rect.right(), | 640 int dest_x = rect.right() - dest_right_border_width; |
| 640 rect.bottom()); | 641 DrawBitmapInt(canvas, *right_border_image, 0, 0, right_border_image->width(), |
| 641 canvas->drawBitmapRect(*right_border_image, NULL, dest_rect); | 642 right_border_image->height(), dest_x, rect.y(), dest_right_border_width, |
| 643 rect.height()); |
| 642 } | 644 } |
| 643 | 645 |
| 644 bool NativeThemeAndroid::IntersectsClipRectInt(SkCanvas* canvas, | 646 bool NativeThemeAndroid::IntersectsClipRectInt(SkCanvas* canvas, |
| 645 int x, | 647 int x, |
| 646 int y, | 648 int y, |
| 647 int w, | 649 int w, |
| 648 int h) const { | 650 int h) const { |
| 649 SkRect clip; | 651 SkRect clip; |
| 650 return canvas->getClipBounds(&clip) && | 652 return canvas->getClipBounds(&clip) && |
| 651 clip.intersect(SkIntToScalar(x), SkIntToScalar(y), SkIntToScalar(x + w), | 653 clip.intersect(SkIntToScalar(x), SkIntToScalar(y), SkIntToScalar(x + w), |
| 652 SkIntToScalar(y + h)); | 654 SkIntToScalar(y + h)); |
| 653 } | 655 } |
| 654 | 656 |
| 655 void NativeThemeAndroid::DrawBitmapInt(SkCanvas* canvas, | 657 void NativeThemeAndroid::DrawBitmapInt(SkCanvas* canvas, |
| 656 const SkBitmap& bitmap, | 658 const gfx::ImageSkia& image, |
| 657 int src_x, | 659 int src_x, |
| 658 int src_y, | 660 int src_y, |
| 659 int src_w, | 661 int src_w, |
| 660 int src_h, | 662 int src_h, |
| 661 int dest_x, | 663 int dest_x, |
| 662 int dest_y, | 664 int dest_y, |
| 663 int dest_w, | 665 int dest_w, |
| 664 int dest_h) const { | 666 int dest_h) const { |
| 665 gfx::Canvas(canvas).DrawBitmapInt(bitmap, src_x, src_y, src_w, src_h, | 667 gfx::Canvas(canvas).DrawBitmapInt(image, src_x, src_y, src_w, src_h, |
| 666 dest_x, dest_y, dest_w, dest_h, true); | 668 dest_x, dest_y, dest_w, dest_h, true); |
| 667 } | 669 } |
| 668 | 670 |
| 669 void NativeThemeAndroid::DrawTiledImage(SkCanvas* canvas, | 671 void NativeThemeAndroid::DrawTiledImage(SkCanvas* canvas, |
| 670 const SkBitmap& bitmap, | 672 const gfx::ImageSkia& image, |
| 671 int src_x, | 673 int src_x, |
| 672 int src_y, | 674 int src_y, |
| 673 float tile_scale_x, | 675 float tile_scale_x, |
| 674 float tile_scale_y, | 676 float tile_scale_y, |
| 675 int dest_x, | 677 int dest_x, |
| 676 int dest_y, | 678 int dest_y, |
| 677 int w, | 679 int w, |
| 678 int h) const { | 680 int h) const { |
| 679 gfx::Canvas(canvas).TileImageInt(bitmap, src_x, src_y, tile_scale_x, | 681 gfx::Canvas(canvas).TileImageInt(image, src_x, src_y, tile_scale_x, |
| 680 tile_scale_y, dest_x, dest_y, w, h); | 682 tile_scale_y, dest_x, dest_y, w, h); |
| 681 } | 683 } |
| 682 | 684 |
| 683 SkColor NativeThemeAndroid::SaturateAndBrighten( | 685 SkColor NativeThemeAndroid::SaturateAndBrighten( |
| 684 SkScalar* hsv, | 686 SkScalar* hsv, |
| 685 SkScalar saturate_amount, | 687 SkScalar saturate_amount, |
| 686 SkScalar brighten_amount) const { | 688 SkScalar brighten_amount) const { |
| 687 SkScalar color[3]; | 689 SkScalar color[3]; |
| 688 color[0] = hsv[0]; | 690 color[0] = hsv[0]; |
| 689 color[1] = Clamp(hsv[1] + saturate_amount, 0.0, 1.0); | 691 color[1] = Clamp(hsv[1] + saturate_amount, 0.0, 1.0); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 SkScalar min_diff = Clamp((hsv1[1] + hsv2[1]) * 1.2, 0.28, 0.5); | 734 SkScalar min_diff = Clamp((hsv1[1] + hsv2[1]) * 1.2, 0.28, 0.5); |
| 733 SkScalar diff = Clamp(fabs(hsv1[2] - hsv2[2]) / 2, min_diff, 0.5); | 735 SkScalar diff = Clamp(fabs(hsv1[2] - hsv2[2]) / 2, min_diff, 0.5); |
| 734 | 736 |
| 735 if (hsv1[2] + hsv2[2] > 1.0) | 737 if (hsv1[2] + hsv2[2] > 1.0) |
| 736 diff = -diff; | 738 diff = -diff; |
| 737 | 739 |
| 738 return SaturateAndBrighten(hsv2, -0.2, diff); | 740 return SaturateAndBrighten(hsv2, -0.2, diff); |
| 739 } | 741 } |
| 740 | 742 |
| 741 } // namespace ui | 743 } // namespace ui |
| OLD | NEW |