Chromium Code Reviews| Index: ash/frame/caption_buttons/frame_caption_button.cc |
| diff --git a/ash/frame/caption_buttons/frame_caption_button.cc b/ash/frame/caption_buttons/frame_caption_button.cc |
| index 2b166436a2498ea7ec13bca7ef6266ad55753127..9902a30e030f72a30da2a66e04f3f026a4c2acce 100644 |
| --- a/ash/frame/caption_buttons/frame_caption_button.cc |
| +++ b/ash/frame/caption_buttons/frame_caption_button.cc |
| @@ -23,6 +23,14 @@ const float kFadeOutRatio = 0.5f; |
| // The alpha to draw inactive icons with. |
| const float kInactiveIconAlpha = 0.2f; |
| +// The background colors and alpha values used for the button background |
| +// hovered and pressed states. |
| +// TODO(tdanderson|estade): Request these colors from ThemeProvider. |
| +const int kHoveredAlpha = 0x14; |
| +const SkColor kHoveredColor = SK_ColorBLACK; |
|
Peter Kasting
2015/12/18 18:59:15
Nit: It seems OK to me to just hardcode SK_ColorBL
tdanderson
2016/01/04 23:11:14
Done.
|
| +const int kPressedAlpha = 0x24; |
| +const SkColor kPressedColor = SK_ColorBLACK; |
| + |
| } // namespace |
| // static |
| @@ -32,11 +40,10 @@ FrameCaptionButton::FrameCaptionButton(views::ButtonListener* listener, |
| CaptionButtonIcon icon) |
| : CustomButton(listener), |
| icon_(icon), |
| + size_(gfx::Size()), |
|
Peter Kasting
2015/12/18 18:59:15
No need for this
tdanderson
2016/01/04 23:11:14
Done.
|
| paint_as_active_(false), |
| alpha_(255), |
| icon_image_id_(-1), |
| - hovered_background_image_id_(-1), |
| - pressed_background_image_id_(-1), |
| swap_images_animation_(new gfx::SlideAnimation(this)) { |
| swap_images_animation_->Reset(1); |
| @@ -48,18 +55,14 @@ FrameCaptionButton::FrameCaptionButton(views::ButtonListener* listener, |
| FrameCaptionButton::~FrameCaptionButton() { |
| } |
| -void FrameCaptionButton::SetImages(CaptionButtonIcon icon, |
| - Animate animate, |
| - int icon_image_id, |
| - int hovered_background_image_id, |
| - int pressed_background_image_id) { |
| - // The early return is dependant on |animate| because callers use SetImages() |
| +void FrameCaptionButton::SetImage(CaptionButtonIcon icon, |
| + Animate animate, |
| + int icon_image_id) { |
| + // The early return is dependant on |animate| because callers use SetImage() |
| // with ANIMATE_NO to progress the crossfade animation to the end. |
| if (icon == icon_ && |
| (animate == ANIMATE_YES || !swap_images_animation_->is_animating()) && |
| - icon_image_id == icon_image_id_ && |
| - hovered_background_image_id == hovered_background_image_id_ && |
| - pressed_background_image_id == pressed_background_image_id_) { |
| + icon_image_id == icon_image_id_) { |
| return; |
| } |
| @@ -68,15 +71,9 @@ void FrameCaptionButton::SetImages(CaptionButtonIcon icon, |
| icon_ = icon; |
| icon_image_id_ = icon_image_id; |
| - hovered_background_image_id_ = hovered_background_image_id; |
| - pressed_background_image_id_ = pressed_background_image_id; |
| ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| icon_image_ = *rb.GetImageSkiaNamed(icon_image_id); |
| - hovered_background_image_ = *rb.GetImageSkiaNamed( |
| - hovered_background_image_id); |
| - pressed_background_image_ = *rb.GetImageSkiaNamed( |
| - pressed_background_image_id); |
| if (animate == ANIMATE_YES) { |
| swap_images_animation_->Reset(0); |
| @@ -101,8 +98,7 @@ void FrameCaptionButton::SetAlpha(int alpha) { |
| } |
| gfx::Size FrameCaptionButton::GetPreferredSize() const { |
| - return hovered_background_image_.isNull() ? |
| - gfx::Size() : hovered_background_image_.size(); |
| + return size_; |
| } |
| const char* FrameCaptionButton::GetClassName() const { |
| @@ -111,13 +107,13 @@ const char* FrameCaptionButton::GetClassName() const { |
| void FrameCaptionButton::OnPaint(gfx::Canvas* canvas) { |
| if (hover_animation_->is_animating() || state() == STATE_HOVERED) { |
| - int hovered_background_alpha = hover_animation_->is_animating() ? |
| - hover_animation_->CurrentValueBetween(0, 255) : 255; |
| - SkPaint paint; |
| - paint.setAlpha(hovered_background_alpha); |
| - canvas->DrawImageInt(hovered_background_image_, 0, 0, paint); |
| + int hovered_background_alpha = |
| + hover_animation_->is_animating() |
| + ? hover_animation_->CurrentValueBetween(0, kHoveredAlpha) |
| + : kHoveredAlpha; |
| + canvas->DrawColor(SkColorSetA(kHoveredColor, hovered_background_alpha)); |
| } else if (state() == STATE_PRESSED) { |
| - canvas->DrawImageInt(pressed_background_image_, 0, 0); |
| + canvas->DrawColor(SkColorSetA(kPressedColor, kPressedAlpha)); |
| } |
| int icon_alpha = swap_images_animation_->CurrentValueBetween(0, 255); |