| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ash/frame/caption_buttons/frame_caption_button.h" | 5 #include "ash/frame/caption_buttons/frame_caption_button.h" |
| 6 | 6 |
| 7 #include "ui/gfx/animation/slide_animation.h" | 7 #include "ui/gfx/animation/slide_animation.h" |
| 8 #include "ui/gfx/animation/throb_animation.h" | 8 #include "ui/gfx/animation/throb_animation.h" |
| 9 #include "ui/gfx/canvas.h" | 9 #include "ui/gfx/canvas.h" |
| 10 #include "ui/gfx/color_palette.h" | 10 #include "ui/gfx/color_palette.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 use_light_images_(false), | 44 use_light_images_(false), |
| 45 alpha_(255), | 45 alpha_(255), |
| 46 swap_images_animation_(new gfx::SlideAnimation(this)) { | 46 swap_images_animation_(new gfx::SlideAnimation(this)) { |
| 47 swap_images_animation_->Reset(1); | 47 swap_images_animation_->Reset(1); |
| 48 | 48 |
| 49 // Do not flip the gfx::Canvas passed to the OnPaint() method. The snap left | 49 // Do not flip the gfx::Canvas passed to the OnPaint() method. The snap left |
| 50 // and snap right button icons should not be flipped. The other icons are | 50 // and snap right button icons should not be flipped. The other icons are |
| 51 // horizontally symmetrical. | 51 // horizontally symmetrical. |
| 52 } | 52 } |
| 53 | 53 |
| 54 FrameCaptionButton::~FrameCaptionButton() { | 54 FrameCaptionButton::~FrameCaptionButton() {} |
| 55 } | |
| 56 | 55 |
| 57 void FrameCaptionButton::SetImage(CaptionButtonIcon icon, | 56 void FrameCaptionButton::SetImage(CaptionButtonIcon icon, |
| 58 Animate animate, | 57 Animate animate, |
| 59 gfx::VectorIconId icon_image_id) { | 58 gfx::VectorIconId icon_image_id) { |
| 60 gfx::ImageSkia new_icon_image = gfx::CreateVectorIcon( | 59 gfx::ImageSkia new_icon_image = gfx::CreateVectorIcon( |
| 61 icon_image_id, use_light_images_ ? SK_ColorWHITE : gfx::kChromeIconGrey); | 60 icon_image_id, use_light_images_ ? SK_ColorWHITE : gfx::kChromeIconGrey); |
| 62 | 61 |
| 63 // The early return is dependent on |animate| because callers use SetImage() | 62 // The early return is dependent on |animate| because callers use SetImage() |
| 64 // with ANIMATE_NO to progress the crossfade animation to the end. | 63 // with ANIMATE_NO to progress the crossfade animation to the end. |
| 65 if (icon == icon_ && | 64 if (icon == icon_ && |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 bg_alpha = kPressedAlpha; | 114 bg_alpha = kPressedAlpha; |
| 116 | 115 |
| 117 if (bg_alpha != SK_AlphaTRANSPARENT) { | 116 if (bg_alpha != SK_AlphaTRANSPARENT) { |
| 118 canvas->DrawColor(SkColorSetA( | 117 canvas->DrawColor(SkColorSetA( |
| 119 use_light_images_ ? SK_ColorWHITE : SK_ColorBLACK, bg_alpha)); | 118 use_light_images_ ? SK_ColorWHITE : SK_ColorBLACK, bg_alpha)); |
| 120 } | 119 } |
| 121 | 120 |
| 122 int icon_alpha = swap_images_animation_->CurrentValueBetween(0, 255); | 121 int icon_alpha = swap_images_animation_->CurrentValueBetween(0, 255); |
| 123 int crossfade_icon_alpha = 0; | 122 int crossfade_icon_alpha = 0; |
| 124 if (icon_alpha < static_cast<int>(kFadeOutRatio * 255)) | 123 if (icon_alpha < static_cast<int>(kFadeOutRatio * 255)) |
| 125 crossfade_icon_alpha = static_cast<int>(255 - icon_alpha / kFadeOutRatio); | 124 crossfade_icon_alpha = static_cast<int>(255 - icon_alpha / kFadeOutRatio); |
| 126 | 125 |
| 127 if (crossfade_icon_alpha > 0 && !crossfade_icon_image_.isNull()) { | 126 if (crossfade_icon_alpha > 0 && !crossfade_icon_image_.isNull()) { |
| 128 gfx::Canvas icon_canvas(icon_image_.size(), canvas->image_scale(), false); | 127 gfx::Canvas icon_canvas(icon_image_.size(), canvas->image_scale(), false); |
| 129 SkPaint paint; | 128 SkPaint paint; |
| 130 paint.setAlpha(icon_alpha); | 129 paint.setAlpha(icon_alpha); |
| 131 icon_canvas.DrawImageInt(icon_image_, 0, 0, paint); | 130 icon_canvas.DrawImageInt(icon_image_, 0, 0, paint); |
| 132 | 131 |
| 133 paint.setAlpha(crossfade_icon_alpha); | 132 paint.setAlpha(crossfade_icon_alpha); |
| 134 paint.setXfermodeMode(SkXfermode::kPlus_Mode); | 133 paint.setXfermodeMode(SkXfermode::kPlus_Mode); |
| 135 icon_canvas.DrawImageInt(crossfade_icon_image_, 0, 0, paint); | 134 icon_canvas.DrawImageInt(crossfade_icon_image_, 0, 0, paint); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 inactive_alpha = | 175 inactive_alpha = |
| 177 hover_animation().CurrentValueBetween(inactive_alpha, 1.0f); | 176 hover_animation().CurrentValueBetween(inactive_alpha, 1.0f); |
| 178 } else if (state() == STATE_PRESSED || state() == STATE_HOVERED) { | 177 } else if (state() == STATE_PRESSED || state() == STATE_HOVERED) { |
| 179 inactive_alpha = 1.0f; | 178 inactive_alpha = 1.0f; |
| 180 } | 179 } |
| 181 alpha *= inactive_alpha; | 180 alpha *= inactive_alpha; |
| 182 } | 181 } |
| 183 | 182 |
| 184 SkPaint paint; | 183 SkPaint paint; |
| 185 paint.setAlpha(alpha); | 184 paint.setAlpha(alpha); |
| 186 canvas->DrawImageInt(to_center, | 185 canvas->DrawImageInt(to_center, (width() - to_center.width()) / 2, |
| 187 (width() - to_center.width()) / 2, | 186 (height() - to_center.height()) / 2, paint); |
| 188 (height() - to_center.height()) / 2, | |
| 189 paint); | |
| 190 } | 187 } |
| 191 | 188 |
| 192 } // namespace ash | 189 } // namespace ash |
| OLD | NEW |