summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorzork@chromium.org <zork@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-24 10:54:32 +0000
committerzork@chromium.org <zork@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-24 10:54:32 +0000
commit872a604c8016b761123eb3adf0fe3f5b4df261ec (patch)
treefa12333e6b1df70702a350e0ffa65d0792db4383 /ui
parent9ee5eab3a66eff396bb6513311dbd0abbec3e42b (diff)
downloadchromium_src-872a604c8016b761123eb3adf0fe3f5b4df261ec.zip
chromium_src-872a604c8016b761123eb3adf0fe3f5b4df261ec.tar.gz
chromium_src-872a604c8016b761123eb3adf0fe3f5b4df261ec.tar.bz2
Allow sliders to be adjusted with arrow keys
R=sky@chromium.org BUG=118012 Review URL: http://codereview.chromium.org/9845005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128730 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/views/controls/slider.cc27
-rw-r--r--ui/views/controls/slider.h5
2 files changed, 32 insertions, 0 deletions
diff --git a/ui/views/controls/slider.cc b/ui/views/controls/slider.cc
index c42902b..c806536 100644
--- a/ui/views/controls/slider.cc
+++ b/ui/views/controls/slider.cc
@@ -28,9 +28,11 @@ Slider::Slider(SliderListener* listener, Orientation orientation)
: listener_(listener),
orientation_(orientation),
value_(0.f),
+ keyboard_increment_(0.1f),
animating_value_(0.f),
value_is_valid_(false) {
EnableCanvasFlippingForRTLUI(true);
+ set_focusable(true);
}
Slider::~Slider() {
@@ -40,6 +42,10 @@ void Slider::SetValue(float value) {
SetValueInternal(value, VALUE_CHANGED_BY_API);
}
+void Slider::SetKeyboardIncrement(float increment) {
+ keyboard_increment_ = increment;
+}
+
void Slider::SetValueInternal(float value, SliderChangeReason reason) {
bool old_value_valid = value_is_valid_;
@@ -154,6 +160,27 @@ bool Slider::OnMouseDragged(const views::MouseEvent& event) {
return true;
}
+bool Slider::OnKeyPressed(const views::KeyEvent& event) {
+ if (orientation_ == HORIZONTAL) {
+ if (event.key_code() == ui::VKEY_LEFT) {
+ SetValueInternal(value_ - keyboard_increment_, VALUE_CHANGED_BY_USER);
+ return true;
+ } else if (event.key_code() == ui::VKEY_RIGHT) {
+ SetValueInternal(value_ + keyboard_increment_, VALUE_CHANGED_BY_USER);
+ return true;
+ }
+ } else {
+ if (event.key_code() == ui::VKEY_DOWN) {
+ SetValueInternal(value_ - keyboard_increment_, VALUE_CHANGED_BY_USER);
+ return true;
+ } else if (event.key_code() == ui::VKEY_UP) {
+ SetValueInternal(value_ + keyboard_increment_, VALUE_CHANGED_BY_USER);
+ return true;
+ }
+ }
+ return false;
+}
+
void Slider::AnimationProgressed(const ui::Animation* animation) {
animating_value_ = animation->CurrentValueBetween(animating_value_, value_);
SchedulePaint();
diff --git a/ui/views/controls/slider.h b/ui/views/controls/slider.h
index 2e7a21f..d98c5fd 100644
--- a/ui/views/controls/slider.h
+++ b/ui/views/controls/slider.h
@@ -48,6 +48,9 @@ class VIEWS_EXPORT Slider : public View,
float value() const { return value_; }
void SetValue(float value);
+ // Set the delta used for changing the value via keyboard.
+ void SetKeyboardIncrement(float increment);
+
void SetAccessibleName(const string16& name);
private:
@@ -58,6 +61,7 @@ class VIEWS_EXPORT Slider : public View,
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE;
virtual bool OnMouseDragged(const views::MouseEvent& event) OVERRIDE;
+ virtual bool OnKeyPressed(const views::KeyEvent& event) OVERRIDE;
virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
// ui::AnimationDelegate overrides:
@@ -69,6 +73,7 @@ class VIEWS_EXPORT Slider : public View,
scoped_ptr<ui::SlideAnimation> move_animation_;
float value_;
+ float keyboard_increment_;
float animating_value_;
bool value_is_valid_;
string16 accessible_name_;