Title: [234543] trunk/Source/WebKit
Revision
234543
Author
carlo...@webkit.org
Date
2018-08-03 03:43:14 -0700 (Fri, 03 Aug 2018)

Log Message

[WPE] WebDriver: add support for action commands
https://bugs.webkit.org/show_bug.cgi?id=188301

Reviewed by Žan Doberšek.

WPE doesn't support action commands because the platform specific code for handling events is not implemented.

* SourcesWPE.txt: Add new file to compilation.
* UIProcess/API/glib/WebKitUIClient.cpp: Use the drawing area size as window size in WPE.
* UIProcess/API/wpe/PageClientImpl.cpp:
(WebKit::PageClientImpl::viewBackend): Return the WPE backend of the view.
* UIProcess/API/wpe/PageClientImpl.h:
* UIProcess/Automation/WebAutomationSession.cpp:
(WebKit::WebAutomationSession::performMouseInteraction):
(WebKit::WebAutomationSession::performKeyboardInteractions):
(WebKit::WebAutomationSession::performInteractionSequence):
(WebKit::WebAutomationSession::cancelInteractionSequence):
* UIProcess/Automation/wpe/WebAutomationSessionWPE.cpp: Added.
(WebKit::modifiersToEventState):
(WebKit::mouseButtonToWPEButton):
(WebKit::stateModifierForWPEButton):
(WebKit::doMouseEvent):
(WebKit::doMotionEvent):
(WebKit::WebAutomationSession::platformSimulateMouseInteraction):
(WebKit::doKeyStrokeEvent):
(WebKit::keyCodeForVirtualKey):
(WebKit::modifiersForKeyCode):
(WebKit::WebAutomationSession::platformSimulateKeyboardInteraction):
(WebKit::WebAutomationSession::platformSimulateKeySequence):
* UIProcess/WebPageProxy.h:
* UIProcess/wpe/WebPageProxyWPE.cpp:
(WebKit::WebPageProxy::viewBackend): Return the WPE backend.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (234542 => 234543)


--- trunk/Source/WebKit/ChangeLog	2018-08-03 10:07:55 UTC (rev 234542)
+++ trunk/Source/WebKit/ChangeLog	2018-08-03 10:43:14 UTC (rev 234543)
@@ -1,5 +1,40 @@
 2018-08-03  Carlos Garcia Campos  <cgar...@igalia.com>
 
+        [WPE] WebDriver: add support for action commands
+        https://bugs.webkit.org/show_bug.cgi?id=188301
+
+        Reviewed by Žan Doberšek.
+
+        WPE doesn't support action commands because the platform specific code for handling events is not implemented.
+
+        * SourcesWPE.txt: Add new file to compilation.
+        * UIProcess/API/glib/WebKitUIClient.cpp: Use the drawing area size as window size in WPE.
+        * UIProcess/API/wpe/PageClientImpl.cpp:
+        (WebKit::PageClientImpl::viewBackend): Return the WPE backend of the view.
+        * UIProcess/API/wpe/PageClientImpl.h:
+        * UIProcess/Automation/WebAutomationSession.cpp:
+        (WebKit::WebAutomationSession::performMouseInteraction):
+        (WebKit::WebAutomationSession::performKeyboardInteractions):
+        (WebKit::WebAutomationSession::performInteractionSequence):
+        (WebKit::WebAutomationSession::cancelInteractionSequence):
+        * UIProcess/Automation/wpe/WebAutomationSessionWPE.cpp: Added.
+        (WebKit::modifiersToEventState):
+        (WebKit::mouseButtonToWPEButton):
+        (WebKit::stateModifierForWPEButton):
+        (WebKit::doMouseEvent):
+        (WebKit::doMotionEvent):
+        (WebKit::WebAutomationSession::platformSimulateMouseInteraction):
+        (WebKit::doKeyStrokeEvent):
+        (WebKit::keyCodeForVirtualKey):
+        (WebKit::modifiersForKeyCode):
+        (WebKit::WebAutomationSession::platformSimulateKeyboardInteraction):
+        (WebKit::WebAutomationSession::platformSimulateKeySequence):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/wpe/WebPageProxyWPE.cpp:
+        (WebKit::WebPageProxy::viewBackend): Return the WPE backend.
+
+2018-08-03  Carlos Garcia Campos  <cgar...@igalia.com>
+
         [WPE] Implement MouseEvent.buttons
         https://bugs.webkit.org/show_bug.cgi?id=187998
 

Modified: trunk/Source/WebKit/SourcesWPE.txt (234542 => 234543)


--- trunk/Source/WebKit/SourcesWPE.txt	2018-08-03 10:07:55 UTC (rev 234542)
+++ trunk/Source/WebKit/SourcesWPE.txt	2018-08-03 10:43:14 UTC (rev 234543)
@@ -172,6 +172,8 @@
 
 UIProcess/Automation/cairo/WebAutomationSessionCairo.cpp
 
+UIProcess/Automation/wpe/WebAutomationSessionWPE.cpp
+
 UIProcess/Launcher/glib/ProcessLauncherGLib.cpp
 
 UIProcess/Network/CustomProtocols/LegacyCustomProtocolManagerProxy.cpp

Modified: trunk/Source/WebKit/UIProcess/API/glib/WebKitUIClient.cpp (234542 => 234543)


--- trunk/Source/WebKit/UIProcess/API/glib/WebKitUIClient.cpp	2018-08-03 10:07:55 UTC (rev 234542)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitUIClient.cpp	2018-08-03 10:43:14 UTC (rev 234543)
@@ -21,6 +21,7 @@
 #include "WebKitUIClient.h"
 
 #include "APIUIClient.h"
+#include "DrawingAreaProxy.h"
 #include "WebKitFileChooserRequestPrivate.h"
 #include "WebKitGeolocationPermissionRequestPrivate.h"
 #include "WebKitNavigationActionPrivate.h"
@@ -160,7 +161,11 @@
         completionHandler(WebCore::FloatRect(geometry));
 #elif PLATFORM(WPE)
         // FIXME: I guess this is actually the view size in WPE. We need more refactoring here.
-        completionHandler({ });
+        WebCore::FloatRect rect;
+        auto& page = webkitWebViewGetPage(m_webView);
+        if (page.drawingArea())
+            rect.setSize(page.drawingArea()->size());
+        completionHandler(WTFMove(rect));
 #endif
     }
 

Modified: trunk/Source/WebKit/UIProcess/API/wpe/PageClientImpl.cpp (234542 => 234543)


--- trunk/Source/WebKit/UIProcess/API/wpe/PageClientImpl.cpp	2018-08-03 10:07:55 UTC (rev 234542)
+++ trunk/Source/WebKit/UIProcess/API/wpe/PageClientImpl.cpp	2018-08-03 10:43:14 UTC (rev 234543)
@@ -46,6 +46,11 @@
 
 PageClientImpl::~PageClientImpl() = default;
 
+struct wpe_view_backend* PageClientImpl::viewBackend()
+{
+    return m_view.backend();
+}
+
 std::unique_ptr<DrawingAreaProxy> PageClientImpl::createDrawingAreaProxy()
 {
     return std::make_unique<AcceleratedDrawingAreaProxy>(m_view.page());

Modified: trunk/Source/WebKit/UIProcess/API/wpe/PageClientImpl.h (234542 => 234543)


--- trunk/Source/WebKit/UIProcess/API/wpe/PageClientImpl.h	2018-08-03 10:07:55 UTC (rev 234542)
+++ trunk/Source/WebKit/UIProcess/API/wpe/PageClientImpl.h	2018-08-03 10:43:14 UTC (rev 234543)
@@ -28,6 +28,8 @@
 #include "PageClient.h"
 #include "WebFullScreenManagerProxy.h"
 
+struct wpe_view_backend;
+
 namespace WKWPE {
 class View;
 }
@@ -47,6 +49,8 @@
     PageClientImpl(WKWPE::View&);
     virtual ~PageClientImpl();
 
+    struct wpe_view_backend* viewBackend();
+
 private:
     // PageClient
     std::unique_ptr<DrawingAreaProxy> createDrawingAreaProxy() override;

Modified: trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp (234542 => 234543)


--- trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp	2018-08-03 10:07:55 UTC (rev 234542)
+++ trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp	2018-08-03 10:43:14 UTC (rev 234543)
@@ -1496,7 +1496,7 @@
     // Wait for keyboardEventsFlushedCallback to run when all events are handled.
 }
 
-#if USE(APPKIT) || PLATFORM(GTK)
+#if USE(APPKIT) || PLATFORM(GTK) || PLATFORM(WPE)
 static WebEvent::Modifiers protocolModifierToWebEventModifier(Inspector::Protocol::Automation::KeyModifier modifier)
 {
     switch (modifier) {
@@ -1530,11 +1530,11 @@
 
     RELEASE_ASSERT_NOT_REACHED();
 }
-#endif // USE(APPKIT) || PLATFORM(GTK)
+#endif // USE(APPKIT) || PLATFORM(GTK) || PLATFORM(WPE)
 
 void WebAutomationSession::performMouseInteraction(const String& handle, const JSON::Object& requestedPositionObject, const String& mouseButtonString, const String& mouseInteractionString, const JSON::Array& keyModifierStrings, Ref<PerformMouseInteractionCallback>&& callback)
 {
-#if !USE(APPKIT) && !PLATFORM(GTK)
+#if !USE(APPKIT) && !PLATFORM(GTK) && !PLATFORM(WPE)
     ASYNC_FAIL_WITH_PREDEFINED_ERROR(NotImplemented);
 #else
     WebPageProxy* page = webPageProxyForHandle(handle);
@@ -1603,12 +1603,12 @@
             callbackToCancel(std::nullopt);
         }
     });
-#endif // USE(APPKIT) || PLATFORM(GTK)
+#endif // USE(APPKIT) || PLATFORM(GTK) || PLATFORM(WPE)
 }
 
 void WebAutomationSession::performKeyboardInteractions(const String& handle, const JSON::Array& interactions, Ref<PerformKeyboardInteractionsCallback>&& callback)
 {
-#if !PLATFORM(COCOA) && !PLATFORM(GTK)
+#if !PLATFORM(COCOA) && !PLATFORM(GTK) && !PLATFORM(WPE)
     ASYNC_FAIL_WITH_PREDEFINED_ERROR(NotImplemented);
 #else
     WebPageProxy* page = webPageProxyForHandle(handle);
@@ -1685,10 +1685,10 @@
 
     for (auto& action : actionsToPerform)
         action();
-#endif // PLATFORM(COCOA) || PLATFORM(GTK)
+#endif // PLATFORM(COCOA) || PLATFORM(GTK) || PLATFORM(WPE)
 }
 
-#if USE(APPKIT) || PLATFORM(GTK)
+#if USE(APPKIT) || PLATFORM(GTK) || PLATFORM(WPE)
 static SimulatedInputSourceType simulatedInputSourceTypeFromProtocolSourceType(Inspector::Protocol::Automation::InputSourceType protocolType)
 {
     switch (protocolType) {
@@ -1704,13 +1704,13 @@
 
     RELEASE_ASSERT_NOT_REACHED();
 }
-#endif // USE(APPKIT) || PLATFORM(GTK)
+#endif // USE(APPKIT) || PLATFORM(GTK) || PLATFORM(WPE)
 
 void WebAutomationSession::performInteractionSequence(const String& handle, const String* optionalFrameHandle, const JSON::Array& inputSources, const JSON::Array& steps, Ref<WebAutomationSession::PerformInteractionSequenceCallback>&& callback)
 {
     // This command implements WebKit support for §17.5 Perform Actions.
 
-#if !USE(APPKIT) && !PLATFORM(GTK)
+#if !USE(APPKIT) && !PLATFORM(GTK) && !PLATFORM(WPE)
     ASYNC_FAIL_WITH_PREDEFINED_ERROR(NotImplemented);
 #else
     WebPageProxy* page = webPageProxyForHandle(handle);
@@ -1861,7 +1861,7 @@
         else
             callback->sendSuccess();
     });
-#endif // PLATFORM(COCOA) || PLATFORM(GTK)
+#endif // PLATFORM(COCOA) || PLATFORM(GTK) || PLATFORM(WPE)
 }
 
 void WebAutomationSession::cancelInteractionSequence(const String& handle, const String* optionalFrameHandle, Ref<CancelInteractionSequenceCallback>&& callback)
@@ -1868,7 +1868,7 @@
 {
     // This command implements WebKit support for §17.6 Release Actions.
 
-#if !USE(APPKIT) && !PLATFORM(GTK)
+#if !USE(APPKIT) && !PLATFORM(GTK) && !PLATFORM(WPE)
     ASYNC_FAIL_WITH_PREDEFINED_ERROR(NotImplemented);
 #else
     WebPageProxy* page = webPageProxyForHandle(handle);
@@ -1889,7 +1889,7 @@
         else
             callback->sendSuccess();
     });
-#endif // PLATFORM(COCOA) || PLATFORM(GTK)
+#endif // PLATFORM(COCOA) || PLATFORM(GTK) || PLATFORM(WPE)
 }
 
 void WebAutomationSession::takeScreenshot(const String& handle, const String* optionalFrameHandle, const String* optionalNodeHandle, const bool* optionalScrollIntoViewIfNeeded, const bool* optionalClipToViewport, Ref<TakeScreenshotCallback>&& callback)
@@ -1932,19 +1932,19 @@
 
 // Platform-dependent Implementation Stubs.
 
-#if !PLATFORM(MAC) && !PLATFORM(GTK)
+#if !PLATFORM(MAC) && !PLATFORM(GTK) && !PLATFORM(WPE)
 void WebAutomationSession::platformSimulateMouseInteraction(WebPageProxy&, MouseInteraction, WebMouseEvent::Button, const WebCore::IntPoint&, WebEvent::Modifiers)
 {
 }
-#endif // !PLATFORM(MAC) && !PLATFORM(GTK)
+#endif // !PLATFORM(MAC) && !PLATFORM(GTK) && !PLATFORM(WPE)
 
-#if !PLATFORM(COCOA) && !PLATFORM(GTK)
+#if !PLATFORM(COCOA) && !PLATFORM(GTK) && !PLATFORM(WPE)
 
 
 void WebAutomationSession::platformSimulateKeyboardInteraction(WebPageProxy&, KeyboardInteraction, WTF::Variant<VirtualKey, CharKey>&&)
 {
 }
-#endif // !PLATFORM(COCOA) && !PLATFORM(GTK)
+#endif // !PLATFORM(COCOA) && !PLATFORM(GTK) && !PLATFORM(WPE)
 
 #if !PLATFORM(COCOA) && !USE(CAIRO)
 std::optional<String> WebAutomationSession::platformGetBase64EncodedPNGData(const ShareableBitmap::Handle&)

Added: trunk/Source/WebKit/UIProcess/Automation/wpe/WebAutomationSessionWPE.cpp (0 => 234543)


--- trunk/Source/WebKit/UIProcess/Automation/wpe/WebAutomationSessionWPE.cpp	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/Automation/wpe/WebAutomationSessionWPE.cpp	2018-08-03 10:43:14 UTC (rev 234543)
@@ -0,0 +1,316 @@
+/*
+ * Copyright (C) 2018 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebAutomationSession.h"
+
+#include "WebAutomationSessionMacros.h"
+#include "WebPageProxy.h"
+
+namespace WebKit {
+using namespace WebCore;
+
+static uint32_t modifiersToEventState(WebEvent::Modifiers modifiers)
+{
+    uint32_t state = 0;
+
+    if (modifiers & WebEvent::ControlKey)
+        state |= wpe_input_keyboard_modifier_control;
+    if (modifiers & WebEvent::ShiftKey)
+        state |= wpe_input_keyboard_modifier_shift;
+    if (modifiers & WebEvent::AltKey)
+        state |= wpe_input_keyboard_modifier_alt;
+
+    return state;
+}
+
+static unsigned mouseButtonToWPEButton(WebMouseEvent::Button button)
+{
+    switch (button) {
+    case WebMouseEvent::NoButton:
+    case WebMouseEvent::LeftButton:
+        return 1;
+    case WebMouseEvent::MiddleButton:
+        return 3;
+    case WebMouseEvent::RightButton:
+        return 2;
+    }
+    return 1;
+}
+
+static unsigned stateModifierForWPEButton(unsigned button)
+{
+    uint32_t state = 0;
+
+    switch (button) {
+    case 1:
+        state |= wpe_input_pointer_modifier_button1;
+        break;
+    case 2:
+        state |= wpe_input_pointer_modifier_button2;
+        break;
+    case 3:
+        state |= wpe_input_pointer_modifier_button3;
+        break;
+    default:
+        break;
+    }
+
+    return state;
+}
+
+static void doMouseEvent(struct wpe_view_backend* viewBackend, const WebCore::IntPoint& location, unsigned button, unsigned state, uint32_t modifiers)
+{
+    struct wpe_input_pointer_event event { wpe_input_pointer_event_type_button, 0, location.x(), location.y(), button, static_cast<uint32_t>(state ? 1 : 0), modifiers };
+    wpe_view_backend_dispatch_pointer_event(viewBackend, &event);
+}
+
+static void doMotionEvent(struct wpe_view_backend* viewBackend, const WebCore::IntPoint& location, uint32_t modifiers)
+{
+    struct wpe_input_pointer_event event { wpe_input_pointer_event_type_motion, 0, location.x(), location.y(), 0, 0, modifiers };
+    wpe_view_backend_dispatch_pointer_event(viewBackend, &event);
+}
+
+void WebAutomationSession::platformSimulateMouseInteraction(WebPageProxy& page, MouseInteraction interaction, WebMouseEvent::Button button, const WebCore::IntPoint& locationInView, WebEvent::Modifiers keyModifiers)
+{
+    unsigned wpeButton = mouseButtonToWPEButton(button);
+    auto modifier = stateModifierForWPEButton(wpeButton);
+    uint32_t state = modifiersToEventState(keyModifiers) | m_currentModifiers;
+
+    switch (interaction) {
+    case MouseInteraction::Move:
+        doMotionEvent(page.viewBackend(), locationInView, state);
+        break;
+    case MouseInteraction::Down:
+        m_currentModifiers |= modifier;
+        doMouseEvent(page.viewBackend(), locationInView, wpeButton, 1, state | modifier);
+        break;
+    case MouseInteraction::Up:
+        m_currentModifiers &= ~modifier;
+        doMouseEvent(page.viewBackend(), locationInView, wpeButton, 0, state & ~modifier);
+        break;
+    case MouseInteraction::SingleClick:
+        doMouseEvent(page.viewBackend(), locationInView, wpeButton, 1, state | modifier);
+        doMouseEvent(page.viewBackend(), locationInView, wpeButton, 0, state);
+        break;
+    case MouseInteraction::DoubleClick:
+        doMouseEvent(page.viewBackend(), locationInView, wpeButton, 1, state | modifier);
+        doMouseEvent(page.viewBackend(), locationInView, wpeButton, 0, state);
+        doMouseEvent(page.viewBackend(), locationInView, wpeButton, 1, state | modifier);
+        doMouseEvent(page.viewBackend(), locationInView, wpeButton, 0, state);
+        break;
+    }
+}
+
+static void doKeyStrokeEvent(struct wpe_view_backend* viewBackend, bool pressed, uint32_t keyCode, uint32_t modifiers, bool doReleaseAfterPress = false)
+{
+    struct wpe_input_xkb_keymap_entry* entries;
+    uint32_t entriesCount;
+    wpe_input_xkb_context_get_entries_for_key_code(wpe_input_xkb_context_get_default(), keyCode, &entries, &entriesCount);
+    struct wpe_input_keyboard_event event = { 0, keyCode, entriesCount ? entries[0].hardware_key_code : 0, pressed, modifiers };
+    wpe_view_backend_dispatch_keyboard_event(viewBackend, &event);
+    free(entries);
+
+    if (doReleaseAfterPress) {
+        ASSERT(pressed);
+        event.pressed = false;
+        wpe_view_backend_dispatch_keyboard_event(viewBackend, &event);
+    }
+}
+
+static uint32_t keyCodeForVirtualKey(Inspector::Protocol::Automation::VirtualKey key)
+{
+    switch (key) {
+    case Inspector::Protocol::Automation::VirtualKey::Shift:
+        return WPE_KEY_Shift_R;
+    case Inspector::Protocol::Automation::VirtualKey::Control:
+        return WPE_KEY_Control_R;
+    case Inspector::Protocol::Automation::VirtualKey::Alternate:
+        return WPE_KEY_Alt_L;
+    case Inspector::Protocol::Automation::VirtualKey::Meta:
+        return WPE_KEY_Meta_R;
+    case Inspector::Protocol::Automation::VirtualKey::Command:
+        return WPE_KEY_Execute;
+    case Inspector::Protocol::Automation::VirtualKey::Help:
+        return WPE_KEY_Help;
+    case Inspector::Protocol::Automation::VirtualKey::Backspace:
+        return WPE_KEY_BackSpace;
+    case Inspector::Protocol::Automation::VirtualKey::Tab:
+        return WPE_KEY_Tab;
+    case Inspector::Protocol::Automation::VirtualKey::Clear:
+        return WPE_KEY_Clear;
+    case Inspector::Protocol::Automation::VirtualKey::Enter:
+        return WPE_KEY_Return;
+    case Inspector::Protocol::Automation::VirtualKey::Pause:
+        return WPE_KEY_Pause;
+    case Inspector::Protocol::Automation::VirtualKey::Cancel:
+        return WPE_KEY_Cancel;
+    case Inspector::Protocol::Automation::VirtualKey::Escape:
+        return WPE_KEY_Escape;
+    case Inspector::Protocol::Automation::VirtualKey::PageUp:
+        return WPE_KEY_Page_Up;
+    case Inspector::Protocol::Automation::VirtualKey::PageDown:
+        return WPE_KEY_Page_Down;
+    case Inspector::Protocol::Automation::VirtualKey::End:
+        return WPE_KEY_End;
+    case Inspector::Protocol::Automation::VirtualKey::Home:
+        return WPE_KEY_Home;
+    case Inspector::Protocol::Automation::VirtualKey::LeftArrow:
+        return WPE_KEY_Left;
+    case Inspector::Protocol::Automation::VirtualKey::UpArrow:
+        return WPE_KEY_Up;
+    case Inspector::Protocol::Automation::VirtualKey::RightArrow:
+        return WPE_KEY_Right;
+    case Inspector::Protocol::Automation::VirtualKey::DownArrow:
+        return WPE_KEY_Down;
+    case Inspector::Protocol::Automation::VirtualKey::Insert:
+        return WPE_KEY_Insert;
+    case Inspector::Protocol::Automation::VirtualKey::Delete:
+        return WPE_KEY_Delete;
+    case Inspector::Protocol::Automation::VirtualKey::Space:
+        return WPE_KEY_space;
+    case Inspector::Protocol::Automation::VirtualKey::Semicolon:
+        return WPE_KEY_semicolon;
+    case Inspector::Protocol::Automation::VirtualKey::Equals:
+        return WPE_KEY_equal;
+    case Inspector::Protocol::Automation::VirtualKey::Return:
+        return WPE_KEY_Return;
+    case Inspector::Protocol::Automation::VirtualKey::NumberPad0:
+        return WPE_KEY_KP_0;
+    case Inspector::Protocol::Automation::VirtualKey::NumberPad1:
+        return WPE_KEY_KP_1;
+    case Inspector::Protocol::Automation::VirtualKey::NumberPad2:
+        return WPE_KEY_KP_2;
+    case Inspector::Protocol::Automation::VirtualKey::NumberPad3:
+        return WPE_KEY_KP_3;
+    case Inspector::Protocol::Automation::VirtualKey::NumberPad4:
+        return WPE_KEY_KP_4;
+    case Inspector::Protocol::Automation::VirtualKey::NumberPad5:
+        return WPE_KEY_KP_5;
+    case Inspector::Protocol::Automation::VirtualKey::NumberPad6:
+        return WPE_KEY_KP_6;
+    case Inspector::Protocol::Automation::VirtualKey::NumberPad7:
+        return WPE_KEY_KP_7;
+    case Inspector::Protocol::Automation::VirtualKey::NumberPad8:
+        return WPE_KEY_KP_8;
+    case Inspector::Protocol::Automation::VirtualKey::NumberPad9:
+        return WPE_KEY_KP_9;
+    case Inspector::Protocol::Automation::VirtualKey::NumberPadMultiply:
+        return WPE_KEY_KP_Multiply;
+    case Inspector::Protocol::Automation::VirtualKey::NumberPadAdd:
+        return WPE_KEY_KP_Add;
+    case Inspector::Protocol::Automation::VirtualKey::NumberPadSubtract:
+        return WPE_KEY_KP_Subtract;
+    case Inspector::Protocol::Automation::VirtualKey::NumberPadSeparator:
+        return WPE_KEY_KP_Separator;
+    case Inspector::Protocol::Automation::VirtualKey::NumberPadDecimal:
+        return WPE_KEY_KP_Decimal;
+    case Inspector::Protocol::Automation::VirtualKey::NumberPadDivide:
+        return WPE_KEY_KP_Divide;
+    case Inspector::Protocol::Automation::VirtualKey::Function1:
+        return WPE_KEY_F1;
+    case Inspector::Protocol::Automation::VirtualKey::Function2:
+        return WPE_KEY_F2;
+    case Inspector::Protocol::Automation::VirtualKey::Function3:
+        return WPE_KEY_F3;
+    case Inspector::Protocol::Automation::VirtualKey::Function4:
+        return WPE_KEY_F4;
+    case Inspector::Protocol::Automation::VirtualKey::Function5:
+        return WPE_KEY_F5;
+    case Inspector::Protocol::Automation::VirtualKey::Function6:
+        return WPE_KEY_F6;
+    case Inspector::Protocol::Automation::VirtualKey::Function7:
+        return WPE_KEY_F7;
+    case Inspector::Protocol::Automation::VirtualKey::Function8:
+        return WPE_KEY_F8;
+    case Inspector::Protocol::Automation::VirtualKey::Function9:
+        return WPE_KEY_F9;
+    case Inspector::Protocol::Automation::VirtualKey::Function10:
+        return WPE_KEY_F10;
+    case Inspector::Protocol::Automation::VirtualKey::Function11:
+        return WPE_KEY_F11;
+    case Inspector::Protocol::Automation::VirtualKey::Function12:
+        return WPE_KEY_F12;
+    }
+
+    ASSERT_NOT_REACHED();
+    return 0;
+}
+
+static uint32_t modifiersForKeyCode(unsigned keyCode)
+{
+    switch (keyCode) {
+    case WPE_KEY_Shift_R:
+        return wpe_input_keyboard_modifier_shift;
+    case WPE_KEY_Control_R:
+        return wpe_input_keyboard_modifier_control;
+    case WPE_KEY_Alt_L:
+        return wpe_input_keyboard_modifier_alt;
+    case WPE_KEY_Meta_R:
+        return wpe_input_keyboard_modifier_meta;
+    }
+    return 0;
+}
+
+void WebAutomationSession::platformSimulateKeyboardInteraction(WebPageProxy& page, KeyboardInteraction interaction, WTF::Variant<VirtualKey, CharKey>&& key)
+{
+    uint32_t keyCode;
+    WTF::switchOn(key,
+        [&] (VirtualKey virtualKey) {
+            keyCode = keyCodeForVirtualKey(virtualKey);
+        },
+        [&] (CharKey charKey) {
+            keyCode = wpe_unicode_to_key_code(g_utf8_get_char(&charKey));
+        }
+    );
+    uint32_t modifiers = modifiersForKeyCode(keyCode);
+
+    switch (interaction) {
+    case KeyboardInteraction::KeyPress:
+        m_currentModifiers |= modifiers;
+        doKeyStrokeEvent(page.viewBackend(), true, keyCode, m_currentModifiers);
+        break;
+    case KeyboardInteraction::KeyRelease:
+        m_currentModifiers &= ~modifiers;
+        doKeyStrokeEvent(page.viewBackend(), false, keyCode, m_currentModifiers);
+        break;
+    case KeyboardInteraction::InsertByKey:
+        doKeyStrokeEvent(page.viewBackend(), true, keyCode, m_currentModifiers, true);
+        break;
+    }
+}
+
+void WebAutomationSession::platformSimulateKeySequence(WebPageProxy& page, const String& keySequence)
+{
+    CString keySequenceUTF8 = keySequence.utf8();
+    const char* p = keySequenceUTF8.data();
+    do {
+        doKeyStrokeEvent(page.viewBackend(), true, wpe_unicode_to_key_code(g_utf8_get_char(p)), m_currentModifiers, true);
+        p = g_utf8_next_char(p);
+    } while (*p);
+}
+
+} // namespace WebKit
+

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (234542 => 234543)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2018-08-03 10:07:55 UTC (rev 234542)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2018-08-03 10:43:14 UTC (rev 234543)
@@ -205,6 +205,10 @@
 typedef GtkWidget* PlatformWidget;
 #endif
 
+#if PLATFORM(WPE)
+struct wpe_view_backend;
+#endif
+
 #if PLATFORM(GTK) || PLATFORM(WPE)
 typedef struct OpaqueJSContext* JSGlobalContextRef;
 #endif
@@ -711,6 +715,9 @@
 #if PLATFORM(WIN)
     PlatformWidget viewWidget();
 #endif
+#if PLATFORM(WPE)
+    struct wpe_view_backend* viewBackend();
+#endif
 
     bool isProcessingMouseEvents() const;
     void processNextQueuedMouseEvent();

Modified: trunk/Source/WebKit/UIProcess/wpe/WebPageProxyWPE.cpp (234542 => 234543)


--- trunk/Source/WebKit/UIProcess/wpe/WebPageProxyWPE.cpp	2018-08-03 10:07:55 UTC (rev 234542)
+++ trunk/Source/WebKit/UIProcess/wpe/WebPageProxyWPE.cpp	2018-08-03 10:43:14 UTC (rev 234543)
@@ -38,6 +38,11 @@
     notImplemented();
 }
 
+struct wpe_view_backend* WebPageProxy::viewBackend()
+{
+    return static_cast<PageClientImpl&>(m_pageClient).viewBackend();
+}
+
 String WebPageProxy::standardUserAgent(const String& applicationNameForUserAgent)
 {
     return WebCore::standardUserAgent(applicationNameForUserAgent);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to