diff options
author | yusukes@google.com <yusukes@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-20 02:19:04 +0000 |
---|---|---|
committer | yusukes@google.com <yusukes@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-20 02:19:04 +0000 |
commit | ebfc0c88990620fe05fd9f935ef76a2ebcf649c8 (patch) | |
tree | 1a6d8cb676f83a5cbb60e855961ecdd25a912820 /views/controls | |
parent | 1bd056e69770a53c2778c46918e42e2b8eed6de3 (diff) | |
download | chromium_src-ebfc0c88990620fe05fd9f935ef76a2ebcf649c8.zip chromium_src-ebfc0c88990620fe05fd9f935ef76a2ebcf649c8.tar.gz chromium_src-ebfc0c88990620fe05fd9f935ef76a2ebcf649c8.tar.bz2 |
Enable CustomButton users to call SetEnabled(false) even when |show_highlighted_| of the button is set to false.
This change is necessary for http://codereview.chromium.org/1645012 . Note that SetShowHighlited(false) is used only in two classes, chrome/browser/chromeos/status/language_menu_button.cc and chrome/browser/chromeos/status/clock_menu_button.cc. So I believe the impact of this change should be minimal.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/1539040
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45001 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/controls')
-rw-r--r-- | views/controls/button/custom_button.cc | 7 | ||||
-rw-r--r-- | views/controls/button/custom_button.h | 6 | ||||
-rw-r--r-- | views/controls/button/text_button.cc | 25 | ||||
-rw-r--r-- | views/controls/button/text_button.h | 5 |
4 files changed, 23 insertions, 20 deletions
diff --git a/views/controls/button/custom_button.cc b/views/controls/button/custom_button.cc index ce499f1..ffa5a46 100644 --- a/views/controls/button/custom_button.cc +++ b/views/controls/button/custom_button.cc @@ -19,7 +19,7 @@ CustomButton::~CustomButton() { } void CustomButton::SetState(ButtonState state) { - if (show_highlighted_ && state != state_) { + if (state != state_) { if (animate_on_state_change_ || !hover_animation_->IsAnimating()) { animate_on_state_change_ = true; if (state_ == BS_NORMAL && state == BS_HOT) { @@ -48,10 +48,6 @@ void CustomButton::SetAnimationDuration(int duration) { hover_animation_->SetSlideDuration(duration); } -void CustomButton::SetShowHighlighted(bool show_highlighted) { - show_highlighted_ = show_highlighted; -} - //////////////////////////////////////////////////////////////////////////////// // CustomButton, View overrides: @@ -78,7 +74,6 @@ CustomButton::CustomButton(ButtonListener* listener) : Button(listener), state_(BS_NORMAL), animate_on_state_change_(true), - show_highlighted_(true), triggerable_event_flags_(MouseEvent::EF_LEFT_BUTTON_DOWN) { hover_animation_.reset(new ThrobAnimation(this)); hover_animation_->SetSlideDuration(kHoverFadeDurationMs); diff --git a/views/controls/button/custom_button.h b/views/controls/button/custom_button.h index c8977f8..9f2cb9f 100644 --- a/views/controls/button/custom_button.h +++ b/views/controls/button/custom_button.h @@ -41,9 +41,6 @@ class CustomButton : public Button, // Set how long the hover animation will last for. void SetAnimationDuration(int duration); - // Sets whether or not to show the highlighed (i.e. hot) state. Default true. - void SetShowHighlighted(bool show_highlighted); - // Overridden from View: virtual void SetEnabled(bool enabled); virtual bool IsEnabled() const; @@ -108,9 +105,6 @@ class CustomButton : public Button, // throbbing. bool animate_on_state_change_; - // Whether or not to show the highlighted (i.e. hot) state. - bool show_highlighted_; - // Mouse event flags which can trigger button actions. int triggerable_event_flags_; diff --git a/views/controls/button/text_button.cc b/views/controls/button/text_button.cc index 2442d31..6435be1 100644 --- a/views/controls/button/text_button.cc +++ b/views/controls/button/text_button.cc @@ -175,7 +175,8 @@ TextButton::TextButton(ButtonListener* listener, const std::wstring& text) color_hover_(kHoverColor), has_hover_icon_(false), max_width_(0), - normal_has_border_(false) { + normal_has_border_(false), + show_highlighted_(true) { SetText(text); set_border(new TextButtonBorder); SetAnimationDuration(kHoverAnimationDurationMs); @@ -232,11 +233,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::Paint(gfx::Canvas* canvas, bool for_drag) { if (!for_drag) { PaintBackground(canvas); - if (hover_animation_->IsAnimating()) { + if (show_highlighted_ && hover_animation_->IsAnimating()) { // Draw the hover bitmap into an offscreen buffer, then blend it // back into the current canvas. canvas->saveLayerAlpha(NULL, @@ -245,7 +250,8 @@ void TextButton::Paint(gfx::Canvas* canvas, bool for_drag) { canvas->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); PaintBorder(canvas); canvas->restore(); - } else if (state_ == BS_HOT || state_ == BS_PUSHED || + } else if ((show_highlighted_ && + (state_ == BS_HOT || state_ == BS_PUSHED)) || (state_ == BS_NORMAL && normal_has_border_)) { PaintBorder(canvas); } @@ -254,7 +260,8 @@ void TextButton::Paint(gfx::Canvas* canvas, bool for_drag) { } SkBitmap icon; - if (has_hover_icon_ && (state() == BS_HOT || state() == BS_PUSHED)) + if (has_hover_icon_ && show_highlighted_ && + (state() == BS_HOT || state() == BS_PUSHED)) icon = icon_hover_; else icon = icon_; @@ -306,7 +313,7 @@ void TextButton::Paint(gfx::Canvas* canvas, bool for_drag) { text_bounds.set_x(MirroredLeftPointForRect(text_bounds)); SkColor text_color; - if (state() == BS_HOT || state() == BS_PUSHED) + if (show_highlighted_ && (state() == BS_HOT || state() == BS_PUSHED)) text_color = color_hover_; else text_color = color_; @@ -380,9 +387,11 @@ gfx::Size TextButton::GetMinimumSize() { } void TextButton::SetEnabled(bool enabled) { - if (enabled == IsEnabled()) - return; - CustomButton::SetEnabled(enabled); + if (enabled != IsEnabled()) { + CustomButton::SetEnabled(enabled); + } + // We should always call UpdateColor() since the state of the button might be + // changed by other functions like CustomButton::SetState(). UpdateColor(); SchedulePaint(); } diff --git a/views/controls/button/text_button.h b/views/controls/button/text_button.h index f59b2a7..4257f0a 100644 --- a/views/controls/button/text_button.h +++ b/views/controls/button/text_button.h @@ -117,6 +117,8 @@ 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); // Paint the button into the specified canvas. If |for_drag| is true, the // function paints a drag image representation into the canvas. @@ -184,6 +186,9 @@ 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_; + DISALLOW_COPY_AND_ASSIGN(TextButton); }; |