Chromium Code Reviews| Index: Source/platform/mac/ScrollAnimatorMac.mm |
| diff --git a/Source/platform/mac/ScrollAnimatorMac.mm b/Source/platform/mac/ScrollAnimatorMac.mm |
| index 3c06aac6d4e3475e67238207d8f5c09ae0132280..a8c14addbc0c2153cda0b93776ed9f428646b5e9 100644 |
| --- a/Source/platform/mac/ScrollAnimatorMac.mm |
| +++ b/Source/platform/mac/ScrollAnimatorMac.mm |
| @@ -29,6 +29,8 @@ |
| #include "platform/PlatformGestureEvent.h" |
| #include "platform/PlatformWheelEvent.h" |
| +#include "platform/Timer.h" |
| +#include "platform/animation/TimingFunction.h" |
| #include "platform/geometry/FloatRect.h" |
| #include "platform/geometry/IntRect.h" |
| #include "platform/mac/BlockExceptions.h" |
| @@ -292,9 +294,76 @@ enum FeatureToAnimate { |
| ExpansionTransition |
| }; |
| -@interface WebScrollbarPartAnimation : NSAnimation |
| -{ |
| +@class WebScrollbarPartAnimation; |
| + |
| +namespace blink { |
| + |
| +// This class is used to drive the animation timer for WebScrollbarPartAnimation |
| +// objects. This is used instead of NSAnimation because CoreAnimation |
| +// establishes connections to the WindowServer, which should not be done in a |
| +// sandboxed renderer process. |
| +class WebScrollbarPartAnimationTimer { |
| +public: |
| + WebScrollbarPartAnimationTimer(WebScrollbarPartAnimation* animation, |
| + CFTimeInterval duration) |
| + : m_timer(this, &WebScrollbarPartAnimationTimer::timerFired) |
| + , m_startTime(0.0) |
| + , m_duration(duration) |
| + , m_animation(animation) |
| + , m_timingFunction(CubicBezierTimingFunction::preset(CubicBezierTimingFunction::EaseInOut)) |
| + { |
| + } |
| + |
| + ~WebScrollbarPartAnimationTimer() {} |
| + |
| + void start() |
| + { |
| + 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
|
| + // Set the framerate of the animation. NSAnimation uses a default |
| + // framerate of 60 Hz. This was determined to be sufficient by |
| + // visual inspection. |
| + m_timer.startRepeating(1.0 / 35.0, FROM_HERE); |
| + } |
| + |
| + void stop() |
| + { |
| + m_timer.stop(); |
| + [m_animation setCurrentProgress:1]; |
| + } |
| + |
| + void setDuration(CFTimeInterval duration) |
| + { |
| + m_duration = duration; |
| + } |
| + |
| +private: |
| + void timerFired(Timer<WebScrollbarPartAnimationTimer>*) |
| + { |
| + CFTimeInterval currentTime = CACurrentMediaTime(); |
| + CFTimeInterval delta = currentTime - m_startTime; |
| + |
| + if (delta >= m_duration) { |
| + stop(); |
| + return; |
| + } |
| + |
| + double fraction = delta / m_duration; |
| + double progress = m_timingFunction->evaluate(fraction, 0.001); |
| + [m_animation setCurrentProgress:progress]; |
| + } |
| + |
| + Timer<WebScrollbarPartAnimationTimer> m_timer; |
| + CFTimeInterval m_startTime; |
| + CFTimeInterval m_duration; |
| + 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.
|
| + 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,
|
| +}; |
| + |
| +} // namespace blink |
| + |
| +@interface WebScrollbarPartAnimation : NSObject { |
| Scrollbar* _scrollbar; |
| + OwnPtr<WebScrollbarPartAnimationTimer> _timer; |
| RetainPtr<ScrollbarPainter> _scrollbarPainter; |
| FeatureToAnimate _featureToAnimate; |
| CGFloat _startValue; |
| @@ -307,17 +376,16 @@ enum FeatureToAnimate { |
| - (id)initWithScrollbar:(Scrollbar*)scrollbar featureToAnimate:(FeatureToAnimate)featureToAnimate animateFrom:(CGFloat)startValue animateTo:(CGFloat)endValue duration:(NSTimeInterval)duration |
| { |
| - self = [super initWithDuration:duration animationCurve:NSAnimationEaseInOut]; |
| + self = [super init]; |
| if (!self) |
| return nil; |
| + _timer = adoptPtr(new WebScrollbarPartAnimationTimer(self, duration)); |
| _scrollbar = scrollbar; |
| _featureToAnimate = featureToAnimate; |
| _startValue = startValue; |
| _endValue = endValue; |
| - [self setAnimationBlockingMode:NSAnimationNonblocking]; |
| - |
| return self; |
| } |
| @@ -326,8 +394,17 @@ enum FeatureToAnimate { |
| ASSERT(_scrollbar); |
| _scrollbarPainter = scrollbarPainterForScrollbar(_scrollbar); |
| + _timer->start(); |
| +} |
| - [super startAnimation]; |
| +- (void)stopAnimation |
| +{ |
| + _timer->stop(); |
| +} |
| + |
| +- (void)setDuration:(CFTimeInterval)duration |
| +{ |
| + _timer->setDuration(duration); |
| } |
| - (void)setStartValue:(CGFloat)startValue |
| @@ -342,8 +419,6 @@ enum FeatureToAnimate { |
| - (void)setCurrentProgress:(NSAnimationProgress)progress |
| { |
| - [super setCurrentProgress:progress]; |
| - |
| ASSERT(_scrollbar); |
| CGFloat currentValue; |