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

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: Fix header files 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
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 GetWidget()->NotifyAccessibilityEvent(
sadrul 2012/03/12 08:40:47 A NULL check here for GetWidget(), in case the val
dmazzoni 2012/03/12 08:44:11 Done.
70 this, ui::AccessibilityTypes::EVENT_VALUE_CHANGED, true);
71 }
72
73 void Slider::SetAccessibleName(const string16& name) {
74 accessible_name_ = name;
65 } 75 }
66 76
67 gfx::Size Slider::GetPreferredSize() { 77 gfx::Size Slider::GetPreferredSize() {
68 const int kSizeMajor = 200; 78 const int kSizeMajor = 200;
69 const int kSizeMinor = 40; 79 const int kSizeMinor = 40;
70 80
71 if (orientation_ == HORIZONTAL) 81 if (orientation_ == HORIZONTAL)
72 return gfx::Size(kSizeMajor, kSizeMinor); 82 return gfx::Size(kSizeMajor, kSizeMinor);
73 return gfx::Size(kSizeMinor, kSizeMajor); 83 return gfx::Size(kSizeMinor, kSizeMajor);
74 } 84 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 VALUE_CHANGED_BY_USER); 150 VALUE_CHANGED_BY_USER);
141 } 151 }
142 return true; 152 return true;
143 } 153 }
144 154
145 void Slider::AnimationProgressed(const ui::Animation* animation) { 155 void Slider::AnimationProgressed(const ui::Animation* animation) {
146 animating_value_ = animation->CurrentValueBetween(animating_value_, value_); 156 animating_value_ = animation->CurrentValueBetween(animating_value_, value_);
147 SchedulePaint(); 157 SchedulePaint();
148 } 158 }
149 159
160 void Slider::GetAccessibleState(ui::AccessibleViewState* state) {
161 state->role = ui::AccessibilityTypes::ROLE_SLIDER;
162 state->name = accessible_name_;
163 state->value = UTF8ToUTF16(
164 base::StringPrintf("%d%%", (int)(value_ * 100 + 0.5)));
165 }
166
150 } // namespace views 167 } // namespace views
OLDNEW
« chrome/browser/accessibility/accessibility_extension_api.cc ('K') | « ui/views/controls/slider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698