Пример #1
0
/**
 * WebKitWebView::populate-popup:
 * @web_view: the object on which the signal is emitted
 * @menu: the context menu
 *
 * When a context menu is about to be displayed this signal is emitted.
 *
 * Add menu items to #menu to extend the context menu.
 */
static void
liferea_webkit_on_menu (WebKitWebView *view, GtkMenu *menu)
{
	LifereaHtmlView			*htmlview;
	gchar				*imageUri = NULL;
	gchar				*linkUri = NULL;
	WebKitHitTestResult*		hitResult;
	WebKitHitTestResultContext	context;
	GdkEvent			*event;

	event = gtk_get_current_event ();
	hitResult = webkit_web_view_get_hit_test_result (view, (GdkEventButton *)event);
	g_object_get (hitResult, "context", &context, NULL);

	if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK)
		g_object_get (hitResult, "link-uri", &linkUri, NULL);
	if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE)
		g_object_get (hitResult, "image-uri", &imageUri, NULL);
	if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_MEDIA)
		g_object_get (hitResult, "media-uri", &linkUri, NULL);		/* treat media as normal link */
		
	htmlview = g_object_get_data (G_OBJECT (view), "htmlview");
	
	liferea_htmlview_prepare_context_menu (htmlview, menu, linkUri, imageUri);
}
Пример #2
0
void
populate_popup_cb(WebKitWebView *v, GtkMenu *m, void *c) {
    (void) c;
    gint context;

    if(!uzbl.gui.menu_items)
        return;

    /* check context */
    if((context = get_click_context()) == -1)
        return;

    WebKitHitTestResult *hit_test_result;
    GdkEventButton ev;
    gint x, y;
#if GTK_CHECK_VERSION (3, 0, 0)
    gdk_window_get_device_position (gtk_widget_get_window(GTK_WIDGET(v)),
        gdk_device_manager_get_client_pointer (
            gdk_display_get_device_manager (
                gtk_widget_get_display (GTK_WIDGET (v)))),
        &x, &y, NULL);
#else
    gdk_window_get_pointer(gtk_widget_get_window(GTK_WIDGET(v)), &x, &y, NULL);
#endif
    ev.x = x;
    ev.y = y;
    hit_test_result = webkit_web_view_get_hit_test_result(v, &ev);

    populate_context_menu(m, hit_test_result, context);

    g_object_unref(hit_test_result);
}
static gboolean
button_press_event_cb (WebKitWebView *view,
		       GdkEventButton *event,
		       EphyGreasemonkeyExtension *extension)
{
	/*
	 * Set whether or not the action is visible before we display the
	 * context popup menu
	 */
	WindowData *window_data;
	EphyWindow *window;
	GtkAction *action;
	WebKitHitTestResult *hit_test;
	char *uri;
	guint context;
	gboolean show_install;

	if (event->button != 3 || event->type != GDK_BUTTON_PRESS)
		return FALSE;

	hit_test = webkit_web_view_get_hit_test_result (view, event);
	g_object_get (hit_test, "context", &context, NULL);

	if (!(context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK))
		return FALSE;

	g_object_get (hit_test, "link-uri", &uri, NULL);
	show_install = g_str_has_suffix (uri, ".user.js");

	window = EPHY_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (view)));
	g_return_val_if_fail (window != NULL, FALSE);

	window_data = (WindowData *) g_object_get_data (G_OBJECT (window),
							WINDOW_DATA_KEY);
	g_return_val_if_fail (window_data != NULL, FALSE);

	action = gtk_action_group_get_action (window_data->action_group,
					      ACTION_NAME);
	g_return_val_if_fail (action != NULL, FALSE);

	if (show_install == TRUE)
	{
		g_free (window_data->last_clicked_url);
		window_data->last_clicked_url = g_strdup (uri);
	}

	gtk_action_set_visible (action, show_install);

	g_free (uri);
	g_object_unref (hit_test);

	return FALSE;
}
Пример #4
0
static void
load_status_cb(WebKitWebView* webView,
               GParamSpec* spec,
               gpointer data)
{
    WebKitLoadStatus status = webkit_web_view_get_load_status(webView);
    TestInfo* info = (TestInfo*)data;

    if (status == WEBKIT_LOAD_FINISHED) {
        WebKitHitTestResult* result;
        guint context;
        GdkEvent* event = gdk_event_new(GDK_BUTTON_PRESS);
        WebKitDOMNode* node;
        gint x, y;

        /* Close enough to 0,0 */
        event->button.x = 5;
        event->button.y = 5;

        result = webkit_web_view_get_hit_test_result(webView, (GdkEventButton*) event);
        gdk_event_free(event);
        g_assert(result);

        g_object_get(result, "context", &context, NULL);
        g_assert(context & info->flag);

        g_object_get(result, "inner-node", &node, NULL);
        g_assert(node);
        g_assert(WEBKIT_DOM_IS_NODE(node));

        g_object_get(result, "x", &x, "y", &y, NULL);
        g_assert_cmpint(x, ==, 5);
        g_assert_cmpint(y, ==, 5);

        /* We can only test these node types at the moment. In the
         * input case there seems to be an extra layer with a DIV on
         * top of the input, which gets assigned to the inner-node.
         * tag */
        if (info->flag == WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT)
            g_assert(WEBKIT_DOM_IS_HTML_HTML_ELEMENT(node));
        else if (info->flag == WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE)
            g_assert(WEBKIT_DOM_IS_HTML_IMAGE_ELEMENT(node));
        else if (info->flag == WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK) {
            /* The hit test will give us the inner text node, we want
             * the A tag */
            WebKitDOMNode* parent = webkit_dom_node_get_parent_node(node);
            g_assert(WEBKIT_DOM_IS_HTML_ANCHOR_ELEMENT(parent));
        }

        g_object_unref(result);
        g_main_loop_quit(loop);
    }
Пример #5
0
gint
get_click_context() {
    WebKitHitTestResult *ht;
    guint context;

    if(!uzbl.state.last_button)
        return -1;

    ht = webkit_web_view_get_hit_test_result (uzbl.gui.web_view, uzbl.state.last_button);
    g_object_get (ht, "context", &context, NULL);
    g_object_unref (ht);

    return (gint)context;
}
Пример #6
0
static gboolean
wv_button_press_cb(GtkWidget *view, GdkEventButton *event, widget_t *w)
{
    if((event->type != GDK_BUTTON_PRESS) || (event->button != 1))
        return FALSE;

    /* get webview hit context */
    WebKitHitTestResult *ht = webkit_web_view_get_hit_test_result(WEBKIT_WEB_VIEW(view), event);
    guint c;
    g_object_get(ht, "context", &c, NULL);
    gint context = (gint) c;

    lua_State *L = globalconf.L;
    luaH_object_push(L, w->ref);
    /* raise "form-active" when a user clicks on a form field and raise
     * "root-active" when a user clicks elsewhere */
    if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE)
        luaH_object_emit_signal(L, -1, "form-active", 0, 0);
    else if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT)
        luaH_object_emit_signal(L, -1, "root-active", 0, 0);
    lua_pop(L, 1);
    return FALSE;
}
Пример #7
0
void
populate_popup_cb(WebKitWebView *v, GtkMenu *m, void *c) {
    (void) c;
    GUI *g = &uzbl.gui;
    GtkWidget *item;
    MenuItem *mi;
    guint i=0;
    gint context, hit=0;

    if(!g->menu_items)
        return;

    /* check context */
    if((context = get_click_context(NULL)) == -1)
        return;

    for(i=0; i < uzbl.gui.menu_items->len; i++) {
        hit = 0;
        mi = g_ptr_array_index(uzbl.gui.menu_items, i);

        if (mi->context & WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE) {
            GdkEventButton ev;
            gint x, y;
            gdk_window_get_pointer(gtk_widget_get_window(GTK_WIDGET(v)), &x, &y, NULL);
            ev.x = x;
            ev.y = y;
            mi->hittest = webkit_web_view_get_hit_test_result(v, &ev);
        }

        if((mi->context > WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT) &&
                (context & mi->context)) {
            if(mi->issep) {
                item = gtk_separator_menu_item_new();
                gtk_menu_shell_append(GTK_MENU_SHELL(m), item);
                gtk_widget_show(item);
            }
            else {
                item = gtk_menu_item_new_with_label(mi->name);
                g_signal_connect(item, "activate",
                        G_CALLBACK(run_menu_command), mi);
                gtk_menu_shell_append(GTK_MENU_SHELL(m), item);
                gtk_widget_show(item);
            }
            hit++;
        }

        if((mi->context == WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT)  &&
                (context <= WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT) &&
                !hit) {
            if(mi->issep) {
                item = gtk_separator_menu_item_new();
                gtk_menu_shell_append(GTK_MENU_SHELL(m), item);
                gtk_widget_show(item);
            }
            else {
                item = gtk_menu_item_new_with_label(mi->name);
                g_signal_connect(item, "activate",
                        G_CALLBACK(run_menu_command), mi);
                gtk_menu_shell_append(GTK_MENU_SHELL(m), item);
                gtk_widget_show(item);
            }
        }
    }
}
void
empathy_webkit_context_menu_for_event (WebKitWebView *view,
    GdkEventButton *event,
    EmpathyWebKitMenuFlags flags)
{
  WebKitHitTestResult        *hit_test_result;
  WebKitHitTestResultContext  context;
  GtkWidget                  *menu;
  GtkWidget                  *item;

  hit_test_result = webkit_web_view_get_hit_test_result (view, event);
  g_object_get (G_OBJECT (hit_test_result),
      "context", &context,
      NULL);

  /* The menu */
  menu = empathy_context_menu_new (GTK_WIDGET (view));

  /* Select all item */
  item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
  gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);

  g_signal_connect_swapped (item, "activate",
      G_CALLBACK (webkit_web_view_select_all),
      view);

  /* Copy menu item */
  if (webkit_web_view_can_copy_clipboard (view))
    {
      item = gtk_image_menu_item_new_from_stock (GTK_STOCK_COPY, NULL);
      gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);

      g_signal_connect_swapped (item, "activate",
          G_CALLBACK (webkit_web_view_copy_clipboard),
          view);
    }

  /* Clear menu item */
  if (flags & EMPATHY_WEBKIT_MENU_CLEAR)
    {
      item = gtk_separator_menu_item_new ();
      gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);

      item = gtk_image_menu_item_new_from_stock (GTK_STOCK_CLEAR, NULL);
      gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);

      g_signal_connect_swapped (item, "activate",
          G_CALLBACK (empathy_chat_view_clear),
          view);
    }

  /* We will only add the following menu items if we are
   * right-clicking a link */
  if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK)
    {
      /* Separator */
      item = gtk_separator_menu_item_new ();
      gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);

      /* Copy Link Address menu item */
      item = gtk_menu_item_new_with_mnemonic (_("_Copy Link Address"));
      g_signal_connect (item, "activate",
          G_CALLBACK (empathy_webkit_copy_address_cb),
          hit_test_result);
      gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);

      /* Open Link menu item */
      item = gtk_menu_item_new_with_mnemonic (_("_Open Link"));
      g_signal_connect (item, "activate",
          G_CALLBACK (empathy_webkit_open_address_cb),
          hit_test_result);
      gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
    }

  g_signal_connect (GTK_MENU_SHELL (menu), "selection-done",
      G_CALLBACK (empathy_webkit_context_menu_selection_done_cb),
      hit_test_result);

  /* Display the menu */
  gtk_widget_show_all (menu);
  gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
      event->button, event->time);
}