| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 { | 75 { |
| 76 return (m_animationCurve || m_runState == RunState::WaitingToSendToComposito
r) | 76 return (m_animationCurve || m_runState == RunState::WaitingToSendToComposito
r) |
| 77 ? m_targetOffset : currentPosition(); | 77 ? m_targetOffset : currentPosition(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 bool ScrollAnimator::hasRunningAnimation() const | 80 bool ScrollAnimator::hasRunningAnimation() const |
| 81 { | 81 { |
| 82 return (m_animationCurve || m_runState == RunState::WaitingToSendToComposito
r); | 82 return (m_animationCurve || m_runState == RunState::WaitingToSendToComposito
r); |
| 83 } | 83 } |
| 84 | 84 |
| 85 float ScrollAnimator::computeDeltaToConsume( | 85 FloatSize ScrollAnimator::computeDeltaToConsume(const FloatSize& delta) const |
| 86 ScrollbarOrientation orientation, float pixelDelta) const | |
| 87 { | 86 { |
| 88 FloatPoint pos = desiredTargetPosition(); | 87 FloatPoint pos = desiredTargetPosition(); |
| 89 float currentPos = (orientation == HorizontalScrollbar) ? pos.x() : pos.y(); | 88 FloatPoint newPos = toFloatPoint(m_scrollableArea->clampScrollPosition(pos +
delta)); |
| 90 float newPos = clampScrollPosition(orientation, currentPos + pixelDelta); | 89 return newPos - pos; |
| 91 return (currentPos == newPos) ? 0.0f : (newPos - currentPos); | |
| 92 } | 90 } |
| 93 | 91 |
| 94 void ScrollAnimator::resetAnimationState() | 92 void ScrollAnimator::resetAnimationState() |
| 95 { | 93 { |
| 96 ScrollAnimatorCompositorCoordinator::resetAnimationState(); | 94 ScrollAnimatorCompositorCoordinator::resetAnimationState(); |
| 97 if (m_animationCurve) | 95 if (m_animationCurve) |
| 98 m_animationCurve.clear(); | 96 m_animationCurve.clear(); |
| 99 m_startTime = 0.0; | 97 m_startTime = 0.0; |
| 100 } | 98 } |
| 101 | 99 |
| 102 ScrollResultOneDimensional ScrollAnimator::userScroll( | 100 ScrollResult ScrollAnimator::userScroll( |
| 103 ScrollbarOrientation orientation, ScrollGranularity granularity, float delta
) | 101 ScrollGranularity granularity, const FloatSize& delta) |
| 104 { | 102 { |
| 105 if (!m_scrollableArea->scrollAnimatorEnabled()) | 103 if (!m_scrollableArea->scrollAnimatorEnabled()) |
| 106 return ScrollAnimatorBase::userScroll(orientation, granularity, delta); | 104 return ScrollAnimatorBase::userScroll(granularity, delta); |
| 107 | 105 |
| 108 TRACE_EVENT0("blink", "ScrollAnimator::scroll"); | 106 TRACE_EVENT0("blink", "ScrollAnimator::scroll"); |
| 109 | 107 |
| 110 if (granularity == ScrollByPrecisePixel) { | 108 if (granularity == ScrollByPrecisePixel) { |
| 111 // Cancel scroll animation because asked to instant scroll. | 109 // Cancel scroll animation because asked to instant scroll. |
| 112 if (hasRunningAnimation()) | 110 if (hasRunningAnimation()) |
| 113 cancelAnimation(); | 111 cancelAnimation(); |
| 114 return ScrollAnimatorBase::userScroll(orientation, granularity, delta); | 112 return ScrollAnimatorBase::userScroll(granularity, delta); |
| 115 } | 113 } |
| 116 | 114 |
| 117 float usedDelta = computeDeltaToConsume(orientation, delta); | 115 FloatSize consumedDelta = computeDeltaToConsume(delta); |
| 118 FloatPoint pixelDelta = (orientation == VerticalScrollbar | |
| 119 ? FloatPoint(0, usedDelta) : FloatPoint(usedDelta, 0)); | |
| 120 | 116 |
| 121 FloatPoint targetPos = desiredTargetPosition(); | 117 FloatPoint targetPos = desiredTargetPosition(); |
| 122 targetPos.moveBy(pixelDelta); | 118 targetPos.move(consumedDelta); |
| 123 | 119 |
| 124 if (willAnimateToOffset(targetPos)) { | 120 if (willAnimateToOffset(targetPos)) { |
| 125 m_lastGranularity = granularity; | 121 m_lastGranularity = granularity; |
| 126 // Report unused delta only if there is no animation running. See | 122 // Report unused delta only if there is no animation running. See |
| 127 // comment below regarding scroll latching. | 123 // comment below regarding scroll latching. |
| 128 return ScrollResultOneDimensional(/* didScroll */ true, /* unusedScrollD
elta */ 0); | 124 // TODO(bokan): Need to standardize how ScrollAnimators report |
| 125 // unusedDelta. This differs from ScrollAnimatorMac currently. |
| 126 return ScrollResult(true, true, 0, 0); |
| 129 } | 127 } |
| 130 // 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 |
| 131 // starting one. This ensures we latch for the duration of the | 129 // starting one. This ensures we latch for the duration of the |
| 132 // animation rather than animating multiple scrollers at the same time. | 130 // animation rather than animating multiple scrollers at the same time. |
| 133 return ScrollResultOneDimensional(/* didScroll */ false, delta); | 131 return ScrollResult(false, false, delta.width(), delta.height()); |
| 134 } | 132 } |
| 135 | 133 |
| 136 bool ScrollAnimator::willAnimateToOffset(const FloatPoint& targetPos) | 134 bool ScrollAnimator::willAnimateToOffset(const FloatPoint& targetPos) |
| 137 { | 135 { |
| 138 if (m_runState == RunState::PostAnimationCleanup) | 136 if (m_runState == RunState::PostAnimationCleanup) |
| 139 resetAnimationState(); | 137 resetAnimationState(); |
| 140 | 138 |
| 141 if (m_animationCurve && m_runState != RunState::WaitingToCancelOnCompositor)
{ | 139 if (m_animationCurve && m_runState != RunState::WaitingToCancelOnCompositor)
{ |
| 142 if ((targetPos - m_targetOffset).isZero()) | 140 if ((targetPos - m_targetOffset).isZero()) |
| 143 return true; | 141 return true; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 167 m_startTime = m_timeFunction(); | 165 m_startTime = m_timeFunction(); |
| 168 | 166 |
| 169 if (registerAndScheduleAnimation()) | 167 if (registerAndScheduleAnimation()) |
| 170 m_runState = RunState::WaitingToSendToCompositor; | 168 m_runState = RunState::WaitingToSendToCompositor; |
| 171 | 169 |
| 172 return true; | 170 return true; |
| 173 } | 171 } |
| 174 | 172 |
| 175 void ScrollAnimator::scrollToOffsetWithoutAnimation(const FloatPoint& offset) | 173 void ScrollAnimator::scrollToOffsetWithoutAnimation(const FloatPoint& offset) |
| 176 { | 174 { |
| 177 m_currentPosX = offset.x(); | 175 m_currentPos = offset; |
| 178 m_currentPosY = offset.y(); | |
| 179 | 176 |
| 180 resetAnimationState(); | 177 resetAnimationState(); |
| 181 notifyPositionChanged(); | 178 notifyPositionChanged(); |
| 182 } | 179 } |
| 183 | 180 |
| 184 void ScrollAnimator::tickAnimation(double monotonicTime) | 181 void ScrollAnimator::tickAnimation(double monotonicTime) |
| 185 { | 182 { |
| 186 if (m_runState != RunState::RunningOnMainThread) | 183 if (m_runState != RunState::RunningOnMainThread) |
| 187 return; | 184 return; |
| 188 | 185 |
| 189 TRACE_EVENT0("blink", "ScrollAnimator::tickAnimation"); | 186 TRACE_EVENT0("blink", "ScrollAnimator::tickAnimation"); |
| 190 double elapsedTime = monotonicTime - m_startTime; | 187 double elapsedTime = monotonicTime - m_startTime; |
| 191 | 188 |
| 192 bool isFinished = (elapsedTime > m_animationCurve->duration()); | 189 bool isFinished = (elapsedTime > m_animationCurve->duration()); |
| 193 FloatPoint offset = isFinished ? m_animationCurve->targetValue() | 190 FloatPoint offset = isFinished ? m_animationCurve->targetValue() |
| 194 : m_animationCurve->getValue(elapsedTime); | 191 : m_animationCurve->getValue(elapsedTime); |
| 195 | 192 |
| 196 offset = FloatPoint(m_scrollableArea->clampScrollPosition(offset)); | 193 offset = FloatPoint(m_scrollableArea->clampScrollPosition(offset)); |
| 197 | 194 |
| 198 m_currentPosX = offset.x(); | 195 m_currentPos = offset; |
| 199 m_currentPosY = offset.y(); | |
| 200 | 196 |
| 201 if (isFinished) | 197 if (isFinished) |
| 202 m_runState = RunState::PostAnimationCleanup; | 198 m_runState = RunState::PostAnimationCleanup; |
| 203 else | 199 else |
| 204 scrollableArea()->scheduleAnimation(); | 200 scrollableArea()->scheduleAnimation(); |
| 205 | 201 |
| 206 TRACE_EVENT0("blink", "ScrollAnimator::notifyPositionChanged"); | 202 TRACE_EVENT0("blink", "ScrollAnimator::notifyPositionChanged"); |
| 207 notifyPositionChanged(); | 203 notifyPositionChanged(); |
| 208 } | 204 } |
| 209 | 205 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 } | 375 } |
| 380 return true; | 376 return true; |
| 381 } | 377 } |
| 382 | 378 |
| 383 DEFINE_TRACE(ScrollAnimator) | 379 DEFINE_TRACE(ScrollAnimator) |
| 384 { | 380 { |
| 385 ScrollAnimatorBase::trace(visitor); | 381 ScrollAnimatorBase::trace(visitor); |
| 386 } | 382 } |
| 387 | 383 |
| 388 } // namespace blink | 384 } // namespace blink |
| OLD | NEW |