summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrien Plazas <kekun.plazas@laposte.net>2018-06-07 13:42:11 +0200
committerAdrien Plazas <kekun.plazas@laposte.net>2018-06-21 23:38:59 +0200
commit24e0208dc8bacfcb98b8b76ae90306964af265aa (patch)
tree4f201c5eeb26d1ee052b0703a005fd45660035b0
parent7941615d3ab4efd9b72528ee75f1dd09d7dacc2c (diff)
downloadepiphany-24e0208dc8bacfcb98b8b76ae90306964af265aa.tar.gz
header-bar: Use EphyActionBarStart
-rw-r--r--src/ephy-header-bar.c489
-rw-r--r--src/ephy-header-bar.h2
2 files changed, 19 insertions, 472 deletions
diff --git a/src/ephy-header-bar.c b/src/ephy-header-bar.c
index c2fa2f304..417b9f9bc 100644
--- a/src/ephy-header-bar.c
+++ b/src/ephy-header-bar.c
@@ -57,35 +57,27 @@ enum {
static GParamSpec *object_properties[N_PROPERTIES] = { NULL, };
-#define MAX_LABEL_LENGTH 48
-#define HISTORY_ITEM_DATA_KEY "history-item-data-key"
-
struct _EphyHeaderBar {
GtkHeaderBar parent_instance;
EphyWindow *window;
EphyTitleWidget *title_widget;
+ EphyActionBarStart *action_bar_start;
GtkWidget *navigation_box;
GtkWidget *reader_mode_revealer;
GtkWidget *reader_mode_button;
GtkWidget *new_tab_revealer;
GtkWidget *new_tab_button;
- GtkWidget *combined_stop_reload_button;
GtkWidget *bookmarks_button;
GtkWidget *page_menu_button;
GtkWidget *downloads_revealer;
GtkWidget *downloads_button;
GtkWidget *downloads_popover;
GtkWidget *zoom_level_button;
-
- guint navigation_buttons_menu_timeout;
};
G_DEFINE_TYPE (EphyHeaderBar, ephy_header_bar, GTK_TYPE_HEADER_BAR)
-/* Translators: tooltip for the refresh button */
-static const char *REFRESH_BUTTON_TOOLTIP = N_("Reload the current page");
-
static gboolean
header_bar_is_for_active_window (EphyHeaderBar *header_bar)
{
@@ -181,368 +173,13 @@ sync_chromes_visibility (EphyHeaderBar *header_bar)
chrome = ephy_window_get_chrome (header_bar->window);
- gtk_widget_set_visible (header_bar->navigation_box, chrome & EPHY_WINDOW_CHROME_HEADER_BAR);
+ gtk_widget_set_visible (ephy_action_bar_start_get_navigation_box (header_bar->action_bar_start),
+ chrome & EPHY_WINDOW_CHROME_HEADER_BAR);
gtk_widget_set_visible (header_bar->bookmarks_button, chrome & EPHY_WINDOW_CHROME_BOOKMARKS);
gtk_widget_set_visible (header_bar->page_menu_button, chrome & EPHY_WINDOW_CHROME_MENU);
gtk_widget_set_visible (header_bar->new_tab_button, chrome & EPHY_WINDOW_CHROME_TABSBAR);
}
-static void
-homepage_url_changed (GSettings *settings,
- const char *key,
- GtkWidget *button)
-{
- char *setting;
- gboolean show_button;
-
- setting = g_settings_get_string (settings, key);
- show_button = setting && setting[0] && g_strcmp0 (setting, "about:blank") != 0;
-
- gtk_widget_set_visible (button, show_button);
- g_free (setting);
-}
-
-typedef enum {
- EPHY_NAVIGATION_HISTORY_DIRECTION_BACK,
- EPHY_NAVIGATION_HISTORY_DIRECTION_FORWARD
-} EphyNavigationHistoryDirection;
-
-typedef enum {
- WEBKIT_HISTORY_BACKWARD,
- WEBKIT_HISTORY_FORWARD
-} WebKitHistoryType;
-
-static gboolean
-item_enter_notify_event_cb (GtkWidget *widget,
- GdkEvent *event,
- EphyWebView *view)
-{
- char *text;
-
- text = g_object_get_data (G_OBJECT (widget), "link-message");
- ephy_web_view_set_link_message (view, text);
-
- return FALSE;
-}
-
-static gboolean
-item_leave_notify_event_cb (GtkWidget *widget,
- GdkEvent *event,
- EphyWebView *view)
-{
- ephy_web_view_set_link_message (view, NULL);
- return FALSE;
-}
-
-static void
-icon_loaded_cb (GObject *source,
- GAsyncResult *result,
- GtkWidget *image)
-{
- WebKitFaviconDatabase *database = WEBKIT_FAVICON_DATABASE (source);
- GdkPixbuf *favicon = NULL;
- cairo_surface_t *icon_surface = webkit_favicon_database_get_favicon_finish (database, result, NULL);
-
- if (icon_surface) {
- favicon = ephy_pixbuf_get_from_surface_scaled (icon_surface, FAVICON_SIZE, FAVICON_SIZE);
- cairo_surface_destroy (icon_surface);
- }
-
- if (favicon) {
- gtk_image_set_from_pixbuf (GTK_IMAGE (image), favicon);
- gtk_widget_show (image);
-
- g_object_unref (favicon);
- }
-
- g_object_unref (image);
-}
-
-static GtkWidget *
-new_history_menu_item (EphyWebView *view,
- const char *origtext,
- const char *address)
-{
- GtkWidget *menu_item;
- GtkWidget *box;
- GtkWidget *image;
- GtkWidget *label;
- WebKitFaviconDatabase *database;
- EphyEmbedShell *shell = ephy_embed_shell_get_default ();
-
- g_assert (address != NULL && origtext != NULL);
-
- box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
-
- image = gtk_image_new ();
- gtk_box_pack_start (GTK_BOX (box), image, FALSE, FALSE, 0);
-
- label = gtk_label_new (origtext);
- gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
- gtk_label_set_max_width_chars (GTK_LABEL (label), MAX_LABEL_LENGTH);
- gtk_label_set_xalign (GTK_LABEL (label), 0.0f);
- gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 6);
-
- menu_item = gtk_menu_item_new ();
- gtk_container_add (GTK_CONTAINER (menu_item), box);
-
- database = webkit_web_context_get_favicon_database (ephy_embed_shell_get_web_context (shell));
- webkit_favicon_database_get_favicon (database, address,
- NULL,
- (GAsyncReadyCallback)icon_loaded_cb,
- g_object_ref (image));
-
- g_object_set_data_full (G_OBJECT (menu_item), "link-message", g_strdup (address), (GDestroyNotify)g_free);
-
- g_signal_connect (menu_item, "enter-notify-event",
- G_CALLBACK (item_enter_notify_event_cb), view);
- g_signal_connect (menu_item, "leave-notify-event",
- G_CALLBACK (item_leave_notify_event_cb), view);
-
- gtk_widget_show_all (menu_item);
-
- return menu_item;
-}
-
-static void
-middle_click_handle_on_history_menu_item (EphyEmbed *embed,
- WebKitBackForwardListItem *item)
-{
- EphyEmbed *new_embed = NULL;
- const gchar *url;
-
- new_embed = ephy_shell_new_tab (ephy_shell_get_default (),
- EPHY_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (embed))),
- embed,
- 0);
- g_assert (new_embed != NULL);
-
- /* Load the new URL */
- url = webkit_back_forward_list_item_get_original_uri (item);
- ephy_web_view_load_url (ephy_embed_get_web_view (new_embed), url);
-}
-
-static gboolean
-navigation_menu_item_pressed_cb (GtkWidget *menuitem,
- GdkEvent *event,
- gpointer user_data)
-{
- EphyWindow *window = EPHY_WINDOW (user_data);
- WebKitBackForwardListItem *item;
- EphyEmbed *embed;
-
- embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
-
- item = (WebKitBackForwardListItem *)g_object_get_data (G_OBJECT (menuitem), HISTORY_ITEM_DATA_KEY);
-
- if (((GdkEventButton *)event)->button == GDK_BUTTON_MIDDLE) {
- middle_click_handle_on_history_menu_item (embed, item);
- } else {
- WebKitWebView *web_view;
-
- web_view = EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed);
- webkit_web_view_go_to_back_forward_list_item (web_view, item);
- }
-
- return G_SOURCE_REMOVE;
-}
-
-static GList *
-construct_webkit_history_list (WebKitWebView *web_view,
- WebKitHistoryType hist_type,
- int limit)
-{
- WebKitBackForwardList *back_forward_list;
-
- back_forward_list = webkit_web_view_get_back_forward_list (web_view);
- return hist_type == WEBKIT_HISTORY_FORWARD ?
- g_list_reverse (webkit_back_forward_list_get_forward_list_with_limit (back_forward_list, limit)) :
- webkit_back_forward_list_get_back_list_with_limit (back_forward_list, limit);
-}
-
-static GtkWidget *
-build_dropdown_menu (EphyWindow *window,
- EphyNavigationHistoryDirection direction)
-{
- GtkMenuShell *menu;
- EphyEmbed *embed;
- GList *list, *l;
- WebKitWebView *web_view;
-
- embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
- g_assert (embed != NULL);
-
- menu = GTK_MENU_SHELL (gtk_menu_new ());
-
- web_view = EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed);
-
- if (direction == EPHY_NAVIGATION_HISTORY_DIRECTION_BACK)
- list = construct_webkit_history_list (web_view,
- WEBKIT_HISTORY_BACKWARD, 10);
- else
- list = construct_webkit_history_list (web_view,
- WEBKIT_HISTORY_FORWARD, 10);
-
- for (l = list; l != NULL; l = l->next) {
- GtkWidget *item;
- WebKitBackForwardListItem *hitem;
- const char *uri;
- char *title;
-
- hitem = (WebKitBackForwardListItem *)l->data;
- uri = webkit_back_forward_list_item_get_uri (hitem);
- title = g_strdup (webkit_back_forward_list_item_get_title (hitem));
-
- if (title == NULL || g_strstrip (title)[0] == '\0')
- item = new_history_menu_item (EPHY_WEB_VIEW (web_view), uri, uri);
- else
- item = new_history_menu_item (EPHY_WEB_VIEW (web_view), title, uri);
-
- g_free (title);
-
- g_object_set_data_full (G_OBJECT (item), HISTORY_ITEM_DATA_KEY,
- g_object_ref (hitem), g_object_unref);
-
- g_signal_connect (item, "button-release-event",
- G_CALLBACK (navigation_menu_item_pressed_cb), window);
-
- gtk_menu_shell_append (menu, item);
- gtk_widget_show_all (item);
- }
-
- g_list_free (list);
-
- return GTK_WIDGET (menu);
-}
-
-static void
-popup_history_menu (GtkWidget *widget,
- EphyWindow *window,
- EphyNavigationHistoryDirection direction,
- GdkEventButton *event)
-{
- GtkWidget *menu;
-
- menu = build_dropdown_menu (window, direction);
- gtk_menu_popup_at_widget (GTK_MENU (menu),
- widget,
- GDK_GRAVITY_SOUTH_WEST,
- GDK_GRAVITY_NORTH_WEST,
- (GdkEvent *)event);
-}
-
-typedef struct {
- GtkWidget *button;
- EphyWindow *window;
- EphyNavigationHistoryDirection direction;
- GdkEventButton *event;
-} PopupData;
-
-static gboolean
-menu_timeout_cb (PopupData *data)
-{
- if (data != NULL && data->window)
- popup_history_menu (data->button, data->window, data->direction, data->event);
-
- return G_SOURCE_REMOVE;
-}
-
-static gboolean
-navigation_button_press_event_cb (GtkButton *button,
- GdkEvent *event,
- gpointer user_data)
-{
- EphyHeaderBar *header_bar = EPHY_HEADER_BAR (user_data);
- EphyNavigationHistoryDirection direction;
- const gchar *action_name;
-
- action_name = gtk_actionable_get_action_name (GTK_ACTIONABLE (button));
-
- direction = strstr (action_name, "back") ? EPHY_NAVIGATION_HISTORY_DIRECTION_BACK
- : EPHY_NAVIGATION_HISTORY_DIRECTION_FORWARD;
-
- if (((GdkEventButton *)event)->button == GDK_BUTTON_SECONDARY) {
- popup_history_menu (GTK_WIDGET (button), header_bar->window,
- direction, (GdkEventButton *)event);
- } else {
- PopupData *data;
-
- data = g_new (PopupData, 1);
- data->button = GTK_WIDGET (button);
- data->window = header_bar->window;
- data->direction = direction;
- data->event = (GdkEventButton *)event;
-
- header_bar->navigation_buttons_menu_timeout = g_timeout_add_full (G_PRIORITY_DEFAULT, 500,
- (GSourceFunc)menu_timeout_cb,
- data,
- (GDestroyNotify)g_free);
- g_source_set_name_by_id (header_bar->navigation_buttons_menu_timeout, "[epiphany] menu_timeout_cb");
- }
-
- return FALSE;
-}
-
-static gboolean
-navigation_button_release_event_cb (GtkButton *button,
- GdkEvent *event,
- gpointer user_data)
-{
- EphyHeaderBar *header_bar = EPHY_HEADER_BAR (user_data);
- GActionGroup *action_group;
- GAction *action;
- EphyNavigationHistoryDirection direction;
- const gchar *action_name;
-
- if (header_bar->navigation_buttons_menu_timeout > 0) {
- g_source_remove (header_bar->navigation_buttons_menu_timeout);
- header_bar->navigation_buttons_menu_timeout = 0;
- }
-
- action_name = gtk_actionable_get_action_name (GTK_ACTIONABLE (button));
- action_group = gtk_widget_get_action_group (GTK_WIDGET (header_bar->window), "toolbar");
-
- direction = strcmp (action_name, "toolbar.navigation-back") == 0 ? EPHY_NAVIGATION_HISTORY_DIRECTION_BACK
- : EPHY_NAVIGATION_HISTORY_DIRECTION_FORWARD;
-
- switch (((GdkEventButton *)event)->button) {
- case GDK_BUTTON_MIDDLE:
- if (direction == EPHY_NAVIGATION_HISTORY_DIRECTION_BACK) {
- action = g_action_map_lookup_action (G_ACTION_MAP (action_group),
- "navigation-back-new-tab");
- g_action_activate (action, NULL);
- } else if (direction == EPHY_NAVIGATION_HISTORY_DIRECTION_FORWARD) {
- action = g_action_map_lookup_action (G_ACTION_MAP (action_group),
- "navigation-forward-new-tab");
- g_action_activate (action, NULL);
- }
- break;
- case GDK_BUTTON_SECONDARY:
- popup_history_menu (GTK_WIDGET (button), header_bar->window,
- direction, (GdkEventButton *)event);
- break;
- default:
- break;
- }
-
- return G_SOURCE_REMOVE;
-}
-
-static gboolean
-navigation_leave_notify_event_cb (GtkButton *button,
- GdkEvent *event,
- gpointer user_data)
-{
- EphyHeaderBar *header_bar = EPHY_HEADER_BAR (user_data);
-
- if (header_bar->navigation_buttons_menu_timeout > 0) {
- g_source_remove (header_bar->navigation_buttons_menu_timeout);
- header_bar->navigation_buttons_menu_timeout = 0;
- }
-
- return G_SOURCE_REMOVE;
-}
-
void
ephy_header_bar_change_combined_stop_reload_state (GSimpleAction *action,
GVariant *loading,
@@ -550,22 +187,11 @@ ephy_header_bar_change_combined_stop_reload_state (GSimpleAction *action,
{
EphyWindow *window = EPHY_WINDOW (user_data);
EphyHeaderBar *header_bar;
- GtkWidget *image;
header_bar = EPHY_HEADER_BAR (ephy_window_get_header_bar (window));
- if (g_variant_get_boolean (loading)) {
- image = gtk_image_new_from_icon_name ("process-stop-symbolic",
- GTK_ICON_SIZE_BUTTON);
- /* Translators: tooltip for the stop button */
- gtk_widget_set_tooltip_text (header_bar->combined_stop_reload_button, _("Stop loading the current page"));
- } else {
- image = gtk_image_new_from_icon_name ("view-refresh-symbolic",
- GTK_ICON_SIZE_BUTTON);
- gtk_widget_set_tooltip_text (header_bar->combined_stop_reload_button, _(REFRESH_BUTTON_TOOLTIP));
- }
-
- gtk_button_set_image (GTK_BUTTON (header_bar->combined_stop_reload_button), image);
+ ephy_action_bar_start_change_combined_stop_reload_state (header_bar->action_bar_start,
+ g_variant_get_boolean (loading));
g_simple_action_set_state (action, loading);
}
@@ -611,7 +237,7 @@ static void
ephy_header_bar_constructed (GObject *object)
{
EphyHeaderBar *header_bar = EPHY_HEADER_BAR (object);
- GtkWidget *box, *button, *notebook;
+ GtkWidget *button, *notebook;
GtkWidget *page_menu_popover;
EphyDownloadsManager *downloads_manager;
GtkBuilder *builder;
@@ -622,87 +248,14 @@ ephy_header_bar_constructed (GObject *object)
g_signal_connect_swapped (header_bar->window, "notify::chrome",
G_CALLBACK (sync_chromes_visibility), header_bar);
- /* Back and Forward */
- box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
- header_bar->navigation_box = box;
+ /* Start action elements */
+ header_bar->action_bar_start = ephy_action_bar_start_new ();
+ gtk_widget_show (GTK_WIDGET (header_bar->action_bar_start));
- /* Back */
- button = gtk_button_new ();
- gtk_button_set_image (GTK_BUTTON (button),
- gtk_image_new_from_icon_name ("go-previous-symbolic",
- GTK_ICON_SIZE_BUTTON));
- gtk_widget_set_valign (button, GTK_ALIGN_CENTER);
- /* Translators: tooltip for the back button */
- gtk_widget_set_tooltip_text (button, _("Go back to the previous page"));
- gtk_actionable_set_action_name (GTK_ACTIONABLE (button),
- "toolbar.navigation-back");
- g_signal_connect (button, "button-press-event",
- G_CALLBACK (navigation_button_press_event_cb), header_bar);
- g_signal_connect (button, "button-release-event",
- G_CALLBACK (navigation_button_release_event_cb), header_bar);
- g_signal_connect (button, "leave-notify-event",
- G_CALLBACK (navigation_leave_notify_event_cb), header_bar);
- gtk_container_add (GTK_CONTAINER (box), button);
- gtk_widget_show (GTK_WIDGET (button));
-
- /* Forward */
- button = gtk_button_new ();
- gtk_button_set_image (GTK_BUTTON (button),
- gtk_image_new_from_icon_name ("go-next-symbolic",
- GTK_ICON_SIZE_BUTTON));
- gtk_widget_set_valign (button, GTK_ALIGN_CENTER);
- /* Translators: tooltip for the forward button */
- gtk_widget_set_tooltip_text (button, _("Go forward to the next page"));
- gtk_actionable_set_action_name (GTK_ACTIONABLE (button),
- "toolbar.navigation-forward");
- g_signal_connect (button, "button-press-event",
- G_CALLBACK (navigation_button_press_event_cb), header_bar);
- g_signal_connect (button, "button-release-event",
- G_CALLBACK (navigation_button_release_event_cb), header_bar);
- g_signal_connect (button, "leave-notify-event",
- G_CALLBACK (navigation_leave_notify_event_cb), header_bar);
- gtk_container_add (GTK_CONTAINER (box), button);
- gtk_widget_show (GTK_WIDGET (button));
-
- gtk_style_context_add_class (gtk_widget_get_style_context (box),
- "raised");
- gtk_style_context_add_class (gtk_widget_get_style_context (box),
- "linked");
-
- gtk_header_bar_pack_start (GTK_HEADER_BAR (header_bar), box);
-
- /* Reload/Stop */
- button = gtk_button_new ();
- header_bar->combined_stop_reload_button = button;
- gtk_button_set_image (GTK_BUTTON (button),
- gtk_image_new_from_icon_name ("view-refresh-symbolic", GTK_ICON_SIZE_BUTTON));
- gtk_widget_set_valign (button, GTK_ALIGN_CENTER);
- gtk_widget_set_tooltip_text (button, _(REFRESH_BUTTON_TOOLTIP));
- gtk_actionable_set_action_name (GTK_ACTIONABLE (button),
- "toolbar.combined-stop-reload");
- gtk_style_context_add_class (gtk_widget_get_style_context (button),
- "image-button");
- gtk_widget_show (GTK_WIDGET (button));
- gtk_header_bar_pack_start (GTK_HEADER_BAR (header_bar), button);
-
- /* Homepage */
- button = gtk_button_new ();
- gtk_button_set_image (GTK_BUTTON (button),
- gtk_image_new_from_icon_name ("go-home-symbolic", GTK_ICON_SIZE_BUTTON));
- gtk_widget_set_valign (button, GTK_ALIGN_CENTER);
- /* Translators: tooltip for the secret homepage button */
- gtk_widget_set_tooltip_text (button, _("Go to your homepage"));
- gtk_actionable_set_action_name (GTK_ACTIONABLE (button), "win.home");
- gtk_header_bar_pack_start (GTK_HEADER_BAR (header_bar), button);
+ gtk_header_bar_pack_start (GTK_HEADER_BAR (header_bar),
+ GTK_WIDGET (header_bar->action_bar_start));
embed_shell = ephy_embed_shell_get_default ();
- if (ephy_embed_shell_get_mode (embed_shell) != EPHY_EMBED_SHELL_MODE_APPLICATION) {
- homepage_url_changed (EPHY_SETTINGS_MAIN, EPHY_PREFS_HOMEPAGE_URL, button);
- g_signal_connect (EPHY_SETTINGS_MAIN,
- "changed::" EPHY_PREFS_HOMEPAGE_URL,
- G_CALLBACK (homepage_url_changed),
- button);
- }
/* Title widget (location entry or title box) */
if (ephy_embed_shell_get_mode (embed_shell) == EPHY_EMBED_SHELL_MODE_APPLICATION)
@@ -825,24 +378,10 @@ ephy_header_bar_init (EphyHeaderBar *header_bar)
}
static void
-ephy_header_bar_dispose (GObject *object)
-{
- EphyHeaderBar *header_bar = EPHY_HEADER_BAR (object);
-
- if (header_bar->navigation_buttons_menu_timeout > 0) {
- g_source_remove (header_bar->navigation_buttons_menu_timeout);
- header_bar->navigation_buttons_menu_timeout = 0;
- }
-
- G_OBJECT_CLASS (ephy_header_bar_parent_class)->dispose (object);
-}
-
-static void
ephy_header_bar_class_init (EphyHeaderBarClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
- gobject_class->dispose = ephy_header_bar_dispose;
gobject_class->set_property = ephy_header_bar_set_property;
gobject_class->get_property = ephy_header_bar_get_property;
gobject_class->constructed = ephy_header_bar_constructed;
@@ -893,3 +432,9 @@ ephy_header_bar_get_window (EphyHeaderBar *header_bar)
{
return header_bar->window;
}
+
+EphyActionBarStart *
+ephy_header_bar_get_action_bar_start (EphyHeaderBar *header_bar)
+{
+ return header_bar->action_bar_start;
+}
diff --git a/src/ephy-header-bar.h b/src/ephy-header-bar.h
index 51696db2d..bdf420e5d 100644
--- a/src/ephy-header-bar.h
+++ b/src/ephy-header-bar.h
@@ -22,6 +22,7 @@
#include <gtk/gtk.h>
+#include "ephy-action-bar-start.h"
#include "ephy-title-widget.h"
#include "ephy-window.h"
@@ -43,5 +44,6 @@ GtkWidget *ephy_header_bar_get_page_menu_button (EphyHeaderBa
EphyWindow *ephy_header_bar_get_window (EphyHeaderBar *header_bar);
void ephy_header_bar_set_reader_mode_state (EphyHeaderBar *header_bar,
EphyWebView *view);
+EphyActionBarStart *ephy_header_bar_get_action_bar_start (EphyHeaderBar *header_bar);
G_END_DECLS