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 "cc/paint/paint_flags.h" |
7 #include "third_party/skia/include/core/SkDrawLooper.h" | 8 #include "third_party/skia/include/core/SkDrawLooper.h" |
8 #include "third_party/skia/include/core/SkPaint.h" | |
9 #include "ui/accessibility/ax_node_data.h" | 9 #include "ui/accessibility/ax_node_data.h" |
10 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
11 #include "ui/gfx/color_palette.h" | 11 #include "ui/gfx/color_palette.h" |
12 #include "ui/gfx/color_utils.h" | 12 #include "ui/gfx/color_utils.h" |
13 #include "ui/gfx/geometry/rect_conversions.h" | 13 #include "ui/gfx/geometry/rect_conversions.h" |
14 #include "ui/gfx/shadow_value.h" | 14 #include "ui/gfx/shadow_value.h" |
15 #include "ui/gfx/skia_paint_util.h" | 15 #include "ui/gfx/skia_paint_util.h" |
16 #include "ui/views/animation/ink_drop_impl.h" | 16 #include "ui/views/animation/ink_drop_impl.h" |
17 #include "ui/views/animation/ink_drop_ripple.h" | 17 #include "ui/views/animation/ink_drop_ripple.h" |
18 #include "ui/views/border.h" | 18 #include "ui/views/border.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 | 71 |
72 void OnPaint(gfx::Canvas* canvas) override { | 72 void OnPaint(gfx::Canvas* canvas) override { |
73 const float dsf = canvas->UndoDeviceScaleFactor(); | 73 const float dsf = canvas->UndoDeviceScaleFactor(); |
74 std::vector<gfx::ShadowValue> shadows; | 74 std::vector<gfx::ShadowValue> shadows; |
75 gfx::ShadowValue shadow( | 75 gfx::ShadowValue shadow( |
76 gfx::Vector2d(kShadowOffsetX, kShadowOffsetY), 2 * kShadowBlur, | 76 gfx::Vector2d(kShadowOffsetX, kShadowOffsetY), 2 * kShadowBlur, |
77 SkColorSetA(GetNativeTheme()->GetSystemColor( | 77 SkColorSetA(GetNativeTheme()->GetSystemColor( |
78 ui::NativeTheme::kColorId_LabelEnabledColor), | 78 ui::NativeTheme::kColorId_LabelEnabledColor), |
79 0x99)); | 79 0x99)); |
80 shadows.push_back(shadow.Scale(dsf)); | 80 shadows.push_back(shadow.Scale(dsf)); |
81 SkPaint thumb_paint; | 81 cc::PaintFlags thumb_paint; |
82 thumb_paint.setLooper(gfx::CreateShadowDrawLooperCorrectBlur(shadows)); | 82 thumb_paint.setLooper(gfx::CreateShadowDrawLooperCorrectBlur(shadows)); |
83 thumb_paint.setAntiAlias(true); | 83 thumb_paint.setAntiAlias(true); |
84 const SkColor thumb_on_color = GetNativeTheme()->GetSystemColor( | 84 const SkColor thumb_on_color = GetNativeTheme()->GetSystemColor( |
85 ui::NativeTheme::kColorId_ProminentButtonColor); | 85 ui::NativeTheme::kColorId_ProminentButtonColor); |
86 const SkColor thumb_off_color = GetNativeTheme()->GetSystemColor( | 86 const SkColor thumb_off_color = GetNativeTheme()->GetSystemColor( |
87 ui::NativeTheme::kColorId_DialogBackground); | 87 ui::NativeTheme::kColorId_DialogBackground); |
88 const SkAlpha blend = static_cast<SkAlpha>(SK_AlphaOPAQUE * color_ratio_); | 88 const SkAlpha blend = static_cast<SkAlpha>(SK_AlphaOPAQUE * color_ratio_); |
89 thumb_paint.setColor( | 89 thumb_paint.setColor( |
90 color_utils::AlphaBlend(thumb_on_color, thumb_off_color, blend)); | 90 color_utils::AlphaBlend(thumb_on_color, thumb_off_color, blend)); |
91 | 91 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 } | 190 } |
191 | 191 |
192 void ToggleButton::OnPaint(gfx::Canvas* canvas) { | 192 void ToggleButton::OnPaint(gfx::Canvas* canvas) { |
193 // Paint the toggle track. To look sharp even at fractional scale factors, | 193 // Paint the toggle track. To look sharp even at fractional scale factors, |
194 // round up to pixel boundaries. | 194 // round up to pixel boundaries. |
195 canvas->Save(); | 195 canvas->Save(); |
196 float dsf = canvas->UndoDeviceScaleFactor(); | 196 float dsf = canvas->UndoDeviceScaleFactor(); |
197 gfx::RectF track_rect(GetTrackBounds()); | 197 gfx::RectF track_rect(GetTrackBounds()); |
198 track_rect.Scale(dsf); | 198 track_rect.Scale(dsf); |
199 track_rect = gfx::RectF(gfx::ToEnclosingRect(track_rect)); | 199 track_rect = gfx::RectF(gfx::ToEnclosingRect(track_rect)); |
200 SkPaint track_paint; | 200 cc::PaintFlags track_paint; |
201 track_paint.setAntiAlias(true); | 201 track_paint.setAntiAlias(true); |
202 const double color_ratio = slide_animation_.GetCurrentValue(); | 202 const double color_ratio = slide_animation_.GetCurrentValue(); |
203 track_paint.setColor(color_utils::AlphaBlend( | 203 track_paint.setColor(color_utils::AlphaBlend( |
204 GetTrackColor(true), GetTrackColor(false), | 204 GetTrackColor(true), GetTrackColor(false), |
205 static_cast<SkAlpha>(SK_AlphaOPAQUE * color_ratio))); | 205 static_cast<SkAlpha>(SK_AlphaOPAQUE * color_ratio))); |
206 canvas->DrawRoundRect(track_rect, track_rect.height() / 2, track_paint); | 206 canvas->DrawRoundRect(track_rect, track_rect.height() / 2, track_paint); |
207 canvas->Restore(); | 207 canvas->Restore(); |
208 | 208 |
209 Painter::PaintFocusPainter(this, canvas, focus_painter_.get()); | 209 Painter::PaintFocusPainter(this, canvas, focus_painter_.get()); |
210 } | 210 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 // TODO(varkha, estade): The thumb is using its own view. Investigate if | 272 // TODO(varkha, estade): The thumb is using its own view. Investigate if |
273 // repainting in every animation step to update colors could be avoided. | 273 // repainting in every animation step to update colors could be avoided. |
274 UpdateThumb(); | 274 UpdateThumb(); |
275 SchedulePaint(); | 275 SchedulePaint(); |
276 return; | 276 return; |
277 } | 277 } |
278 CustomButton::AnimationProgressed(animation); | 278 CustomButton::AnimationProgressed(animation); |
279 } | 279 } |
280 | 280 |
281 } // namespace views | 281 } // namespace views |
OLD | NEW |