Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(235)

Side by Side Diff: ui/views/controls/button/text_button.cc

Issue 10933049: Fixed position of plus image on action box button; added ICON_CENTERED placement to TextButton (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/views/controls/button/text_button.h ('k') | ui/views/examples/button_example.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/views/controls/button/text_button.h" 5 #include "ui/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 "grit/ui_resources.h" 10 #include "grit/ui_resources.h"
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 723
724 void TextButton::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { 724 void TextButton::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) {
725 TextButtonBase::PaintButton(canvas, mode); 725 TextButtonBase::PaintButton(canvas, mode);
726 726
727 const gfx::ImageSkia& icon = GetImageToPaint(); 727 const gfx::ImageSkia& icon = GetImageToPaint();
728 728
729 if (icon.width() > 0) { 729 if (icon.width() > 0) {
730 gfx::Rect text_bounds = GetTextBounds(); 730 gfx::Rect text_bounds = GetTextBounds();
731 int icon_x; 731 int icon_x;
732 int spacing = text_.empty() ? 0 : icon_text_spacing_; 732 int spacing = text_.empty() ? 0 : icon_text_spacing_;
733 gfx::Insets insets = GetInsets();
733 if (icon_placement_ == ICON_ON_LEFT) { 734 if (icon_placement_ == ICON_ON_LEFT) {
734 icon_x = text_bounds.x() - icon.width() - spacing; 735 icon_x = text_bounds.x() - icon.width() - spacing;
735 } else { 736 } else if (icon_placement_ == ICON_ON_RIGHT) {
736 icon_x = text_bounds.right() + spacing; 737 icon_x = text_bounds.right() + spacing;
738 } else { // ICON_CENTERED
739 DCHECK(text_.empty());
740 icon_x = (width() - insets.width() - icon.width()) / 2 + insets.left();
737 } 741 }
738 742
739 gfx::Insets insets = GetInsets();
740 int available_height = height() - insets.height(); 743 int available_height = height() - insets.height();
741 int icon_y = (available_height - icon.height()) / 2 + insets.top(); 744 int icon_y = (available_height - icon.height()) / 2 + insets.top();
742 745
743 // Mirroring the icon position if necessary. 746 // Mirroring the icon position if necessary.
744 gfx::Rect icon_bounds(icon_x, icon_y, icon.width(), icon.height()); 747 gfx::Rect icon_bounds(icon_x, icon_y, icon.width(), icon.height());
745 icon_bounds.set_x(GetMirroredXForRect(icon_bounds)); 748 icon_bounds.set_x(GetMirroredXForRect(icon_bounds));
746 canvas->DrawImageInt(icon, icon_bounds.x(), icon_bounds.y()); 749 canvas->DrawImageInt(icon, icon_bounds.x(), icon_bounds.y());
747 } 750 }
748 } 751 }
749 752
(...skipping 28 matching lines...) Expand all
778 const gfx::ImageSkia& icon = GetImageToPaint(); 781 const gfx::ImageSkia& icon = GetImageToPaint();
779 if (icon.width() > 0) 782 if (icon.width() > 0)
780 extra_width = icon.width() + (text_.empty() ? 0 : icon_text_spacing_); 783 extra_width = icon.width() + (text_.empty() ? 0 : icon_text_spacing_);
781 784
782 gfx::Rect bounds(GetContentBounds(extra_width)); 785 gfx::Rect bounds(GetContentBounds(extra_width));
783 786
784 if (extra_width > 0) { 787 if (extra_width > 0) {
785 // Make sure the icon is always fully visible. 788 // Make sure the icon is always fully visible.
786 if (icon_placement_ == ICON_ON_LEFT) { 789 if (icon_placement_ == ICON_ON_LEFT) {
787 bounds.Inset(extra_width, 0, 0, 0); 790 bounds.Inset(extra_width, 0, 0, 0);
788 } else { 791 } else if (icon_placement_ == ICON_ON_RIGHT) {
789 bounds.Inset(0, 0, extra_width, 0); 792 bounds.Inset(0, 0, extra_width, 0);
790 } 793 }
791 } 794 }
792 795
793 return bounds; 796 return bounds;
794 } 797 }
795 798
796 const gfx::ImageSkia& TextButton::GetImageToPaint() const { 799 const gfx::ImageSkia& TextButton::GetImageToPaint() const {
797 if (show_multiple_icon_states_) { 800 if (show_multiple_icon_states_) {
798 if (has_hover_icon_ && (state() == BS_HOT)) 801 if (has_hover_icon_ && (state() == BS_HOT))
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 // Windows may paint a dotted focus rect in 866 // Windows may paint a dotted focus rect in
864 // NativeTextButton::OnPaintFocusBorder. To avoid getting two focus 867 // NativeTextButton::OnPaintFocusBorder. To avoid getting two focus
865 // indications (A dotted rect and a highlighted border) only set is_focused on 868 // indications (A dotted rect and a highlighted border) only set is_focused on
866 // non windows platforms. 869 // non windows platforms.
867 params->button.is_focused = HasFocus() && 870 params->button.is_focused = HasFocus() &&
868 (focusable() || IsAccessibilityFocusable()); 871 (focusable() || IsAccessibilityFocusable());
869 #endif 872 #endif
870 } 873 }
871 874
872 } // namespace views 875 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/button/text_button.h ('k') | ui/views/examples/button_example.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698