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

Side by Side 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: rebased 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 unified diff | Download patch | Annotate | Revision Log
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 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 focus_painter_ = focus_painter.Pass(); 438 focus_painter_ = focus_painter.Pass();
439 } 439 }
440 440
441 void TextButtonBase::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { 441 void TextButtonBase::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) {
442 if (mode == PB_NORMAL) { 442 if (mode == PB_NORMAL) {
443 OnPaintBackground(canvas); 443 OnPaintBackground(canvas);
444 OnPaintBorder(canvas); 444 OnPaintBorder(canvas);
445 Painter::PaintFocusPainter(this, canvas, focus_painter_.get()); 445 Painter::PaintFocusPainter(this, canvas, focus_painter_.get());
446 } 446 }
447 447
448 OnPaintText(canvas, mode);
449 }
450
451 void TextButtonBase::OnPaintText(gfx::Canvas* canvas, PaintButtonMode mode) {
448 gfx::Rect text_bounds(GetTextBounds()); 452 gfx::Rect text_bounds(GetTextBounds());
449 if (text_bounds.width() > 0) { 453 if (text_bounds.width() > 0) {
450 // Because the text button can (at times) draw multiple elements on the 454 // Because the text button can (at times) draw multiple elements on the
451 // canvas, we can not mirror the button by simply flipping the canvas as 455 // canvas, we can not mirror the button by simply flipping the canvas as
452 // doing this will mirror the text itself. Flipping the canvas will also 456 // doing this will mirror the text itself. Flipping the canvas will also
453 // make the icons look wrong because icons are almost always represented as 457 // make the icons look wrong because icons are almost always represented as
454 // direction-insensitive images and such images should never be flipped 458 // direction-insensitive images and such images should never be flipped
455 // horizontally. 459 // horizontally.
456 // 460 //
457 // Due to the above, we must perform the flipping manually for RTL UIs. 461 // Due to the above, we must perform the flipping manually for RTL UIs.
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 prefsize.set_height(std::max(prefsize.height(), min_height_)); 627 prefsize.set_height(std::max(prefsize.height(), min_height_));
624 628
625 return prefsize; 629 return prefsize;
626 } 630 }
627 631
628 void TextButton::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { 632 void TextButton::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) {
629 if (full_justification_ && icon_placement_ == ICON_ON_LEFT) 633 if (full_justification_ && icon_placement_ == ICON_ON_LEFT)
630 set_alignment(ALIGN_RIGHT); 634 set_alignment(ALIGN_RIGHT);
631 635
632 TextButtonBase::PaintButton(canvas, mode); 636 TextButtonBase::PaintButton(canvas, mode);
637 OnPaintIcon(canvas, mode);
638 }
633 639
640 void TextButton::OnPaintIcon(gfx::Canvas* canvas, PaintButtonMode mode) {
634 const gfx::ImageSkia& icon = GetImageToPaint(); 641 const gfx::ImageSkia& icon = GetImageToPaint();
635 642
636 if (icon.width() > 0) { 643 if (icon.width() > 0) {
637 gfx::Rect text_bounds = GetTextBounds(); 644 gfx::Rect text_bounds = GetTextBounds();
638 int icon_x = 0; 645 int icon_x = 0;
639 int spacing = text_.empty() ? 0 : icon_text_spacing_; 646 int spacing = text_.empty() ? 0 : icon_text_spacing_;
640 gfx::Insets insets = GetInsets(); 647 gfx::Insets insets = GetInsets();
641 switch (icon_placement_) { 648 switch (icon_placement_) {
642 case ICON_ON_LEFT: 649 case ICON_ON_LEFT:
643 icon_x = full_justification_ ? insets.left() 650 icon_x = full_justification_ ? insets.left()
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 if (show_multiple_icon_states_) { 719 if (show_multiple_icon_states_) {
713 if (has_hover_icon_ && (state() == STATE_HOVERED)) 720 if (has_hover_icon_ && (state() == STATE_HOVERED))
714 return icon_hover_; 721 return icon_hover_;
715 if (has_pushed_icon_ && (state() == STATE_PRESSED)) 722 if (has_pushed_icon_ && (state() == STATE_PRESSED))
716 return icon_pushed_; 723 return icon_pushed_;
717 } 724 }
718 return icon_; 725 return icon_;
719 } 726 }
720 727
721 } // namespace views 728 } // namespace views
OLDNEW
« ui/views/controls/button/text_button.h ('K') | « 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