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 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
746 if (icon_placement_ == ICON_ON_LEFT) { | 740 if (icon_placement_ == ICON_ON_LEFT) { |
747 bounds.Inset(extra_width, 0, 0, 0); | 741 bounds.Inset(extra_width, 0, 0, 0); |
748 } else { | 742 } else { |
749 bounds.Inset(0, 0, extra_width, 0); | 743 bounds.Inset(0, 0, extra_width, 0); |
750 } | 744 } |
751 } | 745 } |
752 | 746 |
753 return bounds; | 747 return bounds; |
754 } | 748 } |
755 | 749 |
750 SkBitmap TextButton::GetImageToPaint() const { | |
751 if (show_multiple_icon_states_) { | |
752 if (has_hover_icon_ && (state() == BS_HOT)) | |
753 return icon_hover_; | |
754 else if (has_pushed_icon_ && (state() == BS_PUSHED)) | |
Peter Kasting
2011/06/09 18:03:31
Nit: No else after return
sail
2011/06/10 00:56:20
Done.
| |
755 return icon_pushed_; | |
756 } | |
757 return icon_; | |
758 } | |
759 | |
756 } // namespace views | 760 } // namespace views |
OLD | NEW |