svnno****@sourc*****
svnno****@sourc*****
Fri Dec 26 10:39:37 JST 2008
Revision: 3519 http://svn.sourceforge.jp/view?root=kazehakase&view=rev&rev=3519 Author: ikezoe Date: 2008-12-26 10:39:37 +0900 (Fri, 26 Dec 2008) Log Message: ----------- * module/embed/webkit-gtk/kz-webkit-gtk.c: Now gesture works but popup menu does not work. Modified Paths: -------------- kazehakase/trunk/ChangeLog kazehakase/trunk/module/embed/webkit-gtk/kz-webkit-gtk.c Modified: kazehakase/trunk/ChangeLog =================================================================== --- kazehakase/trunk/ChangeLog 2008-12-25 23:48:36 UTC (rev 3518) +++ kazehakase/trunk/ChangeLog 2008-12-26 01:39:37 UTC (rev 3519) @@ -1,6 +1,8 @@ 2008-12-26 Hiroyuki Ikezoe <poinc****@ikezo*****> * src/kz-embed.c (kz_embed_get_last_modified): Suppress g_warning. + * module/embed/webkit-gtk/kz-webkit-gtk.c: Now gesture works but popup + menu does not work. 2008-12-25 Hiroyuki Ikezoe <poinc****@ikezo*****> Modified: kazehakase/trunk/module/embed/webkit-gtk/kz-webkit-gtk.c =================================================================== --- kazehakase/trunk/module/embed/webkit-gtk/kz-webkit-gtk.c 2008-12-25 23:48:36 UTC (rev 3518) +++ kazehakase/trunk/module/embed/webkit-gtk/kz-webkit-gtk.c 2008-12-26 01:39:37 UTC (rev 3519) @@ -49,12 +49,6 @@ static void kz_webkit_gtk_init (KzWebKitGtk *webkit_gtk); static void kz_webkit_gtk_dispose (GObject *object); -#if 0 -static gboolean button_press_event (GtkWidget *widget, - GdkEventButton *event); -static gboolean button_release_event (GtkWidget *widget, - GdkEventButton *event); -#endif static void load_url (KzEmbed *kzembed, const gchar *url); static void stop_load (KzEmbed *kzembed); @@ -140,6 +134,14 @@ WebKitWebNavigationAction *action, WebKitWebPolicyDecision *decision, gpointer data); +static gboolean cb_button_press_event + (GtkWidget *widget, + GdkEventButton *event, + gpointer data); +static gboolean cb_button_release_event + (GtkWidget *widget, + GdkEventButton *event, + gpointer data); static void set_default_preferences (KzWebKitGtk *webkit); @@ -195,10 +197,7 @@ widget_class = GTK_WIDGET_CLASS(klass); object_class->dispose = kz_webkit_gtk_dispose; -#if 0 - widget_class->button_press_event = button_press_event; - widget_class->button_release_event = button_release_event; -#endif + g_type_class_add_private(object_class, sizeof(KzWebKitGtkPrivate)); } @@ -331,6 +330,10 @@ G_CALLBACK(cb_populate_popup), webkit); g_signal_connect(priv->web_view, "navigation-policy-decision-requested", G_CALLBACK(cb_navigation_policy_decision_requested), webkit); + g_signal_connect(priv->web_view, "button-press-event", + G_CALLBACK(cb_button_press_event), webkit); + g_signal_connect(priv->web_view, "button-release-event", + G_CALLBACK(cb_button_release_event), webkit); set_default_preferences(webkit); } @@ -362,55 +365,7 @@ "vscrollbar-policy", GTK_POLICY_AUTOMATIC, NULL)); } -#if 0 -static KzEmbedEventMouse * -create_kz_embed_event_mouse (GdkEventButton *event) -{ - KzEmbedEventMouse *kzevent; - kzevent = (KzEmbedEventMouse *) kz_embed_event_new(KZ_EMBED_EVENT_MOUSE); - if (event->state & GDK_SHIFT_MASK) - kzevent->modifier |= KZ_SHIFT_KEY; - if (event->state & GDK_CONTROL_MASK) - kzevent->modifier |= KZ_CTRL_KEY; - if (event->state & GDK_MOD1_MASK) - kzevent->modifier |= KZ_ALT_KEY; - if (event->state & GDK_META_MASK) - kzevent->modifier |= KZ_META_KEY; - kzevent->x = event->x; - kzevent->y = event->y; - kzevent->button = event->button; - kzevent->cinfo.context = KZ_CONTEXT_NONE; - - return kzevent; -} - -static gboolean -button_press_event (GtkWidget *widget, GdkEventButton *event) -{ - KzEmbedEventMouse *kzevent; - gint ret = FALSE; - - kzevent = create_kz_embed_event_mouse(event); - g_signal_emit_by_name(widget, "kz-dom-mouse-down", kzevent, &ret); - kz_embed_event_free((KzEmbedEvent *) kzevent); - - return ret; -} - -static gboolean -button_release_event (GtkWidget *widget, GdkEventButton *event) -{ - KzEmbedEventMouse *kzevent; - gint ret = FALSE; - - kzevent = create_kz_embed_event_mouse(event); - g_signal_emit_by_name(widget, "kz-dom-mouse-up", kzevent, &ret); - kz_embed_event_free((KzEmbedEvent *) kzevent); - - return ret; -} -#endif static void load_url (KzEmbed *kzembed, const gchar *url) { @@ -760,7 +715,6 @@ static void set_history (KzEmbed *kzembed, KzBookmark *history) { -/* WebKitWebBackForwardList *list; WebKitWebHistoryItem *item; GList *children, *node; @@ -785,7 +739,6 @@ current_pos = kz_bookmark_get_current(history); item = webkit_web_back_forward_list_get_nth_item(list, current_pos - total + 1); webkit_web_view_go_to_back_forward_item(KZ_WEBKIT_GTK_GET_PRIVATE(kzembed)->web_view, item); -*/ } static gboolean @@ -895,13 +848,6 @@ g_signal_emit_by_name(data, "kz-link-message"); } -static void -cb_populate_popup (WebKitWebView* web_view, - GtkMenu *menu, - gpointer data) -{ -} - static gboolean cb_navigation_policy_decision_requested (WebKitWebView* web_view, WebKitWebFrame *frame, @@ -932,7 +878,136 @@ return FALSE; } +static KzEmbedEventMouse * +create_kz_embed_event_mouse (GdkEventButton *event, + KzEmbedEventContext context) +{ + KzEmbedEventMouse *kzevent; + + kzevent = (KzEmbedEventMouse *) kz_embed_event_new(KZ_EMBED_EVENT_MOUSE); + if (event->state & GDK_SHIFT_MASK) + kzevent->modifier |= KZ_SHIFT_KEY; + if (event->state & GDK_CONTROL_MASK) + kzevent->modifier |= KZ_CTRL_KEY; + if (event->state & GDK_MOD1_MASK) + kzevent->modifier |= KZ_ALT_KEY; + if (event->state & GDK_META_MASK) + kzevent->modifier |= KZ_META_KEY; + kzevent->x = event->x; + kzevent->y = event->y; + switch (event->button) + { + case 1: + kzevent->button = 1; + break; + case 2: + kzevent->button = 3; + break; + case 3: + kzevent->button = 2; + break; + } + kzevent->cinfo.context = context; + + return kzevent; +} + +static gboolean +cb_button_press_event (GtkWidget *widget, GdkEventButton *event, gpointer data) +{ + KzEmbedEventMouse *kzevent; + gint ret = FALSE; + + kzevent = create_kz_embed_event_mouse(event, KZ_CONTEXT_NONE); + g_signal_emit_by_name(data, "kz-dom-mouse-down", kzevent, &ret); + kz_embed_event_free((KzEmbedEvent *) kzevent); + + return ret; +} + +static gboolean +cb_button_release_event (GtkWidget *widget, GdkEventButton *event, gpointer data) +{ + KzEmbedEventMouse *kzevent; + gint ret = FALSE; + + kzevent = create_kz_embed_event_mouse(event, KZ_CONTEXT_NONE); + g_signal_emit_by_name(data, "kz-dom-mouse-up", kzevent, &ret); + kz_embed_event_free((KzEmbedEvent *) kzevent); + + return ret; +} + static void +cb_remove_menu_item (GtkWidget *menu_item, gpointer data) +{ + GtkContainer *container = GTK_CONTAINER(data); + gtk_container_remove(container, menu_item); +} + +static KzEmbedEventContext +get_event_context_from_menu (GtkMenu *menu) +{ + GList *menu_items; + GtkWidget *first_item; + GtkWidget *label; + const gchar *label_text; + + menu_items = gtk_container_get_children(GTK_CONTAINER(menu)); + if (!menu_items) + return KZ_CONTEXT_NONE; + first_item = GTK_WIDGET(menu_items->data); + g_list_free(menu_items); + + label = gtk_bin_get_child(GTK_BIN(first_item)); + label_text = gtk_label_get_text(GTK_LABEL(label)); + + if (g_str_equal(label_text, "Open Image in New Window")) + { + return KZ_CONTEXT_IMAGE; + } + else if (g_str_equal(label_text, "Open Link")) + { + return KZ_CONTEXT_LINK; + } + return KZ_CONTEXT_NONE; +} + +static void +cb_populate_popup (WebKitWebView* web_view, + GtkMenu *menu, + gpointer data) +{ + KzEmbedEventMouse *kzevent; + KzEmbedEventContext context; + GdkEventButton *gdk_event; + gboolean ret; + gint x, y; + + context = get_event_context_from_menu(menu); + + gtk_container_forall(GTK_CONTAINER(menu), + cb_remove_menu_item, menu); + + gdk_event = ((GdkEventButton*)gdk_event_new(GDK_BUTTON_RELEASE)); + gtk_widget_get_pointer(GTK_WIDGET(web_view), + &x, &y); + gdk_event->x = (gdouble)x; + gdk_event->y = (gdouble)y; + gdk_event->button = 3; + kzevent = create_kz_embed_event_mouse(gdk_event, context); + if (context & KZ_CONTEXT_LINK) + { + /* FIXME set the link */ + } + + g_signal_emit_by_name(data, "kz-dom-mouse-down", kzevent, &ret); + g_signal_emit_by_name(data, "kz-dom-mouse-up", kzevent, &ret); + kz_embed_event_free((KzEmbedEvent *) kzevent); + gdk_event_free((GdkEvent*)gdk_event); +} + +static void set_font_preferences (KzProfile *profile, WebKitWebSettings *settings) { /* font settings */