Index: ui/views/controls/slider.cc |
diff --git a/ui/views/controls/slider.cc b/ui/views/controls/slider.cc |
index dd1148ff1a59123e6f2c960404aee5ffe732267c..75a4c16d53ac5c121a4ce469465f2f7e63bb77b1 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_) { |
+ 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); |
@@ -165,17 +163,15 @@ gfx::Size Slider::GetPreferredSize() const { |
return gfx::Size(std::max(width(), kSizeMajor), kSizeMinor); |
} |
-void Slider::OnPaint(gfx::Canvas* canvas) { |
- View::OnPaint(canvas); |
- OnPaintFocus(canvas); |
-} |
- |
float Slider::GetAnimatingValue() const{ |
- return move_animation_.get() && move_animation_->is_animating() |
- ? animating_value_ |
+ return move_animation_ && move_animation_->is_animating() |
+ ? move_animation_->CurrentValueBetween(initial_animating_value_, |
+ value_) |
: value_; |
} |
+void Slider::SetHighlighted(bool is_highlighted) {} |
+ |
bool Slider::OnMousePressed(const ui::MouseEvent& event) { |
if (!event.IsOnlyLeftMouseButton()) |
return false; |
@@ -240,11 +236,20 @@ void Slider::OnGestureEvent(ui::GestureEvent* event) { |
} |
} |
+void Slider::OnPaint(gfx::Canvas* canvas) { |
+ View::OnPaint(canvas); |
+ OnPaintFocus(canvas); |
+} |
varkha
2016/09/24 13:59:18
nit: I think it would be easier to read this class
yiyix
2016/09/29 19:09:39
Done.
bruthig
2016/09/30 21:56:18
In the future it would make it easier as a reviewe
|
+ |
void Slider::AnimationProgressed(const gfx::Animation* animation) { |
- animating_value_ = animation->CurrentValueBetween(animating_value_, value_); |
SchedulePaint(); |
} |
+void Slider::AnimationEnded(const gfx::Animation* animation) { |
+ if (animation == move_animation_.get()) |
+ move_animation_.reset(); |
+} |
+ |
void Slider::GetAccessibleState(ui::AXViewState* state) { |
state->role = ui::AX_ROLE_SLIDER; |
state->name = accessible_name_; |
@@ -253,11 +258,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); |
} |