<!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
<rdar://problem/25227576>
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 <bburg@apple.com>
+
+ Web Automation: implement Automation.performMouseInteraction
+ https://bugs.webkit.org/show_bug.cgi?id=155606
+ <rdar://problem/25227576>
+
+ Reviewed by Timothy Hatcher.
+
+ * wtf/mac/AppKitCompatibilityDeclarations.h: Add missing some NSEventTypes.
+
</ins><span class="cx"> 2016-03-29 Yusuke Suzuki <utatane.tea@gmail.com>
</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 <bburg@apple.com>
+
+ Web Automation: implement Automation.performMouseInteraction
+ https://bugs.webkit.org/show_bug.cgi?id=155606
+ <rdar://problem/25227576>
+
+ 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 <cgarcia@igalia.com>
</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"> { "name": "windowSize", "$ref": "Size", "description": "The current size of the browsing context's window." },
</span><span class="cx"> { "name": "windowOrigin", "$ref": "Point", "description": "The current (x, y) position of the browsing context's window relative to the top-left of the screen." }
</span><span class="cx"> ]
</span><ins>+ },
+ {
+ "id": "MouseInteraction",
+ "type": "string",
+ "description": "Enumerates different ways of interacting with a mouse cursor.",
+ "enum": [
+ "Move",
+ "Down",
+ "Up",
+ "SingleClick",
+ "DoubleClick"
+ ]
+ },
+ {
+ "id": "MouseButton",
+ "type": "string",
+ "description": "Enumerates different mouse buttons that can be used.",
+ "enum": [
+ "None",
+ "Left",
+ "Middle",
+ "Right"
+ ]
+ },
+ {
+ "id": "KeyModifier",
+ "type": "string",
+ "description": "Enumerates different key modifiers that can remain pressed during other mouse/touch interactions.",
+ "enum": [
+ "CapsLock",
+ "Control",
+ "Shift",
+ "Meta",
+ "Alt"
+ ]
</ins><span class="cx"> }
</span><span class="cx"> ],
</span><span class="cx"> "commands": [
</span><span class="lines">@@ -171,6 +206,20 @@
</span><span class="cx"> "async": true
</span><span class="cx"> },
</span><span class="cx"> {
</span><ins>+ "name": "performMouseInteraction",
+ "description": "Simulates interaction with a mouse cursor.",
+ "parameters": [
+ { "name": "handle", "$ref": "BrowsingContextHandle", "description": "The browsing context to be interacted with." },
+ { "name": "position", "$ref": "Point", "description": "The requested position for the mouse cursor, specified in viewport coordinates." },
+ { "name": "button", "$ref": "MouseButton", "description": "The button to use to perform the interaction. This parameter only has an effect for the <code>Down</code>, <code>Up</code>, <code>Click</code>, and <code>DoubleClick</code> mouse interactions." },
+ { "name": "interaction", "$ref": "MouseInteraction", "description": "The type of interaction to be performed with the mouse cursor." },
+ { "name": "modifiers", "type": "array", "items": { "$ref": "KeyModifier" }, "description": "Key modifiers to be active during the mouse interaction." }
+ ],
+ "returns": [
+ { "name": "position", "$ref": "Point", "description": "The updated position of the mouse cursor, specified in viewport coordinates." }
+ ]
+ },
+ {
</ins><span class="cx"> "name": "resolveChildFrameHandle",
</span><span class="cx"> "description": "Determines the <code>FrameHandle</code> based on the ordinal, name or node handle of a child frame.",
</span><span class="cx"> "parameters": [
</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 <JavaScriptCore/InspectorFrontendRouter.h>
</span><span class="cx"> #include <WebCore/URL.h>
</span><span class="cx"> #include <WebCore/UUID.h>
</span><ins>+#include <algorithm>
</ins><span class="cx"> #include <wtf/HashMap.h>
</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->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& errorString, const String& handle, const Inspector::InspectorObject& requestedPositionObject, const String& mouseButtonString, const String& mouseInteractionString, const Inspector::InspectorArray& keyModifierStrings, RefPtr<Inspector::Protocol::Automation::Point>& updatedPositionObject)
+{
+#if !USE(APPKIT)
+ FAIL_WITH_PREDEFINED_ERROR_MESSAGE(NotImplemented);
+#else
+ WebPageProxy* page = webPageProxyForHandle(handle);
+ if (!page)
+ FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
+
+ // FIXME <rdar://problem/25094106>: 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("x"), x))
+ FAIL_WITH_PREDEFINED_ERROR_MESSAGE(MissingParameter);
+
+ float y;
+ if (!requestedPositionObject.getDouble(WTF::ASCIILiteral("y"), y))
+ FAIL_WITH_PREDEFINED_ERROR_MESSAGE(MissingParameter);
+
+ WebCore::FloatRect windowFrame;
+ page->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<int>(x), static_cast<int>(y));
+
+ auto parsedInteraction = Inspector::Protocol::parseEnumValueFromString<Inspector::Protocol::Automation::MouseInteraction>(mouseInteractionString);
+ if (!parsedInteraction)
+ FAIL_WITH_PREDEFINED_ERROR_MESSAGE(InvalidParameter);
+
+ auto parsedButton = Inspector::Protocol::parseEnumValueFromString<Inspector::Protocol::Automation::MouseButton>(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->get()->asString(modifierString))
+ FAIL_WITH_PREDEFINED_ERROR_MESSAGE(InvalidParameter);
+
+ auto parsedModifier = Inspector::Protocol::parseEnumValueFromString<Inspector::Protocol::Automation::KeyModifier>(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&, const WebCore::IntPoint&, 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 "APIObject.h"
</span><span class="cx"> #include "AutomationBackendDispatchers.h"
</span><span class="cx"> #include "Connection.h"
</span><ins>+#include "WebEvent.h"
</ins><span class="cx"> #include <wtf/Forward.h>
</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&, const String&) override;
</span><span class="cx"> void reloadBrowsingContext(Inspector::ErrorString&, const String&) override;
</span><span class="cx"> void evaluateJavaScriptFunction(Inspector::ErrorString&, const String& browsingContextHandle, const String* optionalFrameHandle, const String& function, const Inspector::InspectorArray& arguments, bool expectsImplicitCallbackArgument, Ref<Inspector::AutomationBackendDispatcherHandler::EvaluateJavaScriptFunctionCallback>&&) override;
</span><ins>+ void performMouseInteraction(Inspector::ErrorString&, const String& handle, const Inspector::InspectorObject& requestedPosition, const String& mouseButton, const String& mouseInteraction, const Inspector::InspectorArray& keyModifiers, RefPtr<Inspector::Protocol::Automation::Point>& updatedPosition) override;
</ins><span class="cx"> void resolveChildFrameHandle(Inspector::ErrorString&, const String& browsingContextHandle, const String* optionalFrameHandle, const int* optionalOrdinal, const String* optionalName, const String* optionalNodeHandle, Ref<ResolveChildFrameHandleCallback>&&) override;
</span><span class="cx"> void resolveParentFrameHandle(Inspector::ErrorString&, const String& browsingContextHandle, const String& frameHandle, Ref<ResolveParentFrameHandleCallback>&&) override;
</span><span class="cx"> void computeElementLayout(Inspector::ErrorString&, const String& browsingContextHandle, const String& frameHandle, const String& nodeHandle, const bool* optionalScrollIntoViewIfNeeded, const bool* useViewportCoordinates, Ref<Inspector::AutomationBackendDispatcherHandler::ComputeElementLayoutCallback>&&) override;
</span><span class="lines">@@ -121,6 +130,13 @@
</span><span class="cx"> void didResolveParentFrame(uint64_t callbackID, uint64_t frameID, const String& errorType);
</span><span class="cx"> void didComputeElementLayout(uint64_t callbackID, WebCore::IntRect, const String& errorType);
</span><span class="cx">
</span><ins>+ // Platform-specific helper methods.
+ void platformSimulateMouseInteraction(WebPageProxy&, const WebCore::IntPoint& viewPosition, Inspector::Protocol::Automation::MouseInteraction, Inspector::Protocol::Automation::MouseButton, WebEvent::Modifiers);
+
+#if USE(APPKIT)
+ void sendSynthesizedEventsToPage(WebPageProxy&, NSArray *eventsToSend);
+#endif
+
</ins><span class="cx"> WebProcessPool* m_processPool { nullptr };
</span><span class="cx">
</span><span class="cx"> std::unique_ptr<API::AutomationSessionClient> 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 "config.h"
+#import "WebAutomationSession.h"
+
+#import "WebPageProxy.h"
+#import "_WKAutomationSession.h"
+#import <WebCore/IntPoint.h>
+#import <WebCore/IntSize.h>
+#import <WebCore/PlatformMouseEvent.h>
+#import <objc/runtime.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+#if USE(APPKIT)
+
+void WebAutomationSession::sendSynthesizedEventsToPage(WebPageProxy& page, NSArray *eventsToSend)
+{
+ NSWindow *window = page.platformWindow();
+
+ for (NSEvent *event in eventsToSend) {
+ // FIXME: <https://www.webkit.org/b/155963> 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& page, const WebCore::IntPoint& 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 & WebEvent::MetaKey)
+ modifiers |= NSEventModifierFlagCommand;
+ if (keyModifiers & WebEvent::AltKey)
+ modifiers |= NSEventModifierFlagOption;
+ if (keyModifiers & WebEvent::ControlKey)
+ modifiers |= NSEventModifierFlagControl;
+ if (keyModifiers & 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<NSEvent *> *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 = "<group>"; };
</span><span class="cx">                 9955A6F21C79866400EB6A93 /* AutomationProtocolObjects.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AutomationProtocolObjects.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 9955A6F31C79866400EB6A93 /* AutomationProtocolObjects.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AutomationProtocolObjects.h; sourceTree = "<group>"; };
</span><ins>+                9986BDD61CA9A222004800AA /* WebAutomationSessionCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebAutomationSessionCocoa.mm; sourceTree = "<group>"; };
</ins><span class="cx">                 99C81D551C20DFBE005C4C82 /* AutomationClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AutomationClient.h; sourceTree = "<group>"; };
</span><span class="cx">                 99C81D561C20DFBE005C4C82 /* AutomationClient.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AutomationClient.mm; sourceTree = "<group>"; };
</span><span class="cx">                 99C81D5B1C20E817005C4C82 /* APIAutomationClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APIAutomationClient.h; sourceTree = "<group>"; };
</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 <Foundation/Foundation.h>
</span><span class="cx"> #if USE(APPKIT)
</span><span class="cx"> #import <Cocoa/Cocoa.h>
</span><ins>+#import <wtf/mac/AppKitCompatibilityDeclarations.h>
</ins><span class="cx"> #endif
</span><span class="cx"> #endif
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>