[Webkit-unassigned] [Bug 137116] [GTK] Add selection-changed signal to the WebKit2 API

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Thu Dec 11 03:54:07 PST 2014


https://bugs.webkit.org/show_bug.cgi?id=137116

Carlos Garcia Campos <cgarcia at igalia.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
 Attachment #242949|review?, commit-queue?      |review-, commit-queue-
              Flags|                            |

--- Comment #8 from Carlos Garcia Campos <cgarcia at igalia.com> ---
Comment on attachment 242949
  --> https://bugs.webkit.org/attachment.cgi?id=242949
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=242949&action=review

> Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp:420
> +    WKBundlePageEditorClientV0 editorClient = {
> +        {
> +            0, // version
> +            page, // clientInfo
> +        },
> +        0, // shouldBeginEditing
> +        0, // shouldEndEditing
> +        0, // shouldInsertNode
> +        0, // shouldInsertText
> +        0, // shouldDeleteRange
> +        0, // shouldChangeSelectedRange
> +        0, // shouldApplyStyle
> +        0, // didBeginEditing
> +        0, // didEndEditing
> +        0, // didChange
> +        didChangeSelection
> +    };
> +    WKBundlePageSetEditorClient(toAPI(webPage), &editorClient.base);

I wonder if it would be better to expose this as a WebKitWebEditor, and add the signals there, just in case we end up needing more of those calbacks exposed. The user would do webkit_web_page_get_editor, and connect to the signals there.

> Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebExtensions.cpp:100
> +    GUniquePtr<char> extensionBusName(g_strdup_printf("org.webkit.gtk.WebExtensionTest%u", Test::s_webExtensionID));
> +    GRefPtr<GDBusProxy> proxy = adoptGRef(bus->createProxy(extensionBusName.get(),
> +        "/org/webkit/gtk/WebExtensionTest", "org.webkit.gtk.WebExtensionTest", test->m_mainLoop));
> +    GDBusConnection* connection = g_dbus_proxy_get_connection(proxy.get());
> +    guint id = g_dbus_connection_signal_subscribe(connection,
> +        0,
> +        "org.webkit.gtk.WebExtensionTest",
> +        "SelectionChanged",
> +        "/org/webkit/gtk/WebExtensionTest",
> +        0,
> +        G_DBUS_SIGNAL_FLAGS_NONE,
> +        reinterpret_cast<GDBusSignalCallback>(selectionChangedCallback),
> +        test,
> +        0);
> +    g_assert(id);

We can avoid all this now by using user script messages.

> Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebExtensions.cpp:107
> +    test->loadHtml("<html><body>All work and no play make Jack a dull boy.</body></html>", 0);
> +    test->waitUntilLoadFinished();
> +
> +    webkit_web_view_execute_editing_command(test->m_webView, WEBKIT_EDITING_COMMAND_SELECT_ALL);
> +
> +    g_main_loop_run(test->m_mainLoop);

We could also tests that the signal is emitted again after clearing the selection, for example.

> Tools/TestWebKitAPI/Tests/WebKit2Gtk/WebExtensionTest.cpp:147
> +    // FIXME: Too much code just to send a message, we need convenient custom API for this.
> +    WebKitDOMDocument* document = webkit_web_page_get_dom_document(webPage);
> +    WebKitDOMDOMWindow* window = webkit_dom_document_get_default_view(document);
> +    if (WebKitDOMWebKitNamespace* webkit = webkit_dom_dom_window_get_webkit_namespace(window)) {
> +        WebKitDOMUserMessageHandlersNamespace* messageHandlers = webkit_dom_webkit_namespace_get_message_handlers(webkit);
> +        if (WebKitDOMUserMessageHandler* handler = webkit_dom_user_message_handlers_namespace_get_handler(messageHandlers, "dom"))
> +            webkit_dom_user_message_handler_post_message(handler, "SelectionChanged");
> +    }
> +
> +    webkit_dom_dom_window_webkit_message_handlers_post_message(window, "dom-convenience", "SelectionChanged");

So, you are indeed using user script messages, but not connecting to the signal. I guess you copy-pasted. So, we now have the convenient api, so you could simply call webkit_dom_dom_window_webkit_message_handlers_post_message() with "editor" as message handler name. In the UI process part of the test, instead of doing all the dbus proxy, you can simply connect to "script-message-received::editor" of WebKitUserContentManager. With that we don't need the the dbus signal at all, and everything is simpler.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20141211/1d16ea6f/attachment-0002.html>


More information about the webkit-unassigned mailing list