OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "views/controls/button/text_button.h" | 5 #include "views/controls/button/text_button.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 | 646 |
647 if (max_width_ > 0) | 647 if (max_width_ > 0) |
648 prefsize.set_width(std::min(max_width_, prefsize.width())); | 648 prefsize.set_width(std::min(max_width_, prefsize.width())); |
649 | 649 |
650 return prefsize; | 650 return prefsize; |
651 } | 651 } |
652 | 652 |
653 void TextButton::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { | 653 void TextButton::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { |
654 TextButtonBase::PaintButton(canvas, mode); | 654 TextButtonBase::PaintButton(canvas, mode); |
655 | 655 |
656 SkBitmap icon = icon_; | 656 const SkBitmap& icon = GetImageToPaint(); |
657 if (show_multiple_icon_states_) { | |
658 if (has_hover_icon_ && (state() == BS_HOT)) | |
659 icon = icon_hover_; | |
660 else if (has_pushed_icon_ && (state() == BS_PUSHED)) | |
661 icon = icon_pushed_; | |
662 } | |
663 | 657 |
664 if (icon.width() > 0) { | 658 if (icon.width() > 0) { |
665 gfx::Rect text_bounds = GetTextBounds(); | 659 gfx::Rect text_bounds = GetTextBounds(); |
666 int icon_x; | 660 int icon_x; |
667 int spacing = text_.empty() ? 0 : icon_text_spacing_; | 661 int spacing = text_.empty() ? 0 : icon_text_spacing_; |
668 if (icon_placement_ == ICON_ON_LEFT) { | 662 if (icon_placement_ == ICON_ON_LEFT) { |
669 icon_x = text_bounds.x() - icon.width() - spacing; | 663 icon_x = text_bounds.x() - icon.width() - spacing; |
670 } else { | 664 } else { |
671 icon_x = text_bounds.right() + spacing; | 665 icon_x = text_bounds.right() + spacing; |
672 } | 666 } |
(...skipping 22 matching lines...) Expand all Loading... |
695 params->button.indeterminate = false; | 689 params->button.indeterminate = false; |
696 params->button.is_default = is_default_; | 690 params->button.is_default = is_default_; |
697 params->button.has_border = false; | 691 params->button.has_border = false; |
698 params->button.classic_state = 0; | 692 params->button.classic_state = 0; |
699 params->button.background_color = kEnabledColor; | 693 params->button.background_color = kEnabledColor; |
700 } | 694 } |
701 | 695 |
702 gfx::Rect TextButton::GetTextBounds() const { | 696 gfx::Rect TextButton::GetTextBounds() const { |
703 int extra_width = 0; | 697 int extra_width = 0; |
704 | 698 |
705 SkBitmap icon = icon_; | 699 const SkBitmap& icon = GetImageToPaint(); |
706 if (show_multiple_icon_states_) { | |
707 if (has_hover_icon_ && (state() == BS_HOT)) | |
708 icon = icon_hover_; | |
709 else if (has_pushed_icon_ && (state() == BS_PUSHED)) | |
710 icon = icon_pushed_; | |
711 } | |
712 | |
713 if (icon.width() > 0) | 700 if (icon.width() > 0) |
714 extra_width = icon.width() + (text_.empty() ? 0 : icon_text_spacing_); | 701 extra_width = icon.width() + (text_.empty() ? 0 : icon_text_spacing_); |
715 | 702 |
716 gfx::Rect bounds(GetContentBounds(extra_width)); | 703 gfx::Rect bounds(GetContentBounds(extra_width)); |
717 | 704 |
718 if (extra_width > 0) { | 705 if (extra_width > 0) { |
719 // Make sure the icon is always fully visible. | 706 // Make sure the icon is always fully visible. |
720 if (icon_placement_ == ICON_ON_LEFT) { | 707 if (icon_placement_ == ICON_ON_LEFT) { |
721 bounds.Inset(extra_width, 0, 0, 0); | 708 bounds.Inset(extra_width, 0, 0, 0); |
722 } else { | 709 } else { |
723 bounds.Inset(0, 0, extra_width, 0); | 710 bounds.Inset(0, 0, extra_width, 0); |
724 } | 711 } |
725 } | 712 } |
726 | 713 |
727 return bounds; | 714 return bounds; |
728 } | 715 } |
729 | 716 |
| 717 const SkBitmap& TextButton::GetImageToPaint() const { |
| 718 if (show_multiple_icon_states_) { |
| 719 if (has_hover_icon_ && (state() == BS_HOT)) |
| 720 return icon_hover_; |
| 721 if (has_pushed_icon_ && (state() == BS_PUSHED)) |
| 722 return icon_pushed_; |
| 723 } |
| 724 return icon_; |
| 725 } |
| 726 |
730 } // namespace views | 727 } // namespace views |
OLD | NEW |