OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ui/views/controls/button/toggle_button.h" | 5 #include "ui/views/controls/button/toggle_button.h" |
6 | 6 |
7 #include "third_party/skia/include/core/SkDrawLooper.h" | 7 #include "third_party/skia/include/core/SkDrawLooper.h" |
8 #include "third_party/skia/include/core/SkPaint.h" | 8 #include "third_party/skia/include/core/SkPaint.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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 thumb_paint.setStyle(SkPaint::kFill_Style); | 92 thumb_paint.setStyle(SkPaint::kFill_Style); |
93 thumb_paint.setAntiAlias(true); | 93 thumb_paint.setAntiAlias(true); |
94 const SkColor thumb_on_color = GetNativeTheme()->GetSystemColor( | 94 const SkColor thumb_on_color = GetNativeTheme()->GetSystemColor( |
95 ui::NativeTheme::kColorId_ProminentButtonColor); | 95 ui::NativeTheme::kColorId_ProminentButtonColor); |
96 // TODO(estade): get this color from the theme? | 96 // TODO(estade): get this color from the theme? |
97 const SkColor thumb_off_color = SK_ColorWHITE; | 97 const SkColor thumb_off_color = SK_ColorWHITE; |
98 thumb_paint.setColor( | 98 thumb_paint.setColor( |
99 color_utils::AlphaBlend(thumb_on_color, thumb_off_color, blend)); | 99 color_utils::AlphaBlend(thumb_on_color, thumb_off_color, blend)); |
100 canvas->DrawCircle(gfx::RectF(thumb_bounds).CenterPoint(), | 100 canvas->DrawCircle(gfx::RectF(thumb_bounds).CenterPoint(), |
101 thumb_bounds.height() / 2.f, thumb_paint); | 101 thumb_bounds.height() / 2.f, thumb_paint); |
102 | |
103 // Adjust thumb ink drop highlight position to make it animate with the thumb. | |
104 OffsetInkDropRipple(thumb_bounds.CenterPoint() - original_center_point_); | |
Evan Stade
2016/10/10 17:33:15
I'm kind of skeptical this will look great/stay in
varkha
2016/10/12 00:44:59
Done.
| |
102 } | 105 } |
103 | 106 |
104 void ToggleButton::NotifyClick(const ui::Event& event) { | 107 void ToggleButton::NotifyClick(const ui::Event& event) { |
105 SetIsOn(!is_on(), true); | 108 SetIsOn(!is_on(), true); |
106 CustomButton::NotifyClick(event); | 109 CustomButton::NotifyClick(event); |
107 } | 110 } |
108 | 111 |
109 void ToggleButton::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 112 void ToggleButton::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
110 SchedulePaint(); | 113 SchedulePaint(); |
111 } | 114 } |
112 | 115 |
116 void ToggleButton::AddInkDropLayer(ui::Layer* ink_drop_layer) { | |
117 original_center_point_ = GetThumbBounds().CenterPoint(); | |
118 CustomButton::AddInkDropLayer(ink_drop_layer); | |
119 } | |
120 | |
113 std::unique_ptr<InkDropRipple> ToggleButton::CreateInkDropRipple() const { | 121 std::unique_ptr<InkDropRipple> ToggleButton::CreateInkDropRipple() const { |
114 return CreateDefaultInkDropRipple(GetThumbBounds().CenterPoint()); | 122 return CreateDefaultInkDropRipple(GetThumbBounds().CenterPoint()); |
115 } | 123 } |
116 | 124 |
117 SkColor ToggleButton::GetInkDropBaseColor() const { | 125 SkColor ToggleButton::GetInkDropBaseColor() const { |
118 return is_on() | 126 return is_on() |
119 ? GetNativeTheme()->GetSystemColor( | 127 ? GetNativeTheme()->GetSystemColor( |
120 ui::NativeTheme::kColorId_ProminentButtonColor) | 128 ui::NativeTheme::kColorId_ProminentButtonColor) |
121 : kTrackOffColor; | 129 : kTrackOffColor; |
122 } | 130 } |
(...skipping 15 matching lines...) Expand all Loading... | |
138 thumb_bounds.set_x(thumb_bounds.x() + | 146 thumb_bounds.set_x(thumb_bounds.x() + |
139 slide_animation_.GetCurrentValue() * | 147 slide_animation_.GetCurrentValue() * |
140 (thumb_bounds.width() - thumb_bounds.height())); | 148 (thumb_bounds.width() - thumb_bounds.height())); |
141 // The thumb is a circle, so the width should match the height. | 149 // The thumb is a circle, so the width should match the height. |
142 thumb_bounds.set_width(thumb_bounds.height()); | 150 thumb_bounds.set_width(thumb_bounds.height()); |
143 thumb_bounds.set_x(GetMirroredXForRect(thumb_bounds)); | 151 thumb_bounds.set_x(GetMirroredXForRect(thumb_bounds)); |
144 return thumb_bounds; | 152 return thumb_bounds; |
145 } | 153 } |
146 | 154 |
147 } // namespace views | 155 } // namespace views |
OLD | NEW |