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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 | 172 |
173 float Slider::GetAnimatingValue() const{ | 173 float Slider::GetAnimatingValue() const{ |
174 return move_animation_.get() && move_animation_->is_animating() | 174 return move_animation_.get() && move_animation_->is_animating() |
175 ? animating_value_ | 175 ? animating_value_ |
176 : value_; | 176 : value_; |
177 } | 177 } |
178 | 178 |
179 bool Slider::OnMousePressed(const ui::MouseEvent& event) { | 179 bool Slider::OnMousePressed(const ui::MouseEvent& event) { |
180 if (!event.IsOnlyLeftMouseButton()) | 180 if (!event.IsOnlyLeftMouseButton()) |
181 return false; | 181 return false; |
182 SetFocus(true); | |
bruthig
2016/09/21 00:27:46
Instead of calling SetFocus() from OnMousePressed(
yiyix
2016/09/21 15:20:52
good call!!
| |
182 OnSliderDragStarted(); | 183 OnSliderDragStarted(); |
183 PrepareForMove(event.location().x()); | 184 PrepareForMove(event.location().x()); |
184 MoveButtonTo(event.location()); | 185 MoveButtonTo(event.location()); |
185 return true; | 186 return true; |
186 } | 187 } |
187 | 188 |
188 bool Slider::OnMouseDragged(const ui::MouseEvent& event) { | 189 bool Slider::OnMouseDragged(const ui::MouseEvent& event) { |
189 MoveButtonTo(event.location()); | 190 MoveButtonTo(event.location()); |
190 return true; | 191 return true; |
191 } | 192 } |
192 | 193 |
193 void Slider::OnMouseReleased(const ui::MouseEvent& event) { | 194 void Slider::OnMouseReleased(const ui::MouseEvent& event) { |
195 SetFocus(false); | |
194 OnSliderDragEnded(); | 196 OnSliderDragEnded(); |
195 } | 197 } |
196 | 198 |
197 bool Slider::OnKeyPressed(const ui::KeyEvent& event) { | 199 bool Slider::OnKeyPressed(const ui::KeyEvent& event) { |
198 float new_value = value_; | 200 float new_value = value_; |
199 if (event.key_code() == ui::VKEY_LEFT) | 201 if (event.key_code() == ui::VKEY_LEFT) |
200 new_value -= keyboard_increment_; | 202 new_value -= keyboard_increment_; |
201 else if (event.key_code() == ui::VKEY_RIGHT) | 203 else if (event.key_code() == ui::VKEY_RIGHT) |
202 new_value += keyboard_increment_; | 204 new_value += keyboard_increment_; |
203 else | 205 else |
204 return false; | 206 return false; |
205 SetValueInternal(new_value, VALUE_CHANGED_BY_USER); | 207 SetValueInternal(new_value, VALUE_CHANGED_BY_USER); |
206 return true; | 208 return true; |
207 } | 209 } |
208 | 210 |
209 void Slider::OnFocus() { | 211 void Slider::OnFocus() { |
210 View::OnFocus(); | 212 View::OnFocus(); |
213 SetFocus(true); | |
211 SchedulePaint(); | 214 SchedulePaint(); |
212 } | 215 } |
213 | 216 |
214 void Slider::OnBlur() { | 217 void Slider::OnBlur() { |
215 View::OnBlur(); | 218 View::OnBlur(); |
219 SetFocus(false); | |
216 SchedulePaint(); | 220 SchedulePaint(); |
217 } | 221 } |
218 | 222 |
219 void Slider::OnGestureEvent(ui::GestureEvent* event) { | 223 void Slider::OnGestureEvent(ui::GestureEvent* event) { |
220 switch (event->type()) { | 224 switch (event->type()) { |
221 // In a multi point gesture only the touch point will generate | 225 // In a multi point gesture only the touch point will generate |
222 // an ET_GESTURE_TAP_DOWN event. | 226 // an ET_GESTURE_TAP_DOWN event. |
223 case ui::ET_GESTURE_TAP_DOWN: | 227 case ui::ET_GESTURE_TAP_DOWN: |
224 OnSliderDragStarted(); | 228 OnSliderDragStarted(); |
225 PrepareForMove(event->location().x()); | 229 PrepareForMove(event->location().x()); |
226 // Intentional fall through to next case. | 230 // Intentional fall through to next case. |
227 case ui::ET_GESTURE_SCROLL_BEGIN: | 231 case ui::ET_GESTURE_SCROLL_BEGIN: |
228 case ui::ET_GESTURE_SCROLL_UPDATE: | 232 case ui::ET_GESTURE_SCROLL_UPDATE: |
233 SetFocus(true); | |
229 MoveButtonTo(event->location()); | 234 MoveButtonTo(event->location()); |
230 event->SetHandled(); | 235 event->SetHandled(); |
231 break; | 236 break; |
232 case ui::ET_GESTURE_END: | 237 case ui::ET_GESTURE_END: |
238 SetFocus(false); | |
233 MoveButtonTo(event->location()); | 239 MoveButtonTo(event->location()); |
234 event->SetHandled(); | 240 event->SetHandled(); |
235 if (event->details().touch_points() <= 1) | 241 if (event->details().touch_points() <= 1) |
236 OnSliderDragEnded(); | 242 OnSliderDragEnded(); |
237 break; | 243 break; |
238 default: | 244 default: |
239 break; | 245 break; |
240 } | 246 } |
241 } | 247 } |
242 | 248 |
243 void Slider::AnimationProgressed(const gfx::Animation* animation) { | 249 void Slider::AnimationProgressed(const gfx::Animation* animation) { |
244 animating_value_ = animation->CurrentValueBetween(animating_value_, value_); | 250 animating_value_ = animation->CurrentValueBetween(animating_value_, value_); |
bruthig
2016/09/21 00:27:46
This should only update |animating_value_| if |ani
yiyix
2016/09/21 15:20:52
Done.
| |
245 SchedulePaint(); | 251 SchedulePaint(); |
246 } | 252 } |
247 | 253 |
248 void Slider::GetAccessibleState(ui::AXViewState* state) { | 254 void Slider::GetAccessibleState(ui::AXViewState* state) { |
249 state->role = ui::AX_ROLE_SLIDER; | 255 state->role = ui::AX_ROLE_SLIDER; |
250 state->name = accessible_name_; | 256 state->name = accessible_name_; |
251 state->value = base::UTF8ToUTF16( | 257 state->value = base::UTF8ToUTF16( |
252 base::StringPrintf("%d%%", static_cast<int>(value_ * 100 + 0.5))); | 258 base::StringPrintf("%d%%", static_cast<int>(value_ * 100 + 0.5))); |
253 } | 259 } |
254 | 260 |
255 void Slider::OnSliderDragStarted() { | 261 void Slider::OnSliderDragStarted() { |
256 if (listener_) | 262 if (listener_) |
257 listener_->SliderDragStarted(this); | 263 listener_->SliderDragStarted(this); |
258 } | 264 } |
259 | 265 |
260 void Slider::OnSliderDragEnded() { | 266 void Slider::OnSliderDragEnded() { |
261 if (listener_) | 267 if (listener_) |
262 listener_->SliderDragEnded(this); | 268 listener_->SliderDragEnded(this); |
263 } | 269 } |
264 | 270 |
265 } // namespace views | 271 } // namespace views |
OLD | NEW |