Chromium Code Reviews| Index: ui/views/controls/slider.cc |
| diff --git a/ui/views/controls/slider.cc b/ui/views/controls/slider.cc |
| index dd1148ff1a59123e6f2c960404aee5ffe732267c..3eb2c0dde65d86ed63f851105349e94c32f48481 100644 |
| --- a/ui/views/controls/slider.cc |
| +++ b/ui/views/controls/slider.cc |
| @@ -27,7 +27,7 @@ |
| #include "ui/views/widget/widget.h" |
| namespace { |
| -const int kSlideValueChangeDurationMS = 150; |
| +const int kSlideValueChangeDurationMs = 150; |
| // The image chunks. |
| enum BorderElements { |
| @@ -55,7 +55,7 @@ Slider::Slider(SliderListener* listener) |
| : listener_(listener), |
| value_(0.f), |
| keyboard_increment_(0.1f), |
| - animating_value_(0.f), |
| + initial_animating_value_(0.f), |
| value_is_valid_(false), |
| accessibility_events_enabled_(true), |
| focus_border_color_(0), |
| @@ -93,26 +93,24 @@ void Slider::SetValueInternal(float value, SliderChangeReason reason) { |
| if (old_value_valid && base::MessageLoop::current()) { |
| // Do not animate when setting the value of the slider for the first time. |
| // There is no message-loop when running tests. So we cannot animate then. |
| - animating_value_ = old_value; |
| - move_animation_.reset(new gfx::SlideAnimation(this)); |
| - move_animation_->SetSlideDuration(kSlideValueChangeDurationMS); |
| - move_animation_->Show(); |
| - AnimationProgressed(move_animation_.get()); |
| + if (!move_animation_.get() || !move_animation_->is_animating()) { |
|
varkha
2016/09/23 22:30:25
I suspect you could remove ".get()".
yiyix
2016/09/24 06:24:36
right, i missed this after our discussion yesterda
|
| + initial_animating_value_ = old_value; |
| + move_animation_.reset(new gfx::SlideAnimation(this)); |
| + move_animation_->SetSlideDuration(kSlideValueChangeDurationMs); |
| + move_animation_->Show(); |
| + } |
| } else { |
| SchedulePaint(); |
| } |
| - if (accessibility_events_enabled_ && GetWidget()) { |
| - NotifyAccessibilityEvent( |
| - ui::AX_EVENT_VALUE_CHANGED, true); |
| - } |
| + if (accessibility_events_enabled_ && GetWidget()) |
| + NotifyAccessibilityEvent(ui::AX_EVENT_VALUE_CHANGED, true); |
| } |
| void Slider::PrepareForMove(const int new_x) { |
| // Try to remember the position of the mouse cursor on the button. |
| gfx::Insets inset = GetInsets(); |
| gfx::Rect content = GetContentsBounds(); |
| - float value = move_animation_.get() && move_animation_->is_animating() ? |
| - animating_value_ : value_; |
| + float value = GetAnimatingValue(); |
| const int thumb_width = GetThumbWidth(); |
| const int thumb_x = value * (content.width() - thumb_width); |
| @@ -172,7 +170,8 @@ void Slider::OnPaint(gfx::Canvas* canvas) { |
| float Slider::GetAnimatingValue() const{ |
| return move_animation_.get() && move_animation_->is_animating() |
|
varkha
2016/09/23 22:30:25
See if you don't need ".get()".
yiyix
2016/09/24 06:24:36
Done.
|
| - ? animating_value_ |
| + ? move_animation_->CurrentValueBetween(initial_animating_value_, |
| + value_) |
| : value_; |
| } |
| @@ -241,10 +240,17 @@ void Slider::OnGestureEvent(ui::GestureEvent* event) { |
| } |
| void Slider::AnimationProgressed(const gfx::Animation* animation) { |
| - animating_value_ = animation->CurrentValueBetween(animating_value_, value_); |
| + if (animation && animation != move_animation_.get()) |
| + return; |
|
varkha
2016/09/23 22:30:25
So you are no longer doing exponential approximati
yiyix
2016/09/24 06:24:36
No, I like the default SlideAnimation behavior
|
| SchedulePaint(); |
| } |
| +void Slider::AnimationEnded(const gfx::Animation* animation) { |
| + if (animation == move_animation_.get() && !move_animation_->IsShowing()) { |
|
tdanderson
2016/09/23 20:55:50
nit: no {}
yiyix
2016/09/23 21:39:57
Done.
|
| + move_animation_.reset(); |
| + } |
| +} |
| + |
| void Slider::GetAccessibleState(ui::AXViewState* state) { |
| state->role = ui::AX_ROLE_SLIDER; |
| state->name = accessible_name_; |
| @@ -253,11 +259,13 @@ void Slider::GetAccessibleState(ui::AXViewState* state) { |
| } |
| void Slider::OnSliderDragStarted() { |
| + SetHighlighted(true); |
| if (listener_) |
| listener_->SliderDragStarted(this); |
| } |
| void Slider::OnSliderDragEnded() { |
| + SetHighlighted(false); |
| if (listener_) |
| listener_->SliderDragEnded(this); |
| } |