Diff
Modified: trunk/Source/WebCore/ChangeLog (283025 => 283026)
--- trunk/Source/WebCore/ChangeLog 2021-09-24 04:50:38 UTC (rev 283025)
+++ trunk/Source/WebCore/ChangeLog 2021-09-24 05:07:19 UTC (rev 283026)
@@ -1,5 +1,34 @@
2021-09-23 Simon Fraser <[email protected]>
+ Move ScrollSnapAnimatorState's ScrollAnimationMomentum into ScrollingEffectsController
+ https://bugs.webkit.org/show_bug.cgi?id=230732
+
+ Reviewed by Wenson Hsieh.
+
+ Continuing the work to move all animations into ScrollingEffectsController, move
+ the ScrollAnimationMomentum that ScrollSnapAnimatorState uses into ScrollingEffectsController.
+
+ ScrollSnapAnimatorState is no longer a ScrollAnimationClient.
+
+ ScrollingEffectsController::updateScrollSnapAnimatingState(), which is Mac-only code
+ (but probably doens't need to be) can now consult the animation directly.
+
+ * platform/ScrollSnapAnimatorState.cpp:
+ (WebCore::ScrollSnapAnimatorState::setupAnimationForState):
+ (WebCore::ScrollSnapAnimatorState::teardownAnimationForState):
+ (WebCore::ScrollSnapAnimatorState::currentAnimatedScrollOffset const): Deleted.
+ (WebCore::ScrollSnapAnimatorState::scrollExtentsForAnimation): Deleted.
+ * platform/ScrollSnapAnimatorState.h:
+ (WebCore::ScrollSnapAnimatorState::ScrollSnapAnimatorState):
+ * platform/ScrollingEffectsController.cpp:
+ (WebCore::ScrollingEffectsController::startMomentumScrollWithInitialVelocity):
+ (WebCore::ScrollingEffectsController::setSnapOffsetsInfo):
+ * platform/ScrollingEffectsController.h:
+ * platform/mac/ScrollingEffectsController.mm:
+ (WebCore::ScrollingEffectsController::updateScrollSnapAnimatingState):
+
+2021-09-23 Simon Fraser <[email protected]>
+
Move the ScrollAnimationSmooth from ScrollAnimator into ScrollingEffectsController
https://bugs.webkit.org/show_bug.cgi?id=230720
Modified: trunk/Source/WebCore/platform/ScrollSnapAnimatorState.cpp (283025 => 283026)
--- trunk/Source/WebCore/platform/ScrollSnapAnimatorState.cpp 2021-09-24 04:50:38 UTC (rev 283025)
+++ trunk/Source/WebCore/platform/ScrollSnapAnimatorState.cpp 2021-09-24 05:07:19 UTC (rev 283026)
@@ -26,7 +26,7 @@
#include "config.h"
#include "ScrollSnapAnimatorState.h"
-#include "ScrollAnimationMomentum.h"
+#include "ScrollingEffectsController.h"
#include <wtf/MathExtras.h>
#include <wtf/text/TextStream.h>
@@ -50,13 +50,7 @@
if (m_currentState == state)
return false;
- m_scrollExtents = scrollExtents;
-
- if (m_momentumScrollAnimation)
- m_momentumScrollAnimation->stop();
-
- m_momentumScrollAnimation = WTF::makeUnique<ScrollAnimationMomentum>(*this);
- bool animating = m_momentumScrollAnimation->startAnimatedScrollWithInitialVelocity(initialOffset, initialVelocity, initialDelta, [&](const FloatPoint& targetOffset) {
+ bool animating = m_scrollController.startMomentumScrollWithInitialVelocity(initialOffset, initialVelocity, initialDelta, [&](const FloatPoint& targetOffset) {
float targetOffsetX, targetOffsetY;
std::tie(targetOffsetX, m_activeSnapIndexX) = targetOffsetForStartOffset(ScrollEventAxis::Horizontal, scrollExtents, initialOffset.x(), targetOffset, pageScale, initialDelta.width());
std::tie(targetOffsetY, m_activeSnapIndexY) = targetOffsetForStartOffset(ScrollEventAxis::Vertical, scrollExtents, initialOffset.y(), targetOffset, pageScale, initialDelta.height());
@@ -67,7 +61,6 @@
if (!animating)
return false;
- m_startTime = MonotonicTime::now();
m_currentState = state;
return animating;
}
@@ -149,24 +142,10 @@
if (m_currentState == state)
return;
- m_momentumScrollAnimation = nullptr;
- m_startTime = { };
+ m_scrollController.stopAnimatedScroll();
m_currentState = state;
}
-FloatPoint ScrollSnapAnimatorState::currentAnimatedScrollOffset(MonotonicTime currentTime, bool& isAnimationComplete) const
-{
- if (!m_momentumScrollAnimation) {
- isAnimationComplete = true;
- return { };
- }
-
- auto currentOffset = m_momentumScrollAnimation->serviceAnimation(currentTime);
- isAnimationComplete = !m_momentumScrollAnimation->isActive();
-
- return currentOffset;
-}
-
std::pair<float, std::optional<unsigned>> ScrollSnapAnimatorState::targetOffsetForStartOffset(ScrollEventAxis axis, const ScrollExtents& scrollExtents, float startOffset, FloatPoint predictedOffset, float pageScale, float initialDelta) const
{
auto minScrollOffset = (axis == ScrollEventAxis::Horizontal) ? scrollExtents.minimumScrollOffset().x() : scrollExtents.minimumScrollOffset().y();
@@ -181,11 +160,6 @@
return std::make_pair(pageScale * clampTo<float>(float { targetOffset }, minScrollOffset, maxScrollOffset), snapIndex);
}
-ScrollExtents ScrollSnapAnimatorState::scrollExtentsForAnimation(ScrollAnimation&)
-{
- return m_scrollExtents;
-}
-
TextStream& operator<<(TextStream& ts, const ScrollSnapAnimatorState& state)
{
ts << "ScrollSnapAnimatorState";
Modified: trunk/Source/WebCore/platform/ScrollSnapAnimatorState.h (283025 => 283026)
--- trunk/Source/WebCore/platform/ScrollSnapAnimatorState.h 2021-09-24 04:50:38 UTC (rev 283025)
+++ trunk/Source/WebCore/platform/ScrollSnapAnimatorState.h 2021-09-24 05:07:19 UTC (rev 283026)
@@ -40,6 +40,8 @@
namespace WebCore {
+class ScrollingEffectsController;
+
enum class ScrollSnapState {
Snapping,
Gliding,
@@ -47,9 +49,12 @@
UserInteraction
};
-class ScrollSnapAnimatorState : public ScrollAnimationClient {
+class ScrollSnapAnimatorState {
WTF_MAKE_FAST_ALLOCATED;
public:
+ ScrollSnapAnimatorState(ScrollingEffectsController& scrollController)
+ : m_scrollController(scrollController)
+ { }
virtual ~ScrollSnapAnimatorState();
const Vector<SnapOffset<LayoutUnit>>& snapOffsetsForAxis(ScrollEventAxis axis) const
@@ -84,8 +89,6 @@
bool setNearestScrollSnapIndexForOffset(ScrollOffset, const ScrollExtents&, float pageScale);
- FloatPoint currentAnimatedScrollOffset(MonotonicTime, bool& isAnimationComplete) const;
-
// State transition helpers.
// These return true if they start a new animation.
bool transitionToSnapAnimationState(const ScrollExtents&, float pageScale, const FloatPoint& initialOffset);
@@ -99,20 +102,14 @@
bool setupAnimationForState(ScrollSnapState, const ScrollExtents&, float pageScale, const FloatPoint& initialOffset, const FloatSize& initialVelocity, const FloatSize& initialDelta);
void teardownAnimationForState(ScrollSnapState);
- // ScrollAnimationClient.
- ScrollExtents scrollExtentsForAnimation(ScrollAnimation&) final;
+ ScrollingEffectsController& m_scrollController;
ScrollSnapState m_currentState { ScrollSnapState::UserInteraction };
LayoutScrollSnapOffsetsInfo m_snapOffsetsInfo;
-
- ScrollExtents m_scrollExtents;
std::optional<unsigned> m_activeSnapIndexX;
std::optional<unsigned> m_activeSnapIndexY;
-
- MonotonicTime m_startTime;
- std::unique_ptr<ScrollAnimationMomentum> m_momentumScrollAnimation;
};
WTF::TextStream& operator<<(WTF::TextStream&, const ScrollSnapAnimatorState&);
Modified: trunk/Source/WebCore/platform/ScrollingEffectsController.cpp (283025 => 283026)
--- trunk/Source/WebCore/platform/ScrollingEffectsController.cpp 2021-09-24 04:50:38 UTC (rev 283025)
+++ trunk/Source/WebCore/platform/ScrollingEffectsController.cpp 2021-09-24 05:07:19 UTC (rev 283026)
@@ -31,6 +31,7 @@
#include "Logging.h"
#include "PlatformWheelEvent.h"
#include "ScrollAnimationKinetic.h"
+#include "ScrollAnimationMomentum.h"
#include "ScrollAnimationSmooth.h"
#include "ScrollableArea.h"
#include "WheelEventTestMonitor.h"
@@ -111,7 +112,7 @@
}
if (!m_currentAnimation)
- m_currentAnimation = WTF::makeUnique<ScrollAnimationKinetic>(*this);
+ m_currentAnimation = makeUnique<ScrollAnimationKinetic>(*this);
auto& kineticAnimation = downcast<ScrollAnimationKinetic>(*m_currentAnimation);
kineticAnimation.appendToScrollHistory(event);
@@ -131,6 +132,21 @@
return false;
}
+bool ScrollingEffectsController::startMomentumScrollWithInitialVelocity(const FloatPoint& initialOffset, const FloatSize& initialVelocity, const FloatSize& initialDelta, const Function<FloatPoint(const FloatPoint&)>& destinationModifier)
+{
+ if (m_currentAnimation) {
+ if (is<ScrollAnimationMomentum>(m_currentAnimation.get()))
+ m_currentAnimation->stop();
+ else
+ m_currentAnimation = nullptr;
+ }
+
+ if (!m_currentAnimation)
+ m_currentAnimation = makeUnique<ScrollAnimationMomentum>(*this);
+
+ return downcast<ScrollAnimationMomentum>(*m_currentAnimation).startAnimatedScrollWithInitialVelocity(initialOffset, initialVelocity, initialDelta, destinationModifier);
+}
+
void ScrollingEffectsController::setIsAnimatingRubberBand(bool isAnimatingRubberBand)
{
if (isAnimatingRubberBand == m_isAnimatingRubberBand)
@@ -178,7 +194,7 @@
bool shouldComputeCurrentSnapIndices = !m_scrollSnapState;
if (!m_scrollSnapState)
- m_scrollSnapState = makeUnique<ScrollSnapAnimatorState>();
+ m_scrollSnapState = makeUnique<ScrollSnapAnimatorState>(*this);
m_scrollSnapState->setSnapOffsetInfo(snapOffsetInfo);
Modified: trunk/Source/WebCore/platform/ScrollingEffectsController.h (283025 => 283026)
--- trunk/Source/WebCore/platform/ScrollingEffectsController.h 2021-09-24 04:50:38 UTC (rev 283025)
+++ trunk/Source/WebCore/platform/ScrollingEffectsController.h 2021-09-24 05:07:19 UTC (rev 283026)
@@ -138,6 +138,8 @@
// FIXME: Hack for ScrollAnimatorGeneric. Needs cleanup.
bool processWheelEventForKineticScrolling(const PlatformWheelEvent&);
+ bool startMomentumScrollWithInitialVelocity(const FloatPoint& initialOffset, const FloatSize& initialVelocity, const FloatSize& initialDelta, const WTF::Function<FloatPoint(const FloatPoint&)>& destinationModifier);
+
void beginKeyboardScrolling();
void stopKeyboardScrolling();
Modified: trunk/Source/WebCore/platform/mac/ScrollingEffectsController.mm (283025 => 283026)
--- trunk/Source/WebCore/platform/mac/ScrollingEffectsController.mm 2021-09-24 04:50:38 UTC (rev 283025)
+++ trunk/Source/WebCore/platform/mac/ScrollingEffectsController.mm 2021-09-24 05:07:19 UTC (rev 283026)
@@ -755,8 +755,17 @@
return;
}
- bool isAnimationComplete;
- auto animationOffset = m_scrollSnapState->currentAnimatedScrollOffset(currentTime, isAnimationComplete);
+ if (!is<ScrollAnimationMomentum>(m_currentAnimation.get())) {
+ m_scrollSnapState->transitionToDestinationReachedState();
+ stopScrollSnapAnimation();
+ return;
+ }
+
+ auto& momentumScrollAnimation = downcast<ScrollAnimationMomentum>(*m_currentAnimation);
+
+ auto animationOffset = momentumScrollAnimation.serviceAnimation(currentTime);
+ bool isAnimationComplete = !momentumScrollAnimation.isActive();
+
LOG_WITH_STREAM(ScrollSnap, stream << "ScrollingEffectsController " << this << " updateScrollSnapAnimatingState - isAnimationComplete " << isAnimationComplete << " animationOffset " << animationOffset << " (main thread " << isMainThread() << ")");
scrollToOffsetForAnimation(animationOffset);