| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2011, Google Inc. All rights reserved. | 2 * Copyright (c) 2011, Google 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 PassOwnPtrWillBeRawPtr<ScrollAnimatorBase> ScrollAnimatorBase::create(Scrollable
Area* scrollableArea) | 44 PassOwnPtrWillBeRawPtr<ScrollAnimatorBase> ScrollAnimatorBase::create(Scrollable
Area* scrollableArea) |
| 45 { | 45 { |
| 46 if (scrollableArea && scrollableArea->scrollAnimatorEnabled()) | 46 if (scrollableArea && scrollableArea->scrollAnimatorEnabled()) |
| 47 return adoptPtrWillBeNoop(new ScrollAnimator(scrollableArea)); | 47 return adoptPtrWillBeNoop(new ScrollAnimator(scrollableArea)); |
| 48 return adoptPtrWillBeNoop(new ScrollAnimatorBase(scrollableArea)); | 48 return adoptPtrWillBeNoop(new ScrollAnimatorBase(scrollableArea)); |
| 49 } | 49 } |
| 50 | 50 |
| 51 ScrollAnimator::ScrollAnimator(ScrollableArea* scrollableArea, WTF::TimeFunction
timeFunction) | 51 ScrollAnimator::ScrollAnimator(ScrollableArea* scrollableArea, WTF::TimeFunction
timeFunction) |
| 52 : ScrollAnimatorBase(scrollableArea) | 52 : ScrollAnimatorBase(scrollableArea) |
| 53 , m_lastTickTime(0.0) | |
| 54 , m_timeFunction(timeFunction) | 53 , m_timeFunction(timeFunction) |
| 55 { | 54 { |
| 56 } | 55 } |
| 57 | 56 |
| 58 ScrollAnimator::~ScrollAnimator() | 57 ScrollAnimator::~ScrollAnimator() |
| 59 { | 58 { |
| 60 } | 59 } |
| 61 | 60 |
| 62 FloatPoint ScrollAnimator::desiredTargetPosition() const | 61 FloatPoint ScrollAnimator::desiredTargetPosition() const |
| 63 { | 62 { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 return ScrollResultOneDimensional(/* didScroll */ true, /* unusedScr
ollDelta */ 0); | 106 return ScrollResultOneDimensional(/* didScroll */ true, /* unusedScr
ollDelta */ 0); |
| 108 } | 107 } |
| 109 | 108 |
| 110 m_targetOffset = targetPos; | 109 m_targetOffset = targetPos; |
| 111 ASSERT(m_runState == RunState::RunningOnMainThread | 110 ASSERT(m_runState == RunState::RunningOnMainThread |
| 112 || m_runState == RunState::RunningOnCompositor | 111 || m_runState == RunState::RunningOnCompositor |
| 113 || m_runState == RunState::RunningOnCompositorButNeedsUpdate); | 112 || m_runState == RunState::RunningOnCompositorButNeedsUpdate); |
| 114 | 113 |
| 115 if (m_runState == RunState::RunningOnCompositor | 114 if (m_runState == RunState::RunningOnCompositor |
| 116 || m_runState == RunState::RunningOnCompositorButNeedsUpdate) { | 115 || m_runState == RunState::RunningOnCompositorButNeedsUpdate) { |
| 117 m_runState = RunState::RunningOnCompositorButNeedsUpdate; | 116 if (registerAndScheduleAnimation()) |
| 117 m_runState = RunState::RunningOnCompositorButNeedsUpdate; |
| 118 return ScrollResultOneDimensional(/* didScroll */ true, /* unusedScr
ollDelta */ 0); | 118 return ScrollResultOneDimensional(/* didScroll */ true, /* unusedScr
ollDelta */ 0); |
| 119 } | 119 } |
| 120 | 120 |
| 121 // Running on the main thread, simply update the target offset instead | 121 // Running on the main thread, simply update the target offset instead |
| 122 // of sending to the compositor. | 122 // of sending to the compositor. |
| 123 m_animationCurve->updateTarget(m_timeFunction() - m_startTime, targetPos
); | 123 m_animationCurve->updateTarget(m_timeFunction() - m_startTime, targetPos
); |
| 124 return ScrollResultOneDimensional(/* didScroll */ true, /* unusedScrollD
elta */ 0); | 124 return ScrollResultOneDimensional(/* didScroll */ true, /* unusedScrollD
elta */ 0); |
| 125 } | 125 } |
| 126 | 126 |
| 127 if ((targetPos - currentPosition()).isZero()) { | 127 if ((targetPos - currentPosition()).isZero()) { |
| 128 // Report unused delta only if there is no animation and we are not | 128 // Report unused delta only if there is no animation and we are not |
| 129 // starting one. This ensures we latch for the duration of the | 129 // starting one. This ensures we latch for the duration of the |
| 130 // animation rather than animating multiple scrollers at the same time. | 130 // animation rather than animating multiple scrollers at the same time. |
| 131 return ScrollResultOneDimensional(/* didScroll */ false, delta); | 131 return ScrollResultOneDimensional(/* didScroll */ false, delta); |
| 132 } | 132 } |
| 133 | 133 |
| 134 m_targetOffset = targetPos; | 134 m_targetOffset = targetPos; |
| 135 m_startTime = m_timeFunction(); | 135 m_startTime = m_timeFunction(); |
| 136 | 136 |
| 137 scrollableArea()->registerForAnimation(); | 137 if (registerAndScheduleAnimation()) |
| 138 if (!m_scrollableArea->scheduleAnimation()) { | 138 m_runState = RunState::WaitingToSendToCompositor; |
| 139 scrollToOffsetWithoutAnimation(targetPos); | |
| 140 resetAnimationState(); | |
| 141 return ScrollResultOneDimensional(/* didScroll */ true, /* unusedScrollD
elta */ 0); | |
| 142 } | |
| 143 | 139 |
| 144 m_runState = RunState::WaitingToSendToCompositor; | |
| 145 return ScrollResultOneDimensional(/* didScroll */ true, /* unusedScrollDelta
*/ 0); | 140 return ScrollResultOneDimensional(/* didScroll */ true, /* unusedScrollDelta
*/ 0); |
| 146 } | 141 } |
| 147 | 142 |
| 148 void ScrollAnimator::scrollToOffsetWithoutAnimation(const FloatPoint& offset) | 143 void ScrollAnimator::scrollToOffsetWithoutAnimation(const FloatPoint& offset) |
| 149 { | 144 { |
| 150 m_currentPosX = offset.x(); | 145 m_currentPosX = offset.x(); |
| 151 m_currentPosY = offset.y(); | 146 m_currentPosY = offset.y(); |
| 152 | 147 |
| 153 resetAnimationState(); | 148 resetAnimationState(); |
| 154 notifyPositionChanged(); | 149 notifyPositionChanged(); |
| 155 } | 150 } |
| 156 | 151 |
| 157 void ScrollAnimator::tickAnimation(double monotonicTime) | 152 void ScrollAnimator::tickAnimation(double monotonicTime) |
| 158 { | 153 { |
| 159 m_lastTickTime = monotonicTime; | |
| 160 | |
| 161 if (m_runState != RunState::RunningOnMainThread) | 154 if (m_runState != RunState::RunningOnMainThread) |
| 162 return; | 155 return; |
| 163 | 156 |
| 164 TRACE_EVENT0("blink", "ScrollAnimator::tickAnimation"); | 157 TRACE_EVENT0("blink", "ScrollAnimator::tickAnimation"); |
| 165 double elapsedTime = monotonicTime - m_startTime; | 158 double elapsedTime = monotonicTime - m_startTime; |
| 166 | 159 |
| 167 bool isFinished = (elapsedTime > m_animationCurve->duration()); | 160 bool isFinished = (elapsedTime > m_animationCurve->duration()); |
| 168 FloatPoint offset = isFinished ? m_animationCurve->targetValue() | 161 FloatPoint offset = isFinished ? m_animationCurve->targetValue() |
| 169 : m_animationCurve->getValue(elapsedTime); | 162 : m_animationCurve->getValue(elapsedTime); |
| 170 | 163 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 if (m_runState == RunState::WaitingToSendToCompositor | 199 if (m_runState == RunState::WaitingToSendToCompositor |
| 207 || m_runState == RunState::RunningOnCompositorButNeedsUpdate) { | 200 || m_runState == RunState::RunningOnCompositorButNeedsUpdate) { |
| 208 if (m_runState == RunState::RunningOnCompositorButNeedsUpdate) { | 201 if (m_runState == RunState::RunningOnCompositorButNeedsUpdate) { |
| 209 // Abort the running animation before a new one with an updated | 202 // Abort the running animation before a new one with an updated |
| 210 // target is added. | 203 // target is added. |
| 211 abortAnimation(); | 204 abortAnimation(); |
| 212 | 205 |
| 213 m_compositorAnimationId = 0; | 206 m_compositorAnimationId = 0; |
| 214 m_compositorAnimationGroupId = 0; | 207 m_compositorAnimationGroupId = 0; |
| 215 | 208 |
| 216 m_animationCurve->updateTarget(m_lastTickTime - m_startTime, | 209 m_animationCurve->updateTarget(m_timeFunction() - m_startTime, |
| 217 m_targetOffset); | 210 m_targetOffset); |
| 218 m_runState = RunState::WaitingToSendToCompositor; | 211 m_runState = RunState::WaitingToSendToCompositor; |
| 219 } | 212 } |
| 220 | 213 |
| 221 if (!m_animationCurve) { | 214 if (!m_animationCurve) { |
| 222 m_animationCurve = adoptPtr(Platform::current()->compositorSupport() | 215 m_animationCurve = adoptPtr(Platform::current()->compositorSupport() |
| 223 ->createScrollOffsetAnimationCurve( | 216 ->createScrollOffsetAnimationCurve( |
| 224 m_targetOffset, | 217 m_targetOffset, |
| 225 WebCompositorAnimationCurve::TimingFunctionTypeEaseInOut, | 218 WebCompositorAnimationCurve::TimingFunctionTypeEaseInOut, |
| 226 WebScrollOffsetAnimationCurve::ScrollDurationConstant)); | 219 WebScrollOffsetAnimationCurve::ScrollDurationConstant)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 249 sentToCompositor = addAnimation(animation.release()); | 242 sentToCompositor = addAnimation(animation.release()); |
| 250 if (sentToCompositor) { | 243 if (sentToCompositor) { |
| 251 m_runState = RunState::RunningOnCompositor; | 244 m_runState = RunState::RunningOnCompositor; |
| 252 m_compositorAnimationId = animationId; | 245 m_compositorAnimationId = animationId; |
| 253 m_compositorAnimationGroupId = animationGroupId; | 246 m_compositorAnimationGroupId = animationGroupId; |
| 254 } | 247 } |
| 255 } | 248 } |
| 256 } | 249 } |
| 257 | 250 |
| 258 if (!sentToCompositor) { | 251 if (!sentToCompositor) { |
| 259 m_runState = RunState::RunningOnMainThread; | 252 if (registerAndScheduleAnimation()) |
| 260 if (!m_scrollableArea->scheduleAnimation()) { | 253 m_runState = RunState::RunningOnMainThread; |
| 261 scrollToOffsetWithoutAnimation(m_targetOffset); | |
| 262 resetAnimationState(); | |
| 263 } | |
| 264 } | 254 } |
| 265 } | 255 } |
| 266 } | 256 } |
| 267 | 257 |
| 268 void ScrollAnimator::notifyCompositorAnimationFinished(int groupId) | 258 void ScrollAnimator::notifyCompositorAnimationFinished(int groupId) |
| 269 { | 259 { |
| 270 ScrollAnimatorCompositorCoordinator::compositorAnimationFinished(groupId); | 260 ScrollAnimatorCompositorCoordinator::compositorAnimationFinished(groupId); |
| 271 } | 261 } |
| 272 | 262 |
| 273 void ScrollAnimator::cancelAnimation() | 263 void ScrollAnimator::cancelAnimation() |
| 274 { | 264 { |
| 275 ScrollAnimatorCompositorCoordinator::cancelAnimation(); | 265 ScrollAnimatorCompositorCoordinator::cancelAnimation(); |
| 276 } | 266 } |
| 277 | 267 |
| 278 void ScrollAnimator::layerForCompositedScrollingDidChange( | 268 void ScrollAnimator::layerForCompositedScrollingDidChange( |
| 279 WebCompositorAnimationTimeline* timeline) | 269 WebCompositorAnimationTimeline* timeline) |
| 280 { | 270 { |
| 281 reattachCompositorPlayerIfNeeded(timeline); | 271 reattachCompositorPlayerIfNeeded(timeline); |
| 282 } | 272 } |
| 283 | 273 |
| 274 bool ScrollAnimator::registerAndScheduleAnimation() |
| 275 { |
| 276 scrollableArea()->registerForAnimation(); |
| 277 if (!m_scrollableArea->scheduleAnimation()) { |
| 278 scrollToOffsetWithoutAnimation(m_targetOffset); |
| 279 resetAnimationState(); |
| 280 return false; |
| 281 } |
| 282 return true; |
| 283 } |
| 284 |
| 284 DEFINE_TRACE(ScrollAnimator) | 285 DEFINE_TRACE(ScrollAnimator) |
| 285 { | 286 { |
| 286 ScrollAnimatorBase::trace(visitor); | 287 ScrollAnimatorBase::trace(visitor); |
| 287 } | 288 } |
| 288 | 289 |
| 289 } // namespace blink | 290 } // namespace blink |
| OLD | NEW |