Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(373)

Unified Diff: ui/views/controls/slider.cc

Issue 10089001: views slider: Add support for gestures. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/controls/slider.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/slider.cc
diff --git a/ui/views/controls/slider.cc b/ui/views/controls/slider.cc
index 1f396c349120bf1e88363de7377221b90c014fec..218c13e838260c7befdb5d05eaa64ec5b2b6664b 100644
--- a/ui/views/controls/slider.cc
+++ b/ui/views/controls/slider.cc
@@ -78,6 +78,19 @@ void Slider::SetValueInternal(float value, SliderChangeReason reason) {
}
}
+void Slider::MoveButtonTo(const gfx::Point& point) {
+ gfx::Insets inset = GetInsets();
+ if (orientation_ == HORIZONTAL) {
+ int amount = base::i18n::IsRTL() ? width() - inset.left() - point.x() :
+ point.x() - inset.left();
+ SetValueInternal(static_cast<float>(amount) / (width() - inset.width()),
+ VALUE_CHANGED_BY_USER);
+ } else {
+ SetValueInternal(1.0f - static_cast<float>(point.y()) / height(),
+ VALUE_CHANGED_BY_USER);
+ }
+}
+
void Slider::SetAccessibleName(const string16& name) {
accessible_name_ = name;
}
@@ -145,20 +158,12 @@ void Slider::OnPaint(gfx::Canvas* canvas) {
bool Slider::OnMousePressed(const views::MouseEvent& event) {
if (listener_)
listener_->SliderDragStarted(this);
- return OnMouseDragged(event);
+ MoveButtonTo(event.location());
+ return true;
}
bool Slider::OnMouseDragged(const views::MouseEvent& event) {
- gfx::Insets inset = GetInsets();
- if (orientation_ == HORIZONTAL) {
- int amount = base::i18n::IsRTL() ? width() - inset.left() - event.x() :
- event.x() - inset.left();
- SetValueInternal(static_cast<float>(amount) / (width() - inset.width()),
- VALUE_CHANGED_BY_USER);
- } else {
- SetValueInternal(1.0f - static_cast<float>(event.y()) / height(),
- VALUE_CHANGED_BY_USER);
- }
+ MoveButtonTo(event.location());
return true;
}
@@ -188,6 +193,15 @@ bool Slider::OnKeyPressed(const views::KeyEvent& event) {
return false;
}
+ui::GestureStatus Slider::OnGestureEvent(const views::GestureEvent& event) {
+ if (event.type() == ui::ET_GESTURE_SCROLL_UPDATE ||
+ event.type() == ui::ET_GESTURE_TAP_DOWN) {
+ MoveButtonTo(event.location());
+ return ui::GESTURE_STATUS_CONSUMED;
+ }
+ return ui::GESTURE_STATUS_UNKNOWN;
+}
+
void Slider::AnimationProgressed(const ui::Animation* animation) {
animating_value_ = animation->CurrentValueBetween(animating_value_, value_);
SchedulePaint();
« no previous file with comments | « ui/views/controls/slider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698