From 88a2aee734829c70d95825b7ecb5d82b1772f015 Mon Sep 17 00:00:00 2001 From: Frederic Wang Date: Tue, 25 Jun 2019 11:20:52 +0200 Subject: [PATCH xserver] Bug 188043 - Add support for ScrollOptions' ScrollBehavior and CSS scroll-behavior properties --- LayoutTests/ChangeLog | 10 ++ LayoutTests/imported/w3c/ChangeLog | 25 +++ .../scroll-behavior-default-css-expected.txt | 2 +- .../scroll-behavior-default-css.html | 2 +- .../scroll-behavior-element-expected.txt | 32 ++-- .../cssom-view/scroll-behavior-element.html | 2 +- ...roll-behavior-main-frame-root-expected.txt | 32 ++-- .../scroll-behavior-main-frame-root.html | 2 +- ...ll-behavior-main-frame-window-expected.txt | 24 +-- .../scroll-behavior-main-frame-window.html | 2 +- ...ehavior-scrollintoview-nested-expected.txt | 4 +- ...scroll-behavior-scrollintoview-nested.html | 2 +- .../scroll-behavior-smooth-positions.html | 2 +- ...scroll-behavior-subframe-root-expected.txt | 32 ++-- .../scroll-behavior-subframe-root.html | 2 +- ...roll-behavior-subframe-window-expected.txt | 24 +-- .../scroll-behavior-subframe-window.html | 2 +- LayoutTests/platform/mac-wk1/TestExpectations | 6 + Source/WebCore/CMakeLists.txt | 2 + Source/WebCore/ChangeLog | 145 ++++++++++++++++++ Source/WebCore/DerivedSources.make | 2 + Source/WebCore/Headers.cmake | 2 + Source/WebCore/Sources.txt | 4 + Source/WebCore/SourcesGTK.txt | 1 - .../WebCore/WebCore.xcodeproj/project.pbxproj | 28 ++++ .../css/CSSComputedStyleDeclaration.cpp | 7 + Source/WebCore/css/CSSProperties.json | 16 ++ Source/WebCore/css/CSSValueKeywords.in | 4 + Source/WebCore/css/StyleBuilderConverter.h | 6 + .../WebCore/css/parser/CSSParserContext.cpp | 2 + Source/WebCore/css/parser/CSSParserContext.h | 4 +- .../WebCore/css/parser/CSSParserFastPaths.cpp | 5 - .../WebCore/css/parser/CSSPropertyParser.cpp | 12 ++ Source/WebCore/dom/Element.cpp | 29 +++- Source/WebCore/page/DOMWindow.cpp | 14 +- Source/WebCore/page/ScrollBehavior.cpp | 48 ++++++ Source/WebCore/page/ScrollBehavior.h | 34 ++++ Source/WebCore/page/ScrollBehavior.idl | 20 +++ Source/WebCore/page/ScrollIntoViewOptions.h | 5 +- Source/WebCore/page/ScrollIntoViewOptions.idl | 3 +- Source/WebCore/page/ScrollOptions.h | 30 ++++ Source/WebCore/page/ScrollOptions.idl | 22 +++ Source/WebCore/page/ScrollToOptions.h | 13 +- Source/WebCore/page/ScrollToOptions.idl | 3 +- Source/WebCore/page/Settings.yaml | 3 + Source/WebCore/platform/ScrollAnimation.h | 3 + .../platform/ScrollAnimationKinetic.cpp | 5 + .../WebCore/platform/ScrollAnimationKinetic.h | 1 + .../platform/ScrollAnimationSmooth.cpp | 26 +++- .../WebCore/platform/ScrollAnimationSmooth.h | 8 +- Source/WebCore/platform/ScrollAnimator.cpp | 48 ++++++ Source/WebCore/platform/ScrollAnimator.h | 15 +- Source/WebCore/platform/ScrollView.cpp | 6 +- Source/WebCore/platform/ScrollableArea.cpp | 11 ++ Source/WebCore/platform/ScrollableArea.h | 2 + .../WebCore/platform/mac/ScrollAnimatorMac.mm | 1 + Source/WebCore/rendering/RenderBox.cpp | 8 + Source/WebCore/rendering/RenderBox.h | 1 + Source/WebCore/rendering/RenderLayer.cpp | 39 ++++- Source/WebCore/rendering/RenderLayer.h | 3 + Source/WebCore/rendering/style/RenderStyle.h | 6 + .../style/StyleRareNonInheritedData.cpp | 3 + .../style/StyleRareNonInheritedData.h | 2 + Source/WebCore/testing/Internals.cpp | 2 +- Source/WebKit/ChangeLog | 11 ++ Source/WebKit/Shared/WebPreferences.yaml | 8 +- Source/WebKitLegacy/mac/ChangeLog | 17 ++ .../mac/WebView/WebPreferenceKeysPrivate.h | 1 + .../mac/WebView/WebPreferences.mm | 11 ++ .../mac/WebView/WebPreferencesPrivate.h | 1 + Source/WebKitLegacy/mac/WebView/WebView.mm | 1 + Source/WebKitLegacy/win/ChangeLog | 17 ++ .../win/Interfaces/IWebPreferencesPrivate.idl | 2 + .../win/WebPreferenceKeysPrivate.h | 1 + Source/WebKitLegacy/win/WebPreferences.cpp | 16 ++ Source/WebKitLegacy/win/WebPreferences.h | 2 + Source/WebKitLegacy/win/WebView.cpp | 5 + Tools/ChangeLog | 11 ++ Tools/DumpRenderTree/TestOptions.cpp | 2 + Tools/DumpRenderTree/TestOptions.h | 1 + Tools/DumpRenderTree/mac/DumpRenderTree.mm | 1 + 81 files changed, 837 insertions(+), 132 deletions(-) create mode 100644 Source/WebCore/page/ScrollBehavior.cpp create mode 100644 Source/WebCore/page/ScrollBehavior.h create mode 100644 Source/WebCore/page/ScrollBehavior.idl create mode 100644 Source/WebCore/page/ScrollOptions.h create mode 100644 Source/WebCore/page/ScrollOptions.idl diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog index 8a9fa8f70b0..a9f7bdc5842 100644 --- a/LayoutTests/ChangeLog +++ b/LayoutTests/ChangeLog @@ -1,3 +1,13 @@ +2018-11-07 Frederic Wang + + Add support for ScrollOptions' ScrollBehavior and CSS scroll-behavior properties + https://bugs.webkit.org/show_bug.cgi?id=188043 + + Reviewed by NOBODY (OOPS!). + + * platform/mac-wk1/TestExpectations: Skip these tests on WK1 as they don't work for now and + are slow anyway. + 2019-06-24 Wenson Hsieh [Text autosizing] [iPadOS] Revise our heuristics to determine idempotent text autosizing candidates diff --git a/LayoutTests/imported/w3c/ChangeLog b/LayoutTests/imported/w3c/ChangeLog index 3d32170ae4e..9e791c333ca 100644 --- a/LayoutTests/imported/w3c/ChangeLog +++ b/LayoutTests/imported/w3c/ChangeLog @@ -1,3 +1,28 @@ +2018-11-06 Frederic Wang + + Add support for ScrollOptions' ScrollBehavior and CSS scroll-behavior properties + https://bugs.webkit.org/show_bug.cgi?id=188043 + + Reviewed by NOBODY (OOPS!). + + 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: + 2019-06-24 Antoine Quint [Pointer Events WPT] Unskip imported/w3c/web-platform-tests/pointerevents/pointerlock/pointerevent_coordinates_when_locked.html diff --git a/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-default-css-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-default-css-expected.txt index 9068b797552..8d4ca64155f 100644 --- a/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-default-css-expected.txt +++ b/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-default-css-expected.txt @@ -1,4 +1,4 @@ PASS Instant scrolling of an element with default scroll-behavior -FAIL Smooth scrolling of an element with default scroll-behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 +PASS Smooth scrolling of an element with default scroll-behavior diff --git a/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-default-css.html b/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-default-css.html index 8606b1f3ed4..eed63a06932 100644 --- a/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-default-css.html +++ b/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-default-css.html @@ -1,4 +1,4 @@ - + Testing default value of scroll-behavior diff --git a/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-element-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-element-expected.txt index 2b9129c1cf4..53a961ef56a 100644 --- a/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-element-expected.txt +++ b/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-element-expected.txt @@ -2,35 +2,35 @@ PASS Element with auto scroll-behavior ; scroll() with default behavior PASS Element with auto scroll-behavior ; scroll() with auto behavior PASS Element with auto scroll-behavior ; scroll() with instant behavior -FAIL Element with auto scroll-behavior ; scroll() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 -FAIL Element with smooth scroll-behavior ; scroll() with default behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 -FAIL Element with smooth scroll-behavior ; scroll() with auto behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 +PASS Element with auto scroll-behavior ; scroll() with smooth behavior +PASS Element with smooth scroll-behavior ; scroll() with default behavior +PASS Element with smooth scroll-behavior ; scroll() with auto behavior PASS Element with smooth scroll-behavior ; scroll() with instant behavior -FAIL Element with smooth scroll-behavior ; scroll() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 +PASS Element with smooth scroll-behavior ; scroll() with smooth behavior PASS Element with auto scroll-behavior ; scrollTo() with default behavior PASS Element with auto scroll-behavior ; scrollTo() with auto behavior PASS Element with auto scroll-behavior ; scrollTo() with instant behavior -FAIL Element with auto scroll-behavior ; scrollTo() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 -FAIL Element with smooth scroll-behavior ; scrollTo() with default behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 -FAIL Element with smooth scroll-behavior ; scrollTo() with auto behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 +PASS Element with auto scroll-behavior ; scrollTo() with smooth behavior +PASS Element with smooth scroll-behavior ; scrollTo() with default behavior +PASS Element with smooth scroll-behavior ; scrollTo() with auto behavior PASS Element with smooth scroll-behavior ; scrollTo() with instant behavior -FAIL Element with smooth scroll-behavior ; scrollTo() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 +PASS Element with smooth scroll-behavior ; scrollTo() with smooth behavior PASS Element with auto scroll-behavior ; scrollBy() with default behavior PASS Element with auto scroll-behavior ; scrollBy() with auto behavior PASS Element with auto scroll-behavior ; scrollBy() with instant behavior -FAIL Element with auto scroll-behavior ; scrollBy() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 -FAIL Element with smooth scroll-behavior ; scrollBy() with default behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 -FAIL Element with smooth scroll-behavior ; scrollBy() with auto behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 +PASS Element with auto scroll-behavior ; scrollBy() with smooth behavior +PASS Element with smooth scroll-behavior ; scrollBy() with default behavior +PASS Element with smooth scroll-behavior ; scrollBy() with auto behavior PASS Element with smooth scroll-behavior ; scrollBy() with instant behavior -FAIL Element with smooth scroll-behavior ; scrollBy() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 +PASS Element with smooth scroll-behavior ; scrollBy() with smooth behavior PASS Element with auto scroll-behavior ; scrollIntoView() with default behavior PASS Element with auto scroll-behavior ; scrollIntoView() with auto behavior PASS Element with auto scroll-behavior ; scrollIntoView() with instant behavior -FAIL Element with auto scroll-behavior ; scrollIntoView() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 -FAIL Element with smooth scroll-behavior ; scrollIntoView() with default behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 -FAIL Element with smooth scroll-behavior ; scrollIntoView() with auto behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 +PASS Element with auto scroll-behavior ; scrollIntoView() with smooth behavior +PASS Element with smooth scroll-behavior ; scrollIntoView() with default behavior +PASS Element with smooth scroll-behavior ; scrollIntoView() with auto behavior PASS Element with smooth scroll-behavior ; scrollIntoView() with instant behavior -FAIL Element with smooth scroll-behavior ; scrollIntoView() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 +PASS Element with smooth scroll-behavior ; scrollIntoView() with smooth behavior PASS Aborting an ongoing smooth scrolling on an element with another smooth scrolling PASS Aborting an ongoing smooth scrolling on an element with an instant scrolling diff --git a/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-element.html b/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-element.html index 9f60ca77112..556b66c824f 100644 --- a/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-element.html +++ b/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-element.html @@ -1,4 +1,4 @@ - + Testing scrollOptions' behavior for Element.scroll* and scroll-behavior on an element diff --git a/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-main-frame-root-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-main-frame-root-expected.txt index d922258af27..97caea27bb5 100644 --- a/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-main-frame-root-expected.txt +++ b/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-main-frame-root-expected.txt @@ -3,35 +3,35 @@ PASS Page loaded PASS Main frame with auto scroll-behavior ; scroll() with default behavior PASS Main frame with auto scroll-behavior ; scroll() with auto behavior PASS Main frame with auto scroll-behavior ; scroll() with instant behavior -FAIL Main frame with auto scroll-behavior ; scroll() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 2430 but got 2430 -FAIL Main frame with smooth scroll-behavior ; scroll() with default behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 2430 but got 2430 -FAIL Main frame with smooth scroll-behavior ; scroll() with auto behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 2430 but got 2430 +PASS Main frame with auto scroll-behavior ; scroll() with smooth behavior +PASS Main frame with smooth scroll-behavior ; scroll() with default behavior +PASS Main frame with smooth scroll-behavior ; scroll() with auto behavior PASS Main frame with smooth scroll-behavior ; scroll() with instant behavior -FAIL Main frame with smooth scroll-behavior ; scroll() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 2430 but got 2430 +PASS Main frame with smooth scroll-behavior ; scroll() with smooth behavior PASS Main frame with auto scroll-behavior ; scrollTo() with default behavior PASS Main frame with auto scroll-behavior ; scrollTo() with auto behavior PASS Main frame with auto scroll-behavior ; scrollTo() with instant behavior -FAIL Main frame with auto scroll-behavior ; scrollTo() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 2430 but got 2430 -FAIL Main frame with smooth scroll-behavior ; scrollTo() with default behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 2430 but got 2430 -FAIL Main frame with smooth scroll-behavior ; scrollTo() with auto behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 2430 but got 2430 +PASS Main frame with auto scroll-behavior ; scrollTo() with smooth behavior +PASS Main frame with smooth scroll-behavior ; scrollTo() with default behavior +PASS Main frame with smooth scroll-behavior ; scrollTo() with auto behavior PASS Main frame with smooth scroll-behavior ; scrollTo() with instant behavior -FAIL Main frame with smooth scroll-behavior ; scrollTo() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 2430 but got 2430 +PASS Main frame with smooth scroll-behavior ; scrollTo() with smooth behavior PASS Main frame with auto scroll-behavior ; scrollBy() with default behavior PASS Main frame with auto scroll-behavior ; scrollBy() with auto behavior PASS Main frame with auto scroll-behavior ; scrollBy() with instant behavior -FAIL Main frame with auto scroll-behavior ; scrollBy() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 2430 but got 2430 -FAIL Main frame with smooth scroll-behavior ; scrollBy() with default behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 2430 but got 2430 -FAIL Main frame with smooth scroll-behavior ; scrollBy() with auto behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 2430 but got 2430 +PASS Main frame with auto scroll-behavior ; scrollBy() with smooth behavior +PASS Main frame with smooth scroll-behavior ; scrollBy() with default behavior +PASS Main frame with smooth scroll-behavior ; scrollBy() with auto behavior PASS Main frame with smooth scroll-behavior ; scrollBy() with instant behavior -FAIL Main frame with smooth scroll-behavior ; scrollBy() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 2430 but got 2430 +PASS Main frame with smooth scroll-behavior ; scrollBy() with smooth behavior PASS Main frame with auto scroll-behavior ; scrollIntoView() with default behavior PASS Main frame with auto scroll-behavior ; scrollIntoView() with auto behavior PASS Main frame with auto scroll-behavior ; scrollIntoView() with instant behavior -FAIL Main frame with auto scroll-behavior ; scrollIntoView() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 2430 but got 2430 -FAIL Main frame with smooth scroll-behavior ; scrollIntoView() with default behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 2430 but got 2430 -FAIL Main frame with smooth scroll-behavior ; scrollIntoView() with auto behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 2430 but got 2430 +PASS Main frame with auto scroll-behavior ; scrollIntoView() with smooth behavior +PASS Main frame with smooth scroll-behavior ; scrollIntoView() with default behavior +PASS Main frame with smooth scroll-behavior ; scrollIntoView() with auto behavior PASS Main frame with smooth scroll-behavior ; scrollIntoView() with instant behavior -FAIL Main frame with smooth scroll-behavior ; scrollIntoView() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 2430 but got 2430 +PASS Main frame with smooth scroll-behavior ; scrollIntoView() with smooth behavior PASS Aborting an ongoing smooth scrolling on the main frame with another smooth scrolling PASS Aborting an ongoing smooth scrolling on the main frame with an instant scrolling diff --git a/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-main-frame-root.html b/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-main-frame-root.html index 7ef0a4aa0da..188863ff82c 100644 --- a/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-main-frame-root.html +++ b/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-main-frame-root.html @@ -1,4 +1,4 @@ - + Testing scrollOptions' behavior for Element.scroll* and scroll-behavior on the root of the main frame diff --git a/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-main-frame-window-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-main-frame-window-expected.txt index c6be96661c2..382385aab49 100644 --- a/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-main-frame-window-expected.txt +++ b/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-main-frame-window-expected.txt @@ -3,27 +3,27 @@ PASS Page loaded PASS Main frame with auto scroll-behavior ; scroll() with default behavior PASS Main frame with auto scroll-behavior ; scroll() with auto behavior PASS Main frame with auto scroll-behavior ; scroll() with instant behavior -FAIL Main frame with auto scroll-behavior ; scroll() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 2430 but got 2430 -FAIL Main frame with smooth scroll-behavior ; scroll() with default behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 2430 but got 2430 -FAIL Main frame with smooth scroll-behavior ; scroll() with auto behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 2430 but got 2430 +PASS Main frame with auto scroll-behavior ; scroll() with smooth behavior +PASS Main frame with smooth scroll-behavior ; scroll() with default behavior +PASS Main frame with smooth scroll-behavior ; scroll() with auto behavior PASS Main frame with smooth scroll-behavior ; scroll() with instant behavior -FAIL Main frame with smooth scroll-behavior ; scroll() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 2430 but got 2430 +PASS Main frame with smooth scroll-behavior ; scroll() with smooth behavior PASS Main frame with auto scroll-behavior ; scrollTo() with default behavior PASS Main frame with auto scroll-behavior ; scrollTo() with auto behavior PASS Main frame with auto scroll-behavior ; scrollTo() with instant behavior -FAIL Main frame with auto scroll-behavior ; scrollTo() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 2430 but got 2430 -FAIL Main frame with smooth scroll-behavior ; scrollTo() with default behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 2430 but got 2430 -FAIL Main frame with smooth scroll-behavior ; scrollTo() with auto behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 2430 but got 2430 +PASS Main frame with auto scroll-behavior ; scrollTo() with smooth behavior +PASS Main frame with smooth scroll-behavior ; scrollTo() with default behavior +PASS Main frame with smooth scroll-behavior ; scrollTo() with auto behavior PASS Main frame with smooth scroll-behavior ; scrollTo() with instant behavior -FAIL Main frame with smooth scroll-behavior ; scrollTo() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 2430 but got 2430 +PASS Main frame with smooth scroll-behavior ; scrollTo() with smooth behavior PASS Main frame with auto scroll-behavior ; scrollBy() with default behavior PASS Main frame with auto scroll-behavior ; scrollBy() with auto behavior PASS Main frame with auto scroll-behavior ; scrollBy() with instant behavior -FAIL Main frame with auto scroll-behavior ; scrollBy() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 2430 but got 2430 -FAIL Main frame with smooth scroll-behavior ; scrollBy() with default behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 2430 but got 2430 -FAIL Main frame with smooth scroll-behavior ; scrollBy() with auto behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 2430 but got 2430 +PASS Main frame with auto scroll-behavior ; scrollBy() with smooth behavior +PASS Main frame with smooth scroll-behavior ; scrollBy() with default behavior +PASS Main frame with smooth scroll-behavior ; scrollBy() with auto behavior PASS Main frame with smooth scroll-behavior ; scrollBy() with instant behavior -FAIL Main frame with smooth scroll-behavior ; scrollBy() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 2430 but got 2430 +PASS Main frame with smooth scroll-behavior ; scrollBy() with smooth behavior PASS Aborting an ongoing smooth scrolling on the main frame with another smooth scrolling PASS Aborting an ongoing smooth scrolling on the main frame with an instant scrolling diff --git a/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-main-frame-window.html b/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-main-frame-window.html index 57b0d913461..23e298dfdf0 100644 --- a/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-main-frame-window.html +++ b/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-main-frame-window.html @@ -1,4 +1,4 @@ - + Testing scrollOptions' behavior for Element.scroll* on the window of the main frame diff --git a/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-scrollintoview-nested-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-scrollintoview-nested-expected.txt index 7ce10c08961..a3a51d3e6ab 100644 --- a/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-scrollintoview-nested-expected.txt +++ b/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-scrollintoview-nested-expected.txt @@ -1,3 +1,5 @@ -FAIL scrollIntoView with nested elements with different scroll-behavior assert_less_than: Element with smooth behavior should not scroll immediately expected a number less than 500 but got 500 +FAIL scrollIntoView with nested elements with different scroll-behavior assert_equals: Element with instant behavior should jump to the final position expected 0 but got 1000 + +assert_equals: Element with instant behavior should jump to the final position expected 500 but got 1000 diff --git a/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-scrollintoview-nested.html b/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-scrollintoview-nested.html index 2a97e065663..ece539b3352 100644 --- a/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-scrollintoview-nested.html +++ b/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-scrollintoview-nested.html @@ -1,4 +1,4 @@ - + Testing scrollOptions' behavior with scrollIntoView for nested scrolling nodes diff --git a/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-smooth-positions.html b/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-smooth-positions.html index 19e317d5e4b..b610a47b5c7 100644 --- a/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-smooth-positions.html +++ b/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-smooth-positions.html @@ -1,4 +1,4 @@ - + Testing scroll positions when scrolling an element with smooth behavior diff --git a/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-subframe-root-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-subframe-root-expected.txt index b6fa1c2ec8b..2799fdcc29e 100644 --- a/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-subframe-root-expected.txt +++ b/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-subframe-root-expected.txt @@ -3,35 +3,35 @@ PASS iframe loaded PASS Subframe with auto scroll-behavior ; scroll() with default behavior PASS Subframe with auto scroll-behavior ; scroll() with auto behavior PASS Subframe with auto scroll-behavior ; scroll() with instant behavior -FAIL Subframe with auto scroll-behavior ; scroll() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 -FAIL Subframe with smooth scroll-behavior ; scroll() with default behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 -FAIL Subframe with smooth scroll-behavior ; scroll() with auto behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 +PASS Subframe with auto scroll-behavior ; scroll() with smooth behavior +PASS Subframe with smooth scroll-behavior ; scroll() with default behavior +PASS Subframe with smooth scroll-behavior ; scroll() with auto behavior PASS Subframe with smooth scroll-behavior ; scroll() with instant behavior -FAIL Subframe with smooth scroll-behavior ; scroll() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 +PASS Subframe with smooth scroll-behavior ; scroll() with smooth behavior PASS Subframe with auto scroll-behavior ; scrollTo() with default behavior PASS Subframe with auto scroll-behavior ; scrollTo() with auto behavior PASS Subframe with auto scroll-behavior ; scrollTo() with instant behavior -FAIL Subframe with auto scroll-behavior ; scrollTo() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 -FAIL Subframe with smooth scroll-behavior ; scrollTo() with default behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 -FAIL Subframe with smooth scroll-behavior ; scrollTo() with auto behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 +PASS Subframe with auto scroll-behavior ; scrollTo() with smooth behavior +PASS Subframe with smooth scroll-behavior ; scrollTo() with default behavior +PASS Subframe with smooth scroll-behavior ; scrollTo() with auto behavior PASS Subframe with smooth scroll-behavior ; scrollTo() with instant behavior -FAIL Subframe with smooth scroll-behavior ; scrollTo() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 +PASS Subframe with smooth scroll-behavior ; scrollTo() with smooth behavior PASS Subframe with auto scroll-behavior ; scrollBy() with default behavior PASS Subframe with auto scroll-behavior ; scrollBy() with auto behavior PASS Subframe with auto scroll-behavior ; scrollBy() with instant behavior -FAIL Subframe with auto scroll-behavior ; scrollBy() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 -FAIL Subframe with smooth scroll-behavior ; scrollBy() with default behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 -FAIL Subframe with smooth scroll-behavior ; scrollBy() with auto behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 +PASS Subframe with auto scroll-behavior ; scrollBy() with smooth behavior +PASS Subframe with smooth scroll-behavior ; scrollBy() with default behavior +PASS Subframe with smooth scroll-behavior ; scrollBy() with auto behavior PASS Subframe with smooth scroll-behavior ; scrollBy() with instant behavior -FAIL Subframe with smooth scroll-behavior ; scrollBy() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 +PASS Subframe with smooth scroll-behavior ; scrollBy() with smooth behavior PASS Subframe with auto scroll-behavior ; scrollIntoView() with default behavior PASS Subframe with auto scroll-behavior ; scrollIntoView() with auto behavior PASS Subframe with auto scroll-behavior ; scrollIntoView() with instant behavior -FAIL Subframe with auto scroll-behavior ; scrollIntoView() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 -FAIL Subframe with smooth scroll-behavior ; scrollIntoView() with default behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 -FAIL Subframe with smooth scroll-behavior ; scrollIntoView() with auto behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 +PASS Subframe with auto scroll-behavior ; scrollIntoView() with smooth behavior +PASS Subframe with smooth scroll-behavior ; scrollIntoView() with default behavior +PASS Subframe with smooth scroll-behavior ; scrollIntoView() with auto behavior PASS Subframe with smooth scroll-behavior ; scrollIntoView() with instant behavior -FAIL Subframe with smooth scroll-behavior ; scrollIntoView() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 +PASS Subframe with smooth scroll-behavior ; scrollIntoView() with smooth behavior PASS Aborting an ongoing smooth scrolling on a subframe with another smooth scrolling PASS Aborting an ongoing smooth scrolling on a subframe with an instant scrolling diff --git a/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-subframe-root.html b/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-subframe-root.html index 32de1b62038..d36c9d03bff 100644 --- a/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-subframe-root.html +++ b/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-subframe-root.html @@ -1,4 +1,4 @@ - + Testing scrollOptions' behavior for Element.scroll* and scroll-behavior on the root of a subframe diff --git a/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-subframe-window-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-subframe-window-expected.txt index cc665ebdb8b..05eb3272f40 100644 --- a/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-subframe-window-expected.txt +++ b/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-subframe-window-expected.txt @@ -3,27 +3,27 @@ PASS iframe loaded PASS Main frame with auto scroll-behavior ; scroll() with default behavior PASS Main frame with auto scroll-behavior ; scroll() with auto behavior PASS Main frame with auto scroll-behavior ; scroll() with instant behavior -FAIL Main frame with auto scroll-behavior ; scroll() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 -FAIL Main frame with smooth scroll-behavior ; scroll() with default behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 -FAIL Main frame with smooth scroll-behavior ; scroll() with auto behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 +PASS Main frame with auto scroll-behavior ; scroll() with smooth behavior +PASS Main frame with smooth scroll-behavior ; scroll() with default behavior +PASS Main frame with smooth scroll-behavior ; scroll() with auto behavior PASS Main frame with smooth scroll-behavior ; scroll() with instant behavior -FAIL Main frame with smooth scroll-behavior ; scroll() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 +PASS Main frame with smooth scroll-behavior ; scroll() with smooth behavior PASS Main frame with auto scroll-behavior ; scrollTo() with default behavior PASS Main frame with auto scroll-behavior ; scrollTo() with auto behavior PASS Main frame with auto scroll-behavior ; scrollTo() with instant behavior -FAIL Main frame with auto scroll-behavior ; scrollTo() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 -FAIL Main frame with smooth scroll-behavior ; scrollTo() with default behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 -FAIL Main frame with smooth scroll-behavior ; scrollTo() with auto behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 +PASS Main frame with auto scroll-behavior ; scrollTo() with smooth behavior +PASS Main frame with smooth scroll-behavior ; scrollTo() with default behavior +PASS Main frame with smooth scroll-behavior ; scrollTo() with auto behavior PASS Main frame with smooth scroll-behavior ; scrollTo() with instant behavior -FAIL Main frame with smooth scroll-behavior ; scrollTo() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 +PASS Main frame with smooth scroll-behavior ; scrollTo() with smooth behavior PASS Main frame with auto scroll-behavior ; scrollBy() with default behavior PASS Main frame with auto scroll-behavior ; scrollBy() with auto behavior PASS Main frame with auto scroll-behavior ; scrollBy() with instant behavior -FAIL Main frame with auto scroll-behavior ; scrollBy() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 -FAIL Main frame with smooth scroll-behavior ; scrollBy() with default behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 -FAIL Main frame with smooth scroll-behavior ; scrollBy() with auto behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 +PASS Main frame with auto scroll-behavior ; scrollBy() with smooth behavior +PASS Main frame with smooth scroll-behavior ; scrollBy() with default behavior +PASS Main frame with smooth scroll-behavior ; scrollBy() with auto behavior PASS Main frame with smooth scroll-behavior ; scrollBy() with instant behavior -FAIL Main frame with smooth scroll-behavior ; scrollBy() with smooth behavior assert_less_than: Should not set scrollLeft immediately expected a number less than 500 but got 500 +PASS Main frame with smooth scroll-behavior ; scrollBy() with smooth behavior PASS Aborting an ongoing smooth scrolling on the main frame with another smooth scrolling PASS Aborting an ongoing smooth scrolling on the main frame with an instant scrolling diff --git a/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-subframe-window.html b/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-subframe-window.html index 0a8ed39d1b9..74aec5467ff 100644 --- a/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-subframe-window.html +++ b/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-subframe-window.html @@ -1,4 +1,4 @@ - + Testing scrollOptions' behavior for Element.scroll* and scroll-behavior on the root of a subframe diff --git a/LayoutTests/platform/mac-wk1/TestExpectations b/LayoutTests/platform/mac-wk1/TestExpectations index a046f6afa0e..427dd752e34 100644 --- a/LayoutTests/platform/mac-wk1/TestExpectations +++ b/LayoutTests/platform/mac-wk1/TestExpectations @@ -694,6 +694,12 @@ webkit.org/b/189594 imported/w3c/web-platform-tests/css/css-animations/pending-s webkit.org/b/188070 imported/w3c/web-platform-tests/streams/piping/error-propagation-backward.html [ Pass Failure ] +# Tests for smooth scroll behavior do not all work and they are slow, so let's just skip them. +webkit.org/b/191357 imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-main-frame-root.html [ Skip ] +webkit.org/b/191357 imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-main-frame-window.html [ Skip ] +webkit.org/b/191357 imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-subframe-root.html [ Skip ] +webkit.org/b/191357 imported/w3c/web-platform-tests/css/cssom-view/scroll-behavior-subframe-window.html [ Skip ] + webkit.org/b/189908 imported/w3c/web-platform-tests/resource-timing/resource_timing.worker.html [ Failure ] webkit.org/b/189756 [ Mojave+ ] compositing/filters/opacity-change-on-filtered-paints-into-ancestor.html [ Pass ImageOnlyFailure ] diff --git a/Source/WebCore/CMakeLists.txt b/Source/WebCore/CMakeLists.txt index 9cae1b7f47b..e4019c80372 100644 --- a/Source/WebCore/CMakeLists.txt +++ b/Source/WebCore/CMakeLists.txt @@ -933,8 +933,10 @@ set(WebCore_NON_SVG_IDL_FILES page/ResizeObserverCallback.idl page/ResizeObserverEntry.idl page/Screen.idl + page/ScrollBehavior.idl page/ScrollIntoViewOptions.idl page/ScrollLogicalPosition.idl + page/ScrollOptions.idl page/ScrollToOptions.idl page/ShareData.idl page/UndoItem.idl diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index e54e326efc2..0ee54547403 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,148 @@ +2018-11-09 Frederic Wang + + Add support for ScrollOptions' ScrollBehavior and CSS scroll-behavior properties + https://bugs.webkit.org/show_bug.cgi?id=188043 + + Reviewed by NOBODY (OOPS!). + + 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. The Element.scrollIntoView part will be refined later in bug 189907. The actual + animation relies on the existing ScrollAnimationSmooth. + + [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 + + Add support for ScrollOptions' ScrollBehavior and CSS scroll-behavior properties + + 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 + + * CMakeLists.txt: Add IDL files for ScrollOptions and ScrollBehavior. + * DerivedSources.make: Ditto. + * Sources.txt: Add ScrollBehavor and ScrollOptions implementation. Also build + ScrollAnimationSmooth.cpp on all platforms. + * Headers.cmake: Add headers for ScrollBehavor and ScrollOptions. + * SourcesGTK.txt: Remove ScrollAnimationSmooth.cpp since it is built on all platforms now. + * WebCore.xcodeproj/project.pbxproj: Add files to the build system. + * css/CSSComputedStyleDeclaration.cpp: Handle scroll-behavior. + (WebCore::ComputedStyleExtractor::valueForPropertyinStyle): + * css/CSSProperties.json: Add scroll-behavior. + * css/CSSValueKeywords.in: Add keywords for scroll-behavior. + * css/StyleBuilderConverter.h: + (WebCore::StyleBuilderConverter::convertSmoothScrolling): New function to convert + scroll-behavior into a "is smooth" boolean. + * css/parser/CSSParserContext.cpp: Add runtime config for scroll-behavior. + (WebCore::CSSParserContext::CSSParserContext): + (WebCore::operator==): + * css/parser/CSSParserContext.h: Ditto. + (WebCore::CSSParserContextHash::hash): + * css/parser/CSSParserFastPaths.cpp: Remove scroll-behavior templates. It is handled in the + slow path since property can be disabled. + (WebCore::CSSParserFastPaths::isValidKeywordPropertyAndValue): + (WebCore::CSSParserFastPaths::isKeywordPropertyID): + * css/parser/CSSPropertyParser.cpp: + (WebCore::CSSPropertyParser::parseSingleValue): Parse scroll-behavior (only if enabled). + * dom/Element.cpp: + (WebCore::Element::scrollIntoView): Pass scroll behavior, if any. + (WebCore::Element::scrollBy): Use fromCoordinates helper function. + (WebCore::Element::scrollTo): Handle the case when scroll behavior is smooth. Use + fromCoordinates helper function. + * page/DOMWindow.cpp: + (WebCore::DOMWindow::scrollBy const): Use fromCoordinates helper function. + (WebCore::DOMWindow::scrollTo const): Use fromCoordinates helper function. Handle the case + when scroll behavior is smooth. The optimization when scroll position is (0, 0) is skipped + when a scroll is in progress, otherwise such a scroll can't be cancelled by a follow-up + scroll. + * page/ScrollBehavior.cpp: Added. + (WebCore::useSmoothScrolling): Helper funciton to determine the scroll behavior to apply to + an element from the CSS and DOM behavior. + * page/ScrollBehavior.h: Added. + * page/ScrollBehavior.idl: Added. + * page/ScrollIntoViewOptions.h: Make this class inherits from ScrollOption. Also remove + unnecessary forward declaration. + * page/ScrollIntoViewOptions.idl: Make this class inherits from ScrollOption. + * page/ScrollOptions.h: Added. + * page/ScrollOptions.idl: Added. + * page/ScrollToOptions.h: Make this struct inherits from ScrollOptions. + (WebCore::fromCoordinates): New helper function to generate a ScrollToOptions with undefined + behavior. This is necessary to replace curly brace { x, y } declarations now that there is + an extra behavior member from the parent class. + (WebCore::normalizeNonFiniteCoordinatesOrFallBackTo): Copy the current ScrollToOptions so + that the scroll behavior is preserved. + * page/ScrollToOptions.idl: Make this class inherit from ScrollOptions. + * page/Settings.yaml: New setting for CSSOM View smooth scrolling. + * platform/ScrollAnimation.h: + (WebCore::ScrollAnimation::scroll): Function to animate scrolling to a specified position. + (WebCore::ScrollAnimation::isScrollInProgress const): + * platform/ScrollAnimationKinetic.cpp: + (WebCore::ScrollAnimationKinetic::isScrollInProgress const): + * platform/ScrollAnimationKinetic.h: + * 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::isScrollInProgress const): For now, only claims scroll is in + progress if smooth programmatic scroll is in progress. + (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. + * platform/ScrollAnimatorMac.mm: + (WebCore::ScrollAnimatorMac::cancelAnimations): Call parent member to handle programmatic 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/ScrollableArea.cpp: + (WebCore::ScrollableArea::isScrollInProgress const): Helper function to check whether scroll + is in progress on the animator. If m_scrollAnimator does not exist we don't construct it. + (WebCore::ScrollableArea::scrollToOffsetWithAnimation): + * platform/ScrollableArea.h: + * rendering/RenderBox.cpp: + (WebCore::RenderBox::scrollToPositionWithAnimation): Similar to setScrollTop/setScrollLeft + but animate the scrolling. + * rendering/RenderBox.h: + * rendering/RenderLayer.cpp: + (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). + (WebCore::RenderLayer::scrollToOffsetWithAnimation): Ditto. This is similar to scrollToOffset + but animates the scroll. + (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/style/RenderStyle.h: Handle 'smooth scrolling' boolean data. + (WebCore::RenderStyle::useSmoothScrolling const): + (WebCore::RenderStyle::setUseSmoothScrolling): + (WebCore::RenderStyle::initialUseSmoothScrolling): + * rendering/style/StyleRareNonInheritedData.cpp: Ditto. + (WebCore::StyleRareNonInheritedData::StyleRareNonInheritedData): + (WebCore::StyleRareNonInheritedData::operator== const): + * rendering/style/StyleRareNonInheritedData.h: Ditto. + * testing/Internals.cpp: + (WebCore::Internals::unconstrainedScrollTo): Use fromCoordinates helper function. + 2019-06-24 Wenson Hsieh [Text autosizing] [iPadOS] Revise our heuristics to determine idempotent text autosizing candidates diff --git a/Source/WebCore/DerivedSources.make b/Source/WebCore/DerivedSources.make index d88aed458f0..1c0230b1bd2 100644 --- a/Source/WebCore/DerivedSources.make +++ b/Source/WebCore/DerivedSources.make @@ -879,8 +879,10 @@ JS_BINDING_IDLS = \ $(WebCore)/page/ResizeObserverCallback.idl \ $(WebCore)/page/ResizeObserverEntry.idl \ $(WebCore)/page/Screen.idl \ + $(WebCore)/page/ScrollBehavior.idl \ $(WebCore)/page/ScrollIntoViewOptions.idl \ $(WebCore)/page/ScrollLogicalPosition.idl \ + $(WebCore)/page/ScrollOptions.idl \ $(WebCore)/page/ScrollToOptions.idl \ $(WebCore)/page/ShareData.idl \ $(WebCore)/page/UndoItem.idl \ diff --git a/Source/WebCore/Headers.cmake b/Source/WebCore/Headers.cmake index a81d82ab8df..e41ef886153 100644 --- a/Source/WebCore/Headers.cmake +++ b/Source/WebCore/Headers.cmake @@ -805,8 +805,10 @@ set(WebCore_PRIVATE_FRAMEWORK_HEADERS page/RemoteFrame.h page/RenderingUpdateScheduler.h page/RuntimeEnabledFeatures.h + page/ScrollBehavior.h page/ScrollIntoViewOptions.h page/ScrollLogicalPosition.h + page/ScrollOptions.h page/ScrollToOptions.h page/SecurityOrigin.h page/SecurityOriginData.h diff --git a/Source/WebCore/Sources.txt b/Source/WebCore/Sources.txt index 155c66139b5..dc9ca598e67 100644 --- a/Source/WebCore/Sources.txt +++ b/Source/WebCore/Sources.txt @@ -1554,6 +1554,7 @@ page/ResourceUsageOverlay.cpp page/ResourceUsageThread.cpp page/RuntimeEnabledFeatures.cpp page/Screen.cpp +page/ScrollBehavior.cpp page/SecurityOrigin.cpp page/SecurityOriginData.cpp page/SecurityPolicy.cpp @@ -1657,6 +1658,7 @@ platform/RuntimeApplicationChecks.cpp platform/SSLKeyGenerator.cpp platform/SchemeRegistry.cpp platform/ScrollAnimator.cpp +platform/ScrollAnimationSmooth.cpp platform/ScrollView.cpp platform/ScrollableArea.cpp platform/Scrollbar.cpp @@ -3237,8 +3239,10 @@ JSSVGZoomEvent.cpp JSScreen.cpp JSScreenLuminance.cpp JSScriptProcessorNode.cpp +JSScrollBehavior.cpp JSScrollIntoViewOptions.cpp JSScrollLogicalPosition.cpp +JSScrollOptions.cpp JSScrollToOptions.cpp JSSecurityPolicyViolationEvent.cpp JSServiceWorker.cpp diff --git a/Source/WebCore/SourcesGTK.txt b/Source/WebCore/SourcesGTK.txt index 33430f903c8..81a91c77b31 100644 --- a/Source/WebCore/SourcesGTK.txt +++ b/Source/WebCore/SourcesGTK.txt @@ -60,7 +60,6 @@ page/scrolling/nicosia/ScrollingTreeStickyNode.cpp page/scrolling/generic/ScrollingThreadGeneric.cpp platform/ScrollAnimationKinetic.cpp -platform/ScrollAnimationSmooth.cpp platform/UserAgentQuirks.cpp platform/generic/ScrollAnimatorGeneric.cpp diff --git a/Source/WebCore/WebCore.xcodeproj/project.pbxproj b/Source/WebCore/WebCore.xcodeproj/project.pbxproj index ae4802efa5b..cde7690003a 100644 --- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj +++ b/Source/WebCore/WebCore.xcodeproj/project.pbxproj @@ -2406,6 +2406,8 @@ 83407FC11E8D9C1700E048D3 /* VisibilityChangeClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 83407FC01E8D9C1200E048D3 /* VisibilityChangeClient.h */; settings = {ATTRIBUTES = (Private, ); }; }; 834476EF1DA5BC5E002B5EB0 /* JSScrollLogicalPosition.h in Headers */ = {isa = PBXBuildFile; fileRef = 83E9B3011DA5A51E00FFD8D4 /* JSScrollLogicalPosition.h */; }; 834476EF1DA5BC5E002B5EC1 /* JSScrollIntoViewOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 83E9B3011DA5A51E00FFD8E5 /* JSScrollIntoViewOptions.h */; }; + 834476EF1DA5BC5E002B6EB0 /* JSScrollBehavior.h in Headers */ = {isa = PBXBuildFile; fileRef = 83E9B3011DA5A51E00FFE8D4 /* JSScrollBehavior.h */; }; + 834476EF1DA5BC5E002B6EC1 /* JSScrollOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 83E9B3011DA5A51E00FFE8E5 /* JSScrollOptions.h */; }; 834476EF1DA5BC5E002B6ED2 /* JSScrollToOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 83E9B3011DA5A51E00FFE8F6 /* JSScrollToOptions.h */; }; 8348BFAC1B85729800912F36 /* ClassCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = 8348BFAA1B85729500912F36 /* ClassCollection.h */; }; 834DFAD01F7DAE5D00C2725B /* SharedStringHash.h in Headers */ = {isa = PBXBuildFile; fileRef = 834DFACC1F7DAE5600C2725B /* SharedStringHash.h */; settings = {ATTRIBUTES = (Private, ); }; }; @@ -2461,6 +2463,8 @@ 83C45B8E1DC2B68A008871BA /* ValidationBubble.h in Headers */ = {isa = PBXBuildFile; fileRef = 83C45B8D1DC2B67C008871BA /* ValidationBubble.h */; settings = {ATTRIBUTES = (Private, ); }; }; 83C5795D1DA5C301006F9C86 /* ScrollLogicalPosition.h in Headers */ = {isa = PBXBuildFile; fileRef = 8350C3E71DA59B6200355424 /* ScrollLogicalPosition.h */; settings = {ATTRIBUTES = (Private, ); }; }; 83C5795D1DA5C301006F9C97 /* ScrollIntoViewOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 8350C3E71DA59B6200355435 /* ScrollIntoViewOptions.h */; settings = {ATTRIBUTES = (Private, ); }; }; + 83C5795D1DA5C301006FAC86 /* ScrollBehavior.h in Headers */ = {isa = PBXBuildFile; fileRef = 8350C3E71DA59B6200356424 /* ScrollBehavior.h */; settings = {ATTRIBUTES = (Private, ); }; }; + 83C5795D1DA5C301006FAC97 /* ScrollOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 8350C3E71DA59B6200356435 /* ScrollOptions.h */; settings = {ATTRIBUTES = (Private, ); }; }; 83C5795D1DA5C301006FACA8 /* ScrollToOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 8350C3E71DA59B6200356446 /* ScrollToOptions.h */; settings = {ATTRIBUTES = (Private, ); }; }; 83D35AEC1C7187FA00F70D5A /* XMLHttpRequestEventTarget.h in Headers */ = {isa = PBXBuildFile; fileRef = 83D35AEA1C7187ED00F70D5A /* XMLHttpRequestEventTarget.h */; }; 83D35AF21C718D9000F70D5A /* JSXMLHttpRequestEventTarget.h in Headers */ = {isa = PBXBuildFile; fileRef = 83D35AF01C718D8400F70D5A /* JSXMLHttpRequestEventTarget.h */; }; @@ -10037,6 +10041,12 @@ 834DFACE1F7DAE5700C2725B /* SharedStringHash.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SharedStringHash.cpp; sourceTree = ""; }; 8350C3E71DA59B6200355424 /* ScrollLogicalPosition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollLogicalPosition.h; sourceTree = ""; }; 8350C3E71DA59B6200355435 /* ScrollIntoViewOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollIntoViewOptions.h; sourceTree = ""; }; + 8350C3E81DA59B6200355435 /* ScrollIntoViewOptions.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ScrollIntoViewOptions.idl; sourceTree = ""; }; + 8350C3E71DA59B6200356424 /* ScrollBehavior.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollBehavior.h; sourceTree = ""; }; + 8350C3E71DA59B6200356434 /* ScrollBehavior.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollBehavior.cpp; sourceTree = ""; }; + 8350C3E81DA59B6200356424 /* ScrollBehavior.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ScrollBehavior.idl; sourceTree = ""; }; + 8350C3E71DA59B6200356435 /* ScrollOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollOptions.h; sourceTree = ""; }; + 8350C3E81DA59B6200356435 /* ScrollOptions.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ScrollOptions.idl; sourceTree = ""; }; 8350C3E71DA59B6200356446 /* ScrollToOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollToOptions.h; sourceTree = ""; }; 8350C3E81DA59B6200355424 /* ScrollLogicalPosition.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ScrollLogicalPosition.idl; sourceTree = ""; }; 8350C3E81DA59B6200355435 /* ScrollIntoViewOptions.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ScrollIntoViewOptions.idl; sourceTree = ""; }; @@ -10158,6 +10168,11 @@ 83E959E11B8BC22B004D9385 /* NativeNodeFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NativeNodeFilter.h; sourceTree = ""; }; 83E9B3001DA5A51E00FFD8D4 /* JSScrollLogicalPosition.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSScrollLogicalPosition.cpp; sourceTree = ""; }; 83E9B3001DA5A51E00FFD8E5 /* JSScrollIntoViewOptions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSScrollIntoViewOptions.cpp; sourceTree = ""; }; + 83E9B3011DA5A51E00FFD8E5 /* JSScrollIntoViewOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSScrollIntoViewOptions.h; sourceTree = ""; }; + 83E9B3001DA5A51E00FFE8D4 /* JSScrollBehavior.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSScrollBehavior.cpp; sourceTree = ""; }; + 83E9B3011DA5A51E00FFE8D4 /* JSScrollBehavior.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSScrollBehavior.h; sourceTree = ""; }; + 83E9B3001DA5A51E00FFE8E5 /* JSScrollOptions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSScrollOptions.cpp; sourceTree = ""; }; + 83E9B3011DA5A51E00FFE8E5 /* JSScrollOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSScrollOptions.h; sourceTree = ""; }; 83E9B3001DA5A51E00FFE8F6 /* JSScrollToOptions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSScrollToOptions.cpp; sourceTree = ""; }; 83E9B3011DA5A51E00FFD8D4 /* JSScrollLogicalPosition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSScrollLogicalPosition.h; sourceTree = ""; }; 83E9B3011DA5A51E00FFD8E5 /* JSScrollIntoViewOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSScrollIntoViewOptions.h; sourceTree = ""; }; @@ -20351,10 +20366,15 @@ BCEC01BA0C274DAC009F4EC9 /* Screen.cpp */, BCEC01BB0C274DAC009F4EC9 /* Screen.h */, BCEC01BC0C274DAC009F4EC9 /* Screen.idl */, + 8350C3E71DA59B6200356434 /* ScrollBehavior.cpp */, + 8350C3E71DA59B6200356424 /* ScrollBehavior.h */, + 8350C3E81DA59B6200356424 /* ScrollBehavior.idl */, 8350C3E71DA59B6200355435 /* ScrollIntoViewOptions.h */, 8350C3E81DA59B6200355435 /* ScrollIntoViewOptions.idl */, 8350C3E71DA59B6200355424 /* ScrollLogicalPosition.h */, 8350C3E81DA59B6200355424 /* ScrollLogicalPosition.idl */, + 8350C3E71DA59B6200356435 /* ScrollOptions.h */, + 8350C3E81DA59B6200356435 /* ScrollOptions.idl */, 8350C3E71DA59B6200356446 /* ScrollToOptions.h */, 8350C3E81DA59B6200356446 /* ScrollToOptions.idl */, BCD0E0F70E972C3500265DEA /* SecurityOrigin.cpp */, @@ -25067,10 +25087,14 @@ 58B2FA022232D60A00938D63 /* JSResizeObserverEntry.h */, BCEC01C00C274DDD009F4EC9 /* JSScreen.cpp */, BCEC01C10C274DDD009F4EC9 /* JSScreen.h */, + 83E9B3001DA5A51E00FFE8D4 /* JSScrollBehavior.cpp */, + 83E9B3011DA5A51E00FFE8D4 /* JSScrollBehavior.h */, 83E9B3001DA5A51E00FFD8E5 /* JSScrollIntoViewOptions.cpp */, 83E9B3011DA5A51E00FFD8E5 /* JSScrollIntoViewOptions.h */, 83E9B3001DA5A51E00FFD8D4 /* JSScrollLogicalPosition.cpp */, 83E9B3011DA5A51E00FFD8D4 /* JSScrollLogicalPosition.h */, + 83E9B3001DA5A51E00FFE8E5 /* JSScrollOptions.cpp */, + 83E9B3011DA5A51E00FFE8E5 /* JSScrollOptions.h */, 83E9B3001DA5A51E00FFE8F6 /* JSScrollToOptions.cpp */, 83E9B3011DA5A51E00FFE8F6 /* JSScrollToOptions.h */, 7C73FB0F191EF6F4007DE061 /* JSUserMessageHandler.cpp */, @@ -30210,8 +30234,10 @@ 5E2C436C1BCF071E0001E2BC /* JSRTCTrackEvent.h in Headers */, BCEC01C30C274DDD009F4EC9 /* JSScreen.h in Headers */, FDA15ECE12B03F61003A583A /* JSScriptProcessorNode.h in Headers */, + 834476EF1DA5BC5E002B6EB0 /* JSScrollBehavior.h in Headers */, 834476EF1DA5BC5E002B5EC1 /* JSScrollIntoViewOptions.h in Headers */, 834476EF1DA5BC5E002B5EB0 /* JSScrollLogicalPosition.h in Headers */, + 834476EF1DA5BC5E002B6EC1 /* JSScrollOptions.h in Headers */, 834476EF1DA5BC5E002B6ED2 /* JSScrollToOptions.h in Headers */, CED06AD11C77754800FDFAF1 /* JSSecurityPolicyViolationEvent.h in Headers */, 5182C2561F3143CD0059BA7C /* JSServiceWorker.h in Headers */, @@ -31394,6 +31420,7 @@ 44C991860F3D1EBE00586670 /* ScrollbarThemeIOS.h in Headers */, BC8B853E0E7C7F1100AB6984 /* ScrollbarThemeMac.h in Headers */, 0FE71406142170B800DB33BA /* ScrollbarThemeMock.h in Headers */, + 83C5795D1DA5C301006FAC86 /* ScrollBehavior.h in Headers */, 1AA84F05143BA7BD0051D153 /* ScrollController.h in Headers */, 0F605AED15F94848004DF0C0 /* ScrollingConstraints.h in Headers */, 1AF62EE814DA22A70041556C /* ScrollingCoordinator.h in Headers */, @@ -31430,6 +31457,7 @@ 83C5795D1DA5C301006F9C97 /* ScrollIntoViewOptions.h in Headers */, 7AAFE8D019CB8672000F56D8 /* ScrollLatchingState.h in Headers */, 83C5795D1DA5C301006F9C86 /* ScrollLogicalPosition.h in Headers */, + 83C5795D1DA5C301006FAC97 /* ScrollOptions.h in Headers */, F478755419983AFF0024A287 /* ScrollSnapAnimatorState.h in Headers */, F46729281E0DE68500ACC3D8 /* ScrollSnapOffsetsInfo.h in Headers */, 83C5795D1DA5C301006FACA8 /* ScrollToOptions.h in Headers */, diff --git a/Source/WebCore/css/CSSComputedStyleDeclaration.cpp b/Source/WebCore/css/CSSComputedStyleDeclaration.cpp index aff6d3aba30..8ddd5315997 100644 --- a/Source/WebCore/css/CSSComputedStyleDeclaration.cpp +++ b/Source/WebCore/css/CSSComputedStyleDeclaration.cpp @@ -434,6 +434,9 @@ static const CSSPropertyID computedProperties[] = { #if ENABLE(OVERFLOW_SCROLLING_TOUCH) CSSPropertyWebkitOverflowScrolling, #endif + CSSPropertyScrollBehavior, + CSSPropertyPerspective, + CSSPropertyPerspectiveOrigin, CSSPropertyWebkitPrintColorAdjust, CSSPropertyWebkitRtlOrdering, #if ENABLE(TOUCH_EVENTS) @@ -3717,6 +3720,10 @@ RefPtr ComputedStyleExtractor::valueForPropertyInStyle(const RenderSty return cssValuePool.createIdentifierValue(CSSValueAuto); return cssValuePool.createIdentifierValue(CSSValueTouch); #endif + case CSSPropertyScrollBehavior: + if (!style.useSmoothScrolling()) + return cssValuePool.createIdentifierValue(CSSValueAuto); + return cssValuePool.createIdentifierValue(CSSValueSmooth); case CSSPropertyPerspective: if (!style.hasPerspective()) return cssValuePool.createIdentifierValue(CSSValueNone); diff --git a/Source/WebCore/css/CSSProperties.json b/Source/WebCore/css/CSSProperties.json index bcf161c01b4..f36ab8def54 100644 --- a/Source/WebCore/css/CSSProperties.json +++ b/Source/WebCore/css/CSSProperties.json @@ -6492,6 +6492,22 @@ "url": "https://www.w3.org/TR/css-ui-4/#propdef-user-select" } }, + "scroll-behavior": { + "values": [ + "auto", + "smooth" + ], + "codegen-properties": { + "converter": "SmoothScrolling", + "name-for-methods": "UseSmoothScrolling" + }, + "status": { + "status": "experimental" + }, + "specification": { + "url": "https://drafts.csswg.org/cssom-view/#propdef-scroll-behavior" + } + }, "scroll-padding": { "codegen-properties": { "enable-if": "ENABLE_CSS_SCROLL_SNAP", diff --git a/Source/WebCore/css/CSSValueKeywords.in b/Source/WebCore/css/CSSValueKeywords.in index c4767f5a731..d4a50311381 100644 --- a/Source/WebCore/css/CSSValueKeywords.in +++ b/Source/WebCore/css/CSSValueKeywords.in @@ -1384,6 +1384,10 @@ pan-y pinch-zoom #endif +// scroll-behavior +// auto +smooth + // hanging-punctuation allow-end first diff --git a/Source/WebCore/css/StyleBuilderConverter.h b/Source/WebCore/css/StyleBuilderConverter.h index 69af5581565..adcceb5c9c4 100644 --- a/Source/WebCore/css/StyleBuilderConverter.h +++ b/Source/WebCore/css/StyleBuilderConverter.h @@ -127,6 +127,7 @@ public: #if ENABLE(OVERFLOW_SCROLLING_TOUCH) static bool convertOverflowScrolling(StyleResolver&, const CSSValue&); #endif + static bool convertSmoothScrolling(StyleResolver&, const CSSValue&); static FontFeatureSettings convertFontFeatureSettings(StyleResolver&, const CSSValue&); static FontSelectionValue convertFontWeightFromValue(const CSSValue&); static FontSelectionValue convertFontStretchFromValue(const CSSValue&); @@ -1404,6 +1405,11 @@ inline bool StyleBuilderConverter::convertOverflowScrolling(StyleResolver&, cons } #endif +inline bool StyleBuilderConverter::convertSmoothScrolling(StyleResolver&, const CSSValue& value) +{ + return downcast(value).valueID() == CSSValueSmooth; +} + inline SVGLengthValue StyleBuilderConverter::convertSVGLengthValue(StyleResolver&, const CSSValue& value) { return SVGLengthValue::fromCSSPrimitiveValue(downcast(value)); diff --git a/Source/WebCore/css/parser/CSSParserContext.cpp b/Source/WebCore/css/parser/CSSParserContext.cpp index 7537188cb93..71f9aa62c4c 100644 --- a/Source/WebCore/css/parser/CSSParserContext.cpp +++ b/Source/WebCore/css/parser/CSSParserContext.cpp @@ -75,6 +75,7 @@ CSSParserContext::CSSParserContext(const Document& document, const URL& sheetBas attachmentEnabled = RuntimeEnabledFeatures::sharedFeatures().attachmentElementEnabled(); #endif deferredCSSParserEnabled = document.settings().deferredCSSParserEnabled(); + scrollBehaviorEnabled = document.settings().CSSOMViewSmoothScrollingEnabled(); useSystemAppearance = document.page() ? document.page()->useSystemAppearance() : false; } @@ -99,6 +100,7 @@ bool operator==(const CSSParserContext& a, const CSSParserContext& b) && a.attachmentEnabled == b.attachmentEnabled #endif && a.deferredCSSParserEnabled == b.deferredCSSParserEnabled + && a.scrollBehaviorEnabled == b.scrollBehaviorEnabled && a.hasDocumentSecurityOrigin == b.hasDocumentSecurityOrigin && a.useSystemAppearance == b.useSystemAppearance; } diff --git a/Source/WebCore/css/parser/CSSParserContext.h b/Source/WebCore/css/parser/CSSParserContext.h index a302b3878da..4a15b136a04 100644 --- a/Source/WebCore/css/parser/CSSParserContext.h +++ b/Source/WebCore/css/parser/CSSParserContext.h @@ -61,6 +61,7 @@ public: bool attachmentEnabled { false }; #endif bool deferredCSSParserEnabled { false }; + bool scrollBehaviorEnabled { false }; // This is only needed to support getMatchedCSSRules. bool hasDocumentSecurityOrigin { false }; @@ -110,7 +111,8 @@ struct CSSParserContextHash { #if ENABLE(ATTACHMENT_ELEMENT) & key.attachmentEnabled << 11 #endif - & key.mode << 12; // Keep this last. + & key.scrollBehaviorEnabled << 12 + & key.mode << 13; // Keep this last. hash ^= WTF::intHash(bits); return hash; } diff --git a/Source/WebCore/css/parser/CSSParserFastPaths.cpp b/Source/WebCore/css/parser/CSSParserFastPaths.cpp index b949cc8bd60..04ce31411d1 100644 --- a/Source/WebCore/css/parser/CSSParserFastPaths.cpp +++ b/Source/WebCore/css/parser/CSSParserFastPaths.cpp @@ -634,10 +634,6 @@ bool CSSParserFastPaths::isValidKeywordPropertyAndValue(CSSPropertyID propertyId || valueID == CSSValueSticky || valueID == CSSValueWebkitSticky; case CSSPropertyResize: // none | both | horizontal | vertical | auto return valueID == CSSValueNone || valueID == CSSValueBoth || valueID == CSSValueHorizontal || valueID == CSSValueVertical || valueID == CSSValueAuto; - // FIXME-NEWPARSER: Investigate this property. - // case CSSPropertyScrollBehavior: // auto | smooth - // ASSERT(RuntimeEnabledFeatures::cssomSmoothScrollEnabled()); - // return valueID == CSSValueAuto || valueID == CSSValueSmooth; case CSSPropertyShapeRendering: return valueID == CSSValueAuto || valueID == CSSValueOptimizeSpeed || valueID == CSSValueCrispedges || valueID == CSSValueGeometricPrecision; case CSSPropertyStrokeLinejoin: @@ -937,7 +933,6 @@ bool CSSParserFastPaths::isKeywordPropertyID(CSSPropertyID propertyId) // case CSSPropertyFontKerning: // case CSSPropertyHyphens: // case CSSPropertyOverflowAnchor: - // case CSSPropertyScrollBehavior: // case CSSPropertyScrollSnapType: // case CSSPropertyTextAlignLast: // case CSSPropertyTextCombineUpright: diff --git a/Source/WebCore/css/parser/CSSPropertyParser.cpp b/Source/WebCore/css/parser/CSSPropertyParser.cpp index 902da151c03..25021d91816 100644 --- a/Source/WebCore/css/parser/CSSPropertyParser.cpp +++ b/Source/WebCore/css/parser/CSSPropertyParser.cpp @@ -2323,6 +2323,14 @@ static RefPtr consumeScrollSnapType(CSSParserTokenRange& range) #endif +static RefPtr consumeScrollBehavior(CSSParserTokenRange& range) +{ + auto valueID = range.peek().id(); + if (valueID != CSSValueAuto && valueID != CSSValueSmooth) + return nullptr; + return consumeIdent(range); +} + static RefPtr consumeBorderRadiusCorner(CSSParserTokenRange& range, CSSParserMode cssParserMode) { RefPtr parsedValue1 = consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative); @@ -3922,6 +3930,10 @@ RefPtr CSSPropertyParser::parseSingleValue(CSSPropertyID property, CSS case CSSPropertyScrollSnapType: return consumeScrollSnapType(m_range); #endif + case CSSPropertyScrollBehavior: + if (!m_context.scrollBehaviorEnabled) + return nullptr; + return consumeScrollBehavior(m_range); case CSSPropertyClip: return consumeClip(m_range, m_context.mode); #if ENABLE(POINTER_EVENTS) diff --git a/Source/WebCore/dom/Element.cpp b/Source/WebCore/dom/Element.cpp index f07c5ec61d2..4bdd15c4bc3 100644 --- a/Source/WebCore/dom/Element.cpp +++ b/Source/WebCore/dom/Element.cpp @@ -729,7 +729,6 @@ void Element::scrollIntoView(Optional>&& ar bool insideFixed; LayoutRect absoluteBounds = renderer()->absoluteAnchorRect(&insideFixed); - // FIXME(webkit.org/b/188043): Support ScrollBehavior. ScrollIntoViewOptions options; if (arg) { auto value = arg.value(); @@ -739,9 +738,15 @@ void Element::scrollIntoView(Optional>&& ar options.blockPosition = ScrollLogicalPosition::End; } - ScrollAlignment alignX = toScrollAlignment(options.inlinePosition, false); - ScrollAlignment alignY = toScrollAlignment(options.blockPosition, true); - renderer()->scrollRectToVisible(absoluteBounds, insideFixed, { SelectionRevealMode::Reveal, alignX, alignY, ShouldAllowCrossOriginScrolling::No }); + ScrollRectToVisibleOptions scrollRectToVisibleOptions { + SelectionRevealMode::Reveal, + toScrollAlignment(options.inlinePosition, false), + toScrollAlignment(options.blockPosition, true), + ShouldAllowCrossOriginScrolling::No, + }; + if (options.behavior) + scrollRectToVisibleOptions.behavior = options.behavior.value(); + renderer()->scrollRectToVisible(absoluteBounds, insideFixed, scrollRectToVisibleOptions); } void Element::scrollIntoView(bool alignToTop) @@ -800,7 +805,7 @@ void Element::scrollBy(const ScrollToOptions& options) void Element::scrollBy(double x, double y) { - scrollBy({ x, y }); + scrollBy(fromCoordinates(x, y)); } void Element::scrollTo(const ScrollToOptions& options, ScrollClamping clamping) @@ -836,13 +841,21 @@ void Element::scrollTo(const ScrollToOptions& options, ScrollClamping clamping) adjustForAbsoluteZoom(renderer->scrollLeft(), *renderer), adjustForAbsoluteZoom(renderer->scrollTop(), *renderer) ); - renderer->setScrollLeft(clampToInteger(scrollToOptions.left.value() * renderer->style().effectiveZoom()), ScrollType::Programmatic, clamping); - renderer->setScrollTop(clampToInteger(scrollToOptions.top.value() * renderer->style().effectiveZoom()), ScrollType::Programmatic, clamping); + IntPoint scrollPosition( + clampToInteger(scrollToOptions.left.value() * renderer->style().effectiveZoom()), + clampToInteger(scrollToOptions.top.value() * renderer->style().effectiveZoom()) + ); + if (useSmoothScrolling(scrollToOptions.behavior.valueOr(ScrollBehavior::Auto), *this)) { + renderer->scrollToPositionWithAnimation(scrollPosition, clamping); + return; + } + renderer->setScrollLeft(scrollPosition.x(), ScrollType::Programmatic, clamping); + renderer->setScrollTop(scrollPosition.y(), ScrollType::Programmatic, clamping); } void Element::scrollTo(double x, double y) { - scrollTo({ x, y }); + scrollTo(fromCoordinates(x, y)); } void Element::scrollByUnits(int units, ScrollGranularity granularity) diff --git a/Source/WebCore/page/DOMWindow.cpp b/Source/WebCore/page/DOMWindow.cpp index 29476b00b7e..41e0cd017eb 100644 --- a/Source/WebCore/page/DOMWindow.cpp +++ b/Source/WebCore/page/DOMWindow.cpp @@ -1567,7 +1567,7 @@ double DOMWindow::devicePixelRatio() const void DOMWindow::scrollBy(double x, double y) const { - scrollBy({ x, y }); + scrollBy(fromCoordinates(x, y)); } void DOMWindow::scrollBy(const ScrollToOptions& options) const @@ -1589,10 +1589,10 @@ void DOMWindow::scrollBy(const ScrollToOptions& options) const void DOMWindow::scrollTo(double x, double y, ScrollClamping clamping) const { - scrollTo({ x, y }, clamping); + scrollTo(fromCoordinates(x, y), clamping); } -void DOMWindow::scrollTo(const ScrollToOptions& options, ScrollClamping) const +void DOMWindow::scrollTo(const ScrollToOptions& options, ScrollClamping clamping) const { if (!isCurrentlyDisplayedInFrame()) return; @@ -1605,12 +1605,18 @@ void DOMWindow::scrollTo(const ScrollToOptions& options, ScrollClamping) const view->contentsScrollPosition().x(), view->contentsScrollPosition().y() ); - if (!scrollToOptions.left.value() && !scrollToOptions.top.value() && view->contentsScrollPosition() == IntPoint(0, 0)) + if (!view->isScrollInProgress() && !scrollToOptions.left.value() && !scrollToOptions.top.value() && view->contentsScrollPosition() == IntPoint(0, 0)) return; document()->updateLayoutIgnorePendingStylesheets(); IntPoint layoutPos(view->mapFromCSSToLayoutUnits(scrollToOptions.left.value()), view->mapFromCSSToLayoutUnits(scrollToOptions.top.value())); + // FIXME: Should we use document()->scrollingElement()? + // See https://github.com/w3c/csswg-drafts/issues/2977 + if (document()->documentElement() && useSmoothScrolling(scrollToOptions.behavior.valueOr(ScrollBehavior::Auto), *document()->documentElement())) { + view->scrollToOffsetWithAnimation(layoutPos, clamping); + return; + } view->setContentsScrollPosition(layoutPos); } diff --git a/Source/WebCore/page/ScrollBehavior.cpp b/Source/WebCore/page/ScrollBehavior.cpp new file mode 100644 index 00000000000..5328c9b83a8 --- /dev/null +++ b/Source/WebCore/page/ScrollBehavior.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2018 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "ScrollBehavior.h" + +#include "Element.h" +#include "RenderElement.h" +#include "RenderStyle.h" +#include "Settings.h" + +namespace WebCore { + +bool useSmoothScrolling(ScrollBehavior behavior, Element& associatedElement) +{ + if (!associatedElement.document().settings().CSSOMViewSmoothScrollingEnabled() || !associatedElement.renderer()) + return false; + + // https://drafts.csswg.org/cssom-view/#scrolling + switch (behavior) { + case ScrollBehavior::Auto: + return associatedElement.renderer()->style().useSmoothScrolling(); + case ScrollBehavior::Instant: + return false; + case ScrollBehavior::Smooth: + return true; + } + ASSERT_NOT_REACHED(); + return false; +} + +} // namespace WebCore diff --git a/Source/WebCore/page/ScrollBehavior.h b/Source/WebCore/page/ScrollBehavior.h new file mode 100644 index 00000000000..f01497b0307 --- /dev/null +++ b/Source/WebCore/page/ScrollBehavior.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2018 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#pragma once + +namespace WebCore { + +class Element; + +enum class ScrollBehavior : uint8_t { + Auto = 0, + Instant, + Smooth +}; + +bool useSmoothScrolling(ScrollBehavior, Element& associatedElement); + +} // namespace WebCore diff --git a/Source/WebCore/page/ScrollBehavior.idl b/Source/WebCore/page/ScrollBehavior.idl new file mode 100644 index 00000000000..a865fbe665b --- /dev/null +++ b/Source/WebCore/page/ScrollBehavior.idl @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2018 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +enum ScrollBehavior { "auto", "instant", "smooth" }; diff --git a/Source/WebCore/page/ScrollIntoViewOptions.h b/Source/WebCore/page/ScrollIntoViewOptions.h index 939cd73425a..f275f2fbd1a 100644 --- a/Source/WebCore/page/ScrollIntoViewOptions.h +++ b/Source/WebCore/page/ScrollIntoViewOptions.h @@ -20,12 +20,11 @@ #pragma once #include "ScrollLogicalPosition.h" +#include "ScrollOptions.h" namespace WebCore { -class Element; - -struct ScrollIntoViewOptions { +struct ScrollIntoViewOptions : ScrollOptions { Optional blockPosition { ScrollLogicalPosition::Start }; Optional inlinePosition { ScrollLogicalPosition::Nearest }; }; diff --git a/Source/WebCore/page/ScrollIntoViewOptions.idl b/Source/WebCore/page/ScrollIntoViewOptions.idl index cf9d1fd7678..1b24c686fc7 100644 --- a/Source/WebCore/page/ScrollIntoViewOptions.idl +++ b/Source/WebCore/page/ScrollIntoViewOptions.idl @@ -17,8 +17,7 @@ * Boston, MA 02110-1301, USA. */ -// FIXME(webkit.org/b/188043): Support ScrollBehavior. -dictionary ScrollIntoViewOptions { +dictionary ScrollIntoViewOptions : ScrollOptions { [ImplementedAs=blockPosition] ScrollLogicalPosition block = "start"; [ImplementedAs=inlinePosition] ScrollLogicalPosition inline = "nearest"; }; diff --git a/Source/WebCore/page/ScrollOptions.h b/Source/WebCore/page/ScrollOptions.h new file mode 100644 index 00000000000..e7f63b9ff1c --- /dev/null +++ b/Source/WebCore/page/ScrollOptions.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2018 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#pragma once + +#include "ScrollBehavior.h" + +namespace WebCore { + +struct ScrollOptions { + Optional behavior { ScrollBehavior::Auto }; +}; + +} // namespace WebCore diff --git a/Source/WebCore/page/ScrollOptions.idl b/Source/WebCore/page/ScrollOptions.idl new file mode 100644 index 00000000000..140f5c70ed1 --- /dev/null +++ b/Source/WebCore/page/ScrollOptions.idl @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2018 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +dictionary ScrollOptions { + ScrollBehavior behavior = "auto"; +}; diff --git a/Source/WebCore/page/ScrollToOptions.h b/Source/WebCore/page/ScrollToOptions.h index ce1cba1c7c0..65b6e571db9 100644 --- a/Source/WebCore/page/ScrollToOptions.h +++ b/Source/WebCore/page/ScrollToOptions.h @@ -28,16 +28,25 @@ #pragma once +#include "ScrollOptions.h" #include #include namespace WebCore { -struct ScrollToOptions { +struct ScrollToOptions : ScrollOptions { Optional left; Optional top; }; +inline ScrollToOptions fromCoordinates(double x, double y) +{ + ScrollToOptions options; + options.left = x; + options.top = y; + return options; +}; + inline double normalizeNonFiniteValueOrFallBackTo(Optional value, double fallbackValue) { // Normalize non-finite values (https://drafts.csswg.org/cssom-view/#normalize-non-finite-values). @@ -47,7 +56,7 @@ inline double normalizeNonFiniteValueOrFallBackTo(Optional value, double // FIXME(https://webkit.org/b/88339): Consider using FloatPoint or DoublePoint for fallback and return values. inline ScrollToOptions normalizeNonFiniteCoordinatesOrFallBackTo(const ScrollToOptions& value, double x, double y) { - ScrollToOptions options; + ScrollToOptions options = value; options.left = normalizeNonFiniteValueOrFallBackTo(value.left, x); options.top = normalizeNonFiniteValueOrFallBackTo(value.top, y); return options; diff --git a/Source/WebCore/page/ScrollToOptions.idl b/Source/WebCore/page/ScrollToOptions.idl index 510bc071a68..2b9b554122a 100644 --- a/Source/WebCore/page/ScrollToOptions.idl +++ b/Source/WebCore/page/ScrollToOptions.idl @@ -26,8 +26,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -// FIXME(webkit.org/b/188043): Support ScrollBehavior. -dictionary ScrollToOptions { +dictionary ScrollToOptions : ScrollOptions { unrestricted double left; unrestricted double top; }; diff --git a/Source/WebCore/page/Settings.yaml b/Source/WebCore/page/Settings.yaml index cbc73a110fb..49ab6aeb080 100644 --- a/Source/WebCore/page/Settings.yaml +++ b/Source/WebCore/page/Settings.yaml @@ -595,6 +595,9 @@ syntheticEditingCommandsEnabled: CSSOMViewScrollingAPIEnabled: initial: false +CSSOMViewSmoothScrollingEnabled: + initial: false + inputEventsEnabled: initial: true diff --git a/Source/WebCore/platform/ScrollAnimation.h b/Source/WebCore/platform/ScrollAnimation.h index 2e5f63bcef2..501007e04d2 100644 --- a/Source/WebCore/platform/ScrollAnimation.h +++ b/Source/WebCore/platform/ScrollAnimation.h @@ -32,15 +32,18 @@ namespace WebCore { class FloatPoint; class ScrollableArea; +enum class ScrollClamping : uint8_t; class ScrollAnimation { public: virtual ~ScrollAnimation() { }; virtual bool scroll(ScrollbarOrientation, ScrollGranularity, float /* step */, float /* multiplier */) { return true; }; + virtual void scroll(const FloatPoint&, ScrollClamping) { }; virtual void stop() = 0; virtual void updateVisibleLengths() { }; virtual void setCurrentPosition(const FloatPoint&) { }; virtual void serviceAnimation() { }; + virtual bool isScrollInProgress() const { return false; } protected: ScrollAnimation(ScrollableArea& scrollableArea) diff --git a/Source/WebCore/platform/ScrollAnimationKinetic.cpp b/Source/WebCore/platform/ScrollAnimationKinetic.cpp index ac9f2f0f37f..50fb6098409 100644 --- a/Source/WebCore/platform/ScrollAnimationKinetic.cpp +++ b/Source/WebCore/platform/ScrollAnimationKinetic.cpp @@ -165,4 +165,9 @@ void ScrollAnimationKinetic::animationTimerFired() m_notifyPositionChangedFunction(FloatPoint(m_position)); } +bool ScrollAnimationKinetic::isScrollInProgress() const +{ + return m_animationTimer.isActive(); +} + } // namespace WebCore diff --git a/Source/WebCore/platform/ScrollAnimationKinetic.h b/Source/WebCore/platform/ScrollAnimationKinetic.h index cfd33ce5b49..291fa9c19a7 100644 --- a/Source/WebCore/platform/ScrollAnimationKinetic.h +++ b/Source/WebCore/platform/ScrollAnimationKinetic.h @@ -66,6 +66,7 @@ public: private: void stop() override; void animationTimerFired(); + bool isScrollInProgress() const override; std::function m_notifyPositionChangedFunction; diff --git a/Source/WebCore/platform/ScrollAnimationSmooth.cpp b/Source/WebCore/platform/ScrollAnimationSmooth.cpp index d064e69379f..7cc1958a1c5 100644 --- a/Source/WebCore/platform/ScrollAnimationSmooth.cpp +++ b/Source/WebCore/platform/ScrollAnimationSmooth.cpp @@ -28,8 +28,6 @@ #include "config.h" #include "ScrollAnimationSmooth.h" -#if ENABLE(SMOOTH_SCROLLING) - #include "FloatPoint.h" #include "ScrollableArea.h" @@ -38,6 +36,7 @@ namespace WebCore { static const double frameRate = 60; static const Seconds tickTime = 1_s / frameRate; static const Seconds minimumTimerInterval { 1_ms }; +static const double smoothFactorForProgrammaticScroll = 5; ScrollAnimationSmooth::ScrollAnimationSmooth(ScrollableArea& scrollableArea, const FloatPoint& position, WTF::Function&& notifyPositionChangedFunction) : ScrollAnimation(scrollableArea) @@ -67,6 +66,19 @@ bool ScrollAnimationSmooth::scroll(ScrollbarOrientation orientation, ScrollGranu return needToScroll; } +void ScrollAnimationSmooth::scroll(const FloatPoint& position, ScrollClamping) +{ + // FIXME: Consider clamping? + ScrollGranularity granularity = ScrollByPage; + bool needToScroll = updatePerAxisData(m_horizontalData, granularity, position.x() - m_horizontalData.currentPosition, m_scrollableArea.minimumScrollPosition().x(), m_scrollableArea.maximumScrollPosition().x(), smoothFactorForProgrammaticScroll); + needToScroll |= + updatePerAxisData(m_verticalData, granularity, position.y() - m_verticalData.currentPosition, m_scrollableArea.minimumScrollPosition().y(), m_scrollableArea.maximumScrollPosition().y(), smoothFactorForProgrammaticScroll); + if (needToScroll && !animationTimerActive()) { + m_startTime = m_horizontalData.startTime; + animationTimerFired(); + } +}; + void ScrollAnimationSmooth::stop() { m_animationTimer.stop(); @@ -247,7 +259,7 @@ static inline void getAnimationParametersForGranularity(ScrollGranularity granul } } -bool ScrollAnimationSmooth::updatePerAxisData(PerAxisData& data, ScrollGranularity granularity, float delta, float minScrollPosition, float maxScrollPosition) +bool ScrollAnimationSmooth::updatePerAxisData(PerAxisData& data, ScrollGranularity granularity, float delta, float minScrollPosition, float maxScrollPosition, double smoothFactor) { if (!data.startTime || !delta || (delta < 0) != (data.desiredPosition - data.currentPosition < 0)) { data.desiredPosition = data.currentPosition; @@ -264,6 +276,12 @@ bool ScrollAnimationSmooth::updatePerAxisData(PerAxisData& data, ScrollGranulari Curve coastTimeCurve; getAnimationParametersForGranularity(granularity, animationTime, repeatMinimumSustainTime, attackTime, releaseTime, coastTimeCurve, maximumCoastTime); + animationTime *= smoothFactor; + repeatMinimumSustainTime *= smoothFactor; + attackTime *= smoothFactor; + releaseTime *= smoothFactor; + maximumCoastTime *= smoothFactor; + data.desiredPosition = newPosition; if (!data.startTime) data.attackTime = attackTime; @@ -407,5 +425,3 @@ bool ScrollAnimationSmooth::animationTimerActive() const } } // namespace WebCore - -#endif // ENABLE(SMOOTH_SCROLLING) diff --git a/Source/WebCore/platform/ScrollAnimationSmooth.h b/Source/WebCore/platform/ScrollAnimationSmooth.h index 02cc4ee2bd7..351889f3244 100644 --- a/Source/WebCore/platform/ScrollAnimationSmooth.h +++ b/Source/WebCore/platform/ScrollAnimationSmooth.h @@ -27,14 +27,13 @@ #include "ScrollAnimation.h" -#if ENABLE(SMOOTH_SCROLLING) - #include "Timer.h" namespace WebCore { class FloatPoint; class ScrollableArea; +enum class ScrollClamping : uint8_t; class ScrollAnimationSmooth final: public ScrollAnimation { public: @@ -51,9 +50,11 @@ public: private: bool scroll(ScrollbarOrientation, ScrollGranularity, float step, float multiplier) override; + void scroll(const FloatPoint&, ScrollClamping) override; void stop() override; void updateVisibleLengths() override; void setCurrentPosition(const FloatPoint&) override; + bool isScrollInProgress() const override { return animationTimerActive(); } struct PerAxisData { PerAxisData() = delete; @@ -89,7 +90,7 @@ private: int visibleLength { 0 }; }; - bool updatePerAxisData(PerAxisData&, ScrollGranularity, float delta, float minScrollPosition, float maxScrollPosition); + bool updatePerAxisData(PerAxisData&, ScrollGranularity, float delta, float minScrollPosition, float maxScrollPosition, double smoothFactor = 1); bool animateScroll(PerAxisData&, MonotonicTime currentTime); void requestAnimationTimerFired(); @@ -108,4 +109,3 @@ private: } // namespace WebCore -#endif // ENABLE(SMOOTH_SCROLLING) diff --git a/Source/WebCore/platform/ScrollAnimator.cpp b/Source/WebCore/platform/ScrollAnimator.cpp index d9154d9351a..e6c95f9062a 100644 --- a/Source/WebCore/platform/ScrollAnimator.cpp +++ b/Source/WebCore/platform/ScrollAnimator.cpp @@ -35,6 +35,7 @@ #include "FloatPoint.h" #include "LayoutSize.h" #include "PlatformWheelEvent.h" +#include "ScrollAnimationSmooth.h" #include "ScrollableArea.h" #include @@ -52,11 +53,22 @@ ScrollAnimator::ScrollAnimator(ScrollableArea& scrollableArea) #if ENABLE(CSS_SCROLL_SNAP) || ENABLE(RUBBER_BANDING) , m_scrollController(*this) #endif + , m_animationProgrammaticScroll(std::make_unique(scrollableArea, m_currentPosition, [this](FloatPoint&& position) { + FloatSize delta = position - m_currentPosition; + m_currentPosition = WTFMove(position); + notifyPositionChanged(delta); + })) { } ScrollAnimator::~ScrollAnimator() = default; +bool ScrollAnimator::isScrollInProgress() const +{ + // FIXME (TODO): This should also take into account animations in derived classes. + return m_animationProgrammaticScroll->isScrollInProgress(); +} + bool ScrollAnimator::scroll(ScrollbarOrientation orientation, ScrollGranularity, float step, float multiplier) { FloatPoint currentPosition = this->currentPosition(); @@ -75,6 +87,13 @@ bool ScrollAnimator::scroll(ScrollbarOrientation orientation, ScrollGranularity, return true; } +void ScrollAnimator::scrollToOffset(const FloatPoint& offset, ScrollClamping clamping) +{ + m_animationProgrammaticScroll->setCurrentPosition(m_currentPosition); + auto newPosition = ScrollableArea::scrollPositionFromOffset(offset, toFloatSize(m_scrollableArea.scrollOrigin())); + m_animationProgrammaticScroll->scroll(newPosition, clamping); +} + void ScrollAnimator::scrollToOffsetWithoutAnimation(const FloatPoint& offset, ScrollClamping) { FloatPoint newPositon = ScrollableArea::scrollPositionFromOffset(offset, toFloatSize(m_scrollableArea.scrollOrigin())); @@ -245,4 +264,33 @@ void ScrollAnimator::removeTestDeferralForReason(WheelEventTestTrigger::Scrollab } #endif +void ScrollAnimator::cancelAnimations() +{ +#if !USE(REQUEST_ANIMATION_FRAME_TIMER) + m_animationProgrammaticScroll->stop(); +#endif +} + +void ScrollAnimator::serviceScrollAnimations() +{ +#if !USE(REQUEST_ANIMATION_FRAME_TIMER) + m_animationProgrammaticScroll->serviceAnimation(); +#endif +} + +void ScrollAnimator::willEndLiveResize() +{ + m_animationProgrammaticScroll->updateVisibleLengths(); +} + +void ScrollAnimator::didAddVerticalScrollbar(Scrollbar*) +{ + m_animationProgrammaticScroll->updateVisibleLengths(); +} + +void ScrollAnimator::didAddHorizontalScrollbar(Scrollbar*) +{ + m_animationProgrammaticScroll->updateVisibleLengths(); +} + } // namespace WebCore diff --git a/Source/WebCore/platform/ScrollAnimator.h b/Source/WebCore/platform/ScrollAnimator.h index 6e2a884abb2..6914483d730 100644 --- a/Source/WebCore/platform/ScrollAnimator.h +++ b/Source/WebCore/platform/ScrollAnimator.h @@ -46,6 +46,7 @@ namespace WebCore { class FloatPoint; class PlatformTouchEvent; +class ScrollAnimation; class ScrollableArea; class Scrollbar; class WheelEventTestTrigger; @@ -68,6 +69,7 @@ public: // The base class implementation always scrolls immediately, never animates. virtual bool scroll(ScrollbarOrientation, ScrollGranularity, float step, float multiplier); + void scrollToOffset(const FloatPoint&, ScrollClamping = ScrollClamping::Clamped); virtual void scrollToOffsetWithoutAnimation(const FloatPoint&, ScrollClamping = ScrollClamping::Clamped); ScrollableArea& scrollableArea() const { return m_scrollableArea; } @@ -85,8 +87,8 @@ public: void setCurrentPosition(const FloatPoint&); const FloatPoint& currentPosition() const { return m_currentPosition; } - virtual void cancelAnimations() { } - virtual void serviceScrollAnimations() { } + virtual void cancelAnimations(); + virtual void serviceScrollAnimations(); virtual void contentAreaWillPaint() const { } virtual void mouseEnteredContentArea() { } @@ -97,16 +99,16 @@ public: virtual void mouseIsDownInScrollbar(Scrollbar*, bool) const { } virtual void willStartLiveResize() { } virtual void contentsResized() const { } - virtual void willEndLiveResize() { } + virtual void willEndLiveResize(); virtual void contentAreaDidShow() { } virtual void contentAreaDidHide() { } virtual void lockOverlayScrollbarStateToHidden(bool) { } virtual bool scrollbarsCanBeActive() const { return true; } - virtual void didAddVerticalScrollbar(Scrollbar*) { } + virtual void didAddVerticalScrollbar(Scrollbar*); virtual void willRemoveVerticalScrollbar(Scrollbar*) { } - virtual void didAddHorizontalScrollbar(Scrollbar*) { } + virtual void didAddHorizontalScrollbar(Scrollbar*); virtual void willRemoveHorizontalScrollbar(Scrollbar*) { } virtual void invalidateScrollbarPartLayers(Scrollbar*) { } @@ -120,6 +122,7 @@ public: virtual bool isRubberBandInProgress() const { return false; } virtual bool isScrollSnapInProgress() const { return false; } + bool isScrollInProgress() const; void setWheelEventTestTrigger(RefPtr&& testTrigger) { m_wheelEventTestTrigger = testTrigger; } #if (ENABLE(CSS_SCROLL_SNAP) || ENABLE(RUBBER_BANDING)) && PLATFORM(MAC) @@ -150,6 +153,8 @@ protected: ScrollController m_scrollController; #endif FloatPoint m_currentPosition; + + std::unique_ptr m_animationProgrammaticScroll; }; } // namespace WebCore diff --git a/Source/WebCore/platform/ScrollView.cpp b/Source/WebCore/platform/ScrollView.cpp index b126a9c2b70..b780f8c1d63 100644 --- a/Source/WebCore/platform/ScrollView.cpp +++ b/Source/WebCore/platform/ScrollView.cpp @@ -475,9 +475,13 @@ void ScrollView::setScrollPosition(const ScrollPosition& scrollPosition) ScrollPosition newScrollPosition = !delegatesScrolling() ? adjustScrollPositionWithinRange(scrollPosition) : scrollPosition; - if ((!delegatesScrolling() || currentScrollType() == ScrollType::User) && newScrollPosition == this->scrollPosition()) + bool scrollInProgress = isScrollInProgress(); + if ((!delegatesScrolling() || currentScrollType() == ScrollType::User) && !scrollInProgress && newScrollPosition == this->scrollPosition()) return; + if (scrollInProgress) + scrollAnimator().cancelAnimations(); + if (requestScrollPositionUpdate(newScrollPosition)) return; diff --git a/Source/WebCore/platform/ScrollableArea.cpp b/Source/WebCore/platform/ScrollableArea.cpp index c8882ee2305..a925c175402 100644 --- a/Source/WebCore/platform/ScrollableArea.cpp +++ b/Source/WebCore/platform/ScrollableArea.cpp @@ -101,6 +101,11 @@ float ScrollableArea::adjustScrollStepForFixedContent(float step, ScrollbarOrien return step; } +bool ScrollableArea::isScrollInProgress() const +{ + return m_scrollAnimator && scrollAnimator().isScrollInProgress(); +} + bool ScrollableArea::scroll(ScrollDirection direction, ScrollGranularity granularity, float multiplier) { ScrollbarOrientation orientation; @@ -139,6 +144,12 @@ bool ScrollableArea::scroll(ScrollDirection direction, ScrollGranularity granula return scrollAnimator().scroll(orientation, granularity, step, multiplier); } +void ScrollableArea::scrollToOffsetWithAnimation(const FloatPoint& offset, ScrollClamping clamping) +{ + LOG_WITH_STREAM(Scrolling, stream << "ScrollableArea " << this << " scrollToOffset " << offset); + scrollAnimator().scrollToOffset(offset, clamping); +} + void ScrollableArea::scrollToOffsetWithoutAnimation(const FloatPoint& offset, ScrollClamping clamping) { LOG_WITH_STREAM(Scrolling, stream << "ScrollableArea " << this << " scrollToOffsetWithoutAnimation " << offset); diff --git a/Source/WebCore/platform/ScrollableArea.h b/Source/WebCore/platform/ScrollableArea.h index d7438c15cd5..0014e327470 100644 --- a/Source/WebCore/platform/ScrollableArea.h +++ b/Source/WebCore/platform/ScrollableArea.h @@ -62,7 +62,9 @@ inline int offsetForOrientation(ScrollOffset offset, ScrollbarOrientation orient class ScrollableArea : public CanMakeWeakPtr { public: + WEBCORE_EXPORT bool isScrollInProgress() const; WEBCORE_EXPORT bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1); + WEBCORE_EXPORT void scrollToOffsetWithAnimation(const FloatPoint&, ScrollClamping = ScrollClamping::Clamped); WEBCORE_EXPORT void scrollToOffsetWithoutAnimation(const FloatPoint&, ScrollClamping = ScrollClamping::Clamped); void scrollToOffsetWithoutAnimation(ScrollbarOrientation, float offset); diff --git a/Source/WebCore/platform/mac/ScrollAnimatorMac.mm b/Source/WebCore/platform/mac/ScrollAnimatorMac.mm index a83175122ec..ff07619c692 100644 --- a/Source/WebCore/platform/mac/ScrollAnimatorMac.mm +++ b/Source/WebCore/platform/mac/ScrollAnimatorMac.mm @@ -1151,6 +1151,7 @@ void ScrollAnimatorMac::notifyContentAreaScrolled(const FloatSize& delta) void ScrollAnimatorMac::cancelAnimations() { + ScrollAnimator::cancelAnimations(); m_haveScrolledSincePageLoad = false; if (scrollbarPaintTimerIsActive()) diff --git a/Source/WebCore/rendering/RenderBox.cpp b/Source/WebCore/rendering/RenderBox.cpp index c7ed22358b0..308e5eed3e2 100644 --- a/Source/WebCore/rendering/RenderBox.cpp +++ b/Source/WebCore/rendering/RenderBox.cpp @@ -591,6 +591,14 @@ void RenderBox::setScrollTop(int newTop, ScrollType scrollType, ScrollClamping c layer()->scrollToYPosition(newTop, scrollType, clamping); } +void RenderBox::scrollToPositionWithAnimation(ScrollPosition scrollPosition, ScrollClamping clamping) +{ + if (!hasOverflowClip() || !layer()) + return; + setupWheelEventTestTrigger(*layer()); + layer()->scrollToOffsetWithAnimation(scrollPosition, clamping); +} + void RenderBox::absoluteRects(Vector& rects, const LayoutPoint& accumulatedOffset) const { rects.append(snappedIntRect(accumulatedOffset, size())); diff --git a/Source/WebCore/rendering/RenderBox.h b/Source/WebCore/rendering/RenderBox.h index b2afd00acf5..ca1b0d36605 100644 --- a/Source/WebCore/rendering/RenderBox.h +++ b/Source/WebCore/rendering/RenderBox.h @@ -249,6 +249,7 @@ public: virtual int scrollHeight() const; virtual void setScrollLeft(int, ScrollType, ScrollClamping = ScrollClamping::Clamped); virtual void setScrollTop(int, ScrollType, ScrollClamping = ScrollClamping::Clamped); + void scrollToPositionWithAnimation(ScrollPosition, ScrollClamping = ScrollClamping::Clamped); LayoutUnit marginTop() const override { return m_marginBox.top(); } LayoutUnit marginBottom() const override { return m_marginBox.bottom(); } diff --git a/Source/WebCore/rendering/RenderLayer.cpp b/Source/WebCore/rendering/RenderLayer.cpp index ca7290a02d3..2fb2a8f6e5e 100644 --- a/Source/WebCore/rendering/RenderLayer.cpp +++ b/Source/WebCore/rendering/RenderLayer.cpp @@ -114,6 +114,7 @@ #include "ScaleTransformOperation.h" #include "ScriptDisallowedScope.h" #include "ScrollAnimator.h" +#include "ScrollBehavior.h" #include "Scrollbar.h" #include "ScrollbarTheme.h" #include "ScrollingCoordinator.h" @@ -2448,12 +2449,25 @@ void RenderLayer::scrollToOffset(const ScrollOffset& scrollOffset, ScrollType sc handled = scrollingCoordinator->requestScrollPositionUpdate(*this, scrollPositionFromOffset(clampedScrollOffset)); #endif - if (!handled) + bool scrollInProgress = isScrollInProgress(); + if (scrollInProgress) + scrollAnimator().cancelAnimations(); + if (scrollInProgress || !handled) scrollToOffsetWithoutAnimation(clampedScrollOffset, clamping); setCurrentScrollType(previousScrollType); } +void RenderLayer::scrollToOffsetWithAnimation(const ScrollOffset& scrollOffset, ScrollClamping clamping) +{ + ScrollOffset newScrollOffset = clamping == ScrollClamping::Clamped ? clampScrollOffset(scrollOffset) : scrollOffset; + bool scrollInProgress = isScrollInProgress(); + if (scrollInProgress) + scrollAnimator().cancelAnimations(); + if (scrollInProgress || newScrollOffset != this->scrollOffset()) + ScrollableArea::scrollToOffsetWithAnimation(newScrollOffset, clamping); +} + void RenderLayer::scrollTo(const ScrollPosition& position) { RenderBox* box = renderBox(); @@ -2603,6 +2617,7 @@ bool RenderLayer::allowsCurrentScroll() const void RenderLayer::scrollRectToVisible(const LayoutRect& absoluteRect, bool insideFixed, const ScrollRectToVisibleOptions& options) { + // FIXME (https://webkit.org/b/189907): Make this work with nested scrollable boxes when a smooth scrolling must be performed. LOG_WITH_STREAM(Scrolling, stream << "Layer " << this << " scrollRectToVisible " << absoluteRect); RenderLayer* parentLayer = nullptr; @@ -2625,9 +2640,12 @@ void RenderLayer::scrollRectToVisible(const LayoutRect& absoluteRect, bool insid LayoutRect revealRect = getRectToExpose(layerBounds, localExposeRect, insideFixed, options.alignX, options.alignY); ScrollOffset clampedScrollOffset = clampScrollOffset(scrollOffset() + toIntSize(roundedIntRect(revealRect).location())); - if (clampedScrollOffset != scrollOffset()) { + if (isScrollInProgress() || clampedScrollOffset != scrollOffset()) { ScrollOffset oldScrollOffset = scrollOffset(); - scrollToOffset(clampedScrollOffset); + if (box->element() && useSmoothScrolling(options.behavior, *box->element())) + scrollToOffsetWithAnimation(clampedScrollOffset); + else + scrollToOffset(clampedScrollOffset); IntSize scrollOffsetDifference = scrollOffset() - oldScrollOffset; localExposeRect.move(-scrollOffsetDifference); newRect = LayoutRect(box->localToAbsoluteQuad(FloatQuad(FloatRect(localExposeRect)), UseTransforms).boundingBox()); @@ -2651,7 +2669,12 @@ void RenderLayer::scrollRectToVisible(const LayoutRect& absoluteRect, bool insid IntPoint scrollOffset(roundedIntPoint(exposeRect.location())); // Adjust offsets if they're outside of the allowable range. scrollOffset = scrollOffset.constrainedBetween(IntPoint(), IntPoint(frameView.contentsSize())); - frameView.setScrollPosition(scrollOffset); + // FIXME: Should we use contentDocument()->scrollingElement()? + // See https://github.com/w3c/csswg-drafts/issues/2977 + if (ownerElement->contentDocument() && ownerElement->contentDocument()->documentElement() && useSmoothScrolling(options.behavior, *ownerElement->contentDocument()->documentElement())) + frameView.scrollToOffsetWithAnimation(scrollOffset); + else + frameView.setScrollPosition(scrollOffset); if (options.shouldAllowCrossOriginScrolling == ShouldAllowCrossOriginScrolling::Yes || frameView.safeToPropagateScrollToParent()) { parentLayer = ownerElement->renderer()->enclosingLayer(); @@ -2685,7 +2708,13 @@ void RenderLayer::scrollRectToVisible(const LayoutRect& absoluteRect, bool insid LayoutRect revealRect = getRectToExpose(viewRect, targetRect, insideFixed, options.alignX, options.alignY); ScrollOffset clampedScrollPosition = roundedIntPoint(revealRect.location()).constrainedBetween(minScrollPosition, maxScrollPosition); - frameView.setScrollPosition(clampedScrollPosition); + IntPoint scrollOffset(clampedScrollPosition); + // FIXME: Should we use document()->scrollingElement()? + // See https://github.com/w3c/csswg-drafts/issues/2977 + if (renderer().document().documentElement() && useSmoothScrolling(options.behavior, *renderer().document().documentElement())) + frameView.scrollToOffsetWithAnimation(scrollOffset); + else + frameView.setScrollPosition(scrollOffset); // This is the outermost view of a web page, so after scrolling this view we // scroll its container by calling Page::scrollRectIntoView. diff --git a/Source/WebCore/rendering/RenderLayer.h b/Source/WebCore/rendering/RenderLayer.h index 8cc87588a0c..f8dbea7bb13 100644 --- a/Source/WebCore/rendering/RenderLayer.h +++ b/Source/WebCore/rendering/RenderLayer.h @@ -50,6 +50,7 @@ #include "PaintInfo.h" #include "RenderBox.h" #include "RenderPtr.h" +#include "ScrollBehavior.h" #include "ScrollableArea.h" #include #include @@ -133,6 +134,7 @@ struct ScrollRectToVisibleOptions { const ScrollAlignment& alignX { ScrollAlignment::alignCenterIfNeeded }; const ScrollAlignment& alignY { ScrollAlignment::alignCenterIfNeeded }; ShouldAllowCrossOriginScrolling shouldAllowCrossOriginScrolling { ShouldAllowCrossOriginScrolling::No }; + ScrollBehavior behavior { ScrollBehavior::Auto }; }; class RenderLayer final : public ScrollableArea { @@ -431,6 +433,7 @@ public: void scrollByRecursively(const IntSize& delta, ScrollableArea** scrolledArea = nullptr); WEBCORE_EXPORT void scrollToOffset(const ScrollOffset&, ScrollType = ScrollType::Programmatic, ScrollClamping = ScrollClamping::Clamped); + WEBCORE_EXPORT void scrollToOffsetWithAnimation(const ScrollOffset&, ScrollClamping = ScrollClamping::Clamped); void scrollToXPosition(int x, ScrollType, ScrollClamping = ScrollClamping::Clamped); void scrollToYPosition(int y, ScrollType, ScrollClamping = ScrollClamping::Clamped); diff --git a/Source/WebCore/rendering/style/RenderStyle.h b/Source/WebCore/rendering/style/RenderStyle.h index c0d837d5cf5..94ffad63bb4 100644 --- a/Source/WebCore/rendering/style/RenderStyle.h +++ b/Source/WebCore/rendering/style/RenderStyle.h @@ -738,6 +738,8 @@ public: bool useTouchOverflowScrolling() const { return m_rareInheritedData->useTouchOverflowScrolling; } #endif + bool useSmoothScrolling() const { return m_rareNonInheritedData->useSmoothScrolling; } + #if ENABLE(TEXT_AUTOSIZING) TextSizeAdjustment textSizeAdjust() const { return m_rareInheritedData->textSizeAdjust; } AutosizeStatus autosizeStatus() const; @@ -1248,6 +1250,8 @@ public: void setUseTouchOverflowScrolling(bool v) { SET_VAR(m_rareInheritedData, useTouchOverflowScrolling, v); } #endif + void setUseSmoothScrolling(bool v) { SET_VAR(m_rareNonInheritedData, useSmoothScrolling, v); } + #if ENABLE(TEXT_AUTOSIZING) void setTextSizeAdjust(TextSizeAdjustment adjustment) { SET_VAR(m_rareInheritedData, textSizeAdjust, adjustment); } void setAutosizeStatus(AutosizeStatus); @@ -1685,6 +1689,8 @@ public: static bool initialUseTouchOverflowScrolling() { return false; } #endif + static bool initialUseSmoothScrolling() { return false; } + static const FilterOperations& initialFilter() { static NeverDestroyed ops; return ops; } static const FilterOperations& initialAppleColorFilter() { static NeverDestroyed ops; return ops; } diff --git a/Source/WebCore/rendering/style/StyleRareNonInheritedData.cpp b/Source/WebCore/rendering/style/StyleRareNonInheritedData.cpp index 6fbb2b7b0c3..f951078e97a 100644 --- a/Source/WebCore/rendering/style/StyleRareNonInheritedData.cpp +++ b/Source/WebCore/rendering/style/StyleRareNonInheritedData.cpp @@ -80,6 +80,7 @@ StyleRareNonInheritedData::StyleRareNonInheritedData() #if ENABLE(POINTER_EVENTS) , touchActions(static_cast(RenderStyle::initialTouchActions())) #endif + , useSmoothScrolling(static_cast(RenderStyle::initialUseSmoothScrolling())) , pageSizeType(PAGE_SIZE_AUTO) , transformStyle3D(static_cast(RenderStyle::initialTransformStyle3D())) , backfaceVisibility(static_cast(RenderStyle::initialBackfaceVisibility())) @@ -174,6 +175,7 @@ inline StyleRareNonInheritedData::StyleRareNonInheritedData(const StyleRareNonIn #if ENABLE(POINTER_EVENTS) , touchActions(o.touchActions) #endif + , useSmoothScrolling(o.useSmoothScrolling) , pageSizeType(o.pageSizeType) , transformStyle3D(o.transformStyle3D) , backfaceVisibility(o.backfaceVisibility) @@ -286,6 +288,7 @@ bool StyleRareNonInheritedData::operator==(const StyleRareNonInheritedData& o) c #if ENABLE(POINTER_EVENTS) && touchActions == o.touchActions #endif + && useSmoothScrolling == o.useSmoothScrolling #if ENABLE(CSS_COMPOSITING) && effectiveBlendMode == o.effectiveBlendMode && isolation == o.isolation diff --git a/Source/WebCore/rendering/style/StyleRareNonInheritedData.h b/Source/WebCore/rendering/style/StyleRareNonInheritedData.h index 19c591b2d12..58f1c6ccf66 100644 --- a/Source/WebCore/rendering/style/StyleRareNonInheritedData.h +++ b/Source/WebCore/rendering/style/StyleRareNonInheritedData.h @@ -175,6 +175,8 @@ public: unsigned touchActions : 6; // TouchAction #endif + unsigned useSmoothScrolling : 1; // ScrollBehavior + unsigned pageSizeType : 2; // PageSizeType unsigned transformStyle3D : 1; // TransformStyle3D unsigned backfaceVisibility : 1; // BackfaceVisibility diff --git a/Source/WebCore/testing/Internals.cpp b/Source/WebCore/testing/Internals.cpp index acde12f8de4..173bfdd571e 100644 --- a/Source/WebCore/testing/Internals.cpp +++ b/Source/WebCore/testing/Internals.cpp @@ -1711,7 +1711,7 @@ ExceptionOr Internals::unconstrainedScrollTo(Element& element, double x, d if (!document || !document->view()) return Exception { InvalidAccessError }; - element.scrollTo({ x, y }, ScrollClamping::Unclamped); + element.scrollTo(fromCoordinates(x, y), ScrollClamping::Unclamped); return { }; } diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog index 4e8cb65c981..51a45365973 100644 --- a/Source/WebKit/ChangeLog +++ b/Source/WebKit/ChangeLog @@ -1,3 +1,14 @@ +2018-11-06 Frederic Wang + + Add support for ScrollOptions' ScrollBehavior and CSS scroll-behavior properties + https://bugs.webkit.org/show_bug.cgi?id=188043 + + Reviewed by NOBODY (OOPS!). + + Add CSSOM smooth scrolling as an experimental feature. + + * Shared/WebPreferences.yaml: + 2019-06-24 Brady Eidson Null deref in WebFrameLoaderClient::dispatchDidReceiveServerRedirectForProvisionalLoad. diff --git a/Source/WebKit/Shared/WebPreferences.yaml b/Source/WebKit/Shared/WebPreferences.yaml index 4174681ace7..1abdc6d0e4b 100644 --- a/Source/WebKit/Shared/WebPreferences.yaml +++ b/Source/WebKit/Shared/WebPreferences.yaml @@ -1221,7 +1221,6 @@ ShouldDecidePolicyBeforeLoadingQuickLookPreview: # DEFAULT_EXPERIMENTAL_FEATURES_ENABLED (for features that are ready for # wider testing). - SpringTimingFunctionEnabled: type: bool defaultValue: DEFAULT_EXPERIMENTAL_FEATURES_ENABLED @@ -1282,6 +1281,13 @@ BlockingOfSmallPluginsEnabled: humanReadableDescription: "Stop plugins smaller than a certain threshold from loading." category: internal +CSSOMViewSmoothScrollingEnabled: + type: bool + defaultValue: false + humanReadableName: "CSSOM View Smooth Scrolling" + humanReadableDescription: "Enable DOM API and CSS property for 'smooth' scroll behavior" + category: experimental + WebAnimationsEnabled: type: bool defaultValue: DEFAULT_EXPERIMENTAL_FEATURES_ENABLED diff --git a/Source/WebKitLegacy/mac/ChangeLog b/Source/WebKitLegacy/mac/ChangeLog index fe432d06460..923bd484bc4 100644 --- a/Source/WebKitLegacy/mac/ChangeLog +++ b/Source/WebKitLegacy/mac/ChangeLog @@ -1,3 +1,20 @@ +2018-11-07 Frederic Wang + + Add support for ScrollOptions' ScrollBehavior and CSS scroll-behavior properties + https://bugs.webkit.org/show_bug.cgi?id=188043 + + Reviewed by NOBODY (OOPS!). + + * WebView/WebPreferenceKeysPrivate.h: Handle CSSOMViewSmoothScrolling by. + * WebView/WebPreferencesPrivate.h: Ditto. + * WebView/WebView.mm: + (-[WebView _preferencesChanged:]): Ditto. + + * WebView/WebPreferences.mm: + (+[WebPreferences initialize]): Disable CSSOMViewSmoothScrolling by default. + (-[WebPreferences CSSOMViewSmoothScrollingEnabled]): Getter. + (-[WebPreferences setCSSOMViewSmoothScrollingEnabled:]): Setter. + 2019-06-16 Darin Adler Rename AtomicString to AtomString diff --git a/Source/WebKitLegacy/mac/WebView/WebPreferenceKeysPrivate.h b/Source/WebKitLegacy/mac/WebView/WebPreferenceKeysPrivate.h index 86addf6a11b..2afe65ea7df 100644 --- a/Source/WebKitLegacy/mac/WebView/WebPreferenceKeysPrivate.h +++ b/Source/WebKitLegacy/mac/WebView/WebPreferenceKeysPrivate.h @@ -185,6 +185,7 @@ #define WebKitDirectoryUploadEnabledPreferenceKey @"WebKitDirectoryUploadEnabled" #define WebKitVisualViewportAPIEnabledPreferenceKey @"WebKitVisualViewportAPIEnabled" #define WebKitCSSOMViewScrollingAPIEnabledPreferenceKey @"WebKitCSSOMViewScrollingAPIEnabled" +#define WebKitCSSOMViewSmoothScrollingEnabledPreferenceKey @"WebKitCSSOMViewSmoothScrollingEnabled" #define WebKitModernMediaControlsEnabledPreferenceKey @"WebKitModernMediaControlsEnabled" #define WebKitSubtleCryptoEnabledPreferenceKey @"WebKitSubtleCryptoEnabled" #define WebKitMediaDevicesEnabledPreferenceKey @"WebKitMediaDevicesEnabled" diff --git a/Source/WebKitLegacy/mac/WebView/WebPreferences.mm b/Source/WebKitLegacy/mac/WebView/WebPreferences.mm index ec913276914..93422778069 100644 --- a/Source/WebKitLegacy/mac/WebView/WebPreferences.mm +++ b/Source/WebKitLegacy/mac/WebView/WebPreferences.mm @@ -652,6 +652,7 @@ public: #endif [NSNumber numberWithBool:NO], WebKitCSSOMViewScrollingAPIEnabledPreferenceKey, + [NSNumber numberWithBool:NO], WebKitCSSOMViewSmoothScrollingEnabledPreferenceKey, [NSNumber numberWithBool:YES], WebKitNeedsStorageAccessFromFileURLsQuirkKey, [NSNumber numberWithBool:NO], WebKitAllowCrossOriginSubresourcesToAskForCredentialsKey, #if ENABLE(MEDIA_STREAM) @@ -3137,6 +3138,16 @@ static NSString *classIBCreatorID = nil; [self _setBoolValue:flag forKey:WebKitCSSOMViewScrollingAPIEnabledPreferenceKey]; } +- (BOOL)CSSOMViewSmoothScrollingEnabled +{ + return [self _boolValueForKey:WebKitCSSOMViewSmoothScrollingEnabledPreferenceKey]; +} + +- (void)setCSSOMViewSmoothScrollingEnabled:(BOOL)flag +{ + [self _setBoolValue:flag forKey:WebKitCSSOMViewSmoothScrollingEnabledPreferenceKey]; +} + - (BOOL)webAnimationsEnabled { return [self _boolValueForKey:WebKitWebAnimationsEnabledPreferenceKey]; diff --git a/Source/WebKitLegacy/mac/WebView/WebPreferencesPrivate.h b/Source/WebKitLegacy/mac/WebView/WebPreferencesPrivate.h index a8b9ac72062..830e41e11bc 100644 --- a/Source/WebKitLegacy/mac/WebView/WebPreferencesPrivate.h +++ b/Source/WebKitLegacy/mac/WebView/WebPreferencesPrivate.h @@ -614,6 +614,7 @@ extern NSString *WebPreferencesCacheModelChangedInternalNotification WEBKIT_DEPR @property (nonatomic) BOOL visualViewportAPIEnabled; @property (nonatomic) BOOL CSSOMViewScrollingAPIEnabled; +@property (nonatomic) BOOL CSSOMViewSmoothScrollingEnabled; @property (nonatomic) BOOL largeImageAsyncDecodingEnabled; @property (nonatomic) BOOL animatedImageAsyncDecodingEnabled; @property (nonatomic) BOOL javaScriptMarkupEnabled; diff --git a/Source/WebKitLegacy/mac/WebView/WebView.mm b/Source/WebKitLegacy/mac/WebView/WebView.mm index 6e13500c5d5..699e3f6c93f 100644 --- a/Source/WebKitLegacy/mac/WebView/WebView.mm +++ b/Source/WebKitLegacy/mac/WebView/WebView.mm @@ -2983,6 +2983,7 @@ static bool needsSelfRetainWhileLoadingQuirk() settings.setVisualViewportAPIEnabled([preferences visualViewportAPIEnabled]); settings.setSyntheticEditingCommandsEnabled([preferences syntheticEditingCommandsEnabled]); settings.setCSSOMViewScrollingAPIEnabled([preferences CSSOMViewScrollingAPIEnabled]); + settings.setCSSOMViewSmoothScrollingEnabled([preferences CSSOMViewSmoothScrollingEnabled]); settings.setMediaContentTypesRequiringHardwareSupport([preferences mediaContentTypesRequiringHardwareSupport]); switch ([preferences storageBlockingPolicy]) { diff --git a/Source/WebKitLegacy/win/ChangeLog b/Source/WebKitLegacy/win/ChangeLog index 601d76234ce..a4e9b5331bb 100644 --- a/Source/WebKitLegacy/win/ChangeLog +++ b/Source/WebKitLegacy/win/ChangeLog @@ -1,3 +1,20 @@ +2018-11-07 Frederic Wang + + Add support for ScrollOptions' ScrollBehavior and CSS scroll-behavior properties + https://bugs.webkit.org/show_bug.cgi?id=188043 + + Reviewed by NOBODY (OOPS!). + + * Interfaces/IWebPreferencesPrivate.idl: Handle smooth scrolling option. + * WebPreferenceKeysPrivate.h: Ditto. + * WebPreferences.cpp: Ditto. + (WebPreferences::initializeDefaultSettings): + (WebPreferences::CSSOMViewSmoothScrollingEnabled): + (WebPreferences::setCSSOMViewSmoothScrollingEnabled): + * WebPreferences.h: Ditto. + * WebView.cpp: Ditto. + (WebView::notifyPreferencesChanged): + 2019-06-16 Darin Adler Rename AtomicString to AtomString diff --git a/Source/WebKitLegacy/win/Interfaces/IWebPreferencesPrivate.idl b/Source/WebKitLegacy/win/Interfaces/IWebPreferencesPrivate.idl index cb8dda4aefb..e1adfdcd582 100644 --- a/Source/WebKitLegacy/win/Interfaces/IWebPreferencesPrivate.idl +++ b/Source/WebKitLegacy/win/Interfaces/IWebPreferencesPrivate.idl @@ -223,6 +223,8 @@ interface IWebPreferencesPrivate6 : IWebPreferencesPrivate5 HRESULT setVisualViewportAPIEnabled([in] BOOL enabled); HRESULT CSSOMViewScrollingAPIEnabled([out, retval] BOOL*); HRESULT setCSSOMViewScrollingAPIEnabled([in] BOOL enabled); + HRESULT CSSOMViewSmoothScrollingEnabled([out, retval] BOOL*); + HRESULT setCSSOMViewSmoothScrollingEnabled([in] BOOL enabled); HRESULT fetchAPIKeepAliveEnabled([out, retval] BOOL* enabled); HRESULT setFetchAPIKeepAliveEnabled([in] BOOL enabled); HRESULT spatialNavigationEnabled([out, retval] BOOL *enabled); diff --git a/Source/WebKitLegacy/win/WebPreferenceKeysPrivate.h b/Source/WebKitLegacy/win/WebPreferenceKeysPrivate.h index ba662703ab8..6d80b2c2f89 100644 --- a/Source/WebKitLegacy/win/WebPreferenceKeysPrivate.h +++ b/Source/WebKitLegacy/win/WebPreferenceKeysPrivate.h @@ -205,6 +205,7 @@ #define WebKitServerTimingEnabledPreferenceKey "WebKitServerTimingEnabled" #define WebKitCSSOMViewScrollingAPIEnabledPreferenceKey "WebKitCSSOMViewScrollingAPIEnabled" +#define WebKitCSSOMViewSmoothScrollingEnabledPreferenceKey "WebKitCSSOMViewSmoothScrollingEnabled" #define WebKitResizeObserverEnabledPreferenceKey "WebKitResizeObserverEnabled" diff --git a/Source/WebKitLegacy/win/WebPreferences.cpp b/Source/WebKitLegacy/win/WebPreferences.cpp index 13948686bcf..2a5d71de92e 100644 --- a/Source/WebKitLegacy/win/WebPreferences.cpp +++ b/Source/WebKitLegacy/win/WebPreferences.cpp @@ -333,6 +333,8 @@ void WebPreferences::initializeDefaultSettings() CFDictionaryAddValue(defaults, CFSTR(WebKitCoreMathMLEnabledPreferenceKey), kCFBooleanFalse); + CFDictionaryAddValue(defaults, CFSTR(WebKitCSSOMViewSmoothScrollingEnabledPreferenceKey), kCFBooleanFalse); + defaultSettings = defaults; } @@ -2216,6 +2218,20 @@ HRESULT WebPreferences::setCoreMathMLEnabled(BOOL enabled) setBoolValue(WebKitCoreMathMLEnabledPreferenceKey, enabled); return S_OK; } + +HRESULT WebPreferences::CSSOMViewSmoothScrollingEnabled(_Out_ BOOL* enabled) +{ + if (!enabled) + return E_POINTER; + *enabled = boolValueForKey(WebKitCSSOMViewSmoothScrollingEnabledPreferenceKey); + return S_OK; +} + +HRESULT WebPreferences::setCSSOMViewSmoothScrollingEnabled(BOOL enabled) +{ + setBoolValue(WebKitCSSOMViewSmoothScrollingEnabledPreferenceKey, enabled); + return S_OK; +} HRESULT WebPreferences::setApplicationId(BSTR applicationId) { diff --git a/Source/WebKitLegacy/win/WebPreferences.h b/Source/WebKitLegacy/win/WebPreferences.h index 5ee6427b353..71a73272cce 100644 --- a/Source/WebKitLegacy/win/WebPreferences.h +++ b/Source/WebKitLegacy/win/WebPreferences.h @@ -271,6 +271,8 @@ public: virtual HRESULT STDMETHODCALLTYPE setVisualViewportAPIEnabled(BOOL); virtual HRESULT STDMETHODCALLTYPE CSSOMViewScrollingAPIEnabled(_Out_ BOOL*); virtual HRESULT STDMETHODCALLTYPE setCSSOMViewScrollingAPIEnabled(BOOL); + virtual HRESULT STDMETHODCALLTYPE CSSOMViewSmoothScrollingEnabled(_Out_ BOOL*); + virtual HRESULT STDMETHODCALLTYPE setCSSOMViewSmoothScrollingEnabled(BOOL); virtual HRESULT STDMETHODCALLTYPE fetchAPIKeepAliveEnabled(_Out_ BOOL*); virtual HRESULT STDMETHODCALLTYPE setFetchAPIKeepAliveEnabled(BOOL); virtual HRESULT STDMETHODCALLTYPE spatialNavigationEnabled(_Out_ BOOL*); diff --git a/Source/WebKitLegacy/win/WebView.cpp b/Source/WebKitLegacy/win/WebView.cpp index d51aa345714..f632efb763b 100644 --- a/Source/WebKitLegacy/win/WebView.cpp +++ b/Source/WebKitLegacy/win/WebView.cpp @@ -5297,6 +5297,11 @@ HRESULT WebView::notifyPreferencesChanged(IWebNotification* notification) return hr; settings.setCSSOMViewScrollingAPIEnabled(!!enabled); + hr = prefsPrivate->CSSOMViewSmoothScrollingEnabled(&enabled); + if (FAILED(hr)) + return hr; + settings.setCSSOMViewSmoothScrollingEnabled(!!enabled); + hr = preferences->privateBrowsingEnabled(&enabled); if (FAILED(hr)) return hr; diff --git a/Tools/ChangeLog b/Tools/ChangeLog index 44ef1c96e14..bec3b4e06dd 100644 --- a/Tools/ChangeLog +++ b/Tools/ChangeLog @@ -1,3 +1,14 @@ +2018-11-06 Frederic Wang + + Add support for ScrollOptions' ScrollBehavior and CSS scroll-behavior properties + https://bugs.webkit.org/show_bug.cgi?id=188043 + + * DumpRenderTree/TestOptions.cpp: + (TestOptions::TestOptions): Parse CSSOMViewSmoothScrollingEnabled. + * DumpRenderTree/TestOptions.h: Add CSSOMViewSmoothScrollingEnabled, disabled by default. + * DumpRenderTree/mac/DumpRenderTree.mm: + (setWebPreferencesForTestOptions): Set CSSOMViewSmoothScrollingEnabled from the test options. + 2019-06-24 Michael Catanzaro contributors.json not canonicalized since r243297 diff --git a/Tools/DumpRenderTree/TestOptions.cpp b/Tools/DumpRenderTree/TestOptions.cpp index aaa5e72d4eb..2604e50a9f1 100644 --- a/Tools/DumpRenderTree/TestOptions.cpp +++ b/Tools/DumpRenderTree/TestOptions.cpp @@ -117,6 +117,8 @@ TestOptions::TestOptions(const std::string& pathOrURL, const std::string& absolu enableResizeObserver = parseBooleanTestHeaderValue(value); else if (key == "experimental:CoreMathMLEnabled") enableCoreMathML = parseBooleanTestHeaderValue(value); + else if (key == "experimental:CSSOMViewSmoothScrollingEnabled") + enableCSSOMViewSmoothScrolling = parseBooleanTestHeaderValue(value); pairStart = pairEnd + 1; } } diff --git a/Tools/DumpRenderTree/TestOptions.h b/Tools/DumpRenderTree/TestOptions.h index d16f758a366..1f11f35f771 100644 --- a/Tools/DumpRenderTree/TestOptions.h +++ b/Tools/DumpRenderTree/TestOptions.h @@ -48,6 +48,7 @@ struct TestOptions { bool adClickAttributionEnabled { false }; bool enableResizeObserver { false }; bool enableCoreMathML { false }; + bool enableCSSOMViewSmoothScrolling { false }; std::string jscOptions; std::string additionalSupportedImageTypes; diff --git a/Tools/DumpRenderTree/mac/DumpRenderTree.mm b/Tools/DumpRenderTree/mac/DumpRenderTree.mm index 6660c32d921..f37c4eff2f4 100644 --- a/Tools/DumpRenderTree/mac/DumpRenderTree.mm +++ b/Tools/DumpRenderTree/mac/DumpRenderTree.mm @@ -1022,6 +1022,7 @@ static void setWebPreferencesForTestOptions(const TestOptions& options) preferences.adClickAttributionEnabled = options.adClickAttributionEnabled; preferences.resizeObserverEnabled = options.enableResizeObserver; preferences.coreMathMLEnabled = options.enableCoreMathML; + preferences.CSSOMViewSmoothScrollingEnabled = options.enableCSSOMViewSmoothScrolling; } // Called once on DumpRenderTree startup. -- 2.20.1