<!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>[198792] 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/198792">198792</a></dd>
<dt>Author</dt> <dd>bburg@apple.com</dd>
<dt>Date</dt> <dd>2016-03-29 13:19:45 -0700 (Tue, 29 Mar 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Web Automation: implement Automation.performMouseInteraction
https://bugs.webkit.org/show_bug.cgi?id=155606
&lt;rdar://problem/25227576&gt;

Source/WebKit2:

Reviewed by Timothy Hatcher.

This method implements common mouse interactions by synthesizing native events.
The creation and dispatching of simulated events is implemented separately per
application/window/event framework. This patch adds an implementation for ports
that use AppKit.

The event is created synthetically in a platform-specific way and delivered to
the platform's window in the UIProcess. The event goes through all the
layers of processing that a real mouse event could go through once it reaches
WebKit itself.

* UIProcess/Automation/Automation.json: Add new enums and command.

* UIProcess/Automation/WebAutomationSession.cpp:
(WebKit::protocolModifierToWebEventModifier):
(WebKit::WebAutomationSession::performMouseInteraction): Added.
Clip the requested cursor position so that it stays within the selected window's
frame and doesn't wander off into other windows or applications. Fire it using
the platform-specific simulation method.

(WebKit::WebAutomationSession::platformSimulateMouseInteraction): Added.

* UIProcess/Automation/WebAutomationSession.h:
* UIProcess/Cocoa/WebAutomationSessionCocoa.mm:
(WebKit::WebAutomationSession::platformSimulateMouseInteraction): Added.
Convert Automation protocol values to AppKit values. Simulate and dispatch
one or more events depending on the desired interaction.
* WebKit2Prefix.h: Include AppKitCompatibilityDeclarations.h so newer
NSEventTypes can be used.

Source/WTF:

Reviewed by Timothy Hatcher.

* wtf/mac/AppKitCompatibilityDeclarations.h: Add missing some NSEventTypes.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFwtfmacAppKitCompatibilityDeclarationsh">trunk/Source/WTF/wtf/mac/AppKitCompatibilityDeclarations.h</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAutomationAutomationjson">trunk/Source/WebKit2/UIProcess/Automation/Automation.json</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAutomationWebAutomationSessioncpp">trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAutomationWebAutomationSessionh">trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h</a></li>
<li><a href="#trunkSourceWebKit2WebKit2xcodeprojprojectpbxproj">trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebKit2WebKit2Prefixh">trunk/Source/WebKit2/WebKit2Prefix.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2UIProcessCocoaWebAutomationSessionCocoamm">trunk/Source/WebKit2/UIProcess/Cocoa/WebAutomationSessionCocoa.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (198791 => 198792)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog        2016-03-29 20:12:18 UTC (rev 198791)
+++ trunk/Source/WTF/ChangeLog        2016-03-29 20:19:45 UTC (rev 198792)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2016-03-28  Brian Burg  &lt;bburg@apple.com&gt;
+
+        Web Automation: implement Automation.performMouseInteraction
+        https://bugs.webkit.org/show_bug.cgi?id=155606
+        &lt;rdar://problem/25227576&gt;
+
+        Reviewed by Timothy Hatcher.
+
+        * wtf/mac/AppKitCompatibilityDeclarations.h: Add missing some NSEventTypes.
+
</ins><span class="cx"> 2016-03-29  Yusuke Suzuki  &lt;utatane.tea@gmail.com&gt;
</span><span class="cx"> 
</span><span class="cx">         REGRESSION(r192914): 10% regression on Sunspider's date-format-tofte
</span></span></pre></div>
<a id="trunkSourceWTFwtfmacAppKitCompatibilityDeclarationsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/mac/AppKitCompatibilityDeclarations.h (198791 => 198792)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/mac/AppKitCompatibilityDeclarations.h        2016-03-29 20:12:18 UTC (rev 198791)
+++ trunk/Source/WTF/wtf/mac/AppKitCompatibilityDeclarations.h        2016-03-29 20:19:45 UTC (rev 198792)
</span><span class="lines">@@ -78,8 +78,12 @@
</span><span class="cx"> static const NSEventType NSEventTypeLeftMouseUp = NSLeftMouseUp;
</span><span class="cx"> static const NSEventType NSEventTypeMouseMoved = NSMouseMoved;
</span><span class="cx"> static const NSEventType NSEventTypeOtherMouseDown = NSOtherMouseDown;
</span><ins>+static const NSEventType NSEventTypeOtherMouseDragged = NSOtherMouseDragged;
+static const NSEventType NSEventTypeOtherMouseUp = NSOtherMouseUp;
</ins><span class="cx"> static const NSEventType NSEventTypePeriodic = NSPeriodic;
</span><span class="cx"> static const NSEventType NSEventTypeRightMouseDown = NSRightMouseDown;
</span><ins>+static const NSEventType NSEventTypeRightMouseDragged = NSRightMouseDragged;
+static const NSEventType NSEventTypeRightMouseUp = NSRightMouseUp;
</ins><span class="cx"> static const NSEventType NSEventTypeScrollWheel = NSScrollWheel;
</span><span class="cx"> static const NSEventType NSEventTypeSystemDefined = NSSystemDefined;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (198791 => 198792)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2016-03-29 20:12:18 UTC (rev 198791)
+++ trunk/Source/WebKit2/ChangeLog        2016-03-29 20:19:45 UTC (rev 198792)
</span><span class="lines">@@ -1,3 +1,40 @@
</span><ins>+2016-03-28  Brian Burg  &lt;bburg@apple.com&gt;
+
+        Web Automation: implement Automation.performMouseInteraction
+        https://bugs.webkit.org/show_bug.cgi?id=155606
+        &lt;rdar://problem/25227576&gt;
+
+        Reviewed by Timothy Hatcher.
+
+        This method implements common mouse interactions by synthesizing native events.
+        The creation and dispatching of simulated events is implemented separately per
+        application/window/event framework. This patch adds an implementation for ports
+        that use AppKit.
+
+        The event is created synthetically in a platform-specific way and delivered to
+        the platform's window in the UIProcess. The event goes through all the
+        layers of processing that a real mouse event could go through once it reaches
+        WebKit itself.
+
+        * UIProcess/Automation/Automation.json: Add new enums and command.
+
+        * UIProcess/Automation/WebAutomationSession.cpp:
+        (WebKit::protocolModifierToWebEventModifier):
+        (WebKit::WebAutomationSession::performMouseInteraction): Added.
+        Clip the requested cursor position so that it stays within the selected window's
+        frame and doesn't wander off into other windows or applications. Fire it using
+        the platform-specific simulation method.
+
+        (WebKit::WebAutomationSession::platformSimulateMouseInteraction): Added.
+
+        * UIProcess/Automation/WebAutomationSession.h:
+        * UIProcess/Cocoa/WebAutomationSessionCocoa.mm:
+        (WebKit::WebAutomationSession::platformSimulateMouseInteraction): Added.
+        Convert Automation protocol values to AppKit values. Simulate and dispatch
+        one or more events depending on the desired interaction.
+        * WebKit2Prefix.h: Include AppKitCompatibilityDeclarations.h so newer
+        NSEventTypes can be used.
+
</ins><span class="cx"> 2016-03-29  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed. Follow up to r198580.
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAutomationAutomationjson"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Automation/Automation.json (198791 => 198792)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Automation/Automation.json        2016-03-29 20:12:18 UTC (rev 198791)
+++ trunk/Source/WebKit2/UIProcess/Automation/Automation.json        2016-03-29 20:19:45 UTC (rev 198792)
</span><span class="lines">@@ -68,6 +68,41 @@
</span><span class="cx">                 { &quot;name&quot;: &quot;windowSize&quot;, &quot;$ref&quot;: &quot;Size&quot;, &quot;description&quot;: &quot;The current size of the browsing context's window.&quot; },
</span><span class="cx">                 { &quot;name&quot;: &quot;windowOrigin&quot;, &quot;$ref&quot;: &quot;Point&quot;, &quot;description&quot;: &quot;The current (x, y) position of the browsing context's window relative to the top-left of the screen.&quot; }
</span><span class="cx">             ]
</span><ins>+        },
+        {
+            &quot;id&quot;: &quot;MouseInteraction&quot;,
+            &quot;type&quot;: &quot;string&quot;,
+            &quot;description&quot;: &quot;Enumerates different ways of interacting with a mouse cursor.&quot;,
+            &quot;enum&quot;: [
+                &quot;Move&quot;,
+                &quot;Down&quot;,
+                &quot;Up&quot;,
+                &quot;SingleClick&quot;,
+                &quot;DoubleClick&quot;
+            ]
+        },
+        {
+            &quot;id&quot;: &quot;MouseButton&quot;,
+            &quot;type&quot;: &quot;string&quot;,
+            &quot;description&quot;: &quot;Enumerates different mouse buttons that can be used.&quot;,
+            &quot;enum&quot;: [
+                &quot;None&quot;,
+                &quot;Left&quot;,
+                &quot;Middle&quot;,
+                &quot;Right&quot;
+            ]
+        },
+        {
+            &quot;id&quot;: &quot;KeyModifier&quot;,
+            &quot;type&quot;: &quot;string&quot;,
+            &quot;description&quot;: &quot;Enumerates different key modifiers that can remain pressed during other mouse/touch interactions.&quot;,
+            &quot;enum&quot;: [
+                &quot;CapsLock&quot;,
+                &quot;Control&quot;,
+                &quot;Shift&quot;,
+                &quot;Meta&quot;,
+                &quot;Alt&quot;
+            ]
</ins><span class="cx">         }
</span><span class="cx">     ],
</span><span class="cx">     &quot;commands&quot;: [
</span><span class="lines">@@ -171,6 +206,20 @@
</span><span class="cx">             &quot;async&quot;: true
</span><span class="cx">         },
</span><span class="cx">         {
</span><ins>+            &quot;name&quot;: &quot;performMouseInteraction&quot;,
+            &quot;description&quot;: &quot;Simulates interaction with a mouse cursor.&quot;,
+            &quot;parameters&quot;: [
+                { &quot;name&quot;: &quot;handle&quot;, &quot;$ref&quot;: &quot;BrowsingContextHandle&quot;, &quot;description&quot;: &quot;The browsing context to be interacted with.&quot; },
+                { &quot;name&quot;: &quot;position&quot;, &quot;$ref&quot;: &quot;Point&quot;, &quot;description&quot;: &quot;The requested position for the mouse cursor, specified in viewport coordinates.&quot; },
+                { &quot;name&quot;: &quot;button&quot;, &quot;$ref&quot;: &quot;MouseButton&quot;, &quot;description&quot;: &quot;The button to use to perform the interaction. This parameter only has an effect for the &lt;code&gt;Down&lt;/code&gt;, &lt;code&gt;Up&lt;/code&gt;, &lt;code&gt;Click&lt;/code&gt;, and &lt;code&gt;DoubleClick&lt;/code&gt; mouse interactions.&quot; },
+                { &quot;name&quot;: &quot;interaction&quot;, &quot;$ref&quot;: &quot;MouseInteraction&quot;, &quot;description&quot;: &quot;The type of interaction to be performed with the mouse cursor.&quot; },
+                { &quot;name&quot;: &quot;modifiers&quot;, &quot;type&quot;: &quot;array&quot;, &quot;items&quot;: { &quot;$ref&quot;: &quot;KeyModifier&quot; }, &quot;description&quot;: &quot;Key modifiers to be active during the mouse interaction.&quot; }
+            ],
+            &quot;returns&quot;: [
+                { &quot;name&quot;: &quot;position&quot;, &quot;$ref&quot;: &quot;Point&quot;, &quot;description&quot;: &quot;The updated position of the mouse cursor, specified in viewport coordinates.&quot; }
+            ]
+        },
+        {
</ins><span class="cx">             &quot;name&quot;: &quot;resolveChildFrameHandle&quot;,
</span><span class="cx">             &quot;description&quot;: &quot;Determines the &lt;code&gt;FrameHandle&lt;/code&gt; based on the ordinal, name or node handle of a child frame.&quot;,
</span><span class="cx">             &quot;parameters&quot;: [
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAutomationWebAutomationSessioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp (198791 => 198792)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp        2016-03-29 20:12:18 UTC (rev 198791)
+++ trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp        2016-03-29 20:19:45 UTC (rev 198792)
</span><span class="lines">@@ -35,6 +35,7 @@
</span><span class="cx"> #include &lt;JavaScriptCore/InspectorFrontendRouter.h&gt;
</span><span class="cx"> #include &lt;WebCore/URL.h&gt;
</span><span class="cx"> #include &lt;WebCore/UUID.h&gt;
</span><ins>+#include &lt;algorithm&gt;
</ins><span class="cx"> #include &lt;wtf/HashMap.h&gt;
</span><span class="cx"> 
</span><span class="cx"> using namespace Inspector;
</span><span class="lines">@@ -631,4 +632,86 @@
</span><span class="cx">     m_client-&gt;setUserInputForCurrentJavaScriptPromptOnPage(this, page, promptValue);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if USE(APPKIT)
+static WebEvent::Modifiers protocolModifierToWebEventModifier(Inspector::Protocol::Automation::KeyModifier modifier)
+{
+    switch (modifier) {
+    case Inspector::Protocol::Automation::KeyModifier::Alt:
+        return WebEvent::AltKey;
+    case Inspector::Protocol::Automation::KeyModifier::Meta:
+        return WebEvent::MetaKey;
+    case Inspector::Protocol::Automation::KeyModifier::Control:
+        return WebEvent::ControlKey;
+    case Inspector::Protocol::Automation::KeyModifier::Shift:
+        return WebEvent::ShiftKey;
+    case Inspector::Protocol::Automation::KeyModifier::CapsLock:
+        return WebEvent::CapsLockKey;
+    }
+}
+#endif // USE(APPKIT)
+
+void WebAutomationSession::performMouseInteraction(Inspector::ErrorString&amp; errorString, const String&amp; handle, const Inspector::InspectorObject&amp; requestedPositionObject, const String&amp; mouseButtonString, const String&amp; mouseInteractionString, const Inspector::InspectorArray&amp; keyModifierStrings, RefPtr&lt;Inspector::Protocol::Automation::Point&gt;&amp; updatedPositionObject)
+{
+#if !USE(APPKIT)
+    FAIL_WITH_PREDEFINED_ERROR_MESSAGE(NotImplemented);
+#else
+    WebPageProxy* page = webPageProxyForHandle(handle);
+    if (!page)
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
+
+    // FIXME &lt;rdar://problem/25094106&gt;: Specify what parameter was missing or invalid and how.
+    // This requires some changes to the other end's error handling. Right now it looks for an
+    // exact error message match. We could stuff this into the 'data' field on error object.
+    float x;
+    if (!requestedPositionObject.getDouble(WTF::ASCIILiteral(&quot;x&quot;), x))
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(MissingParameter);
+
+    float y;
+    if (!requestedPositionObject.getDouble(WTF::ASCIILiteral(&quot;y&quot;), y))
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(MissingParameter);
+
+    WebCore::FloatRect windowFrame;
+    page-&gt;getWindowFrame(windowFrame);
+
+    x = std::max(std::min(0.0f, x), windowFrame.size().width());
+    y = std::max(std::min(0.0f, y), windowFrame.size().height());
+
+    WebCore::IntPoint viewPosition = WebCore::IntPoint(static_cast&lt;int&gt;(x), static_cast&lt;int&gt;(y));
+
+    auto parsedInteraction = Inspector::Protocol::parseEnumValueFromString&lt;Inspector::Protocol::Automation::MouseInteraction&gt;(mouseInteractionString);
+    if (!parsedInteraction)
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(InvalidParameter);
+
+    auto parsedButton = Inspector::Protocol::parseEnumValueFromString&lt;Inspector::Protocol::Automation::MouseButton&gt;(mouseButtonString);
+    if (!parsedButton)
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(InvalidParameter);
+
+    WebEvent::Modifiers keyModifiers = (WebEvent::Modifiers)0;
+    for (auto it = keyModifierStrings.begin(); it != keyModifierStrings.end(); ++it) {
+        String modifierString;
+        if (!it-&gt;get()-&gt;asString(modifierString))
+            FAIL_WITH_PREDEFINED_ERROR_MESSAGE(InvalidParameter);
+
+        auto parsedModifier = Inspector::Protocol::parseEnumValueFromString&lt;Inspector::Protocol::Automation::KeyModifier&gt;(modifierString);
+        if (!parsedModifier)
+            FAIL_WITH_PREDEFINED_ERROR_MESSAGE(InvalidParameter);
+        WebEvent::Modifiers enumValue = protocolModifierToWebEventModifier(parsedModifier.value());
+        keyModifiers = (WebEvent::Modifiers)(enumValue | keyModifiers);
+    }
+
+    platformSimulateMouseInteraction(*page, viewPosition, parsedInteraction.value(), parsedButton.value(), keyModifiers);
+
+    updatedPositionObject = Inspector::Protocol::Automation::Point::create()
+        .setX(x)
+        .setY(y)
+        .release();
+#endif // USE(APPKIT)
+}
+
+#if !USE(APPKIT)
+void WebAutomationSession::platformSimulateMouseInteraction(WebKit::WebPageProxy&amp;, const WebCore::IntPoint&amp;, Inspector::Protocol::Automation::MouseInteraction, Inspector::Protocol::Automation::MouseButton, WebEvent::Modifiers)
+{
+}
+#endif // !USE(APPKIT)
+
</ins><span class="cx"> } // namespace WebKit
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAutomationWebAutomationSessionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h (198791 => 198792)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h        2016-03-29 20:12:18 UTC (rev 198791)
+++ trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h        2016-03-29 20:19:45 UTC (rev 198792)
</span><span class="lines">@@ -23,12 +23,12 @@
</span><span class="cx">  * THE POSSIBILITY OF SUCH DAMAGE.
</span><span class="cx">  */
</span><span class="cx"> 
</span><del>-#ifndef WebAutomationSession_h
-#define WebAutomationSession_h
</del><ins>+#pragma once
</ins><span class="cx"> 
</span><span class="cx"> #include &quot;APIObject.h&quot;
</span><span class="cx"> #include &quot;AutomationBackendDispatchers.h&quot;
</span><span class="cx"> #include &quot;Connection.h&quot;
</span><ins>+#include &quot;WebEvent.h&quot;
</ins><span class="cx"> #include &lt;wtf/Forward.h&gt;
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(REMOTE_INSPECTOR)
</span><span class="lines">@@ -48,6 +48,14 @@
</span><span class="cx"> class IntRect;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+namespace WebCore {
+class IntPoint;
+}
+
+#if USE(APPKIT)
+OBJC_CLASS NSArray;
+#endif
+
</ins><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><span class="cx"> class WebAutomationSessionClient;
</span><span class="lines">@@ -94,6 +102,7 @@
</span><span class="cx">     void goForwardInBrowsingContext(Inspector::ErrorString&amp;, const String&amp;) override;
</span><span class="cx">     void reloadBrowsingContext(Inspector::ErrorString&amp;, const String&amp;) override;
</span><span class="cx">     void evaluateJavaScriptFunction(Inspector::ErrorString&amp;, const String&amp; browsingContextHandle, const String* optionalFrameHandle, const String&amp; function, const Inspector::InspectorArray&amp; arguments, bool expectsImplicitCallbackArgument, Ref&lt;Inspector::AutomationBackendDispatcherHandler::EvaluateJavaScriptFunctionCallback&gt;&amp;&amp;) override;
</span><ins>+    void performMouseInteraction(Inspector::ErrorString&amp;, const String&amp; handle, const Inspector::InspectorObject&amp; requestedPosition, const String&amp; mouseButton, const String&amp; mouseInteraction, const Inspector::InspectorArray&amp; keyModifiers, RefPtr&lt;Inspector::Protocol::Automation::Point&gt;&amp; updatedPosition) override;
</ins><span class="cx">     void resolveChildFrameHandle(Inspector::ErrorString&amp;, const String&amp; browsingContextHandle, const String* optionalFrameHandle, const int* optionalOrdinal, const String* optionalName, const String* optionalNodeHandle, Ref&lt;ResolveChildFrameHandleCallback&gt;&amp;&amp;) override;
</span><span class="cx">     void resolveParentFrameHandle(Inspector::ErrorString&amp;, const String&amp; browsingContextHandle, const String&amp; frameHandle, Ref&lt;ResolveParentFrameHandleCallback&gt;&amp;&amp;) override;
</span><span class="cx">     void computeElementLayout(Inspector::ErrorString&amp;, const String&amp; browsingContextHandle, const String&amp; frameHandle, const String&amp; nodeHandle, const bool* optionalScrollIntoViewIfNeeded, const bool* useViewportCoordinates, Ref&lt;Inspector::AutomationBackendDispatcherHandler::ComputeElementLayoutCallback&gt;&amp;&amp;) override;
</span><span class="lines">@@ -121,6 +130,13 @@
</span><span class="cx">     void didResolveParentFrame(uint64_t callbackID, uint64_t frameID, const String&amp; errorType);
</span><span class="cx">     void didComputeElementLayout(uint64_t callbackID, WebCore::IntRect, const String&amp; errorType);
</span><span class="cx"> 
</span><ins>+    // Platform-specific helper methods.
+    void platformSimulateMouseInteraction(WebPageProxy&amp;, const WebCore::IntPoint&amp; viewPosition, Inspector::Protocol::Automation::MouseInteraction, Inspector::Protocol::Automation::MouseButton, WebEvent::Modifiers);
+
+#if USE(APPKIT)
+    void sendSynthesizedEventsToPage(WebPageProxy&amp;, NSArray *eventsToSend);
+#endif
+
</ins><span class="cx">     WebProcessPool* m_processPool { nullptr };
</span><span class="cx"> 
</span><span class="cx">     std::unique_ptr&lt;API::AutomationSessionClient&gt; m_client;
</span><span class="lines">@@ -154,5 +170,3 @@
</span><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebKit
</span><del>-
-#endif // WebAutomationSession_h
</del></span></pre></div>
<a id="trunkSourceWebKit2UIProcessCocoaWebAutomationSessionCocoamm"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/UIProcess/Cocoa/WebAutomationSessionCocoa.mm (0 => 198792)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Cocoa/WebAutomationSessionCocoa.mm                                (rev 0)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebAutomationSessionCocoa.mm        2016-03-29 20:19:45 UTC (rev 198792)
</span><span class="lines">@@ -0,0 +1,131 @@
</span><ins>+/*
+ * Copyright (C) 2016 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.
+ */
+
+#import &quot;config.h&quot;
+#import &quot;WebAutomationSession.h&quot;
+
+#import &quot;WebPageProxy.h&quot;
+#import &quot;_WKAutomationSession.h&quot;
+#import &lt;WebCore/IntPoint.h&gt;
+#import &lt;WebCore/IntSize.h&gt;
+#import &lt;WebCore/PlatformMouseEvent.h&gt;
+#import &lt;objc/runtime.h&gt;
+
+using namespace WebCore;
+
+namespace WebKit {
+
+#if USE(APPKIT)
+
+void WebAutomationSession::sendSynthesizedEventsToPage(WebPageProxy&amp; page, NSArray *eventsToSend)
+{
+    NSWindow *window = page.platformWindow();
+
+    for (NSEvent *event in eventsToSend) {
+        // FIXME: &lt;https://www.webkit.org/b/155963&gt; Set an associated object with a per-session identifier.
+        // This will allow a WebKit2 client to tell apart events synthesized on behalf of an automation command.
+        [window sendEvent:event];
+    }
+}
+
+void WebAutomationSession::platformSimulateMouseInteraction(WebPageProxy&amp; page, const WebCore::IntPoint&amp; viewPosition, Inspector::Protocol::Automation::MouseInteraction interaction, Inspector::Protocol::Automation::MouseButton button, WebEvent::Modifiers keyModifiers)
+{
+    IntRect windowRect;
+    page.rootViewToWindow(IntRect(viewPosition, IntSize()), windowRect);
+    IntPoint windowPosition = windowRect.location();
+
+    NSEventModifierFlags modifiers = 0;
+    if (keyModifiers &amp; WebEvent::MetaKey)
+        modifiers |= NSEventModifierFlagCommand;
+    if (keyModifiers &amp; WebEvent::AltKey)
+        modifiers |= NSEventModifierFlagOption;
+    if (keyModifiers &amp; WebEvent::ControlKey)
+        modifiers |= NSEventModifierFlagControl;
+    if (keyModifiers &amp; WebEvent::ShiftKey)
+        modifiers |= NSEventModifierFlagShift;
+
+    NSTimeInterval timestamp = [NSDate timeIntervalSinceReferenceDate];
+    NSWindow *window = page.platformWindow();
+    NSInteger windowNumber = window.windowNumber;
+
+    NSEventType downEventType;
+    NSEventType dragEventType;
+    NSEventType upEventType;
+    switch (button) {
+    case Inspector::Protocol::Automation::MouseButton::None:
+        downEventType = upEventType = dragEventType = NSEventTypeMouseMoved;
+        break;
+    case Inspector::Protocol::Automation::MouseButton::Left:
+        downEventType = NSEventTypeLeftMouseDown;
+        dragEventType = NSEventTypeLeftMouseDragged;
+        upEventType = NSEventTypeLeftMouseUp;
+        break;
+    case Inspector::Protocol::Automation::MouseButton::Middle:
+        downEventType = NSEventTypeOtherMouseDown;
+        dragEventType = NSEventTypeLeftMouseDragged;
+        upEventType = NSEventTypeOtherMouseUp;
+        break;
+    case Inspector::Protocol::Automation::MouseButton::Right:
+        downEventType = NSEventTypeRightMouseDown;
+        upEventType = NSEventTypeRightMouseUp;
+        break;
+    }
+
+    NSMutableArray&lt;NSEvent *&gt; *eventsToBeSent = [NSMutableArray new];
+
+    switch (interaction) {
+    case Inspector::Protocol::Automation::MouseInteraction::Move:
+        [eventsToBeSent addObject:[NSEvent mouseEventWithType:dragEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:0 clickCount:0 pressure:0.0f]];
+        break;
+    case Inspector::Protocol::Automation::MouseInteraction::Down:
+        // Hard-code the click count to one, since clients don't expect successive simulated
+        // down/up events to be potentially counted as a double click event.
+        [eventsToBeSent addObject:[NSEvent mouseEventWithType:downEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:0 clickCount:1 pressure:WebCore::ForceAtClick]];
+        break;
+    case Inspector::Protocol::Automation::MouseInteraction::Up:
+        // Hard-code the click count to one, since clients don't expect successive simulated
+        // down/up events to be potentially counted as a double click event.
+        [eventsToBeSent addObject:[NSEvent mouseEventWithType:upEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:0 clickCount:1 pressure:0.0f]];
+        break;
+    case Inspector::Protocol::Automation::MouseInteraction::SingleClick:
+        // Send separate down and up events. WebCore will see this as a single-click event.
+        [eventsToBeSent addObject:[NSEvent mouseEventWithType:downEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:0 clickCount:1 pressure:WebCore::ForceAtClick]];
+        [eventsToBeSent addObject:[NSEvent mouseEventWithType:upEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:0 clickCount:1 pressure:0.0f]];
+        break;
+    case Inspector::Protocol::Automation::MouseInteraction::DoubleClick:
+        // Send multiple down and up events with proper click count.
+        // WebCore will see this as a single-click event then double-click event.
+        [eventsToBeSent addObject:[NSEvent mouseEventWithType:downEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:0 clickCount:1 pressure:WebCore::ForceAtClick]];
+        [eventsToBeSent addObject:[NSEvent mouseEventWithType:upEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:0 clickCount:1 pressure:0.0f]];
+        [eventsToBeSent addObject:[NSEvent mouseEventWithType:downEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:0 clickCount:2 pressure:WebCore::ForceAtClick]];
+        [eventsToBeSent addObject:[NSEvent mouseEventWithType:upEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:0 clickCount:2 pressure:0.0f]];
+    }
+
+    sendSynthesizedEventsToPage(page, eventsToBeSent);
+}
+
+#endif // USE(APPKIT)
+
+} // namespace WebKit
</ins></span></pre></div>
<a id="trunkSourceWebKit2WebKit2xcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (198791 => 198792)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj        2016-03-29 20:12:18 UTC (rev 198791)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj        2016-03-29 20:19:45 UTC (rev 198792)
</span><span class="lines">@@ -1238,6 +1238,7 @@
</span><span class="cx">                 9955A6F51C7986E000EB6A93 /* AutomationBackendDispatchers.h in Headers */ = {isa = PBXBuildFile; fileRef = 9955A6F11C79866400EB6A93 /* AutomationBackendDispatchers.h */; };
</span><span class="cx">                 9955A6F61C7986E300EB6A93 /* AutomationProtocolObjects.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9955A6F21C79866400EB6A93 /* AutomationProtocolObjects.cpp */; };
</span><span class="cx">                 9955A6F71C7986E500EB6A93 /* AutomationProtocolObjects.h in Headers */ = {isa = PBXBuildFile; fileRef = 9955A6F31C79866400EB6A93 /* AutomationProtocolObjects.h */; };
</span><ins>+                9986BDD71CA9A22C004800AA /* WebAutomationSessionCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9986BDD61CA9A222004800AA /* WebAutomationSessionCocoa.mm */; };
</ins><span class="cx">                 99C81D591C20E1E5005C4C82 /* AutomationClient.mm in Sources */ = {isa = PBXBuildFile; fileRef = 99C81D561C20DFBE005C4C82 /* AutomationClient.mm */; };
</span><span class="cx">                 99C81D5A1C20E7E2005C4C82 /* AutomationClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 99C81D551C20DFBE005C4C82 /* AutomationClient.h */; };
</span><span class="cx">                 99C81D5D1C21F38B005C4C82 /* APIAutomationClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 99C81D5B1C20E817005C4C82 /* APIAutomationClient.h */; };
</span><span class="lines">@@ -3271,6 +3272,7 @@
</span><span class="cx">                 9955A6F11C79866400EB6A93 /* AutomationBackendDispatchers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AutomationBackendDispatchers.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 9955A6F21C79866400EB6A93 /* AutomationProtocolObjects.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AutomationProtocolObjects.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 9955A6F31C79866400EB6A93 /* AutomationProtocolObjects.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AutomationProtocolObjects.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                9986BDD61CA9A222004800AA /* WebAutomationSessionCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebAutomationSessionCocoa.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 99C81D551C20DFBE005C4C82 /* AutomationClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AutomationClient.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 99C81D561C20DFBE005C4C82 /* AutomationClient.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AutomationClient.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 99C81D5B1C20E817005C4C82 /* APIAutomationClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APIAutomationClient.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -4631,6 +4633,7 @@
</span><span class="cx">                                 1AFE436318B6C081009C7A48 /* UIDelegate.mm */,
</span><span class="cx">                                 E4E8648E1B1673FB00C82F40 /* VersionChecks.h */,
</span><span class="cx">                                 E4E8648F1B1673FB00C82F40 /* VersionChecks.mm */,
</span><ins>+                                9986BDD61CA9A222004800AA /* WebAutomationSessionCocoa.mm */,
</ins><span class="cx">                                 1AC0273E196622D600C12B75 /* WebPageProxyCocoa.mm */,
</span><span class="cx">                                 7C4694CB1A4B510A00AD5845 /* WebPasteboardProxyCocoa.mm */,
</span><span class="cx">                                 7CE4D2151A49148400C7F152 /* WebProcessPoolCocoa.mm */,
</span><span class="lines">@@ -9455,6 +9458,7 @@
</span><span class="cx">                                 C5E1AFEA16B20B7B006CC1F2 /* WKWebArchiveResource.cpp in Sources */,
</span><span class="cx">                                 1AA2E56618D77508003814BD /* WKWebProcessBundleParameters.mm in Sources */,
</span><span class="cx">                                 BC989D81161A7E5D000D46D3 /* WKWebProcessPlugIn.mm in Sources */,
</span><ins>+                                9986BDD71CA9A22C004800AA /* WebAutomationSessionCocoa.mm in Sources */,
</ins><span class="cx">                                 BC8F2F2A16273A2C005FACB5 /* WKWebProcessPlugInBrowserContextController.mm in Sources */,
</span><span class="cx">                                 1F7506AD1859161C00EC0FF7 /* WKWebProcessPlugInFrame.mm in Sources */,
</span><span class="cx">                                 1F7506AE1859162200EC0FF7 /* WKWebProcessPlugInHitTestResult.mm in Sources */,
</span></span></pre></div>
<a id="trunkSourceWebKit2WebKit2Prefixh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebKit2Prefix.h (198791 => 198792)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebKit2Prefix.h        2016-03-29 20:12:18 UTC (rev 198791)
+++ trunk/Source/WebKit2/WebKit2Prefix.h        2016-03-29 20:19:45 UTC (rev 198792)
</span><span class="lines">@@ -51,6 +51,7 @@
</span><span class="cx"> #import &lt;Foundation/Foundation.h&gt;
</span><span class="cx"> #if USE(APPKIT)
</span><span class="cx"> #import &lt;Cocoa/Cocoa.h&gt;
</span><ins>+#import &lt;wtf/mac/AppKitCompatibilityDeclarations.h&gt;
</ins><span class="cx"> #endif
</span><span class="cx"> #endif
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>