Changeset 55300 in webkit


Ignore:
Timestamp:
Feb 26, 2010 12:32:52 PM (14 years ago)
Author:
tonikitoo@webkit.org
Message:

[GTK] Make webkit_web_view_grab_focus to active focus controller.
https://bugs.webkit.org/show_bug.cgi?id=35402

Reviewed by Xan Lopez.
Patch by Antonio Gomes <tonikitoo@webkit.org>

When programatically setting focus to an element in an inner document,
calling "hasFocus()" from this document returns FALSE, because
document's FocusController is not activated. It does not happen
if |document| is the main document.

Making webkit_web_view_grab_focus to actually activate the FocusController,
fixes the issue.

  • tests/testwebview.c:

(server_callback):
(test_webkit_web_view_grab_focus):

  • webkit/webkitwebview.cpp:

(webkit_web_view_grab_focus):

Location:
trunk/WebKit/gtk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit/gtk/ChangeLog

    r55298 r55300  
     12010-02-26  Antonio Gomes  <tonikitoo@webkit.org>
     2
     3        Reviewed by Xan Lopez.
     4        Patch by Antonio Gomes <tonikitoo@webkit.org>
     5
     6        [GTK] Make webkit_web_view_grab_focus to active focus controller.
     7        https://bugs.webkit.org/show_bug.cgi?id=35402
     8
     9        When programatically setting focus to an element in an inner document,
     10        calling "hasFocus()" from this document returns FALSE, because
     11        document's FocusController is not activated. It does not happen
     12        if |document| is the main document.
     13
     14        Making webkit_web_view_grab_focus to actually activate the FocusController,
     15        fixes the issue.
     16
     17        * tests/testwebview.c:
     18        (server_callback):
     19        (test_webkit_web_view_grab_focus):
     20        * webkit/webkitwebview.cpp:
     21        (webkit_web_view_grab_focus):
     22
    1232010-02-26  Alejandro G. Castro  <alex@igalia.com>
    224
  • trunk/WebKit/gtk/tests/testwebview.c

    r55245 r55300  
    5959        soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, contents, length);
    6060    } else if (g_str_equal(path, "/bigdiv.html")) {
    61         char* contents = g_strdup("<html><body><div style=\"background-color: green; height: 1200px;\"></div></body></html>");
     61        char* contents = g_strdup("<html><body><a id=\"link\" href=\"http://abc.def\">test</a><div style=\"background-color: green; height: 1200px;\"></div></body></html>");
    6262        soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, contents, strlen(contents));
    6363    } else if (g_str_equal(path, "/iframe.html")) {
    64         char* contents = g_strdup("<html><body><div style=\"background-color: green; height: 50px;\"></div><iframe src=\"bigdiv.html\"></iframe></body></html>");
     64        char* contents = g_strdup("<html><body id=\"some-content\"><div style=\"background-color: green; height: 50px;\"></div><iframe src=\"bigdiv.html\"></iframe></body></html>");
    6565        soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, contents, strlen(contents));
    6666    } else {
     
    136136
    137137    return FALSE;
     138}
     139
     140static void test_webkit_web_view_grab_focus()
     141{
     142    char* uri = g_strconcat(base_uri, "iframe.html", NULL);
     143    GtkWidget* window = gtk_window_new(GTK_WINDOW_POPUP);
     144    GtkWidget* scrolled_window = gtk_scrolled_window_new(NULL, NULL);
     145    WebKitWebView* view = WEBKIT_WEB_VIEW(webkit_web_view_new());
     146    GtkAdjustment* adjustment;
     147
     148    gtk_window_set_default_size(GTK_WINDOW(window), 400, 200);
     149
     150    gtk_container_add(GTK_CONTAINER(window), scrolled_window);
     151    gtk_container_add(GTK_CONTAINER(scrolled_window), GTK_WIDGET(view));
     152
     153    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
     154                                   GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
     155
     156    loop = g_main_loop_new(NULL, TRUE);
     157
     158    g_signal_connect(view, "progress", G_CALLBACK(idle_quit_loop_cb), NULL);
     159
     160    /* Wait for window to show up */
     161    gtk_widget_show_all(window);
     162    g_signal_connect(window, "map-event",
     163                     G_CALLBACK(map_event_cb), loop);
     164    g_main_loop_run(loop);
     165
     166    /* Load a page with a big div that will cause scrollbars to appear */
     167    webkit_web_view_load_uri(view, uri);
     168    g_main_loop_run(loop);
     169
     170    adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(scrolled_window));
     171    g_assert_cmpfloat(gtk_adjustment_get_value(adjustment), ==, 0.0);
     172
     173    /* Since webkit_web_view_execute_script does not return a value,
     174       it is impossible to know if an inner document has focus after
     175       a node of it was focused via .focus() method.
     176       The code below is an workaround: if the node has focus, a scroll
     177       action is performed and afterward it is checked if the adjustment
     178       has to be different from 0.
     179    */
     180    char script[] = "var innerDoc = document.defaultView.frames[0].document; \
     181                     innerDoc.getElementById(\"link\").focus();              \
     182                     if (innerDoc.hasFocus())                                \
     183                        window.scrollBy(0, 100);";
     184
     185    /* Focus an element using JavaScript */
     186    webkit_web_view_execute_script(view, script);
     187
     188    /* Make sure the ScrolledWindow noticed the scroll */
     189    g_assert_cmpfloat(gtk_adjustment_get_value(adjustment), !=, 0.0);
     190
     191    g_free(uri);
     192    gtk_widget_destroy(window);
    138193}
    139194
     
    284339    g_test_add_func("/webkit/webview/adjustments", test_webkit_web_view_adjustments);
    285340    g_test_add_func("/webkit/webview/destroy", test_webkit_web_view_destroy);
     341    g_test_add_func("/webkit/webview/grab_focus", test_webkit_web_view_grab_focus);
    286342
    287343    return g_test_run ();
  • trunk/WebKit/gtk/webkit/webkitwebview.cpp

    r55245 r55300  
    640640        WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
    641641        FocusController* focusController = core(webView)->focusController();
     642
     643        focusController->setActive(true);
    642644
    643645        if (focusController->focusedFrame())
Note: See TracChangeset for help on using the changeset viewer.