Title: [187024] trunk
Revision
187024
Author
commit-qu...@webkit.org
Date
2015-07-20 10:42:01 -0700 (Mon, 20 Jul 2015)

Log Message

[GTK] Add selection-changed signal to the WebKit2 API
https://bugs.webkit.org/show_bug.cgi?id=137116

Patch by Tomas Popela <tpop...@redhat.com> on 2015-07-20
Reviewed by Carlos Garcia Campos.

Source/WebKit2:

Add a new object WebKitWebEditor where the editing capabilities of a
WebPage will be grouped and exposed. Add the selection-changed signal
there (we used the same name as in WK1 API).

* PlatformGTK.cmake:
* UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt:
* WebProcess/InjectedBundle/API/gtk/WebKitWebEditor.cpp: Added.
(didChangeSelection):
(webkitWebEditorCreate):
(webkit_web_editor_get_page):
* WebProcess/InjectedBundle/API/gtk/WebKitWebEditor.h: Added.
* WebProcess/InjectedBundle/API/gtk/WebKitWebEditorPrivate.h: Added.
* WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp:
(webkitWebPageGetPage):
(webkit_web_page_get_editor):
* WebProcess/InjectedBundle/API/gtk/WebKitWebPage.h:
* WebProcess/InjectedBundle/API/gtk/WebKitWebPagePrivate.h:
* WebProcess/InjectedBundle/API/gtk/webkit-web-extension.h:

Tools:

Add a new WebProcess test TestEditor that is testing the WebKitWebEditor
(namely the selection-changed signal).

* TestWebKitAPI/Tests/WebKit2Gtk/CMakeLists.txt:
* TestWebKitAPI/Tests/WebKit2Gtk/EditorTest.cpp: Added.
(WebKitWebEditorTest::create):
(WebKitWebEditorTest::selectionChangedCallback):
(WebKitWebEditorTest::testSelectionSelectAll):
(WebKitWebEditorTest::testSelectionCollapse):
(WebKitWebEditorTest::testSelectionModifyMove):
(WebKitWebEditorTest::testSelectionModifyExtend):
(WebKitWebEditorTest::testSelectionUnselect):
(registerTests):
* TestWebKitAPI/Tests/WebKit2Gtk/TestEditor.cpp: Added.
(testWebKitWebEditorSelectionChanged):
(beforeAll):
(afterAll):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (187023 => 187024)


--- trunk/Source/WebKit2/ChangeLog	2015-07-20 17:08:10 UTC (rev 187023)
+++ trunk/Source/WebKit2/ChangeLog	2015-07-20 17:42:01 UTC (rev 187024)
@@ -1,3 +1,29 @@
+2015-07-20  Tomas Popela  <tpop...@redhat.com>
+
+        [GTK] Add selection-changed signal to the WebKit2 API
+        https://bugs.webkit.org/show_bug.cgi?id=137116
+
+        Reviewed by Carlos Garcia Campos.
+
+        Add a new object WebKitWebEditor where the editing capabilities of a
+        WebPage will be grouped and exposed. Add the selection-changed signal
+        there (we used the same name as in WK1 API).
+
+        * PlatformGTK.cmake:
+        * UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt:
+        * WebProcess/InjectedBundle/API/gtk/WebKitWebEditor.cpp: Added.
+        (didChangeSelection):
+        (webkitWebEditorCreate):
+        (webkit_web_editor_get_page):
+        * WebProcess/InjectedBundle/API/gtk/WebKitWebEditor.h: Added.
+        * WebProcess/InjectedBundle/API/gtk/WebKitWebEditorPrivate.h: Added.
+        * WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp:
+        (webkitWebPageGetPage):
+        (webkit_web_page_get_editor):
+        * WebProcess/InjectedBundle/API/gtk/WebKitWebPage.h:
+        * WebProcess/InjectedBundle/API/gtk/WebKitWebPagePrivate.h:
+        * WebProcess/InjectedBundle/API/gtk/webkit-web-extension.h:
+
 2015-07-16  Anders Carlsson  <ander...@apple.com>
 
         WebsiteDataStore operations need to grab background assertions

Modified: trunk/Source/WebKit2/PlatformGTK.cmake (187023 => 187024)


--- trunk/Source/WebKit2/PlatformGTK.cmake	2015-07-20 17:08:10 UTC (rev 187023)
+++ trunk/Source/WebKit2/PlatformGTK.cmake	2015-07-20 17:42:01 UTC (rev 187024)
@@ -314,6 +314,7 @@
 
     WebProcess/InjectedBundle/API/gtk/WebKitFrame.cpp
     WebProcess/InjectedBundle/API/gtk/WebKitScriptWorld.cpp
+    WebProcess/InjectedBundle/API/gtk/WebKitWebEditor.cpp
     WebProcess/InjectedBundle/API/gtk/WebKitWebExtension.cpp
     WebProcess/InjectedBundle/API/gtk/WebKitWebHitTestResult.cpp
     WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp
@@ -418,6 +419,7 @@
 set(WebKit2WebExtension_INSTALLED_HEADERS
     ${WEBKIT2_DIR}/WebProcess/InjectedBundle/API/gtk/WebKitFrame.h
     ${WEBKIT2_DIR}/WebProcess/InjectedBundle/API/gtk/WebKitScriptWorld.h
+    ${WEBKIT2_DIR}/WebProcess/InjectedBundle/API/gtk/WebKitWebEditor.h
     ${WEBKIT2_DIR}/WebProcess/InjectedBundle/API/gtk/WebKitWebExtension.h
     ${WEBKIT2_DIR}/WebProcess/InjectedBundle/API/gtk/WebKitWebHitTestResult.h
     ${WEBKIT2_DIR}/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.h

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt (187023 => 187024)


--- trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt	2015-07-20 17:08:10 UTC (rev 187023)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt	2015-07-20 17:42:01 UTC (rev 187024)
@@ -1202,6 +1202,7 @@
 webkit_web_page_get_id
 webkit_web_page_get_uri
 webkit_web_page_get_main_frame
+webkit_web_page_get_editor
 
 <SUBSECTION Standard>
 WebKitWebPageClass
@@ -1218,6 +1219,25 @@
 </SECTION>
 
 <SECTION>
+<FILE>WebKitWebEditor</FILE>
+WebKitWebEditor
+webkit_web_editor_get_page
+
+<SUBSECTION Standard>
+WebKitWebEditorClass
+WEBKIT_TYPE_WEB_EDITOR
+WEBKIT_WEB_EDITOR
+WEBKIT_IS_WEB_EDITOR
+WEBKIT_WEB_EDITOR_CLASS
+WEBKIT_IS_WEB_EDITOR_CLASS
+WEBKIT_WEB_EDITOR_GET_CLASS
+
+<SUBSECTION Private>
+WebKitWebEditorPrivate
+webkit_web_editor_get_type
+</SECTION>
+
+<SECTION>
 <FILE>WebKitFrame</FILE>
 WebKitFrame
 webkit_frame_is_main_frame

Added: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebEditor.cpp (0 => 187024)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebEditor.cpp	                        (rev 0)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebEditor.cpp	2015-07-20 17:42:01 UTC (rev 187024)
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2015 Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2,1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "WebKitWebEditor.h"
+
+#include "WebKitPrivate.h"
+#include "WebKitWebEditorPrivate.h"
+#include "WebKitWebPagePrivate.h"
+#include "WKBundleAPICast.h"
+
+using namespace WebKit;
+using namespace WebCore;
+
+/**
+ * SECTION: WebKitWebEditor
+ * @Short_description: Access to editing capabilities of a #WebKitWebPage
+ * @Title: WebKitWebEditor
+ * @See_also: #WebKitWebPage
+ *
+ * The WebKitWebEditor provides access to various editing capabilities of
+ * a #WebKitWebPage such as a possibility to react to the current selection in
+ * #WebKitWebPage.
+ *
+ * Since: 2.10
+ */
+enum {
+    SELECTION_CHANGED,
+
+    LAST_SIGNAL
+};
+
+struct _WebKitWebEditorPrivate {
+    WebKitWebPage* webPage;
+};
+
+static guint signals[LAST_SIGNAL] = { 0, };
+
+WEBKIT_DEFINE_TYPE(WebKitWebEditor, webkit_web_editor, G_TYPE_OBJECT)
+
+static void webkit_web_editor_class_init(WebKitWebEditorClass* klass)
+{
+    /**
+     * WebKitWebEditor::selection-changed:
+     * @editor: the #WebKitWebEditor on which the signal is emitted
+     *
+     * This signal is emitted for every selection change inside a #WebKitWebPage
+     * as well as for every caret position change as the caret is a collapsed
+     * selection.
+     *
+     * Since: 2.10
+     */
+    signals[SELECTION_CHANGED] = g_signal_new(
+        "selection-changed",
+        G_TYPE_FROM_CLASS(klass),
+        G_SIGNAL_RUN_LAST,
+        0, nullptr, nullptr,
+        g_cclosure_marshal_VOID__VOID,
+        G_TYPE_NONE, 0);
+}
+
+static void didChangeSelection(WKBundlePageRef, WKStringRef /* notificationName */, const void* clientInfo)
+{
+    g_signal_emit(WEBKIT_WEB_EDITOR(clientInfo), signals[SELECTION_CHANGED], 0);
+}
+
+WebKitWebEditor* webkitWebEditorCreate(WebKitWebPage* webPage)
+{
+    WebKitWebEditor* editor = WEBKIT_WEB_EDITOR(g_object_new(WEBKIT_TYPE_WEB_EDITOR, nullptr));
+    editor->priv->webPage = webPage;
+
+    WKBundlePageEditorClientV0 editorClient = {
+        {
+            0, // version
+            editor, // clientInfo
+        },
+        nullptr, // shouldBeginEditing
+        nullptr, // shouldEndEditing
+        nullptr, // shouldInsertNode
+        nullptr, // shouldInsertText
+        nullptr, // shouldDeleteRange
+        nullptr, // shouldChangeSelectedRange
+        nullptr, // shouldApplyStyle
+        nullptr, // didBeginEditing
+        nullptr, // didEndEditing
+        nullptr, // didChange
+        didChangeSelection
+    };
+    WKBundlePageSetEditorClient(toAPI(webkitWebPageGetPage(webPage)), &editorClient.base);
+
+    return editor;
+}
+
+/**
+ * webkit_web_editor_get_page:
+ * @editor: a #WebKitWebEditor
+ *
+ * Gets the #WebKitWebPage that is associated with the #WebKitWebEditor that can
+ * be used to access the #WebKitDOMDocument currently loaded into it.
+ *
+ * Returns: (transfer none): the associated #WebKitWebPage
+ *
+ * Since: 2.10
+ */
+WebKitWebPage* webkit_web_editor_get_page(WebKitWebEditor* editor)
+{
+    return editor->priv->webPage;
+}

Added: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebEditor.h (0 => 187024)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebEditor.h	                        (rev 0)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebEditor.h	2015-07-20 17:42:01 UTC (rev 187024)
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2015 Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2,1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#if !defined(__WEBKIT_WEB_EXTENSION_H_INSIDE__) && !defined(WEBKIT2_COMPILATION)
+#error "Only <webkit2/webkit-web-extension.h> can be included directly."
+#endif
+
+#ifndef WebKitWebEditor_h
+#define WebKitWebEditor_h
+
+#include <glib-object.h>
+#include <webkit2/WebKitDefines.h>
+#include <webkit2/WebKitWebPage.h>
+
+G_BEGIN_DECLS
+
+#define WEBKIT_TYPE_WEB_EDITOR               (webkit_web_editor_get_type())
+#define WEBKIT_WEB_EDITOR(obj)               (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_WEB_EDITOR, WebKitWebEditor))
+#define WEBKIT_IS_WEB_EDITOR(obj)            (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_WEB_EDITOR))
+#define WEBKIT_WEB_EDITOR_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST((klass),  WEBKIT_TYPE_WEB_EDITOR, WebKitWebEditorClass))
+#define WEBKIT_IS_WEB_EDITOR_CLASS(klass)    (G_TYPE_CHECK_CLASS_TYPE((klass),  WEBKIT_TYPE_WEB_EDITOR))
+#define WEBKIT_WEB_EDITOR_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS((obj),  WEBKIT_TYPE_WEB_EDITOR, WebKitWebEditorClass))
+
+typedef struct _WebKitWebEditor        WebKitWebEditor;
+typedef struct _WebKitWebEditorClass   WebKitWebEditorClass;
+typedef struct _WebKitWebEditorPrivate WebKitWebEditorPrivate;
+
+/* Forward declarations */
+typedef struct _WebKitWebPage          WebKitWebPage;
+
+struct _WebKitWebEditor {
+    GObject parent;
+
+    WebKitWebEditorPrivate *priv;
+};
+
+struct _WebKitWebEditorClass {
+    GObjectClass parent_class;
+};
+
+WEBKIT_API GType
+webkit_web_editor_get_type (void);
+
+WEBKIT_API WebKitWebPage *
+webkit_web_editor_get_page (WebKitWebEditor *editor);
+
+G_END_DECLS
+
+#endif // WebKitWebEditor_h

Copied: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebEditorPrivate.h (from rev 187023, trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPagePrivate.h) (0 => 187024)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebEditorPrivate.h	                        (rev 0)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebEditorPrivate.h	2015-07-20 17:42:01 UTC (rev 187024)
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2015 Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef WebKitWebEditorPrivate_h
+#define WebKitWebEditorPrivate_h
+
+#include "WebKitWebEditor.h"
+#include "WebKitWebPage.h"
+
+WebKitWebEditor* webkitWebEditorCreate(WebKitWebPage*);
+
+#endif // WebKitWebEditor_h

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp (187023 => 187024)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp	2015-07-20 17:08:10 UTC (rev 187023)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp	2015-07-20 17:42:01 UTC (rev 187024)
@@ -36,6 +36,7 @@
 #include "WebKitScriptWorldPrivate.h"
 #include "WebKitURIRequestPrivate.h"
 #include "WebKitURIResponsePrivate.h"
+#include "WebKitWebEditorPrivate.h"
 #include "WebKitWebHitTestResultPrivate.h"
 #include "WebKitWebPagePrivate.h"
 #include "WebProcess.h"
@@ -70,6 +71,8 @@
     WebPage* webPage;
 
     CString uri;
+
+    GRefPtr<WebKitWebEditor> webEditor;
 };
 
 static guint signals[LAST_SIGNAL] = { 0, };
@@ -394,6 +397,11 @@
         WEBKIT_TYPE_WEB_HIT_TEST_RESULT);
 }
 
+WebPage* webkitWebPageGetPage(WebKitWebPage *webPage)
+{
+    return webPage->priv->webPage;
+}
+
 WebKitWebPage* webkitWebPageCreate(WebPage* webPage)
 {
     WebKitWebPage* page = WEBKIT_WEB_PAGE(g_object_new(WEBKIT_TYPE_WEB_PAGE, NULL));
@@ -575,3 +583,23 @@
 
     return webkitFrameGetOrCreate(webPage->priv->webPage->mainWebFrame());
 }
+
+/**
+ * webkit_web_page_get_editor:
+ * @web_page: a #WebKitWebPage
+ *
+ * Gets the #WebKitWebEditor of a #WebKitWebPage.
+ *
+ * Returns: (transfer none): the #WebKitWebEditor
+ *
+ * Since: 2.10
+ */
+WebKitWebEditor* webkit_web_page_get_editor(WebKitWebPage* webPage)
+{
+    g_return_val_if_fail(WEBKIT_IS_WEB_PAGE(webPage), nullptr);
+
+    if (!webPage->priv->webEditor)
+        webPage->priv->webEditor = adoptGRef(webkitWebEditorCreate(webPage));
+
+    return webPage->priv->webEditor.get();
+}

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.h (187023 => 187024)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.h	2015-07-20 17:08:10 UTC (rev 187023)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.h	2015-07-20 17:42:01 UTC (rev 187024)
@@ -27,6 +27,7 @@
 #include <glib-object.h>
 #include <webkit2/WebKitDefines.h>
 #include <webkit2/WebKitFrame.h>
+#include <webkit2/WebKitWebEditor.h>
 #include <webkitdom/webkitdom.h>
 
 G_BEGIN_DECLS
@@ -42,6 +43,9 @@
 typedef struct _WebKitWebPageClass   WebKitWebPageClass;
 typedef struct _WebKitWebPagePrivate WebKitWebPagePrivate;
 
+/* Forward declarations */
+typedef struct _WebKitWebEditor      WebKitWebEditor;
+
 struct _WebKitWebPage {
     GObject parent;
 
@@ -67,6 +71,9 @@
 WEBKIT_API WebKitFrame *
 webkit_web_page_get_main_frame   (WebKitWebPage *web_page);
 
+WEBKIT_API WebKitWebEditor *
+webkit_web_page_get_editor       (WebKitWebPage *web_page);
+
 G_END_DECLS
 
 #endif

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPagePrivate.h (187023 => 187024)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPagePrivate.h	2015-07-20 17:08:10 UTC (rev 187023)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPagePrivate.h	2015-07-20 17:42:01 UTC (rev 187024)
@@ -26,5 +26,6 @@
 
 WebKitWebPage* webkitWebPageCreate(WebKit::WebPage*);
 void webkitWebPageDidReceiveMessage(WebKitWebPage*, const String& messageName, API::Dictionary& message);
+WebKit::WebPage* webkitWebPageGetPage(WebKitWebPage*);
 
 #endif // WebKitWebPagePrivate_h

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/webkit-web-extension.h (187023 => 187024)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/webkit-web-extension.h	2015-07-20 17:08:10 UTC (rev 187023)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/webkit-web-extension.h	2015-07-20 17:42:01 UTC (rev 187024)
@@ -34,6 +34,7 @@
 #include <webkit2/WebKitURIRequest.h>
 #include <webkit2/WebKitURIResponse.h>
 #include <webkit2/WebKitVersion.h>
+#include <webkit2/WebKitWebEditor.h>
 #include <webkit2/WebKitWebExtension.h>
 #include <webkit2/WebKitWebHitTestResult.h>
 #include <webkit2/WebKitWebPage.h>

Modified: trunk/Tools/ChangeLog (187023 => 187024)


--- trunk/Tools/ChangeLog	2015-07-20 17:08:10 UTC (rev 187023)
+++ trunk/Tools/ChangeLog	2015-07-20 17:42:01 UTC (rev 187024)
@@ -1,3 +1,28 @@
+2015-07-20  Tomas Popela  <tpop...@redhat.com>
+
+        [GTK] Add selection-changed signal to the WebKit2 API
+        https://bugs.webkit.org/show_bug.cgi?id=137116
+
+        Reviewed by Carlos Garcia Campos.
+
+        Add a new WebProcess test TestEditor that is testing the WebKitWebEditor
+        (namely the selection-changed signal).
+
+        * TestWebKitAPI/Tests/WebKit2Gtk/CMakeLists.txt:
+        * TestWebKitAPI/Tests/WebKit2Gtk/EditorTest.cpp: Added.
+        (WebKitWebEditorTest::create):
+        (WebKitWebEditorTest::selectionChangedCallback):
+        (WebKitWebEditorTest::testSelectionSelectAll):
+        (WebKitWebEditorTest::testSelectionCollapse):
+        (WebKitWebEditorTest::testSelectionModifyMove):
+        (WebKitWebEditorTest::testSelectionModifyExtend):
+        (WebKitWebEditorTest::testSelectionUnselect):
+        (registerTests):
+        * TestWebKitAPI/Tests/WebKit2Gtk/TestEditor.cpp: Added.
+        (testWebKitWebEditorSelectionChanged):
+        (beforeAll):
+        (afterAll):
+
 2015-07-20  Alex Christensen  <achristen...@webkit.org>
 
         Resurrect CMake build on Windows.

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/CMakeLists.txt (187023 => 187024)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/CMakeLists.txt	2015-07-20 17:08:10 UTC (rev 187023)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/CMakeLists.txt	2015-07-20 17:42:01 UTC (rev 187024)
@@ -89,7 +89,7 @@
 endmacro()
 
 ADD_WK2_TEST_WEB_EXTENSION(WebExtensionTest WebExtensionTest.cpp)
-ADD_WK2_TEST_WEB_EXTENSION(WebProcessTest DOMNodeTest.cpp DOMNodeFilterTest.cpp DOMXPathNSResolverTest.cpp FrameTest.cpp WebProcessTest.cpp)
+ADD_WK2_TEST_WEB_EXTENSION(WebProcessTest DOMNodeTest.cpp DOMNodeFilterTest.cpp DOMXPathNSResolverTest.cpp FrameTest.cpp WebProcessTest.cpp EditorTest.cpp)
 
 ADD_WK2_TEST(InspectorTestServer InspectorTestServer.cpp)
 ADD_WK2_TEST(TestAuthentication TestAuthentication.cpp)
@@ -119,6 +119,7 @@
 ADD_WK2_TEST(TestWebKitWebContext TestWebKitWebContext.cpp)
 ADD_WK2_TEST(TestWebKitWebView TestWebKitWebView.cpp)
 ADD_WK2_TEST(TestWebKitUserContentManager TestWebKitUserContentManager.cpp)
+ADD_WK2_TEST(TestEditor TestEditor.cpp)
 
 if (ATSPI_FOUND)
     ADD_WK2_TEST(AccessibilityTestServer AccessibilityTestServer.cpp)

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/EditorTest.cpp (0 => 187024)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/EditorTest.cpp	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/EditorTest.cpp	2015-07-20 17:42:01 UTC (rev 187024)
@@ -0,0 +1,131 @@
+/*
+ * Copyright (C) 2015 Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+
+#include "WebProcessTest.h"
+#include <webkit2/webkit-web-extension.h>
+
+#define WEBKIT_DOM_USE_UNSTABLE_API
+#include <webkitdom/WebKitDOMDOMSelection.h>
+#include <webkitdom/WebKitDOMDOMWindowUnstable.h>
+
+class WebKitWebEditorTest : public WebProcessTest {
+public:
+    static std::unique_ptr<WebProcessTest> create() { return std::unique_ptr<WebProcessTest>(new WebKitWebEditorTest()); }
+
+private:
+    static void selectionChangedCallback(bool* selectionChanged)
+    {
+        *selectionChanged = true;
+    }
+
+    void testSelectionSelectAll(WebKitWebPage* page)
+    {
+        WebKitDOMDocument* document = webkit_web_page_get_dom_document(page);
+        g_assert(WEBKIT_DOM_IS_DOCUMENT(document));
+
+        webkit_dom_document_exec_command(document, "SelectAll", false, "");
+    }
+
+    void testSelectionCollapse(WebKitWebPage* page)
+    {
+        WebKitDOMDocument* document = webkit_web_page_get_dom_document(page);
+        g_assert(WEBKIT_DOM_IS_DOCUMENT(document));
+        GRefPtr<WebKitDOMDOMWindow> domWindow = adoptGRef(webkit_dom_document_get_default_view(document));
+        g_assert(WEBKIT_DOM_IS_DOM_WINDOW(domWindow.get()));
+        GRefPtr<WebKitDOMDOMSelection> domSelection = adoptGRef(webkit_dom_dom_window_get_selection(domWindow.get()));
+        g_assert(WEBKIT_DOM_IS_DOM_SELECTION(domSelection.get()));
+
+        webkit_dom_dom_selection_collapse_to_start(domSelection.get(), nullptr);
+    }
+
+    void testSelectionModifyMove(WebKitWebPage* page)
+    {
+        WebKitDOMDocument* document = webkit_web_page_get_dom_document(page);
+        g_assert(WEBKIT_DOM_IS_DOCUMENT(document));
+        GRefPtr<WebKitDOMDOMWindow> domWindow = adoptGRef(webkit_dom_document_get_default_view(document));
+        g_assert(WEBKIT_DOM_IS_DOM_WINDOW(domWindow.get()));
+        GRefPtr<WebKitDOMDOMSelection> domSelection = adoptGRef(webkit_dom_dom_window_get_selection(domWindow.get()));
+        g_assert(WEBKIT_DOM_IS_DOM_SELECTION(domSelection.get()));
+
+        webkit_dom_dom_selection_modify(domSelection.get(), "move", "forward", "character");
+    }
+
+    void testSelectionModifyExtend(WebKitWebPage* page)
+    {
+        WebKitDOMDocument* document = webkit_web_page_get_dom_document(page);
+        g_assert(WEBKIT_DOM_IS_DOCUMENT(document));
+        GRefPtr<WebKitDOMDOMWindow> domWindow = adoptGRef(webkit_dom_document_get_default_view(document));
+        g_assert(WEBKIT_DOM_IS_DOM_WINDOW(domWindow.get()));
+        GRefPtr<WebKitDOMDOMSelection> domSelection = adoptGRef(webkit_dom_dom_window_get_selection(domWindow.get()));
+        g_assert(WEBKIT_DOM_IS_DOM_SELECTION(domSelection.get()));
+
+        webkit_dom_dom_selection_modify(domSelection.get(), "extend", "forward", "word");
+    }
+
+    void testSelectionUnselect(WebKitWebPage* page)
+    {
+        WebKitDOMDocument* document = webkit_web_page_get_dom_document(page);
+        g_assert(WEBKIT_DOM_IS_DOCUMENT(document));
+
+        webkit_dom_document_exec_command(document, "Unselect", false, "");
+    }
+
+    bool runTest(const char* testName, WebKitWebPage* page) override
+    {
+        if (!strcmp(testName, "selection-changed")) {
+            bool selectionChanged = false;
+
+            WebKitWebEditor* editor = webkit_web_page_get_editor(page);
+            g_assert(WEBKIT_IS_WEB_EDITOR(editor));
+            assertObjectIsDeletedWhenTestFinishes(G_OBJECT(editor));
+            g_signal_connect_swapped(editor, "selection-changed", G_CALLBACK(selectionChangedCallback), &selectionChanged);
+
+            testSelectionSelectAll(page);
+            g_assert(selectionChanged);
+
+            selectionChanged = false;
+            testSelectionCollapse(page);
+            g_assert(selectionChanged);
+
+            selectionChanged = false;
+            testSelectionModifyMove(page);
+            g_assert(selectionChanged);
+
+            selectionChanged = false;
+            testSelectionModifyExtend(page);
+            g_assert(selectionChanged);
+
+            selectionChanged = false;
+            testSelectionUnselect(page);
+            g_assert(selectionChanged);
+
+            return true;
+        }
+
+        g_assert_not_reached();
+        return false;
+    }
+};
+
+static void __attribute__((constructor)) registerTests()
+{
+    REGISTER_TEST(WebKitWebEditorTest, "WebKitWebEditor/selection-changed");
+}

Copied: trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestEditor.cpp (from rev 187023, trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/webkit-web-extension.h) (0 => 187024)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestEditor.cpp	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestEditor.cpp	2015-07-20 17:42:01 UTC (rev 187024)
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2015 Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2,1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+
+#include "WebViewTest.h"
+#include <gtk/gtk.h>
+#include <webkit2/webkit2.h>
+
+static void testWebKitWebEditorSelectionChanged(WebViewTest* test, gconstpointer)
+{
+    static const gchar* testHTML = "<html><body>All work and no play make Jack a dull boy.</body></html>";
+    test->loadHtml(testHTML, nullptr);
+    test->waitUntilLoadFinished();
+
+    g_assert(test->runWebProcessTest("WebKitWebEditor", "selection-changed"));
+}
+
+void beforeAll()
+{
+    WebViewTest::add("WebKitWebEditor", "selection-changed", testWebKitWebEditorSelectionChanged);
+}
+
+void afterAll()
+{
+}
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to