Diff
Modified: trunk/Source/WebCore/ChangeLog (282797 => 282798)
--- trunk/Source/WebCore/ChangeLog 2021-09-21 01:51:09 UTC (rev 282797)
+++ trunk/Source/WebCore/ChangeLog 2021-09-21 04:01:10 UTC (rev 282798)
@@ -1,3 +1,50 @@
+2021-09-20 Simon Fraser <simon.fra...@apple.com>
+
+ Wrap ScrollingMomentumCalculator in a ScrollAnimationMomentum when used for scroll snap
+ https://bugs.webkit.org/show_bug.cgi?id=230506
+
+ Reviewed by Wenson Hsieh.
+
+ The long-term goal is to have all scroll animations run via ScrollAnimation subclasses,
+ and for there to be a class (ScrollAnimator or ScrollingEffectsController) that has
+ a member variable for the single active scroll animation, for there can be only one
+ at a time.
+
+ As a step towards that goal, make ScrollAnimationMomentum and have it wrap the
+ ScrollingMomentumCalculator. ScrollSnapAnimatorState then owns a ScrollAnimationMomentum.
+
+ Other ScrollAnimations are running their own timers (which should go away in future),
+ but for now ScrollAnimationMomentum is driven "manually" by ScrollSnapAnimatorState.
+ Facilitate this by having ScrollAnimation::serviceAnimation() return the current offset.
+
+ * Headers.cmake:
+ * Sources.txt:
+ * WebCore.xcodeproj/project.pbxproj:
+ * platform/ScrollAnimation.h:
+ (WebCore::ScrollAnimationClient::scrollAnimationDidUpdate):
+ (WebCore::ScrollAnimationClient::scrollAnimationDidEnd):
+ (WebCore::ScrollAnimation::serviceAnimation):
+ * platform/ScrollAnimationMomentum.cpp: Added.
+ (WebCore::ScrollAnimationMomentum::ScrollAnimationMomentum):
+ (WebCore::ScrollAnimationMomentum::startAnimatedScrollWithInitialVelocity):
+ (WebCore::ScrollAnimationMomentum::retargetActiveAnimation):
+ (WebCore::ScrollAnimationMomentum::stop):
+ (WebCore::ScrollAnimationMomentum::isActive const):
+ (WebCore::ScrollAnimationMomentum::serviceAnimation):
+ (WebCore::ScrollAnimationMomentum::updateScrollExtents):
+ * platform/ScrollAnimationMomentum.h: Added.
+ * platform/ScrollAnimationSmooth.cpp:
+ * platform/ScrollSnapAnimatorState.cpp:
+ (WebCore::ScrollSnapAnimatorState::setupAnimationForState):
+ (WebCore::ScrollSnapAnimatorState::teardownAnimationForState):
+ (WebCore::ScrollSnapAnimatorState::currentAnimatedScrollOffset const):
+ (WebCore::ScrollSnapAnimatorState::scrollExtentsForAnimation):
+ * platform/ScrollSnapAnimatorState.h:
+ * platform/ScrollingEffectsController.cpp:
+ * platform/ScrollingEffectsController.h:
+ * platform/mac/ScrollingEffectsController.mm:
+ (WebCore::ScrollingEffectsController::statelessSnapTransitionTimerFired):
+
2021-09-20 Nikos Mouchtaris <nmouchta...@apple.com>
Implement exp,log functions calc functions
Modified: trunk/Source/WebCore/Headers.cmake (282797 => 282798)
--- trunk/Source/WebCore/Headers.cmake 2021-09-21 01:51:09 UTC (rev 282797)
+++ trunk/Source/WebCore/Headers.cmake 2021-09-21 04:01:10 UTC (rev 282798)
@@ -1132,6 +1132,7 @@
platform/SSLKeyGenerator.h
platform/ScreenProperties.h
platform/ScriptExecutionContextIdentifier.h
+ platform/ScrollAnimationMomentum.h
platform/ScrollAnimator.h
platform/ScrollTypes.h
platform/ScrollView.h
@@ -1139,7 +1140,6 @@
platform/Scrollbar.h
platform/ScrollbarTheme.h
platform/ScrollbarThemeComposite.h
- platform/ScrollingMomentumCalculator.h
platform/SearchPopupMenu.h
platform/SerializedPlatformDataCue.h
platform/SerializedPlatformDataCueValue.h
Modified: trunk/Source/WebCore/Sources.txt (282797 => 282798)
--- trunk/Source/WebCore/Sources.txt 2021-09-21 01:51:09 UTC (rev 282797)
+++ trunk/Source/WebCore/Sources.txt 2021-09-21 04:01:10 UTC (rev 282798)
@@ -1823,6 +1823,7 @@
platform/RuntimeApplicationChecks.cpp
platform/SSLKeyGenerator.cpp
platform/ScrollAnimationKinetic.cpp
+platform/ScrollAnimationMomentum.cpp
platform/ScrollAnimationSmooth.cpp
platform/ScrollAnimator.cpp
platform/ScrollingEffectsController.cpp
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (282797 => 282798)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2021-09-21 01:51:09 UTC (rev 282797)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2021-09-21 04:01:10 UTC (rev 282798)
@@ -290,6 +290,7 @@
0F03C0741884695E00A5F8CA /* SystemMemory.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F03C0731884695E00A5F8CA /* SystemMemory.h */; };
0F03C0751884805500A5F8CA /* InspectorOverlay.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C522D4A15B478B2009B7C95 /* InspectorOverlay.h */; settings = {ATTRIBUTES = (Private, ); }; };
0F099D0917B968A100FF84B9 /* WebCoreTypedArrayController.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F099D0717B968A100FF84B9 /* WebCoreTypedArrayController.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ 0F0E009C26F92D8400ACE9C6 /* ScrollAnimationMomentum.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F0E009A26F92D7B00ACE9C6 /* ScrollAnimationMomentum.h */; settings = {ATTRIBUTES = (Private, ); }; };
0F11781822E3C47F008BD570 /* FrameIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F11781622E3C47E008BD570 /* FrameIdentifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
0F11A54F0F39233100C37884 /* RenderSelectionInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F11A54E0F39233100C37884 /* RenderSelectionInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
0F13163E16ED0CC80035CC04 /* PlatformCAFilters.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F13163D16ED0CC80035CC04 /* PlatformCAFilters.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -350,7 +351,7 @@
0F94B6522209150600157014 /* ScrollingStatePositionedNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F94B651220914FF00157014 /* ScrollingStatePositionedNode.h */; settings = {ATTRIBUTES = (Private, ); }; };
0F94B655220931E400157014 /* ScrollingTreePositionedNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F94B6532209156C00157014 /* ScrollingTreePositionedNode.h */; settings = {ATTRIBUTES = (Private, ); }; };
0F94F37E23661626003AA5C7 /* StyleRuleType.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F94F37C23661131003AA5C7 /* StyleRuleType.h */; settings = {ATTRIBUTES = (Private, ); }; };
- 0F99059A26F6BE850054FBE0 /* ScrollingMomentumCalculator.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F99059926F6BE7F0054FBE0 /* ScrollingMomentumCalculator.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ 0F99059A26F6BE850054FBE0 /* ScrollingMomentumCalculator.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F99059926F6BE7F0054FBE0 /* ScrollingMomentumCalculator.h */; };
0F99059D26F6BE9A0054FBE0 /* ScrollingMomentumCalculatorMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F99059B26F6BE940054FBE0 /* ScrollingMomentumCalculatorMac.h */; };
0F9DAA0F1FD1C66A0079C5B2 /* DOMGCOutputConstraint.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F9DAA0E1FD1C6640079C5B2 /* DOMGCOutputConstraint.h */; };
0FA24D7A162DF91900A3F4C0 /* GraphicsLayerUpdater.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FA24D78162DF91900A3F4C0 /* GraphicsLayerUpdater.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -6184,6 +6185,8 @@
0F03C0731884695E00A5F8CA /* SystemMemory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SystemMemory.h; sourceTree = "<group>"; };
0F099D0617B968A100FF84B9 /* WebCoreTypedArrayController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebCoreTypedArrayController.cpp; sourceTree = "<group>"; };
0F099D0717B968A100FF84B9 /* WebCoreTypedArrayController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebCoreTypedArrayController.h; sourceTree = "<group>"; };
+ 0F0E009A26F92D7B00ACE9C6 /* ScrollAnimationMomentum.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ScrollAnimationMomentum.h; sourceTree = "<group>"; };
+ 0F0E009B26F92D7B00ACE9C6 /* ScrollAnimationMomentum.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollAnimationMomentum.cpp; sourceTree = "<group>"; };
0F11781622E3C47E008BD570 /* FrameIdentifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FrameIdentifier.h; sourceTree = "<group>"; };
0F11A54E0F39233100C37884 /* RenderSelectionInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderSelectionInfo.h; sourceTree = "<group>"; };
0F13163D16ED0CC80035CC04 /* PlatformCAFilters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformCAFilters.h; sourceTree = "<group>"; };
@@ -28145,6 +28148,8 @@
0FA61B0C26F43212001AADB6 /* ScrollAnimation.h */,
0FC692BC257C0F410098E3F9 /* ScrollAnimationKinetic.cpp */,
0FC692BA257C0F400098E3F9 /* ScrollAnimationKinetic.h */,
+ 0F0E009B26F92D7B00ACE9C6 /* ScrollAnimationMomentum.cpp */,
+ 0F0E009A26F92D7B00ACE9C6 /* ScrollAnimationMomentum.h */,
0FC692BD257C0F410098E3F9 /* ScrollAnimationSmooth.cpp */,
0FC692BE257C0F420098E3F9 /* ScrollAnimationSmooth.h */,
CA3BF67B10D99BAE00E6CE53 /* ScrollAnimator.cpp */,
@@ -34931,6 +34936,7 @@
BC8AE34F12EA096A00EB3AE6 /* ScrollableArea.h in Headers */,
5D925B680F64D4DD00B847F0 /* ScrollAlignment.h in Headers */,
0FA61B0E26F43213001AADB6 /* ScrollAnimation.h in Headers */,
+ 0F0E009C26F92D8400ACE9C6 /* ScrollAnimationMomentum.h in Headers */,
CA3BF67E10D99BAE00E6CE53 /* ScrollAnimator.h in Headers */,
0F1774801378B772009DA76A /* ScrollAnimatorIOS.h in Headers */,
BCAE1FA712939DB7004CB026 /* ScrollAnimatorMac.h in Headers */,
Modified: trunk/Source/WebCore/platform/ScrollAnimation.h (282797 => 282798)
--- trunk/Source/WebCore/platform/ScrollAnimation.h 2021-09-21 01:51:09 UTC (rev 282797)
+++ trunk/Source/WebCore/platform/ScrollAnimation.h 2021-09-21 04:01:10 UTC (rev 282798)
@@ -28,6 +28,7 @@
#include "ScrollTypes.h"
#include <wtf/FastMalloc.h>
+#include <wtf/MonotonicTime.h>
namespace WebCore {
@@ -38,8 +39,8 @@
public:
virtual ~ScrollAnimationClient() = default;
- virtual void scrollAnimationDidUpdate(ScrollAnimation&, const FloatPoint& currentOffset) = 0;
- virtual void scrollAnimationDidEnd(ScrollAnimation&) = 0;
+ virtual void scrollAnimationDidUpdate(ScrollAnimation&, const FloatPoint& /* currentOffset */) { }
+ virtual void scrollAnimationDidEnd(ScrollAnimation&) { }
virtual ScrollExtents scrollExtentsForAnimation(ScrollAnimation&) = 0;
};
@@ -56,8 +57,8 @@
virtual bool isActive() const = 0;
virtual void updateScrollExtents() { };
- // FIXME: No-op. Need to use this instead of subclasses having timers.
- virtual void serviceAnimation() { };
+ // Returns current offset.
+ virtual FloatPoint serviceAnimation(MonotonicTime) { return { }; };
protected:
ScrollAnimationClient& m_client;
Added: trunk/Source/WebCore/platform/ScrollAnimationMomentum.cpp (0 => 282798)
--- trunk/Source/WebCore/platform/ScrollAnimationMomentum.cpp (rev 0)
+++ trunk/Source/WebCore/platform/ScrollAnimationMomentum.cpp 2021-09-21 04:01:10 UTC (rev 282798)
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "ScrollAnimationMomentum.h"
+
+#include "Logging.h"
+#include "ScrollingMomentumCalculator.h"
+#include <wtf/text/TextStream.h>
+
+namespace WebCore {
+
+ScrollAnimationMomentum::ScrollAnimationMomentum(ScrollAnimationClient& client)
+ : ScrollAnimation(client)
+{
+}
+
+ScrollAnimationMomentum::~ScrollAnimationMomentum() = default;
+
+bool ScrollAnimationMomentum::startAnimatedScrollWithInitialVelocity(const FloatPoint& initialOffset, const FloatSize& initialVelocity, const FloatSize& initialDelta, const WTF::Function<FloatPoint(const FloatPoint&)>& destinationModifier)
+{
+ auto extents = m_client.scrollExtentsForAnimation(*this);
+
+ m_momentumCalculator = ScrollingMomentumCalculator::create(extents, initialOffset, initialDelta, initialVelocity);
+ auto predictedScrollOffset = m_momentumCalculator->predictedDestinationOffset();
+
+ if (destinationModifier) {
+ predictedScrollOffset = destinationModifier(predictedScrollOffset);
+ m_momentumCalculator->setRetargetedScrollOffset(predictedScrollOffset);
+ }
+
+ if (predictedScrollOffset == initialOffset) {
+ m_momentumCalculator = nullptr;
+ m_animationComplete = true;
+ return false;
+ }
+
+ m_startTime = MonotonicTime::now();
+ m_animationComplete = false;
+ return true;
+}
+
+bool ScrollAnimationMomentum::retargetActiveAnimation(const FloatPoint& newDestination)
+{
+ if (m_momentumCalculator) {
+ m_momentumCalculator->setRetargetedScrollOffset(newDestination);
+ auto newDuration = m_momentumCalculator->animationDuration();
+ m_animationComplete = newDuration > 0_s;
+ return !m_animationComplete;
+ }
+ return false;
+}
+
+void ScrollAnimationMomentum::stop()
+{
+ m_momentumCalculator = nullptr;
+ m_animationComplete = true;
+ m_client.scrollAnimationDidEnd(*this);
+}
+
+bool ScrollAnimationMomentum::isActive() const
+{
+ return !m_animationComplete;
+}
+
+FloatPoint ScrollAnimationMomentum::serviceAnimation(MonotonicTime currentTime)
+{
+ if (!m_momentumCalculator) {
+ ASSERT_NOT_REACHED();
+ return { };
+ }
+
+ auto elapsedTime = currentTime - m_startTime;
+ m_animationComplete = elapsedTime >= m_momentumCalculator->animationDuration();
+ auto newOffset = m_momentumCalculator->scrollOffsetAfterElapsedTime(elapsedTime);
+
+ m_client.scrollAnimationDidUpdate(*this, newOffset);
+
+ if (m_animationComplete)
+ m_client.scrollAnimationDidEnd(*this);
+
+ return newOffset;
+}
+
+void ScrollAnimationMomentum::updateScrollExtents()
+{
+ auto extents = m_client.scrollExtentsForAnimation(*this);
+ auto predictedScrollOffset = m_momentumCalculator->predictedDestinationOffset();
+ auto constrainedOffset = predictedScrollOffset.constrainedBetween(extents.minimumScrollOffset(), extents.maximumScrollOffset());
+ if (constrainedOffset != predictedScrollOffset) {
+ retargetActiveAnimation(constrainedOffset);
+ if (m_animationComplete)
+ m_client.scrollAnimationDidEnd(*this);
+ }
+}
+
+} // namespace WebCore
Added: trunk/Source/WebCore/platform/ScrollAnimationMomentum.h (0 => 282798)
--- trunk/Source/WebCore/platform/ScrollAnimationMomentum.h (rev 0)
+++ trunk/Source/WebCore/platform/ScrollAnimationMomentum.h 2021-09-21 04:01:10 UTC (rev 282798)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "ScrollAnimation.h"
+
+namespace WebCore {
+
+class ScrollingMomentumCalculator;
+
+class ScrollAnimationMomentum final : public ScrollAnimation {
+public:
+ ScrollAnimationMomentum(ScrollAnimationClient&);
+ virtual ~ScrollAnimationMomentum();
+
+ bool startAnimatedScrollWithInitialVelocity(const FloatPoint& initialOffset, const FloatSize& initialVelocity, const FloatSize& initialDelta, const WTF::Function<FloatPoint(const FloatPoint&)>& destinationModifier);
+
+ bool retargetActiveAnimation(const FloatPoint& newDestination) final;
+ void stop() final;
+ bool isActive() const final;
+ FloatPoint serviceAnimation(MonotonicTime) final;
+ void updateScrollExtents() final;
+
+private:
+ std::unique_ptr<ScrollingMomentumCalculator> m_momentumCalculator;
+
+ MonotonicTime m_startTime;
+ bool m_animationComplete { false };
+};
+
+} // namespace WebCore
Modified: trunk/Source/WebCore/platform/ScrollAnimationSmooth.cpp (282797 => 282798)
--- trunk/Source/WebCore/platform/ScrollAnimationSmooth.cpp 2021-09-21 01:51:09 UTC (rev 282797)
+++ trunk/Source/WebCore/platform/ScrollAnimationSmooth.cpp 2021-09-21 04:01:10 UTC (rev 282798)
@@ -39,7 +39,9 @@
namespace WebCore {
+static const double frameRate = 60;
static const float animationSpeed { 1000.0f };
+static constexpr Seconds minimumTimerInterval { 1_ms };
static const Seconds maxAnimationDuration { 200_ms };
ScrollAnimationSmooth::ScrollAnimationSmooth(ScrollAnimationClient& client)
Modified: trunk/Source/WebCore/platform/ScrollSnapAnimatorState.cpp (282797 => 282798)
--- trunk/Source/WebCore/platform/ScrollSnapAnimatorState.cpp 2021-09-21 01:51:09 UTC (rev 282797)
+++ trunk/Source/WebCore/platform/ScrollSnapAnimatorState.cpp 2021-09-21 04:01:10 UTC (rev 282798)
@@ -26,11 +26,14 @@
#include "config.h"
#include "ScrollSnapAnimatorState.h"
+#include "ScrollAnimationMomentum.h"
#include <wtf/MathExtras.h>
#include <wtf/text/TextStream.h>
namespace WebCore {
+ScrollSnapAnimatorState::~ScrollSnapAnimatorState() = default;
+
bool ScrollSnapAnimatorState::transitionToSnapAnimationState(const ScrollExtents& scrollExtents, float pageScale, const FloatPoint& initialOffset)
{
return setupAnimationForState(ScrollSnapState::Snapping, scrollExtents, pageScale, initialOffset, { }, { });
@@ -47,21 +50,26 @@
if (m_currentState == state)
return false;
- m_momentumCalculator = ScrollingMomentumCalculator::create(scrollExtents, initialOffset, initialDelta, initialVelocity);
- FloatPoint predictedScrollTarget { m_momentumCalculator->predictedDestinationOffset() };
+ m_scrollExtents = scrollExtents;
- float targetOffsetX, targetOffsetY;
- std::tie(targetOffsetX, m_activeSnapIndexX) = targetOffsetForStartOffset(ScrollEventAxis::Horizontal, scrollExtents, initialOffset.x(), predictedScrollTarget, pageScale, initialDelta.width());
- std::tie(targetOffsetY, m_activeSnapIndexY) = targetOffsetForStartOffset(ScrollEventAxis::Vertical, scrollExtents, initialOffset.y(), predictedScrollTarget, pageScale, initialDelta.height());
- auto targetOffset = FloatPoint { targetOffsetX, targetOffsetY };
- m_momentumCalculator->setRetargetedScrollOffset(targetOffset);
+ if (m_momentumScrollAnimation)
+ m_momentumScrollAnimation->stop();
- if (targetOffset == initialOffset)
+ m_momentumScrollAnimation = WTF::makeUnique<ScrollAnimationMomentum>(*this);
+ bool animating = m_momentumScrollAnimation->startAnimatedScrollWithInitialVelocity(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());
+
+ return FloatPoint { targetOffsetX, targetOffsetY };
+ });
+
+ if (!animating)
return false;
m_startTime = MonotonicTime::now();
m_currentState = state;
- return true;
+ return animating;
}
void ScrollSnapAnimatorState::transitionToUserInteractionState()
@@ -80,21 +88,22 @@
if (m_currentState == state)
return;
- m_momentumCalculator = nullptr;
- m_startTime = MonotonicTime();
+ m_momentumScrollAnimation = nullptr;
+ m_startTime = { };
m_currentState = state;
}
FloatPoint ScrollSnapAnimatorState::currentAnimatedScrollOffset(MonotonicTime currentTime, bool& isAnimationComplete) const
{
- if (!m_momentumCalculator) {
+ if (!m_momentumScrollAnimation) {
isAnimationComplete = true;
return { };
}
- Seconds elapsedTime = currentTime - m_startTime;
- isAnimationComplete = elapsedTime >= m_momentumCalculator->animationDuration();
- return m_momentumCalculator->scrollOffsetAfterElapsedTime(elapsedTime);
+ 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
@@ -111,6 +120,11 @@
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 (282797 => 282798)
--- trunk/Source/WebCore/platform/ScrollSnapAnimatorState.h 2021-09-21 01:51:09 UTC (rev 282797)
+++ trunk/Source/WebCore/platform/ScrollSnapAnimatorState.h 2021-09-21 04:01:10 UTC (rev 282798)
@@ -29,9 +29,9 @@
#include "FloatSize.h"
#include "LayoutPoint.h"
#include "PlatformWheelEvent.h"
+#include "ScrollAnimationMomentum.h"
#include "ScrollSnapOffsetsInfo.h"
#include "ScrollTypes.h"
-#include "ScrollingMomentumCalculator.h"
#include <wtf/MonotonicTime.h>
namespace WTF {
@@ -47,11 +47,11 @@
UserInteraction
};
-struct ScrollExtents;
-
-class ScrollSnapAnimatorState {
+class ScrollSnapAnimatorState : public ScrollAnimationClient {
WTF_MAKE_FAST_ALLOCATED;
public:
+ virtual ~ScrollSnapAnimatorState();
+
const Vector<SnapOffset<LayoutUnit>>& snapOffsetsForAxis(ScrollEventAxis axis) const
{
return axis == ScrollEventAxis::Horizontal ? m_snapOffsetsInfo.horizontalSnapOffsets : m_snapOffsetsInfo.verticalSnapOffsets;
@@ -90,15 +90,20 @@
bool setupAnimationForState(ScrollSnapState, const ScrollExtents&, float pageScale, const FloatPoint& initialOffset, const FloatSize& initialVelocity, const FloatSize& initialDelta);
void teardownAnimationForState(ScrollSnapState);
+ // ScrollAnimationClient.
+ ScrollExtents scrollExtentsForAnimation(ScrollAnimation&) final;
+
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<ScrollingMomentumCalculator> m_momentumCalculator;
+ std::unique_ptr<ScrollAnimationMomentum> m_momentumScrollAnimation;
};
WTF::TextStream& operator<<(WTF::TextStream&, const ScrollSnapAnimatorState&);
Modified: trunk/Source/WebCore/platform/ScrollingEffectsController.cpp (282797 => 282798)
--- trunk/Source/WebCore/platform/ScrollingEffectsController.cpp 2021-09-21 01:51:09 UTC (rev 282797)
+++ trunk/Source/WebCore/platform/ScrollingEffectsController.cpp 2021-09-21 04:01:10 UTC (rev 282798)
@@ -30,7 +30,6 @@
#include "LayoutSize.h"
#include "Logging.h"
#include "PlatformWheelEvent.h"
-#include "ScrollSnapAnimatorState.h"
#include "ScrollableArea.h"
#include "WheelEventTestMonitor.h"
#include <wtf/text/TextStream.h>
Modified: trunk/Source/WebCore/platform/ScrollingEffectsController.h (282797 => 282798)
--- trunk/Source/WebCore/platform/ScrollingEffectsController.h 2021-09-21 01:51:09 UTC (rev 282797)
+++ trunk/Source/WebCore/platform/ScrollingEffectsController.h 2021-09-21 04:01:10 UTC (rev 282798)
@@ -41,6 +41,7 @@
class KeyboardScrollingAnimator;
class LayoutSize;
class PlatformWheelEvent;
+class ScrollSnapAnimatorState;
class ScrollingEffectsController;
class ScrollableArea;
class WheelEventTestMonitor;
Modified: trunk/Source/WebCore/platform/mac/ScrollingEffectsController.mm (282797 => 282798)
--- trunk/Source/WebCore/platform/mac/ScrollingEffectsController.mm 2021-09-21 01:51:09 UTC (rev 282797)
+++ trunk/Source/WebCore/platform/mac/ScrollingEffectsController.mm 2021-09-21 04:01:10 UTC (rev 282798)
@@ -666,8 +666,8 @@
if (!usesScrollSnap())
return;
- m_scrollSnapState->transitionToSnapAnimationState(m_client.scrollExtents(), m_client.pageScaleFactor(), m_client.scrollOffset());
- startScrollSnapAnimation();
+ if (m_scrollSnapState->transitionToSnapAnimationState(m_client.scrollExtents(), m_client.pageScaleFactor(), m_client.scrollOffset()))
+ startScrollSnapAnimation();
}
void ScrollingEffectsController::startDeferringWheelEventTestCompletionDueToScrollSnapping()