<!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>[285781] trunk</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/285781">285781</a></dd>
<dt>Author</dt> <dd>simon.fraser@apple.com</dd>
<dt>Date</dt> <dd>2021-11-13 15:04:06 -0800 (Sat, 13 Nov 2021)</dd>
</dl>

<h3>Log Message</h3>
<pre>Implement UIScriptController.sendEventStream() for DumpRenderTree
https://bugs.webkit.org/show_bug.cgi?id=233090

Reviewed by Wenson Hsieh.
Tools:

Implement UIScriptControllerMac::sendEventStream(), sharing some event dispatching code from
EventSendingController.

* DumpRenderTree/mac/EventSendingController.h:
* DumpRenderTree/mac/EventSendingController.mm:
(-[EventSendingController mouseScrollByX:andY:withWheel:andMomentumPhases:]):
(-[EventSendingController sendScrollEventAt:deltaX:deltaY:units:wheelPhase:momentumPhase:timestamp:]):
* DumpRenderTree/mac/UIScriptControllerMac.h:
* DumpRenderTree/mac/UIScriptControllerMac.mm:
(WTR::gesturePhaseFromString):
(WTR::momentumPhaseFromString):
(WTR::eventSenderFromView):
(WTR::UIScriptControllerMac::sendEventStream):

LayoutTests:

Convert one test that runs in WK1 to use sendEventStream().

* fast/scrolling/overflow-scroll-past-max.html:
* resources/ui-helper.js:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsfastscrollingoverflowscrollpastmaxhtml">trunk/LayoutTests/fast/scrolling/overflow-scroll-past-max.html</a></li>
<li><a href="#trunkLayoutTestsresourcesuihelperjs">trunk/LayoutTests/resources/ui-helper.js</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsDumpRenderTreemacEventSendingControllerh">trunk/Tools/DumpRenderTree/mac/EventSendingController.h</a></li>
<li><a href="#trunkToolsDumpRenderTreemacEventSendingControllermm">trunk/Tools/DumpRenderTree/mac/EventSendingController.mm</a></li>
<li><a href="#trunkToolsDumpRenderTreemacUIScriptControllerMach">trunk/Tools/DumpRenderTree/mac/UIScriptControllerMac.h</a></li>
<li><a href="#trunkToolsDumpRenderTreemacUIScriptControllerMacmm">trunk/Tools/DumpRenderTree/mac/UIScriptControllerMac.mm</a></li>
<li><a href="#trunkToolsWebKitTestRunnermacUIScriptControllerMacmm">trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (285780 => 285781)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog      2021-11-13 21:59:47 UTC (rev 285780)
+++ trunk/LayoutTests/ChangeLog 2021-11-13 23:04:06 UTC (rev 285781)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2021-11-13  Simon Fraser  <simon.fraser@apple.com>
+
+        Implement UIScriptController.sendEventStream() for DumpRenderTree
+        https://bugs.webkit.org/show_bug.cgi?id=233090
+
+        Reviewed by Wenson Hsieh.
+
+        Convert one test that runs in WK1 to use sendEventStream().
+
+        * fast/scrolling/overflow-scroll-past-max.html:
+        * resources/ui-helper.js:
+
</ins><span class="cx"> 2021-11-13  Tyler Wilcock  <tyler_w@apple.com>
</span><span class="cx"> 
</span><span class="cx">         AX: Make 7 more layout tests async so that they pass in --release --accessibility-isolated-tree mode
</span></span></pre></div>
<a id="trunkLayoutTestsfastscrollingoverflowscrollpastmaxhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/scrolling/overflow-scroll-past-max.html (285780 => 285781)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/scrolling/overflow-scroll-past-max.html   2021-11-13 21:59:47 UTC (rev 285780)
+++ trunk/LayoutTests/fast/scrolling/overflow-scroll-past-max.html      2021-11-13 23:04:06 UTC (rev 285781)
</span><span class="lines">@@ -16,6 +16,7 @@
</span><span class="cx">             background-image: linear-gradient(silver, gray);
</span><span class="cx">         }
</span><span class="cx">     </style>
</span><ins>+    <script src="../../resources/ui-helper.js"></script>
</ins><span class="cx">     <script>
</span><span class="cx">         function checkForScroll()
</span><span class="cx">         {
</span><span class="lines">@@ -30,22 +31,73 @@
</span><span class="cx">             testRunner.notifyDone();
</span><span class="cx">         }
</span><span class="cx">         
</span><del>-        function scrollTest()
</del><ins>+        async function scrollTest()
</ins><span class="cx">         {
</span><del>-            eventSender.mouseMoveTo(20, 20);
-            eventSender.mouseScrollByWithWheelAndMomentumPhases(0, -1, "began", "none");
-            eventSender.mouseScrollByWithWheelAndMomentumPhases(0, -100, "changed", "none");
-            eventSender.mouseScrollByWithWheelAndMomentumPhases(0, -100, "changed", "none");
-            eventSender.mouseScrollByWithWheelAndMomentumPhases(0, -1, "changed", "none");
-            eventSender.mouseScrollByWithWheelAndMomentumPhases(0, 0, "ended", "none");
-            eventSender.mouseScrollByWithWheelAndMomentumPhases(0, -100, "none", "begin");
-            eventSender.mouseScrollByWithWheelAndMomentumPhases(0, -100, "none", "continue");
-            eventSender.mouseScrollByWithWheelAndMomentumPhases(0, -100, "none", "continue");
-            eventSender.mouseScrollByWithWheelAndMomentumPhases(0, -100, "none", "continue");
-            eventSender.mouseScrollByWithWheelAndMomentumPhases(0, -100, "none", "continue");
-            eventSender.mouseScrollByWithWheelAndMomentumPhases(0, -100, "none", "continue");
-            eventSender.mouseScrollByWithWheelAndMomentumPhases(0, 0, "none", "end");
-            eventSender.callAfterScrollingCompletes(checkForScroll);
</del><ins>+            const events = [
+                {
+                    type : "wheel",
+                    viewX : 20,
+                    viewY : 20,
+                    deltaY : -10,
+                    phase : "began"
+                },
+                {
+                    type : "wheel",
+                    deltaY : -1000,
+                    phase : "changed"
+                },
+                {
+                    type : "wheel",
+                    deltaY : -1000,
+                    phase : "changed"
+                },
+                {
+                    type : "wheel",
+                    deltaY : -10,
+                    phase : "changed"
+                },
+                {
+                    type : "wheel",
+                    phase : "ended"
+                },
+                {
+                    type : "wheel",
+                    deltaY : -1000,
+                    momentumPhase : "began"
+                },
+                {
+                    type : "wheel",
+                    deltaY : -1000,
+                    momentumPhase : "began"
+                },
+                {
+                    type : "wheel",
+                    deltaY : -1000,
+                    momentumPhase : "began"
+                },
+                {
+                    type : "wheel",
+                    deltaY : -1000,
+                    momentumPhase : "began"
+                },
+                {
+                    type : "wheel",
+                    deltaY : -1000,
+                    momentumPhase : "began"
+                },
+                {
+                    type : "wheel",
+                    deltaY : -1000,
+                    momentumPhase : "began"
+                },
+                {
+                    type : "wheel",
+                    momentumPhase : "ended"
+                }
+            ];
+
+            await UIHelper.mouseWheelSequence({ events: events });
+            checkForScroll();
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         function startTest()
</span></span></pre></div>
<a id="trunkLayoutTestsresourcesuihelperjs"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/resources/ui-helper.js (285780 => 285781)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/resources/ui-helper.js 2021-11-13 21:59:47 UTC (rev 285780)
+++ trunk/LayoutTests/resources/ui-helper.js    2021-11-13 23:04:06 UTC (rev 285781)
</span><span class="lines">@@ -110,11 +110,6 @@
</span><span class="cx"> 
</span><span class="cx">     static async mouseWheelSequence(eventStream, { waitForCompletion = true } = {})
</span><span class="cx">     {
</span><del>-        if (!this.isWebKit2()) {
-            console.log('UIHelper.mouseWheelSequence() does not work in DumpRenderTree')
-            return Promise.resolve();
-        }
-
</del><span class="cx">         if (waitForCompletion)
</span><span class="cx">             eventSender.monitorWheelEvents();
</span><span class="cx">         const eventStreamAsString = JSON.stringify(eventStream);
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (285780 => 285781)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog    2021-11-13 21:59:47 UTC (rev 285780)
+++ trunk/Tools/ChangeLog       2021-11-13 23:04:06 UTC (rev 285781)
</span><span class="lines">@@ -1,3 +1,24 @@
</span><ins>+2021-11-13  Simon Fraser  <simon.fraser@apple.com>
+
+        Implement UIScriptController.sendEventStream() for DumpRenderTree
+        https://bugs.webkit.org/show_bug.cgi?id=233090
+
+        Reviewed by Wenson Hsieh.
+        
+        Implement UIScriptControllerMac::sendEventStream(), sharing some event dispatching code from
+        EventSendingController.
+
+        * DumpRenderTree/mac/EventSendingController.h:
+        * DumpRenderTree/mac/EventSendingController.mm:
+        (-[EventSendingController mouseScrollByX:andY:withWheel:andMomentumPhases:]):
+        (-[EventSendingController sendScrollEventAt:deltaX:deltaY:units:wheelPhase:momentumPhase:timestamp:]):
+        * DumpRenderTree/mac/UIScriptControllerMac.h:
+        * DumpRenderTree/mac/UIScriptControllerMac.mm:
+        (WTR::gesturePhaseFromString):
+        (WTR::momentumPhaseFromString):
+        (WTR::eventSenderFromView):
+        (WTR::UIScriptControllerMac::sendEventStream):
+
</ins><span class="cx"> 2021-11-13  Jonathan Bedard  <jbedard@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Unreviewed, reverting r285772.
</span></span></pre></div>
<a id="trunkToolsDumpRenderTreemacEventSendingControllerh"></a>
<div class="modfile"><h4>Modified: trunk/Tools/DumpRenderTree/mac/EventSendingController.h (285780 => 285781)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/DumpRenderTree/mac/EventSendingController.h  2021-11-13 21:59:47 UTC (rev 285780)
+++ trunk/Tools/DumpRenderTree/mac/EventSendingController.h     2021-11-13 23:04:06 UTC (rev 285781)
</span><span class="lines">@@ -58,6 +58,11 @@
</span><span class="cx"> 
</span><span class="cx"> - (void)handleEvent:(DOMEvent *)event;
</span><span class="cx"> 
</span><ins>+#if PLATFORM(MAC)
+// Timestamp is mach_absolute_time() units.
+- (void)sendScrollEventAt:(NSPoint)mouseLocation deltaX:(double)deltaX deltaY:(double)deltaY units:(CGScrollEventUnit)units wheelPhase:(CGGesturePhase)wheelPhase momentumPhase:(CGMomentumScrollPhase)momentumPhase timestamp:(uint64_t)timestamp;
+#endif
+
</ins><span class="cx"> @end
</span><span class="cx"> 
</span><span class="cx"> extern NSPoint lastMousePosition;
</span></span></pre></div>
<a id="trunkToolsDumpRenderTreemacEventSendingControllermm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/DumpRenderTree/mac/EventSendingController.mm (285780 => 285781)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/DumpRenderTree/mac/EventSendingController.mm 2021-11-13 21:59:47 UTC (rev 285780)
+++ trunk/Tools/DumpRenderTree/mac/EventSendingController.mm    2021-11-13 23:04:06 UTC (rev 285781)
</span><span class="lines">@@ -841,51 +841,62 @@
</span><span class="cx">     [self mouseScrollByX:x andY:y continuously:NO];
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (void)mouseScrollByX:(int)x andY:(int)y withWheel:(NSString*)phaseName andMomentumPhases:(NSString*)momentumName
</del><ins>+- (void)mouseScrollByX:(int)x andY:(int)y withWheel:(NSString*)wheelPhase andMomentumPhases:(NSString*)momentumPhase
</ins><span class="cx"> {
</span><span class="cx"> #if PLATFORM(MAC)
</span><span class="cx">     [[[mainFrame frameView] documentView] layout];
</span><span class="cx"> 
</span><del>-    uint32_t phase = 0;
-    if ([phaseName isEqualToString: @"none"])
-        phase = 0;
-    else if ([phaseName isEqualToString: @"began"])
-        phase = kCGScrollPhaseBegan;
-    else if ([phaseName isEqualToString: @"changed"])
-        phase = kCGScrollPhaseChanged;
-    else if ([phaseName isEqualToString: @"ended"])
-        phase = kCGScrollPhaseEnded;
-    else if ([phaseName isEqualToString: @"cancelled"])
-        phase = kCGScrollPhaseCancelled;
-    else if ([phaseName isEqualToString: @"maybegin"])
-        phase = kCGScrollPhaseMayBegin;
</del><ins>+    CGGesturePhase phase = kCGGesturePhaseNone;
+    if ([wheelPhase isEqualToString: @"none"])
+        phase = kCGGesturePhaseNone;
+    else if ([wheelPhase isEqualToString: @"began"])
+        phase = kCGGesturePhaseBegan;
+    else if ([wheelPhase isEqualToString: @"changed"])
+        phase = kCGGesturePhaseChanged;
+    else if ([wheelPhase isEqualToString: @"ended"])
+        phase = kCGGesturePhaseEnded;
+    else if ([wheelPhase isEqualToString: @"cancelled"])
+        phase = kCGGesturePhaseCancelled;
+    else if ([wheelPhase isEqualToString: @"maybegin"])
+        phase = kCGGesturePhaseMayBegin;
</ins><span class="cx"> 
</span><del>-    uint32_t momentum = 0;
-    if ([momentumName isEqualToString: @"none"])
</del><ins>+    CGMomentumScrollPhase momentum = kCGMomentumScrollPhaseNone;
+    if ([momentumPhase isEqualToString: @"none"])
</ins><span class="cx">         momentum = kCGMomentumScrollPhaseNone;
</span><del>-    else if ([momentumName isEqualToString:@"begin"])
</del><ins>+    else if ([momentumPhase isEqualToString:@"begin"])
</ins><span class="cx">         momentum = kCGMomentumScrollPhaseBegin;
</span><del>-    else if ([momentumName isEqualToString:@"continue"])
</del><ins>+    else if ([momentumPhase isEqualToString:@"continue"])
</ins><span class="cx">         momentum = kCGMomentumScrollPhaseContinue;
</span><del>-    else if ([momentumName isEqualToString:@"end"])
</del><ins>+    else if ([momentumPhase isEqualToString:@"end"])
</ins><span class="cx">         momentum = kCGMomentumScrollPhaseEnd;
</span><span class="cx"> 
</span><del>-    if (phase == kCGScrollPhaseEnded || phase == kCGScrollPhaseCancelled)
</del><ins>+    // FIXME: Maybe use a valid timestamp: webkit.org/b/232791.
+    [self sendScrollEventAt:lastMousePosition deltaX:x deltaY:y units:kCGScrollEventUnitLine wheelPhase:phase momentumPhase:momentum timestamp:0];
+#endif
+}
+
+#if PLATFORM(MAC)
+- (void)sendScrollEventAt:(NSPoint)mouseLocation deltaX:(double)deltaX deltaY:(double)deltaY units:(CGScrollEventUnit)units wheelPhase:(CGGesturePhase)wheelPhase momentumPhase:(CGMomentumScrollPhase)momentumPhase timestamp:(uint64_t)timestamp
+{
+    if (wheelPhase == kCGGesturePhaseEnded || wheelPhase == kCGGesturePhaseCancelled)
</ins><span class="cx">         _sentWheelPhaseEndOrCancel = YES;
</span><span class="cx"> 
</span><del>-    if (momentum == kCGMomentumScrollPhaseEnd)
</del><ins>+    if (momentumPhase == kCGMomentumScrollPhaseEnd)
</ins><span class="cx">         _sentMomentumPhaseEnd = YES;
</span><span class="cx"> 
</span><del>-    auto cgScrollEvent = adoptCF(CGEventCreateScrollWheelEvent2(NULL, kCGScrollEventUnitLine, 2, y, x, 0));
</del><ins>+    constexpr uint32_t wheelCount = 2;
+    // Note that the delta get converted to integral values here. NSEvent has float deltas, CGEvent has integral deltas.
+    auto cgScrollEvent = adoptCF(CGEventCreateScrollWheelEvent2(NULL, units, wheelCount, deltaY, deltaX, 0));
+    CGEventSetTimestamp(cgScrollEvent.get(), timestamp);
</ins><span class="cx"> 
</span><span class="cx">     // Set the CGEvent location in flipped coords relative to the first screen, which
</span><span class="cx">     // compensates for the behavior of +[NSEvent eventWithCGEvent:] when the event has
</span><span class="cx">     // no associated window. See <rdar://problem/17180591>.
</span><del>-    CGPoint lastGlobalMousePosition = CGPointMake(lastMousePosition.x, [[[NSScreen screens] objectAtIndex:0] frame].size.height - lastMousePosition.y);
-    CGEventSetLocation(cgScrollEvent.get(), lastGlobalMousePosition);
</del><ins>+    CGPoint globalMousePosition = CGPointMake(mouseLocation.x, [[[NSScreen screens] objectAtIndex:0] frame].size.height - mouseLocation.y);
+    CGEventSetLocation(cgScrollEvent.get(), globalMousePosition);
</ins><span class="cx">     CGEventSetIntegerValueField(cgScrollEvent.get(), kCGScrollWheelEventIsContinuous, 1);
</span><del>-    CGEventSetIntegerValueField(cgScrollEvent.get(), kCGScrollWheelEventScrollPhase, phase);
-    CGEventSetIntegerValueField(cgScrollEvent.get(), kCGScrollWheelEventMomentumPhase, momentum);
</del><ins>+    CGEventSetIntegerValueField(cgScrollEvent.get(), kCGScrollWheelEventScrollPhase, wheelPhase);
+    CGEventSetIntegerValueField(cgScrollEvent.get(), kCGScrollWheelEventMomentumPhase, momentumPhase);
</ins><span class="cx">     
</span><span class="cx">     NSEvent* scrollEvent = [NSEvent eventWithCGEvent:cgScrollEvent.get()];
</span><span class="cx"> 
</span><span class="lines">@@ -895,8 +906,8 @@
</span><span class="cx">         [NSApp _setCurrentEvent:nil];
</span><span class="cx">     } else
</span><span class="cx">         printf("mouseScrollByX...andMomentumPhases: Unable to locate target view for current mouse location.");
</span><ins>+}
</ins><span class="cx"> #endif
</span><del>-}
</del><span class="cx"> 
</span><span class="cx"> - (NSArray *)contextClick
</span><span class="cx"> {
</span></span></pre></div>
<a id="trunkToolsDumpRenderTreemacUIScriptControllerMach"></a>
<div class="modfile"><h4>Modified: trunk/Tools/DumpRenderTree/mac/UIScriptControllerMac.h (285780 => 285781)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/DumpRenderTree/mac/UIScriptControllerMac.h   2021-11-13 21:59:47 UTC (rev 285780)
+++ trunk/Tools/DumpRenderTree/mac/UIScriptControllerMac.h      2021-11-13 23:04:06 UTC (rev 285781)
</span><span class="lines">@@ -52,6 +52,7 @@
</span><span class="cx">     void copyText(JSStringRef) override;
</span><span class="cx">     void activateDataListSuggestion(unsigned, JSValueRef) override;
</span><span class="cx">     void setSpellCheckerResults(JSValueRef) override;
</span><ins>+    void sendEventStream(JSStringRef, JSValueRef) override;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkToolsDumpRenderTreemacUIScriptControllerMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/DumpRenderTree/mac/UIScriptControllerMac.mm (285780 => 285781)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/DumpRenderTree/mac/UIScriptControllerMac.mm  2021-11-13 21:59:47 UTC (rev 285780)
+++ trunk/Tools/DumpRenderTree/mac/UIScriptControllerMac.mm     2021-11-13 23:04:06 UTC (rev 285781)
</span><span class="lines">@@ -29,6 +29,7 @@
</span><span class="cx"> #if PLATFORM(MAC)
</span><span class="cx"> 
</span><span class="cx"> #import "DumpRenderTree.h"
</span><ins>+#import "EventSendingController.h"
</ins><span class="cx"> #import "LayoutTestSpellChecker.h"
</span><span class="cx"> #import "UIScriptContext.h"
</span><span class="cx"> #import <JavaScriptCore/JSContext.h>
</span><span class="lines">@@ -37,6 +38,7 @@
</span><span class="cx"> #import <JavaScriptCore/OpaqueJSString.h>
</span><span class="cx"> #import <WebKit/WebPreferences.h>
</span><span class="cx"> #import <WebKit/WebViewPrivate.h>
</span><ins>+#import <mach/mach_time.h>
</ins><span class="cx"> #import <pal/spi/mac/NSTextInputContextSPI.h>
</span><span class="cx"> #import <wtf/WorkQueue.h>
</span><span class="cx"> 
</span><span class="lines">@@ -173,6 +175,139 @@
</span><span class="cx">     [[LayoutTestSpellChecker checker] setResultsFromJSValue:results inContext:m_context->jsContext()];
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static NSString *const TopLevelEventInfoKey = @"events";
+static NSString *const EventTypeKey = @"type";
+static NSString *const ViewRelativeXPositionKey = @"viewX";
+static NSString *const ViewRelativeYPositionKey = @"viewY";
+static NSString *const DeltaXKey = @"deltaX";
+static NSString *const DeltaYKey = @"deltaY";
+static NSString *const PhaseKey = @"phase";
+static NSString *const MomentumPhaseKey = @"momentumPhase";
+
+static CGGesturePhase gesturePhaseFromString(NSString *phaseStr)
+{
+    if ([phaseStr isEqualToString:@"began"])
+        return kCGGesturePhaseBegan;
+
+    if ([phaseStr isEqualToString:@"changed"])
+        return kCGGesturePhaseChanged;
+
+    if ([phaseStr isEqualToString:@"ended"])
+        return kCGGesturePhaseEnded;
+
+    if ([phaseStr isEqualToString:@"cancelled"])
+        return kCGGesturePhaseCancelled;
+
+    if ([phaseStr isEqualToString:@"maybegin"])
+        return kCGGesturePhaseMayBegin;
+
+    return kCGGesturePhaseNone;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static CGMomentumScrollPhase momentumPhaseFromString(NSString *phaseStr)
+{
+    if ([phaseStr isEqualToString:@"began"])
+        return kCGMomentumScrollPhaseBegin;
+
+    if ([phaseStr isEqualToString:@"changed"] || [phaseStr isEqualToString:@"continue"]) // Allow "continue" for ease of conversion from mouseScrollByWithWheelAndMomentumPhases values.
+        return kCGMomentumScrollPhaseContinue;
+
+    if ([phaseStr isEqualToString:@"ended"])
+        return kCGMomentumScrollPhaseEnd;
+
+    return kCGMomentumScrollPhaseNone;
+}
+
+static EventSendingController *eventSenderFromView(WebView *webView)
+{
+    auto frame = [webView mainFrame];
+    auto windowObject = [frame windowObject];
+    return [windowObject valueForKey:@"eventSender"];
+}
+
+void UIScriptControllerMac::sendEventStream(JSStringRef eventsJSON, JSValueRef callback)
+{
+    WebView *webView = [mainFrame webView];
+
+    // didClearWindowObjectInStandardWorldForFrame stashed EventSendingController on this window property.
+    EventSendingController* eventSender = eventSenderFromView(webView);
+    if (!eventSender) {
+        ASSERT_NOT_REACHED();
+        return;
+    }
+
+    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
+
+    auto jsonString = eventsJSON->string();
+    auto eventInfo = dynamic_objc_cast<NSDictionary>([NSJSONSerialization JSONObjectWithData:[(NSString *)jsonString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:nil]);
+    if (!eventInfo || ![eventInfo isKindOfClass:[NSDictionary class]]) {
+        WTFLogAlways("JSON is not convertible to a dictionary");
+        return;
+    }
+
+    double currentViewRelativeX = 0;
+    double currentViewRelativeY = 0;
+
+    constexpr uint64_t nanosecondsPerSecond = 1e9;
+    constexpr uint64_t nanosecondsEventInterval = nanosecondsPerSecond / 60;
+
+    auto currentTime = mach_absolute_time();
+
+    for (NSMutableDictionary *event in eventInfo[TopLevelEventInfoKey]) {
+
+        id eventType = event[EventTypeKey];
+        if (!event[EventTypeKey]) {
+            WTFLogAlways("Missing event type");
+            break;
+        }
+        
+        if ([eventType isEqualToString:@"wheel"]) {
+            auto phase = kCGGesturePhaseNone;
+            auto momentumPhase = kCGMomentumScrollPhaseNone;
+
+            if (!event[PhaseKey] && !event[MomentumPhaseKey]) {
+                WTFLogAlways("Event must specify phase or momentumPhase");
+                break;
+            }
+
+            if (id phaseString = event[PhaseKey])
+                phase = gesturePhaseFromString(phaseString);
+
+            if (id phaseString = event[MomentumPhaseKey])
+                momentumPhase = momentumPhaseFromString(phaseString);
+
+            ASSERT_IMPLIES(phase == kCGGesturePhaseNone, momentumPhase != kCGMomentumScrollPhaseNone);
+            ASSERT_IMPLIES(momentumPhase == kCGMomentumScrollPhaseNone, phase != kCGGesturePhaseNone);
+
+            if (event[ViewRelativeXPositionKey])
+                currentViewRelativeX = [event[ViewRelativeXPositionKey] floatValue];
+
+            if (event[ViewRelativeYPositionKey])
+                currentViewRelativeY = [event[ViewRelativeYPositionKey] floatValue];
+
+            double deltaX = 0;
+            double deltaY = 0;
+
+            if (event[DeltaXKey])
+                deltaX = [event[DeltaXKey] floatValue];
+
+            if (event[DeltaYKey])
+                deltaY = [event[DeltaYKey] floatValue];
+
+            auto windowPoint = [webView convertPoint:CGPointMake(currentViewRelativeX, [webView frame].size.height - currentViewRelativeY) toView:nil];
+            [eventSender sendScrollEventAt:windowPoint deltaX:deltaX deltaY:deltaY units:kCGScrollEventUnitPixel wheelPhase:phase momentumPhase:momentumPhase timestamp:currentTime];
+        }
+
+        currentTime += nanosecondsEventInterval;
+    }
+
+    WorkQueue::main().dispatch([this, strongThis = Ref { *this }, callbackID] {
+        if (!m_context)
+            return;
+        m_context->asyncTaskComplete(callbackID);
+    });
+}
+
+} // namespace WTR
+
</ins><span class="cx"> #endif // PLATFORM(MAC)
</span></span></pre></div>
<a id="trunkToolsWebKitTestRunnermacUIScriptControllerMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm (285780 => 285781)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm        2021-11-13 21:59:47 UTC (rev 285780)
+++ trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm   2021-11-13 23:04:06 UTC (rev 285781)
</span><span class="lines">@@ -308,14 +308,14 @@
</span><span class="cx">     [[LayoutTestSpellChecker checker] setResultsFromJSValue:results inContext:m_context->jsContext()];
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static NSString* const TopLevelEventInfoKey = @"events";
-static NSString* const EventTypeKey = @"type";
-static NSString* const ViewRelativeXPositionKey = @"viewX";
-static NSString* const ViewRelativeYPositionKey = @"viewY";
-static NSString* const DeltaXKey = @"deltaX";
-static NSString* const DeltaYKey = @"deltaY";
-static NSString* const PhaseKey = @"phase";
-static NSString* const MomentumPhaseKey = @"momentumPhase";
</del><ins>+static NSString *const TopLevelEventInfoKey = @"events";
+static NSString *const EventTypeKey = @"type";
+static NSString *const ViewRelativeXPositionKey = @"viewX";
+static NSString *const ViewRelativeYPositionKey = @"viewY";
+static NSString *const DeltaXKey = @"deltaX";
+static NSString *const DeltaYKey = @"deltaY";
+static NSString *const PhaseKey = @"phase";
+static NSString *const MomentumPhaseKey = @"momentumPhase";
</ins><span class="cx"> 
</span><span class="cx"> static EventSenderProxy::WheelEventPhase eventPhaseFromString(NSString *phaseStr)
</span><span class="cx"> {
</span></span></pre>
</div>
</div>

</body>
</html>