Chromium Code Reviews| Index: ui/views/controls/button/toggle_button.cc |
| diff --git a/ui/views/controls/button/toggle_button.cc b/ui/views/controls/button/toggle_button.cc |
| index 9d700a8b4e77e5830d948640bbb6622f43ae1c89..c7f13533228f8da18dde377c98523dd3d70032a7 100644 |
| --- a/ui/views/controls/button/toggle_button.cc |
| +++ b/ui/views/controls/button/toggle_button.cc |
| @@ -4,6 +4,8 @@ |
| #include "ui/views/controls/button/toggle_button.h" |
| +#include "third_party/skia/include/core/SkDrawLooper.h" |
| +#include "third_party/skia/include/core/SkPaint.h" |
| #include "ui/gfx/canvas.h" |
| #include "ui/gfx/color_utils.h" |
| #include "ui/views/border.h" |
| @@ -16,10 +18,13 @@ namespace { |
| const int kTrackHeight = 14; |
| const int kTrackWidth = 36; |
| // Margins from edge of track to edge of view. |
| -const int kTrackVerticalMargin = 4; |
| -const int kTrackHorizontalMargin = 1; |
| -// Margin from edge of thumb to closest three edges of view. |
| -const int kThumbMargin = 1; |
| +const int kTrackVerticalMargin = 6; |
| +const int kTrackHorizontalMargin = 2; |
| +// Margin from edge of thumb to closest edge of view. Note that the thumb |
| +// margins must be sufficiently large to allow space for the shadow. |
| +const int kThumbHorizontalMargin = 2; |
| +// Margin from top/bottom edge of thumb to top/bottom edge of view. |
| +const int kThumbVerticalMargin = 3; |
| } // namespace |
| @@ -57,38 +62,43 @@ void ToggleButton::OnPaint(gfx::Canvas* canvas) { |
| SkAlpha blend = |
| static_cast<SkAlpha>(SK_AlphaOPAQUE * slide_animation_.GetCurrentValue()); |
| - gfx::RectF track_rect(GetContentsBounds()); |
| - SkPaint paint; |
| - paint.setAntiAlias(true); |
| - |
| // Track. |
| + gfx::RectF track_rect(GetContentsBounds()); |
| + SkPaint track_paint; |
| + track_paint.setAntiAlias(true); |
| const SkColor track_on_color = |
| SkColorSetA(GetNativeTheme()->GetSystemColor( |
| ui::NativeTheme::kColorId_CallToActionColor), |
| 0xFF / 2); |
| // TODO(estade): get this color from the theme. |
| const SkColor track_off_color = SkColorSetA(SK_ColorBLACK, 0x61); |
| - paint.setColor( |
| + track_paint.setColor( |
| color_utils::AlphaBlend(track_on_color, track_off_color, blend)); |
| - canvas->DrawRoundRect(track_rect, track_rect.height() / 2, paint); |
| + canvas->DrawRoundRect(track_rect, track_rect.height() / 2, track_paint); |
| // Thumb. |
| - const SkColor thumb_on_color = GetNativeTheme()->GetSystemColor( |
| - ui::NativeTheme::kColorId_CallToActionColor); |
| - // TODO(estade): get this color from the theme. |
| - const SkColor thumb_off_color = SkColorSetRGB(0xFA, 0xFA, 0xFA); |
| - paint.setColor( |
| - color_utils::AlphaBlend(thumb_on_color, thumb_off_color, blend)); |
| gfx::Rect thumb_bounds = GetLocalBounds(); |
| - thumb_bounds.Inset(gfx::Insets(kThumbMargin)); |
| + thumb_bounds.Inset(gfx::Insets(kThumbVerticalMargin, kThumbHorizontalMargin)); |
| thumb_bounds.set_x(thumb_bounds.x() + |
| slide_animation_.GetCurrentValue() * |
| (thumb_bounds.width() - thumb_bounds.height())); |
| thumb_bounds.set_width(thumb_bounds.height()); |
| thumb_bounds.set_x(GetMirroredXForRect(thumb_bounds)); |
| + SkPaint thumb_paint; |
| + std::vector<gfx::ShadowValue> shadows; |
| + shadows.emplace(shadows.end(), gfx::Vector2d(0, 1), 5.f, |
|
sadrul
2016/07/22 03:35:05
emplace_back instead?
Evan Stade
2016/07/22 14:03:28
done, thanks
|
| + SkColorSetA(SK_ColorBLACK, 0x99)); |
| + thumb_paint.setLooper(gfx::CreateShadowDrawLooperCorrectBlur(shadows)); |
| + thumb_paint.setStyle(SkPaint::kStrokeAndFill_Style); |
| + thumb_paint.setAntiAlias(true); |
| + const SkColor thumb_on_color = GetNativeTheme()->GetSystemColor( |
| + ui::NativeTheme::kColorId_CallToActionColor); |
| + // TODO(estade): get this color from the theme. |
| + const SkColor thumb_off_color = SkColorSetRGB(0xFA, 0xFA, 0xFA); |
| + thumb_paint.setColor( |
| + color_utils::AlphaBlend(thumb_on_color, thumb_off_color, blend)); |
| canvas->DrawCircle(gfx::RectF(thumb_bounds).CenterPoint(), |
| - thumb_bounds.height() / 2.f, paint); |
| - // TODO(estade): add a shadow to the thumb. |
| + thumb_bounds.height() / 2.f, thumb_paint); |
| } |
| void ToggleButton::NotifyClick(const ui::Event& event) { |