OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2010, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2010, 2011 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 11 matching lines...) Expand all Loading... | |
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 * THE POSSIBILITY OF SUCH DAMAGE. | 23 * THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "config.h" | 26 #include "config.h" |
27 | 27 |
28 #include "platform/mac/ScrollAnimatorMac.h" | 28 #include "platform/mac/ScrollAnimatorMac.h" |
29 | 29 |
30 #include "platform/PlatformGestureEvent.h" | 30 #include "platform/PlatformGestureEvent.h" |
31 #include "platform/PlatformWheelEvent.h" | 31 #include "platform/PlatformWheelEvent.h" |
32 #include "platform/Timer.h" | |
33 #include "platform/animation/TimingFunction.h" | |
32 #include "platform/geometry/FloatRect.h" | 34 #include "platform/geometry/FloatRect.h" |
33 #include "platform/geometry/IntRect.h" | 35 #include "platform/geometry/IntRect.h" |
34 #include "platform/mac/BlockExceptions.h" | 36 #include "platform/mac/BlockExceptions.h" |
35 #include "platform/mac/NSScrollerImpDetails.h" | 37 #include "platform/mac/NSScrollerImpDetails.h" |
36 #include "platform/scroll/ScrollView.h" | 38 #include "platform/scroll/ScrollView.h" |
37 #include "platform/scroll/ScrollableArea.h" | 39 #include "platform/scroll/ScrollableArea.h" |
38 #include "platform/scroll/ScrollbarTheme.h" | 40 #include "platform/scroll/ScrollbarTheme.h" |
39 #include "platform/scroll/ScrollbarThemeMacCommon.h" | 41 #include "platform/scroll/ScrollbarThemeMacCommon.h" |
40 #include "platform/scroll/ScrollbarThemeMacOverlayAPI.h" | 42 #include "platform/scroll/ScrollbarThemeMacOverlayAPI.h" |
41 #include "wtf/MainThread.h" | 43 #include "wtf/MainThread.h" |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
285 | 287 |
286 @end | 288 @end |
287 | 289 |
288 enum FeatureToAnimate { | 290 enum FeatureToAnimate { |
289 ThumbAlpha, | 291 ThumbAlpha, |
290 TrackAlpha, | 292 TrackAlpha, |
291 UIStateTransition, | 293 UIStateTransition, |
292 ExpansionTransition | 294 ExpansionTransition |
293 }; | 295 }; |
294 | 296 |
295 @interface WebScrollbarPartAnimation : NSAnimation | 297 @class WebScrollbarPartAnimation; |
296 { | 298 |
299 class WebScrollbarPartAnimationTimer { | |
Alexei Svitkine (slow)
2014/09/03 15:39:35
Can you add a comment on the class briefly summari
Alexei Svitkine (slow)
2014/09/03 15:39:36
Nit: Not sure on Blink style, but maybe this shoul
Robert Sesek
2014/09/03 16:51:11
I codesearched and it seems mostly to be for tests
Robert Sesek
2014/09/03 16:51:11
Done.
| |
300 public: | |
301 WebScrollbarPartAnimationTimer(WebScrollbarPartAnimation* animation, | |
302 CFTimeInterval duration) | |
303 : m_timer(this, &WebScrollbarPartAnimationTimer::timerFired) | |
304 , m_startTime(0.0) | |
305 , m_duration(duration) | |
306 , m_animation(animation) | |
307 , m_timingFunction(CubicBezierTimingFunction::preset(CubicBezierTimingFu nction::EaseInOut)) | |
308 { | |
309 } | |
310 | |
311 ~WebScrollbarPartAnimationTimer() {} | |
312 | |
313 void start() | |
314 { | |
315 m_startTime = CACurrentMediaTime(); | |
316 m_timer.startRepeating(1.0 / 35.0, FROM_HERE); | |
Alexei Svitkine (slow)
2014/09/03 15:39:35
Nit: Can you add a comment about where this consta
Robert Sesek
2014/09/03 16:51:11
Done. All OS versions use a framerate of 60Hz, tho
| |
317 } | |
318 | |
319 void stop() | |
320 { | |
321 m_timer.stop(); | |
322 [m_animation setCurrentProgress:1]; | |
323 } | |
324 | |
325 void setDuration(CFTimeInterval duration) | |
326 { | |
327 m_duration = duration; | |
328 } | |
329 | |
330 private: | |
331 void timerFired(Timer<WebScrollbarPartAnimationTimer>*) | |
332 { | |
333 CFTimeInterval currentTime = CACurrentMediaTime(); | |
334 CFTimeInterval delta = currentTime - m_startTime; | |
335 | |
336 if (delta >= m_duration) { | |
337 stop(); | |
338 return; | |
339 } | |
340 | |
341 double fraction = delta / m_duration; | |
342 double progress = m_timingFunction->evaluate(fraction, 0.001); | |
343 [m_animation setCurrentProgress:progress]; | |
344 } | |
345 | |
346 Timer<WebScrollbarPartAnimationTimer> m_timer; | |
347 CFTimeInterval m_startTime; | |
348 CFTimeInterval m_duration; | |
349 WebScrollbarPartAnimation* m_animation; | |
350 CubicBezierTimingFunction* m_timingFunction; | |
351 }; | |
352 | |
353 @interface WebScrollbarPartAnimation : NSObject { | |
297 Scrollbar* _scrollbar; | 354 Scrollbar* _scrollbar; |
355 OwnPtr<WebScrollbarPartAnimationTimer> _timer; | |
298 RetainPtr<ScrollbarPainter> _scrollbarPainter; | 356 RetainPtr<ScrollbarPainter> _scrollbarPainter; |
299 FeatureToAnimate _featureToAnimate; | 357 FeatureToAnimate _featureToAnimate; |
300 CGFloat _startValue; | 358 CGFloat _startValue; |
301 CGFloat _endValue; | 359 CGFloat _endValue; |
302 } | 360 } |
303 - (id)initWithScrollbar:(Scrollbar*)scrollbar featureToAnimate:(FeatureToAnimate )featureToAnimate animateFrom:(CGFloat)startValue animateTo:(CGFloat)endValue du ration:(NSTimeInterval)duration; | 361 - (id)initWithScrollbar:(Scrollbar*)scrollbar featureToAnimate:(FeatureToAnimate )featureToAnimate animateFrom:(CGFloat)startValue animateTo:(CGFloat)endValue du ration:(NSTimeInterval)duration; |
304 @end | 362 @end |
305 | 363 |
306 @implementation WebScrollbarPartAnimation | 364 @implementation WebScrollbarPartAnimation |
307 | 365 |
308 - (id)initWithScrollbar:(Scrollbar*)scrollbar featureToAnimate:(FeatureToAnimate )featureToAnimate animateFrom:(CGFloat)startValue animateTo:(CGFloat)endValue du ration:(NSTimeInterval)duration | 366 - (id)initWithScrollbar:(Scrollbar*)scrollbar featureToAnimate:(FeatureToAnimate )featureToAnimate animateFrom:(CGFloat)startValue animateTo:(CGFloat)endValue du ration:(NSTimeInterval)duration |
309 { | 367 { |
310 self = [super initWithDuration:duration animationCurve:NSAnimationEaseInOut] ; | 368 self = [super init]; |
311 if (!self) | 369 if (!self) |
312 return nil; | 370 return nil; |
313 | 371 |
372 _timer = adoptPtr(new WebScrollbarPartAnimationTimer(self, duration)); | |
314 _scrollbar = scrollbar; | 373 _scrollbar = scrollbar; |
315 _featureToAnimate = featureToAnimate; | 374 _featureToAnimate = featureToAnimate; |
316 _startValue = startValue; | 375 _startValue = startValue; |
317 _endValue = endValue; | 376 _endValue = endValue; |
318 | 377 |
319 [self setAnimationBlockingMode:NSAnimationNonblocking]; | |
320 | |
321 return self; | 378 return self; |
322 } | 379 } |
323 | 380 |
324 - (void)startAnimation | 381 - (void)startAnimation |
325 { | 382 { |
326 ASSERT(_scrollbar); | 383 ASSERT(_scrollbar); |
327 | 384 |
328 _scrollbarPainter = scrollbarPainterForScrollbar(_scrollbar); | 385 _scrollbarPainter = scrollbarPainterForScrollbar(_scrollbar); |
386 _timer->start(); | |
387 } | |
329 | 388 |
330 [super startAnimation]; | 389 - (void)stopAnimation |
390 { | |
391 _timer->stop(); | |
392 } | |
393 | |
394 - (void)setDuration:(CFTimeInterval)duration | |
395 { | |
396 _timer->setDuration(duration); | |
331 } | 397 } |
332 | 398 |
333 - (void)setStartValue:(CGFloat)startValue | 399 - (void)setStartValue:(CGFloat)startValue |
334 { | 400 { |
335 _startValue = startValue; | 401 _startValue = startValue; |
336 } | 402 } |
337 | 403 |
338 - (void)setEndValue:(CGFloat)endValue | 404 - (void)setEndValue:(CGFloat)endValue |
339 { | 405 { |
340 _endValue = endValue; | 406 _endValue = endValue; |
341 } | 407 } |
342 | 408 |
343 - (void)setCurrentProgress:(NSAnimationProgress)progress | 409 - (void)setCurrentProgress:(NSAnimationProgress)progress |
344 { | 410 { |
345 [super setCurrentProgress:progress]; | |
346 | |
347 ASSERT(_scrollbar); | 411 ASSERT(_scrollbar); |
348 | 412 |
349 CGFloat currentValue; | 413 CGFloat currentValue; |
350 if (_startValue > _endValue) | 414 if (_startValue > _endValue) |
351 currentValue = 1 - progress; | 415 currentValue = 1 - progress; |
352 else | 416 else |
353 currentValue = progress; | 417 currentValue = progress; |
354 | 418 |
355 switch (_featureToAnimate) { | 419 switch (_featureToAnimate) { |
356 case ThumbAlpha: | 420 case ThumbAlpha: |
(...skipping 930 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1287 return; | 1351 return; |
1288 | 1352 |
1289 m_visibleScrollerThumbRect = rectInViewCoordinates; | 1353 m_visibleScrollerThumbRect = rectInViewCoordinates; |
1290 } | 1354 } |
1291 | 1355 |
1292 bool ScrollAnimatorMac::canUseCoordinatedScrollbar() { | 1356 bool ScrollAnimatorMac::canUseCoordinatedScrollbar() { |
1293 return ScrollbarThemeMacCommon::isOverlayAPIAvailable(); | 1357 return ScrollbarThemeMacCommon::isOverlayAPIAvailable(); |
1294 } | 1358 } |
1295 | 1359 |
1296 } // namespace blink | 1360 } // namespace blink |
OLD | NEW |