| 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 "config.h" | 5 #include "config.h" |
| 6 #include "platform/scroll/ProgrammaticScrollAnimator.h" | 6 #include "platform/scroll/ProgrammaticScrollAnimator.h" |
| 7 | 7 |
| 8 #include "platform/geometry/IntPoint.h" | 8 #include "platform/geometry/IntPoint.h" |
| 9 #include "platform/graphics/GraphicsLayer.h" | 9 #include "platform/graphics/GraphicsLayer.h" |
| 10 #include "platform/scroll/ScrollableArea.h" | 10 #include "platform/scroll/ScrollableArea.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 void ProgrammaticScrollAnimator::resetAnimationState() | 36 void ProgrammaticScrollAnimator::resetAnimationState() |
| 37 { | 37 { |
| 38 m_animationCurve.clear(); | 38 m_animationCurve.clear(); |
| 39 m_startTime = 0.0; | 39 m_startTime = 0.0; |
| 40 m_runState = RunState::Idle; | 40 m_runState = RunState::Idle; |
| 41 m_compositorAnimationId = 0; | 41 m_compositorAnimationId = 0; |
| 42 m_compositorAnimationGroupId = 0; | 42 m_compositorAnimationGroupId = 0; |
| 43 } | 43 } |
| 44 | 44 |
| 45 void ProgrammaticScrollAnimator::notifyPositionChanged(const DoublePoint& offset
) |
| 46 { |
| 47 m_scrollableArea->scrollPositionChanged(offset, ProgrammaticScroll); |
| 48 } |
| 49 |
| 50 void ProgrammaticScrollAnimator::scrollToOffsetWithoutAnimation(const FloatPoint
& offset) |
| 51 { |
| 52 cancelAnimation(); |
| 53 notifyPositionChanged(offset); |
| 54 } |
| 55 |
| 45 void ProgrammaticScrollAnimator::animateToOffset(FloatPoint offset) | 56 void ProgrammaticScrollAnimator::animateToOffset(FloatPoint offset) |
| 46 { | 57 { |
| 47 m_startTime = 0.0; | 58 m_startTime = 0.0; |
| 48 m_targetOffset = offset; | 59 m_targetOffset = offset; |
| 49 m_animationCurve = adoptPtr(Platform::current()->compositorSupport()->create
ScrollOffsetAnimationCurve(m_targetOffset, WebCompositorAnimationCurve::TimingFu
nctionTypeEaseInOut)); | 60 m_animationCurve = adoptPtr(Platform::current()->compositorSupport()->create
ScrollOffsetAnimationCurve(m_targetOffset, WebCompositorAnimationCurve::TimingFu
nctionTypeEaseInOut)); |
| 50 | 61 |
| 51 m_animationCurve->setInitialValue(FloatPoint(m_scrollableArea->scrollPositio
n())); | 62 m_animationCurve->setInitialValue(FloatPoint(m_scrollableArea->scrollPositio
n())); |
| 52 m_scrollableArea->registerForAnimation(); | 63 m_scrollableArea->registerForAnimation(); |
| 53 if (!m_scrollableArea->scheduleAnimation()) { | 64 if (!m_scrollableArea->scheduleAnimation()) { |
| 54 resetAnimationState(); | 65 resetAnimationState(); |
| 55 m_scrollableArea->notifyScrollPositionChanged(IntPoint(offset.x(), offse
t.y())); | 66 notifyPositionChanged(IntPoint(offset.x(), offset.y())); |
| 56 } | 67 } |
| 57 m_runState = RunState::WaitingToSendToCompositor; | 68 m_runState = RunState::WaitingToSendToCompositor; |
| 58 } | 69 } |
| 59 | 70 |
| 60 void ProgrammaticScrollAnimator::cancelAnimation() | 71 void ProgrammaticScrollAnimator::cancelAnimation() |
| 61 { | 72 { |
| 62 switch (m_runState) { | 73 switch (m_runState) { |
| 63 case RunState::Idle: | 74 case RunState::Idle: |
| 64 case RunState::WaitingToCancelOnCompositor: | 75 case RunState::WaitingToCancelOnCompositor: |
| 65 break; | 76 break; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 85 void ProgrammaticScrollAnimator::tickAnimation(double monotonicTime) | 96 void ProgrammaticScrollAnimator::tickAnimation(double monotonicTime) |
| 86 { | 97 { |
| 87 if (m_runState != RunState::RunningOnMainThread) | 98 if (m_runState != RunState::RunningOnMainThread) |
| 88 return; | 99 return; |
| 89 | 100 |
| 90 if (!m_startTime) | 101 if (!m_startTime) |
| 91 m_startTime = monotonicTime; | 102 m_startTime = monotonicTime; |
| 92 double elapsedTime = monotonicTime - m_startTime; | 103 double elapsedTime = monotonicTime - m_startTime; |
| 93 bool isFinished = (elapsedTime > m_animationCurve->duration()); | 104 bool isFinished = (elapsedTime > m_animationCurve->duration()); |
| 94 FloatPoint offset = m_animationCurve->getValue(elapsedTime); | 105 FloatPoint offset = m_animationCurve->getValue(elapsedTime); |
| 95 m_scrollableArea->notifyScrollPositionChanged(IntPoint(offset.x(), offset.y(
))); | 106 notifyPositionChanged(IntPoint(offset.x(), offset.y())); |
| 96 | 107 |
| 97 if (isFinished) { | 108 if (isFinished) { |
| 98 resetAnimationState(); | 109 resetAnimationState(); |
| 99 } else if (!m_scrollableArea->scheduleAnimation()) { | 110 } else if (!m_scrollableArea->scheduleAnimation()) { |
| 100 m_scrollableArea->notifyScrollPositionChanged(IntPoint(m_targetOffset.x(
), m_targetOffset.y())); | 111 notifyPositionChanged(IntPoint(m_targetOffset.x(), m_targetOffset.y())); |
| 101 resetAnimationState(); | 112 resetAnimationState(); |
| 102 } | 113 } |
| 103 } | 114 } |
| 104 | 115 |
| 105 bool ProgrammaticScrollAnimator::hasAnimationThatRequiresService() const | 116 bool ProgrammaticScrollAnimator::hasAnimationThatRequiresService() const |
| 106 { | 117 { |
| 107 switch (m_runState) { | 118 switch (m_runState) { |
| 108 case RunState::Idle: | 119 case RunState::Idle: |
| 109 case RunState::RunningOnCompositor: | 120 case RunState::RunningOnCompositor: |
| 110 return false; | 121 return false; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 m_runState = RunState::RunningOnCompositor; | 160 m_runState = RunState::RunningOnCompositor; |
| 150 m_compositorAnimationId = animationId; | 161 m_compositorAnimationId = animationId; |
| 151 m_compositorAnimationGroupId = animationGroupId; | 162 m_compositorAnimationGroupId = animationGroupId; |
| 152 } | 163 } |
| 153 } | 164 } |
| 154 } | 165 } |
| 155 | 166 |
| 156 if (!sentToCompositor) { | 167 if (!sentToCompositor) { |
| 157 m_runState = RunState::RunningOnMainThread; | 168 m_runState = RunState::RunningOnMainThread; |
| 158 if (!m_scrollableArea->scheduleAnimation()) { | 169 if (!m_scrollableArea->scheduleAnimation()) { |
| 159 m_scrollableArea->notifyScrollPositionChanged(IntPoint(m_targetO
ffset.x(), m_targetOffset.y())); | 170 notifyPositionChanged(IntPoint(m_targetOffset.x(), m_targetOffse
t.y())); |
| 160 resetAnimationState(); | 171 resetAnimationState(); |
| 161 } | 172 } |
| 162 } | 173 } |
| 163 } | 174 } |
| 164 } | 175 } |
| 165 | 176 |
| 166 void ProgrammaticScrollAnimator::layerForCompositedScrollingDidChange() | 177 void ProgrammaticScrollAnimator::layerForCompositedScrollingDidChange() |
| 167 { | 178 { |
| 168 // If the composited scrolling layer is lost during a composited animation, | 179 // If the composited scrolling layer is lost during a composited animation, |
| 169 // continue the animation on the main thread. | 180 // continue the animation on the main thread. |
| 170 if (m_runState == RunState::RunningOnCompositor && !m_scrollableArea->layerF
orScrolling()) { | 181 if (m_runState == RunState::RunningOnCompositor && !m_scrollableArea->layerF
orScrolling()) { |
| 171 m_runState = RunState::RunningOnMainThread; | 182 m_runState = RunState::RunningOnMainThread; |
| 172 m_compositorAnimationId = 0; | 183 m_compositorAnimationId = 0; |
| 173 m_compositorAnimationGroupId = 0; | 184 m_compositorAnimationGroupId = 0; |
| 174 m_animationCurve->setInitialValue(FloatPoint(m_scrollableArea->scrollPos
ition())); | 185 m_animationCurve->setInitialValue(FloatPoint(m_scrollableArea->scrollPos
ition())); |
| 175 m_scrollableArea->registerForAnimation(); | 186 m_scrollableArea->registerForAnimation(); |
| 176 if (!m_scrollableArea->scheduleAnimation()) { | 187 if (!m_scrollableArea->scheduleAnimation()) { |
| 177 resetAnimationState(); | 188 resetAnimationState(); |
| 178 m_scrollableArea->notifyScrollPositionChanged(IntPoint(m_targetOffse
t.x(), m_targetOffset.y())); | 189 notifyPositionChanged(IntPoint(m_targetOffset.x(), m_targetOffset.y(
))); |
| 179 } | 190 } |
| 180 } | 191 } |
| 181 } | 192 } |
| 182 | 193 |
| 183 void ProgrammaticScrollAnimator::notifyCompositorAnimationFinished(int groupId) | 194 void ProgrammaticScrollAnimator::notifyCompositorAnimationFinished(int groupId) |
| 184 { | 195 { |
| 185 if (m_compositorAnimationGroupId != groupId) | 196 if (m_compositorAnimationGroupId != groupId) |
| 186 return; | 197 return; |
| 187 | 198 |
| 188 m_compositorAnimationId = 0; | 199 m_compositorAnimationId = 0; |
| 189 m_compositorAnimationGroupId = 0; | 200 m_compositorAnimationGroupId = 0; |
| 190 | 201 |
| 191 switch (m_runState) { | 202 switch (m_runState) { |
| 192 case RunState::Idle: | 203 case RunState::Idle: |
| 193 case RunState::RunningOnMainThread: | 204 case RunState::RunningOnMainThread: |
| 194 ASSERT_NOT_REACHED(); | 205 ASSERT_NOT_REACHED(); |
| 195 break; | 206 break; |
| 196 case RunState::WaitingToSendToCompositor: | 207 case RunState::WaitingToSendToCompositor: |
| 197 break; | 208 break; |
| 198 case RunState::RunningOnCompositor: | 209 case RunState::RunningOnCompositor: |
| 199 case RunState::WaitingToCancelOnCompositor: | 210 case RunState::WaitingToCancelOnCompositor: |
| 200 resetAnimationState(); | 211 resetAnimationState(); |
| 201 } | 212 } |
| 202 } | 213 } |
| 203 | 214 |
| 204 } // namespace blink | 215 } // namespace blink |
| OLD | NEW |