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 26 matching lines...) Expand all Loading... |
37 #include "FloatPoint.h" | 37 #include "FloatPoint.h" |
38 #include "NotImplemented.h" | 38 #include "NotImplemented.h" |
39 #include "OwnArrayPtr.h" | 39 #include "OwnArrayPtr.h" |
40 #include "ScrollableArea.h" | 40 #include "ScrollableArea.h" |
41 #include "ScrollbarTheme.h" | 41 #include "ScrollbarTheme.h" |
42 #include "TraceEvent.h" | 42 #include "TraceEvent.h" |
43 #include <algorithm> | 43 #include <algorithm> |
44 #include <wtf/CurrentTime.h> | 44 #include <wtf/CurrentTime.h> |
45 #include <wtf/PassOwnPtr.h> | 45 #include <wtf/PassOwnPtr.h> |
46 | 46 |
| 47 using namespace std; |
| 48 |
47 namespace WebCore { | 49 namespace WebCore { |
48 | 50 |
49 static double kTickTime = .0166; | 51 static double kTickTime = .0166; |
50 | 52 |
51 // This is used to set the timer delay - it needs to be slightly smaller than th
e tick count to leave some overhead. | 53 // This is used to set the timer delay - it needs to be slightly smaller than th
e tick count to leave some overhead. |
52 static double kAnimationTimerDelay = 0.015; | 54 static double kAnimationTimerDelay = 0.015; |
53 | 55 |
54 PassOwnPtr<ScrollAnimator> ScrollAnimator::create(ScrollableArea* scrollableArea
) | 56 PassOwnPtr<ScrollAnimator> ScrollAnimator::create(ScrollableArea* scrollableArea
) |
55 { | 57 { |
56 if (scrollableArea && scrollableArea->scrollAnimatorEnabled()) | 58 if (scrollableArea && scrollableArea->scrollAnimatorEnabled()) |
57 return adoptPtr(new ScrollAnimatorNone(scrollableArea)); | 59 return adoptPtr(new ScrollAnimatorNone(scrollableArea)); |
58 return adoptPtr(new ScrollAnimator(scrollableArea)); | 60 return adoptPtr(new ScrollAnimator(scrollableArea)); |
59 } | 61 } |
60 | 62 |
61 ScrollAnimatorNone::Parameters::Parameters() | 63 ScrollAnimatorNone::Parameters::Parameters() |
62 : m_isEnabled(false) | 64 : m_isEnabled(false) |
63 { | 65 { |
64 } | 66 } |
65 | 67 |
66 ScrollAnimatorNone::Parameters::Parameters(bool isEnabled, double animationTime,
Curve attackCurve, double attackTime, Curve releaseCurve, double releaseTime) | 68 ScrollAnimatorNone::Parameters::Parameters(bool isEnabled, double animationTime,
double repeatMinimumSustainTime, Curve attackCurve, double attackTime, Curve re
leaseCurve, double releaseTime) |
67 : m_isEnabled(isEnabled) | 69 : m_isEnabled(isEnabled) |
68 , m_animationTime(animationTime) | 70 , m_animationTime(animationTime) |
| 71 , m_repeatMinimumSustainTime(repeatMinimumSustainTime) |
69 , m_attackCurve(attackCurve) | 72 , m_attackCurve(attackCurve) |
70 , m_attackTime(attackTime) | 73 , m_attackTime(attackTime) |
71 , m_releaseCurve(releaseCurve) | 74 , m_releaseCurve(releaseCurve) |
72 , m_releaseTime(releaseTime) | 75 , m_releaseTime(releaseTime) |
73 { | 76 { |
74 } | 77 } |
75 | 78 |
76 double ScrollAnimatorNone::PerAxisData::curveAt(Curve curve, double t) | 79 double ScrollAnimatorNone::PerAxisData::curveAt(Curve curve, double t) |
77 { | 80 { |
78 switch (curve) { | 81 switch (curve) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 m_attackCurve = Quadratic; | 155 m_attackCurve = Quadratic; |
153 | 156 |
154 m_releasePosition = 0; | 157 m_releasePosition = 0; |
155 m_releaseTime = 0; | 158 m_releaseTime = 0; |
156 m_releaseCurve = Quadratic; | 159 m_releaseCurve = Quadratic; |
157 } | 160 } |
158 | 161 |
159 | 162 |
160 bool ScrollAnimatorNone::PerAxisData::updateDataFromParameters(ScrollbarOrientat
ion orientation, float step, float multiplier, float scrollableSize, double curr
entTime, Parameters* parameters) | 163 bool ScrollAnimatorNone::PerAxisData::updateDataFromParameters(ScrollbarOrientat
ion orientation, float step, float multiplier, float scrollableSize, double curr
entTime, Parameters* parameters) |
161 { | 164 { |
162 m_animationTime = parameters->m_animationTime; | 165 if (parameters->m_animationTime > m_animationTime) |
| 166 m_animationTime = parameters->m_animationTime; |
163 m_attackTime = parameters->m_attackTime; | 167 m_attackTime = parameters->m_attackTime; |
164 m_releaseTime = parameters->m_releaseTime; | 168 m_releaseTime = parameters->m_releaseTime; |
165 m_attackCurve = parameters->m_attackCurve; | 169 m_attackCurve = parameters->m_attackCurve; |
166 m_releaseCurve = parameters->m_releaseCurve; | 170 m_releaseCurve = parameters->m_releaseCurve; |
167 | 171 |
168 // Prioritize our way out of over constraint. | 172 // Prioritize our way out of over constraint. |
169 if (m_attackTime + m_releaseTime > m_animationTime) { | 173 if (m_attackTime + m_releaseTime > m_animationTime) { |
170 if (m_releaseTime > m_animationTime) | 174 if (m_releaseTime > m_animationTime) |
171 m_releaseTime = m_animationTime; | 175 m_releaseTime = m_animationTime; |
172 m_attackTime = m_animationTime - m_releaseTime; | 176 m_attackTime = m_animationTime - m_releaseTime; |
173 } | 177 } |
174 | 178 |
175 m_orientation = orientation; | 179 m_orientation = orientation; |
176 | 180 |
177 if (!m_desiredPosition) | 181 if (!m_startTime) |
178 m_desiredPosition = *m_currentPosition; | 182 m_desiredPosition = *m_currentPosition; |
179 float newPosition = m_desiredPosition + (step * multiplier); | 183 float newPosition = m_desiredPosition + (step * multiplier); |
180 | 184 |
181 if (newPosition < 0 || newPosition > scrollableSize) | 185 if (newPosition < 0 || newPosition > scrollableSize) |
182 newPosition = std::max(std::min(newPosition, scrollableSize), 0.0f); | 186 newPosition = max(min(newPosition, scrollableSize), 0.0f); |
183 | 187 |
184 if (newPosition == m_desiredPosition) | 188 if (newPosition == m_desiredPosition) |
185 return false; | 189 return false; |
186 | 190 |
187 m_desiredPosition = newPosition; | 191 m_desiredPosition = newPosition; |
188 | 192 |
189 if (!m_startTime) { | 193 if (!m_startTime) { |
190 // FIXME: This should be the time from the event that got us here. | 194 // FIXME: This should be the time from the event that got us here. |
191 m_startTime = currentTime - kTickTime / 2; | 195 m_startTime = currentTime - kTickTime / 2; |
192 m_startPosition = *m_currentPosition; | 196 m_startPosition = *m_currentPosition; |
193 m_lastAnimationTime = currentTime; | 197 m_lastAnimationTime = currentTime; |
194 } | 198 } |
195 m_startVelocity = m_currentVelocity; | 199 m_startVelocity = m_currentVelocity; |
196 | 200 |
197 double remainingDelta = m_desiredPosition - *m_currentPosition; | 201 double remainingDelta = m_desiredPosition - *m_currentPosition; |
198 | 202 |
199 double attackAreaLeft = 0; | 203 double attackAreaLeft = 0; |
200 | 204 |
201 double deltaTime = m_lastAnimationTime - m_startTime; | 205 double deltaTime = m_lastAnimationTime - m_startTime; |
| 206 double attackTimeLeft = max(0., m_attackTime - deltaTime); |
202 double timeLeft = m_animationTime - deltaTime; | 207 double timeLeft = m_animationTime - deltaTime; |
203 if (timeLeft < m_releaseTime) { | 208 double minTimeLeft = m_releaseTime + min(parameters->m_repeatMinimumSustainT
ime, m_animationTime - m_releaseTime - attackTimeLeft); |
204 m_animationTime = deltaTime + m_releaseTime; | 209 if (timeLeft < minTimeLeft) { |
205 timeLeft = m_releaseTime; | 210 m_animationTime = deltaTime + minTimeLeft; |
| 211 timeLeft = minTimeLeft; |
206 } | 212 } |
207 double releaseTimeLeft = std::min(timeLeft, m_releaseTime); | 213 |
208 double attackTimeLeft = std::max(0., m_attackTime - deltaTime); | 214 double releaseTimeLeft = min(timeLeft, m_releaseTime); |
209 double sustainTimeLeft = std::max(0., timeLeft - releaseTimeLeft - attackTim
eLeft); | 215 double sustainTimeLeft = max(0., timeLeft - releaseTimeLeft - attackTimeLeft
); |
210 | 216 |
211 if (attackTimeLeft) { | 217 if (attackTimeLeft) { |
212 double attackSpot = deltaTime / m_attackTime; | 218 double attackSpot = deltaTime / m_attackTime; |
213 attackAreaLeft = attackTimeLeft / (curveDerivativeAt(m_attackCurve, 1) -
curveDerivativeAt(m_attackCurve, attackSpot)); | 219 attackAreaLeft = attackTimeLeft / (curveDerivativeAt(m_attackCurve, 1) -
curveDerivativeAt(m_attackCurve, attackSpot)); |
214 } | 220 } |
215 | 221 |
216 double releaseSpot = (m_releaseTime - releaseTimeLeft) / m_releaseTime; | 222 double releaseSpot = (m_releaseTime - releaseTimeLeft) / m_releaseTime; |
217 double releaseAreaLeft = releaseTimeLeft / (curveDerivativeAt(m_releaseCurv
e, 1) - curveDerivativeAt(m_releaseCurve, releaseSpot)); | 223 double releaseAreaLeft = releaseTimeLeft / (curveDerivativeAt(m_releaseCurv
e, 1) - curveDerivativeAt(m_releaseCurve, releaseSpot)); |
218 | 224 |
219 m_desiredVelocity = remainingDelta / (attackAreaLeft + sustainTimeLeft + rel
easeAreaLeft); | 225 m_desiredVelocity = remainingDelta / (attackAreaLeft + sustainTimeLeft + rel
easeAreaLeft); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 if (!m_scrollableArea->scrollAnimatorEnabled()) | 288 if (!m_scrollableArea->scrollAnimatorEnabled()) |
283 return ScrollAnimator::scroll(orientation, granularity, step, multiplier
); | 289 return ScrollAnimator::scroll(orientation, granularity, step, multiplier
); |
284 | 290 |
285 // FIXME: get the type passed in. MouseWheel could also be by line, but shou
ld still have different | 291 // FIXME: get the type passed in. MouseWheel could also be by line, but shou
ld still have different |
286 // animation parameters than the keyboard. | 292 // animation parameters than the keyboard. |
287 Parameters parameters; | 293 Parameters parameters; |
288 switch (granularity) { | 294 switch (granularity) { |
289 case ScrollByDocument: | 295 case ScrollByDocument: |
290 break; | 296 break; |
291 case ScrollByLine: | 297 case ScrollByLine: |
292 parameters = Parameters(true, 10 * kTickTime, Quadratic, 3 * kTickTime,
Quadratic, 3 * kTickTime); | 298 parameters = Parameters(true, 10 * kTickTime, 7 * kTickTime, Quadratic,
3 * kTickTime, Quadratic, 3 * kTickTime); |
293 break; | 299 break; |
294 case ScrollByPage: | 300 case ScrollByPage: |
295 parameters = Parameters(true, 15 * kTickTime, Quadratic, 5 * kTickTime,
Quadratic, 5 * kTickTime); | 301 parameters = Parameters(true, 15 * kTickTime, 10 * kTickTime, Quadratic,
5 * kTickTime, Quadratic, 5 * kTickTime); |
296 break; | 302 break; |
297 case ScrollByPixel: | 303 case ScrollByPixel: |
298 parameters = Parameters(true, 11 * kTickTime, Quadratic, 3 * kTickTime,
Quadratic, 3 * kTickTime); | 304 parameters = Parameters(true, 11 * kTickTime, 2 * kTickTime, Quadratic,
3 * kTickTime, Quadratic, 3 * kTickTime); |
299 break; | 305 break; |
300 default: | 306 default: |
301 break; | 307 break; |
302 } | 308 } |
303 | 309 |
304 // If the individual input setting is disabled, bail. | 310 // If the individual input setting is disabled, bail. |
305 if (!parameters.m_isEnabled) | 311 if (!parameters.m_isEnabled) |
306 return ScrollAnimator::scroll(orientation, granularity, step, multiplier
); | 312 return ScrollAnimator::scroll(orientation, granularity, step, multiplier
); |
307 | 313 |
308 // This is an animatable scroll. Calculate the scroll delta. | 314 // This is an animatable scroll. Calculate the scroll delta. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 | 356 |
351 void ScrollAnimatorNone::stopAnimationTimerIfNeeded(PerAxisData* data) | 357 void ScrollAnimatorNone::stopAnimationTimerIfNeeded(PerAxisData* data) |
352 { | 358 { |
353 if (data->m_animationTimer.isActive()) | 359 if (data->m_animationTimer.isActive()) |
354 data->m_animationTimer.stop(); | 360 data->m_animationTimer.stop(); |
355 } | 361 } |
356 | 362 |
357 } // namespace WebCore | 363 } // namespace WebCore |
358 | 364 |
359 #endif // ENABLE(SMOOTH_SCROLLING) | 365 #endif // ENABLE(SMOOTH_SCROLLING) |
OLD | NEW |