| 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/md_slider.h" | 5 #include "ui/views/controls/md_slider.h" |
| 6 | 6 |
| 7 #include "skia/ext/cdl_paint.h" |
| 7 #include "third_party/skia/include/core/SkColor.h" | 8 #include "third_party/skia/include/core/SkColor.h" |
| 8 #include "third_party/skia/include/core/SkPaint.h" | 9 #include "third_party/skia/include/core/SkPaint.h" |
| 9 #include "ui/gfx/animation/slide_animation.h" | 10 #include "ui/gfx/animation/slide_animation.h" |
| 10 #include "ui/gfx/canvas.h" | 11 #include "ui/gfx/canvas.h" |
| 11 #include "ui/gfx/geometry/point.h" | 12 #include "ui/gfx/geometry/point.h" |
| 12 #include "ui/gfx/geometry/rect.h" | 13 #include "ui/gfx/geometry/rect.h" |
| 13 #include "ui/views/controls/slider.h" | 14 #include "ui/views/controls/slider.h" |
| 14 | 15 |
| 15 namespace views { | 16 namespace views { |
| 16 | 17 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 const int full = GetAnimatingValue() * width; | 53 const int full = GetAnimatingValue() * width; |
| 53 const int empty = width - full; | 54 const int empty = width - full; |
| 54 const int y = content.height() / 2 - kLineThickness / 2; | 55 const int y = content.height() / 2 - kLineThickness / 2; |
| 55 const int x = content.x() + full + kThumbRadius; | 56 const int x = content.x() + full + kThumbRadius; |
| 56 const SkColor current_thumb_color = | 57 const SkColor current_thumb_color = |
| 57 is_active_ ? kActiveColor : kDisabledColor; | 58 is_active_ ? kActiveColor : kDisabledColor; |
| 58 | 59 |
| 59 // Extra space used to hide slider ends behind the thumb. | 60 // Extra space used to hide slider ends behind the thumb. |
| 60 const int extra_padding = 1; | 61 const int extra_padding = 1; |
| 61 | 62 |
| 62 SkPaint slider_paint; | 63 CdlPaint slider_paint; |
| 63 slider_paint.setFlags(SkPaint::kAntiAlias_Flag); | 64 slider_paint.setAntiAlias(true); |
| 64 slider_paint.setColor(current_thumb_color); | 65 slider_paint.setColor(current_thumb_color); |
| 65 canvas->DrawRoundRect( | 66 canvas->DrawRoundRect( |
| 66 gfx::Rect(content.x(), y, full + extra_padding, kLineThickness), | 67 gfx::Rect(content.x(), y, full + extra_padding, kLineThickness), |
| 67 kSliderRoundedRadius, slider_paint); | 68 kSliderRoundedRadius, slider_paint); |
| 68 slider_paint.setColor(kDisabledColor); | 69 slider_paint.setColor(kDisabledColor); |
| 69 canvas->DrawRoundRect(gfx::Rect(x + kThumbRadius - extra_padding, y, | 70 canvas->DrawRoundRect(gfx::Rect(x + kThumbRadius - extra_padding, y, |
| 70 empty + extra_padding, kLineThickness), | 71 empty + extra_padding, kLineThickness), |
| 71 kSliderRoundedRadius, slider_paint); | 72 kSliderRoundedRadius, slider_paint); |
| 72 | 73 |
| 73 gfx::Point thumb_center(x, content.height() / 2); | 74 gfx::Point thumb_center(x, content.height() / 2); |
| 74 | 75 |
| 75 // Paint the thumb highlight if it exists. | 76 // Paint the thumb highlight if it exists. |
| 76 if (is_active_ && thumb_highlight_radius_ > kThumbRadius) { | 77 if (is_active_ && thumb_highlight_radius_ > kThumbRadius) { |
| 77 SkPaint highlight; | 78 CdlPaint highlight; |
| 78 SkColor kHighlightColor = SkColorSetA(kActiveColor, kHighlightColorAlpha); | 79 SkColor kHighlightColor = SkColorSetA(kActiveColor, kHighlightColorAlpha); |
| 79 highlight.setColor(kHighlightColor); | 80 highlight.setColor(kHighlightColor); |
| 80 highlight.setFlags(SkPaint::kAntiAlias_Flag); | 81 highlight.setAntiAlias(true); |
| 81 canvas->DrawCircle(thumb_center, thumb_highlight_radius_, highlight); | 82 canvas->DrawCircle(thumb_center, thumb_highlight_radius_, highlight); |
| 82 } | 83 } |
| 83 | 84 |
| 84 // Paint the thumb of the slider. | 85 // Paint the thumb of the slider. |
| 85 SkPaint paint; | 86 CdlPaint paint; |
| 86 paint.setColor(current_thumb_color); | 87 paint.setColor(current_thumb_color); |
| 87 paint.setFlags(SkPaint::kAntiAlias_Flag); | 88 paint.setAntiAlias(true); |
| 88 | 89 |
| 89 if (!is_active_) { | 90 if (!is_active_) { |
| 90 paint.setStrokeWidth(kThumbStroke); | 91 paint.setStrokeWidth(kThumbStroke); |
| 91 paint.setStyle(SkPaint::kStroke_Style); | 92 paint.setStyle(CdlPaint::kStroke_Style); |
| 92 } | 93 } |
| 93 canvas->DrawCircle( | 94 canvas->DrawCircle( |
| 94 thumb_center, | 95 thumb_center, |
| 95 is_active_ ? kThumbRadius : (kThumbRadius - kThumbStroke / 2), paint); | 96 is_active_ ? kThumbRadius : (kThumbRadius - kThumbStroke / 2), paint); |
| 96 } | 97 } |
| 97 | 98 |
| 98 const char* MdSlider::GetClassName() const { | 99 const char* MdSlider::GetClassName() const { |
| 99 return "MdSlider"; | 100 return "MdSlider"; |
| 100 } | 101 } |
| 101 | 102 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 Slider::AnimationEnded(animation); | 138 Slider::AnimationEnded(animation); |
| 138 return; | 139 return; |
| 139 } | 140 } |
| 140 if (animation == highlight_animation_.get() && | 141 if (animation == highlight_animation_.get() && |
| 141 !highlight_animation_->IsShowing()) { | 142 !highlight_animation_->IsShowing()) { |
| 142 highlight_animation_.reset(); | 143 highlight_animation_.reset(); |
| 143 } | 144 } |
| 144 } | 145 } |
| 145 | 146 |
| 146 } // namespace views | 147 } // namespace views |
| OLD | NEW |