Diff
Modified: trunk/Source/WebCore/ChangeLog (282732 => 282733)
--- trunk/Source/WebCore/ChangeLog 2021-09-19 00:56:15 UTC (rev 282732)
+++ trunk/Source/WebCore/ChangeLog 2021-09-19 02:55:42 UTC (rev 282733)
@@ -1,5 +1,26 @@
2021-09-18 Simon Fraser <[email protected]>
+ Move ScrollingMomentumCalculator into the platform directory
+ https://bugs.webkit.org/show_bug.cgi?id=230452
+
+ Reviewed by Wenson Hsieh.
+
+ ScrollingMomentumCalculator/ScrollingMomentumCalculatorMac have no non-platform dependencies.
+
+ Other changes are unified sources fallout.
+
+ * Sources.txt:
+ * SourcesCocoa.txt:
+ * WebCore.xcodeproj/project.pbxproj:
+ * platform/ScrollingMomentumCalculator.cpp: Renamed from Source/WebCore/page/scrolling/ScrollingMomentumCalculator.cpp.
+ * platform/ScrollingMomentumCalculator.h: Renamed from Source/WebCore/page/scrolling/ScrollingMomentumCalculator.h.
+ * platform/gamepad/mac/HIDGamepadElement.cpp:
+ * platform/graphics/Model.cpp:
+ * platform/mac/ScrollingMomentumCalculatorMac.h: Renamed from Source/WebCore/page/scrolling/mac/ScrollingMomentumCalculatorMac.h.
+ * platform/mac/ScrollingMomentumCalculatorMac.mm: Renamed from Source/WebCore/page/scrolling/mac/ScrollingMomentumCalculatorMac.mm.
+
+2021-09-18 Simon Fraser <[email protected]>
+
Scroll offsets in ScrollingMomentumCalculator should be FloatPoint, not FloatSize
https://bugs.webkit.org/show_bug.cgi?id=230451
Modified: trunk/Source/WebCore/Headers.cmake (282732 => 282733)
--- trunk/Source/WebCore/Headers.cmake 2021-09-19 00:56:15 UTC (rev 282732)
+++ trunk/Source/WebCore/Headers.cmake 2021-09-19 02:55:42 UTC (rev 282733)
@@ -1015,7 +1015,6 @@
page/scrolling/ScrollingConstraints.h
page/scrolling/ScrollingCoordinator.h
page/scrolling/ScrollingCoordinatorTypes.h
- page/scrolling/ScrollingMomentumCalculator.h
page/scrolling/ScrollingStateFixedNode.h
page/scrolling/ScrollingStateFrameHostingNode.h
page/scrolling/ScrollingStateFrameScrollingNode.h
@@ -1140,6 +1139,7 @@
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 (282732 => 282733)
--- trunk/Source/WebCore/Sources.txt 2021-09-19 00:56:15 UTC (rev 282732)
+++ trunk/Source/WebCore/Sources.txt 2021-09-19 02:55:42 UTC (rev 282733)
@@ -1754,7 +1754,6 @@
page/scrolling/ScrollLatchingController.cpp
page/scrolling/ScrollingConstraints.cpp
page/scrolling/ScrollingCoordinator.cpp
-page/scrolling/ScrollingMomentumCalculator.cpp
page/scrolling/ScrollingStateFixedNode.cpp
page/scrolling/ScrollingStateFrameHostingNode.cpp
page/scrolling/ScrollingStateFrameScrollingNode.cpp
@@ -1834,6 +1833,7 @@
platform/ScrollbarsController.cpp
platform/ScrollbarTheme.cpp
platform/ScrollbarThemeComposite.cpp
+platform/ScrollingMomentumCalculator.cpp
platform/SerializedPlatformDataCue.cpp
platform/SharedBuffer.cpp
platform/SharedBufferChunkReader.cpp
Modified: trunk/Source/WebCore/SourcesCocoa.txt (282732 => 282733)
--- trunk/Source/WebCore/SourcesCocoa.txt 2021-09-19 00:56:15 UTC (rev 282732)
+++ trunk/Source/WebCore/SourcesCocoa.txt 2021-09-19 02:55:42 UTC (rev 282733)
@@ -209,7 +209,6 @@
page/scrolling/cocoa/ScrollingTreePositionedNode.mm
page/scrolling/cocoa/ScrollingTreeStickyNode.mm
page/scrolling/mac/ScrollingCoordinatorMac.mm
-page/scrolling/mac/ScrollingMomentumCalculatorMac.mm
page/scrolling/mac/ScrollingStateScrollingNodeMac.mm
page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm
page/scrolling/mac/ScrollingTreeMac.mm
@@ -493,6 +492,7 @@
platform/mac/ScrollViewMac.mm
platform/mac/ScrollbarsControllerMac.mm @no-unify
platform/mac/ScrollbarThemeMac.mm @no-unify
+platform/mac/ScrollingMomentumCalculatorMac.mm
platform/mac/SerializedPlatformDataCueMac.mm
platform/mac/StringUtilities.mm
platform/mac/SuddenTermination.mm
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (282732 => 282733)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2021-09-19 00:56:15 UTC (rev 282732)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2021-09-19 02:55:42 UTC (rev 282733)
@@ -350,6 +350,8 @@
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, ); }; };
+ 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, ); }; };
0FA61B0E26F43213001AADB6 /* ScrollAnimation.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FA61B0C26F43212001AADB6 /* ScrollAnimation.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -1586,7 +1588,6 @@
517A63C51B74318F00E7DCDC /* KeyedDecoderCF.h in Headers */ = {isa = PBXBuildFile; fileRef = 517A63C01B74317E00E7DCDC /* KeyedDecoderCF.h */; settings = {ATTRIBUTES = (Private, ); }; };
517A63C61B74319200E7DCDC /* KeyedEncoderCF.h in Headers */ = {isa = PBXBuildFile; fileRef = 517A63C21B74317E00E7DCDC /* KeyedEncoderCF.h */; settings = {ATTRIBUTES = (Private, ); }; };
517B25AA1CC82B2A0061C011 /* IDBConnectionProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 517B25A81CC820320061C011 /* IDBConnectionProxy.h */; settings = {ATTRIBUTES = (Private, ); }; };
- 517DEEE81DE94B0800B91644 /* ScrollingMomentumCalculatorMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 517DEEE71DE94B0800B91644 /* ScrollingMomentumCalculatorMac.h */; settings = {ATTRIBUTES = (Private, ); }; };
517E03F724B6D9840054895A /* MultiGamepadProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 517E03F424B6B9630054895A /* MultiGamepadProvider.h */; settings = {ATTRIBUTES = (Private, ); }; };
5182C2561F3143CD0059BA7C /* JSServiceWorker.h in Headers */ = {isa = PBXBuildFile; fileRef = 5182C2521F3142500059BA7C /* JSServiceWorker.h */; };
5182C2581F3143CD0059BA7C /* JSServiceWorkerContainer.h in Headers */ = {isa = PBXBuildFile; fileRef = 5182C2541F3142500059BA7C /* JSServiceWorkerContainer.h */; };
@@ -1648,7 +1649,6 @@
51BCCE301F8F179E006BA0ED /* ServiceWorkerThread.h in Headers */ = {isa = PBXBuildFile; fileRef = 517C87101F8EE72E00EB8076 /* ServiceWorkerThread.h */; settings = {ATTRIBUTES = (Private, ); }; };
51BE37E00DAEE00E001085FC /* StorageArea.h in Headers */ = {isa = PBXBuildFile; fileRef = 51BE37DE0DAEE00E001085FC /* StorageArea.h */; settings = {ATTRIBUTES = (Private, ); }; };
51C0AA390F2AA10A001648C2 /* CachedFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 51C0AA380F2AA10A001648C2 /* CachedFrame.h */; settings = {ATTRIBUTES = (Private, ); }; };
- 51C61B0B1DE536E7008A212D /* ScrollingMomentumCalculator.h in Headers */ = {isa = PBXBuildFile; fileRef = 51C61B091DE536E7008A212D /* ScrollingMomentumCalculator.h */; settings = {ATTRIBUTES = (Private, ); }; };
51C81B8A0C4422F70019ECE3 /* FTPDirectoryParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 51C81B880C4422F70019ECE3 /* FTPDirectoryParser.h */; };
51CA7EE91F883390003D3131 /* ServiceWorkerContextData.h in Headers */ = {isa = PBXBuildFile; fileRef = 51CA7EE71F8832E0003D3131 /* ServiceWorkerContextData.h */; settings = {ATTRIBUTES = (Private, ); }; };
51CBFC990D10E483002DBF51 /* CachedFramePlatformData.h in Headers */ = {isa = PBXBuildFile; fileRef = 51CBFC980D10E483002DBF51 /* CachedFramePlatformData.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -6334,6 +6334,10 @@
0F9510F024F4769C001F52DC /* ScrollLatchingController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ScrollLatchingController.h; sourceTree = "<group>"; };
0F9510F224F4769C001F52DC /* ScrollLatchingController.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollLatchingController.cpp; sourceTree = "<group>"; };
0F97A657155DA81E00FADD4C /* DisplayRefreshMonitorIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DisplayRefreshMonitorIOS.mm; sourceTree = "<group>"; };
+ 0F99059826F6BE7F0054FBE0 /* ScrollingMomentumCalculator.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollingMomentumCalculator.cpp; sourceTree = "<group>"; };
+ 0F99059926F6BE7F0054FBE0 /* ScrollingMomentumCalculator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ScrollingMomentumCalculator.h; sourceTree = "<group>"; };
+ 0F99059B26F6BE940054FBE0 /* ScrollingMomentumCalculatorMac.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ScrollingMomentumCalculatorMac.h; sourceTree = "<group>"; };
+ 0F99059C26F6BE950054FBE0 /* ScrollingMomentumCalculatorMac.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ScrollingMomentumCalculatorMac.mm; sourceTree = "<group>"; };
0F9B547522B4A772007B5E8A /* ScrollingStateOverflowScrollProxyNode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ScrollingStateOverflowScrollProxyNode.h; sourceTree = "<group>"; };
0F9B547622B4A773007B5E8A /* ScrollingStateOverflowScrollProxyNode.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollingStateOverflowScrollProxyNode.cpp; sourceTree = "<group>"; };
0F9DAA0C1FD1C6630079C5B2 /* DOMGCOutputConstraint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DOMGCOutputConstraint.cpp; sourceTree = "<group>"; };
@@ -9055,8 +9059,6 @@
517C87101F8EE72E00EB8076 /* ServiceWorkerThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ServiceWorkerThread.h; path = workers/service/context/ServiceWorkerThread.h; sourceTree = SOURCE_ROOT; };
517C87111F8EE72F00EB8076 /* ServiceWorkerThread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ServiceWorkerThread.cpp; path = workers/service/context/ServiceWorkerThread.cpp; sourceTree = SOURCE_ROOT; };
517C87161F8FD4D300EB8076 /* ServiceWorkerContextData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerContextData.cpp; sourceTree = "<group>"; };
- 517DEEE31DE94ADC00B91644 /* ScrollingMomentumCalculatorMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ScrollingMomentumCalculatorMac.mm; sourceTree = "<group>"; };
- 517DEEE71DE94B0800B91644 /* ScrollingMomentumCalculatorMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollingMomentumCalculatorMac.h; sourceTree = "<group>"; };
517E03F424B6B9630054895A /* MultiGamepadProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MultiGamepadProvider.h; sourceTree = "<group>"; };
517E03F524B6B9640054895A /* MultiGamepadProvider.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MultiGamepadProvider.mm; sourceTree = "<group>"; };
517FBA17151AA71B00B57959 /* DOMWindowExtension.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DOMWindowExtension.cpp; sourceTree = "<group>"; };
@@ -9139,8 +9141,6 @@
51BE37DE0DAEE00E001085FC /* StorageArea.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StorageArea.h; sourceTree = "<group>"; };
51C0AA380F2AA10A001648C2 /* CachedFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CachedFrame.h; sourceTree = "<group>"; };
51C0AA400F2AA15E001648C2 /* CachedFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CachedFrame.cpp; sourceTree = "<group>"; };
- 51C61B081DE536E7008A212D /* ScrollingMomentumCalculator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollingMomentumCalculator.cpp; sourceTree = "<group>"; };
- 51C61B091DE536E7008A212D /* ScrollingMomentumCalculator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollingMomentumCalculator.h; sourceTree = "<group>"; };
51C81B870C4422F70019ECE3 /* FTPDirectoryParser.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = FTPDirectoryParser.cpp; sourceTree = "<group>"; };
51C81B880C4422F70019ECE3 /* FTPDirectoryParser.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FTPDirectoryParser.h; sourceTree = "<group>"; };
51CA7EE71F8832E0003D3131 /* ServiceWorkerContextData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerContextData.h; sourceTree = "<group>"; };
@@ -18868,8 +18868,6 @@
1AF62EE414DA22A70041556C /* ScrollingCoordinator.cpp */,
1AF62EE514DA22A70041556C /* ScrollingCoordinator.h */,
712DBA4721F8AD79008F36B2 /* ScrollingCoordinatorTypes.h */,
- 51C61B081DE536E7008A212D /* ScrollingMomentumCalculator.cpp */,
- 51C61B091DE536E7008A212D /* ScrollingMomentumCalculator.h */,
93C38BFC164473C700091EB2 /* ScrollingStateFixedNode.cpp */,
93C38BFD164473C700091EB2 /* ScrollingStateFixedNode.h */,
0FD41E6321F80260000C006D /* ScrollingStateFrameHostingNode.cpp */,
@@ -18925,8 +18923,6 @@
children = (
9391A990162746CB00297330 /* ScrollingCoordinatorMac.h */,
1AF62EE314DA22A70041556C /* ScrollingCoordinatorMac.mm */,
- 517DEEE71DE94B0800B91644 /* ScrollingMomentumCalculatorMac.h */,
- 517DEEE31DE94ADC00B91644 /* ScrollingMomentumCalculatorMac.mm */,
0F73B765222B327F00805316 /* ScrollingStateScrollingNodeMac.mm */,
93C4A4131629DF5A00C3EB6E /* ScrollingTreeFrameScrollingNodeMac.h */,
93C4A4141629DF5A00C3EB6E /* ScrollingTreeFrameScrollingNodeMac.mm */,
@@ -22180,6 +22176,8 @@
BC8B853C0E7C7F1100AB6984 /* ScrollbarThemeMac.h */,
BCEF869E0E844E9D00A85CD5 /* ScrollbarThemeMac.mm */,
5B1E0E4325D1629B00272281 /* ScrollingEffectsController.mm */,
+ 0F99059B26F6BE940054FBE0 /* ScrollingMomentumCalculatorMac.h */,
+ 0F99059C26F6BE950054FBE0 /* ScrollingMomentumCalculatorMac.mm */,
9353676A09AED88B00D35CD6 /* ScrollViewMac.mm */,
077AF14118F4B1BB0001ED61 /* SerializedPlatformDataCueMac.h */,
077AF14218F4B1BB0001ED61 /* SerializedPlatformDataCueMac.mm */,
@@ -28157,6 +28155,8 @@
BC1402890E83680800319717 /* ScrollbarThemeComposite.h */,
5B46655E25D14C09000CFE14 /* ScrollingEffectsController.cpp */,
5B46655F25D14C09000CFE14 /* ScrollingEffectsController.h */,
+ 0F99059826F6BE7F0054FBE0 /* ScrollingMomentumCalculator.cpp */,
+ 0F99059926F6BE7F0054FBE0 /* ScrollingMomentumCalculator.h */,
5B46655D25D14C09000CFE14 /* ScrollSnapAnimatorState.cpp */,
5B46656025D14C0A000CFE14 /* ScrollSnapAnimatorState.h */,
0F4CDEAA23D91A8A00251B02 /* ScrollTypes.cpp */,
@@ -34943,8 +34943,8 @@
9391A991162746CB00297330 /* ScrollingCoordinatorMac.h in Headers */,
712DBA4921F8AD83008F36B2 /* ScrollingCoordinatorTypes.h in Headers */,
5B46656325D14C0A000CFE14 /* ScrollingEffectsController.h in Headers */,
- 51C61B0B1DE536E7008A212D /* ScrollingMomentumCalculator.h in Headers */,
- 517DEEE81DE94B0800B91644 /* ScrollingMomentumCalculatorMac.h in Headers */,
+ 0F99059A26F6BE850054FBE0 /* ScrollingMomentumCalculator.h in Headers */,
+ 0F99059D26F6BE9A0054FBE0 /* ScrollingMomentumCalculatorMac.h in Headers */,
93C38BFF164473C700091EB2 /* ScrollingStateFixedNode.h in Headers */,
0FD41E6921F80D14000C006D /* ScrollingStateFrameHostingNode.h in Headers */,
0FEA3E7B191B2FC5000F1B55 /* ScrollingStateFrameScrollingNode.h in Headers */,
Deleted: trunk/Source/WebCore/page/scrolling/ScrollingMomentumCalculator.cpp (282732 => 282733)
--- trunk/Source/WebCore/page/scrolling/ScrollingMomentumCalculator.cpp 2021-09-19 00:56:15 UTC (rev 282732)
+++ trunk/Source/WebCore/page/scrolling/ScrollingMomentumCalculator.cpp 2021-09-19 02:55:42 UTC (rev 282733)
@@ -1,235 +0,0 @@
-/*
- * Copyright (C) 2016 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 "ScrollingMomentumCalculator.h"
-
-#include "FloatPoint.h"
-#include "FloatSize.h"
-
-namespace WebCore {
-
-static const Seconds scrollSnapAnimationDuration = 1_s;
-static inline float projectedInertialScrollDistance(float initialWheelDelta)
-{
- // On macOS 10.10 and earlier, we don't have a platform scrolling momentum calculator, so we instead approximate the scroll destination
- // by multiplying the initial wheel delta by a constant factor. By running a few experiments (i.e. logging scroll destination and initial
- // wheel delta for many scroll gestures) we determined that this is a reasonable way to approximate where scrolling will take us without
- // using _NSScrollingMomentumCalculator.
- static constexpr double inertialScrollPredictionFactor = 16.7;
- return inertialScrollPredictionFactor * initialWheelDelta;
-}
-
-ScrollingMomentumCalculator::ScrollingMomentumCalculator(const FloatSize& viewportSize, const FloatSize& contentSize, const FloatPoint& initialOffset, const FloatSize& initialDelta, const FloatSize& initialVelocity)
- : m_initialDelta(initialDelta)
- , m_initialVelocity(initialVelocity)
- , m_initialScrollOffset(initialOffset)
- , m_viewportSize(viewportSize)
- , m_contentSize(contentSize)
-{
-}
-
-void ScrollingMomentumCalculator::setRetargetedScrollOffset(const FloatPoint& target)
-{
- if (m_retargetedScrollOffset && m_retargetedScrollOffset == target)
- return;
-
- m_retargetedScrollOffset = target;
- retargetedScrollOffsetDidChange();
-}
-
-FloatPoint ScrollingMomentumCalculator::predictedDestinationOffset()
-{
- float initialOffsetX = clampTo<float>(m_initialScrollOffset.x() + projectedInertialScrollDistance(m_initialDelta.width()), 0, m_contentSize.width() - m_viewportSize.width());
- float initialOffsetY = clampTo<float>(m_initialScrollOffset.y() + projectedInertialScrollDistance(m_initialDelta.height()), 0, m_contentSize.height() - m_viewportSize.height());
- return { initialOffsetX, initialOffsetY };
-}
-
-#if !PLATFORM(MAC)
-
-std::unique_ptr<ScrollingMomentumCalculator> ScrollingMomentumCalculator::create(const FloatSize& viewportSize, const FloatSize& contentSize, const FloatPoint& initialOffset, const FloatSize& initialDelta, const FloatSize& initialVelocity)
-{
- return makeUnique<BasicScrollingMomentumCalculator>(viewportSize, contentSize, initialOffset, initialDelta, initialVelocity);
-}
-
-void ScrollingMomentumCalculator::setPlatformMomentumScrollingPredictionEnabled(bool)
-{
-}
-
-#endif
-
-BasicScrollingMomentumCalculator::BasicScrollingMomentumCalculator(const FloatSize& viewportSize, const FloatSize& contentSize, const FloatPoint& initialOffset, const FloatSize& initialDelta, const FloatSize& initialVelocity)
- : ScrollingMomentumCalculator(viewportSize, contentSize, initialOffset, initialDelta, initialVelocity)
-{
-}
-
-FloatPoint BasicScrollingMomentumCalculator::linearlyInterpolatedOffsetAtProgress(float progress)
-{
- return m_initialScrollOffset + progress * (retargetedScrollOffset() - m_initialScrollOffset);
-}
-
-FloatPoint BasicScrollingMomentumCalculator::cubicallyInterpolatedOffsetAtProgress(float progress) const
-{
- ASSERT(!m_forceLinearAnimationCurve);
- FloatPoint interpolatedPoint;
- for (int i = 0; i < 4; ++i)
- interpolatedPoint += std::pow(progress, i) * m_snapAnimationCurveCoefficients[i];
-
- return interpolatedPoint;
-}
-
-FloatPoint BasicScrollingMomentumCalculator::scrollOffsetAfterElapsedTime(Seconds elapsedTime)
-{
- if (m_momentumCalculatorRequiresInitialization) {
- initializeSnapProgressCurve();
- initializeInterpolationCoefficientsIfNecessary();
- m_momentumCalculatorRequiresInitialization = false;
- }
-
- float progress = animationProgressAfterElapsedTime(elapsedTime);
- return m_forceLinearAnimationCurve ? linearlyInterpolatedOffsetAtProgress(progress) : cubicallyInterpolatedOffsetAtProgress(progress);
-}
-
-Seconds BasicScrollingMomentumCalculator::animationDuration()
-{
- return scrollSnapAnimationDuration;
-}
-
-/**
- * Computes and sets coefficients required for interpolated snapping when scrolling in 2 dimensions, given
- * initial conditions (the initial and target vectors, along with the initial wheel delta as a vector). The
- * path is a cubic Bezier curve of the form p(s) = INITIAL + (C_1 * s) + (C_2 * s^2) + (C_3 * s^3) where each
- * C_i is a 2D vector and INITIAL is the vector representing the initial scroll offset. s is a real in the
- * interval [0, 1] indicating the "progress" of the curve (i.e. how much of the curve has been traveled).
- *
- * The curve has 4 control points, the first and last of which are the initial and target points, respectively.
- * The distances between adjacent control points are constrained to be the same, making the convex hull an
- * isosceles trapezoid with 3 sides of equal length. Additionally, the vector from the first control point to
- * the second points in the same direction as the initial scroll delta. These constraints ensure two properties:
- * 1. The direction of the snap animation at s=0 will be equal to the direction of the initial scroll delta.
- * 2. Points at regular intervals of s will be evenly spread out.
- *
- * If the initial scroll direction is orthogonal to or points in the opposite direction as the vector from the
- * initial point to the target point, initialization returns early and sets the curve to animate directly to the
- * snap point without cubic interpolation.
- *
- * FIXME: This should be refactored to use UnitBezier.
- */
-void BasicScrollingMomentumCalculator::initializeInterpolationCoefficientsIfNecessary()
-{
- m_forceLinearAnimationCurve = true;
- float initialDeltaMagnitude = m_initialDelta.diagonalLength();
- if (initialDeltaMagnitude < 1) {
- // The initial wheel delta is so insignificant that we're better off considering this to have the same effect as finishing a scroll gesture with no momentum.
- // Thus, cubic interpolation isn't needed here.
- return;
- }
-
- FloatSize startToEndVector = retargetedScrollOffset() - m_initialScrollOffset;
- float startToEndDistance = startToEndVector.diagonalLength();
- if (!startToEndDistance) {
- // The start and end positions are the same, so we shouldn't try to interpolate a path.
- return;
- }
-
- float cosTheta = (m_initialDelta.width() * startToEndVector.width() + m_initialDelta.height() * startToEndVector.height()) / (initialDeltaMagnitude * startToEndDistance);
- if (cosTheta <= 0) {
- // It's possible that the user is not scrolling towards the target snap offset (for instance, scrolling against a corner when 2D scroll snapping).
- // In this case, just let the scroll offset animate to the target without computing a cubic curve.
- return;
- }
-
- float sideLength = startToEndDistance / (2.0f * cosTheta + 1.0f);
- auto initialOffsetAsSize = toFloatSize(m_initialScrollOffset);
- FloatSize controlVector1 = initialOffsetAsSize + sideLength * m_initialDelta / initialDeltaMagnitude;
- FloatSize controlVector2 = controlVector1 + (sideLength * startToEndVector / startToEndDistance);
- m_snapAnimationCurveCoefficients[0] = initialOffsetAsSize;
- m_snapAnimationCurveCoefficients[1] = 3 * (controlVector1 - initialOffsetAsSize);
- m_snapAnimationCurveCoefficients[2] = 3 * (initialOffsetAsSize - 2 * controlVector1 + controlVector2);
- m_snapAnimationCurveCoefficients[3] = 3 * (controlVector1 - controlVector2) - initialOffsetAsSize + toFloatSize(retargetedScrollOffset());
- m_forceLinearAnimationCurve = false;
-}
-
-static const float framesPerSecond = 60.0f;
-
-/**
- * Computes and sets parameters required for tracking the progress of a snap animation curve, interpolated
- * or linear. The progress curve s(t) maps time t to progress s; both variables are in the interval [0, 1].
- * The time input t is 0 when the current time is the start of the animation, t = 0, and 1 when the current
- * time is at or after the end of the animation, t = m_scrollSnapAnimationDuration.
- *
- * In this exponential progress model, s(t) = A - A * b^(-kt), where k = 60T is the number of frames in the
- * animation (assuming 60 FPS and an animation duration of T) and A, b are reals greater than or equal to 1.
- * Also note that we are given the initial progress, a value indicating the portion of the curve which our
- * initial scroll delta takes us. This is important when matching the initial speed of the animation to the
- * user's initial momentum scrolling speed. Let this initial progress amount equal v_0. I clamp this initial
- * progress amount to a minimum or maximum value.
- *
- * A is referred to as the curve magnitude, while b is referred to as the decay factor. We solve for A and b,
- * keeping the following constraints in mind:
- * 1. s(0) = 0
- * 2. s(1) = 1
- * 3. s(1/k) = v_0
- *
- * First, observe that s(0) = 0 holds for appropriate values of A, b. Solving for the remaining constraints
- * yields a nonlinear system of two equations. In lieu of a purely analytical solution, an alternating
- * optimization scheme is used to approximate A and b. This technique converges quickly (within 5 iterations
- * or so) for appropriate values of v_0. The optimization terminates early when the decay factor changes by
- * less than a threshold between one iteration and the next.
- */
-void BasicScrollingMomentumCalculator::initializeSnapProgressCurve()
-{
- static const int maxNumScrollSnapParameterEstimationIterations = 10;
- static const float scrollSnapDecayFactorConvergenceThreshold = 0.001;
- static const float initialScrollSnapCurveMagnitude = 1.1;
- static const float minScrollSnapInitialProgress = 0.1;
- static const float maxScrollSnapInitialProgress = 0.5;
-
- FloatSize alignmentVector = m_initialDelta * (retargetedScrollOffset() - m_initialScrollOffset);
- float initialProgress;
- if (alignmentVector.width() + alignmentVector.height() > 0)
- initialProgress = clampTo(m_initialDelta.diagonalLength() / (retargetedScrollOffset() - m_initialScrollOffset).diagonalLength(), minScrollSnapInitialProgress, maxScrollSnapInitialProgress);
- else
- initialProgress = minScrollSnapInitialProgress;
-
- float previousDecayFactor = 1.0f;
- m_snapAnimationCurveMagnitude = initialScrollSnapCurveMagnitude;
- for (int i = 0; i < maxNumScrollSnapParameterEstimationIterations; ++i) {
- m_snapAnimationDecayFactor = m_snapAnimationCurveMagnitude / (m_snapAnimationCurveMagnitude - initialProgress);
- m_snapAnimationCurveMagnitude = 1.0f / (1.0f - std::pow(m_snapAnimationDecayFactor, -framesPerSecond * scrollSnapAnimationDuration.value()));
- if (std::abs(m_snapAnimationDecayFactor - previousDecayFactor) < scrollSnapDecayFactorConvergenceThreshold)
- break;
-
- previousDecayFactor = m_snapAnimationDecayFactor;
- }
-}
-
-float BasicScrollingMomentumCalculator::animationProgressAfterElapsedTime(Seconds elapsedTime) const
-{
- float timeProgress = clampTo<float>(elapsedTime / scrollSnapAnimationDuration, 0, 1);
- return std::min(1.0, m_snapAnimationCurveMagnitude * (1.0 - std::pow(m_snapAnimationDecayFactor, -framesPerSecond * scrollSnapAnimationDuration.value() * timeProgress)));
-}
-
-}; // namespace WebCore
Deleted: trunk/Source/WebCore/page/scrolling/ScrollingMomentumCalculator.h (282732 => 282733)
--- trunk/Source/WebCore/page/scrolling/ScrollingMomentumCalculator.h 2021-09-19 00:56:15 UTC (rev 282732)
+++ trunk/Source/WebCore/page/scrolling/ScrollingMomentumCalculator.h 2021-09-19 02:55:42 UTC (rev 282733)
@@ -1,87 +0,0 @@
-/*
- * Copyright (C) 2016 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 "PlatformWheelEvent.h"
-#include "ScrollTypes.h"
-#include <wtf/Seconds.h>
-
-namespace WebCore {
-
-class FloatPoint;
-class FloatSize;
-
-class ScrollingMomentumCalculator {
- WTF_MAKE_FAST_ALLOCATED;
-public:
- WEBCORE_EXPORT static void setPlatformMomentumScrollingPredictionEnabled(bool);
-
- static std::unique_ptr<ScrollingMomentumCalculator> create(const FloatSize& viewportSize, const FloatSize& contentSize, const FloatPoint& initialOffset, const FloatSize& initialDelta, const FloatSize& initialVelocity);
-
- ScrollingMomentumCalculator(const FloatSize& viewportSize, const FloatSize& contentSize, const FloatPoint& initialOffset, const FloatSize& initialDelta, const FloatSize& initialVelocity);
- virtual ~ScrollingMomentumCalculator() = default;
-
- virtual FloatPoint scrollOffsetAfterElapsedTime(Seconds) = 0;
- virtual Seconds animationDuration() = 0;
- virtual FloatPoint predictedDestinationOffset();
- void setRetargetedScrollOffset(const FloatPoint&);
-
-protected:
- const FloatPoint& retargetedScrollOffset() const { return m_retargetedScrollOffset.value(); }
- virtual void retargetedScrollOffsetDidChange() { }
-
- FloatSize m_initialDelta;
- FloatSize m_initialVelocity;
- FloatPoint m_initialScrollOffset;
- FloatSize m_viewportSize;
- FloatSize m_contentSize;
-
-private:
- std::optional<FloatPoint> m_retargetedScrollOffset;
-};
-
-class BasicScrollingMomentumCalculator final : public ScrollingMomentumCalculator {
-public:
- BasicScrollingMomentumCalculator(const FloatSize& viewportSize, const FloatSize& contentSize, const FloatPoint& initialOffset, const FloatSize& initialDelta, const FloatSize& initialVelocity);
-
-private:
- FloatPoint scrollOffsetAfterElapsedTime(Seconds) final;
- Seconds animationDuration() final;
- void initializeInterpolationCoefficientsIfNecessary();
- void initializeSnapProgressCurve();
- float animationProgressAfterElapsedTime(Seconds) const;
- FloatPoint linearlyInterpolatedOffsetAtProgress(float progress);
- FloatPoint cubicallyInterpolatedOffsetAtProgress(float progress) const;
-
- float m_snapAnimationCurveMagnitude { 0 };
- float m_snapAnimationDecayFactor { 0 };
- FloatSize m_snapAnimationCurveCoefficients[4] { };
- bool m_forceLinearAnimationCurve { false };
- bool m_momentumCalculatorRequiresInitialization { true };
- std::optional<FloatSize> m_predictedDestinationOffset;
-};
-
-} // namespace WebCore
Deleted: trunk/Source/WebCore/page/scrolling/mac/ScrollingMomentumCalculatorMac.h (282732 => 282733)
--- trunk/Source/WebCore/page/scrolling/mac/ScrollingMomentumCalculatorMac.h 2021-09-19 00:56:15 UTC (rev 282732)
+++ trunk/Source/WebCore/page/scrolling/mac/ScrollingMomentumCalculatorMac.h 2021-09-19 02:55:42 UTC (rev 282733)
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2016 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 "ScrollingMomentumCalculator.h"
-#include <wtf/RetainPtr.h>
-
-@class _NSScrollingMomentumCalculator;
-
-namespace WebCore {
-
-class ScrollingMomentumCalculatorMac final : public ScrollingMomentumCalculator {
-public:
- ScrollingMomentumCalculatorMac(const FloatSize& viewportSize, const FloatSize& contentSize, const FloatPoint& initialOffset, const FloatSize& initialDelta, const FloatSize& initialVelocity);
-
-private:
- FloatPoint scrollOffsetAfterElapsedTime(Seconds) final;
- Seconds animationDuration() final;
- FloatPoint predictedDestinationOffset() final;
- void retargetedScrollOffsetDidChange() final;
-
- _NSScrollingMomentumCalculator *ensurePlatformMomentumCalculator();
- bool requiresMomentumScrolling();
-
- RetainPtr<_NSScrollingMomentumCalculator> m_platformMomentumCalculator;
- std::optional<bool> m_requiresMomentumScrolling;
- FloatPoint m_initialDestinationOrigin;
-};
-
-} // namespace WebCore
Deleted: trunk/Source/WebCore/page/scrolling/mac/ScrollingMomentumCalculatorMac.mm (282732 => 282733)
--- trunk/Source/WebCore/page/scrolling/mac/ScrollingMomentumCalculatorMac.mm 2021-09-19 00:56:15 UTC (rev 282732)
+++ trunk/Source/WebCore/page/scrolling/mac/ScrollingMomentumCalculatorMac.mm 2021-09-19 02:55:42 UTC (rev 282733)
@@ -1,106 +0,0 @@
-/*
- * Copyright (C) 2016 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.
- */
-
-#import "config.h"
-#import "ScrollingMomentumCalculatorMac.h"
-
-#if PLATFORM(MAC)
-
-#import <pal/spi/mac/NSScrollingMomentumCalculatorSPI.h>
-
-namespace WebCore {
-
-static bool gEnablePlatformMomentumScrollingPrediction = true;
-
-std::unique_ptr<ScrollingMomentumCalculator> ScrollingMomentumCalculator::create(const FloatSize& viewportSize, const FloatSize& contentSize, const FloatPoint& initialOffset, const FloatSize& initialDelta, const FloatSize& initialVelocity)
-{
- return makeUnique<ScrollingMomentumCalculatorMac>(viewportSize, contentSize, initialOffset, initialDelta, initialVelocity);
-}
-
-void ScrollingMomentumCalculator::setPlatformMomentumScrollingPredictionEnabled(bool enabled)
-{
- gEnablePlatformMomentumScrollingPrediction = enabled;
-}
-
-ScrollingMomentumCalculatorMac::ScrollingMomentumCalculatorMac(const FloatSize& viewportSize, const FloatSize& contentSize, const FloatPoint& initialOffset, const FloatSize& initialDelta, const FloatSize& initialVelocity)
- : ScrollingMomentumCalculator(viewportSize, contentSize, initialOffset, initialDelta, initialVelocity)
-{
-}
-
-FloatPoint ScrollingMomentumCalculatorMac::scrollOffsetAfterElapsedTime(Seconds elapsedTime)
-{
- if (!requiresMomentumScrolling())
- return retargetedScrollOffset();
-
- return [ensurePlatformMomentumCalculator() positionAfterDuration:elapsedTime.value()];
-}
-
-FloatPoint ScrollingMomentumCalculatorMac::predictedDestinationOffset()
-{
- if (!gEnablePlatformMomentumScrollingPrediction)
- return ScrollingMomentumCalculator::predictedDestinationOffset();
-
- ensurePlatformMomentumCalculator();
- return { m_initialDestinationOrigin.x(), m_initialDestinationOrigin.y() };
-}
-
-void ScrollingMomentumCalculatorMac::retargetedScrollOffsetDidChange()
-{
- _NSScrollingMomentumCalculator *calculator = ensurePlatformMomentumCalculator();
- calculator.destinationOrigin = retargetedScrollOffset();
- [calculator calculateToReachDestination];
-}
-
-Seconds ScrollingMomentumCalculatorMac::animationDuration()
-{
- if (!requiresMomentumScrolling())
- return 0_s;
-
- return Seconds([ensurePlatformMomentumCalculator() durationUntilStop]);
-}
-
-bool ScrollingMomentumCalculatorMac::requiresMomentumScrolling()
-{
- if (m_requiresMomentumScrolling == std::nullopt)
- m_requiresMomentumScrolling = m_initialScrollOffset != retargetedScrollOffset() || m_initialVelocity.area();
- return m_requiresMomentumScrolling.value();
-}
-
-_NSScrollingMomentumCalculator *ScrollingMomentumCalculatorMac::ensurePlatformMomentumCalculator()
-{
- if (m_platformMomentumCalculator)
- return m_platformMomentumCalculator.get();
-
- NSPoint origin = m_initialScrollOffset;
- NSRect contentFrame = NSMakeRect(0, 0, m_contentSize.width(), m_contentSize.height());
- NSPoint velocity = NSMakePoint(m_initialVelocity.width(), m_initialVelocity.height());
- m_platformMomentumCalculator = adoptNS([[_NSScrollingMomentumCalculator alloc] initWithInitialOrigin:origin velocity:velocity documentFrame:contentFrame constrainedClippingOrigin:NSZeroPoint clippingSize:m_viewportSize tolerance:NSMakeSize(1, 1)]);
- m_initialDestinationOrigin = [m_platformMomentumCalculator destinationOrigin];
- return m_platformMomentumCalculator.get();
-}
-
-} // namespace WebCore
-
-#endif // PLATFORM(MAC)
Copied: trunk/Source/WebCore/platform/ScrollingMomentumCalculator.cpp (from rev 282732, trunk/Source/WebCore/page/scrolling/ScrollingMomentumCalculator.cpp) (0 => 282733)
--- trunk/Source/WebCore/platform/ScrollingMomentumCalculator.cpp (rev 0)
+++ trunk/Source/WebCore/platform/ScrollingMomentumCalculator.cpp 2021-09-19 02:55:42 UTC (rev 282733)
@@ -0,0 +1,235 @@
+/*
+ * Copyright (C) 2016 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 "ScrollingMomentumCalculator.h"
+
+#include "FloatPoint.h"
+#include "FloatSize.h"
+
+namespace WebCore {
+
+static const Seconds scrollSnapAnimationDuration = 1_s;
+static inline float projectedInertialScrollDistance(float initialWheelDelta)
+{
+ // On macOS 10.10 and earlier, we don't have a platform scrolling momentum calculator, so we instead approximate the scroll destination
+ // by multiplying the initial wheel delta by a constant factor. By running a few experiments (i.e. logging scroll destination and initial
+ // wheel delta for many scroll gestures) we determined that this is a reasonable way to approximate where scrolling will take us without
+ // using _NSScrollingMomentumCalculator.
+ static constexpr double inertialScrollPredictionFactor = 16.7;
+ return inertialScrollPredictionFactor * initialWheelDelta;
+}
+
+ScrollingMomentumCalculator::ScrollingMomentumCalculator(const FloatSize& viewportSize, const FloatSize& contentSize, const FloatPoint& initialOffset, const FloatSize& initialDelta, const FloatSize& initialVelocity)
+ : m_initialDelta(initialDelta)
+ , m_initialVelocity(initialVelocity)
+ , m_initialScrollOffset(initialOffset)
+ , m_viewportSize(viewportSize)
+ , m_contentSize(contentSize)
+{
+}
+
+void ScrollingMomentumCalculator::setRetargetedScrollOffset(const FloatPoint& target)
+{
+ if (m_retargetedScrollOffset && m_retargetedScrollOffset == target)
+ return;
+
+ m_retargetedScrollOffset = target;
+ retargetedScrollOffsetDidChange();
+}
+
+FloatPoint ScrollingMomentumCalculator::predictedDestinationOffset()
+{
+ float initialOffsetX = clampTo<float>(m_initialScrollOffset.x() + projectedInertialScrollDistance(m_initialDelta.width()), 0, m_contentSize.width() - m_viewportSize.width());
+ float initialOffsetY = clampTo<float>(m_initialScrollOffset.y() + projectedInertialScrollDistance(m_initialDelta.height()), 0, m_contentSize.height() - m_viewportSize.height());
+ return { initialOffsetX, initialOffsetY };
+}
+
+#if !PLATFORM(MAC)
+
+std::unique_ptr<ScrollingMomentumCalculator> ScrollingMomentumCalculator::create(const FloatSize& viewportSize, const FloatSize& contentSize, const FloatPoint& initialOffset, const FloatSize& initialDelta, const FloatSize& initialVelocity)
+{
+ return makeUnique<BasicScrollingMomentumCalculator>(viewportSize, contentSize, initialOffset, initialDelta, initialVelocity);
+}
+
+void ScrollingMomentumCalculator::setPlatformMomentumScrollingPredictionEnabled(bool)
+{
+}
+
+#endif
+
+BasicScrollingMomentumCalculator::BasicScrollingMomentumCalculator(const FloatSize& viewportSize, const FloatSize& contentSize, const FloatPoint& initialOffset, const FloatSize& initialDelta, const FloatSize& initialVelocity)
+ : ScrollingMomentumCalculator(viewportSize, contentSize, initialOffset, initialDelta, initialVelocity)
+{
+}
+
+FloatPoint BasicScrollingMomentumCalculator::linearlyInterpolatedOffsetAtProgress(float progress)
+{
+ return m_initialScrollOffset + progress * (retargetedScrollOffset() - m_initialScrollOffset);
+}
+
+FloatPoint BasicScrollingMomentumCalculator::cubicallyInterpolatedOffsetAtProgress(float progress) const
+{
+ ASSERT(!m_forceLinearAnimationCurve);
+ FloatPoint interpolatedPoint;
+ for (int i = 0; i < 4; ++i)
+ interpolatedPoint += std::pow(progress, i) * m_snapAnimationCurveCoefficients[i];
+
+ return interpolatedPoint;
+}
+
+FloatPoint BasicScrollingMomentumCalculator::scrollOffsetAfterElapsedTime(Seconds elapsedTime)
+{
+ if (m_momentumCalculatorRequiresInitialization) {
+ initializeSnapProgressCurve();
+ initializeInterpolationCoefficientsIfNecessary();
+ m_momentumCalculatorRequiresInitialization = false;
+ }
+
+ float progress = animationProgressAfterElapsedTime(elapsedTime);
+ return m_forceLinearAnimationCurve ? linearlyInterpolatedOffsetAtProgress(progress) : cubicallyInterpolatedOffsetAtProgress(progress);
+}
+
+Seconds BasicScrollingMomentumCalculator::animationDuration()
+{
+ return scrollSnapAnimationDuration;
+}
+
+/**
+ * Computes and sets coefficients required for interpolated snapping when scrolling in 2 dimensions, given
+ * initial conditions (the initial and target vectors, along with the initial wheel delta as a vector). The
+ * path is a cubic Bezier curve of the form p(s) = INITIAL + (C_1 * s) + (C_2 * s^2) + (C_3 * s^3) where each
+ * C_i is a 2D vector and INITIAL is the vector representing the initial scroll offset. s is a real in the
+ * interval [0, 1] indicating the "progress" of the curve (i.e. how much of the curve has been traveled).
+ *
+ * The curve has 4 control points, the first and last of which are the initial and target points, respectively.
+ * The distances between adjacent control points are constrained to be the same, making the convex hull an
+ * isosceles trapezoid with 3 sides of equal length. Additionally, the vector from the first control point to
+ * the second points in the same direction as the initial scroll delta. These constraints ensure two properties:
+ * 1. The direction of the snap animation at s=0 will be equal to the direction of the initial scroll delta.
+ * 2. Points at regular intervals of s will be evenly spread out.
+ *
+ * If the initial scroll direction is orthogonal to or points in the opposite direction as the vector from the
+ * initial point to the target point, initialization returns early and sets the curve to animate directly to the
+ * snap point without cubic interpolation.
+ *
+ * FIXME: This should be refactored to use UnitBezier.
+ */
+void BasicScrollingMomentumCalculator::initializeInterpolationCoefficientsIfNecessary()
+{
+ m_forceLinearAnimationCurve = true;
+ float initialDeltaMagnitude = m_initialDelta.diagonalLength();
+ if (initialDeltaMagnitude < 1) {
+ // The initial wheel delta is so insignificant that we're better off considering this to have the same effect as finishing a scroll gesture with no momentum.
+ // Thus, cubic interpolation isn't needed here.
+ return;
+ }
+
+ FloatSize startToEndVector = retargetedScrollOffset() - m_initialScrollOffset;
+ float startToEndDistance = startToEndVector.diagonalLength();
+ if (!startToEndDistance) {
+ // The start and end positions are the same, so we shouldn't try to interpolate a path.
+ return;
+ }
+
+ float cosTheta = (m_initialDelta.width() * startToEndVector.width() + m_initialDelta.height() * startToEndVector.height()) / (initialDeltaMagnitude * startToEndDistance);
+ if (cosTheta <= 0) {
+ // It's possible that the user is not scrolling towards the target snap offset (for instance, scrolling against a corner when 2D scroll snapping).
+ // In this case, just let the scroll offset animate to the target without computing a cubic curve.
+ return;
+ }
+
+ float sideLength = startToEndDistance / (2.0f * cosTheta + 1.0f);
+ auto initialOffsetAsSize = toFloatSize(m_initialScrollOffset);
+ FloatSize controlVector1 = initialOffsetAsSize + sideLength * m_initialDelta / initialDeltaMagnitude;
+ FloatSize controlVector2 = controlVector1 + (sideLength * startToEndVector / startToEndDistance);
+ m_snapAnimationCurveCoefficients[0] = initialOffsetAsSize;
+ m_snapAnimationCurveCoefficients[1] = 3 * (controlVector1 - initialOffsetAsSize);
+ m_snapAnimationCurveCoefficients[2] = 3 * (initialOffsetAsSize - 2 * controlVector1 + controlVector2);
+ m_snapAnimationCurveCoefficients[3] = 3 * (controlVector1 - controlVector2) - initialOffsetAsSize + toFloatSize(retargetedScrollOffset());
+ m_forceLinearAnimationCurve = false;
+}
+
+static const float framesPerSecond = 60.0f;
+
+/**
+ * Computes and sets parameters required for tracking the progress of a snap animation curve, interpolated
+ * or linear. The progress curve s(t) maps time t to progress s; both variables are in the interval [0, 1].
+ * The time input t is 0 when the current time is the start of the animation, t = 0, and 1 when the current
+ * time is at or after the end of the animation, t = m_scrollSnapAnimationDuration.
+ *
+ * In this exponential progress model, s(t) = A - A * b^(-kt), where k = 60T is the number of frames in the
+ * animation (assuming 60 FPS and an animation duration of T) and A, b are reals greater than or equal to 1.
+ * Also note that we are given the initial progress, a value indicating the portion of the curve which our
+ * initial scroll delta takes us. This is important when matching the initial speed of the animation to the
+ * user's initial momentum scrolling speed. Let this initial progress amount equal v_0. I clamp this initial
+ * progress amount to a minimum or maximum value.
+ *
+ * A is referred to as the curve magnitude, while b is referred to as the decay factor. We solve for A and b,
+ * keeping the following constraints in mind:
+ * 1. s(0) = 0
+ * 2. s(1) = 1
+ * 3. s(1/k) = v_0
+ *
+ * First, observe that s(0) = 0 holds for appropriate values of A, b. Solving for the remaining constraints
+ * yields a nonlinear system of two equations. In lieu of a purely analytical solution, an alternating
+ * optimization scheme is used to approximate A and b. This technique converges quickly (within 5 iterations
+ * or so) for appropriate values of v_0. The optimization terminates early when the decay factor changes by
+ * less than a threshold between one iteration and the next.
+ */
+void BasicScrollingMomentumCalculator::initializeSnapProgressCurve()
+{
+ static const int maxNumScrollSnapParameterEstimationIterations = 10;
+ static const float scrollSnapDecayFactorConvergenceThreshold = 0.001;
+ static const float initialScrollSnapCurveMagnitude = 1.1;
+ static const float minScrollSnapInitialProgress = 0.1;
+ static const float maxScrollSnapInitialProgress = 0.5;
+
+ FloatSize alignmentVector = m_initialDelta * (retargetedScrollOffset() - m_initialScrollOffset);
+ float initialProgress;
+ if (alignmentVector.width() + alignmentVector.height() > 0)
+ initialProgress = clampTo(m_initialDelta.diagonalLength() / (retargetedScrollOffset() - m_initialScrollOffset).diagonalLength(), minScrollSnapInitialProgress, maxScrollSnapInitialProgress);
+ else
+ initialProgress = minScrollSnapInitialProgress;
+
+ float previousDecayFactor = 1.0f;
+ m_snapAnimationCurveMagnitude = initialScrollSnapCurveMagnitude;
+ for (int i = 0; i < maxNumScrollSnapParameterEstimationIterations; ++i) {
+ m_snapAnimationDecayFactor = m_snapAnimationCurveMagnitude / (m_snapAnimationCurveMagnitude - initialProgress);
+ m_snapAnimationCurveMagnitude = 1.0f / (1.0f - std::pow(m_snapAnimationDecayFactor, -framesPerSecond * scrollSnapAnimationDuration.value()));
+ if (std::abs(m_snapAnimationDecayFactor - previousDecayFactor) < scrollSnapDecayFactorConvergenceThreshold)
+ break;
+
+ previousDecayFactor = m_snapAnimationDecayFactor;
+ }
+}
+
+float BasicScrollingMomentumCalculator::animationProgressAfterElapsedTime(Seconds elapsedTime) const
+{
+ float timeProgress = clampTo<float>(elapsedTime / scrollSnapAnimationDuration, 0, 1);
+ return std::min(1.0, m_snapAnimationCurveMagnitude * (1.0 - std::pow(m_snapAnimationDecayFactor, -framesPerSecond * scrollSnapAnimationDuration.value() * timeProgress)));
+}
+
+}; // namespace WebCore
Copied: trunk/Source/WebCore/platform/ScrollingMomentumCalculator.h (from rev 282732, trunk/Source/WebCore/page/scrolling/ScrollingMomentumCalculator.h) (0 => 282733)
--- trunk/Source/WebCore/platform/ScrollingMomentumCalculator.h (rev 0)
+++ trunk/Source/WebCore/platform/ScrollingMomentumCalculator.h 2021-09-19 02:55:42 UTC (rev 282733)
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2016 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 "PlatformWheelEvent.h"
+#include "ScrollTypes.h"
+#include <wtf/Seconds.h>
+
+namespace WebCore {
+
+class FloatPoint;
+class FloatSize;
+
+class ScrollingMomentumCalculator {
+ WTF_MAKE_FAST_ALLOCATED;
+public:
+ WEBCORE_EXPORT static void setPlatformMomentumScrollingPredictionEnabled(bool);
+
+ static std::unique_ptr<ScrollingMomentumCalculator> create(const FloatSize& viewportSize, const FloatSize& contentSize, const FloatPoint& initialOffset, const FloatSize& initialDelta, const FloatSize& initialVelocity);
+
+ ScrollingMomentumCalculator(const FloatSize& viewportSize, const FloatSize& contentSize, const FloatPoint& initialOffset, const FloatSize& initialDelta, const FloatSize& initialVelocity);
+ virtual ~ScrollingMomentumCalculator() = default;
+
+ virtual FloatPoint scrollOffsetAfterElapsedTime(Seconds) = 0;
+ virtual Seconds animationDuration() = 0;
+ virtual FloatPoint predictedDestinationOffset();
+ void setRetargetedScrollOffset(const FloatPoint&);
+
+protected:
+ const FloatPoint& retargetedScrollOffset() const { return m_retargetedScrollOffset.value(); }
+ virtual void retargetedScrollOffsetDidChange() { }
+
+ FloatSize m_initialDelta;
+ FloatSize m_initialVelocity;
+ FloatPoint m_initialScrollOffset;
+ FloatSize m_viewportSize;
+ FloatSize m_contentSize;
+
+private:
+ std::optional<FloatPoint> m_retargetedScrollOffset;
+};
+
+class BasicScrollingMomentumCalculator final : public ScrollingMomentumCalculator {
+public:
+ BasicScrollingMomentumCalculator(const FloatSize& viewportSize, const FloatSize& contentSize, const FloatPoint& initialOffset, const FloatSize& initialDelta, const FloatSize& initialVelocity);
+
+private:
+ FloatPoint scrollOffsetAfterElapsedTime(Seconds) final;
+ Seconds animationDuration() final;
+ void initializeInterpolationCoefficientsIfNecessary();
+ void initializeSnapProgressCurve();
+ float animationProgressAfterElapsedTime(Seconds) const;
+ FloatPoint linearlyInterpolatedOffsetAtProgress(float progress);
+ FloatPoint cubicallyInterpolatedOffsetAtProgress(float progress) const;
+
+ float m_snapAnimationCurveMagnitude { 0 };
+ float m_snapAnimationDecayFactor { 0 };
+ FloatSize m_snapAnimationCurveCoefficients[4] { };
+ bool m_forceLinearAnimationCurve { false };
+ bool m_momentumCalculatorRequiresInitialization { true };
+ std::optional<FloatSize> m_predictedDestinationOffset;
+};
+
+} // namespace WebCore
Modified: trunk/Source/WebCore/platform/gamepad/mac/HIDGamepadElement.cpp (282732 => 282733)
--- trunk/Source/WebCore/platform/gamepad/mac/HIDGamepadElement.cpp 2021-09-19 00:56:15 UTC (rev 282732)
+++ trunk/Source/WebCore/platform/gamepad/mac/HIDGamepadElement.cpp 2021-09-19 02:55:42 UTC (rev 282733)
@@ -28,6 +28,8 @@
#if ENABLE(GAMEPAD) && PLATFORM(MAC)
+#include <IOKit/hid/IOHIDElement.h>
+
namespace WebCore {
#pragma mark HIDGamepadElement
Modified: trunk/Source/WebCore/platform/graphics/Model.cpp (282732 => 282733)
--- trunk/Source/WebCore/platform/graphics/Model.cpp 2021-09-19 00:56:15 UTC (rev 282732)
+++ trunk/Source/WebCore/platform/graphics/Model.cpp 2021-09-19 02:55:42 UTC (rev 282733)
@@ -28,6 +28,8 @@
#if ENABLE(MODEL_ELEMENT)
+#include <wtf/text/TextStream.h>
+
namespace WebCore {
Ref<Model> Model::create(Ref<SharedBuffer> data, String mimeType, URL url)
Copied: trunk/Source/WebCore/platform/mac/ScrollingMomentumCalculatorMac.h (from rev 282732, trunk/Source/WebCore/page/scrolling/mac/ScrollingMomentumCalculatorMac.h) (0 => 282733)
--- trunk/Source/WebCore/platform/mac/ScrollingMomentumCalculatorMac.h (rev 0)
+++ trunk/Source/WebCore/platform/mac/ScrollingMomentumCalculatorMac.h 2021-09-19 02:55:42 UTC (rev 282733)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2016 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 "ScrollingMomentumCalculator.h"
+#include <wtf/RetainPtr.h>
+
+@class _NSScrollingMomentumCalculator;
+
+namespace WebCore {
+
+class ScrollingMomentumCalculatorMac final : public ScrollingMomentumCalculator {
+public:
+ ScrollingMomentumCalculatorMac(const FloatSize& viewportSize, const FloatSize& contentSize, const FloatPoint& initialOffset, const FloatSize& initialDelta, const FloatSize& initialVelocity);
+
+private:
+ FloatPoint scrollOffsetAfterElapsedTime(Seconds) final;
+ Seconds animationDuration() final;
+ FloatPoint predictedDestinationOffset() final;
+ void retargetedScrollOffsetDidChange() final;
+
+ _NSScrollingMomentumCalculator *ensurePlatformMomentumCalculator();
+ bool requiresMomentumScrolling();
+
+ RetainPtr<_NSScrollingMomentumCalculator> m_platformMomentumCalculator;
+ std::optional<bool> m_requiresMomentumScrolling;
+ FloatPoint m_initialDestinationOrigin;
+};
+
+} // namespace WebCore
Copied: trunk/Source/WebCore/platform/mac/ScrollingMomentumCalculatorMac.mm (from rev 282732, trunk/Source/WebCore/page/scrolling/mac/ScrollingMomentumCalculatorMac.mm) (0 => 282733)
--- trunk/Source/WebCore/platform/mac/ScrollingMomentumCalculatorMac.mm (rev 0)
+++ trunk/Source/WebCore/platform/mac/ScrollingMomentumCalculatorMac.mm 2021-09-19 02:55:42 UTC (rev 282733)
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#import "config.h"
+#import "ScrollingMomentumCalculatorMac.h"
+
+#if PLATFORM(MAC)
+
+#import <pal/spi/mac/NSScrollingMomentumCalculatorSPI.h>
+
+namespace WebCore {
+
+static bool gEnablePlatformMomentumScrollingPrediction = true;
+
+std::unique_ptr<ScrollingMomentumCalculator> ScrollingMomentumCalculator::create(const FloatSize& viewportSize, const FloatSize& contentSize, const FloatPoint& initialOffset, const FloatSize& initialDelta, const FloatSize& initialVelocity)
+{
+ return makeUnique<ScrollingMomentumCalculatorMac>(viewportSize, contentSize, initialOffset, initialDelta, initialVelocity);
+}
+
+void ScrollingMomentumCalculator::setPlatformMomentumScrollingPredictionEnabled(bool enabled)
+{
+ gEnablePlatformMomentumScrollingPrediction = enabled;
+}
+
+ScrollingMomentumCalculatorMac::ScrollingMomentumCalculatorMac(const FloatSize& viewportSize, const FloatSize& contentSize, const FloatPoint& initialOffset, const FloatSize& initialDelta, const FloatSize& initialVelocity)
+ : ScrollingMomentumCalculator(viewportSize, contentSize, initialOffset, initialDelta, initialVelocity)
+{
+}
+
+FloatPoint ScrollingMomentumCalculatorMac::scrollOffsetAfterElapsedTime(Seconds elapsedTime)
+{
+ if (!requiresMomentumScrolling())
+ return retargetedScrollOffset();
+
+ return [ensurePlatformMomentumCalculator() positionAfterDuration:elapsedTime.value()];
+}
+
+FloatPoint ScrollingMomentumCalculatorMac::predictedDestinationOffset()
+{
+ if (!gEnablePlatformMomentumScrollingPrediction)
+ return ScrollingMomentumCalculator::predictedDestinationOffset();
+
+ ensurePlatformMomentumCalculator();
+ return { m_initialDestinationOrigin.x(), m_initialDestinationOrigin.y() };
+}
+
+void ScrollingMomentumCalculatorMac::retargetedScrollOffsetDidChange()
+{
+ _NSScrollingMomentumCalculator *calculator = ensurePlatformMomentumCalculator();
+ calculator.destinationOrigin = retargetedScrollOffset();
+ [calculator calculateToReachDestination];
+}
+
+Seconds ScrollingMomentumCalculatorMac::animationDuration()
+{
+ if (!requiresMomentumScrolling())
+ return 0_s;
+
+ return Seconds([ensurePlatformMomentumCalculator() durationUntilStop]);
+}
+
+bool ScrollingMomentumCalculatorMac::requiresMomentumScrolling()
+{
+ if (m_requiresMomentumScrolling == std::nullopt)
+ m_requiresMomentumScrolling = m_initialScrollOffset != retargetedScrollOffset() || m_initialVelocity.area();
+ return m_requiresMomentumScrolling.value();
+}
+
+_NSScrollingMomentumCalculator *ScrollingMomentumCalculatorMac::ensurePlatformMomentumCalculator()
+{
+ if (m_platformMomentumCalculator)
+ return m_platformMomentumCalculator.get();
+
+ NSPoint origin = m_initialScrollOffset;
+ NSRect contentFrame = NSMakeRect(0, 0, m_contentSize.width(), m_contentSize.height());
+ NSPoint velocity = NSMakePoint(m_initialVelocity.width(), m_initialVelocity.height());
+ m_platformMomentumCalculator = adoptNS([[_NSScrollingMomentumCalculator alloc] initWithInitialOrigin:origin velocity:velocity documentFrame:contentFrame constrainedClippingOrigin:NSZeroPoint clippingSize:m_viewportSize tolerance:NSMakeSize(1, 1)]);
+ m_initialDestinationOrigin = [m_platformMomentumCalculator destinationOrigin];
+ return m_platformMomentumCalculator.get();
+}
+
+} // namespace WebCore
+
+#endif // PLATFORM(MAC)