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

Unified Diff: ui/views/controls/button/text_button.cc

Issue 284033002: Allow TextButton derivatives to override drawing of certain parts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/controls/button/text_button.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
« no previous file with comments | « ui/views/controls/button/text_button.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698