Changeset 178703 in webkit


Ignore:
Timestamp:
Jan 20, 2015 3:22:03 AM (9 years ago)
Author:
commit-queue@webkit.org
Message:

[GTK] Add API to set the web view editable into WebKit2 GTK+ API
https://bugs.webkit.org/show_bug.cgi?id=139443

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

Source/WebKit2:

Provide a way to set the web view editable, without accessing the DOM
and setting the contenteditable attribute to elements.

  • UIProcess/API/gtk/WebKitWebView.cpp:

(webkitWebViewSetProperty):
(webkitWebViewGetProperty):
(webkit_web_view_class_init):
(webkit_web_view_is_editable):
(webkit_web_view_set_editable):

  • UIProcess/API/gtk/WebKitWebView.h:
  • UIProcess/API/gtk/docs/webkit2gtk-sections.txt:

Tools:

Create the new test cases for setting the editable property on the web
view and on the contenteditable enabled document. Also rework the
current tests that are expecting that the web view is editable.

  • TestWebKitAPI/Tests/WebKit2Gtk/TestWebViewEditor.cpp:

(loadTestHtml):
(testWebViewEditorCutCopyPasteNonEditable):
(testWebViewEditorCutCopyPasteEditable):
(testWebViewEditorSelectAllNonEditable):
(testWebViewEditorSelectAllEditable):
(runEditorEditableCutTests):
(testWebViewEditorEditableOnNonEditable):
(testWebViewEditorEditableOnContentEditable):
(testWebViewEditorNonEditable):
(beforeAll):

  • TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp:

(WebViewTest::isEditable):
(WebViewTest::setEditable):

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r178700 r178703  
     12015-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
    1202015-01-20  Carlos Garcia Campos  <cgarcia@igalia.com>
    221
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp

    r178700 r178703  
    150150    PROP_ZOOM_LEVEL,
    151151    PROP_IS_LOADING,
    152     PROP_IS_PLAYING_AUDIO
     152    PROP_IS_PLAYING_AUDIO,
     153    PROP_EDITABLE
    153154};
    154155
     
    688689    case PROP_ZOOM_LEVEL:
    689690        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));
    690694        break;
    691695    default:
     
    729733        g_value_set_boolean(value, webkit_web_view_is_playing_audio(webView));
    730734        break;
     735    case PROP_EDITABLE:
     736        g_value_set_boolean(value, webkit_web_view_is_editable(webView));
     737        break;
    731738    default:
    732739        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
     
    958965            FALSE,
    959966            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));
    960985
    961986    /**
     
    35743599    *rgba = getPage(webView)->backgroundColor();
    35753600}
     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 */
     3615gboolean 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 */
     3640void 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  
    486486                                                      GdkRGBA                   *rgba);
    487487
     488WEBKIT_API gboolean
     489webkit_web_view_is_editable                          (WebKitWebView             *web_view);
     490
     491WEBKIT_API void
     492webkit_web_view_set_editable                         (WebKitWebView             *web_view,
     493                                                      gboolean                  editable);
     494
    488495G_END_DECLS
    489496
  • trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt

    r178699 r178703  
    202202webkit_web_view_set_background_color
    203203webkit_web_view_get_background_color
     204webkit_web_view_set_editable
     205webkit_web_view_is_editable
    204206
    205207<SUBSECTION WebKitJavascriptResult>
  • trunk/Tools/ChangeLog

    r178700 r178703  
     12015-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
    1272015-01-20  Carlos Garcia Campos  <cgarcia@igalia.com>
    228
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebViewEditor.cpp

    r163797 r178703  
    7474    }
    7575
     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
    7691    GtkClipboard* m_clipboard;
    7792    bool m_canExecuteEditingCommand;
     
    7994};
    8095
     96static 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
    81103static void testWebViewEditorCutCopyPasteNonEditable(EditorTest* test, gconstpointer)
    82104{
    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 
    89105    // Nothing loaded yet.
    90106    g_assert(!test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_CUT));
     
    92108    g_assert(!test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_PASTE));
    93109
    94     test->loadHtml(selectedSpanHTML, 0);
     110    GUniquePtr<char> selectedSpanHTML(g_strdup_printf(selectedSpanHTMLFormat, "false"));
     111    test->loadHtml(selectedSpanHTML.get(), nullptr);
    95112    test->waitUntilLoadFinished();
    96113
     
    108125static void testWebViewEditorCutCopyPasteEditable(EditorTest* test, gconstpointer)
    109126{
    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 
    116127    // Nothing loaded yet.
    117128    g_assert(!test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_CUT));
     
    119130    g_assert(!test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_PASTE));
    120131
    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);
    122138    test->waitUntilLoadFinished();
    123139
     
    129145    test->copyClipboard();
    130146    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");
    132148}
    133149
    134150static void testWebViewEditorSelectAllNonEditable(EditorTest* test, gconstpointer)
    135151{
    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);
    145156    test->waitUntilLoadFinished();
    146157
     
    163174static void testWebViewEditorSelectAllEditable(EditorTest* test, gconstpointer)
    164175{
    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);
    174184    test->waitUntilLoadFinished();
    175185
     
    190200}
    191201
     202static 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
     224static 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
     241static 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
    192258void beforeAll()
    193259{
     260    EditorTest::add("WebKitWebView", "editable/editable", testWebViewEditorEditable);
    194261    EditorTest::add("WebKitWebView", "cut-copy-paste/non-editable", testWebViewEditorCutCopyPasteNonEditable);
    195262    EditorTest::add("WebKitWebView", "cut-copy-paste/editable", testWebViewEditorCutCopyPasteEditable);
  • trunk/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp

    r178644 r178703  
    263263}
    264264
     265bool WebViewTest::isEditable()
     266{
     267    webkit_web_view_is_editable(m_webView);
     268}
     269
     270void WebViewTest::setEditable(bool editable)
     271{
     272    webkit_web_view_set_editable(m_webView, editable);
     273}
     274
    265275static void resourceGetDataCallback(GObject* object, GAsyncResult* result, gpointer userData)
    266276{
  • trunk/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h

    r178644 r178703  
    5454    const char* mainResourceData(size_t& mainResourceDataSize);
    5555
     56    bool isEditable();
     57    void setEditable(bool);
     58
    5659    void mouseMoveTo(int x, int y, unsigned mouseModifiers = 0);
    5760    void clickMouseButton(int x, int y, unsigned button = 1, unsigned mouseModifiers = 0);
Note: See TracChangeset for help on using the changeset viewer.