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

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

Issue 2335513002: Adding ripple effect for clicks on MD slider (Closed)
Patch Set: imporve animation Created 4 years, 2 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
« ui/views/controls/slider.h ('K') | « 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 <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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 View::OnPaint(canvas); 169 View::OnPaint(canvas);
170 OnPaintFocus(canvas); 170 OnPaintFocus(canvas);
171 } 171 }
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 void Slider::SetHighlighted(bool focus) {
180 return;
bruthig 2016/09/22 21:05:24 nit: Remove
yiyix 2016/09/23 20:35:37 Highlight needs a default implementation, so non_m
bruthig 2016/09/23 22:24:39 I was just asking you to remove the return; statem
181 }
182
179 bool Slider::OnMousePressed(const ui::MouseEvent& event) { 183 bool Slider::OnMousePressed(const ui::MouseEvent& event) {
180 if (!event.IsOnlyLeftMouseButton()) 184 if (!event.IsOnlyLeftMouseButton())
181 return false; 185 return false;
182 OnSliderDragStarted(); 186 OnSliderDragStarted();
183 PrepareForMove(event.location().x()); 187 PrepareForMove(event.location().x());
184 MoveButtonTo(event.location()); 188 MoveButtonTo(event.location());
185 return true; 189 return true;
186 } 190 }
187 191
188 bool Slider::OnMouseDragged(const ui::MouseEvent& event) { 192 bool Slider::OnMouseDragged(const ui::MouseEvent& event) {
(...skipping 11 matching lines...) Expand all
200 new_value -= keyboard_increment_; 204 new_value -= keyboard_increment_;
201 else if (event.key_code() == ui::VKEY_RIGHT) 205 else if (event.key_code() == ui::VKEY_RIGHT)
202 new_value += keyboard_increment_; 206 new_value += keyboard_increment_;
203 else 207 else
204 return false; 208 return false;
205 SetValueInternal(new_value, VALUE_CHANGED_BY_USER); 209 SetValueInternal(new_value, VALUE_CHANGED_BY_USER);
206 return true; 210 return true;
207 } 211 }
208 212
209 void Slider::OnFocus() { 213 void Slider::OnFocus() {
214 SetHighlighted(true);
210 View::OnFocus(); 215 View::OnFocus();
211 SchedulePaint(); 216 SchedulePaint();
212 } 217 }
213 218
214 void Slider::OnBlur() { 219 void Slider::OnBlur() {
220 SetHighlighted(false);
215 View::OnBlur(); 221 View::OnBlur();
216 SchedulePaint(); 222 SchedulePaint();
217 } 223 }
218 224
219 void Slider::OnGestureEvent(ui::GestureEvent* event) { 225 void Slider::OnGestureEvent(ui::GestureEvent* event) {
220 switch (event->type()) { 226 switch (event->type()) {
221 // In a multi point gesture only the touch point will generate 227 // In a multi point gesture only the touch point will generate
222 // an ET_GESTURE_TAP_DOWN event. 228 // an ET_GESTURE_TAP_DOWN event.
223 case ui::ET_GESTURE_TAP_DOWN: 229 case ui::ET_GESTURE_TAP_DOWN:
224 OnSliderDragStarted(); 230 OnSliderDragStarted();
225 PrepareForMove(event->location().x()); 231 PrepareForMove(event->location().x());
226 // Intentional fall through to next case. 232 // Intentional fall through to next case.
227 case ui::ET_GESTURE_SCROLL_BEGIN: 233 case ui::ET_GESTURE_SCROLL_BEGIN:
228 case ui::ET_GESTURE_SCROLL_UPDATE: 234 case ui::ET_GESTURE_SCROLL_UPDATE:
229 MoveButtonTo(event->location()); 235 MoveButtonTo(event->location());
230 event->SetHandled(); 236 event->SetHandled();
231 break; 237 break;
232 case ui::ET_GESTURE_END: 238 case ui::ET_GESTURE_END:
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 if (move_animation_.get() && (animation == move_animation_.get())) {
bruthig 2016/09/22 21:05:24 nit: Checking that |move_animation_| here is redun
245 SchedulePaint(); 251 float old_animating_value = animating_value_;
252 animating_value_ = animation->CurrentValueBetween(animating_value_, value_);
253 if (animating_value_ != old_animating_value)
254 SchedulePaint();
255 }
246 } 256 }
247 257
248 void Slider::GetAccessibleState(ui::AXViewState* state) { 258 void Slider::GetAccessibleState(ui::AXViewState* state) {
249 state->role = ui::AX_ROLE_SLIDER; 259 state->role = ui::AX_ROLE_SLIDER;
250 state->name = accessible_name_; 260 state->name = accessible_name_;
251 state->value = base::UTF8ToUTF16( 261 state->value = base::UTF8ToUTF16(
252 base::StringPrintf("%d%%", static_cast<int>(value_ * 100 + 0.5))); 262 base::StringPrintf("%d%%", static_cast<int>(value_ * 100 + 0.5)));
253 } 263 }
254 264
255 void Slider::OnSliderDragStarted() { 265 void Slider::OnSliderDragStarted() {
266 SetHighlighted(true);
256 if (listener_) 267 if (listener_)
257 listener_->SliderDragStarted(this); 268 listener_->SliderDragStarted(this);
258 } 269 }
259 270
260 void Slider::OnSliderDragEnded() { 271 void Slider::OnSliderDragEnded() {
272 SetHighlighted(false);
261 if (listener_) 273 if (listener_)
262 listener_->SliderDragEnded(this); 274 listener_->SliderDragEnded(this);
263 } 275 }
264 276
265 } // namespace views 277 } // namespace views
OLDNEW
« ui/views/controls/slider.h ('K') | « ui/views/controls/slider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698