Changeset 90109 in webkit


Ignore:
Timestamp:
Jun 30, 2011, 6:02:47 AM (14 years ago)
Author:
Carlos Garcia Campos
Message:

2011-06-30 Carlos Garcia Campos <cgarcia@igalia.com>

Reviewed by Martin Robinson.

[GTK] Add back/forward menu to MiniBrowser toolbar
https://bugs.webkit.org/show_bug.cgi?id=63445

  • MiniBrowser/gtk/BrowserWindow.c: (browser_window_init): Use a GtkMenuToolButton for navigation widgets. (browserWindowConstructed): Get the page BackForwardList. (browserWindowHistoryItemActivated): Go to activated history item. (browserWindowHistoryItemSelected): Show the url of currently selected history item in the statusbar. (createGtkActionFromBackForwardItem): Create a GtkAction from a WKBackForwardListItemRef. (browserWindowCreateMenuItemFromBackForwardItem): Create a GtkMenuItem from a WKBackForwardListItemRef. (browserWindowCreateBackForwardMenu): Create a GtkMenu with the given history items. (browserWindowUpdateNavigationActions): Update navigation widgets sensitivity and history menus. (didChangeBackForwardList): Call browserWindowUpdateNavigationActions(). (browserWindowLoaderClientInit): Add didChangeBackForwardList callback.
Location:
trunk/Tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r90108 r90109  
     12011-06-30  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        Reviewed by Martin Robinson.
     4
     5        [GTK] Add back/forward menu to MiniBrowser toolbar
     6        https://bugs.webkit.org/show_bug.cgi?id=63445
     7
     8        * MiniBrowser/gtk/BrowserWindow.c:
     9        (browser_window_init): Use a GtkMenuToolButton for navigation
     10        widgets.
     11        (browserWindowConstructed): Get the page BackForwardList.
     12        (browserWindowHistoryItemActivated): Go to activated history item.
     13        (browserWindowHistoryItemSelected): Show the url of currently
     14        selected history item in the statusbar.
     15        (createGtkActionFromBackForwardItem): Create a GtkAction from a
     16        WKBackForwardListItemRef.
     17        (browserWindowCreateMenuItemFromBackForwardItem): Create a
     18        GtkMenuItem from a WKBackForwardListItemRef.
     19        (browserWindowCreateBackForwardMenu): Create a GtkMenu with the
     20        given history items.
     21        (browserWindowUpdateNavigationActions): Update navigation widgets
     22        sensitivity and history menus.
     23        (didChangeBackForwardList): Call
     24        browserWindowUpdateNavigationActions().
     25        (browserWindowLoaderClientInit): Add didChangeBackForwardList
     26        callback.
     27
    1282011-06-30  Dmitry Lomov  <dslomov@google.com>
    229
  • trunk/Tools/MiniBrowser/gtk/BrowserWindow.c

    r88912 r90109  
    4040    GtkWidget *uriEntry;
    4141    GtkWidget *statusBar;
     42    GtkWidget *backItem;
     43    GtkWidget *forwardItem;
    4244    WKViewRef webView;
    4345
    4446    guint statusBarContextId;
     47    WKBackForwardListRef history;
    4548
    4649    gchar *title;
     
    130133    gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH_HORIZ);
    131134
    132     GtkToolItem *item = gtk_tool_button_new_from_stock(GTK_STOCK_GO_BACK);
     135    GtkToolItem *item = gtk_menu_tool_button_new_from_stock(GTK_STOCK_GO_BACK);
     136    window->backItem = GTK_WIDGET(item);
     137    gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(item), 0);
    133138    g_signal_connect_swapped(item, "clicked", G_CALLBACK(goBackCallback), (gpointer)window);
    134139    gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
    135140    gtk_widget_show(GTK_WIDGET(item));
    136141
    137     item = gtk_tool_button_new_from_stock(GTK_STOCK_GO_FORWARD);
     142    item = gtk_menu_tool_button_new_from_stock(GTK_STOCK_GO_FORWARD);
     143    window->forwardItem = GTK_WIDGET(item);
     144    gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(item), 0);
    138145    g_signal_connect_swapped(G_OBJECT(item), "clicked", G_CALLBACK(goForwardCallback), (gpointer)window);
    139146    gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
     
    172179    gtk_box_pack_start(GTK_BOX(window->mainBox), window->statusBar, FALSE, FALSE, 0);
    173180    gtk_widget_show(window->statusBar);
     181
     182    window->history = WKPageGetBackForwardList(WKViewGetPage(window->webView));
    174183
    175184    browserWindowLoaderClientInit(window);
     
    250259}
    251260
     261static void browserWindowHistoryItemActivated(BrowserWindow *window, GtkAction *action)
     262{
     263    WKBackForwardListItemRef item = g_object_get_data(G_OBJECT(action), "back-forward-list-item");
     264    if (!item)
     265        return;
     266
     267    WKPageGoToBackForwardListItem(WKViewGetPage(window->webView), item);
     268}
     269
     270static void browserWindowHistoryItemSelected(BrowserWindow *window, GtkMenuItem *item)
     271{
     272    gtk_statusbar_pop(GTK_STATUSBAR(window->statusBar), window->statusBarContextId);
     273
     274    GtkAction *action = gtk_activatable_get_related_action(GTK_ACTIVATABLE(item));
     275    if (!action)
     276        return;
     277
     278    gtk_statusbar_push(GTK_STATUSBAR(window->statusBar), window->statusBarContextId, gtk_action_get_name(action));
     279}
     280
     281static GtkAction *createGtkActionFromBackForwardItem(WKBackForwardListItemRef item)
     282{
     283    if (!item)
     284        return 0;
     285
     286    WKURLRef url = WKBackForwardListItemCopyURL(item);
     287    char *name = WKURLGetCString(url);
     288    WKRelease(url);
     289
     290    WKStringRef title = WKBackForwardListItemCopyTitle(item);
     291    char *label = WKStringGetCString(title);
     292    WKRelease(title);
     293
     294    GtkAction *action = gtk_action_new(name, label, 0, 0);
     295    g_free(name);
     296    g_free(label);
     297
     298    return action;
     299}
     300
     301static GtkWidget *browserWindowCreateMenuItemFromBackForwardItem(BrowserWindow *window, WKBackForwardListItemRef item)
     302{
     303    GtkAction *action = createGtkActionFromBackForwardItem(item);
     304    if (!action)
     305        return 0;
     306
     307    g_object_set_data_full(G_OBJECT(action), "back-forward-list-item", (gpointer)WKRetain(item), (GDestroyNotify)WKRelease);
     308    g_signal_connect_swapped(action, "activate", G_CALLBACK(browserWindowHistoryItemActivated), window);
     309
     310    GtkWidget *menuItem = gtk_action_create_menu_item(action);
     311    g_signal_connect_swapped(menuItem, "select", G_CALLBACK(browserWindowHistoryItemSelected), window);
     312    g_object_unref(action);
     313
     314    return menuItem;
     315}
     316
     317static GtkWidget *browserWindowCreateBackForwardMenu(BrowserWindow *window, WKArrayRef list)
     318{
     319    if (!list)
     320        return 0;
     321
     322    guint listCount = WKArrayGetSize(list);
     323    if (!listCount)
     324        return 0;
     325
     326    GtkWidget *menu = gtk_menu_new();
     327    gboolean hasItems = FALSE;
     328    guint i;
     329    for (i = 0; i < listCount; i++) {
     330        WKBackForwardListItemRef item = WKArrayGetItemAtIndex(list, i);
     331        GtkWidget *menuItem = browserWindowCreateMenuItemFromBackForwardItem(window, item);
     332        if (!menuItem)
     333            continue;
     334
     335        gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), menuItem);
     336        gtk_widget_show(menuItem);
     337        hasItems = TRUE;
     338    }
     339
     340    if (!hasItems) {
     341        gtk_widget_destroy(menu);
     342        return 0;
     343    }
     344
     345    return menu;
     346}
     347
     348static void browserWindowUpdateNavigationActions(BrowserWindow* window)
     349{
     350    gtk_widget_set_sensitive(window->backItem, WKPageCanGoBack(WKViewGetPage(window->webView)));
     351    gtk_widget_set_sensitive(window->forwardItem, WKPageCanGoForward(WKViewGetPage(window->webView)));
     352
     353    WKArrayRef list = WKBackForwardListCopyBackListWithLimit(window->history, 10);
     354    GtkWidget *menu = browserWindowCreateBackForwardMenu(window, list);
     355    gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(window->backItem), menu);
     356    if (list)
     357        WKRelease(list);
     358
     359    list = WKBackForwardListCopyForwardListWithLimit(window->history, 10);
     360    menu = browserWindowCreateBackForwardMenu(window, list);
     361    gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(window->forwardItem), menu);
     362    if (list)
     363        WKRelease(list);
     364}
     365
    252366// Loader client.
    253367static void didStartProvisionalLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo)
     
    365479static void didBecomeResponsive(WKPageRef page, const void* clientInfo)
    366480{
     481}
     482
     483static void didChangeBackForwardList(WKPageRef page, WKBackForwardListItemRef addedItem, WKArrayRef removedItems, const void *clientInfo)
     484{
     485    browserWindowUpdateNavigationActions(BROWSER_WINDOW(clientInfo));
    367486}
    368487
     
    394513        didBecomeResponsive,
    395514        0,       /* processDidCrash */
    396         0,       /* didChangeBackForwardList */
     515        didChangeBackForwardList,
    397516        0,       /* shouldGoToBackForwardListItem */
    398517        0        /* didFailToInitializePlugin */
Note: See TracChangeset for help on using the changeset viewer.