Skip to content
Permalink
Browse files
Turn macOS smooth keyboard scrolling on by default
https://bugs.webkit.org/show_bug.cgi?id=228159
rdar://80912063

Reviewed by Tim Horton and Wenson Hsieh.

No tests added.

Set the default value for EventHandlerDrivenSmoothKeyboardScrollingEnabled to true in WebKit.

* LayoutTests/css3/scroll-snap/scroll-padding-overflow-paging.html:
Updated to reflect non-instananeous scrolling.

* LayoutTests/fast/repaint/resources/fixed-move-after-keyboard-scroll-iframe.html:
Updated to reflect non-instananeous scrolling.

* LayoutTests/fast/scrolling/arrow-key-scroll-in-rtl-document-expected.txt:
* LayoutTests/fast/scrolling/arrow-key-scroll-in-rtl-document.html:
* LayoutTests/platform/mac-wk1/fast/scrolling/arrow-key-scroll-in-rtl-document-expected.txt: Added.
Updated these tests to reflect the new distance scrolled.

* Source/WTF/Scripts/Preferences/WebPreferencesInternal.yaml:
`EventHandlerDrivenSmoothKeyboardScrollingEnabled` is now true on default for WebKit.

* Source/WebCore/page/EventHandler.cpp:
(WebCore::EventHandler::startKeyboardScrollAnimationOnEnclosingScrollableContainer):
Added check if renderer is null to fix crash in LayoutTests/fast/forms/select/select-change-type-on-focus.

* Tools/TestWebKitAPI/Tests/WebKit/SpacebarScrolling.cpp:
(TestWebKitAPI::didRunJavascript):
(TestWebKitAPI::TEST):
Updated to reflect non-instananeous scrolling.

Canonical link: https://commits.webkit.org/255031@main
  • Loading branch information
rr-codes committed Sep 30, 2022
1 parent 3de7e6f commit cd1dbd2ab3f6005242c7ba9db7356e538d09ad2d
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 10 deletions.
@@ -1,4 +1,4 @@
<!DOCTYPE html> <!-- webkit-test-runner [ ScrollAnimatorEnabled=false ] -->
<!DOCTYPE html>
<html>
<head>
<style>
@@ -29,6 +29,7 @@

clickOnElement(container);
await UIHelper.keyDown("pageDown");
await UIHelper.waitForTargetScrollAnimationToSettle(container);

expectTrue(container.scrollTop != 0, "paging moved container");
let defaultPagePosition = container.scrollTop;
@@ -37,6 +38,7 @@
container.scrollTop = 0;
container.style.scrollPaddingTop = "10px";
await UIHelper.keyDown("pageDown");
await UIHelper.waitForTargetScrollAnimationToSettle(container);

let expected = (container.clientHeight - 10) * pageProportion;
expectTrue(container.scrollTop != 0, "paging moved padded container");
@@ -46,6 +48,7 @@
container.style.scrollPaddingTop = "0px";
container.style.scrollPaddingBottom = "10px";
await UIHelper.keyDown("pageDown");
await UIHelper.waitForTargetScrollAnimationToSettle(container);

expectTrue(container.scrollTop != 0, "paging moved padded container");
shouldBeCloseTo("container.scrollTop", expected, 1);
@@ -54,6 +57,7 @@
container.style.scrollPaddingTop = "10px";
container.style.scrollPaddingBottom = "10px";
await UIHelper.keyDown("pageDown");
await UIHelper.waitForTargetScrollAnimationToSettle(container);

expected = (container.clientHeight - 20) * pageProportion;
expectTrue(container.scrollTop != 0, "paging moved padded container");
@@ -21,7 +21,12 @@
}
if (window.testRunner)
window.testRunner.waitUntilDone();
document.addEventListener("scroll", scrollAndRepaint, false);

eventSender.monitorWheelEvents();

setTimeout(function() {
eventSender.callAfterScrollingCompletes(scrollAndRepaint);
}, 0);
</script>
</head>
<body style="height: 820;">
@@ -1 +1 @@
PASS: scrollLeft is -120
scrollLeft is -40
@@ -28,12 +28,8 @@

function checkForScroll()
{
var expectedScrollLeft = -120;
var scrollLeft = document.scrollingElement.scrollLeft;
if (scrollLeft != expectedScrollLeft)
document.getElementById('result').textContent = "FAIL: scrollLeft is " + scrollLeft + ", expected " + expectedScrollLeft;
else
document.getElementById('result').textContent = "PASS: scrollLeft is " + scrollLeft;
document.getElementById('result').textContent = "scrollLeft is " + scrollLeft;

if (window.testRunner)
testRunner.notifyDone();
@@ -0,0 +1 @@
scrollLeft is -120
@@ -275,7 +275,7 @@ EventHandlerDrivenSmoothKeyboardScrollingEnabled:
WebKitLegacy:
default: false
WebKit:
default: false
default: true
WebCore:
default: false

@@ -4411,8 +4411,11 @@ bool EventHandler::startKeyboardScrollAnimationOnEnclosingScrollableContainer(Sc

if (node) {
auto renderer = node->renderer();
if (!renderer)
return false;

RenderBox& renderBox = renderer->enclosingBox();
if (renderer && !renderer->isListBox() && startKeyboardScrollAnimationOnRenderBoxAndItsAncestors(direction, granularity, &renderBox))
if (!renderer->isListBox() && startKeyboardScrollAnimationOnRenderBoxAndItsAncestors(direction, granularity, &renderBox))
return true;
}
return false;
@@ -32,11 +32,14 @@
#include "PlatformWebView.h"
#include <WebKit/WKPreferencesRefPrivate.h>
#include <WebKit/WKRetainPtr.h>
#include <WebKit/WKSerializedScriptValue.h>

namespace TestWebKitAPI {

static bool didFinishLoad;
static bool didNotHandleKeyDownEvent;
static bool javascriptRun;
static bool isScrolled;

static void didFinishNavigation(WKPageRef, WKNavigationRef, WKTypeRef, const void*)
{
@@ -49,6 +52,18 @@ static void didNotHandleKeyEventCallback(WKPageRef, WKNativeEventPtr event, cons
didNotHandleKeyDownEvent = true;
}


static void didRunJavascript(WKSerializedScriptValueRef serializedScriptValue, WKErrorRef error, void* context)
{
JSGlobalContextRef scriptContext = JSGlobalContextCreate(0);
JSValueRef jsValue = WKSerializedScriptValueDeserialize(serializedScriptValue, scriptContext, 0);
isScrolled = JSValueToBoolean(scriptContext, jsValue);

javascriptRun = true;

JSGlobalContextRelease(scriptContext);
}

TEST(WebKit, SpacebarScrolling)
{
WKRetainPtr<WKContextRef> context = adoptWK(Util::createContextWithInjectedBundle());
@@ -101,6 +116,12 @@ TEST(WebKit, SpacebarScrolling)
didNotHandleKeyDownEvent = false;
webView.simulateSpacebarKeyPress();

while (!isScrolled) {
javascriptRun = false;
WKPageRunJavaScriptInMainFrame(webView.page(), Util::toWK("isDocumentScrolled()").get(), 0, didRunJavascript);
Util::run(&javascriptRun);
}

EXPECT_JS_TRUE(webView.page(), "isDocumentScrolled()");
EXPECT_JS_TRUE(webView.page(), "textFieldContainsSpace()");

0 comments on commit cd1dbd2

Please sign in to comment.