| 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 #include "platform/scroll/ProgrammaticScrollAnimator.h" | 5 #include "platform/scroll/ProgrammaticScrollAnimator.h" |
| 6 | 6 |
| 7 #include "platform/animation/CompositorAnimation.h" |
| 8 #include "platform/animation/CompositorScrollOffsetAnimationCurve.h" |
| 7 #include "platform/geometry/IntPoint.h" | 9 #include "platform/geometry/IntPoint.h" |
| 10 #include "platform/graphics/CompositorFactory.h" |
| 8 #include "platform/graphics/GraphicsLayer.h" | 11 #include "platform/graphics/GraphicsLayer.h" |
| 9 #include "platform/scroll/ScrollableArea.h" | 12 #include "platform/scroll/ScrollableArea.h" |
| 10 #include "public/platform/Platform.h" | 13 #include "public/platform/Platform.h" |
| 11 #include "public/platform/WebCompositorAnimation.h" | |
| 12 #include "public/platform/WebCompositorSupport.h" | 14 #include "public/platform/WebCompositorSupport.h" |
| 13 #include "public/platform/WebScrollOffsetAnimationCurve.h" | |
| 14 | 15 |
| 15 namespace blink { | 16 namespace blink { |
| 16 | 17 |
| 17 PassOwnPtrWillBeRawPtr<ProgrammaticScrollAnimator> ProgrammaticScrollAnimator::c
reate(ScrollableArea* scrollableArea) | 18 PassOwnPtrWillBeRawPtr<ProgrammaticScrollAnimator> ProgrammaticScrollAnimator::c
reate(ScrollableArea* scrollableArea) |
| 18 { | 19 { |
| 19 return adoptPtrWillBeNoop(new ProgrammaticScrollAnimator(scrollableArea)); | 20 return adoptPtrWillBeNoop(new ProgrammaticScrollAnimator(scrollableArea)); |
| 20 } | 21 } |
| 21 | 22 |
| 22 ProgrammaticScrollAnimator::ProgrammaticScrollAnimator(ScrollableArea* scrollabl
eArea) | 23 ProgrammaticScrollAnimator::ProgrammaticScrollAnimator(ScrollableArea* scrollabl
eArea) |
| 23 : m_scrollableArea(scrollableArea) | 24 : m_scrollableArea(scrollableArea) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 44 void ProgrammaticScrollAnimator::scrollToOffsetWithoutAnimation(const FloatPoint
& offset) | 45 void ProgrammaticScrollAnimator::scrollToOffsetWithoutAnimation(const FloatPoint
& offset) |
| 45 { | 46 { |
| 46 cancelAnimation(); | 47 cancelAnimation(); |
| 47 notifyPositionChanged(offset); | 48 notifyPositionChanged(offset); |
| 48 } | 49 } |
| 49 | 50 |
| 50 void ProgrammaticScrollAnimator::animateToOffset(FloatPoint offset) | 51 void ProgrammaticScrollAnimator::animateToOffset(FloatPoint offset) |
| 51 { | 52 { |
| 52 m_startTime = 0.0; | 53 m_startTime = 0.0; |
| 53 m_targetOffset = offset; | 54 m_targetOffset = offset; |
| 54 m_animationCurve = adoptPtr(Platform::current()->compositorSupport()->create
ScrollOffsetAnimationCurve( | 55 m_animationCurve = adoptPtr(CompositorFactory::current().createScrollOffsetA
nimationCurve( |
| 55 m_targetOffset, | 56 m_targetOffset, |
| 56 WebCompositorAnimationCurve::TimingFunctionTypeEaseInOut, | 57 CompositorAnimationCurve::TimingFunctionTypeEaseInOut, |
| 57 WebScrollOffsetAnimationCurve::ScrollDurationDeltaBased)); | 58 CompositorScrollOffsetAnimationCurve::ScrollDurationDeltaBased)); |
| 58 | 59 |
| 59 m_scrollableArea->registerForAnimation(); | 60 m_scrollableArea->registerForAnimation(); |
| 60 if (!m_scrollableArea->scheduleAnimation()) { | 61 if (!m_scrollableArea->scheduleAnimation()) { |
| 61 resetAnimationState(); | 62 resetAnimationState(); |
| 62 notifyPositionChanged(IntPoint(offset.x(), offset.y())); | 63 notifyPositionChanged(IntPoint(offset.x(), offset.y())); |
| 63 } | 64 } |
| 64 m_runState = RunState::WaitingToSendToCompositor; | 65 m_runState = RunState::WaitingToSendToCompositor; |
| 65 } | 66 } |
| 66 | 67 |
| 67 void ProgrammaticScrollAnimator::cancelAnimation() | 68 void ProgrammaticScrollAnimator::cancelAnimation() |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 if (m_runState == RunState::WaitingToCancelOnCompositor) { | 107 if (m_runState == RunState::WaitingToCancelOnCompositor) { |
| 107 resetAnimationState(); | 108 resetAnimationState(); |
| 108 return; | 109 return; |
| 109 } | 110 } |
| 110 } | 111 } |
| 111 | 112 |
| 112 if (m_runState == RunState::WaitingToSendToCompositor) { | 113 if (m_runState == RunState::WaitingToSendToCompositor) { |
| 113 bool sentToCompositor = false; | 114 bool sentToCompositor = false; |
| 114 | 115 |
| 115 if (!m_scrollableArea->shouldScrollOnMainThread()) { | 116 if (!m_scrollableArea->shouldScrollOnMainThread()) { |
| 116 OwnPtr<WebCompositorAnimation> animation = adoptPtr(Platform::curren
t()->compositorSupport()->createAnimation(*m_animationCurve, WebCompositorAnimat
ion::TargetPropertyScrollOffset)); | 117 OwnPtr<CompositorAnimation> animation = adoptPtr(CompositorFactory::
current().createAnimation(*m_animationCurve, CompositorAnimation::TargetProperty
ScrollOffset)); |
| 117 | 118 |
| 118 int animationId = animation->id(); | 119 int animationId = animation->id(); |
| 119 int animationGroupId = animation->group(); | 120 int animationGroupId = animation->group(); |
| 120 | 121 |
| 121 if (addAnimation(animation.release())) { | 122 if (addAnimation(animation.release())) { |
| 122 sentToCompositor = true; | 123 sentToCompositor = true; |
| 123 m_runState = RunState::RunningOnCompositor; | 124 m_runState = RunState::RunningOnCompositor; |
| 124 m_compositorAnimationId = animationId; | 125 m_compositorAnimationId = animationId; |
| 125 m_compositorAnimationGroupId = animationGroupId; | 126 m_compositorAnimationGroupId = animationGroupId; |
| 126 } | 127 } |
| 127 } | 128 } |
| 128 | 129 |
| 129 if (!sentToCompositor) { | 130 if (!sentToCompositor) { |
| 130 m_runState = RunState::RunningOnMainThread; | 131 m_runState = RunState::RunningOnMainThread; |
| 131 m_animationCurve->setInitialValue(FloatPoint(m_scrollableArea->scrol
lPosition())); | 132 m_animationCurve->setInitialValue(FloatPoint(m_scrollableArea->scrol
lPosition())); |
| 132 if (!m_scrollableArea->scheduleAnimation()) { | 133 if (!m_scrollableArea->scheduleAnimation()) { |
| 133 notifyPositionChanged(IntPoint(m_targetOffset.x(), m_targetOffse
t.y())); | 134 notifyPositionChanged(IntPoint(m_targetOffset.x(), m_targetOffse
t.y())); |
| 134 resetAnimationState(); | 135 resetAnimationState(); |
| 135 } | 136 } |
| 136 } | 137 } |
| 137 } | 138 } |
| 138 } | 139 } |
| 139 | 140 |
| 140 void ProgrammaticScrollAnimator::layerForCompositedScrollingDidChange(WebComposi
torAnimationTimeline* timeline) | 141 void ProgrammaticScrollAnimator::layerForCompositedScrollingDidChange(Compositor
AnimationTimeline* timeline) |
| 141 { | 142 { |
| 142 reattachCompositorPlayerIfNeeded(timeline); | 143 reattachCompositorPlayerIfNeeded(timeline); |
| 143 | 144 |
| 144 // If the composited scrolling layer is lost during a composited animation, | 145 // If the composited scrolling layer is lost during a composited animation, |
| 145 // continue the animation on the main thread. | 146 // continue the animation on the main thread. |
| 146 if (m_runState == RunState::RunningOnCompositor && !m_scrollableArea->layerF
orScrolling()) { | 147 if (m_runState == RunState::RunningOnCompositor && !m_scrollableArea->layerF
orScrolling()) { |
| 147 m_runState = RunState::RunningOnMainThread; | 148 m_runState = RunState::RunningOnMainThread; |
| 148 m_compositorAnimationId = 0; | 149 m_compositorAnimationId = 0; |
| 149 m_compositorAnimationGroupId = 0; | 150 m_compositorAnimationGroupId = 0; |
| 150 m_animationCurve->setInitialValue(FloatPoint(m_scrollableArea->scrollPos
ition())); | 151 m_animationCurve->setInitialValue(FloatPoint(m_scrollableArea->scrollPos
ition())); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 162 ScrollAnimatorCompositorCoordinator::compositorAnimationFinished(groupId); | 163 ScrollAnimatorCompositorCoordinator::compositorAnimationFinished(groupId); |
| 163 } | 164 } |
| 164 | 165 |
| 165 DEFINE_TRACE(ProgrammaticScrollAnimator) | 166 DEFINE_TRACE(ProgrammaticScrollAnimator) |
| 166 { | 167 { |
| 167 visitor->trace(m_scrollableArea); | 168 visitor->trace(m_scrollableArea); |
| 168 ScrollAnimatorCompositorCoordinator::trace(visitor); | 169 ScrollAnimatorCompositorCoordinator::trace(visitor); |
| 169 } | 170 } |
| 170 | 171 |
| 171 } // namespace blink | 172 } // namespace blink |
| OLD | NEW |