Title: [129399] trunk/Source/WebKit2
Revision
129399
Author
[email protected]
Date
2012-09-24 12:53:40 -0700 (Mon, 24 Sep 2012)

Log Message

[GTK] Add Select All method to WebKit2 GTK+ API
https://bugs.webkit.org/show_bug.cgi?id=97460

Patch by Simon Pena <[email protected]> on 2012-09-24
Reviewed by Martin Robinson.

Following the same approach used when added Cut, Copy and Paste,
the Select All method is added to the WebKit2 GTK+ API.

This introduces a new macro in the WebKitEditingCommands,
updates the documentation, and includes a new unit test.

* UIProcess/API/gtk/WebKitEditingCommands.h: Add a new macro for
the Select All command.
* UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Include the Select All
command in the documentation.
* UIProcess/API/gtk/tests/TestWebViewEditor.cpp: Cover the new command
with a unit test.
(testWebViewEditorSelectAll):
(beforeAll):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (129398 => 129399)


--- trunk/Source/WebKit2/ChangeLog	2012-09-24 19:12:29 UTC (rev 129398)
+++ trunk/Source/WebKit2/ChangeLog	2012-09-24 19:53:40 UTC (rev 129399)
@@ -1,3 +1,25 @@
+2012-09-24  Simon Pena  <[email protected]>
+
+        [GTK] Add Select All method to WebKit2 GTK+ API
+        https://bugs.webkit.org/show_bug.cgi?id=97460
+
+        Reviewed by Martin Robinson.
+
+        Following the same approach used when added Cut, Copy and Paste,
+        the Select All method is added to the WebKit2 GTK+ API.
+
+        This introduces a new macro in the WebKitEditingCommands,
+        updates the documentation, and includes a new unit test.
+
+        * UIProcess/API/gtk/WebKitEditingCommands.h: Add a new macro for
+        the Select All command.
+        * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Include the Select All
+        command in the documentation.
+        * UIProcess/API/gtk/tests/TestWebViewEditor.cpp: Cover the new command
+        with a unit test.
+        (testWebViewEditorSelectAll):
+        (beforeAll):
+
 2012-09-24  Bo Liu  <[email protected]>
 
         Reland "Add in-place reload behavior to ImagesEnabled setting" with optimizations

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitEditingCommands.h (129398 => 129399)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitEditingCommands.h	2012-09-24 19:12:29 UTC (rev 129398)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitEditingCommands.h	2012-09-24 19:53:40 UTC (rev 129399)
@@ -62,6 +62,15 @@
  */
 #define WEBKIT_EDITING_COMMAND_PASTE "Paste"
 
+/**
+ * WEBKIT_EDITING_COMMAND_SELECT_ALL:
+ *
+ * The select all command. Selects all the content of the current text field in
+ * a #WebKitWebView.
+ * It is always possible to select all text, no matter wheter the #WebKitWebView content
+ * is editable or not. You can still check it with webkit_web_view_can_execute_editing_command().
+ */
+#define WEBKIT_EDITING_COMMAND_SELECT_ALL "SelectAll"
 
 G_END_DECLS
 

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


--- trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt	2012-09-24 19:12:29 UTC (rev 129398)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt	2012-09-24 19:53:40 UTC (rev 129399)
@@ -70,6 +70,7 @@
 WEBKIT_EDITING_COMMAND_CUT
 WEBKIT_EDITING_COMMAND_COPY
 WEBKIT_EDITING_COMMAND_PASTE
+WEBKIT_EDITING_COMMAND_SELECT_ALL
 
 <SUBSECTION>
 webkit_web_view_new

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebViewEditor.cpp (129398 => 129399)


--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebViewEditor.cpp	2012-09-24 19:12:29 UTC (rev 129398)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebViewEditor.cpp	2012-09-24 19:53:40 UTC (rev 129399)
@@ -131,10 +131,70 @@
     g_assert_cmpstr(clipboardText.get(), ==, "All work and no play make Jack a dull boy.");
 }
 
+static void testWebViewEditorSelectAllNonEditable(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>";
+
+    g_assert(test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_SELECT_ALL));
+
+    test->loadHtml(selectedSpanHTML, 0);
+    test->waitUntilLoadFinished();
+
+    g_assert(test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_SELECT_ALL));
+
+    test->copyClipboard();
+    GOwnPtr<char> clipboardText(gtk_clipboard_wait_for_text(test->m_clipboard));
+
+    // Initially only the subspan is selected.
+    g_assert_cmpstr(clipboardText.get(), ==, "make Jack a dull");
+
+    webkit_web_view_execute_editing_command(test->m_webView, WEBKIT_EDITING_COMMAND_SELECT_ALL);
+    test->copyClipboard();
+    clipboardText.set(gtk_clipboard_wait_for_text(test->m_clipboard));
+
+    // The mainspan should be selected after calling SELECT_ALL.
+    g_assert_cmpstr(clipboardText.get(), ==, "All work and no play make Jack a dull boy.");
+}
+
+static void testWebViewEditorSelectAllEditable(EditorTest* test, gconstpointer)
+{
+    static const char* selectedSpanHTML = "<html><body contentEditable=\"true\">"
+        "<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>";
+
+    g_assert(test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_SELECT_ALL));
+
+    test->loadHtml(selectedSpanHTML, 0);
+    test->waitUntilLoadFinished();
+
+    g_assert(test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_SELECT_ALL));
+
+    test->copyClipboard();
+    GOwnPtr<char> clipboardText(gtk_clipboard_wait_for_text(test->m_clipboard));
+
+    // Initially only the subspan is selected.
+    g_assert_cmpstr(clipboardText.get(), ==, "make Jack a dull");
+
+    webkit_web_view_execute_editing_command(test->m_webView, WEBKIT_EDITING_COMMAND_SELECT_ALL);
+    test->copyClipboard();
+    clipboardText.set(gtk_clipboard_wait_for_text(test->m_clipboard));
+
+    // The mainspan should be selected after calling SELECT_ALL.
+    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);
+    EditorTest::add("WebKitWebView", "select-all/non-editable", testWebViewEditorSelectAllNonEditable);
+    EditorTest::add("WebKitWebView", "select-all/editable", testWebViewEditorSelectAllEditable);
 }
 
 void afterAll()
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to