Index: ui/views/controls/button/text_button.cc |
diff --git a/ui/views/controls/button/text_button.cc b/ui/views/controls/button/text_button.cc |
index 99ac86b51dccfe1155ce09e8e82836a87b3081e9..be1d2492b5d5002ee89091350c51e46c1c3bab78 100644 |
--- a/ui/views/controls/button/text_button.cc |
+++ b/ui/views/controls/button/text_button.cc |
@@ -358,6 +358,39 @@ void TextButtonBase::CalculateTextSize(gfx::Size* text_size, int max_width) { |
text_size->SetSize(w, h); |
} |
+void TextButtonBase::OnPaintText(gfx::Canvas* canvas, PaintButtonMode mode) { |
+ gfx::Rect text_bounds(GetTextBounds()); |
+ if (text_bounds.width() > 0) { |
+ // Because the text button can (at times) draw multiple elements on the |
+ // canvas, we can not mirror the button by simply flipping the canvas as |
+ // doing this will mirror the text itself. Flipping the canvas will also |
+ // make the icons look wrong because icons are almost always represented as |
+ // direction-insensitive images and such images should never be flipped |
+ // horizontally. |
+ // |
+ // Due to the above, we must perform the flipping manually for RTL UIs. |
+ text_bounds.set_x(GetMirroredXForRect(text_bounds)); |
+ |
+ SkColor text_color = (show_multiple_icon_states_ && |
+ (state() == STATE_HOVERED || state() == STATE_PRESSED)) ? |
+ color_hover_ : color_; |
+ |
+ int draw_string_flags = gfx::Canvas::DefaultCanvasTextAlignment() | |
+ ComputeCanvasStringFlags(); |
+ |
+ if (mode == PB_FOR_DRAG) { |
+ // Disable sub-pixel rendering as background is transparent. |
+ draw_string_flags |= gfx::Canvas::NO_SUBPIXEL_RENDERING; |
+ canvas->DrawStringRectWithHalo(text_, font_list_, |
+ SK_ColorBLACK, SK_ColorWHITE, |
+ text_bounds, draw_string_flags); |
+ } else { |
+ canvas->DrawStringRectWithFlags(text_, font_list_, text_color, |
+ text_bounds, draw_string_flags); |
+ } |
+ } |
+} |
+ |
int TextButtonBase::ComputeCanvasStringFlags() const { |
if (!multi_line_) |
return 0; |
@@ -445,36 +478,7 @@ void TextButtonBase::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { |
Painter::PaintFocusPainter(this, canvas, focus_painter_.get()); |
} |
- gfx::Rect text_bounds(GetTextBounds()); |
- if (text_bounds.width() > 0) { |
- // Because the text button can (at times) draw multiple elements on the |
- // canvas, we can not mirror the button by simply flipping the canvas as |
- // doing this will mirror the text itself. Flipping the canvas will also |
- // make the icons look wrong because icons are almost always represented as |
- // direction-insensitive images and such images should never be flipped |
- // horizontally. |
- // |
- // Due to the above, we must perform the flipping manually for RTL UIs. |
- text_bounds.set_x(GetMirroredXForRect(text_bounds)); |
- |
- SkColor text_color = (show_multiple_icon_states_ && |
- (state() == STATE_HOVERED || state() == STATE_PRESSED)) ? |
- color_hover_ : color_; |
- |
- int draw_string_flags = gfx::Canvas::DefaultCanvasTextAlignment() | |
- ComputeCanvasStringFlags(); |
- |
- if (mode == PB_FOR_DRAG) { |
- // Disable sub-pixel rendering as background is transparent. |
- draw_string_flags |= gfx::Canvas::NO_SUBPIXEL_RENDERING; |
- canvas->DrawStringRectWithHalo(text_, font_list_, |
- SK_ColorBLACK, SK_ColorWHITE, |
- text_bounds, draw_string_flags); |
- } else { |
- canvas->DrawStringRectWithFlags(text_, font_list_, text_color, |
- text_bounds, draw_string_flags); |
- } |
- } |
+ OnPaintText(canvas, mode); |
} |
gfx::Size TextButtonBase::GetMinimumSize() { |
@@ -630,7 +634,10 @@ void TextButton::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { |
set_alignment(ALIGN_RIGHT); |
TextButtonBase::PaintButton(canvas, mode); |
+ OnPaintIcon(canvas, mode); |
+} |
+void TextButton::OnPaintIcon(gfx::Canvas* canvas, PaintButtonMode mode) { |
const gfx::ImageSkia& icon = GetImageToPaint(); |
if (icon.width() > 0) { |