diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-27 21:29:06 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-27 21:29:06 +0000 |
commit | 65ecd5bdf29b107913436eafb2a7c32684ccedbc (patch) | |
tree | beaf7a3e603fca4e5030d6cd62e3903de6b52a88 /views | |
parent | d070ec638d42d355dbf11fd8c1d65d80452b37b3 (diff) | |
download | chromium_src-65ecd5bdf29b107913436eafb2a7c32684ccedbc.zip chromium_src-65ecd5bdf29b107913436eafb2a7c32684ccedbc.tar.gz chromium_src-65ecd5bdf29b107913436eafb2a7c32684ccedbc.tar.bz2 |
Add "pushed" as a state a TextButton can show (alongside "normal" and "hover").
BUG=50107
TEST=none
Review URL: http://codereview.chromium.org/3058011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53847 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/controls/button/text_button.cc | 36 | ||||
-rw-r--r-- | views/controls/button/text_button.h | 20 |
2 files changed, 34 insertions, 22 deletions
diff --git a/views/controls/button/text_button.cc b/views/controls/button/text_button.cc index 16dae01..5c1ec29 100644 --- a/views/controls/button/text_button.cc +++ b/views/controls/button/text_button.cc @@ -188,9 +188,10 @@ TextButton::TextButton(ButtonListener* listener, const std::wstring& text) color_highlight_(kHighlightColor), color_hover_(kHoverColor), has_hover_icon_(false), + has_pushed_icon_(false), max_width_(0), normal_has_border_(false), - show_highlighted_(true), + show_multiple_icon_states_(true), prefix_type_(PREFIX_NONE) { SetText(text); set_border(new TextButtonBorder); @@ -214,6 +215,11 @@ void TextButton::SetHoverIcon(const SkBitmap& icon) { has_hover_icon_ = true; } +void TextButton::SetPushedIcon(const SkBitmap& icon) { + icon_pushed_ = icon; + has_pushed_icon_ = true; +} + void TextButton::SetFont(const gfx::Font& font) { font_ = font; UpdateTextSize(); @@ -245,15 +251,15 @@ void TextButton::SetNormalHasBorder(bool normal_has_border) { normal_has_border_ = normal_has_border; } -void TextButton::SetShowHighlighted(bool show_highlighted) { - show_highlighted_ = show_highlighted; +void TextButton::SetShowMultipleIconStates(bool show_multiple_icon_states) { + show_multiple_icon_states_ = show_multiple_icon_states; } void TextButton::Paint(gfx::Canvas* canvas, bool for_drag) { if (!for_drag) { PaintBackground(canvas); - if (show_highlighted_ && hover_animation_->is_animating()) { + if (show_multiple_icon_states_ && hover_animation_->is_animating()) { // Draw the hover bitmap into an offscreen buffer, then blend it // back into the current canvas. canvas->SaveLayerAlpha( @@ -262,7 +268,7 @@ void TextButton::Paint(gfx::Canvas* canvas, bool for_drag) { SkXfermode::kClear_Mode); PaintBorder(canvas); canvas->Restore(); - } else if ((show_highlighted_ && + } else if ((show_multiple_icon_states_ && (state_ == BS_HOT || state_ == BS_PUSHED)) || (state_ == BS_NORMAL && normal_has_border_)) { PaintBorder(canvas); @@ -271,12 +277,13 @@ void TextButton::Paint(gfx::Canvas* canvas, bool for_drag) { PaintFocusBorder(canvas); } - SkBitmap icon; - if (has_hover_icon_ && show_highlighted_ && - (state() == BS_HOT || state() == BS_PUSHED)) - icon = icon_hover_; - else - icon = icon_; + SkBitmap icon = icon_; + if (show_multiple_icon_states_) { + if (has_hover_icon_ && (state() == BS_HOT)) + icon = icon_hover_; + else if (has_pushed_icon_ && (state() == BS_PUSHED)) + icon = icon_pushed_; + } gfx::Insets insets = GetInsets(); int available_width = width() - insets.width(); @@ -324,11 +331,8 @@ void TextButton::Paint(gfx::Canvas* canvas, bool for_drag) { gfx::Rect text_bounds(text_x, text_y, text_width, text_size_.height()); text_bounds.set_x(MirroredLeftPointForRect(text_bounds)); - SkColor text_color; - if (show_highlighted_ && (state() == BS_HOT || state() == BS_PUSHED)) - text_color = color_hover_; - else - text_color = color_; + SkColor text_color = (show_multiple_icon_states_ && + (state() == BS_HOT || state() == BS_PUSHED)) ? color_hover_ : color_; int draw_string_flags = gfx::CanvasSkia::DefaultCanvasTextAlignment() | PrefixTypeToCanvasType(prefix_type_); diff --git a/views/controls/button/text_button.h b/views/controls/button/text_button.h index 8fc028b..310bbda 100644 --- a/views/controls/button/text_button.h +++ b/views/controls/button/text_button.h @@ -106,9 +106,10 @@ class TextButton : public CustomButton { // Sets the icon. void SetIcon(const SkBitmap& icon); - SkBitmap icon() const { return icon_; } void SetHoverIcon(const SkBitmap& icon); - SkBitmap icon_hover() const { return icon_hover_; } + void SetPushedIcon(const SkBitmap& icon); + + bool HasIcon() const { return !icon_.empty(); } // Meanings are reversed for right-to-left layouts. enum IconPlacement { @@ -133,8 +134,9 @@ class TextButton : public CustomButton { void SetHighlightColor(SkColor color); void SetHoverColor(SkColor color); void SetNormalHasBorder(bool normal_has_border); - // Sets whether or not to show the highlighed (i.e. hot) state. Default true. - void SetShowHighlighted(bool show_highlighted); + // Sets whether or not to show the hot and pushed states for the button icon + // (if present) in addition to the normal state. Defaults to true. + void SetShowMultipleIconStates(bool show_multiple_icon_states); // Paint the button into the specified canvas. If |for_drag| is true, the // function paints a drag image representation into the canvas. @@ -152,6 +154,8 @@ class TextButton : public CustomButton { static const SkColor kHoverColor; protected: + SkBitmap icon() const { return icon_; } + virtual void Paint(gfx::Canvas* canvas); // Called when enabled or disabled state changes, or the colors for those @@ -198,6 +202,10 @@ class TextButton : public CustomButton { SkBitmap icon_hover_; bool has_hover_icon_; + // An optional different version of the icon for pushed state. + SkBitmap icon_pushed_; + bool has_pushed_icon_; + // The width of the button will never be larger than this value. A value <= 0 // indicates the width is not constrained. int max_width_; @@ -205,8 +213,8 @@ class TextButton : public CustomButton { // This is true if normal state has a border frame; default is false. bool normal_has_border_; - // Whether or not to show the highlighted (i.e. hot) state. - bool show_highlighted_; + // Whether or not to show the hot and pushed icon states. + bool show_multiple_icon_states_; PrefixType prefix_type_; |