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

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 kbr@ 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 | « no previous file | 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 = WTF::currentTime();
322 // Set the framerate of the animation. NSAnimation uses a default
323 // framerate of 60 Hz, so use that here.
324 m_timer.startRepeating(1.0 / 60.0, FROM_HERE);
325 }
326
327 void stop()
328 {
329 m_timer.stop();
330 [m_animation setCurrentProgress:1];
331 }
332
333 void setDuration(CFTimeInterval duration)
334 {
335 m_duration = duration;
336 }
337
338 private:
339 void timerFired(Timer<WebScrollbarPartAnimationTimer>*)
340 {
341 double currentTime = WTF::currentTime();
342 double delta = currentTime - m_startTime;
343
344 if (delta >= m_duration) {
345 stop();
346 return;
347 }
348
349 double fraction = delta / m_duration;
350 double progress = m_timingFunction->evaluate(fraction, 0.001);
351 [m_animation setCurrentProgress:progress];
352 }
353
354 Timer<WebScrollbarPartAnimationTimer> m_timer;
355 double m_startTime; // In seconds.
356 double m_duration; // In seconds.
357 WebScrollbarPartAnimation* m_animation; // Weak, owns this.
358 RefPtr<CubicBezierTimingFunction> m_timingFunction;
359 };
360
361 } // namespace blink
362
363 @interface WebScrollbarPartAnimation : NSObject {
297 Scrollbar* _scrollbar; 364 Scrollbar* _scrollbar;
365 OwnPtr<WebScrollbarPartAnimationTimer> _timer;
298 RetainPtr<ScrollbarPainter> _scrollbarPainter; 366 RetainPtr<ScrollbarPainter> _scrollbarPainter;
299 FeatureToAnimate _featureToAnimate; 367 FeatureToAnimate _featureToAnimate;
300 CGFloat _startValue; 368 CGFloat _startValue;
301 CGFloat _endValue; 369 CGFloat _endValue;
302 } 370 }
303 - (id)initWithScrollbar:(Scrollbar*)scrollbar featureToAnimate:(FeatureToAnimate )featureToAnimate animateFrom:(CGFloat)startValue animateTo:(CGFloat)endValue du ration:(NSTimeInterval)duration; 371 - (id)initWithScrollbar:(Scrollbar*)scrollbar featureToAnimate:(FeatureToAnimate )featureToAnimate animateFrom:(CGFloat)startValue animateTo:(CGFloat)endValue du ration:(NSTimeInterval)duration;
304 @end 372 @end
305 373
306 @implementation WebScrollbarPartAnimation 374 @implementation WebScrollbarPartAnimation
307 375
308 - (id)initWithScrollbar:(Scrollbar*)scrollbar featureToAnimate:(FeatureToAnimate )featureToAnimate animateFrom:(CGFloat)startValue animateTo:(CGFloat)endValue du ration:(NSTimeInterval)duration 376 - (id)initWithScrollbar:(Scrollbar*)scrollbar featureToAnimate:(FeatureToAnimate )featureToAnimate animateFrom:(CGFloat)startValue animateTo:(CGFloat)endValue du ration:(NSTimeInterval)duration
309 { 377 {
310 self = [super initWithDuration:duration animationCurve:NSAnimationEaseInOut] ; 378 self = [super init];
311 if (!self) 379 if (!self)
312 return nil; 380 return nil;
313 381
382 _timer = adoptPtr(new WebScrollbarPartAnimationTimer(self, duration));
314 _scrollbar = scrollbar; 383 _scrollbar = scrollbar;
315 _featureToAnimate = featureToAnimate; 384 _featureToAnimate = featureToAnimate;
316 _startValue = startValue; 385 _startValue = startValue;
317 _endValue = endValue; 386 _endValue = endValue;
318 387
319 [self setAnimationBlockingMode:NSAnimationNonblocking];
320
321 return self; 388 return self;
322 } 389 }
323 390
324 - (void)startAnimation 391 - (void)startAnimation
325 { 392 {
326 ASSERT(_scrollbar); 393 ASSERT(_scrollbar);
327 394
328 _scrollbarPainter = scrollbarPainterForScrollbar(_scrollbar); 395 _scrollbarPainter = scrollbarPainterForScrollbar(_scrollbar);
396 _timer->start();
397 }
329 398
330 [super startAnimation]; 399 - (void)stopAnimation
400 {
401 _timer->stop();
402 }
403
404 - (void)setDuration:(CFTimeInterval)duration
405 {
406 _timer->setDuration(duration);
331 } 407 }
332 408
333 - (void)setStartValue:(CGFloat)startValue 409 - (void)setStartValue:(CGFloat)startValue
334 { 410 {
335 _startValue = startValue; 411 _startValue = startValue;
336 } 412 }
337 413
338 - (void)setEndValue:(CGFloat)endValue 414 - (void)setEndValue:(CGFloat)endValue
339 { 415 {
340 _endValue = endValue; 416 _endValue = endValue;
341 } 417 }
342 418
343 - (void)setCurrentProgress:(NSAnimationProgress)progress 419 - (void)setCurrentProgress:(NSAnimationProgress)progress
344 { 420 {
345 [super setCurrentProgress:progress];
346
347 ASSERT(_scrollbar); 421 ASSERT(_scrollbar);
348 422
349 CGFloat currentValue; 423 CGFloat currentValue;
350 if (_startValue > _endValue) 424 if (_startValue > _endValue)
351 currentValue = 1 - progress; 425 currentValue = 1 - progress;
352 else 426 else
353 currentValue = progress; 427 currentValue = progress;
354 428
355 switch (_featureToAnimate) { 429 switch (_featureToAnimate) {
356 case ThumbAlpha: 430 case ThumbAlpha:
(...skipping 930 matching lines...) Expand 10 before | Expand all | Expand 10 after
1287 return; 1361 return;
1288 1362
1289 m_visibleScrollerThumbRect = rectInViewCoordinates; 1363 m_visibleScrollerThumbRect = rectInViewCoordinates;
1290 } 1364 }
1291 1365
1292 bool ScrollAnimatorMac::canUseCoordinatedScrollbar() { 1366 bool ScrollAnimatorMac::canUseCoordinatedScrollbar() {
1293 return ScrollbarThemeMacCommon::isOverlayAPIAvailable(); 1367 return ScrollbarThemeMacCommon::isOverlayAPIAvailable();
1294 } 1368 }
1295 1369
1296 } // namespace blink 1370 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698