Title: [106961] trunk/Source/WebKit2
Revision
106961
Author
carlo...@webkit.org
Date
2012-02-07 10:57:10 -0800 (Tue, 07 Feb 2012)

Log Message

[GTK] Add cut, copy and paste methods to WebKit2 GTK+ API
https://bugs.webkit.org/show_bug.cgi?id=76998

Reviewed by Martin Robinson.

* GNUmakefile.am: Add WebKitEditingCommands.h.
* UIProcess/API/gtk/WebKitEditingCommands.h: Added.
* UIProcess/API/gtk/WebKitWebView.cpp:
(didValidateCommand): Callback called by the C API when an editor
command has been validated.
(webkit_web_view_can_execute_editing_command): Asynchronously
validate the given editing command.
(webkit_web_view_can_execute_editing_command_finish): Finish async
operation started by webkit_web_view_can_execute_editing_command().
(webkit_web_view_execute_editing_command): Execute the given
command.
* UIProcess/API/gtk/WebKitWebView.h:
* UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add new symbols.
* UIProcess/API/gtk/tests/GNUmakefile.am:
* UIProcess/API/gtk/tests/LoadTrackingTest.cpp:
(LoadTrackingTest::provisionalLoadFailed): Do not finish the main
loop on load failure, now finished is always called.
* UIProcess/API/gtk/tests/TestBackForwardList.cpp: Use WebViewTest
instead of LoadTrackingTest.
* UIProcess/API/gtk/tests/TestWebViewEditor.cpp: Added.
(testWebViewEditorCutCopyPasteNonEditable):
(testWebViewEditorCutCopyPasteEditable):
(beforeAll):
(afterAll):
* UIProcess/API/gtk/tests/WebViewTest.cpp:
(loadChanged):
(WebViewTest::waitUntilLoadFinished): Run a main loop until load
finished.
* UIProcess/API/gtk/tests/WebViewTest.h: Add waitUntilLoadFinished().
* UIProcess/API/gtk/webkit2.h: Include WebKitEditingCommands.h.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (106960 => 106961)


--- trunk/Source/WebKit2/ChangeLog	2012-02-07 18:54:24 UTC (rev 106960)
+++ trunk/Source/WebKit2/ChangeLog	2012-02-07 18:57:10 UTC (rev 106961)
@@ -1,3 +1,41 @@
+2012-02-07  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [GTK] Add cut, copy and paste methods to WebKit2 GTK+ API
+        https://bugs.webkit.org/show_bug.cgi?id=76998
+
+        Reviewed by Martin Robinson.
+
+        * GNUmakefile.am: Add WebKitEditingCommands.h.
+        * UIProcess/API/gtk/WebKitEditingCommands.h: Added.
+        * UIProcess/API/gtk/WebKitWebView.cpp:
+        (didValidateCommand): Callback called by the C API when an editor
+        command has been validated.
+        (webkit_web_view_can_execute_editing_command): Asynchronously
+        validate the given editing command.
+        (webkit_web_view_can_execute_editing_command_finish): Finish async
+        operation started by webkit_web_view_can_execute_editing_command().
+        (webkit_web_view_execute_editing_command): Execute the given
+        command.
+        * UIProcess/API/gtk/WebKitWebView.h:
+        * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add new symbols.
+        * UIProcess/API/gtk/tests/GNUmakefile.am:
+        * UIProcess/API/gtk/tests/LoadTrackingTest.cpp:
+        (LoadTrackingTest::provisionalLoadFailed): Do not finish the main
+        loop on load failure, now finished is always called.
+        * UIProcess/API/gtk/tests/TestBackForwardList.cpp: Use WebViewTest
+        instead of LoadTrackingTest.
+        * UIProcess/API/gtk/tests/TestWebViewEditor.cpp: Added.
+        (testWebViewEditorCutCopyPasteNonEditable):
+        (testWebViewEditorCutCopyPasteEditable):
+        (beforeAll):
+        (afterAll):
+        * UIProcess/API/gtk/tests/WebViewTest.cpp:
+        (loadChanged):
+        (WebViewTest::waitUntilLoadFinished): Run a main loop until load
+        finished.
+        * UIProcess/API/gtk/tests/WebViewTest.h: Add waitUntilLoadFinished().
+        * UIProcess/API/gtk/webkit2.h: Include WebKitEditingCommands.h.
+
 2012-02-07  Allan Sandfeld Jensen  <allan.jen...@nokia.com>
 
         Encode radius, force and rotationAngle in WebPlatformTouchPoint.

Modified: trunk/Source/WebKit2/GNUmakefile.am (106960 => 106961)


--- trunk/Source/WebKit2/GNUmakefile.am	2012-02-07 18:54:24 UTC (rev 106960)
+++ trunk/Source/WebKit2/GNUmakefile.am	2012-02-07 18:57:10 UTC (rev 106961)
@@ -86,6 +86,7 @@
 	$(WebKit2)/UIProcess/API/gtk/WebKitBackForwardListItem.h \
 	$(WebKit2)/UIProcess/API/gtk/WebKitDefines.h \
 	$(WebKit2)/UIProcess/API/gtk/WebKitDownload.h \
+	$(WebKit2)/UIProcess/API/gtk/WebKitEditingCommands.h \
 	$(WebKit2)/UIProcess/API/gtk/WebKitError.h \
 	$(WebKit2)/UIProcess/API/gtk/WebKitNavigationPolicyDecision.h \
 	$(WebKit2)/UIProcess/API/gtk/WebKitPolicyDecision.h \
@@ -534,6 +535,7 @@
 	Source/WebKit2/UIProcess/API/gtk/WebKitDownloadPrivate.h \
 	Source/WebKit2/UIProcess/API/gtk/WebKitDownloadClient.cpp \
 	Source/WebKit2/UIProcess/API/gtk/WebKitDownloadClient.h \
+	Source/WebKit2/UIProcess/API/gtk/WebKitEditingCommands.h \
 	Source/WebKit2/UIProcess/API/gtk/WebKitError.h \
 	Source/WebKit2/UIProcess/API/gtk/WebKitError.cpp \
 	Source/WebKit2/UIProcess/API/gtk/WebKitLoaderClient.h \

Added: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitEditingCommands.h (0 => 106961)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitEditingCommands.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitEditingCommands.h	2012-02-07 18:57:10 UTC (rev 106961)
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2012 Igalia S.L.
+ *
+ * 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.
+ */
+
+#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION)
+#error "Only <webkit2/webkit2.h> can be included directly."
+#endif
+
+#ifndef WebKitEditingCommands_h
+#define WebKitEditingCommands_h
+
+G_BEGIN_DECLS
+
+/**
+ * WEBKIT_EDITING_COMMAND_CUT:
+ *
+ * The cut clipboard command. Copies the current selection inside
+ * a #WebKitWebView to the clipboard and deletes the selected content.
+ * You can check whether it's possible to execute the command with
+ * webkit_web_view_can_execute_editing_command(). In general it's
+ * possible to cut to the clipboard when the #WebKitWebView content is
+ * editable and there is an active selection.
+ */
+#define WEBKIT_EDITING_COMMAND_CUT "Cut"
+
+/**
+ * WEBKIT_EDITING_COMMAND_COPY:
+ *
+ * The copy clipboard command. Copies the current selection inside
+ * a #WebKitWebView to the clipboard.
+ * You can check whether it's possible to execute the command with
+ * webkit_web_view_can_execute_editing_command(). In general it's
+ * possible to copy to the clipboard when there is an active selection
+ * inside the #WebKitWebView.
+ */
+#define WEBKIT_EDITING_COMMAND_COPY "Copy"
+
+/**
+ * WEBKIT_EDITING_COMMAND_PASTE:
+ *
+ * The paste clipboard command. Pastes the contents of the clipboard to
+ * a #WebKitWebView.
+ * You can check whether it's possible to execute the command with
+ * webkit_web_view_can_execute_editing_command(). In general it's possible
+ * to paste from the clipboard when the #WebKitWebView content is editable
+ * and clipboard is not empty.
+ */
+#define WEBKIT_EDITING_COMMAND_PASTE "Paste"
+
+
+G_END_DECLS
+
+#endif

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp (106960 => 106961)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp	2012-02-07 18:54:24 UTC (rev 106960)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp	2012-02-07 18:57:10 UTC (rev 106961)
@@ -1267,3 +1267,77 @@
     WKPageRef wkPage = toAPI(webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView)));
     return WKPageGetPageZoomFactor(wkPage);
 }
+
+
+static void didValidateCommand(WKStringRef command, bool isEnabled, int32_t state, WKErrorRef, void* context)
+{
+    GRefPtr<GSimpleAsyncResult> result = adoptGRef(G_SIMPLE_ASYNC_RESULT(context));
+    g_simple_async_result_set_op_res_gboolean(result.get(), isEnabled);
+    g_simple_async_result_complete(result.get());
+}
+
+/**
+ * webkit_web_view_can_execute_editing_command:
+ * @web_view: a #WebKitWebView
+ * @command: the command to check
+ * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
+ * @user_data: (closure): the data to pass to callback function
+ *
+ * Asynchronously execute the given editing command.
+ *
+ * When the operation is finished, @callback will be called. You can then call
+ * webkit_web_view_can_execute_editing_command_finish() to get the result of the operation.
+ */
+void webkit_web_view_can_execute_editing_command(WebKitWebView* webView, const char* command, GAsyncReadyCallback callback, gpointer userData)
+{
+    g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
+    g_return_if_fail(command);
+
+    GSimpleAsyncResult* result = g_simple_async_result_new(G_OBJECT(webView), callback, userData,
+                                                           reinterpret_cast<gpointer>(webkit_web_view_can_execute_editing_command));
+    WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView));
+    WKRetainPtr<WKStringRef> wkCommand(AdoptWK, WKStringCreateWithUTF8CString(command));
+    WKPageValidateCommand(toAPI(page), wkCommand.get(), result, didValidateCommand);
+}
+
+/**
+ * webkit_web_view_can_execute_editing_command_finish:
+ * @web_view: a #WebKitWebView
+ * @result: a #GAsyncResult
+ * @error: return location for error or %NULL to ignore
+ *
+ * Finish an asynchronous operation started with webkit_web_view_can_execute_editing_command().
+ *
+ * Returns: %TRUE if a selection can be cut or %FALSE otherwise
+ */
+gboolean webkit_web_view_can_execute_editing_command_finish(WebKitWebView* webView, GAsyncResult* result, GError** error)
+{
+    g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
+    g_return_val_if_fail(G_IS_ASYNC_RESULT(result), FALSE);
+
+    GSimpleAsyncResult* simple = G_SIMPLE_ASYNC_RESULT(result);
+    g_warn_if_fail(g_simple_async_result_get_source_tag(simple) == webkit_web_view_can_execute_editing_command);
+
+    if (g_simple_async_result_propagate_error(simple, error))
+        return FALSE;
+    return g_simple_async_result_get_op_res_gboolean(simple);
+}
+
+/**
+ * webkit_web_view_execute_editing_command:
+ * @web_view: a #WebKitWebView
+ * @command: the command to execute
+ *
+ * Request to execute the given @command for @web_view. You can use
+ * webkit_web_view_can_execute_editing_command() to check whether
+ * it's possible to execute the command.
+ */
+void webkit_web_view_execute_editing_command(WebKitWebView* webView, const char* command)
+{
+    g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
+    g_return_if_fail(command);
+
+    WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView));
+    WKRetainPtr<WKStringRef> wkCommand(AdoptWK, WKStringCreateWithUTF8CString(command));
+    WKPageExecuteCommand(toAPI(page), wkCommand.get());
+}

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h (106960 => 106961)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h	2012-02-07 18:54:24 UTC (rev 106960)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h	2012-02-07 18:57:10 UTC (rev 106961)
@@ -39,6 +39,17 @@
 
 G_BEGIN_DECLS
 
+#define WEBKIT_TYPE_WEB_VIEW            (webkit_web_view_get_type())
+#define WEBKIT_WEB_VIEW(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_WEB_VIEW, WebKitWebView))
+#define WEBKIT_IS_WEB_VIEW(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_WEB_VIEW))
+#define WEBKIT_WEB_VIEW_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),  WEBKIT_TYPE_WEB_VIEW, WebKitWebViewClass))
+#define WEBKIT_IS_WEB_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),  WEBKIT_TYPE_WEB_VIEW))
+#define WEBKIT_WEB_VIEW_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),  WEBKIT_TYPE_WEB_VIEW, WebKitWebViewClass))
+
+typedef struct _WebKitWebView WebKitWebView;
+typedef struct _WebKitWebViewClass WebKitWebViewClass;
+typedef struct _WebKitWebViewPrivate WebKitWebViewPrivate;
+
 /**
  * WebKitPolicyDecisionType:
  * @WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION: This type of policy decision
@@ -73,17 +84,6 @@
     WEBKIT_POLICY_DECISION_TYPE_RESPONSE,
 } WebKitPolicyDecisionType;
 
-#define WEBKIT_TYPE_WEB_VIEW            (webkit_web_view_get_type())
-#define WEBKIT_WEB_VIEW(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_WEB_VIEW, WebKitWebView))
-#define WEBKIT_WEB_VIEW_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),  WEBKIT_TYPE_WEB_VIEW, WebKitWebViewClass))
-#define WEBKIT_IS_WEB_VIEW(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_WEB_VIEW))
-#define WEBKIT_IS_WEB_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),  WEBKIT_TYPE_WEB_VIEW))
-#define WEBKIT_WEB_VIEW_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),  WEBKIT_TYPE_WEB_VIEW, WebKitWebViewClass))
-
-typedef struct _WebKitWebView WebKitWebView;
-typedef struct _WebKitWebViewClass WebKitWebViewClass;
-typedef struct _WebKitWebViewPrivate WebKitWebViewPrivate;
-
 /**
  * WebKitLoadEvent
  * @WEBKIT_LOAD_STARTED: A new load request has been made.
@@ -152,99 +152,113 @@
 };
 
 WEBKIT_API GType
-webkit_web_view_get_type                     (void);
+webkit_web_view_get_type                           (void);
 
 WEBKIT_API GtkWidget *
-webkit_web_view_new                          (void);
+webkit_web_view_new                                (void);
 
 WEBKIT_API GtkWidget *
-webkit_web_view_new_with_context             (WebKitWebContext          *context);
+webkit_web_view_new_with_context                   (WebKitWebContext          *context);
 
 WEBKIT_API WebKitWebContext *
-webkit_web_view_get_context                  (WebKitWebView             *web_view);
+webkit_web_view_get_context                        (WebKitWebView             *web_view);
 
 WEBKIT_API void
-webkit_web_view_load_uri                     (WebKitWebView             *web_view,
-                                              const gchar               *uri);
+webkit_web_view_load_uri                           (WebKitWebView             *web_view,
+                                                    const gchar               *uri);
 
 WEBKIT_API void
-webkit_web_view_load_html                    (WebKitWebView             *web_view,
-                                              const gchar               *content,
-                                              const gchar               *base_uri);
+webkit_web_view_load_html                          (WebKitWebView             *web_view,
+                                                    const gchar               *content,
+                                                    const gchar               *base_uri);
 
 WEBKIT_API void
-webkit_web_view_load_plain_text              (WebKitWebView             *web_view,
-                                              const gchar               *plain_text);
+webkit_web_view_load_plain_text                    (WebKitWebView             *web_view,
+                                                    const gchar               *plain_text);
 
 WEBKIT_API void
-webkit_web_view_load_request                 (WebKitWebView             *web_view,
-                                              WebKitURIRequest          *request);
+webkit_web_view_load_request                       (WebKitWebView             *web_view,
+                                                    WebKitURIRequest          *request);
 
 WEBKIT_API void
-webkit_web_view_stop_loading                 (WebKitWebView             *web_view);
+webkit_web_view_stop_loading                       (WebKitWebView             *web_view);
 
 WEBKIT_API void
-webkit_web_view_replace_content              (WebKitWebView             *web_view,
-                                              const gchar               *content,
-                                              const gchar               *content_uri,
-                                              const gchar               *base_uri);
+webkit_web_view_replace_content                    (WebKitWebView             *web_view,
+                                                    const gchar               *content,
+                                                    const gchar               *content_uri,
+                                                    const gchar               *base_uri);
 
 WEBKIT_API const gchar *
-webkit_web_view_get_title                    (WebKitWebView             *web_view);
+webkit_web_view_get_title                          (WebKitWebView             *web_view);
 
 WEBKIT_API void
-webkit_web_view_reload                       (WebKitWebView             *web_view);
+webkit_web_view_reload                             (WebKitWebView             *web_view);
 
 WEBKIT_API void
-webkit_web_view_reload_bypass_cache          (WebKitWebView             *web_view);
+webkit_web_view_reload_bypass_cache                (WebKitWebView             *web_view);
 
 WEBKIT_API gdouble
-webkit_web_view_get_estimated_load_progress  (WebKitWebView             *web_view);
+webkit_web_view_get_estimated_load_progress        (WebKitWebView             *web_view);
 
 WEBKIT_API void
-webkit_web_view_go_back                      (WebKitWebView             *web_view);
+webkit_web_view_go_back                            (WebKitWebView             *web_view);
 
 WEBKIT_API gboolean
-webkit_web_view_can_go_back                  (WebKitWebView             *web_view);
+webkit_web_view_can_go_back                        (WebKitWebView             *web_view);
 
 WEBKIT_API void
-webkit_web_view_go_forward                   (WebKitWebView             *web_view);
+webkit_web_view_go_forward                         (WebKitWebView             *web_view);
 
 WEBKIT_API gboolean
-webkit_web_view_can_go_forward               (WebKitWebView             *web_view);
+webkit_web_view_can_go_forward                     (WebKitWebView             *web_view);
 
 WEBKIT_API WebKitBackForwardList *
-webkit_web_view_get_back_forward_list        (WebKitWebView             *web_view);
+webkit_web_view_get_back_forward_list              (WebKitWebView             *web_view);
 
 WEBKIT_API void
-webkit_web_view_go_to_back_forward_list_item (WebKitWebView             *web_view,
-                                              WebKitBackForwardListItem *list_item);
+webkit_web_view_go_to_back_forward_list_item       (WebKitWebView             *web_view,
+                                                    WebKitBackForwardListItem *list_item);
 WEBKIT_API const gchar *
-webkit_web_view_get_uri                      (WebKitWebView             *web_view);
+webkit_web_view_get_uri                            (WebKitWebView             *web_view);
 
 WEBKIT_API const gchar *
-webkit_web_view_get_custom_charset           (WebKitWebView             *web_view);
+webkit_web_view_get_custom_charset                 (WebKitWebView             *web_view);
 
 WEBKIT_API void
-webkit_web_view_set_custom_charset           (WebKitWebView             *web_view,
-                                              const gchar               *charset);
+webkit_web_view_set_custom_charset                 (WebKitWebView             *web_view,
+                                                    const gchar               *charset);
 
 WEBKIT_API void
-webkit_web_view_set_settings                 (WebKitWebView             *web_view,
-                                              WebKitSettings            *settings);
+webkit_web_view_set_settings                       (WebKitWebView             *web_view,
+                                                    WebKitSettings            *settings);
 
 WEBKIT_API WebKitSettings *
-webkit_web_view_get_settings                 (WebKitWebView             *web_view);
+webkit_web_view_get_settings                       (WebKitWebView             *web_view);
 
 WEBKIT_API WebKitWindowProperties *
-webkit_web_view_get_window_properties        (WebKitWebView             *web_view);
+webkit_web_view_get_window_properties              (WebKitWebView             *web_view);
 
 WEBKIT_API void
-webkit_web_view_set_zoom_level               (WebKitWebView             *web_view,
-                                              gdouble                    zoom_level);
+webkit_web_view_set_zoom_level                     (WebKitWebView             *web_view,
+                                                    gdouble                    zoom_level);
 WEBKIT_API gdouble
-webkit_web_view_get_zoom_level               (WebKitWebView             *web_view);
+webkit_web_view_get_zoom_level                     (WebKitWebView             *web_view);
 
+WEBKIT_API void
+webkit_web_view_can_execute_editing_command        (WebKitWebView             *web_view,
+                                                    const gchar               *command,
+                                                    GAsyncReadyCallback        callback,
+                                                    gpointer                   user_data);
+
+WEBKIT_API gboolean
+webkit_web_view_can_execute_editing_command_finish (WebKitWebView             *web_view,
+                                                    GAsyncResult              *result,
+                                                    GError                   **error);
+
+WEBKIT_API void
+webkit_web_view_execute_editing_command            (WebKitWebView             *web_view,
+                                                    const gchar               *command);
 G_END_DECLS
 
 #endif

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt (106960 => 106961)


--- trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt	2012-02-07 18:54:24 UTC (rev 106960)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt	2012-02-07 18:57:10 UTC (rev 106961)
@@ -49,6 +49,13 @@
 WebKitWebView
 WebKitLoadEvent
 WebKitPolicyDecisionType
+
+<SUBSECTION Editing Commands>
+WEBKIT_EDITING_COMMAND_CUT
+WEBKIT_EDITING_COMMAND_COPY
+WEBKIT_EDITING_COMMAND_PASTE
+
+<SUBSECTION>
 webkit_web_view_new
 webkit_web_view_new_with_context
 webkit_web_view_get_context
@@ -76,6 +83,9 @@
 webkit_web_view_get_window_properties
 webkit_web_view_set_zoom_level
 webkit_web_view_get_zoom_level
+webkit_web_view_can_execute_editing_command
+webkit_web_view_can_execute_editing_command_finish
+webkit_web_view_execute_editing_command
 
 <SUBSECTION Standard>
 WebKitWebViewClass

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am (106960 => 106961)


--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am	2012-02-07 18:54:24 UTC (rev 106960)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am	2012-02-07 18:57:10 UTC (rev 106961)
@@ -5,7 +5,8 @@
 	Programs/WebKit2APITests/TestWebKitSettings \
 	Programs/WebKit2APITests/TestBackForwardList \
 	Programs/WebKit2APITests/TestDownloads \
-	Programs/WebKit2APITests/TestWebKitPolicyClient
+	Programs/WebKit2APITests/TestWebKitPolicyClient \
+	Programs/WebKit2APITests/TestWebViewEditor
 
 noinst_PROGRAMS += $(TEST_PROGS)
 
@@ -111,3 +112,9 @@
 Programs_WebKit2APITests_TestDownloads_CPPFLAGS = $(webkit2_tests_cppflags)
 Programs_WebKit2APITests_TestDownloads_LDADD = $(webkit2_tests_ldadd)
 Programs_WebKit2APITests_TestDownloads_LDFLAGS = $(webkit2_tests_ldflags)
+
+Programs_WebKit2APITests_TestWebViewEditor_SOURCES = \
+        Source/WebKit2/UIProcess/API/gtk/tests/TestWebViewEditor.cpp
+Programs_WebKit2APITests_TestWebViewEditor_CPPFLAGS = $(webkit2_tests_cppflags)
+Programs_WebKit2APITests_TestWebViewEditor_LDADD = $(webkit2_tests_ldadd)
+Programs_WebKit2APITests_TestWebViewEditor_LDFLAGS = $(webkit2_tests_ldflags)

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.cpp (106960 => 106961)


--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.cpp	2012-02-07 18:54:24 UTC (rev 106960)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.cpp	2012-02-07 18:57:10 UTC (rev 106961)
@@ -110,8 +110,6 @@
 void LoadTrackingTest::provisionalLoadFailed(const gchar* failingURI, GError* error)
 {
     m_loadEvents.append(ProvisionalLoadFailed);
-    if (m_runLoadUntilCompletion)
-        g_main_loop_quit(m_mainLoop);
 }
 
 void LoadTrackingTest::loadCommitted()

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestBackForwardList.cpp (106960 => 106961)


--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestBackForwardList.cpp	2012-02-07 18:54:24 UTC (rev 106960)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestBackForwardList.cpp	2012-02-07 18:57:10 UTC (rev 106961)
@@ -19,8 +19,8 @@
 
 #include "config.h"
 
-#include "LoadTrackingTest.h"
 #include "WebKitTestServer.h"
+#include "WebViewTest.h"
 #include <gtk/gtk.h>
 #include <libsoup/soup.h>
 #include <string.h>
@@ -46,7 +46,7 @@
     soup_message_body_complete(msg->response_body);
 }
 
-class BackForwardListTest: public LoadTrackingTest {
+class BackForwardListTest: public WebViewTest {
 public:
     MAKE_GLIB_TEST_FIXTURE(BackForwardListTest);
 
@@ -130,7 +130,7 @@
     void waitUntilLoadFinished()
     {
         m_hasChanged = false;
-        LoadTrackingTest::waitUntilLoadFinished();
+        WebViewTest::waitUntilLoadFinished();
         g_assert(m_hasChanged);
     }
 

Added: trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebViewEditor.cpp (0 => 106961)


--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebViewEditor.cpp	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebViewEditor.cpp	2012-02-07 18:57:10 UTC (rev 106961)
@@ -0,0 +1,142 @@
+/*
+ * Copyright (C) 2012 Igalia S.L.
+ *
+ * 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 <wtf/gobject/GRefPtr.h>
+
+class EditorTest: public WebViewTest {
+public:
+    MAKE_GLIB_TEST_FIXTURE(EditorTest);
+
+    static const unsigned int kClipboardWaitTimeout = 50;
+    static const unsigned int kClipboardWaitMaxTries = 2;
+
+    EditorTest()
+        : m_clipboard(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD))
+        , m_canExecuteEditingCommand(false)
+        , m_triesCount(0)
+    {
+        gtk_clipboard_clear(m_clipboard);
+    }
+
+    static void canExecuteEditingCommandReadyCallback(GObject*, GAsyncResult* result, EditorTest* test)
+    {
+        GOwnPtr<GError> error;
+        test->m_canExecuteEditingCommand = webkit_web_view_can_execute_editing_command_finish(test->m_webView, result, &error.outPtr());
+        g_assert(!error.get());
+        g_main_loop_quit(test->m_mainLoop);
+    }
+
+    bool canExecuteEditingCommand(const char* command)
+    {
+        m_canExecuteEditingCommand = false;
+        webkit_web_view_can_execute_editing_command(m_webView, command, reinterpret_cast<GAsyncReadyCallback>(canExecuteEditingCommandReadyCallback), this);
+        g_main_loop_run(m_mainLoop);
+        return m_canExecuteEditingCommand;
+    }
+
+    static gboolean waitForClipboardText(EditorTest* test)
+    {
+        test->m_triesCount++;
+        if (gtk_clipboard_wait_is_text_available(test->m_clipboard) || test->m_triesCount > kClipboardWaitMaxTries) {
+            g_main_loop_quit(test->m_mainLoop);
+            return FALSE;
+        }
+
+        return TRUE;
+    }
+
+    void copyClipboard()
+    {
+        webkit_web_view_execute_editing_command(m_webView, WEBKIT_EDITING_COMMAND_COPY);
+        // There's no way to know when the selection has been copied to
+        // the clipboard, so use a timeout source to query the clipboard.
+        m_triesCount = 0;
+        g_timeout_add(kClipboardWaitTimeout, reinterpret_cast<GSourceFunc>(waitForClipboardText), this);
+        g_main_loop_run(m_mainLoop);
+    }
+
+    GtkClipboard* m_clipboard;
+    bool m_canExecuteEditingCommand;
+    size_t m_triesCount;
+};
+
+static void testWebViewEditorCutCopyPasteNonEditable(EditorTest* test, gconstpointer)
+{
+    static const char* selectedSpanHTML = "<html><body contentEditable=\"false\">"
+        "<span id=\"mainspan\">All work and no play <span id=\"subspan\">make Jack a dull</span> boy.</span>"
+        "<script>document.getSelection().collapse();\n"
+        "document.getSelection().selectAllChildren(document.getElementById('subspan'));\n"
+        "</script></body></html>";
+
+    // Nothing loaded yet.
+    g_assert(!test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_CUT));
+    g_assert(!test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_COPY));
+    g_assert(!test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_PASTE));
+
+    test->loadHtml(selectedSpanHTML, 0);
+    test->waitUntilLoadFinished();
+
+    g_assert(test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_COPY));
+    // It's not possible to cut and paste when content is not editable
+    // even if there's a selection.
+    g_assert(!test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_CUT));
+    g_assert(!test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_PASTE));
+
+    test->copyClipboard();
+    GOwnPtr<char> clipboardText(gtk_clipboard_wait_for_text(test->m_clipboard));
+    g_assert_cmpstr(clipboardText.get(), ==, "make Jack a dull");
+}
+
+static void testWebViewEditorCutCopyPasteEditable(EditorTest* test, gconstpointer)
+{
+    static const char* selectedSpanHTML = "<html><body contentEditable=\"true\">"
+        "<span id=\"mainspan\">All work and no play <span>make Jack a dull</span> boy.</span>"
+        "<script>document.getSelection().collapse();\n"
+        "document.getSelection().selectAllChildren(document.getElementById('mainspan'));\n"
+        "</script></body></html>";
+
+    // Nothing loaded yet.
+    g_assert(!test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_CUT));
+    g_assert(!test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_COPY));
+    g_assert(!test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_PASTE));
+
+    test->loadHtml(selectedSpanHTML, 0);
+    test->waitUntilLoadFinished();
+
+    // There's a selection.
+    g_assert(test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_CUT));
+    g_assert(test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_COPY));
+    g_assert(test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_PASTE));
+
+    test->copyClipboard();
+    GOwnPtr<char> clipboardText(gtk_clipboard_wait_for_text(test->m_clipboard));
+    g_assert_cmpstr(clipboardText.get(), ==, "All work and no play make Jack a dull boy.");
+}
+
+void beforeAll()
+{
+    EditorTest::add("WebKitWebView", "cut-copy-paste/non-editable", testWebViewEditorCutCopyPasteNonEditable);
+    EditorTest::add("WebKitWebView", "cut-copy-paste/editable", testWebViewEditorCutCopyPasteEditable);
+}
+
+void afterAll()
+{
+}

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp (106960 => 106961)


--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp	2012-02-07 18:54:24 UTC (rev 106960)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp	2012-02-07 18:57:10 UTC (rev 106961)
@@ -116,3 +116,17 @@
     g_timeout_add_seconds(seconds, reinterpret_cast<GSourceFunc>(testLoadTimeoutFinishLoop), m_mainLoop);
     g_main_loop_run(m_mainLoop);
 }
+
+static void loadChanged(WebKitWebView* webView, WebKitLoadEvent loadEvent, WebViewTest* test)
+{
+    if (loadEvent != WEBKIT_LOAD_FINISHED)
+        return;
+    g_signal_handlers_disconnect_by_func(webView, reinterpret_cast<void*>(loadChanged), test);
+    g_main_loop_quit(test->m_mainLoop);
+}
+
+void WebViewTest::waitUntilLoadFinished()
+{
+    g_signal_connect(m_webView, "load-changed", G_CALLBACK(loadChanged), this);
+    g_main_loop_run(m_mainLoop);
+}

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h (106960 => 106961)


--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h	2012-02-07 18:54:24 UTC (rev 106960)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h	2012-02-07 18:57:10 UTC (rev 106961)
@@ -41,6 +41,7 @@
     void goToBackForwardListItem(WebKitBackForwardListItem*);
 
     void wait(double seconds);
+    void waitUntilLoadFinished();
 
     WebKitWebView* m_webView;
     GMainLoop* m_mainLoop;

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/webkit2.h (106960 => 106961)


--- trunk/Source/WebKit2/UIProcess/API/gtk/webkit2.h	2012-02-07 18:54:24 UTC (rev 106960)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/webkit2.h	2012-02-07 18:57:10 UTC (rev 106961)
@@ -27,6 +27,7 @@
 #include <webkit2/WebKitBackForwardListItem.h>
 #include <webkit2/WebKitDefines.h>
 #include <webkit2/WebKitDownload.h>
+#include <webkit2/WebKitEditingCommands.h>
 #include <webkit2/WebKitEnumTypes.h>
 #include <webkit2/WebKitError.h>
 #include <webkit2/WebKitSettings.h>
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to