| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 { | 74 { |
| 75 return (m_animationCurve || m_runState == RunState::WaitingToSendToComposito
r) | 75 return (m_animationCurve || m_runState == RunState::WaitingToSendToComposito
r) |
| 76 ? m_targetOffset : currentPosition(); | 76 ? m_targetOffset : currentPosition(); |
| 77 } | 77 } |
| 78 | 78 |
| 79 bool ScrollAnimator::hasRunningAnimation() const | 79 bool ScrollAnimator::hasRunningAnimation() const |
| 80 { | 80 { |
| 81 return (m_animationCurve || m_runState == RunState::WaitingToSendToComposito
r); | 81 return (m_animationCurve || m_runState == RunState::WaitingToSendToComposito
r); |
| 82 } | 82 } |
| 83 | 83 |
| 84 float ScrollAnimator::computeDeltaToConsume( | 84 FloatSize ScrollAnimator::computeDeltaToConsume(const FloatSize& delta) const |
| 85 ScrollbarOrientation orientation, float pixelDelta) const | |
| 86 { | 85 { |
| 87 FloatPoint pos = desiredTargetPosition(); | 86 FloatPoint pos = desiredTargetPosition(); |
| 88 float currentPos = (orientation == HorizontalScrollbar) ? pos.x() : pos.y(); | 87 FloatPoint newPos = toFloatPoint(m_scrollableArea->clampScrollPosition(pos +
delta)); |
| 89 float newPos = clampScrollPosition(orientation, currentPos + pixelDelta); | 88 return newPos - pos; |
| 90 return (currentPos == newPos) ? 0.0f : (newPos - currentPos); | |
| 91 } | 89 } |
| 92 | 90 |
| 93 void ScrollAnimator::resetAnimationState() | 91 void ScrollAnimator::resetAnimationState() |
| 94 { | 92 { |
| 95 ScrollAnimatorCompositorCoordinator::resetAnimationState(); | 93 ScrollAnimatorCompositorCoordinator::resetAnimationState(); |
| 96 if (m_animationCurve) | 94 if (m_animationCurve) |
| 97 m_animationCurve.clear(); | 95 m_animationCurve.clear(); |
| 98 m_startTime = 0.0; | 96 m_startTime = 0.0; |
| 99 } | 97 } |
| 100 | 98 |
| 101 ScrollResultOneDimensional ScrollAnimator::userScroll( | 99 ScrollResult ScrollAnimator::userScroll( |
| 102 ScrollbarOrientation orientation, ScrollGranularity granularity, float delta
) | 100 ScrollGranularity granularity, const FloatSize& delta) |
| 103 { | 101 { |
| 104 if (!m_scrollableArea->scrollAnimatorEnabled()) | 102 if (!m_scrollableArea->scrollAnimatorEnabled()) |
| 105 return ScrollAnimatorBase::userScroll(orientation, granularity, delta); | 103 return ScrollAnimatorBase::userScroll(granularity, delta); |
| 106 | 104 |
| 107 TRACE_EVENT0("blink", "ScrollAnimator::scroll"); | 105 TRACE_EVENT0("blink", "ScrollAnimator::scroll"); |
| 108 | 106 |
| 109 if (granularity == ScrollByPrecisePixel) { | 107 if (granularity == ScrollByPrecisePixel) { |
| 110 // Cancel scroll animation because asked to instant scroll. | 108 // Cancel scroll animation because asked to instant scroll. |
| 111 if (hasRunningAnimation()) | 109 if (hasRunningAnimation()) |
| 112 cancelAnimation(); | 110 cancelAnimation(); |
| 113 return ScrollAnimatorBase::userScroll(orientation, granularity, delta); | 111 return ScrollAnimatorBase::userScroll(granularity, delta); |
| 114 } | 112 } |
| 115 | 113 |
| 116 float usedDelta = computeDeltaToConsume(orientation, delta); | 114 FloatSize usedDelta = computeDeltaToConsume(delta); |
| 117 FloatPoint pixelDelta = (orientation == VerticalScrollbar | |
| 118 ? FloatPoint(0, usedDelta) : FloatPoint(usedDelta, 0)); | |
| 119 | 115 |
| 120 FloatPoint targetPos = desiredTargetPosition(); | 116 FloatPoint targetPos = desiredTargetPosition(); |
| 121 targetPos.moveBy(pixelDelta); | 117 targetPos.move(usedDelta); |
| 122 | 118 |
| 123 if (m_runState == RunState::PostAnimationCleanup) | 119 if (m_runState == RunState::PostAnimationCleanup) |
| 124 resetAnimationState(); | 120 resetAnimationState(); |
| 125 | 121 |
| 126 if (m_animationCurve && m_runState != RunState::WaitingToCancelOnCompositor)
{ | 122 if (m_animationCurve && m_runState != RunState::WaitingToCancelOnCompositor)
{ |
| 127 if ((targetPos - m_targetOffset).isZero()) { | 123 if ((targetPos - m_targetOffset).isZero()) { |
| 128 // Report unused delta only if there is no animation running. See | 124 // Report unused delta only if there is no animation running. See |
| 129 // comment below regarding scroll latching. | 125 // comment below regarding scroll latching. |
| 130 return ScrollResultOneDimensional(/* didScroll */ true, /* unusedScr
ollDelta */ 0); | 126 // TODO(bokan): Need to standardize and document semantics of |
| 127 // scroll results on animated scrolls. ScrollAnimator currently |
| 128 // differs from ScrollAnimatorMac. |
| 129 return ScrollResult(true, true, 0, 0); |
| 131 } | 130 } |
| 132 | 131 |
| 133 m_targetOffset = targetPos; | 132 m_targetOffset = targetPos; |
| 134 ASSERT(m_runState == RunState::RunningOnMainThread | 133 ASSERT(m_runState == RunState::RunningOnMainThread |
| 135 || m_runState == RunState::RunningOnCompositor | 134 || m_runState == RunState::RunningOnCompositor |
| 136 || m_runState == RunState::RunningOnCompositorButNeedsUpdate); | 135 || m_runState == RunState::RunningOnCompositorButNeedsUpdate); |
| 137 | 136 |
| 138 if (m_runState == RunState::RunningOnCompositor | 137 if (m_runState == RunState::RunningOnCompositor |
| 139 || m_runState == RunState::RunningOnCompositorButNeedsUpdate) { | 138 || m_runState == RunState::RunningOnCompositorButNeedsUpdate) { |
| 140 if (registerAndScheduleAnimation()) | 139 if (registerAndScheduleAnimation()) |
| 141 m_runState = RunState::RunningOnCompositorButNeedsUpdate; | 140 m_runState = RunState::RunningOnCompositorButNeedsUpdate; |
| 142 return ScrollResultOneDimensional(/* didScroll */ true, /* unusedScr
ollDelta */ 0); | 141 return ScrollResult(true, true, 0, 0); |
| 143 } | 142 } |
| 144 | 143 |
| 145 // Running on the main thread, simply update the target offset instead | 144 // Running on the main thread, simply update the target offset instead |
| 146 // of sending to the compositor. | 145 // of sending to the compositor. |
| 147 m_animationCurve->updateTarget(m_timeFunction() - m_startTime, targetPos
); | 146 m_animationCurve->updateTarget(m_timeFunction() - m_startTime, targetPos
); |
| 148 return ScrollResultOneDimensional(/* didScroll */ true, /* unusedScrollD
elta */ 0); | 147 return ScrollResult(true, true, 0, 0); |
| 149 } | 148 } |
| 150 | 149 |
| 151 if ((targetPos - currentPosition()).isZero()) { | 150 if ((targetPos - currentPosition()).isZero()) { |
| 152 // Report unused delta only if there is no animation and we are not | 151 // Report unused delta only if there is no animation and we are not |
| 153 // starting one. This ensures we latch for the duration of the | 152 // starting one. This ensures we latch for the duration of the |
| 154 // animation rather than animating multiple scrollers at the same time. | 153 // animation rather than animating multiple scrollers at the same time. |
| 155 return ScrollResultOneDimensional(/* didScroll */ false, delta); | 154 return ScrollResult(false, false, delta.width(), delta.height()); |
| 156 } | 155 } |
| 157 | 156 |
| 158 m_targetOffset = targetPos; | 157 m_targetOffset = targetPos; |
| 159 m_startTime = m_timeFunction(); | 158 m_startTime = m_timeFunction(); |
| 160 m_lastGranularity = granularity; | 159 m_lastGranularity = granularity; |
| 161 | 160 |
| 162 if (registerAndScheduleAnimation()) | 161 if (registerAndScheduleAnimation()) |
| 163 m_runState = RunState::WaitingToSendToCompositor; | 162 m_runState = RunState::WaitingToSendToCompositor; |
| 164 | 163 |
| 165 return ScrollResultOneDimensional(/* didScroll */ true, /* unusedScrollDelta
*/ 0); | 164 return ScrollResult(true, true, 0, 0); |
| 166 } | 165 } |
| 167 | 166 |
| 168 void ScrollAnimator::scrollToOffsetWithoutAnimation(const FloatPoint& offset) | 167 void ScrollAnimator::scrollToOffsetWithoutAnimation(const FloatPoint& offset) |
| 169 { | 168 { |
| 170 m_currentPosX = offset.x(); | 169 m_currentPos = offset; |
| 171 m_currentPosY = offset.y(); | |
| 172 | 170 |
| 173 resetAnimationState(); | 171 resetAnimationState(); |
| 174 notifyPositionChanged(); | 172 notifyPositionChanged(); |
| 175 } | 173 } |
| 176 | 174 |
| 177 void ScrollAnimator::tickAnimation(double monotonicTime) | 175 void ScrollAnimator::tickAnimation(double monotonicTime) |
| 178 { | 176 { |
| 179 if (m_runState != RunState::RunningOnMainThread) | 177 if (m_runState != RunState::RunningOnMainThread) |
| 180 return; | 178 return; |
| 181 | 179 |
| 182 TRACE_EVENT0("blink", "ScrollAnimator::tickAnimation"); | 180 TRACE_EVENT0("blink", "ScrollAnimator::tickAnimation"); |
| 183 double elapsedTime = monotonicTime - m_startTime; | 181 double elapsedTime = monotonicTime - m_startTime; |
| 184 | 182 |
| 185 bool isFinished = (elapsedTime > m_animationCurve->duration()); | 183 bool isFinished = (elapsedTime > m_animationCurve->duration()); |
| 186 FloatPoint offset = isFinished ? m_animationCurve->targetValue() | 184 FloatPoint offset = isFinished ? m_animationCurve->targetValue() |
| 187 : m_animationCurve->getValue(elapsedTime); | 185 : m_animationCurve->getValue(elapsedTime); |
| 188 | 186 |
| 189 offset = FloatPoint(m_scrollableArea->clampScrollPosition(offset)); | 187 offset = FloatPoint(m_scrollableArea->clampScrollPosition(offset)); |
| 190 | 188 |
| 191 m_currentPosX = offset.x(); | 189 m_currentPos = offset; |
| 192 m_currentPosY = offset.y(); | |
| 193 | 190 |
| 194 if (isFinished) | 191 if (isFinished) |
| 195 m_runState = RunState::PostAnimationCleanup; | 192 m_runState = RunState::PostAnimationCleanup; |
| 196 else | 193 else |
| 197 scrollableArea()->scheduleAnimation(); | 194 scrollableArea()->scheduleAnimation(); |
| 198 | 195 |
| 199 TRACE_EVENT0("blink", "ScrollAnimator::notifyPositionChanged"); | 196 TRACE_EVENT0("blink", "ScrollAnimator::notifyPositionChanged"); |
| 200 notifyPositionChanged(); | 197 notifyPositionChanged(); |
| 201 } | 198 } |
| 202 | 199 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 } | 347 } |
| 351 return true; | 348 return true; |
| 352 } | 349 } |
| 353 | 350 |
| 354 DEFINE_TRACE(ScrollAnimator) | 351 DEFINE_TRACE(ScrollAnimator) |
| 355 { | 352 { |
| 356 ScrollAnimatorBase::trace(visitor); | 353 ScrollAnimatorBase::trace(visitor); |
| 357 } | 354 } |
| 358 | 355 |
| 359 } // namespace blink | 356 } // namespace blink |
| OLD | NEW |