Chromium Code Reviews| 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 "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" | 9 #include "base/stringprintf.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "third_party/skia/include/core/SkCanvas.h" | 11 #include "third_party/skia/include/core/SkCanvas.h" |
| 12 #include "third_party/skia/include/core/SkColor.h" | 12 #include "third_party/skia/include/core/SkColor.h" |
| 13 #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" | 14 #include "ui/base/accessibility/accessible_view_state.h" |
| 15 #include "ui/base/animation/slide_animation.h" | 15 #include "ui/base/animation/slide_animation.h" |
| 16 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
| 17 #include "ui/gfx/point.h" | 17 #include "ui/gfx/point.h" |
| 18 #include "ui/gfx/rect.h" | 18 #include "ui/gfx/rect.h" |
| 19 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
| 20 #include "ui/base/accelerators/accelerator.h" | |
|
sadrul
2012/03/26 22:24:02
sort
rjkroege
2012/04/03 19:24:21
Done.
| |
| 21 | |
| 22 #include <stdio.h> | |
| 20 | 23 |
| 21 namespace { | 24 namespace { |
| 22 const int kSlideValueChangeDurationMS = 150; | 25 const int kSlideValueChangeDurationMS = 150; |
| 23 } | 26 } |
| 24 | 27 |
| 25 namespace views { | 28 namespace views { |
| 26 | 29 |
| 27 Slider::Slider(SliderListener* listener, Orientation orientation) | 30 Slider::Slider(SliderListener* listener, Orientation orientation) |
| 28 : listener_(listener), | 31 : listener_(listener), |
| 29 orientation_(orientation), | 32 orientation_(orientation), |
| 30 value_(0.f), | 33 value_(0.f), |
| 31 animating_value_(0.f), | 34 animating_value_(0.f), |
| 32 value_is_valid_(false) { | 35 value_is_valid_(false) { |
|
sadrul
2012/03/26 22:24:02
Initialize esc_was_pressed_
rjkroege
2012/04/03 19:24:21
Done.
| |
| 33 EnableCanvasFlippingForRTLUI(true); | 36 EnableCanvasFlippingForRTLUI(true); |
| 34 } | 37 } |
| 35 | 38 |
| 36 Slider::~Slider() { | 39 Slider::~Slider() { |
| 37 } | 40 } |
| 38 | 41 |
| 39 void Slider::SetValue(float value) { | 42 void Slider::SetValue(float value) { |
| 40 SetValueInternal(value, VALUE_CHANGED_BY_API); | 43 SetValueInternal(value, VALUE_CHANGED_BY_API); |
| 41 } | 44 } |
| 42 | 45 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 | 133 |
| 131 SkPaint paint; | 134 SkPaint paint; |
| 132 paint.setStyle(SkPaint::kFill_Style); | 135 paint.setStyle(SkPaint::kFill_Style); |
| 133 paint.setAntiAlias(true); | 136 paint.setAntiAlias(true); |
| 134 paint.setColor(kButtonColor); | 137 paint.setColor(kButtonColor); |
| 135 canvas->sk_canvas()->drawCircle(button_cx, button_cy, kButtonRadius, paint); | 138 canvas->sk_canvas()->drawCircle(button_cx, button_cy, kButtonRadius, paint); |
| 136 View::OnPaint(canvas); | 139 View::OnPaint(canvas); |
| 137 } | 140 } |
| 138 | 141 |
| 139 bool Slider::OnMousePressed(const views::MouseEvent& event) { | 142 bool Slider::OnMousePressed(const views::MouseEvent& event) { |
| 143 original_value_ = value_; | |
| 144 ui::Accelerator escape_accelerator(ui::VKEY_ESCAPE, false, false, false); | |
| 145 AddAccelerator(escape_accelerator); | |
| 140 return OnMouseDragged(event); | 146 return OnMouseDragged(event); |
| 141 } | 147 } |
| 142 | 148 |
| 149 void Slider::OnMouseReleased(const views::MouseEvent& event) { | |
| 150 esc_was_pressed_ = false; | |
| 151 ResetAccelerators(); | |
| 152 } | |
| 153 | |
| 143 bool Slider::OnMouseDragged(const views::MouseEvent& event) { | 154 bool Slider::OnMouseDragged(const views::MouseEvent& event) { |
| 155 if (esc_was_pressed_) | |
| 156 return true; | |
| 144 gfx::Insets inset = GetInsets(); | 157 gfx::Insets inset = GetInsets(); |
| 145 if (orientation_ == HORIZONTAL) { | 158 if (orientation_ == HORIZONTAL) { |
| 146 int amount = base::i18n::IsRTL() ? width() - inset.left() - event.x() : | 159 int amount = base::i18n::IsRTL() ? width() - inset.left() - event.x() : |
| 147 event.x() - inset.left(); | 160 event.x() - inset.left(); |
| 148 SetValueInternal(static_cast<float>(amount) / (width() - inset.width()), | 161 SetValueInternal(static_cast<float>(amount) / (width() - inset.width()), |
| 149 VALUE_CHANGED_BY_USER); | 162 VALUE_CHANGED_BY_USER); |
| 150 } else { | 163 } else { |
| 151 SetValueInternal(1.0f - static_cast<float>(event.y()) / height(), | 164 SetValueInternal(1.0f - static_cast<float>(event.y()) / height(), |
| 152 VALUE_CHANGED_BY_USER); | 165 VALUE_CHANGED_BY_USER); |
| 153 } | 166 } |
| 154 return true; | 167 return true; |
| 155 } | 168 } |
| 156 | 169 |
| 157 void Slider::AnimationProgressed(const ui::Animation* animation) { | 170 void Slider::AnimationProgressed(const ui::Animation* animation) { |
| 158 animating_value_ = animation->CurrentValueBetween(animating_value_, value_); | 171 animating_value_ = animation->CurrentValueBetween(animating_value_, value_); |
| 159 SchedulePaint(); | 172 SchedulePaint(); |
| 160 } | 173 } |
| 161 | 174 |
| 162 void Slider::GetAccessibleState(ui::AccessibleViewState* state) { | 175 void Slider::GetAccessibleState(ui::AccessibleViewState* state) { |
| 163 state->role = ui::AccessibilityTypes::ROLE_SLIDER; | 176 state->role = ui::AccessibilityTypes::ROLE_SLIDER; |
| 164 state->name = accessible_name_; | 177 state->name = accessible_name_; |
| 165 state->value = UTF8ToUTF16( | 178 state->value = UTF8ToUTF16( |
| 166 base::StringPrintf("%d%%", (int)(value_ * 100 + 0.5))); | 179 base::StringPrintf("%d%%", (int)(value_ * 100 + 0.5))); |
| 167 } | 180 } |
| 168 | 181 |
| 182 bool Slider::AcceleratorPressed(const ui::Accelerator& accelerator) { | |
| 183 SetValueInternal(original_value_, VALUE_CHANGED_BY_USER); | |
| 184 esc_was_pressed_ = true; | |
| 185 return true; | |
| 186 } | |
| 187 | |
| 169 } // namespace views | 188 } // namespace views |
| OLD | NEW |