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

Side by Side Diff: Source/platform/mac/ScrollAnimatorMac.mm

Issue 529103002: Do not use NSAnimation to drive scrollbar animations. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Address comments Created 6 years, 3 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
« no previous file with comments | « Source/platform/blink_platform.gyp ('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 /* 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
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
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 namespace blink {
300
301 // This class is used to drive the animation timer for WebScrollbarPartAnimation
302 // objects. This is used instead of NSAnimation because CoreAnimation
303 // establishes connections to the WindowServer, which should not be done in a
304 // sandboxed renderer process.
305 class WebScrollbarPartAnimationTimer {
306 public:
307 WebScrollbarPartAnimationTimer(WebScrollbarPartAnimation* animation,
308 CFTimeInterval duration)
309 : m_timer(this, &WebScrollbarPartAnimationTimer::timerFired)
310 , m_startTime(0.0)
311 , m_duration(duration)
312 , m_animation(animation)
313 , m_timingFunction(CubicBezierTimingFunction::preset(CubicBezierTimingFu nction::EaseInOut))
314 {
315 }
316
317 ~WebScrollbarPartAnimationTimer() {}
318
319 void start()
320 {
321 m_startTime = CACurrentMediaTime();
Ken Russell (switch to Gerrit) 2014/09/03 23:06:48 Would it be possible to use existing APIs like WTF
Robert Sesek 2014/09/03 23:25:30 Yes, though I bumped the framerate. This doesn't r
322 // Set the framerate of the animation. NSAnimation uses a default
323 // framerate of 60 Hz. This was determined to be sufficient by
324 // visual inspection.
325 m_timer.startRepeating(1.0 / 35.0, FROM_HERE);
326 }
327
328 void stop()
329 {
330 m_timer.stop();
331 [m_animation setCurrentProgress:1];
332 }
333
334 void setDuration(CFTimeInterval duration)
335 {
336 m_duration = duration;
337 }
338
339 private:
340 void timerFired(Timer<WebScrollbarPartAnimationTimer>*)
341 {
342 CFTimeInterval currentTime = CACurrentMediaTime();
343 CFTimeInterval delta = currentTime - m_startTime;
344
345 if (delta >= m_duration) {
346 stop();
347 return;
348 }
349
350 double fraction = delta / m_duration;
351 double progress = m_timingFunction->evaluate(fraction, 0.001);
352 [m_animation setCurrentProgress:progress];
353 }
354
355 Timer<WebScrollbarPartAnimationTimer> m_timer;
356 CFTimeInterval m_startTime;
357 CFTimeInterval m_duration;
358 WebScrollbarPartAnimation* m_animation;
Ken Russell (switch to Gerrit) 2014/09/03 23:06:49 Please document that this is a weak pointer.
Robert Sesek 2014/09/03 23:25:30 Done.
359 CubicBezierTimingFunction* m_timingFunction;
Ken Russell (switch to Gerrit) 2014/09/03 23:06:48 Should be RefPtr<CubicBezierTimingFunction>. (See
Robert Sesek 2014/09/03 23:25:30 Wow, thanks. I assumed that the STATIC_LOCAL thing
Ken Russell (switch to Gerrit) 2014/09/04 00:56:05 I think your code was technically correct before,
360 };
361
362 } // namespace blink
363
364 @interface WebScrollbarPartAnimation : NSObject {
297 Scrollbar* _scrollbar; 365 Scrollbar* _scrollbar;
366 OwnPtr<WebScrollbarPartAnimationTimer> _timer;
298 RetainPtr<ScrollbarPainter> _scrollbarPainter; 367 RetainPtr<ScrollbarPainter> _scrollbarPainter;
299 FeatureToAnimate _featureToAnimate; 368 FeatureToAnimate _featureToAnimate;
300 CGFloat _startValue; 369 CGFloat _startValue;
301 CGFloat _endValue; 370 CGFloat _endValue;
302 } 371 }
303 - (id)initWithScrollbar:(Scrollbar*)scrollbar featureToAnimate:(FeatureToAnimate )featureToAnimate animateFrom:(CGFloat)startValue animateTo:(CGFloat)endValue du ration:(NSTimeInterval)duration; 372 - (id)initWithScrollbar:(Scrollbar*)scrollbar featureToAnimate:(FeatureToAnimate )featureToAnimate animateFrom:(CGFloat)startValue animateTo:(CGFloat)endValue du ration:(NSTimeInterval)duration;
304 @end 373 @end
305 374
306 @implementation WebScrollbarPartAnimation 375 @implementation WebScrollbarPartAnimation
307 376
308 - (id)initWithScrollbar:(Scrollbar*)scrollbar featureToAnimate:(FeatureToAnimate )featureToAnimate animateFrom:(CGFloat)startValue animateTo:(CGFloat)endValue du ration:(NSTimeInterval)duration 377 - (id)initWithScrollbar:(Scrollbar*)scrollbar featureToAnimate:(FeatureToAnimate )featureToAnimate animateFrom:(CGFloat)startValue animateTo:(CGFloat)endValue du ration:(NSTimeInterval)duration
309 { 378 {
310 self = [super initWithDuration:duration animationCurve:NSAnimationEaseInOut] ; 379 self = [super init];
311 if (!self) 380 if (!self)
312 return nil; 381 return nil;
313 382
383 _timer = adoptPtr(new WebScrollbarPartAnimationTimer(self, duration));
314 _scrollbar = scrollbar; 384 _scrollbar = scrollbar;
315 _featureToAnimate = featureToAnimate; 385 _featureToAnimate = featureToAnimate;
316 _startValue = startValue; 386 _startValue = startValue;
317 _endValue = endValue; 387 _endValue = endValue;
318 388
319 [self setAnimationBlockingMode:NSAnimationNonblocking];
320
321 return self; 389 return self;
322 } 390 }
323 391
324 - (void)startAnimation 392 - (void)startAnimation
325 { 393 {
326 ASSERT(_scrollbar); 394 ASSERT(_scrollbar);
327 395
328 _scrollbarPainter = scrollbarPainterForScrollbar(_scrollbar); 396 _scrollbarPainter = scrollbarPainterForScrollbar(_scrollbar);
397 _timer->start();
398 }
329 399
330 [super startAnimation]; 400 - (void)stopAnimation
401 {
402 _timer->stop();
403 }
404
405 - (void)setDuration:(CFTimeInterval)duration
406 {
407 _timer->setDuration(duration);
331 } 408 }
332 409
333 - (void)setStartValue:(CGFloat)startValue 410 - (void)setStartValue:(CGFloat)startValue
334 { 411 {
335 _startValue = startValue; 412 _startValue = startValue;
336 } 413 }
337 414
338 - (void)setEndValue:(CGFloat)endValue 415 - (void)setEndValue:(CGFloat)endValue
339 { 416 {
340 _endValue = endValue; 417 _endValue = endValue;
341 } 418 }
342 419
343 - (void)setCurrentProgress:(NSAnimationProgress)progress 420 - (void)setCurrentProgress:(NSAnimationProgress)progress
344 { 421 {
345 [super setCurrentProgress:progress];
346
347 ASSERT(_scrollbar); 422 ASSERT(_scrollbar);
348 423
349 CGFloat currentValue; 424 CGFloat currentValue;
350 if (_startValue > _endValue) 425 if (_startValue > _endValue)
351 currentValue = 1 - progress; 426 currentValue = 1 - progress;
352 else 427 else
353 currentValue = progress; 428 currentValue = progress;
354 429
355 switch (_featureToAnimate) { 430 switch (_featureToAnimate) {
356 case ThumbAlpha: 431 case ThumbAlpha:
(...skipping 930 matching lines...) Expand 10 before | Expand all | Expand 10 after
1287 return; 1362 return;
1288 1363
1289 m_visibleScrollerThumbRect = rectInViewCoordinates; 1364 m_visibleScrollerThumbRect = rectInViewCoordinates;
1290 } 1365 }
1291 1366
1292 bool ScrollAnimatorMac::canUseCoordinatedScrollbar() { 1367 bool ScrollAnimatorMac::canUseCoordinatedScrollbar() {
1293 return ScrollbarThemeMacCommon::isOverlayAPIAvailable(); 1368 return ScrollbarThemeMacCommon::isOverlayAPIAvailable();
1294 } 1369 }
1295 1370
1296 } // namespace blink 1371 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/blink_platform.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698