Title: [104842] trunk/Source/WebCore
- Revision
- 104842
- Author
- [email protected]
- Date
- 2012-01-12 12:04:31 -0800 (Thu, 12 Jan 2012)
Log Message
Move snapRubberBandTimerFired to ScrollElasticityController
https://bugs.webkit.org/show_bug.cgi?id=76196
Reviewed by Andreas Kling.
* platform/mac/ScrollAnimatorMac.mm:
(WebCore::ScrollAnimatorMac::snapRubberBandTimerFired):
* platform/mac/ScrollElasticityController.h:
* platform/mac/ScrollElasticityController.mm:
(WebCore::elasticDeltaForTimeDelta):
(WebCore::roundTowardZero):
(WebCore::roundToDevicePixelTowardZero):
(WebCore::ScrollElasticityController::snapRubberBandTimerFired):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (104841 => 104842)
--- trunk/Source/WebCore/ChangeLog 2012-01-12 19:55:31 UTC (rev 104841)
+++ trunk/Source/WebCore/ChangeLog 2012-01-12 20:04:31 UTC (rev 104842)
@@ -1,3 +1,19 @@
+2012-01-12 Anders Carlsson <[email protected]>
+
+ Move snapRubberBandTimerFired to ScrollElasticityController
+ https://bugs.webkit.org/show_bug.cgi?id=76196
+
+ Reviewed by Andreas Kling.
+
+ * platform/mac/ScrollAnimatorMac.mm:
+ (WebCore::ScrollAnimatorMac::snapRubberBandTimerFired):
+ * platform/mac/ScrollElasticityController.h:
+ * platform/mac/ScrollElasticityController.mm:
+ (WebCore::elasticDeltaForTimeDelta):
+ (WebCore::roundTowardZero):
+ (WebCore::roundToDevicePixelTowardZero):
+ (WebCore::ScrollElasticityController::snapRubberBandTimerFired):
+
2012-01-12 Joshua Bell <[email protected]>
IndexedDB: Raise NON_TRANSIENT_ERR when invalid mode specified for transaction
Modified: trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.mm (104841 => 104842)
--- trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.mm 2012-01-12 19:55:31 UTC (rev 104841)
+++ trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.mm 2012-01-12 20:04:31 UTC (rev 104842)
@@ -917,26 +917,12 @@
static const float rubberbandAmplitude = 0.31f;
static const float rubberbandPeriod = 1.6f;
-static float elasticDeltaForTimeDelta(float initialPosition, float initialVelocity, float elapsedTime)
-{
- float amplitude = rubberbandAmplitude;
- float period = rubberbandPeriod;
- float criticalDampeningFactor = expf((-elapsedTime * rubberbandStiffness) / period);
-
- return (initialPosition + (-initialVelocity * elapsedTime * amplitude)) * criticalDampeningFactor;
-}
-
static float elasticDeltaForReboundDelta(float delta)
{
float stiffness = std::max(rubberbandStiffness, 1.0f);
return delta / stiffness;
}
-static float reboundDeltaForElasticDelta(float delta)
-{
- return delta * rubberbandStiffness;
-}
-
static float scrollWheelMultiplier()
{
static float multiplier = -1;
@@ -1332,83 +1318,9 @@
m_scrollElasticityController.m_snapRubberbandTimerIsActive = true;
}
-static inline float roundTowardZero(float num)
-{
- return num > 0 ? ceilf(num - 0.5f) : floorf(num + 0.5f);
-}
-
-static inline float roundToDevicePixelTowardZero(float num)
-{
- float roundedNum = roundf(num);
- if (fabs(num - roundedNum) < 0.125)
- num = roundedNum;
-
- return roundTowardZero(num);
-}
-
void ScrollAnimatorMac::snapRubberBandTimerFired(Timer<ScrollAnimatorMac>*)
{
- if (!m_scrollElasticityController.m_momentumScrollInProgress || m_scrollElasticityController.m_ignoreMomentumScrolls) {
- CFTimeInterval timeDelta = [NSDate timeIntervalSinceReferenceDate] - m_scrollElasticityController.m_startTime;
-
- if (m_scrollElasticityController.m_startStretch == FloatSize()) {
- m_scrollElasticityController.m_startStretch = m_scrollElasticityController.m_client->stretchAmount();
- if (m_scrollElasticityController.m_startStretch == FloatSize()) {
- m_scrollElasticityController.m_client->stopSnapRubberbandTimer();
-
- m_scrollElasticityController.m_stretchScrollForce = FloatSize();
- m_scrollElasticityController.m_startTime = 0;
- m_scrollElasticityController.m_startStretch = FloatSize();
- m_scrollElasticityController.m_origOrigin = FloatPoint();
- m_scrollElasticityController.m_origVelocity = FloatSize();
- m_scrollElasticityController.m_snapRubberbandTimerIsActive = false;
-
- return;
- }
-
- m_scrollElasticityController.m_origOrigin = m_scrollElasticityController.m_client->absoluteScrollPosition() - m_scrollElasticityController.m_startStretch;
- m_scrollElasticityController.m_origVelocity = m_scrollElasticityController.m_momentumVelocity;
-
- // Just like normal scrolling, prefer vertical rubberbanding
- if (fabsf(m_scrollElasticityController.m_origVelocity.height()) >= fabsf(m_scrollElasticityController.m_origVelocity.width()))
- m_scrollElasticityController.m_origVelocity.setWidth(0);
-
- // Don't rubber-band horizontally if it's not possible to scroll horizontally
- if (!m_scrollElasticityController.m_client->canScrollHorizontally())
- m_scrollElasticityController.m_origVelocity.setWidth(0);
-
- // Don't rubber-band vertically if it's not possible to scroll vertically
- if (!m_scrollElasticityController.m_client->canScrollVertically())
- m_scrollElasticityController.m_origVelocity.setHeight(0);
- }
-
- FloatPoint delta(roundToDevicePixelTowardZero(elasticDeltaForTimeDelta(m_scrollElasticityController.m_startStretch.width(), -m_scrollElasticityController.m_origVelocity.width(), (float)timeDelta)),
- roundToDevicePixelTowardZero(elasticDeltaForTimeDelta(m_scrollElasticityController.m_startStretch.height(), -m_scrollElasticityController.m_origVelocity.height(), (float)timeDelta)));
-
- if (fabs(delta.x()) >= 1 || fabs(delta.y()) >= 1) {
- FloatPoint newOrigin = m_scrollElasticityController.m_origOrigin + delta;
-
- m_scrollElasticityController.m_client->immediateScrollByWithoutContentEdgeConstraints(FloatSize(delta.x(), delta.y()) - m_scrollElasticityController.m_client->stretchAmount());
-
- FloatSize newStretch = m_scrollElasticityController.m_client->stretchAmount();
-
- m_scrollElasticityController.m_stretchScrollForce.setWidth(reboundDeltaForElasticDelta(newStretch.width()));
- m_scrollElasticityController.m_stretchScrollForce.setHeight(reboundDeltaForElasticDelta(newStretch.height()));
- } else {
- m_scrollElasticityController.m_client->immediateScrollBy(m_scrollElasticityController.m_origOrigin - m_scrollElasticityController.m_client->absoluteScrollPosition());
- m_scrollElasticityController.m_client->stopSnapRubberbandTimer();
-
- m_scrollElasticityController.m_stretchScrollForce = FloatSize();
- m_scrollElasticityController.m_startTime = 0;
- m_scrollElasticityController.m_startStretch = FloatSize();
- m_scrollElasticityController.m_origOrigin = FloatPoint();
- m_scrollElasticityController.m_origVelocity = FloatSize();
- m_scrollElasticityController.m_snapRubberbandTimerIsActive = false;
- }
- } else {
- m_scrollElasticityController.m_startTime = [NSDate timeIntervalSinceReferenceDate];
- m_scrollElasticityController.m_startStretch = FloatSize();
- }
+ m_scrollElasticityController.snapRubberBandTimerFired();
}
#endif
Modified: trunk/Source/WebCore/platform/mac/ScrollElasticityController.h (104841 => 104842)
--- trunk/Source/WebCore/platform/mac/ScrollElasticityController.h 2012-01-12 19:55:31 UTC (rev 104841)
+++ trunk/Source/WebCore/platform/mac/ScrollElasticityController.h 2012-01-12 20:04:31 UTC (rev 104842)
@@ -61,6 +61,8 @@
void beginScrollGesture();
+ void snapRubberBandTimerFired();
+
private:
void stopSnapRubberbandTimer();
Modified: trunk/Source/WebCore/platform/mac/ScrollElasticityController.mm (104841 => 104842)
--- trunk/Source/WebCore/platform/mac/ScrollElasticityController.mm 2012-01-12 19:55:31 UTC (rev 104841)
+++ trunk/Source/WebCore/platform/mac/ScrollElasticityController.mm 2012-01-12 20:04:31 UTC (rev 104842)
@@ -31,7 +31,18 @@
namespace WebCore {
static const float rubberbandStiffness = 20;
+static const float rubberbandAmplitude = 0.31f;
+static const float rubberbandPeriod = 1.6f;
+static float elasticDeltaForTimeDelta(float initialPosition, float initialVelocity, float elapsedTime)
+{
+ float amplitude = rubberbandAmplitude;
+ float period = rubberbandPeriod;
+ float criticalDampeningFactor = expf((-elapsedTime * rubberbandStiffness) / period);
+
+ return (initialPosition + (-initialVelocity * elapsedTime * amplitude)) * criticalDampeningFactor;
+}
+
static float reboundDeltaForElasticDelta(float delta)
{
return delta * rubberbandStiffness;
@@ -65,6 +76,85 @@
stopSnapRubberbandTimer();
}
+static inline float roundTowardZero(float num)
+{
+ return num > 0 ? ceilf(num - 0.5f) : floorf(num + 0.5f);
+}
+
+static inline float roundToDevicePixelTowardZero(float num)
+{
+ float roundedNum = roundf(num);
+ if (fabs(num - roundedNum) < 0.125)
+ num = roundedNum;
+
+ return roundTowardZero(num);
+}
+
+void ScrollElasticityController::snapRubberBandTimerFired()
+{
+ if (!m_momentumScrollInProgress || m_ignoreMomentumScrolls) {
+ CFTimeInterval timeDelta = [NSDate timeIntervalSinceReferenceDate] - m_startTime;
+
+ if (m_startStretch == FloatSize()) {
+ m_startStretch = m_client->stretchAmount();
+ if (m_startStretch == FloatSize()) {
+ m_client->stopSnapRubberbandTimer();
+
+ m_stretchScrollForce = FloatSize();
+ m_startTime = 0;
+ m_startStretch = FloatSize();
+ m_origOrigin = FloatPoint();
+ m_origVelocity = FloatSize();
+ m_snapRubberbandTimerIsActive = false;
+
+ return;
+ }
+
+ m_origOrigin = m_client->absoluteScrollPosition() - m_startStretch;
+ m_origVelocity = m_momentumVelocity;
+
+ // Just like normal scrolling, prefer vertical rubberbanding
+ if (fabsf(m_origVelocity.height()) >= fabsf(m_origVelocity.width()))
+ m_origVelocity.setWidth(0);
+
+ // Don't rubber-band horizontally if it's not possible to scroll horizontally
+ if (!m_client->canScrollHorizontally())
+ m_origVelocity.setWidth(0);
+
+ // Don't rubber-band vertically if it's not possible to scroll vertically
+ if (!m_client->canScrollVertically())
+ m_origVelocity.setHeight(0);
+ }
+
+ FloatPoint delta(roundToDevicePixelTowardZero(elasticDeltaForTimeDelta(m_startStretch.width(), -m_origVelocity.width(), (float)timeDelta)),
+ roundToDevicePixelTowardZero(elasticDeltaForTimeDelta(m_startStretch.height(), -m_origVelocity.height(), (float)timeDelta)));
+
+ if (fabs(delta.x()) >= 1 || fabs(delta.y()) >= 1) {
+ FloatPoint newOrigin = m_origOrigin + delta;
+
+ m_client->immediateScrollByWithoutContentEdgeConstraints(FloatSize(delta.x(), delta.y()) - m_client->stretchAmount());
+
+ FloatSize newStretch = m_client->stretchAmount();
+
+ m_stretchScrollForce.setWidth(reboundDeltaForElasticDelta(newStretch.width()));
+ m_stretchScrollForce.setHeight(reboundDeltaForElasticDelta(newStretch.height()));
+ } else {
+ m_client->immediateScrollBy(m_origOrigin - m_client->absoluteScrollPosition());
+ m_client->stopSnapRubberbandTimer();
+
+ m_stretchScrollForce = FloatSize();
+ m_startTime = 0;
+ m_startStretch = FloatSize();
+ m_origOrigin = FloatPoint();
+ m_origVelocity = FloatSize();
+ m_snapRubberbandTimerIsActive = false;
+ }
+ } else {
+ m_startTime = [NSDate timeIntervalSinceReferenceDate];
+ m_startStretch = FloatSize();
+ }
+}
+
void ScrollElasticityController::stopSnapRubberbandTimer()
{
m_client->stopSnapRubberbandTimer();
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes