| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef ProgrammaticScrollAnimator_h | 5 #ifndef ProgrammaticScrollAnimator_h |
| 6 #define ProgrammaticScrollAnimator_h | 6 #define ProgrammaticScrollAnimator_h |
| 7 | 7 |
| 8 #include "platform/geometry/FloatPoint.h" | 8 #include "platform/geometry/FloatPoint.h" |
| 9 #include "public/platform/WebCompositorAnimationDelegate.h" |
| 10 #include "public/platform/WebCompositorAnimationPlayerClient.h" |
| 9 #include "wtf/FastAllocBase.h" | 11 #include "wtf/FastAllocBase.h" |
| 10 #include "wtf/Noncopyable.h" | 12 #include "wtf/Noncopyable.h" |
| 11 #include "wtf/OwnPtr.h" | 13 #include "wtf/OwnPtr.h" |
| 12 #include "wtf/PassOwnPtr.h" | 14 #include "wtf/PassOwnPtr.h" |
| 13 | 15 |
| 14 namespace blink { | 16 namespace blink { |
| 15 | 17 |
| 16 class ScrollableArea; | 18 class ScrollableArea; |
| 19 class WebCompositorAnimationPlayer; |
| 20 class WebCompositorAnimationTimeline; |
| 17 class WebScrollOffsetAnimationCurve; | 21 class WebScrollOffsetAnimationCurve; |
| 18 | 22 |
| 19 // Animator for fixed-destination scrolls, such as those triggered by | 23 // Animator for fixed-destination scrolls, such as those triggered by |
| 20 // CSSOM View scroll APIs. | 24 // CSSOM View scroll APIs. |
| 21 class ProgrammaticScrollAnimator { | 25 class ProgrammaticScrollAnimator : private WebCompositorAnimationPlayerClient, W
ebCompositorAnimationDelegate { |
| 22 WTF_MAKE_NONCOPYABLE(ProgrammaticScrollAnimator); | 26 WTF_MAKE_NONCOPYABLE(ProgrammaticScrollAnimator); |
| 23 WTF_MAKE_FAST_ALLOCATED(ProgrammaticScrollAnimator); | 27 WTF_MAKE_FAST_ALLOCATED(ProgrammaticScrollAnimator); |
| 24 public: | 28 public: |
| 25 static PassOwnPtr<ProgrammaticScrollAnimator> create(ScrollableArea*); | 29 static PassOwnPtr<ProgrammaticScrollAnimator> create(ScrollableArea*); |
| 26 | 30 |
| 27 ~ProgrammaticScrollAnimator(); | 31 ~ProgrammaticScrollAnimator(); |
| 28 | 32 |
| 29 void scrollToOffsetWithoutAnimation(const FloatPoint&); | 33 void scrollToOffsetWithoutAnimation(const FloatPoint&); |
| 30 void animateToOffset(FloatPoint); | 34 void animateToOffset(FloatPoint); |
| 31 void cancelAnimation(); | 35 void cancelAnimation(); |
| 32 void tickAnimation(double monotonicTime); | 36 void tickAnimation(double monotonicTime); |
| 33 bool hasAnimationThatRequiresService() const; | 37 bool hasAnimationThatRequiresService() const; |
| 34 void updateCompositorAnimations(); | 38 void updateCompositorAnimations(); |
| 35 void layerForCompositedScrollingDidChange(); | 39 void layerForCompositedScrollingDidChange(WebCompositorAnimationTimeline*); |
| 36 void notifyCompositorAnimationFinished(int groupId); | 40 void notifyCompositorAnimationFinished(int groupId); |
| 41 // WebCompositorAnimationDelegate implementation. |
| 42 void notifyAnimationStarted(double monotonicTime, int group) override; |
| 43 void notifyAnimationFinished(double monotonicTime, int group) override; |
| 44 |
| 45 // WebCompositorAnimationPlayerClient implementation. |
| 46 WebCompositorAnimationPlayer* compositorPlayer() const override; |
| 37 | 47 |
| 38 private: | 48 private: |
| 39 explicit ProgrammaticScrollAnimator(ScrollableArea*); | 49 explicit ProgrammaticScrollAnimator(ScrollableArea*); |
| 40 | 50 |
| 41 enum class RunState { | 51 enum class RunState { |
| 42 // No animation. | 52 // No animation. |
| 43 Idle, | 53 Idle, |
| 44 | 54 |
| 45 // Waiting to send an animation to the compositor. There might also | 55 // Waiting to send an animation to the compositor. There might also |
| 46 // already be another animation running on the compositor that will need | 56 // already be another animation running on the compositor that will need |
| 47 // to be canceled first. | 57 // to be canceled first. |
| 48 WaitingToSendToCompositor, | 58 WaitingToSendToCompositor, |
| 49 | 59 |
| 50 // Running an animation on the compositor. | 60 // Running an animation on the compositor. |
| 51 RunningOnCompositor, | 61 RunningOnCompositor, |
| 52 | 62 |
| 53 // Running an animation on the main thread. | 63 // Running an animation on the main thread. |
| 54 RunningOnMainThread, | 64 RunningOnMainThread, |
| 55 | 65 |
| 56 // Waiting to cancel the animation currently running on the compositor. | 66 // Waiting to cancel the animation currently running on the compositor. |
| 57 // There is no pending animation to replace the canceled animation. | 67 // There is no pending animation to replace the canceled animation. |
| 58 WaitingToCancelOnCompositor | 68 WaitingToCancelOnCompositor |
| 59 }; | 69 }; |
| 60 | 70 |
| 61 void resetAnimationState(); | 71 void resetAnimationState(); |
| 62 void notifyPositionChanged(const DoublePoint&); | 72 void notifyPositionChanged(const DoublePoint&); |
| 73 void reattachCompositorPlayerIfNeeded(WebCompositorAnimationTimeline*); |
| 74 |
| 75 OwnPtr<WebCompositorAnimationPlayer> m_compositorPlayer; |
| 76 int m_compositorAnimationAttachedToLayerId; |
| 63 | 77 |
| 64 ScrollableArea* m_scrollableArea; | 78 ScrollableArea* m_scrollableArea; |
| 65 OwnPtr<WebScrollOffsetAnimationCurve> m_animationCurve; | 79 OwnPtr<WebScrollOffsetAnimationCurve> m_animationCurve; |
| 66 FloatPoint m_targetOffset; | 80 FloatPoint m_targetOffset; |
| 67 double m_startTime; | 81 double m_startTime; |
| 68 RunState m_runState; | 82 RunState m_runState; |
| 69 int m_compositorAnimationId; | 83 int m_compositorAnimationId; |
| 70 int m_compositorAnimationGroupId; | 84 int m_compositorAnimationGroupId; |
| 71 }; | 85 }; |
| 72 | 86 |
| 73 } // namespace blink | 87 } // namespace blink |
| 74 | 88 |
| 75 #endif // ProgrammaticScrollAnimator_h | 89 #endif // ProgrammaticScrollAnimator_h |
| OLD | NEW |