| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/controls/slider.h" | 5 #include "ui/views/controls/slider.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 bool Slider::OnMouseDragged(const ui::MouseEvent& event) { | 236 bool Slider::OnMouseDragged(const ui::MouseEvent& event) { |
| 237 MoveButtonTo(event.location()); | 237 MoveButtonTo(event.location()); |
| 238 return true; | 238 return true; |
| 239 } | 239 } |
| 240 | 240 |
| 241 void Slider::OnMouseReleased(const ui::MouseEvent& event) { | 241 void Slider::OnMouseReleased(const ui::MouseEvent& event) { |
| 242 OnSliderDragEnded(); | 242 OnSliderDragEnded(); |
| 243 } | 243 } |
| 244 | 244 |
| 245 bool Slider::OnKeyPressed(const ui::KeyEvent& event) { | 245 bool Slider::OnKeyPressed(const ui::KeyEvent& event) { |
| 246 float new_value = value_; | 246 int direction = 1; |
| 247 if (event.key_code() == ui::VKEY_LEFT) | 247 switch (event.key_code()) { |
| 248 new_value -= keyboard_increment_; | 248 case ui::VKEY_LEFT: |
| 249 else if (event.key_code() == ui::VKEY_RIGHT) | 249 direction = base::i18n::IsRTL() ? 1 : -1; |
| 250 new_value += keyboard_increment_; | 250 break; |
| 251 else | 251 case ui::VKEY_RIGHT: |
| 252 return false; | 252 direction = base::i18n::IsRTL() ? -1 : 1; |
| 253 SetValueInternal(new_value, VALUE_CHANGED_BY_USER); | 253 break; |
| 254 case ui::VKEY_UP: |
| 255 direction = 1; |
| 256 break; |
| 257 case ui::VKEY_DOWN: |
| 258 direction = -1; |
| 259 break; |
| 260 |
| 261 default: |
| 262 return false; |
| 263 } |
| 264 SetValueInternal(value_ + direction * keyboard_increment_, |
| 265 VALUE_CHANGED_BY_USER); |
| 254 return true; | 266 return true; |
| 255 } | 267 } |
| 256 | 268 |
| 257 void Slider::GetAccessibleNodeData(ui::AXNodeData* node_data) { | 269 void Slider::GetAccessibleNodeData(ui::AXNodeData* node_data) { |
| 258 node_data->role = ui::AX_ROLE_SLIDER; | 270 node_data->role = ui::AX_ROLE_SLIDER; |
| 259 node_data->SetName(accessible_name_); | 271 node_data->SetName(accessible_name_); |
| 260 node_data->SetValue(base::UTF8ToUTF16( | 272 node_data->SetValue(base::UTF8ToUTF16( |
| 261 base::StringPrintf("%d%%", static_cast<int>(value_ * 100 + 0.5)))); | 273 base::StringPrintf("%d%%", static_cast<int>(value_ * 100 + 0.5)))); |
| 262 } | 274 } |
| 263 | 275 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 event->SetHandled(); | 355 event->SetHandled(); |
| 344 if (event->details().touch_points() <= 1) | 356 if (event->details().touch_points() <= 1) |
| 345 OnSliderDragEnded(); | 357 OnSliderDragEnded(); |
| 346 break; | 358 break; |
| 347 default: | 359 default: |
| 348 break; | 360 break; |
| 349 } | 361 } |
| 350 } | 362 } |
| 351 | 363 |
| 352 } // namespace views | 364 } // namespace views |
| OLD | NEW |