Changeset 178703 in webkit
- Timestamp:
- Jan 20, 2015 3:22:03 AM (9 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r178700 r178703 1 2015-01-20 Tomas Popela <tpopela@redhat.com> 2 3 [GTK] Add API to set the web view editable into WebKit2 GTK+ API 4 https://bugs.webkit.org/show_bug.cgi?id=139443 5 6 Reviewed by Carlos Garcia Campos. 7 8 Provide a way to set the web view editable, without accessing the DOM 9 and setting the contenteditable attribute to elements. 10 11 * UIProcess/API/gtk/WebKitWebView.cpp: 12 (webkitWebViewSetProperty): 13 (webkitWebViewGetProperty): 14 (webkit_web_view_class_init): 15 (webkit_web_view_is_editable): 16 (webkit_web_view_set_editable): 17 * UIProcess/API/gtk/WebKitWebView.h: 18 * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: 19 1 20 2015-01-20 Carlos Garcia Campos <cgarcia@igalia.com> 2 21 -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp
r178700 r178703 150 150 PROP_ZOOM_LEVEL, 151 151 PROP_IS_LOADING, 152 PROP_IS_PLAYING_AUDIO 152 PROP_IS_PLAYING_AUDIO, 153 PROP_EDITABLE 153 154 }; 154 155 … … 688 689 case PROP_ZOOM_LEVEL: 689 690 webkit_web_view_set_zoom_level(webView, g_value_get_double(value)); 691 break; 692 case PROP_EDITABLE: 693 webkit_web_view_set_editable(webView, g_value_get_boolean(value)); 690 694 break; 691 695 default: … … 729 733 g_value_set_boolean(value, webkit_web_view_is_playing_audio(webView)); 730 734 break; 735 case PROP_EDITABLE: 736 g_value_set_boolean(value, webkit_web_view_is_editable(webView)); 737 break; 731 738 default: 732 739 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec); … … 958 965 FALSE, 959 966 WEBKIT_PARAM_READABLE)); 967 968 /** 969 * WebKitWebView:editable: 970 * 971 * Whether the pages loaded inside #WebKitWebView are editable. For more 972 * information see webkit_web_view_set_editable(). 973 * 974 * Since: 2.8 975 */ 976 g_object_class_install_property( 977 gObjectClass, 978 PROP_EDITABLE, 979 g_param_spec_boolean( 980 "editable", 981 _("Editable"), 982 _("Whether the content can be modified by the user."), 983 FALSE, 984 WEBKIT_PARAM_READWRITE)); 960 985 961 986 /** … … 3574 3599 *rgba = getPage(webView)->backgroundColor(); 3575 3600 } 3601 3602 /* 3603 * webkit_web_view_is_editable: 3604 * @web_view: a #WebKitWebView 3605 * 3606 * Gets whether the user is allowed to edit the HTML document. When @web_view 3607 * is not editable an element in the HTML document can only be edited if the 3608 * CONTENTEDITABLE attribute has been set on the element or one of its parent 3609 * elements. By default a #WebKitWebView is not editable. 3610 * 3611 * Returns: %TRUE if the user is allowed to edit the HTML document, or %FALSE otherwise. 3612 * 3613 * Since: 2.8 3614 */ 3615 gboolean webkit_web_view_is_editable(WebKitWebView* webView) 3616 { 3617 g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE); 3618 3619 return getPage(webView)->isEditable(); 3620 } 3621 3622 /** 3623 * webkit_web_view_set_editable: 3624 * @web_view: a #WebKitWebView 3625 * @editable: a #gboolean indicating the editable state 3626 * 3627 * Sets whether the user is allowed to edit the HTML document. 3628 * 3629 * If @editable is %TRUE, @web_view allows the user to edit the HTML document. If 3630 * @editable is %FALSE, an element in @web_view's document can only be edited if the 3631 * CONTENTEDITABLE attribute has been set on the element or one of its parent 3632 * elements. By default a #WebKitWebView is not editable. 3633 * 3634 * Normally, a HTML document is not editable unless the elements within the 3635 * document are editable. This function provides a way to make the contents 3636 * of a #WebKitWebView editable without altering the document or DOM structure. 3637 * 3638 * Since: 2.8 3639 */ 3640 void webkit_web_view_set_editable(WebKitWebView* webView, gboolean editable) 3641 { 3642 g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); 3643 3644 if (editable == getPage(webView)->isEditable()) 3645 return; 3646 3647 getPage(webView)->setEditable(editable); 3648 3649 g_object_notify(G_OBJECT(webView), "editable"); 3650 } -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h
r178700 r178703 486 486 GdkRGBA *rgba); 487 487 488 WEBKIT_API gboolean 489 webkit_web_view_is_editable (WebKitWebView *web_view); 490 491 WEBKIT_API void 492 webkit_web_view_set_editable (WebKitWebView *web_view, 493 gboolean editable); 494 488 495 G_END_DECLS 489 496 -
trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt
r178699 r178703 202 202 webkit_web_view_set_background_color 203 203 webkit_web_view_get_background_color 204 webkit_web_view_set_editable 205 webkit_web_view_is_editable 204 206 205 207 <SUBSECTION WebKitJavascriptResult> -
trunk/Tools/ChangeLog
r178700 r178703 1 2015-01-20 Tomas Popela <tpopela@redhat.com> 2 3 [GTK] Add API to set the web view editable into WebKit2 GTK+ API 4 https://bugs.webkit.org/show_bug.cgi?id=139443 5 6 Reviewed by Carlos Garcia Campos. 7 8 Create the new test cases for setting the editable property on the web 9 view and on the contenteditable enabled document. Also rework the 10 current tests that are expecting that the web view is editable. 11 12 * TestWebKitAPI/Tests/WebKit2Gtk/TestWebViewEditor.cpp: 13 (loadTestHtml): 14 (testWebViewEditorCutCopyPasteNonEditable): 15 (testWebViewEditorCutCopyPasteEditable): 16 (testWebViewEditorSelectAllNonEditable): 17 (testWebViewEditorSelectAllEditable): 18 (runEditorEditableCutTests): 19 (testWebViewEditorEditableOnNonEditable): 20 (testWebViewEditorEditableOnContentEditable): 21 (testWebViewEditorNonEditable): 22 (beforeAll): 23 * TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp: 24 (WebViewTest::isEditable): 25 (WebViewTest::setEditable): 26 1 27 2015-01-20 Carlos Garcia Campos <cgarcia@igalia.com> 2 28 -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebViewEditor.cpp
r163797 r178703 74 74 } 75 75 76 gchar* cutSelection() 77 { 78 g_assert(canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_CUT)); 79 g_assert(canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_PASTE)); 80 81 webkit_web_view_execute_editing_command(m_webView, WEBKIT_EDITING_COMMAND_CUT); 82 // There's no way to know when the selection has been cut to 83 // the clipboard, so use a timeout source to query the clipboard. 84 m_triesCount = 0; 85 g_timeout_add(kClipboardWaitTimeout, reinterpret_cast<GSourceFunc>(waitForClipboardText), this); 86 g_main_loop_run(m_mainLoop); 87 88 return gtk_clipboard_wait_for_text (m_clipboard); 89 } 90 76 91 GtkClipboard* m_clipboard; 77 92 bool m_canExecuteEditingCommand; … … 79 94 }; 80 95 96 static const char* selectedSpanHTMLFormat = 97 "<html><body contentEditable=\"%s\">" 98 "<span id=\"mainspan\">All work and no play <span id=\"subspan\">make Jack a dull</span> boy.</span>" 99 "<script>document.getSelection().collapse();\n" 100 "document.getSelection().selectAllChildren(document.getElementById('subspan'));\n" 101 "</script></body></html>"; 102 81 103 static void testWebViewEditorCutCopyPasteNonEditable(EditorTest* test, gconstpointer) 82 104 { 83 static const char* selectedSpanHTML = "<html><body contentEditable=\"false\">"84 "<span id=\"mainspan\">All work and no play <span id=\"subspan\">make Jack a dull</span> boy.</span>"85 "<script>document.getSelection().collapse();\n"86 "document.getSelection().selectAllChildren(document.getElementById('subspan'));\n"87 "</script></body></html>";88 89 105 // Nothing loaded yet. 90 106 g_assert(!test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_CUT)); … … 92 108 g_assert(!test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_PASTE)); 93 109 94 test->loadHtml(selectedSpanHTML, 0); 110 GUniquePtr<char> selectedSpanHTML(g_strdup_printf(selectedSpanHTMLFormat, "false")); 111 test->loadHtml(selectedSpanHTML.get(), nullptr); 95 112 test->waitUntilLoadFinished(); 96 113 … … 108 125 static void testWebViewEditorCutCopyPasteEditable(EditorTest* test, gconstpointer) 109 126 { 110 static const char* selectedSpanHTML = "<html><body contentEditable=\"true\">"111 "<span id=\"mainspan\">All work and no play <span>make Jack a dull</span> boy.</span>"112 "<script>document.getSelection().collapse();\n"113 "document.getSelection().selectAllChildren(document.getElementById('mainspan'));\n"114 "</script></body></html>";115 116 127 // Nothing loaded yet. 117 128 g_assert(!test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_CUT)); … … 119 130 g_assert(!test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_PASTE)); 120 131 121 test->loadHtml(selectedSpanHTML, 0); 132 g_assert(!test->isEditable()); 133 test->setEditable(true); 134 g_assert(test->isEditable()); 135 136 GUniquePtr<char> selectedSpanHTML(g_strdup_printf(selectedSpanHTMLFormat, "false")); 137 test->loadHtml(selectedSpanHTML.get(), nullptr); 122 138 test->waitUntilLoadFinished(); 123 139 … … 129 145 test->copyClipboard(); 130 146 GUniquePtr<char> clipboardText(gtk_clipboard_wait_for_text(test->m_clipboard)); 131 g_assert_cmpstr(clipboardText.get(), ==, " All work and no play make Jack a dull boy.");147 g_assert_cmpstr(clipboardText.get(), ==, "make Jack a dull"); 132 148 } 133 149 134 150 static void testWebViewEditorSelectAllNonEditable(EditorTest* test, gconstpointer) 135 151 { 136 static const char* selectedSpanHTML = "<html><body contentEditable=\"false\">" 137 "<span id=\"mainspan\">All work and no play <span id=\"subspan\">make Jack a dull</span> boy.</span>" 138 "<script>document.getSelection().collapse();\n" 139 "document.getSelection().selectAllChildren(document.getElementById('subspan'));\n" 140 "</script></body></html>"; 141 142 g_assert(test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_SELECT_ALL)); 143 144 test->loadHtml(selectedSpanHTML, 0); 152 g_assert(test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_SELECT_ALL)); 153 154 GUniquePtr<char> selectedSpanHTML(g_strdup_printf(selectedSpanHTMLFormat, "false")); 155 test->loadHtml(selectedSpanHTML.get(), nullptr); 145 156 test->waitUntilLoadFinished(); 146 157 … … 163 174 static void testWebViewEditorSelectAllEditable(EditorTest* test, gconstpointer) 164 175 { 165 static const char* selectedSpanHTML = "<html><body contentEditable=\"true\">" 166 "<span id=\"mainspan\">All work and no play <span id=\"subspan\">make Jack a dull</span> boy.</span>" 167 "<script>document.getSelection().collapse();\n" 168 "document.getSelection().selectAllChildren(document.getElementById('subspan'));\n" 169 "</script></body></html>"; 170 171 g_assert(test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_SELECT_ALL)); 172 173 test->loadHtml(selectedSpanHTML, 0); 176 g_assert(test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_SELECT_ALL)); 177 178 g_assert(!test->isEditable()); 179 test->setEditable(true); 180 g_assert(test->isEditable()); 181 182 GUniquePtr<char> selectedSpanHTML(g_strdup_printf(selectedSpanHTMLFormat, "false")); 183 test->loadHtml(selectedSpanHTML.get(), nullptr); 174 184 test->waitUntilLoadFinished(); 175 185 … … 190 200 } 191 201 202 static void loadContentsAndTryToCutSelection(EditorTest* test, bool contentEditable) 203 { 204 // View is not editable by default. 205 g_assert(!test->isEditable()); 206 207 GUniquePtr<char> selectedSpanHTML(g_strdup_printf(selectedSpanHTMLFormat, contentEditable ? "true" : "false")); 208 test->loadHtml(selectedSpanHTML.get(), nullptr); 209 test->waitUntilLoadFinished(); 210 211 g_assert(!test->isEditable()); 212 test->setEditable(true); 213 g_assert(test->isEditable()); 214 215 // Cut the selection to the clipboard to see if the view is indeed editable. 216 GUniquePtr<char> clipboardText(test->cutSelection()); 217 g_assert_cmpstr(clipboardText.get(), ==, "make Jack a dull"); 218 219 // Reset the editable for next test. 220 test->setEditable(false); 221 g_assert(!test->isEditable()); 222 } 223 224 static void testWebViewEditorNonEditable(EditorTest* test) 225 { 226 GUniquePtr<char> selectedSpanHTML(g_strdup_printf(selectedSpanHTMLFormat, "false")); 227 test->loadHtml(selectedSpanHTML.get(), nullptr); 228 test->waitUntilLoadFinished(); 229 230 g_assert(!test->isEditable()); 231 test->setEditable(true); 232 g_assert(test->isEditable()); 233 test->setEditable(false); 234 g_assert(!test->isEditable()); 235 236 // Check if view is indeed non-editable. 237 g_assert(!test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_CUT)); 238 g_assert(!test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_PASTE)); 239 } 240 241 static void testWebViewEditorEditable(EditorTest* test, gconstpointer) 242 { 243 testWebViewEditorNonEditable(test); 244 245 // Reset the editable for next test. 246 test->setEditable(false); 247 g_assert(!test->isEditable()); 248 249 loadContentsAndTryToCutSelection(test, true); 250 251 // Reset the editable for next test. 252 test->setEditable(false); 253 g_assert(!test->isEditable()); 254 255 loadContentsAndTryToCutSelection(test, false); 256 } 257 192 258 void beforeAll() 193 259 { 260 EditorTest::add("WebKitWebView", "editable/editable", testWebViewEditorEditable); 194 261 EditorTest::add("WebKitWebView", "cut-copy-paste/non-editable", testWebViewEditorCutCopyPasteNonEditable); 195 262 EditorTest::add("WebKitWebView", "cut-copy-paste/editable", testWebViewEditorCutCopyPasteEditable); -
trunk/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp
r178644 r178703 263 263 } 264 264 265 bool WebViewTest::isEditable() 266 { 267 webkit_web_view_is_editable(m_webView); 268 } 269 270 void WebViewTest::setEditable(bool editable) 271 { 272 webkit_web_view_set_editable(m_webView, editable); 273 } 274 265 275 static void resourceGetDataCallback(GObject* object, GAsyncResult* result, gpointer userData) 266 276 { -
trunk/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h
r178644 r178703 54 54 const char* mainResourceData(size_t& mainResourceDataSize); 55 55 56 bool isEditable(); 57 void setEditable(bool); 58 56 59 void mouseMoveTo(int x, int y, unsigned mouseModifiers = 0); 57 60 void clickMouseButton(int x, int y, unsigned button = 1, unsigned mouseModifiers = 0);
Note: See TracChangeset
for help on using the changeset viewer.