Changeset 96651 in webkit
- Timestamp:
- Oct 4, 2011 2:58:18 PM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r96646 r96651 1 2011-10-04 Anders Carlsson <andersca@apple.com> 2 3 Move all rubber-banding related member variables to ScrollElasticityController 4 https://bugs.webkit.org/show_bug.cgi?id=69379 5 6 Reviewed by Dan Bernstein. 7 8 * platform/mac/ScrollAnimatorMac.h: 9 * platform/mac/ScrollAnimatorMac.mm: 10 (WebCore::ScrollAnimatorMac::ScrollAnimatorMac): 11 (WebCore::ScrollAnimatorMac::handleWheelEvent): 12 (WebCore::ScrollAnimatorMac::smoothScrollWithEvent): 13 (WebCore::ScrollAnimatorMac::beginScrollGesture): 14 (WebCore::ScrollAnimatorMac::snapRubberBand): 15 (WebCore::ScrollAnimatorMac::snapRubberBandTimerFired): 16 * platform/mac/ScrollElasticityController.h: 17 * platform/mac/ScrollElasticityController.mm: 18 (WebCore::ScrollElasticityController::ScrollElasticityController): 19 1 20 2011-10-04 Anders Carlsson <andersca@apple.com> 2 21 -
trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.h
r96644 r96651 149 149 150 150 ScrollElasticityController m_scrollElasticityController; 151 152 int m_cumulativeHorizontalScroll;153 bool m_didCumulativeHorizontalScrollEverSwitchToOppositeDirectionOfPin;154 155 CFTimeInterval m_lastMomentumScrollTimestamp;156 FloatSize m_overflowScrollDelta;157 FloatSize m_stretchScrollForce;158 FloatSize m_momentumVelocity;159 160 // Rubber band state.161 CFTimeInterval m_startTime;162 FloatSize m_startStretch;163 FloatPoint m_origOrigin;164 FloatSize m_origVelocity;165 151 Timer<ScrollAnimatorMac> m_snapRubberBandTimer; 166 152 #endif 153 167 154 bool m_drawingIntoLayer; 168 155 bool m_haveScrolledSincePageLoad; -
trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.mm
r96644 r96651 460 460 #if ENABLE(RUBBER_BANDING) 461 461 , m_scrollElasticityController(this) 462 , m_lastMomentumScrollTimestamp(0)463 , m_startTime(0)464 462 , m_snapRubberBandTimer(this, &ScrollAnimatorMac::snapRubberBandTimerFired) 465 463 #endif … … 795 793 m_haveScrolledSincePageLoad = true; 796 794 797 if (!wheelEvent.hasPreciseScrollingDeltas()) {795 if (!wheelEvent.hasPreciseScrollingDeltas()) 798 796 return ScrollAnimator::handleWheelEvent(wheelEvent); 799 }800 797 801 798 // FIXME: This is somewhat roundabout hack to allow forwarding wheel events … … 816 813 // boolean, and rubber band. That is, if we were pinned to the left, 817 814 // and we ended up scrolling to the right, we rubber band. 818 m_ cumulativeHorizontalScroll += wheelEvent.deltaX();819 if (m_scrollElasticityController.m_scrollerInitiallyPinnedOnLeft && m_ cumulativeHorizontalScroll < 0)820 m_ didCumulativeHorizontalScrollEverSwitchToOppositeDirectionOfPin = true;821 if (m_scrollElasticityController.m_scrollerInitiallyPinnedOnRight && m_ cumulativeHorizontalScroll > 0)822 m_ didCumulativeHorizontalScrollEverSwitchToOppositeDirectionOfPin = true;815 m_scrollElasticityController.m_cumulativeHorizontalScroll += wheelEvent.deltaX(); 816 if (m_scrollElasticityController.m_scrollerInitiallyPinnedOnLeft && m_scrollElasticityController.m_cumulativeHorizontalScroll < 0) 817 m_scrollElasticityController.m_didCumulativeHorizontalScrollEverSwitchToOppositeDirectionOfPin = true; 818 if (m_scrollElasticityController.m_scrollerInitiallyPinnedOnRight && m_scrollElasticityController.m_cumulativeHorizontalScroll > 0) 819 m_scrollElasticityController.m_didCumulativeHorizontalScrollEverSwitchToOppositeDirectionOfPin = true; 823 820 } 824 821 … … 827 824 // 0+ PlatformWheelEventPhaseChanged 828 825 // 1 PlatformWheelEventPhaseEnded if there was at least one changed event 829 if (wheelEvent.momentumPhase() == PlatformWheelEventPhaseNone && !m_ didCumulativeHorizontalScrollEverSwitchToOppositeDirectionOfPin) {826 if (wheelEvent.momentumPhase() == PlatformWheelEventPhaseNone && !m_scrollElasticityController.m_didCumulativeHorizontalScrollEverSwitchToOppositeDirectionOfPin) { 830 827 if ((isScrollingLeftAndShouldNotRubberBand(wheelEvent, m_scrollableArea) && 831 828 m_scrollElasticityController.m_scrollerInitiallyPinnedOnLeft && … … 926 923 m_haveScrolledSincePageLoad = true; 927 924 928 float deltaX = m_ overflowScrollDelta.width();929 float deltaY = m_ overflowScrollDelta.height();925 float deltaX = m_scrollElasticityController.m_overflowScrollDelta.width(); 926 float deltaY = m_scrollElasticityController.m_overflowScrollDelta.height(); 930 927 931 928 // Reset overflow values because we may decide to remove delta at various points and put it into overflow. 932 m_ overflowScrollDelta = FloatSize();929 m_scrollElasticityController.m_overflowScrollDelta = FloatSize(); 933 930 934 931 float eventCoalescedDeltaX = -wheelEvent.deltaX(); … … 959 956 m_scrollElasticityController.m_momentumScrollInProgress = true; 960 957 961 CFTimeInterval timeDelta = wheelEvent.timestamp() - m_ lastMomentumScrollTimestamp;958 CFTimeInterval timeDelta = wheelEvent.timestamp() - m_scrollElasticityController.m_lastMomentumScrollTimestamp; 962 959 if (m_scrollElasticityController.m_inScrollGesture || m_scrollElasticityController.m_momentumScrollInProgress) { 963 if (m_ lastMomentumScrollTimestamp && timeDelta > 0 && timeDelta < scrollVelocityZeroingTimeout) {964 m_ momentumVelocity.setWidth(eventCoalescedDeltaX / (float)timeDelta);965 m_ momentumVelocity.setHeight(eventCoalescedDeltaY / (float)timeDelta);966 m_ lastMomentumScrollTimestamp = wheelEvent.timestamp();960 if (m_scrollElasticityController.m_lastMomentumScrollTimestamp && timeDelta > 0 && timeDelta < scrollVelocityZeroingTimeout) { 961 m_scrollElasticityController.m_momentumVelocity.setWidth(eventCoalescedDeltaX / (float)timeDelta); 962 m_scrollElasticityController.m_momentumVelocity.setHeight(eventCoalescedDeltaY / (float)timeDelta); 963 m_scrollElasticityController.m_lastMomentumScrollTimestamp = wheelEvent.timestamp(); 967 964 } else { 968 m_ lastMomentumScrollTimestamp = wheelEvent.timestamp();969 m_ momentumVelocity = FloatSize();965 m_scrollElasticityController.m_lastMomentumScrollTimestamp = wheelEvent.timestamp(); 966 m_scrollElasticityController.m_momentumVelocity = FloatSize(); 970 967 } 971 968 … … 976 973 deltaX = 0; 977 974 else if (fabsf(deltaX) < rubberbandMinimumRequiredDeltaBeforeStretch) { 978 m_ overflowScrollDelta.setWidth(m_overflowScrollDelta.width() + deltaX);975 m_scrollElasticityController.m_overflowScrollDelta.setWidth(m_scrollElasticityController.m_overflowScrollDelta.width() + deltaX); 979 976 deltaX = 0; 980 977 } else 981 m_ overflowScrollDelta.setWidth(m_overflowScrollDelta.width() + deltaX);978 m_scrollElasticityController.m_overflowScrollDelta.setWidth(m_scrollElasticityController.m_overflowScrollDelta.width() + deltaX); 982 979 } 983 980 } else if (isHorizontallyStretched) { … … 987 984 deltaY = 0; 988 985 else if (fabsf(deltaY) < rubberbandMinimumRequiredDeltaBeforeStretch) { 989 m_ overflowScrollDelta.setHeight(m_overflowScrollDelta.height() + deltaY);986 m_scrollElasticityController.m_overflowScrollDelta.setHeight(m_scrollElasticityController.m_overflowScrollDelta.height() + deltaY); 990 987 deltaY = 0; 991 988 } else 992 m_ overflowScrollDelta.setHeight(m_overflowScrollDelta.height() + deltaY);989 m_scrollElasticityController.m_overflowScrollDelta.setHeight(m_scrollElasticityController.m_overflowScrollDelta.height() + deltaY); 993 990 } 994 991 } else { … … 997 994 if (fabsf(deltaY) >= fabsf(deltaX)) { 998 995 if (fabsf(deltaX) < rubberbandMinimumRequiredDeltaBeforeStretch) { 999 m_ overflowScrollDelta.setWidth(m_overflowScrollDelta.width() + deltaX);996 m_scrollElasticityController.m_overflowScrollDelta.setWidth(m_scrollElasticityController.m_overflowScrollDelta.width() + deltaX); 1000 997 deltaX = 0; 1001 998 } else 1002 m_ overflowScrollDelta.setWidth(m_overflowScrollDelta.width() + deltaX);999 m_scrollElasticityController.m_overflowScrollDelta.setWidth(m_scrollElasticityController.m_overflowScrollDelta.width() + deltaX); 1003 1000 } 1004 1001 shouldStretch = true; … … 1047 1044 1048 1045 if (m_scrollElasticityController.m_momentumScrollInProgress) { 1049 if ((pinnedInDirection(eventCoalescedDeltaX, eventCoalescedDeltaY) || (fabsf(eventCoalescedDeltaX) + fabsf(eventCoalescedDeltaY) <= 0)) && m_ lastMomentumScrollTimestamp) {1046 if ((pinnedInDirection(eventCoalescedDeltaX, eventCoalescedDeltaY) || (fabsf(eventCoalescedDeltaX) + fabsf(eventCoalescedDeltaY) <= 0)) && m_scrollElasticityController.m_lastMomentumScrollTimestamp) { 1050 1047 m_scrollElasticityController.m_ignoreMomentumScrolls = true; 1051 1048 m_scrollElasticityController.m_momentumScrollInProgress = false; … … 1054 1051 } 1055 1052 1056 m_s tretchScrollForce.setWidth(m_stretchScrollForce.width() + deltaX);1057 m_s tretchScrollForce.setHeight(m_stretchScrollForce.height() + deltaY);1058 1059 FloatSize dampedDelta(ceilf(elasticDeltaForReboundDelta(m_s tretchScrollForce.width())), ceilf(elasticDeltaForReboundDelta(m_stretchScrollForce.height())));1053 m_scrollElasticityController.m_stretchScrollForce.setWidth(m_scrollElasticityController.m_stretchScrollForce.width() + deltaX); 1054 m_scrollElasticityController.m_stretchScrollForce.setHeight(m_scrollElasticityController.m_stretchScrollForce.height() + deltaY); 1055 1056 FloatSize dampedDelta(ceilf(elasticDeltaForReboundDelta(m_scrollElasticityController.m_stretchScrollForce.width())), ceilf(elasticDeltaForReboundDelta(m_scrollElasticityController.m_stretchScrollForce.height()))); 1060 1057 FloatPoint origOrigin = (m_scrollableArea->visibleContentRect().location() + m_scrollableArea->scrollOrigin()) - stretchAmount; 1061 1058 FloatPoint newOrigin = origOrigin + dampedDelta; … … 1072 1069 m_scrollElasticityController.m_momentumScrollInProgress = false; 1073 1070 m_scrollElasticityController.m_ignoreMomentumScrolls = false; 1074 m_ lastMomentumScrollTimestamp = 0;1071 m_scrollElasticityController.m_lastMomentumScrollTimestamp = 0; 1075 1072 } 1076 1073 } … … 1084 1081 m_scrollElasticityController.m_momentumScrollInProgress = false; 1085 1082 m_scrollElasticityController.m_ignoreMomentumScrolls = false; 1086 m_ lastMomentumScrollTimestamp = 0;1087 m_ momentumVelocity = FloatSize();1083 m_scrollElasticityController.m_lastMomentumScrollTimestamp = 0; 1084 m_scrollElasticityController.m_momentumVelocity = FloatSize(); 1088 1085 m_scrollElasticityController.m_scrollerInitiallyPinnedOnLeft = m_scrollableArea->isHorizontalScrollerPinnedToMinimumPosition(); 1089 1086 m_scrollElasticityController.m_scrollerInitiallyPinnedOnRight = m_scrollableArea->isHorizontalScrollerPinnedToMaximumPosition(); 1090 m_ cumulativeHorizontalScroll = 0;1091 m_ didCumulativeHorizontalScrollEverSwitchToOppositeDirectionOfPin = false;1087 m_scrollElasticityController.m_cumulativeHorizontalScroll = 0; 1088 m_scrollElasticityController.m_didCumulativeHorizontalScrollEverSwitchToOppositeDirectionOfPin = false; 1092 1089 1093 1090 IntSize stretchAmount = m_scrollableArea->overhangAmount(); 1094 m_s tretchScrollForce.setWidth(reboundDeltaForElasticDelta(stretchAmount.width()));1095 m_s tretchScrollForce.setHeight(reboundDeltaForElasticDelta(stretchAmount.height()));1096 1097 m_ overflowScrollDelta = FloatSize();1091 m_scrollElasticityController.m_stretchScrollForce.setWidth(reboundDeltaForElasticDelta(stretchAmount.width())); 1092 m_scrollElasticityController.m_stretchScrollForce.setHeight(reboundDeltaForElasticDelta(stretchAmount.height())); 1093 1094 m_scrollElasticityController.m_overflowScrollDelta = FloatSize(); 1098 1095 1099 1096 if (m_snapRubberBandTimer.isActive()) … … 1110 1107 void ScrollAnimatorMac::snapRubberBand() 1111 1108 { 1112 CFTimeInterval timeDelta = [[NSProcessInfo processInfo] systemUptime] - m_ lastMomentumScrollTimestamp;1113 if (m_ lastMomentumScrollTimestamp && timeDelta >= scrollVelocityZeroingTimeout)1114 m_ momentumVelocity = FloatSize();1109 CFTimeInterval timeDelta = [[NSProcessInfo processInfo] systemUptime] - m_scrollElasticityController.m_lastMomentumScrollTimestamp; 1110 if (m_scrollElasticityController.m_lastMomentumScrollTimestamp && timeDelta >= scrollVelocityZeroingTimeout) 1111 m_scrollElasticityController.m_momentumVelocity = FloatSize(); 1115 1112 1116 1113 m_scrollElasticityController.m_inScrollGesture = false; … … 1119 1116 return; 1120 1117 1121 m_s tartTime = [NSDate timeIntervalSinceReferenceDate];1122 m_s tartStretch = FloatSize();1123 m_ origOrigin = FloatPoint();1124 m_ origVelocity = FloatSize();1118 m_scrollElasticityController.m_startTime = [NSDate timeIntervalSinceReferenceDate]; 1119 m_scrollElasticityController.m_startStretch = FloatSize(); 1120 m_scrollElasticityController.m_origOrigin = FloatPoint(); 1121 m_scrollElasticityController.m_origVelocity = FloatSize(); 1125 1122 1126 1123 m_snapRubberBandTimer.startRepeating(1.0/60.0); … … 1144 1141 { 1145 1142 if (!m_scrollElasticityController.m_momentumScrollInProgress || m_scrollElasticityController.m_ignoreMomentumScrolls) { 1146 CFTimeInterval timeDelta = [NSDate timeIntervalSinceReferenceDate] - m_s tartTime;1147 1148 if (m_s tartStretch == FloatSize()) {1149 m_s tartStretch = m_scrollableArea->overhangAmount();1150 if (m_s tartStretch == FloatSize()) {1143 CFTimeInterval timeDelta = [NSDate timeIntervalSinceReferenceDate] - m_scrollElasticityController.m_startTime; 1144 1145 if (m_scrollElasticityController.m_startStretch == FloatSize()) { 1146 m_scrollElasticityController.m_startStretch = m_scrollableArea->overhangAmount(); 1147 if (m_scrollElasticityController.m_startStretch == FloatSize()) { 1151 1148 m_snapRubberBandTimer.stop(); 1152 m_s tretchScrollForce = FloatSize();1153 m_s tartTime = 0;1154 m_s tartStretch = FloatSize();1155 m_ origOrigin = FloatPoint();1156 m_ origVelocity = FloatSize();1149 m_scrollElasticityController.m_stretchScrollForce = FloatSize(); 1150 m_scrollElasticityController.m_startTime = 0; 1151 m_scrollElasticityController.m_startStretch = FloatSize(); 1152 m_scrollElasticityController.m_origOrigin = FloatPoint(); 1153 m_scrollElasticityController.m_origVelocity = FloatSize(); 1157 1154 1158 1155 return; 1159 1156 } 1160 1157 1161 m_scrollableArea->didStartRubberBand(roundedIntSize(m_s tartStretch));1158 m_scrollableArea->didStartRubberBand(roundedIntSize(m_scrollElasticityController.m_startStretch)); 1162 1159 1163 m_ origOrigin = (m_scrollableArea->visibleContentRect().location() + m_scrollableArea->scrollOrigin()) -m_startStretch;1164 m_ origVelocity =m_momentumVelocity;1160 m_scrollElasticityController.m_origOrigin = (m_scrollableArea->visibleContentRect().location() + m_scrollableArea->scrollOrigin()) - m_scrollElasticityController.m_startStretch; 1161 m_scrollElasticityController.m_origVelocity = m_scrollElasticityController.m_momentumVelocity; 1165 1162 1166 1163 // Just like normal scrolling, prefer vertical rubberbanding 1167 if (fabsf(m_ origVelocity.height()) >= fabsf(m_origVelocity.width()))1168 m_ origVelocity.setWidth(0);1164 if (fabsf(m_scrollElasticityController.m_origVelocity.height()) >= fabsf(m_scrollElasticityController.m_origVelocity.width())) 1165 m_scrollElasticityController.m_origVelocity.setWidth(0); 1169 1166 1170 1167 // Don't rubber-band horizontally if it's not possible to scroll horizontally 1171 1168 Scrollbar* hScroller = m_scrollableArea->horizontalScrollbar(); 1172 1169 if (!hScroller || !hScroller->enabled()) 1173 m_ origVelocity.setWidth(0);1170 m_scrollElasticityController.m_origVelocity.setWidth(0); 1174 1171 1175 1172 // Don't rubber-band vertically if it's not possible to scroll horizontally 1176 1173 Scrollbar* vScroller = m_scrollableArea->verticalScrollbar(); 1177 1174 if (!vScroller || !vScroller->enabled()) 1178 m_ origVelocity.setHeight(0);1175 m_scrollElasticityController.m_origVelocity.setHeight(0); 1179 1176 } 1180 1177 1181 FloatPoint delta(roundToDevicePixelTowardZero(elasticDeltaForTimeDelta(m_s tartStretch.width(), -m_origVelocity.width(), (float)timeDelta)),1182 roundToDevicePixelTowardZero(elasticDeltaForTimeDelta(m_s tartStretch.height(), -m_origVelocity.height(), (float)timeDelta)));1178 FloatPoint delta(roundToDevicePixelTowardZero(elasticDeltaForTimeDelta(m_scrollElasticityController.m_startStretch.width(), -m_scrollElasticityController.m_origVelocity.width(), (float)timeDelta)), 1179 roundToDevicePixelTowardZero(elasticDeltaForTimeDelta(m_scrollElasticityController.m_startStretch.height(), -m_scrollElasticityController.m_origVelocity.height(), (float)timeDelta))); 1183 1180 1184 1181 if (fabs(delta.x()) >= 1 || fabs(delta.y()) >= 1) { 1185 FloatPoint newOrigin = m_ origOrigin + delta;1182 FloatPoint newOrigin = m_scrollElasticityController.m_origOrigin + delta; 1186 1183 1187 1184 m_scrollableArea->setConstrainsScrollingToContentEdge(false); … … 1191 1188 FloatSize newStretch = m_scrollableArea->overhangAmount(); 1192 1189 1193 m_s tretchScrollForce.setWidth(reboundDeltaForElasticDelta(newStretch.width()));1194 m_s tretchScrollForce.setHeight(reboundDeltaForElasticDelta(newStretch.height()));1190 m_scrollElasticityController.m_stretchScrollForce.setWidth(reboundDeltaForElasticDelta(newStretch.width())); 1191 m_scrollElasticityController.m_stretchScrollForce.setHeight(reboundDeltaForElasticDelta(newStretch.height())); 1195 1192 } else { 1196 immediateScrollToPoint(m_ origOrigin);1197 1198 m_scrollableArea->didCompleteRubberBand(roundedIntSize(m_s tartStretch));1193 immediateScrollToPoint(m_scrollElasticityController.m_origOrigin); 1194 1195 m_scrollableArea->didCompleteRubberBand(roundedIntSize(m_scrollElasticityController.m_startStretch)); 1199 1196 1200 1197 m_snapRubberBandTimer.stop(); 1201 m_s tretchScrollForce = FloatSize();1198 m_scrollElasticityController.m_stretchScrollForce = FloatSize(); 1202 1199 1203 m_s tartTime = 0;1204 m_s tartStretch = FloatSize();1205 m_ origOrigin = FloatPoint();1206 m_ origVelocity = FloatSize();1200 m_scrollElasticityController.m_startTime = 0; 1201 m_scrollElasticityController.m_startStretch = FloatSize(); 1202 m_scrollElasticityController.m_origOrigin = FloatPoint(); 1203 m_scrollElasticityController.m_origVelocity = FloatSize(); 1207 1204 } 1208 1205 } else { 1209 m_s tartTime = [NSDate timeIntervalSinceReferenceDate];1210 m_s tartStretch = FloatSize();1206 m_scrollElasticityController.m_startTime = [NSDate timeIntervalSinceReferenceDate]; 1207 m_scrollElasticityController.m_startStretch = FloatSize(); 1211 1208 } 1212 1209 } -
trunk/Source/WebCore/platform/mac/ScrollElasticityController.h
r96644 r96651 29 29 #if ENABLE(RUBBER_BANDING) 30 30 31 #include <WebCore/FloatPoint.h> 32 #include <WebCore/FloatSize.h> 31 33 #include <wtf/Noncopyable.h> 32 34 … … 55 57 bool m_scrollerInitiallyPinnedOnLeft; 56 58 bool m_scrollerInitiallyPinnedOnRight; 59 60 int m_cumulativeHorizontalScroll; 61 bool m_didCumulativeHorizontalScrollEverSwitchToOppositeDirectionOfPin; 57 62 63 CFTimeInterval m_lastMomentumScrollTimestamp; 64 FloatSize m_overflowScrollDelta; 65 FloatSize m_stretchScrollForce; 66 FloatSize m_momentumVelocity; 67 68 // Rubber band state. 69 CFTimeInterval m_startTime; 70 FloatSize m_startStretch; 71 FloatPoint m_origOrigin; 72 FloatSize m_origVelocity; 58 73 }; 59 74 -
trunk/Source/WebCore/platform/mac/ScrollElasticityController.mm
r96644 r96651 38 38 , m_scrollerInitiallyPinnedOnLeft(false) 39 39 , m_scrollerInitiallyPinnedOnRight(false) 40 , m_cumulativeHorizontalScroll(0) 41 , m_didCumulativeHorizontalScrollEverSwitchToOppositeDirectionOfPin(false) 42 , m_lastMomentumScrollTimestamp(0) 43 , m_startTime(0) 40 44 { 41 45 }
Note: See TracChangeset
for help on using the changeset viewer.