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

Side by Side Diff: ui/views/controls/slider.cc

Issue 9665026: Make views Slider accessible on Chrome OS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Change value to stringValue Created 8 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/views/controls/slider.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/stringprintf.h"
10 #include "base/utf_string_conversions.h"
9 #include "third_party/skia/include/core/SkCanvas.h" 11 #include "third_party/skia/include/core/SkCanvas.h"
10 #include "third_party/skia/include/core/SkColor.h" 12 #include "third_party/skia/include/core/SkColor.h"
11 #include "third_party/skia/include/core/SkPaint.h" 13 #include "third_party/skia/include/core/SkPaint.h"
14 #include "ui/base/accessibility/accessible_view_state.h"
12 #include "ui/base/animation/slide_animation.h" 15 #include "ui/base/animation/slide_animation.h"
13 #include "ui/gfx/canvas.h" 16 #include "ui/gfx/canvas.h"
14 #include "ui/gfx/point.h" 17 #include "ui/gfx/point.h"
15 #include "ui/gfx/rect.h" 18 #include "ui/gfx/rect.h"
19 #include "ui/views/widget/widget.h"
16 20
17 namespace { 21 namespace {
18 const int kSlideValueChangeDurationMS = 150; 22 const int kSlideValueChangeDurationMS = 150;
19 } 23 }
20 24
21 namespace views { 25 namespace views {
22 26
23 Slider::Slider(SliderListener* listener, Orientation orientation) 27 Slider::Slider(SliderListener* listener, Orientation orientation)
24 : listener_(listener), 28 : listener_(listener),
25 orientation_(orientation), 29 orientation_(orientation),
(...skipping 29 matching lines...) Expand all
55 // Do not animate when setting the value of the slider for the first time. 59 // Do not animate when setting the value of the slider for the first time.
56 // There is no message-loop when running tests. So we cannot animate then. 60 // There is no message-loop when running tests. So we cannot animate then.
57 animating_value_ = old_value; 61 animating_value_ = old_value;
58 move_animation_.reset(new ui::SlideAnimation(this)); 62 move_animation_.reset(new ui::SlideAnimation(this));
59 move_animation_->SetSlideDuration(kSlideValueChangeDurationMS); 63 move_animation_->SetSlideDuration(kSlideValueChangeDurationMS);
60 move_animation_->Show(); 64 move_animation_->Show();
61 AnimationProgressed(move_animation_.get()); 65 AnimationProgressed(move_animation_.get());
62 } else { 66 } else {
63 SchedulePaint(); 67 SchedulePaint();
64 } 68 }
69 if (GetWidget()) {
70 GetWidget()->NotifyAccessibilityEvent(
71 this, ui::AccessibilityTypes::EVENT_VALUE_CHANGED, true);
72 }
73 }
74
75 void Slider::SetAccessibleName(const string16& name) {
76 accessible_name_ = name;
65 } 77 }
66 78
67 gfx::Size Slider::GetPreferredSize() { 79 gfx::Size Slider::GetPreferredSize() {
68 const int kSizeMajor = 200; 80 const int kSizeMajor = 200;
69 const int kSizeMinor = 40; 81 const int kSizeMinor = 40;
70 82
71 if (orientation_ == HORIZONTAL) 83 if (orientation_ == HORIZONTAL)
72 return gfx::Size(kSizeMajor, kSizeMinor); 84 return gfx::Size(kSizeMajor, kSizeMinor);
73 return gfx::Size(kSizeMinor, kSizeMajor); 85 return gfx::Size(kSizeMinor, kSizeMajor);
74 } 86 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 VALUE_CHANGED_BY_USER); 152 VALUE_CHANGED_BY_USER);
141 } 153 }
142 return true; 154 return true;
143 } 155 }
144 156
145 void Slider::AnimationProgressed(const ui::Animation* animation) { 157 void Slider::AnimationProgressed(const ui::Animation* animation) {
146 animating_value_ = animation->CurrentValueBetween(animating_value_, value_); 158 animating_value_ = animation->CurrentValueBetween(animating_value_, value_);
147 SchedulePaint(); 159 SchedulePaint();
148 } 160 }
149 161
162 void Slider::GetAccessibleState(ui::AccessibleViewState* state) {
163 state->role = ui::AccessibilityTypes::ROLE_SLIDER;
164 state->name = accessible_name_;
165 state->value = UTF8ToUTF16(
166 base::StringPrintf("%d%%", (int)(value_ * 100 + 0.5)));
167 }
168
150 } // namespace views 169 } // namespace views
OLDNEW
« 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