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 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 | 672 |
673 if (max_width_ > 0) | 673 if (max_width_ > 0) |
674 prefsize.set_width(std::min(max_width_, prefsize.width())); | 674 prefsize.set_width(std::min(max_width_, prefsize.width())); |
675 | 675 |
676 return prefsize; | 676 return prefsize; |
677 } | 677 } |
678 | 678 |
679 void TextButton::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { | 679 void TextButton::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { |
680 TextButtonBase::PaintButton(canvas, mode); | 680 TextButtonBase::PaintButton(canvas, mode); |
681 | 681 |
682 SkBitmap icon = icon_; | 682 const SkBitmap& icon = GetImageToPaint(); |
683 if (show_multiple_icon_states_) { | |
684 if (has_hover_icon_ && (state() == BS_HOT)) | |
685 icon = icon_hover_; | |
686 else if (has_pushed_icon_ && (state() == BS_PUSHED)) | |
687 icon = icon_pushed_; | |
688 } | |
689 | 683 |
690 if (icon.width() > 0) { | 684 if (icon.width() > 0) { |
691 gfx::Rect text_bounds = GetTextBounds(); | 685 gfx::Rect text_bounds = GetTextBounds(); |
692 int icon_x; | 686 int icon_x; |
693 int spacing = text_.empty() ? 0 : icon_text_spacing_; | 687 int spacing = text_.empty() ? 0 : icon_text_spacing_; |
694 if (icon_placement_ == ICON_ON_LEFT) { | 688 if (icon_placement_ == ICON_ON_LEFT) { |
695 icon_x = text_bounds.x() - icon.width() - spacing; | 689 icon_x = text_bounds.x() - icon.width() - spacing; |
696 } else { | 690 } else { |
697 icon_x = text_bounds.right() + spacing; | 691 icon_x = text_bounds.right() + spacing; |
698 } | 692 } |
(...skipping 22 matching lines...) Expand all Loading... |
721 params->button.indeterminate = false; | 715 params->button.indeterminate = false; |
722 params->button.is_default = is_default_; | 716 params->button.is_default = is_default_; |
723 params->button.has_border = false; | 717 params->button.has_border = false; |
724 params->button.classic_state = 0; | 718 params->button.classic_state = 0; |
725 params->button.background_color = kEnabledColor; | 719 params->button.background_color = kEnabledColor; |
726 } | 720 } |
727 | 721 |
728 gfx::Rect TextButton::GetTextBounds() const { | 722 gfx::Rect TextButton::GetTextBounds() const { |
729 int extra_width = 0; | 723 int extra_width = 0; |
730 | 724 |
731 SkBitmap icon = icon_; | 725 const SkBitmap& icon = GetImageToPaint(); |
732 if (show_multiple_icon_states_) { | |
733 if (has_hover_icon_ && (state() == BS_HOT)) | |
734 icon = icon_hover_; | |
735 else if (has_pushed_icon_ && (state() == BS_PUSHED)) | |
736 icon = icon_pushed_; | |
737 } | |
738 | |
739 if (icon.width() > 0) | 726 if (icon.width() > 0) |
740 extra_width = icon.width() + (text_.empty() ? 0 : icon_text_spacing_); | 727 extra_width = icon.width() + (text_.empty() ? 0 : icon_text_spacing_); |
741 | 728 |
742 gfx::Rect bounds(GetContentBounds(extra_width)); | 729 gfx::Rect bounds(GetContentBounds(extra_width)); |
743 | 730 |
744 if (extra_width > 0) { | 731 if (extra_width > 0) { |
745 // Make sure the icon is always fully visible. | 732 // Make sure the icon is always fully visible. |
746 if (icon_placement_ == ICON_ON_LEFT) { | 733 if (icon_placement_ == ICON_ON_LEFT) { |
747 bounds.Inset(extra_width, 0, 0, 0); | 734 bounds.Inset(extra_width, 0, 0, 0); |
748 } else { | 735 } else { |
749 bounds.Inset(0, 0, extra_width, 0); | 736 bounds.Inset(0, 0, extra_width, 0); |
750 } | 737 } |
751 } | 738 } |
752 | 739 |
753 return bounds; | 740 return bounds; |
754 } | 741 } |
755 | 742 |
| 743 const SkBitmap& TextButton::GetImageToPaint() const { |
| 744 if (show_multiple_icon_states_) { |
| 745 if (has_hover_icon_ && (state() == BS_HOT)) |
| 746 return icon_hover_; |
| 747 if (has_pushed_icon_ && (state() == BS_PUSHED)) |
| 748 return icon_pushed_; |
| 749 } |
| 750 return icon_; |
| 751 } |
| 752 |
756 } // namespace views | 753 } // namespace views |
OLD | NEW |