Commit 362963e6 authored by yiyix's avatar yiyix Committed by Commit bot

Fix controlling volume slider with keyboard

In the current code base, a float number is used when users try to control
the volume slider by using keyboard. It increases/decreases the volume by
0.1 (or 10%) after each press. In the CL2281173002, it accidentally
changed this increment to an integer, so the volume either jumps to silent
or max.

BUG=631775

Review-Url: https://codereview.chromium.org/2297833002
Cr-Commit-Position: refs/heads/master@{#415700}
parent 71d9b4ad
...@@ -242,7 +242,7 @@ void Slider::OnMouseReleased(const ui::MouseEvent& event) { ...@@ -242,7 +242,7 @@ void Slider::OnMouseReleased(const ui::MouseEvent& event) {
} }
bool Slider::OnKeyPressed(const ui::KeyEvent& event) { bool Slider::OnKeyPressed(const ui::KeyEvent& event) {
int new_value = value_; float new_value = value_;
if (event.key_code() == ui::VKEY_LEFT) if (event.key_code() == ui::VKEY_LEFT)
new_value -= keyboard_increment_; new_value -= keyboard_increment_;
else if (event.key_code() == ui::VKEY_RIGHT) else if (event.key_code() == ui::VKEY_RIGHT)
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/event.h" #include "ui/events/event.h"
#include "ui/events/gesture_event_details.h" #include "ui/events/gesture_event_details.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/events/test/event_generator.h" #include "ui/events/test/event_generator.h"
#include "ui/views/test/slider_test_api.h" #include "ui/views/test/slider_test_api.h"
#include "ui/views/test/views_test_base.h" #include "ui/views/test/views_test_base.h"
...@@ -302,6 +303,19 @@ TEST_F(HorizontalSliderTest, SliderValueForScrollGesture) { ...@@ -302,6 +303,19 @@ TEST_F(HorizontalSliderTest, SliderValueForScrollGesture) {
EXPECT_NEAR(0.75, slider()->value(), 0.03); EXPECT_NEAR(0.75, slider()->value(), 0.03);
} }
// Test the slider location by adjusting it using keyboard.
TEST_F(HorizontalSliderTest, SliderValueForKeyboard) {
float value =0.5;
slider()->SetValue(value);
slider()->RequestFocus();
event_generator()->PressKey(ui::VKEY_RIGHT, 0);
EXPECT_GT(slider()->value(), value);
slider()->SetValue(value);
event_generator()->PressKey(ui::VKEY_LEFT, 0);
EXPECT_LT(slider()->value(), value);
}
// Verifies the correct SliderListener events are raised for a tap gesture. // Verifies the correct SliderListener events are raised for a tap gesture.
TEST_F(HorizontalSliderTest, SliderListenerEventsForTapGesture) { TEST_F(HorizontalSliderTest, SliderListenerEventsForTapGesture) {
test::SliderTestApi slider_test_api(slider()); test::SliderTestApi slider_test_api(slider());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment