static void icon_cb (GObject *obj, GParamSpec *spec, GtkWindow *dlg) { GdkPixbuf *pb = gdk_pixbuf_get_from_surface (webkit_web_view_get_favicon (view), 0, 0, -1, -1); if (pb) { gtk_window_set_icon (dlg, pb); g_object_unref (pb); } }
static void testWebViewFavicon(FaviconDatabaseTest* test) { test->m_faviconURI = CString(); cairo_surface_t* iconFromWebView = webkit_web_view_get_favicon(test->m_webView); g_assert(!iconFromWebView); test->loadURI(kServer->getURIForPath("/foo").data()); test->waitUntilFaviconChanged(); g_assert(test->m_faviconNotificationReceived); // The icon is known and hasn't changed in the database, so notify::favicon is emitted // but WebKitFaviconDatabase::icon-changed isn't. g_assert(test->m_faviconURI.isNull()); iconFromWebView = webkit_web_view_get_favicon(test->m_webView); g_assert(iconFromWebView); g_assert_cmpuint(cairo_image_surface_get_width(iconFromWebView), ==, 16); g_assert_cmpuint(cairo_image_surface_get_height(iconFromWebView), ==, 16); }
static void faviconChanged(GObject *object, GParamSpec *paramSpec, BrowserWindow *window) { GdkPixbuf *favicon = NULL; cairo_surface_t *surface = webkit_web_view_get_favicon(window->webView); if (surface) { int width = cairo_image_surface_get_width(surface); int height = cairo_image_surface_get_height(surface); favicon = gdk_pixbuf_get_from_surface(surface, 0, 0, width, height); } if (window->favicon) g_object_unref(window->favicon); window->favicon = favicon; updateUriEntryIcon(window); HS_favicon_changed(surface, window->webView); //add by zlf }
static void collecturiCallback(BrowserWindow *window, GtkEntryIconPosition iconPosition, GdkEvent *event) { if (iconPosition == GTK_ENTRY_ICON_SECONDARY) { g_print("add bookmarkbutton\n"); /* GtkWidget *bookmarkbtn = gtk_button_new(); GtkBox *hBox = GTK_BOX(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0));` GtkWidget *image = gtk_image_new_from_pixbuf(window->favicon); GtkWidget *lab = gtk_label_new(webkit_web_view_get_title(window->webView)); gtk_box_pack_start(hBox, image, FALSE, FALSE, 0); gtk_box_pack_start(hBox, lab, FALSE, FALSE, 0); gtk_container_add(GTK_CONTAINER(bookmarkbtn), hBox); gtk_box_pack_start(window->bookmarkbox, bookmarkbtn, FALSE, FALSE, 0); gtk_widget_show_all(bookmarkbtn); */ GtkToolItem *item = gtk_tool_button_new(NULL, ""); GtkWidget *image = gtk_image_new_from_pixbuf(window->favicon); cairo_surface_t* fivacon = webkit_web_view_get_favicon(window->webView); gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (item), fivacon); GtkWidget* label = gtk_label_new (webkit_web_view_get_title(window->webView)); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_label_set_max_width_chars (GTK_LABEL (label), 25); gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_MIDDLE); gtk_widget_show (label); gtk_tool_button_set_label_widget (GTK_TOOL_BUTTON (item), label); // g_signal_connect_swapped(item, "clicked", G_CALLBACK(goBackCallback), (gpointer)window); gtk_toolbar_insert(GTK_TOOLBAR(window->bookmarkbar), item, -1); gtk_widget_show_all(GTK_WIDGET(item)); /* GtkToolItem *item = gtk_tool_button_new_from_stock(GTK_STOCK_HOME); // g_signal_connect_swapped(item, "clicked", G_CALLBACK(goBackCallback), (gpointer)window); gtk_toolbar_insert(GTK_TOOLBAR(window->bookmarkbar), item, -1); gtk_widget_show(GTK_WIDGET(item)); */ // GdkEventButton *eventButton = (GdkEventButton *)event; //todo 弹出对话框 } }
void onFaviconChange(WebKitWebView *webview, GParamSpec *param, RuskWindow *rusk) { cairo_surface_t *favicon; int width, height; GdkPixbuf *pixbuf; if((favicon = webkit_web_view_get_favicon(rusk->webview)) == NULL) { return; } width = cairo_image_surface_get_width(favicon); height = cairo_image_surface_get_height(favicon); if(width <= 0 || height <= 0) { return; } pixbuf = gdk_pixbuf_get_from_surface(favicon, 0, 0, width, height); gtk_window_set_icon(rusk->window, pixbuf); }