<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[279355] trunk/Source</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/279355">279355</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2021-06-28 17:39:15 -0700 (Mon, 28 Jun 2021)</dd>
</dl>

<h3>Log Message</h3>
<pre>Refactor MacOS keyboard scrolling and use KeyboardScroll struct
https://bugs.webkit.org/show_bug.cgi?id=226986

Patch by Dana Estra <destra@apple.com> on 2021-06-28
Reviewed by Tim Horton.
Source/WebCore:

No tests yet.

* page/EventHandler.cpp:
(WebCore::EventHandler::defaultSpaceEventHandler):

Added usage of switch EventDrivenSmoothKeyboardScrolling
that when enabled sends KeyboardEvent to
HandleKeyboardScrolling.

(WebCore::EventHandler::scrollDistance):
(WebCore::EventHandler::handleKeyboardScrolling):

Makes KeyboardScroll and calls scrollRecursively.

(WebCore::EventHandler::defaultArrowEventHandler):

Added usage of switch EventDrivenSmoothKeyboardScrolling
that when enabled sends KeyboardEvent to
HandleKeyboardScrolling.

* page/EventHandler.h:
* page/KeyboardScroll.cpp: Added.
* page/KeyboardScroll.h: Added.

Source/WebKit:

In addition to notes underneath, changed usage of WebKit::KeyboardScroll, WebKit::ScrollingIncrement, and WebKit::ScrollingDirection to
WebCore::KeyboardScroll, WebCore::ScrollGranularity, and WebCore::ScrollDirection, respectively.

* UIProcess/ios/WKKeyboardScrollingAnimator.h:
* UIProcess/ios/WKKeyboardScrollingAnimator.mm:
(-[WKKeyboardScrollingAnimator parameters]):

Deleted. Now lives in WebCore/KeyboardScroll.h.

(unitVector):

Deleted. Now lives in WebCore/KeyboardScroll.h.

(perpendicularAbsoluteUnitVector):
(boxSide):
(-[WKKeyboardScrollingAnimator keyboardScrollForEvent:]):
(-[WKKeyboardScrollingAnimator beginWithEvent:]):
(farthestPointInDirection):
(-[WKKeyboardScrollViewAnimator distanceForIncrement:inDirection:]):
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::handleEditingKeyboardEvent):
(WebKit::WebPage::performNonEditingBehaviorForSelector):

Added switch that removes selectors that are now handled by
EventHandler when EventHandlerDrivenSmoothKeyboardScrolling
is enabled.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWTFScriptsPreferencesWebPreferencesInternalyaml">trunk/Source/WTF/Scripts/Preferences/WebPreferencesInternal.yaml</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreHeaderscmake">trunk/Source/WebCore/Headers.cmake</a></li>
<li><a href="#trunkSourceWebCoreSourcestxt">trunk/Source/WebCore/Sources.txt</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebCorepageEventHandlercpp">trunk/Source/WebCore/page/EventHandler.cpp</a></li>
<li><a href="#trunkSourceWebCorepageEventHandlerh">trunk/Source/WebCore/page/EventHandler.h</a></li>
<li><a href="#trunkSourceWebCorepagescrollingScrollLatchingControllercpp">trunk/Source/WebCore/page/scrolling/ScrollLatchingController.cpp</a></li>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitUIProcessiosWKContentViewInteractionmm">trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm</a></li>
<li><a href="#trunkSourceWebKitUIProcessiosWKKeyboardScrollingAnimatorh">trunk/Source/WebKit/UIProcess/ios/WKKeyboardScrollingAnimator.h</a></li>
<li><a href="#trunkSourceWebKitUIProcessiosWKKeyboardScrollingAnimatormm">trunk/Source/WebKit/UIProcess/ios/WKKeyboardScrollingAnimator.mm</a></li>
<li><a href="#trunkSourceWebKitWebProcessWebPagemacWebPageMacmm">trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebCorepageKeyboardScrollcpp">trunk/Source/WebCore/page/KeyboardScroll.cpp</a></li>
<li><a href="#trunkSourceWebCorepageKeyboardScrollh">trunk/Source/WebCore/page/KeyboardScroll.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWTFScriptsPreferencesWebPreferencesInternalyaml"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/Scripts/Preferences/WebPreferencesInternal.yaml (279354 => 279355)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/Scripts/Preferences/WebPreferencesInternal.yaml 2021-06-29 00:24:54 UTC (rev 279354)
+++ trunk/Source/WTF/Scripts/Preferences/WebPreferencesInternal.yaml    2021-06-29 00:39:15 UTC (rev 279355)
</span><span class="lines">@@ -220,6 +220,18 @@
</span><span class="cx">     WebCore:
</span><span class="cx">       default: false
</span><span class="cx"> 
</span><ins>+EventHandlerDrivenSmoothKeyboardScrollingEnabled:
+ type: bool
+ humanReadableName: "EventHandler driven smooth keyboard scrolling"
+ humanReadableDescription: "Enable EventHandler driven smooth keyboard scrolling"
+ defaultValue:
+  WebKitLegacy:
+   default: false
+  WebKit:
+   default: false
+  WebCore:
+   default: false
+
</ins><span class="cx"> # FIXME: This is not relevent for WebKitLegacy, so should be excluded from WebKitLegacy entirely.
</span><span class="cx"> ExperimentalPlugInSandboxProfilesEnabled:
</span><span class="cx">   type: bool
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (279354 => 279355)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2021-06-29 00:24:54 UTC (rev 279354)
+++ trunk/Source/WebCore/ChangeLog      2021-06-29 00:39:15 UTC (rev 279355)
</span><span class="lines">@@ -1,3 +1,34 @@
</span><ins>+2021-06-28  Dana Estra  <destra@apple.com>
+
+        Refactor MacOS keyboard scrolling and use KeyboardScroll struct
+        https://bugs.webkit.org/show_bug.cgi?id=226986
+
+        Reviewed by Tim Horton.
+
+        No tests yet.
+
+        * page/EventHandler.cpp:
+        (WebCore::EventHandler::defaultSpaceEventHandler):
+        
+        Added usage of switch EventDrivenSmoothKeyboardScrolling
+        that when enabled sends KeyboardEvent to
+        HandleKeyboardScrolling.
+        
+        (WebCore::EventHandler::scrollDistance):
+        (WebCore::EventHandler::handleKeyboardScrolling):
+        
+        Makes KeyboardScroll and calls scrollRecursively.
+        
+        (WebCore::EventHandler::defaultArrowEventHandler):
+        
+        Added usage of switch EventDrivenSmoothKeyboardScrolling
+        that when enabled sends KeyboardEvent to
+        HandleKeyboardScrolling.
+        
+        * page/EventHandler.h:
+        * page/KeyboardScroll.cpp: Added.
+        * page/KeyboardScroll.h: Added.
+
</ins><span class="cx"> 2021-06-28  Wenson Hsieh  <wenson_hsieh@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Live Text selections inside images is misaligned when "object-fit" is not "fill"
</span></span></pre></div>
<a id="trunkSourceWebCoreHeaderscmake"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Headers.cmake (279354 => 279355)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Headers.cmake       2021-06-29 00:24:54 UTC (rev 279354)
+++ trunk/Source/WebCore/Headers.cmake  2021-06-29 00:39:15 UTC (rev 279355)
</span><span class="lines">@@ -898,6 +898,7 @@
</span><span class="cx">     page/FrameViewLayoutContext.h
</span><span class="cx">     page/GlobalFrameIdentifier.h
</span><span class="cx">     page/GlobalWindowIdentifier.h
</span><ins>+    page/KeyboardScroll.h
</ins><span class="cx">     page/LayoutMilestone.h
</span><span class="cx">     page/MediaCanStartListener.h
</span><span class="cx">     page/MediaControlsContextMenuItem.h
</span></span></pre></div>
<a id="trunkSourceWebCoreSourcestxt"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Sources.txt (279354 => 279355)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Sources.txt 2021-06-29 00:24:54 UTC (rev 279354)
+++ trunk/Source/WebCore/Sources.txt    2021-06-29 00:39:15 UTC (rev 279355)
</span><span class="lines">@@ -1711,6 +1711,7 @@
</span><span class="cx"> page/FrameViewLayoutContext.cpp
</span><span class="cx"> page/History.cpp
</span><span class="cx"> page/ImageOverlayController.cpp
</span><ins>+page/KeyboardScroll.cpp
</ins><span class="cx"> page/IntersectionObserver.cpp
</span><span class="cx"> page/IntersectionObserverEntry.cpp
</span><span class="cx"> page/Location.cpp
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (279354 => 279355)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj   2021-06-29 00:24:54 UTC (rev 279354)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj      2021-06-29 00:39:15 UTC (rev 279355)
</span><span class="lines">@@ -667,6 +667,7 @@
</span><span class="cx">          1DBC1B562347B3D200B901AF /* PictureInPictureObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = 1DBC1B552347B3D200B901AF /* PictureInPictureObserver.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">          1DD3B4C6251DA0B80069B24A /* VideoLayerManagerObjC.mm in Sources */ = {isa = PBXBuildFile; fileRef = 52D5A18D1C54590300DE34A3 /* VideoLayerManagerObjC.mm */; };
</span><span class="cx">          1DF7E81F251A9E0600DB8F61 /* TextTrackRepresentation.h in Headers */ = {isa = PBXBuildFile; fileRef = CDD1E525167BA56400CE820B /* TextTrackRepresentation.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><ins>+               1F020AEF26780FCE0000809A /* KeyboardScroll.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F020AED26780FCE0000809A /* KeyboardScroll.h */; settings = {ATTRIBUTES = (Private, ); }; };
</ins><span class="cx">           1F36EA9C1E21BA1700621E25 /* WebBackgroundTaskController.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F36EA9A1E21BA1700621E25 /* WebBackgroundTaskController.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">          1F72BF0B187FD45C0009BCB3 /* TileControllerMemoryHandlerIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F72BF09187FD4270009BCB3 /* TileControllerMemoryHandlerIOS.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">          1F8756B21E22C3350042C40D /* WebSQLiteDatabaseTrackerClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F8756B11E22BEEF0042C40D /* WebSQLiteDatabaseTrackerClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="lines">@@ -7061,8 +7062,10 @@
</span><span class="cx">          1DEF06DC233D2E1C00EE228D /* DocumentPictureInPicture.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DocumentPictureInPicture.cpp; sourceTree = "<group>"; };
</span><span class="cx">          1DEF06DD233D2E1C00EE228D /* DocumentPictureInPicture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DocumentPictureInPicture.h; sourceTree = "<group>"; };
</span><span class="cx">          1DEF06DE233D2E1C00EE228D /* Document+PictureInPicture.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "Document+PictureInPicture.idl"; sourceTree = "<group>"; };
</span><ins>+               1F020AED26780FCE0000809A /* KeyboardScroll.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KeyboardScroll.h; sourceTree = "<group>"; };
</ins><span class="cx">           1F36EA9A1E21BA1700621E25 /* WebBackgroundTaskController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebBackgroundTaskController.h; sourceTree = "<group>"; };
</span><span class="cx">          1F36EA9B1E21BA1700621E25 /* WebBackgroundTaskController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebBackgroundTaskController.mm; sourceTree = "<group>"; };
</span><ins>+               1F53039A26854E6600236303 /* KeyboardScroll.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = KeyboardScroll.cpp; sourceTree = "<group>"; };
</ins><span class="cx">           1F72BF08187FD4270009BCB3 /* TileControllerMemoryHandlerIOS.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TileControllerMemoryHandlerIOS.cpp; sourceTree = "<group>"; };
</span><span class="cx">          1F72BF09187FD4270009BCB3 /* TileControllerMemoryHandlerIOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TileControllerMemoryHandlerIOS.h; sourceTree = "<group>"; };
</span><span class="cx">          1F8756B01E22BEEF0042C40D /* WebSQLiteDatabaseTrackerClient.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebSQLiteDatabaseTrackerClient.mm; sourceTree = "<group>"; };
</span><span class="lines">@@ -22512,6 +22515,8 @@
</span><span class="cx">                          0F4710D81DB6FE22002DCEC3 /* IntersectionObserverEntry.cpp */,
</span><span class="cx">                          0F4710D91DB6FE22002DCEC3 /* IntersectionObserverEntry.h */,
</span><span class="cx">                          0F4710DA1DB6FE22002DCEC3 /* IntersectionObserverEntry.idl */,
</span><ins>+                               1F53039A26854E6600236303 /* KeyboardScroll.cpp */,
+                               1F020AED26780FCE0000809A /* KeyboardScroll.h */,
</ins><span class="cx">                           931D72F515FE695300C4C07E /* LayoutMilestone.h */,
</span><span class="cx">                          BCE1C41A0D982980003B02F2 /* Location.cpp */,
</span><span class="cx">                          BCE1C4190D982980003B02F2 /* Location.h */,
</span><span class="lines">@@ -34153,6 +34158,7 @@
</span><span class="cx">                          BCEFE1EB0DCA5F6400739219 /* JSXSLTProcessor.h in Headers */,
</span><span class="cx">                          83B74EF61F3E0BF200996BC7 /* KeepaliveRequestTracker.h in Headers */,
</span><span class="cx">                          85031B440A44EFC700F992E0 /* KeyboardEvent.h in Headers */,
</span><ins>+                               1F020AEF26780FCE0000809A /* KeyboardScroll.h in Headers */,
</ins><span class="cx">                           1AE00D59182DAC8D00087DD7 /* KeyedCoding.h in Headers */,
</span><span class="cx">                          517A63C51B74318F00E7DCDC /* KeyedDecoderCF.h in Headers */,
</span><span class="cx">                          517A63C61B74319200E7DCDC /* KeyedEncoderCF.h in Headers */,
</span></span></pre></div>
<a id="trunkSourceWebCorepageEventHandlercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/EventHandler.cpp (279354 => 279355)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/EventHandler.cpp       2021-06-29 00:24:54 UTC (rev 279354)
+++ trunk/Source/WebCore/page/EventHandler.cpp  2021-06-29 00:39:15 UTC (rev 279355)
</span><span class="lines">@@ -68,6 +68,7 @@
</span><span class="cx"> #include "ImageOverlayController.h"
</span><span class="cx"> #include "InspectorInstrumentation.h"
</span><span class="cx"> #include "KeyboardEvent.h"
</span><ins>+#include "KeyboardScroll.h"
</ins><span class="cx"> #include "Logging.h"
</span><span class="cx"> #include "MouseEvent.h"
</span><span class="cx"> #include "MouseEventWithHitTestResults.h"
</span><span class="lines">@@ -4200,7 +4201,8 @@
</span><span class="cx">     if (!view)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    if (view->logicalScroll(direction, ScrollByPage))
</del><ins>+    bool defaultHandled = m_frame.settings().eventHandlerDrivenSmoothKeyboardScrollingEnabled() ? handleKeyboardScrolling(event) : view->logicalScroll(direction, ScrollByPage);
+    if (defaultHandled)
</ins><span class="cx">         event.setDefaultHandled();
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -4232,11 +4234,91 @@
</span><span class="cx">         event.setDefaultHandled();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+float EventHandler::scrollDistance(ScrollDirection direction, ScrollGranularity granularity)
+{
+    auto scrollbar = [&] {
+        if (direction == ScrollDirection::ScrollUp || direction == ScrollDirection::ScrollDown)
+            return m_frame.view()->verticalScrollbar();
+        return m_frame.view()->horizontalScrollbar();
+    }();
+    
+    switch (granularity) {
+    case ScrollGranularity::ScrollByLine:
+        return scrollbar->lineStep();
+    case ScrollGranularity::ScrollByPage:
+        return scrollbar->pageStep();
+    case ScrollGranularity::ScrollByDocument:
+        return scrollbar->totalSize();
+    case ScrollGranularity::ScrollByPixel:
+        return scrollbar->pixelStep();
+    }
+}
</ins><span class="cx"> 
</span><ins>+bool EventHandler::handleKeyboardScrolling(KeyboardEvent& event)
+{
+    // FIXME (bug 227459): This logic does not account for writing-mode.
+
+    enum class Key : uint8_t { LeftArrow, RightArrow, UpArrow, DownArrow, Space };
+
+    Key key;
+    if (event.keyIdentifier() == "Left")
+        key = Key::LeftArrow;
+    else if (event.keyIdentifier() == "Right")
+        key = Key::RightArrow;
+    else if (event.keyIdentifier() == "Up")
+        key = Key::UpArrow;
+    else if (event.keyIdentifier() == "Down")
+        key = Key::DownArrow;
+    else if (event.charCode() == ' ')
+        key = Key::Space;
+    else
+        return false;
+
+    auto granularity = [&] {
+        switch (key) {
+        case Key::LeftArrow:
+        case Key::RightArrow:
+            return event.altKey() ? ScrollGranularity::ScrollByPage : ScrollGranularity::ScrollByLine;
+        case Key::UpArrow:
+        case Key::DownArrow:
+            if (event.metaKey())
+                return ScrollGranularity::ScrollByDocument;
+            if (event.altKey())
+                return ScrollGranularity::ScrollByPage;
+            return ScrollGranularity::ScrollByLine;
+        case Key::Space:
+            return ScrollGranularity::ScrollByPage;
+        };
+    }();
+
+    auto direction = [&] {
+        switch (key) {
+        case Key::LeftArrow:
+            return ScrollDirection::ScrollLeft;
+        case Key::RightArrow:
+            return ScrollDirection::ScrollRight;
+        case Key::UpArrow:
+            return ScrollDirection::ScrollUp;
+        case Key::DownArrow:
+            return ScrollDirection::ScrollDown;
+        case Key::Space:
+            return event.shiftKey() ? ScrollDirection::ScrollUp : ScrollDirection::ScrollDown;
+        }
+    }();
+
+    return EventHandler::scrollRecursively(direction, granularity, nullptr);
+}
+
</ins><span class="cx"> void EventHandler::defaultArrowEventHandler(FocusDirection focusDirection, KeyboardEvent& event)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(event.type() == eventNames().keydownEvent);
</span><span class="cx"> 
</span><ins>+    if (!isSpatialNavigationEnabled(&m_frame)) {
+        if (m_frame.settings().eventHandlerDrivenSmoothKeyboardScrollingEnabled())
+            handleKeyboardScrolling(event);
+        return;
+    }
+
</ins><span class="cx">     if (event.ctrlKey() || event.metaKey() || event.altGraphKey() || event.shiftKey())
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="lines">@@ -4244,9 +4326,6 @@
</span><span class="cx">     if (!page)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    if (!isSpatialNavigationEnabled(&m_frame))
-        return;
-
</del><span class="cx">     // Arrows and other possible directional navigation keys can be used in design
</span><span class="cx">     // mode editing.
</span><span class="cx">     if (m_frame.document()->inDesignMode())
</span></span></pre></div>
<a id="trunkSourceWebCorepageEventHandlerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/EventHandler.h (279354 => 279355)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/EventHandler.h 2021-06-29 00:24:54 UTC (rev 279354)
+++ trunk/Source/WebCore/page/EventHandler.h    2021-06-29 00:39:15 UTC (rev 279355)
</span><span class="lines">@@ -29,6 +29,7 @@
</span><span class="cx"> #include "DragActions.h"
</span><span class="cx"> #include "FocusDirection.h"
</span><span class="cx"> #include "HitTestRequest.h"
</span><ins>+#include "KeyboardScroll.h"
</ins><span class="cx"> #include "LayoutPoint.h"
</span><span class="cx"> #include "PlatformMouseEvent.h"
</span><span class="cx"> #include "RenderObject.h"
</span><span class="lines">@@ -375,6 +376,9 @@
</span><span class="cx">     bool handleMousePressEventDoubleClick(const MouseEventWithHitTestResults&);
</span><span class="cx">     bool handleMousePressEventTripleClick(const MouseEventWithHitTestResults&);
</span><span class="cx"> 
</span><ins>+    float scrollDistance(ScrollDirection, ScrollGranularity);
+    bool handleKeyboardScrolling(KeyboardEvent&);
+
</ins><span class="cx"> #if ENABLE(DRAG_SUPPORT)
</span><span class="cx">     bool handleMouseDraggedEvent(const MouseEventWithHitTestResults&, CheckDragHysteresis = ShouldCheckDragHysteresis);
</span><span class="cx">     bool shouldAllowMouseDownToStartDrag() const;
</span></span></pre></div>
<a id="trunkSourceWebCorepageKeyboardScrollcpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/page/KeyboardScroll.cpp (0 => 279355)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/KeyboardScroll.cpp                             (rev 0)
+++ trunk/Source/WebCore/page/KeyboardScroll.cpp        2021-06-29 00:39:15 UTC (rev 279355)
</span><span class="lines">@@ -0,0 +1,45 @@
</span><ins>+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "KeyboardScroll.h"
+
+namespace WebCore {
+
+FloatSize unitVectorForScrollDirection(ScrollDirection direction)
+{
+    switch (direction) {
+    case ScrollDirection::ScrollUp:
+        return { 0, -1 };
+    case ScrollDirection::ScrollDown:
+        return { 0, 1 };
+    case ScrollDirection::ScrollLeft:
+        return { -1, 0 };
+    case ScrollDirection::ScrollRight:
+        return { 1, 0 };
+    }
+}
+
+}
</ins></span></pre></div>
<a id="trunkSourceWebCorepageKeyboardScrollh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/page/KeyboardScroll.h (0 => 279355)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/KeyboardScroll.h                               (rev 0)
+++ trunk/Source/WebCore/page/KeyboardScroll.h  2021-06-29 00:39:15 UTC (rev 279355)
</span><span class="lines">@@ -0,0 +1,60 @@
</span><ins>+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "ScrollTypes.h"
+
+namespace WebCore {
+
+WEBCORE_EXPORT FloatSize unitVectorForScrollDirection(ScrollDirection);
+
+struct KeyboardScroll {
+    FloatSize offset; // Points per increment.
+    FloatSize maximumVelocity; // Points per second.
+    FloatSize force;
+
+    ScrollGranularity granularity;
+    ScrollDirection direction;
+};
+
+struct KeyboardScrollParameters {
+    float springMass { 1 };
+    float springStiffness { 109 };
+    float springDamping { 20 };
+
+    float maximumVelocityMultiplier { 25 };
+    float timeToMaximumVelocity { 1 };
+
+    float rubberBandForce { 5000 };
+
+    static const KeyboardScrollParameters& parameters()
+    {
+        static const KeyboardScrollParameters parameters;
+        return parameters;
+    }
+};
+
+} // namespace WebCore
</ins></span></pre></div>
<a id="trunkSourceWebCorepagescrollingScrollLatchingControllercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/scrolling/ScrollLatchingController.cpp (279354 => 279355)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/scrolling/ScrollLatchingController.cpp 2021-06-29 00:24:54 UTC (rev 279354)
+++ trunk/Source/WebCore/page/scrolling/ScrollLatchingController.cpp    2021-06-29 00:39:15 UTC (rev 279355)
</span><span class="lines">@@ -29,6 +29,9 @@
</span><span class="cx"> #if ENABLE(WHEEL_EVENT_LATCHING)
</span><span class="cx"> 
</span><span class="cx"> #include "Element.h"
</span><ins>+#include "Frame.h"
+#include "FrameView.h"
+#include "Logging.h"
</ins><span class="cx"> #include "PlatformWheelEvent.h"
</span><span class="cx"> #include "ScrollableArea.h"
</span><span class="cx"> #include <wtf/text/TextStream.h>
</span></span></pre></div>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (279354 => 279355)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog    2021-06-29 00:24:54 UTC (rev 279354)
+++ trunk/Source/WebKit/ChangeLog       2021-06-29 00:39:15 UTC (rev 279355)
</span><span class="lines">@@ -1,3 +1,37 @@
</span><ins>+2021-06-28  Dana Estra  <destra@apple.com>
+
+        Refactor MacOS keyboard scrolling and use KeyboardScroll struct
+        https://bugs.webkit.org/show_bug.cgi?id=226986
+
+        Reviewed by Tim Horton.
+        
+        In addition to notes underneath, changed usage of WebKit::KeyboardScroll, WebKit::ScrollingIncrement, and WebKit::ScrollingDirection to
+        WebCore::KeyboardScroll, WebCore::ScrollGranularity, and WebCore::ScrollDirection, respectively.
+
+        * UIProcess/ios/WKKeyboardScrollingAnimator.h:
+        * UIProcess/ios/WKKeyboardScrollingAnimator.mm:
+        (-[WKKeyboardScrollingAnimator parameters]):
+        
+        Deleted. Now lives in WebCore/KeyboardScroll.h.
+        
+        (unitVector):
+        
+        Deleted. Now lives in WebCore/KeyboardScroll.h.
+        
+        (perpendicularAbsoluteUnitVector):
+        (boxSide):
+        (-[WKKeyboardScrollingAnimator keyboardScrollForEvent:]):
+        (-[WKKeyboardScrollingAnimator beginWithEvent:]):
+        (farthestPointInDirection):
+        (-[WKKeyboardScrollViewAnimator distanceForIncrement:inDirection:]):
+        * WebProcess/WebPage/mac/WebPageMac.mm:
+        (WebKit::WebPage::handleEditingKeyboardEvent):
+        (WebKit::WebPage::performNonEditingBehaviorForSelector):
+        
+        Added switch that removes selectors that are now handled by
+        EventHandler when EventHandlerDrivenSmoothKeyboardScrolling
+        is enabled.
+
</ins><span class="cx"> 2021-06-28  Chris Dumez  <cdumez@apple.com>
</span><span class="cx"> 
</span><span class="cx">         NetworkProcessProxy::networkProcessDidTerminate() should copy process pools before iterating over them
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessiosWKContentViewInteractionmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (279354 => 279355)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm    2021-06-29 00:24:54 UTC (rev 279354)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm       2021-06-29 00:39:15 UTC (rev 279355)
</span><span class="lines">@@ -108,6 +108,7 @@
</span><span class="cx"> #import <WebCore/FontAttributeChanges.h>
</span><span class="cx"> #import <WebCore/InputMode.h>
</span><span class="cx"> #import <WebCore/KeyEventCodesIOS.h>
</span><ins>+#import <WebCore/KeyboardScroll.h>
</ins><span class="cx"> #import <WebCore/LocalizedStrings.h>
</span><span class="cx"> #import <WebCore/MIMETypeRegistry.h>
</span><span class="cx"> #import <WebCore/NotImplemented.h>
</span><span class="lines">@@ -116,6 +117,7 @@
</span><span class="cx"> #import <WebCore/PathUtilities.h>
</span><span class="cx"> #import <WebCore/PromisedAttachmentInfo.h>
</span><span class="cx"> #import <WebCore/RuntimeApplicationChecks.h>
</span><ins>+#import <WebCore/ScrollTypes.h>
</ins><span class="cx"> #import <WebCore/Scrollbar.h>
</span><span class="cx"> #import <WebCore/ShareData.h>
</span><span class="cx"> #import <WebCore/TextAlternativeWithRange.h>
</span><span class="lines">@@ -5950,21 +5952,23 @@
</span><span class="cx">     return YES;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (CGFloat)keyboardScrollViewAnimator:(WKKeyboardScrollViewAnimator *)animator distanceForIncrement:(WebKit::ScrollingIncrement)increment inDirection:(WebKit::ScrollingDirection)direction
</del><ins>+- (CGFloat)keyboardScrollViewAnimator:(WKKeyboardScrollViewAnimator *)animator distanceForIncrement:(WebCore::ScrollGranularity)increment inDirection:(WebCore::ScrollDirection)direction
</ins><span class="cx"> {
</span><del>-    BOOL directionIsHorizontal = direction == WebKit::ScrollingDirection::Left || direction == WebKit::ScrollingDirection::Right;
</del><ins>+    BOOL directionIsHorizontal = direction == WebCore::ScrollDirection::ScrollLeft || direction == WebCore::ScrollDirection::ScrollRight;
</ins><span class="cx"> 
</span><span class="cx">     switch (increment) {
</span><del>-    case WebKit::ScrollingIncrement::Document: {
</del><ins>+    case WebCore::ScrollGranularity::ScrollByDocument: {
</ins><span class="cx">         CGSize documentSize = [self convertRect:self.bounds toView:self.webView].size;
</span><span class="cx">         return directionIsHorizontal ? documentSize.width : documentSize.height;
</span><span class="cx">     }
</span><del>-    case WebKit::ScrollingIncrement::Page: {
</del><ins>+    case WebCore::ScrollGranularity::ScrollByPage: {
</ins><span class="cx">         CGSize pageSize = [self convertSize:CGSizeMake(0, WebCore::Scrollbar::pageStep(_page->unobscuredContentRect().height(), self.bounds.size.height)) toView:self.webView];
</span><span class="cx">         return directionIsHorizontal ? pageSize.width : pageSize.height;
</span><span class="cx">     }
</span><del>-    case WebKit::ScrollingIncrement::Line:
</del><ins>+    case WebCore::ScrollGranularity::ScrollByLine:
</ins><span class="cx">         return [self convertSize:CGSizeMake(0, WebCore::Scrollbar::pixelsPerLineStep()) toView:self.webView].height;
</span><ins>+    case WebCore::ScrollGranularity::ScrollByPixel:
+        return 0;
</ins><span class="cx">     }
</span><span class="cx">     ASSERT_NOT_REACHED();
</span><span class="cx">     return 0;
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessiosWKKeyboardScrollingAnimatorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/ios/WKKeyboardScrollingAnimator.h (279354 => 279355)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/ios/WKKeyboardScrollingAnimator.h  2021-06-29 00:24:54 UTC (rev 279354)
+++ trunk/Source/WebKit/UIProcess/ios/WKKeyboardScrollingAnimator.h     2021-06-29 00:39:15 UTC (rev 279355)
</span><span class="lines">@@ -23,6 +23,8 @@
</span><span class="cx">  * THE POSSIBILITY OF SUCH DAMAGE.
</span><span class="cx">  */
</span><span class="cx"> 
</span><ins>+#import <WebCore/ScrollTypes.h>
+
</ins><span class="cx"> #if PLATFORM(IOS_FAMILY)
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -29,23 +31,7 @@
</span><span class="cx"> class FloatPoint;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-namespace WebKit {
</del><span class="cx"> 
</span><del>-enum class ScrollingIncrement : uint8_t {
-    Document,
-    Page,
-    Line
-};
-
-enum class ScrollingDirection : uint8_t {
-    Up,
-    Down,
-    Left,
-    Right
-};
-
-}
-
</del><span class="cx"> @class UIScrollView;
</span><span class="cx"> @class WebEvent;
</span><span class="cx"> @protocol WKKeyboardScrollViewAnimatorDelegate;
</span><span class="lines">@@ -71,7 +57,7 @@
</span><span class="cx"> @protocol WKKeyboardScrollViewAnimatorDelegate <NSObject>
</span><span class="cx"> @optional
</span><span class="cx"> - (BOOL)isScrollableForKeyboardScrollViewAnimator:(WKKeyboardScrollViewAnimator *)animator;
</span><del>-- (CGFloat)keyboardScrollViewAnimator:(WKKeyboardScrollViewAnimator *)animator distanceForIncrement:(WebKit::ScrollingIncrement)increment inDirection:(WebKit::ScrollingDirection)direction;
</del><ins>+- (CGFloat)keyboardScrollViewAnimator:(WKKeyboardScrollViewAnimator *)animator distanceForIncrement:(WebCore::ScrollGranularity)increment inDirection:(WebCore::ScrollDirection)direction;
</ins><span class="cx"> - (void)keyboardScrollViewAnimatorWillScroll:(WKKeyboardScrollViewAnimator *)animator;
</span><span class="cx"> - (void)keyboardScrollViewAnimatorDidFinishScrolling:(WKKeyboardScrollViewAnimator *)animator;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessiosWKKeyboardScrollingAnimatormm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/ios/WKKeyboardScrollingAnimator.mm (279354 => 279355)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/ios/WKKeyboardScrollingAnimator.mm 2021-06-29 00:24:54 UTC (rev 279354)
+++ trunk/Source/WebKit/UIProcess/ios/WKKeyboardScrollingAnimator.mm    2021-06-29 00:39:15 UTC (rev 279355)
</span><span class="lines">@@ -33,6 +33,7 @@
</span><span class="cx"> #import <QuartzCore/CADisplayLink.h>
</span><span class="cx"> #import <WebCore/FloatPoint.h>
</span><span class="cx"> #import <WebCore/KeyEventCodesIOS.h>
</span><ins>+#import <WebCore/KeyboardScroll.h>
</ins><span class="cx"> #import <WebCore/RectEdges.h>
</span><span class="cx"> #import <WebCore/WebEvent.h>
</span><span class="cx"> #import <WebKit/UIKitSPI.h>
</span><span class="lines">@@ -40,34 +41,11 @@
</span><span class="cx"> #import <wtf/RetainPtr.h>
</span><span class="cx"> #import <wtf/WeakObjCPtr.h>
</span><span class="cx"> 
</span><del>-namespace WebKit {
</del><span class="cx"> 
</span><del>-struct KeyboardScroll {
-    WebCore::FloatSize offset; // Points per increment.
-    WebCore::FloatSize maximumVelocity; // Points per second.
-    WebCore::FloatSize force;
-
-    WebKit::ScrollingIncrement increment;
-    WebKit::ScrollingDirection direction;
-};
-
-struct KeyboardScrollParameters {
-    CGFloat springMass { 1 };
-    CGFloat springStiffness { 109 };
-    CGFloat springDamping { 20 };
-
-    CGFloat maximumVelocityMultiplier { 25 };
-    CGFloat timeToMaximumVelocity { 1 };
-
-    CGFloat rubberBandForce { 5000 };
-};
-
-}
-
</del><span class="cx"> @protocol WKKeyboardScrollableInternal <NSObject>
</span><span class="cx"> @required
</span><span class="cx"> - (BOOL)isKeyboardScrollable;
</span><del>-- (CGFloat)distanceForIncrement:(WebKit::ScrollingIncrement)increment inDirection:(WebKit::ScrollingDirection)direction;
</del><ins>+- (CGFloat)distanceForIncrement:(WebCore::ScrollGranularity)increment inDirection:(WebCore::ScrollDirection)direction;
</ins><span class="cx"> - (void)scrollToContentOffset:(WebCore::FloatPoint)offset animated:(BOOL)animated;
</span><span class="cx"> - (void)scrollWithScrollToExtentAnimationTo:(CGPoint)offset;
</span><span class="cx"> - (CGPoint)contentOffset;
</span><span class="lines">@@ -97,7 +75,7 @@
</span><span class="cx">     id <WKKeyboardScrollableInternal> _scrollable;
</span><span class="cx">     RetainPtr<CADisplayLink> _displayLink;
</span><span class="cx"> 
</span><del>-    std::optional<WebKit::KeyboardScroll> _currentScroll;
</del><ins>+    std::optional<WebCore::KeyboardScroll> _currentScroll;
</ins><span class="cx"> 
</span><span class="cx">     BOOL _scrollTriggeringKeyIsPressed;
</span><span class="cx"> 
</span><span class="lines">@@ -124,9 +102,9 @@
</span><span class="cx">     return self;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (const WebKit::KeyboardScrollParameters &)parameters
</del><ins>+- (const WebCore::KeyboardScrollParameters &)parameters
</ins><span class="cx"> {
</span><del>-    static const WebKit::KeyboardScrollParameters parameters;
</del><ins>+    static const WebCore::KeyboardScrollParameters parameters;
</ins><span class="cx">     return parameters;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -137,47 +115,33 @@
</span><span class="cx">     _scrollable = nil;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static WebCore::FloatSize unitVector(WebKit::ScrollingDirection direction)
</del><ins>+static WebCore::FloatSize perpendicularAbsoluteUnitVector(WebCore::ScrollDirection direction)
</ins><span class="cx"> {
</span><span class="cx">     switch (direction) {
</span><del>-    case WebKit::ScrollingDirection::Up:
-        return { 0, -1 };
-    case WebKit::ScrollingDirection::Down:
-        return { 0, 1 };
-    case WebKit::ScrollingDirection::Left:
-        return { -1, 0 };
-    case WebKit::ScrollingDirection::Right:
</del><ins>+    case WebCore::ScrollDirection::ScrollUp:
+    case WebCore::ScrollDirection::ScrollDown:
</ins><span class="cx">         return { 1, 0 };
</span><del>-    }
-}
-
-static WebCore::FloatSize perpendicularAbsoluteUnitVector(WebKit::ScrollingDirection direction)
-{
-    switch (direction) {
-    case WebKit::ScrollingDirection::Up:
-    case WebKit::ScrollingDirection::Down:
-        return { 1, 0 };
-    case WebKit::ScrollingDirection::Left:
-    case WebKit::ScrollingDirection::Right:
</del><ins>+    case WebCore::ScrollDirection::ScrollLeft:
+    case WebCore::ScrollDirection::ScrollRight:
</ins><span class="cx">         return { 0, 1 };
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static WebCore::BoxSide boxSide(WebKit::ScrollingDirection direction)
</del><ins>+static WebCore::BoxSide boxSide(WebCore::ScrollDirection direction)
</ins><span class="cx"> {
</span><span class="cx">     switch (direction) {
</span><del>-    case WebKit::ScrollingDirection::Up:
</del><ins>+    case WebCore::ScrollDirection::ScrollUp:
</ins><span class="cx">         return WebCore::BoxSide::Top;
</span><del>-    case WebKit::ScrollingDirection::Down:
</del><ins>+    case WebCore::ScrollDirection::ScrollDown:
</ins><span class="cx">         return WebCore::BoxSide::Bottom;
</span><del>-    case WebKit::ScrollingDirection::Left:
</del><ins>+    case WebCore::ScrollDirection::ScrollLeft:
</ins><span class="cx">         return WebCore::BoxSide::Left;
</span><del>-    case WebKit::ScrollingDirection::Right:
</del><ins>+    case WebCore::ScrollDirection::ScrollRight:
</ins><span class="cx">         return WebCore::BoxSide::Right;
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (std::optional<WebKit::KeyboardScroll>)keyboardScrollForEvent:(::WebEvent *)event
</del><ins>+- (std::optional<WebCore::KeyboardScroll>)keyboardScrollForEvent:(::WebEvent *)event
</ins><span class="cx"> {
</span><span class="cx">     static const unsigned kWebSpaceKey = 0x20;
</span><span class="cx"> 
</span><span class="lines">@@ -255,22 +219,22 @@
</span><span class="cx">         case Key::LeftArrow:
</span><span class="cx">         case Key::RightArrow:
</span><span class="cx">             if (altPressed)
</span><del>-                return WebKit::ScrollingIncrement::Page;
-            return WebKit::ScrollingIncrement::Line;
</del><ins>+                return WebCore::ScrollGranularity::ScrollByPage;
+            return WebCore::ScrollGranularity::ScrollByLine;
</ins><span class="cx">         case Key::UpArrow:
</span><span class="cx">         case Key::DownArrow:
</span><span class="cx">             if (altPressed)
</span><del>-                return WebKit::ScrollingIncrement::Page;
</del><ins>+                return WebCore::ScrollGranularity::ScrollByPage;
</ins><span class="cx">             if (cmdPressed)
</span><del>-                return WebKit::ScrollingIncrement::Document;
-            return WebKit::ScrollingIncrement::Line;
</del><ins>+                return WebCore::ScrollGranularity::ScrollByDocument;
+            return WebCore::ScrollGranularity::ScrollByLine;
</ins><span class="cx">         case Key::PageUp:
</span><span class="cx">         case Key::PageDown:
</span><span class="cx">         case Key::Space:
</span><del>-            return WebKit::ScrollingIncrement::Page;
</del><ins>+            return WebCore::ScrollGranularity::ScrollByPage;
</ins><span class="cx">         case Key::Other:
</span><span class="cx">             ASSERT_NOT_REACHED();
</span><del>-            return WebKit::ScrollingIncrement::Line;
</del><ins>+            return WebCore::ScrollGranularity::ScrollByLine;
</ins><span class="cx">         };
</span><span class="cx">     }();
</span><span class="cx"> 
</span><span class="lines">@@ -277,28 +241,30 @@
</span><span class="cx">     auto direction = ^() {
</span><span class="cx">         switch (key) {
</span><span class="cx">         case Key::LeftArrow:
</span><del>-            return WebKit::ScrollingDirection::Left;
</del><ins>+            return WebCore::ScrollDirection::ScrollLeft;
</ins><span class="cx">         case Key::RightArrow:
</span><del>-            return WebKit::ScrollingDirection::Right;
</del><ins>+            return WebCore::ScrollDirection::ScrollRight;
</ins><span class="cx">         case Key::UpArrow:
</span><span class="cx">         case Key::PageUp:
</span><del>-            return WebKit::ScrollingDirection::Up;
</del><ins>+            return WebCore::ScrollDirection::ScrollUp;
</ins><span class="cx">         case Key::DownArrow:
</span><span class="cx">         case Key::PageDown:
</span><del>-            return WebKit::ScrollingDirection::Down;
</del><ins>+            return WebCore::ScrollDirection::ScrollDown;
</ins><span class="cx">         case Key::Space:
</span><del>-            return shiftPressed ? WebKit::ScrollingDirection::Up : WebKit::ScrollingDirection::Down;
</del><ins>+            return shiftPressed ? WebCore::ScrollDirection::ScrollUp : WebCore::ScrollDirection::ScrollDown;
</ins><span class="cx">         case Key::Other:
</span><span class="cx">             ASSERT_NOT_REACHED();
</span><del>-            return WebKit::ScrollingDirection::Down;
</del><ins>+            return WebCore::ScrollDirection::ScrollDown;
</ins><span class="cx">         };
</span><span class="cx">     }();
</span><span class="cx"> 
</span><ins>+    // FIXME (227461): Replace with call to WebCore::KeyboardScroll constructor.
+
</ins><span class="cx">     CGFloat scrollDistance = [_scrollable distanceForIncrement:increment inDirection:direction];
</span><span class="cx"> 
</span><del>-    WebKit::KeyboardScroll scroll;
-    scroll.offset = unitVector(direction).scaled(scrollDistance);
-    scroll.increment = increment;
</del><ins>+    WebCore::KeyboardScroll scroll;
+    scroll.offset = WebCore::unitVectorForScrollDirection(direction).scaled(scrollDistance);
+    scroll.granularity = increment;
</ins><span class="cx">     scroll.direction = direction;
</span><span class="cx">     scroll.maximumVelocity = scroll.offset.scaled(self.parameters.maximumVelocityMultiplier);
</span><span class="cx"> 
</span><span class="lines">@@ -327,7 +293,7 @@
</span><span class="cx">     _scrollTriggeringKeyIsPressed = YES;
</span><span class="cx">     _currentScroll = scroll;
</span><span class="cx"> 
</span><del>-    if (scroll->increment == WebKit::ScrollingIncrement::Document) {
</del><ins>+    if (scroll->granularity == WebCore::ScrollGranularity::ScrollByDocument) {
</ins><span class="cx">         _velocity = { };
</span><span class="cx">         [self stopAnimatedScroll];
</span><span class="cx">         [self stopDisplayLink];
</span><span class="lines">@@ -360,16 +326,16 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static WebCore::FloatPoint farthestPointInDirection(WebCore::FloatPoint a, WebCore::FloatPoint b, WebKit::ScrollingDirection direction)
</del><ins>+static WebCore::FloatPoint farthestPointInDirection(WebCore::FloatPoint a, WebCore::FloatPoint b, WebCore::ScrollDirection direction)
</ins><span class="cx"> {
</span><span class="cx">     switch (direction) {
</span><del>-    case WebKit::ScrollingDirection::Up:
</del><ins>+    case WebCore::ScrollDirection::ScrollUp:
</ins><span class="cx">         return WebCore::FloatPoint(a.x(), std::min(a.y(), b.y()));
</span><del>-    case WebKit::ScrollingDirection::Down:
</del><ins>+    case WebCore::ScrollDirection::ScrollDown:
</ins><span class="cx">         return WebCore::FloatPoint(a.x(), std::max(a.y(), b.y()));
</span><del>-    case WebKit::ScrollingDirection::Left:
</del><ins>+    case WebCore::ScrollDirection::ScrollLeft:
</ins><span class="cx">         return WebCore::FloatPoint(std::min(a.x(), b.x()), a.y());
</span><del>-    case WebKit::ScrollingDirection::Right:
</del><ins>+    case WebCore::ScrollDirection::ScrollRight:
</ins><span class="cx">         return WebCore::FloatPoint(std::max(a.x(), b.x()), a.y());
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -446,7 +412,7 @@
</span><span class="cx">             // The scroll view cannot scroll in this direction, and is rubber-banding.
</span><span class="cx">             // Apply a constant and significant force; otherwise, the force for a
</span><span class="cx">             // single-line increment is not strong enough to rubber-band perceptibly.
</span><del>-            force = unitVector(direction).scaled(self.parameters.rubberBandForce);
</del><ins>+            force = WebCore::unitVectorForScrollDirection(direction).scaled(self.parameters.rubberBandForce);
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         // If we've reached or exceeded the maximum velocity, stop applying any force.
</span><span class="lines">@@ -566,7 +532,7 @@
</span><span class="cx">     return [_delegate isScrollableForKeyboardScrollViewAnimator:self];
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (CGFloat)distanceForIncrement:(WebKit::ScrollingIncrement)increment inDirection:(WebKit::ScrollingDirection)direction
</del><ins>+- (CGFloat)distanceForIncrement:(WebCore::ScrollGranularity)increment inDirection:(WebCore::ScrollDirection)direction
</ins><span class="cx"> {
</span><span class="cx">     auto scrollView = _scrollView.getAutoreleased();
</span><span class="cx">     if (!scrollView)
</span><span class="lines">@@ -575,16 +541,18 @@
</span><span class="cx">     const CGFloat defaultPageScrollFraction = 0.8;
</span><span class="cx">     const CGFloat defaultLineScrollHeight = 40;
</span><span class="cx"> 
</span><del>-    BOOL directionIsHorizontal = direction == WebKit::ScrollingDirection::Left || direction == WebKit::ScrollingDirection::Right;
</del><ins>+    BOOL directionIsHorizontal = direction == WebCore::ScrollDirection::ScrollLeft || direction == WebCore::ScrollDirection::ScrollRight;
</ins><span class="cx"> 
</span><span class="cx">     if (!_delegateRespondsToDistanceForIncrement) {
</span><span class="cx">         switch (increment) {
</span><del>-        case WebKit::ScrollingIncrement::Document:
</del><ins>+        case WebCore::ScrollGranularity::ScrollByDocument:
</ins><span class="cx">             return directionIsHorizontal ? scrollView.contentSize.width : scrollView.contentSize.height;
</span><del>-        case WebKit::ScrollingIncrement::Page:
</del><ins>+        case WebCore::ScrollGranularity::ScrollByPage:
</ins><span class="cx">             return (directionIsHorizontal ? scrollView.frame.size.width : scrollView.frame.size.height) * defaultPageScrollFraction;
</span><del>-        case WebKit::ScrollingIncrement::Line:
</del><ins>+        case WebCore::ScrollGranularity::ScrollByLine:
</ins><span class="cx">             return defaultLineScrollHeight * scrollView.zoomScale;
</span><ins>+        case WebCore::ScrollGranularity::ScrollByPixel:
+            return 0;
</ins><span class="cx">         }
</span><span class="cx">         ASSERT_NOT_REACHED();
</span><span class="cx">         return 0;
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessWebPagemacWebPageMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm (279354 => 279355)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm 2021-06-29 00:24:54 UTC (rev 279354)
+++ trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm    2021-06-29 00:39:15 UTC (rev 279355)
</span><span class="lines">@@ -463,31 +463,34 @@
</span><span class="cx">     // Should such non-editing behaviors be implemented in Editor or EventHandler::defaultArrowEventHandler() perhaps?
</span><span class="cx">     
</span><span class="cx">     bool didPerformAction = false;
</span><ins>+    
+    if (!frame->settings().eventHandlerDrivenSmoothKeyboardScrollingEnabled()) {
+        if (selector == "moveUp:")
+            didPerformAction = scroll(m_page.get(), ScrollUp, ScrollByLine);
+        else if (selector == "moveToBeginningOfParagraph:")
+            didPerformAction = scroll(m_page.get(), ScrollUp, ScrollByPage);
+        else if (selector == "moveToBeginningOfDocument:") {
+            didPerformAction = scroll(m_page.get(), ScrollUp, ScrollByDocument);
+            didPerformAction |= scroll(m_page.get(), ScrollLeft, ScrollByDocument);
+        } else if (selector == "moveDown:")
+            didPerformAction = scroll(m_page.get(), ScrollDown, ScrollByLine);
+        else if (selector == "moveToEndOfParagraph:")
+            didPerformAction = scroll(m_page.get(), ScrollDown, ScrollByPage);
+        else if (selector == "moveToEndOfDocument:") {
+            didPerformAction = scroll(m_page.get(), ScrollDown, ScrollByDocument);
+            didPerformAction |= scroll(m_page.get(), ScrollLeft, ScrollByDocument);
+        } else if (selector == "moveLeft:")
+            didPerformAction = scroll(m_page.get(), ScrollLeft, ScrollByLine);
+        else if (selector == "moveWordLeft:")
+            didPerformAction = scroll(m_page.get(), ScrollLeft, ScrollByPage);
+        else if (selector == "moveRight:")
+            didPerformAction = scroll(m_page.get(), ScrollRight, ScrollByLine);
+        else if (selector == "moveWordRight:")
+            didPerformAction = scroll(m_page.get(), ScrollRight, ScrollByPage);
+    }
</ins><span class="cx"> 
</span><del>-    if (selector == "moveUp:")
-        didPerformAction = scroll(m_page.get(), ScrollUp, ScrollByLine);
-    else if (selector == "moveToBeginningOfParagraph:")
-        didPerformAction = scroll(m_page.get(), ScrollUp, ScrollByPage);
-    else if (selector == "moveToBeginningOfDocument:") {
-        didPerformAction = scroll(m_page.get(), ScrollUp, ScrollByDocument);
-        didPerformAction |= scroll(m_page.get(), ScrollLeft, ScrollByDocument);
-    } else if (selector == "moveDown:")
-        didPerformAction = scroll(m_page.get(), ScrollDown, ScrollByLine);
-    else if (selector == "moveToEndOfParagraph:")
-        didPerformAction = scroll(m_page.get(), ScrollDown, ScrollByPage);
-    else if (selector == "moveToEndOfDocument:") {
-        didPerformAction = scroll(m_page.get(), ScrollDown, ScrollByDocument);
-        didPerformAction |= scroll(m_page.get(), ScrollLeft, ScrollByDocument);
-    } else if (selector == "moveLeft:")
-        didPerformAction = scroll(m_page.get(), ScrollLeft, ScrollByLine);
-    else if (selector == "moveWordLeft:")
-        didPerformAction = scroll(m_page.get(), ScrollLeft, ScrollByPage);
-    else if (selector == "moveToLeftEndOfLine:")
</del><ins>+    if (selector == "moveToLeftEndOfLine:")
</ins><span class="cx">         didPerformAction = m_userInterfaceLayoutDirection == WebCore::UserInterfaceLayoutDirection::LTR ? m_page->backForward().goBack() : m_page->backForward().goForward();
</span><del>-    else if (selector == "moveRight:")
-        didPerformAction = scroll(m_page.get(), ScrollRight, ScrollByLine);
-    else if (selector == "moveWordRight:")
-        didPerformAction = scroll(m_page.get(), ScrollRight, ScrollByPage);
</del><span class="cx">     else if (selector == "moveToRightEndOfLine:")
</span><span class="cx">         didPerformAction = m_userInterfaceLayoutDirection == WebCore::UserInterfaceLayoutDirection::LTR ? m_page->backForward().goForward() : m_page->backForward().goBack();
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>