Commit 5693f3c5 authored by commit-queue@webkit.org's avatar commit-queue@webkit.org
Browse files

[GTK] Add Select All method to WebKit2 GTK+ API

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

Patch by Simon Pena <spena@igalia.com> 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):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@129399 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 1bb443f1
2012-09-24 Simon Pena <spena@igalia.com>
[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 <boliu@chromium.org>
 
Reland "Add in-place reload behavior to ImagesEnabled setting" with optimizations
......
......@@ -62,6 +62,15 @@ G_BEGIN_DECLS
*/
#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
......
......@@ -70,6 +70,7 @@ WebKitSaveMode
WEBKIT_EDITING_COMMAND_CUT
WEBKIT_EDITING_COMMAND_COPY
WEBKIT_EDITING_COMMAND_PASTE
WEBKIT_EDITING_COMMAND_SELECT_ALL
<SUBSECTION>
webkit_web_view_new
......
......@@ -131,10 +131,70 @@ static void testWebViewEditorCutCopyPasteEditable(EditorTest* test, gconstpointe
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()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment