Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Add support for scroll behavior relies on ScrollAnimation of the Web …
…process https://bugs.webkit.org/show_bug.cgi?id=204882 Reviewed by Frédéric Wang Based on the patch by Frédéric Wang. LayoutTests/imported/w3c: Enable CSSOMViewSmoothScrollingEnabled on scroll behavior tests and update expectations. * web-platform-tests/css/cssom-view/scroll-behavior-default-css-expected.txt: * web-platform-tests/css/cssom-view/scroll-behavior-default-css.html: * web-platform-tests/css/cssom-view/scroll-behavior-element-expected.txt: * web-platform-tests/css/cssom-view/scroll-behavior-element.html: * web-platform-tests/css/cssom-view/scroll-behavior-main-frame-root-expected.txt: * web-platform-tests/css/cssom-view/scroll-behavior-main-frame-root.html: * web-platform-tests/css/cssom-view/scroll-behavior-main-frame-window-expected.txt: * web-platform-tests/css/cssom-view/scroll-behavior-main-frame-window.html: * web-platform-tests/css/cssom-view/scroll-behavior-scrollintoview-nested-expected.txt: * web-platform-tests/css/cssom-view/scroll-behavior-scrollintoview-nested.html: * web-platform-tests/css/cssom-view/scroll-behavior-smooth-positions.html: * web-platform-tests/css/cssom-view/scroll-behavior-subframe-root-expected.txt: * web-platform-tests/css/cssom-view/scroll-behavior-subframe-root.html: * web-platform-tests/css/cssom-view/scroll-behavior-subframe-window-expected.txt: * web-platform-tests/css/cssom-view/scroll-behavior-subframe-window.html: Source/WebCore: This patch introduces a programmatic smooth scrolling in WebKit from the CSSOM View specification [1]. To use this effect, web developers can pass a behavior parameter (auto, smooth, or instant) to Element.scroll, Element.scrollTo, Element.scrollBy, Element.scrollIntoView, Window.scroll, Window.scrollTo or Window.scrollBy [2]. When behavior is auto, the instant/smooth characteristic is actually taken from the value of a new CSS scroll-behavior property [3]. Both the new CSS and DOM behavior are protected by a runtime flag. [1] https://drafts.csswg.org/cssom-view [2] https://drafts.csswg.org/cssom-view/#dictdef-scrolloptions [3] https://drafts.csswg.org/cssom-view/#propdef-scroll-behavior Tests: imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-default-css.html imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-element.html imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-main-frame-root.html imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-main-frame-window.html imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-scrollintoview-nested.html imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-smooth-positions.html imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-subframe-root.html imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-subframe-window.html * Sources.txt: Build ScrollAnimationSmooth.cpp on all platforms. * SourcesGTK.txt: Remove ScrollAnimationSmooth.cpp since it is built on all platforms now. * dom/Element.cpp: (WebCore::Element::scrollIntoView): Pass scroll behavior, if any. (WebCore::Element::scrollBy): (WebCore::Element::scrollTo): Handle the case when scroll behavior is smooth. (WebCore::Element::setScrollLeft): Handle the case when scroll behavior is smooth. (WebCore::Element::setScrollTop): Handle the case when scroll behavior is smooth. * page/DOMWindow.cpp: (WebCore::DOMWindow::scrollBy const): (WebCore::DOMWindow::scrollTo const): Handle the case when scroll behavior is smooth. The optimization of cancel (0, 0) scrolling is skipped if an animated scroll is in progress. Otherwise, the previous scroll won't be stopped by a follow-up scroll. * page/FrameView.cpp: (WebCore::FrameView::setScrollPosition): (WebCore::FrameView::scrollToOffsetWithAnimation): Start an animated scroll. * page/FrameView.h: * page/scrolling/AsyncScrollingCoordinator.cpp: (WebCore::AsyncScrollingCoordinator::requestScrollPositionUpdate): * platform/ScrollAnimation.h: (WebCore::ScrollAnimation::scroll): Function to animate scrolling to a specified position. * platform/ScrollAnimationSmooth.cpp: Build this file on all platforms. Add a smoothFactorForProgrammaticScroll parameter to slow down the smooth scrolling. (WebCore::ScrollAnimationSmooth::scroll): (WebCore::ScrollAnimationSmooth::updatePerAxisData): Scale the time parameters of the animation so that it looks smoother. * platform/ScrollAnimationSmooth.h: Declare the class on all platforms. * platform/ScrollAnimator.cpp: (WebCore::ScrollAnimator::ScrollAnimator): Initialize animation member for programmatic scrolling. (WebCore::ScrollAnimator::scrollToOffset): Animate scrolling to the specified position. (WebCore::ScrollAnimator::cancelAnimations): Copy logic from ScrollAnimationSmooth.cpp. (WebCore::ScrollAnimator::serviceScrollAnimations): Ditto. (WebCore::ScrollAnimator::willEndLiveResize): Ditto. (WebCore::ScrollAnimator::didAddVerticalScrollbar): Ditto. (WebCore::ScrollAnimator::didAddHorizontalScrollbar): Ditto. * platform/ScrollAnimator.h: New animation member for smooth programmatic scrolling. (WebCore::ScrollAnimator::ScrollAnimator::cancelAnimations): Deleted. (WebCore::ScrollAnimator::ScrollAnimator::serviceScrollAnimations): Deleted. (WebCore::ScrollAnimator::ScrollAnimator::willEndLiveResize): Deleted. (WebCore::ScrollAnimator::ScrollAnimator::didAddVerticalScrollbar): Deleted. (WebCore::ScrollAnimator::ScrollAnimator::didAddHorizontalScrollbar): Deleted. * platform/ScrollTypes.h: Add ScrollBehaviorStatus to indicate the status of scrolling. * platform/ScrollView.cpp: (WebCore::ScrollView::setScrollPosition): Follow the CSSOM View spec: If a scroll is in progress, we interrupt it and continue the scroll call (even when we are at the final position). * platform/ScrollView.h: * platform/ScrollableArea.cpp: (WebCore::ScrollableArea::scrollToOffsetWithAnimation): (WebCore::ScrollableArea::setScrollOffsetFromInternals): (WebCore::ScrollableArea::setScrollOffsetFromAnimation): To avoid iterate calling, move the requestScrollPositionUpdate(position) checking out of setScrollOffsetFromAnimation(). * platform/ScrollableArea.h: (WebCore::ScrollableArea::currentScrollBehaviorStatus const): Maintain currentScrollBehaviorStatus. (WebCore::ScrollableArea::setScrollBehaviorStatus): * platform/generic/ScrollAnimatorGeneric.cpp: (WebCore::ScrollAnimatorGeneric::updatePosition): * platform/mac/ScrollAnimatorMac.mm: (WebCore::ScrollAnimatorMac::cancelAnimations): Call parent member to handle programmatic scrolling. * rendering/RenderBox.cpp: (WebCore::RenderBox::setScrollLeft): Add flag to indicate animated or not. (WebCore::RenderBox::setScrollTop): Ditto. (WebCore::RenderBox::setScrollPosition): * rendering/RenderBox.h: * rendering/RenderLayer.cpp: (WebCore::RenderLayer::scrollToXPosition): Ditto. (WebCore::RenderLayer::scrollToYPosition): Ditto. (WebCore::RenderLayer::scrollToPosition): (WebCore::RenderLayer::scrollToOffset): Follow the CSSOM View spec: If a scroll is in progress, we interrupt it and continue the scroll call (even when we are at the final position). It's ScrollBehaviorType::Instant scroll. (WebCore::RenderLayer::requestScrollPositionUpdate): (WebCore::RenderLayer::scrollToOffsetWithAnimation): Ditto. This is similar to scrollToOffset but animates the scroll. It's ScrollBehaviorType::Smooth scroll. (WebCore::RenderLayer::scrollTo): (WebCore::RenderLayer::scrollRectToVisible): Again don't do an early return if scroll is in progress. We call scrollToOffsetWithAnimation instead of scrollToOffset when appropriate. Note that this function may not work well for several nested scroll boxes with at least one element with smooth behavior. It will handled in bug Follow. * rendering/RenderLayer.h: Add scroll behavior to ScrollTectToVisibleOptions. * rendering/RenderListBox.cpp: (WebCore::RenderListBox::setScrollLeft): Add animated flag. (WebCore::RenderListBox::setScrollTop): Ditto. * rendering/RenderListBox.h: * rendering/RenderTextControlSingleLine.cpp: (WebCore::RenderTextControlSingleLine::setScrollLeft): (WebCore::RenderTextControlSingleLine::setScrollTop): * rendering/RenderTextControlSingleLine.h: * testing/Internals.cpp: (WebCore::Internals::unconstrainedScrollTo): LayoutTests: * platform/mac-wk1/TestExpectations: Skip these tests on WK1 as they don't work for now. Canonical link: https://commits.webkit.org/219545@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@254807 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information