/* FIXME remove when gtknotebook's func for this becomes public, bug #.... */ static EphyNotebook * find_notebook_at_pointer (gint abs_x, gint abs_y) { GdkWindow *win_at_pointer, *toplevel_win; gpointer toplevel = NULL; gint x, y; /* FIXME multi-head */ win_at_pointer = gdk_window_at_pointer (&x, &y); if (win_at_pointer == NULL) { /* We are outside all windows containing a notebook */ return NULL; } toplevel_win = gdk_window_get_toplevel (win_at_pointer); /* get the GtkWidget which owns the toplevel GdkWindow */ gdk_window_get_user_data (toplevel_win, &toplevel); /* toplevel should be an EphyWindow */ if (toplevel != NULL && EPHY_IS_WINDOW (toplevel)) { return EPHY_NOTEBOOK (ephy_window_get_notebook (EPHY_WINDOW (toplevel))); } return NULL; }
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; }
static void ephy_toolbar_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { EphyToolbarPrivate *priv = EPHY_TOOLBAR (object)->priv; switch (property_id) { case PROP_WINDOW: priv->window = EPHY_WINDOW (g_value_get_object (value)); g_object_notify_by_pspec (object, object_properties[PROP_WINDOW]); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } }
static void hovering_over_link_cb (WebKitWebView *web_view, const gchar *title, const gchar *uri, EphyGreasemonkeyExtension *extension) { WindowData *window_data; EphyWindow *window; window = EPHY_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (web_view))); g_return_if_fail (window != NULL); window_data = (WindowData *) g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY); g_return_if_fail (window_data != NULL); g_free (window_data->last_hovered_url); window_data->last_hovered_url = g_strdup (uri); }
static void ephy_title_box_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { EphyTitleBox *title_box = EPHY_TITLE_BOX (object); switch (prop_id) { case PROP_WINDOW: title_box->window = EPHY_WINDOW (g_value_get_object (value)); break; case PROP_MODE: ephy_title_box_set_mode (title_box, g_value_get_enum (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } }
static void window_added_cb (GtkApplication *application, GtkWindow *window, EphySession *session) { GtkWidget *notebook; EphyWindow *ephy_window; ephy_session_save (session, SESSION_STATE); if (!EPHY_IS_WINDOW (window)) return; ephy_window = EPHY_WINDOW (window); notebook = ephy_window_get_notebook (ephy_window); g_signal_connect (notebook, "page-added", G_CALLBACK (notebook_page_added_cb), session); g_signal_connect (notebook, "page-removed", G_CALLBACK (notebook_page_removed_cb), session); g_signal_connect (notebook, "page-reordered", G_CALLBACK (notebook_page_reordered_cb), session); /* Set unique identifier as role, so that on restore, the WM can * place the window on the right workspace */ if (gtk_window_get_role (window) == NULL) { /* I guess rand() is unique enough, otherwise we could use * time + pid or something */ char *role; role = g_strdup_printf ("epiphany-window-%x", rand()); gtk_window_set_role (window, role); g_free (role); } }
void ephy_session_undo_close_tab (EphySession *session) { EphySessionPrivate *priv; EphyEmbed *embed, *new_tab; ClosedTab *tab; #ifndef HAVE_WEBKIT2 WebKitWebBackForwardList *dest; GList *i; #endif EphyNewTabFlags flags = EPHY_NEW_TAB_OPEN_PAGE | EPHY_NEW_TAB_PRESENT_WINDOW | EPHY_NEW_TAB_JUMP | EPHY_NEW_TAB_DONT_COPY_HISTORY; g_return_if_fail (EPHY_IS_SESSION (session)); priv = session->priv; tab = g_queue_pop_head (priv->closed_tabs); if (tab == NULL) return; LOG ("UNDO CLOSE TAB: %s", tab->url); if (*tab->parent_location != NULL) { GtkWidget *window; flags |= EPHY_NEW_TAB_IN_EXISTING_WINDOW; if (tab->position > 0) { /* Append in the n-th position. */ embed = EPHY_EMBED (gtk_notebook_get_nth_page (GTK_NOTEBOOK (*tab->parent_location), tab->position - 1)); flags |= EPHY_NEW_TAB_APPEND_AFTER; } else { /* Just prepend in the first position. */ embed = NULL; flags |= EPHY_NEW_TAB_FIRST; } window = gtk_widget_get_toplevel (GTK_WIDGET (*tab->parent_location)); new_tab = ephy_shell_new_tab (ephy_shell_get_default (), EPHY_WINDOW (window), embed, tab->url, flags); post_restore_cleanup (priv->closed_tabs, tab, FALSE); } else { EphyNotebook *notebook; flags |= EPHY_NEW_TAB_IN_NEW_WINDOW; new_tab = ephy_shell_new_tab (ephy_shell_get_default (), NULL, NULL, tab->url, flags); /* FIXME: This makes the assumption that the notebook is the parent of the returned EphyEmbed. */ notebook = EPHY_NOTEBOOK (gtk_widget_get_parent (GTK_WIDGET (new_tab))); *tab->parent_location = notebook; post_restore_cleanup (priv->closed_tabs, tab, TRUE); } /* This is deficient: we need to recreate the whole * BackForward list. Also, WebKit2 doesn't have this API. */ #ifndef HAVE_WEBKIT2 dest = webkit_web_view_get_back_forward_list (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (new_tab)); for (i = tab->bflist; i; i = i->next) { LOG ("ADDING TO BF: %s", webkit_web_history_item_get_title ((WebKitWebHistoryItem*) i->data)); webkit_web_back_forward_list_add_item (dest, webkit_web_history_item_copy ((WebKitWebHistoryItem*) i->data)); } #endif closed_tab_free (tab); if (g_queue_is_empty (priv->closed_tabs)) g_object_notify (G_OBJECT (session), "can-undo-tab-closed"); }
static void session_command_open_uris (EphySession *session, char **uris, const char *options, guint32 user_time) { EphyShell *shell; EphyWindow *window; EphyEmbed *embed; EphySessionPrivate *priv; EphyNewTabFlags flags = 0; guint i; priv = session->priv; shell = ephy_shell_get_default (); g_object_ref (shell); window = ephy_session_get_active_window (session); if (options != NULL && strstr (options, "external") != NULL) { flags |= EPHY_NEW_TAB_FROM_EXTERNAL; } if (options != NULL && strstr (options, "new-window") != NULL) { window = NULL; flags |= EPHY_NEW_TAB_IN_NEW_WINDOW; } else if (options != NULL && strstr (options, "new-tab") != NULL) { flags |= EPHY_NEW_TAB_IN_EXISTING_WINDOW | EPHY_NEW_TAB_JUMP; } for (i = 0; uris[i] != NULL; ++i) { const char *url = uris[i]; EphyNewTabFlags page_flags; #ifdef HAVE_WEBKIT2 WebKitURIRequest *request = NULL; #else WebKitNetworkRequest *request = NULL; #endif if (url[0] == '\0') { page_flags = EPHY_NEW_TAB_HOME_PAGE; } else { page_flags = EPHY_NEW_TAB_OPEN_PAGE; #ifdef HAVE_WEBKIT2 request = webkit_uri_request_new (url); #else request = webkit_network_request_new (url); #endif } /* For the first URI, if we have a valid recovery * window, reuse the already existing embed instead of * creating a new one, except if we still want to * present the option to resume a crashed session, in * that case use a new tab in the same window */ if (i == 0 && priv->resume_window != NULL) { EphyWebView *web_view; embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (priv->resume_window)); web_view = ephy_embed_get_web_view (embed); ephy_web_view_load_url (web_view, url); } else { embed = ephy_shell_new_tab_full (shell, window, NULL /* parent tab */, request, flags | page_flags, EPHY_WEB_VIEW_CHROME_ALL, FALSE /* is popup? */, user_time); } if (request) g_object_unref (request); window = EPHY_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (embed))); } g_object_unref (shell); }
static void notebook_drag_data_received_cb (GtkWidget *widget, GdkDragContext *context, int x, int y, GtkSelectionData *selection_data, guint info, guint time, EphyEmbed *embed) { EphyWindow *window; GtkWidget *notebook; GdkAtom target; const guchar *data; target = gtk_selection_data_get_target (selection_data); if (target == gdk_atom_intern_static_string ("GTK_NOTEBOOK_TAB")) return; g_signal_stop_emission_by_name (widget, "drag-data-received"); if (g_settings_get_boolean (EPHY_SETTINGS_LOCKDOWN, EPHY_PREFS_LOCKDOWN_ARBITRARY_URL)) return; data = gtk_selection_data_get_data (selection_data); if (gtk_selection_data_get_length (selection_data) <= 0 || data == NULL) return; window = EPHY_WINDOW (gtk_widget_get_toplevel (widget)); notebook = ephy_window_get_notebook (window); if (target == gdk_atom_intern (EPHY_DND_URL_TYPE, FALSE)) { char **split; /* URL_TYPE has format: url \n title */ split = g_strsplit ((const gchar *)data, "\n", 2); if (split != NULL && split[0] != NULL && split[0][0] != '\0') { ephy_link_open (EPHY_LINK (notebook), split[0], embed, embed ? 0 : EPHY_LINK_NEW_TAB); } g_strfreev (split); } else if (target == gdk_atom_intern (EPHY_DND_URI_LIST_TYPE, FALSE)) { char **uris; int i; uris = gtk_selection_data_get_uris (selection_data); if (uris == NULL) return; for (i = 0; i < INSANE_NUMBER_OF_URLS && uris[i] != NULL; i++) { embed = ephy_link_open (EPHY_LINK (notebook), uris[i], embed, (embed && i == 0) ? 0 : EPHY_LINK_NEW_TAB); } g_strfreev (uris); } else { char *text; text = (char *)gtk_selection_data_get_text (selection_data); if (text != NULL) { char *address; address = ephy_embed_utils_normalize_or_autosearch_address (text); ephy_link_open (EPHY_LINK (notebook), address, embed, embed ? 0 : EPHY_LINK_NEW_TAB); g_free (address); g_free (text); } } }