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 21 matching lines...) Expand all Loading... |
32 | 32 |
33 #include "platform/scroll/ScrollAnimatorNone.h" | 33 #include "platform/scroll/ScrollAnimatorNone.h" |
34 | 34 |
35 #include <algorithm> | 35 #include <algorithm> |
36 #include "platform/scroll/ScrollableArea.h" | 36 #include "platform/scroll/ScrollableArea.h" |
37 #include "wtf/CurrentTime.h" | 37 #include "wtf/CurrentTime.h" |
38 #include "wtf/PassOwnPtr.h" | 38 #include "wtf/PassOwnPtr.h" |
39 | 39 |
40 #include "platform/TraceEvent.h" | 40 #include "platform/TraceEvent.h" |
41 | 41 |
42 using namespace std; | |
43 | |
44 namespace blink { | 42 namespace blink { |
45 | 43 |
46 const double kFrameRate = 60; | 44 const double kFrameRate = 60; |
47 const double kTickTime = 1 / kFrameRate; | 45 const double kTickTime = 1 / kFrameRate; |
48 const double kMinimumTimerInterval = .001; | 46 const double kMinimumTimerInterval = .001; |
49 | 47 |
50 PassOwnPtr<ScrollAnimator> ScrollAnimator::create(ScrollableArea* scrollableArea
) | 48 PassOwnPtr<ScrollAnimator> ScrollAnimator::create(ScrollableArea* scrollableArea
) |
51 { | 49 { |
52 if (scrollableArea && scrollableArea->scrollAnimatorEnabled()) | 50 if (scrollableArea && scrollableArea->scrollAnimatorEnabled()) |
53 return adoptPtr(new ScrollAnimatorNone(scrollableArea)); | 51 return adoptPtr(new ScrollAnimatorNone(scrollableArea)); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 return t * t * t / 3; | 137 return t * t * t / 3; |
140 case Cubic: | 138 case Cubic: |
141 return t * t * t * t / 4; | 139 return t * t * t * t / 4; |
142 case Quartic: | 140 case Quartic: |
143 return t * t * t * t * t / 5; | 141 return t * t * t * t * t / 5; |
144 case Bounce: | 142 case Bounce: |
145 const double kTimeBase = 2.75; | 143 const double kTimeBase = 2.75; |
146 const double kTimeBaseSquared = kTimeBase * kTimeBase; | 144 const double kTimeBaseSquared = kTimeBase * kTimeBase; |
147 const double kTimeBaseSquaredOverThree = kTimeBaseSquared / 3; | 145 const double kTimeBaseSquaredOverThree = kTimeBaseSquared / 3; |
148 double area; | 146 double area; |
149 double t1 = min(t, 1 / kTimeBase); | 147 double t1 = std::min(t, 1 / kTimeBase); |
150 area = kTimeBaseSquaredOverThree * t1 * t1 * t1; | 148 area = kTimeBaseSquaredOverThree * t1 * t1 * t1; |
151 if (t < 1 / kTimeBase) | 149 if (t < 1 / kTimeBase) |
152 return area; | 150 return area; |
153 | 151 |
154 t1 = min(t - 1 / kTimeBase, 1 / kTimeBase); | 152 t1 = std::min(t - 1 / kTimeBase, 1 / kTimeBase); |
155 // The integral of kTimeBaseSquared * (t1 - .5 / kTimeBase) * (t1 - .5 /
kTimeBase) + kParabolaAtEdge | 153 // The integral of kTimeBaseSquared * (t1 - .5 / kTimeBase) * (t1 - .5 /
kTimeBase) + kParabolaAtEdge |
156 const double kSecondInnerOffset = kTimeBaseSquared * .5 / kTimeBase; | 154 const double kSecondInnerOffset = kTimeBaseSquared * .5 / kTimeBase; |
157 double bounceArea = t1 * (t1 * (kTimeBaseSquaredOverThree * t1 - kSecond
InnerOffset) + 1); | 155 double bounceArea = t1 * (t1 * (kTimeBaseSquaredOverThree * t1 - kSecond
InnerOffset) + 1); |
158 area += bounceArea; | 156 area += bounceArea; |
159 if (t < 2 / kTimeBase) | 157 if (t < 2 / kTimeBase) |
160 return area; | 158 return area; |
161 | 159 |
162 t1 = min(t - 2 / kTimeBase, 0.5 / kTimeBase); | 160 t1 = std::min(t - 2 / kTimeBase, 0.5 / kTimeBase); |
163 // The integral of kTimeBaseSquared * (t1 - .25 / kTimeBase) * (t1 - .25
/ kTimeBase) + kParabolaAtEdge | 161 // The integral of kTimeBaseSquared * (t1 - .25 / kTimeBase) * (t1 - .25
/ kTimeBase) + kParabolaAtEdge |
164 const double kThirdInnerOffset = kTimeBaseSquared * .25 / kTimeBase; | 162 const double kThirdInnerOffset = kTimeBaseSquared * .25 / kTimeBase; |
165 bounceArea = t1 * (t1 * (kTimeBaseSquaredOverThree * t1 - kThirdInnerOf
fset) + 1); | 163 bounceArea = t1 * (t1 * (kTimeBaseSquaredOverThree * t1 - kThirdInnerOf
fset) + 1); |
166 area += bounceArea; | 164 area += bounceArea; |
167 if (t < 2.5 / kTimeBase) | 165 if (t < 2.5 / kTimeBase) |
168 return area; | 166 return area; |
169 | 167 |
170 t1 = t - 2.5 / kTimeBase; | 168 t1 = t - 2.5 / kTimeBase; |
171 // The integral of kTimeBaseSquared * (t1 - .125 / kTimeBase) * (t1 - .1
25 / kTimeBase) + kParabolaAtEdge | 169 // The integral of kTimeBaseSquared * (t1 - .125 / kTimeBase) * (t1 - .1
25 / kTimeBase) + kParabolaAtEdge |
172 const double kFourthInnerOffset = kTimeBaseSquared * .125 / kTimeBase; | 170 const double kFourthInnerOffset = kTimeBaseSquared * .125 / kTimeBase; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 bool ScrollAnimatorNone::PerAxisData::updateDataFromParameters(float step, float
delta, float scrollableSize, double currentTime, Parameters* parameters) | 224 bool ScrollAnimatorNone::PerAxisData::updateDataFromParameters(float step, float
delta, float scrollableSize, double currentTime, Parameters* parameters) |
227 { | 225 { |
228 float pixelDelta = step * delta; | 226 float pixelDelta = step * delta; |
229 if (!m_startTime || !pixelDelta || (pixelDelta < 0) != (m_desiredPosition -
*m_currentPosition < 0)) { | 227 if (!m_startTime || !pixelDelta || (pixelDelta < 0) != (m_desiredPosition -
*m_currentPosition < 0)) { |
230 m_desiredPosition = *m_currentPosition; | 228 m_desiredPosition = *m_currentPosition; |
231 m_startTime = 0; | 229 m_startTime = 0; |
232 } | 230 } |
233 float newPosition = m_desiredPosition + pixelDelta; | 231 float newPosition = m_desiredPosition + pixelDelta; |
234 | 232 |
235 if (newPosition < 0 || newPosition > scrollableSize) | 233 if (newPosition < 0 || newPosition > scrollableSize) |
236 newPosition = max(min(newPosition, scrollableSize), 0.0f); | 234 newPosition = std::max(std::min(newPosition, scrollableSize), 0.0f); |
237 | 235 |
238 if (newPosition == m_desiredPosition) | 236 if (newPosition == m_desiredPosition) |
239 return false; | 237 return false; |
240 | 238 |
241 m_desiredPosition = newPosition; | 239 m_desiredPosition = newPosition; |
242 | 240 |
243 if (!m_startTime) { | 241 if (!m_startTime) { |
244 m_attackTime = parameters->m_attackTime; | 242 m_attackTime = parameters->m_attackTime; |
245 m_attackCurve = parameters->m_attackCurve; | 243 m_attackCurve = parameters->m_attackCurve; |
246 } | 244 } |
(...skipping 14 matching lines...) Expand all Loading... |
261 m_startPosition = *m_currentPosition; | 259 m_startPosition = *m_currentPosition; |
262 m_lastAnimationTime = m_startTime; | 260 m_lastAnimationTime = m_startTime; |
263 } | 261 } |
264 m_startVelocity = m_currentVelocity; | 262 m_startVelocity = m_currentVelocity; |
265 | 263 |
266 double remainingDelta = m_desiredPosition - *m_currentPosition; | 264 double remainingDelta = m_desiredPosition - *m_currentPosition; |
267 | 265 |
268 double attackAreaLeft = 0; | 266 double attackAreaLeft = 0; |
269 | 267 |
270 double deltaTime = m_lastAnimationTime - m_startTime; | 268 double deltaTime = m_lastAnimationTime - m_startTime; |
271 double attackTimeLeft = max(0., m_attackTime - deltaTime); | 269 double attackTimeLeft = std::max(0., m_attackTime - deltaTime); |
272 double timeLeft = m_animationTime - deltaTime; | 270 double timeLeft = m_animationTime - deltaTime; |
273 double minTimeLeft = m_releaseTime + min(parameters->m_repeatMinimumSustainT
ime, m_animationTime - m_releaseTime - attackTimeLeft); | 271 double minTimeLeft = m_releaseTime + std::min(parameters->m_repeatMinimumSus
tainTime, m_animationTime - m_releaseTime - attackTimeLeft); |
274 if (timeLeft < minTimeLeft) { | 272 if (timeLeft < minTimeLeft) { |
275 m_animationTime = deltaTime + minTimeLeft; | 273 m_animationTime = deltaTime + minTimeLeft; |
276 timeLeft = minTimeLeft; | 274 timeLeft = minTimeLeft; |
277 } | 275 } |
278 | 276 |
279 if (parameters->m_maximumCoastTime > (parameters->m_repeatMinimumSustainTime
+ parameters->m_releaseTime)) { | 277 if (parameters->m_maximumCoastTime > (parameters->m_repeatMinimumSustainTime
+ parameters->m_releaseTime)) { |
280 double targetMaxCoastVelocity = m_visibleLength * .25 * kFrameRate; | 278 double targetMaxCoastVelocity = m_visibleLength * .25 * kFrameRate; |
281 // This needs to be as minimal as possible while not being intrusive to
page up/down. | 279 // This needs to be as minimal as possible while not being intrusive to
page up/down. |
282 double minCoastDelta = m_visibleLength; | 280 double minCoastDelta = m_visibleLength; |
283 | 281 |
284 if (fabs(remainingDelta) > minCoastDelta) { | 282 if (fabs(remainingDelta) > minCoastDelta) { |
285 double maxCoastDelta = parameters->m_maximumCoastTime * targetMaxCoa
stVelocity; | 283 double maxCoastDelta = parameters->m_maximumCoastTime * targetMaxCoa
stVelocity; |
286 double coastFactor = min(1., (fabs(remainingDelta) - minCoastDelta)
/ (maxCoastDelta - minCoastDelta)); | 284 double coastFactor = std::min(1., (fabs(remainingDelta) - minCoastDe
lta) / (maxCoastDelta - minCoastDelta)); |
287 | 285 |
288 // We could play with the curve here - linear seems a little soft. I
nitial testing makes me want to feed into the sustain time more aggressively. | 286 // We could play with the curve here - linear seems a little soft. I
nitial testing makes me want to feed into the sustain time more aggressively. |
289 double coastMinTimeLeft = min(parameters->m_maximumCoastTime, minTim
eLeft + coastCurve(parameters->m_coastTimeCurve, coastFactor) * (parameters->m_m
aximumCoastTime - minTimeLeft)); | 287 double coastMinTimeLeft = std::min(parameters->m_maximumCoastTime, m
inTimeLeft + coastCurve(parameters->m_coastTimeCurve, coastFactor) * (parameters
->m_maximumCoastTime - minTimeLeft)); |
290 | 288 |
291 double additionalTime = max(0., coastMinTimeLeft - minTimeLeft); | 289 double additionalTime = std::max(0., coastMinTimeLeft - minTimeLeft)
; |
292 if (additionalTime) { | 290 if (additionalTime) { |
293 double additionalReleaseTime = min(additionalTime, parameters->m
_releaseTime / (parameters->m_releaseTime + parameters->m_repeatMinimumSustainTi
me) * additionalTime); | 291 double additionalReleaseTime = std::min(additionalTime, paramete
rs->m_releaseTime / (parameters->m_releaseTime + parameters->m_repeatMinimumSust
ainTime) * additionalTime); |
294 m_releaseTime = parameters->m_releaseTime + additionalReleaseTim
e; | 292 m_releaseTime = parameters->m_releaseTime + additionalReleaseTim
e; |
295 m_animationTime = deltaTime + coastMinTimeLeft; | 293 m_animationTime = deltaTime + coastMinTimeLeft; |
296 timeLeft = coastMinTimeLeft; | 294 timeLeft = coastMinTimeLeft; |
297 } | 295 } |
298 } | 296 } |
299 } | 297 } |
300 | 298 |
301 double releaseTimeLeft = min(timeLeft, m_releaseTime); | 299 double releaseTimeLeft = std::min(timeLeft, m_releaseTime); |
302 double sustainTimeLeft = max(0., timeLeft - releaseTimeLeft - attackTimeLeft
); | 300 double sustainTimeLeft = std::max(0., timeLeft - releaseTimeLeft - attackTim
eLeft); |
303 | 301 |
304 if (attackTimeLeft) { | 302 if (attackTimeLeft) { |
305 double attackSpot = deltaTime / m_attackTime; | 303 double attackSpot = deltaTime / m_attackTime; |
306 attackAreaLeft = attackArea(m_attackCurve, attackSpot, 1) * m_attackTime
; | 304 attackAreaLeft = attackArea(m_attackCurve, attackSpot, 1) * m_attackTime
; |
307 } | 305 } |
308 | 306 |
309 double releaseSpot = (m_releaseTime - releaseTimeLeft) / m_releaseTime; | 307 double releaseSpot = (m_releaseTime - releaseTimeLeft) / m_releaseTime; |
310 double releaseAreaLeft = releaseArea(m_releaseCurve, releaseSpot, 1) * m_re
leaseTime; | 308 double releaseAreaLeft = releaseArea(m_releaseCurve, releaseSpot, 1) * m_re
leaseTime; |
311 | 309 |
312 m_desiredVelocity = remainingDelta / (attackAreaLeft + sustainTimeLeft + rel
easeAreaLeft); | 310 m_desiredVelocity = remainingDelta / (attackAreaLeft + sustainTimeLeft + rel
easeAreaLeft); |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 return m_animationActive; | 516 return m_animationActive; |
519 } | 517 } |
520 | 518 |
521 void ScrollAnimatorNone::stopAnimationTimerIfNeeded() | 519 void ScrollAnimatorNone::stopAnimationTimerIfNeeded() |
522 { | 520 { |
523 if (animationTimerActive()) | 521 if (animationTimerActive()) |
524 m_animationActive = false; | 522 m_animationActive = false; |
525 } | 523 } |
526 | 524 |
527 } // namespace blink | 525 } // namespace blink |
OLD | NEW |