diff options
author | Jan-Michael Brummer <jan.brummer@tabos.org> | 2018-06-30 17:21:07 +0200 |
---|---|---|
committer | Michael Catanzaro <mcatanzaro@posteo.net> | 2018-07-01 22:06:29 +0000 |
commit | 250bb7f879c1ae7930aa3715432e2e7e24f9364e (patch) | |
tree | 42dd695da24012abf17c4105d4d6f28cbae019ca | |
parent | 2d166afcfc083ce650192155e6925ed4f6d79bca (diff) | |
download | epiphany-250bb7f879c1ae7930aa3715432e2e7e24f9364e.tar.gz |
Move progress bar into url box
Moving loading progress bar into url box for EphyLocationEntry widgets. App mode keeps
progress bar within embed widget.
-rw-r--r-- | embed/ephy-embed.c | 35 | ||||
-rw-r--r-- | lib/widgets/ephy-location-entry.c | 96 | ||||
-rw-r--r-- | lib/widgets/ephy-location-entry.h | 4 | ||||
-rw-r--r-- | src/ephy-shell.c | 1 | ||||
-rw-r--r-- | src/ephy-window.c | 34 | ||||
-rw-r--r-- | src/resources/themes/shared.css | 20 | ||||
-rw-r--r-- | src/resources/themes/shared.scss | 20 |
7 files changed, 202 insertions, 8 deletions
diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c index 563f73670..db365cf26 100644 --- a/embed/ephy-embed.c +++ b/embed/ephy-embed.c @@ -87,6 +87,7 @@ struct _EphyEmbed { gulong status_handler_id; gulong progress_update_handler_id; gboolean inspector_loaded; + gboolean progress_bar_enabled; }; G_DEFINE_TYPE (EphyEmbed, ephy_embed, GTK_TYPE_BOX) @@ -95,6 +96,7 @@ enum { PROP_0, PROP_WEB_VIEW, PROP_TITLE, + PROP_PROGRESS_BAR_ENABLED, LAST_PROP }; @@ -444,6 +446,9 @@ ephy_embed_set_property (GObject *object, case PROP_TITLE: ephy_embed_set_title (embed, g_value_get_string (value)); break; + case PROP_PROGRESS_BAR_ENABLED: + embed->progress_bar_enabled = g_value_get_boolean (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -465,6 +470,9 @@ ephy_embed_get_property (GObject *object, case PROP_TITLE: g_value_set_string (value, ephy_embed_get_title (embed)); break; + case PROP_PROGRESS_BAR_ENABLED: + g_value_set_boolean (value, embed->progress_bar_enabled); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -507,6 +515,13 @@ ephy_embed_class_init (EphyEmbedClass *klass) NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + obj_properties[PROP_PROGRESS_BAR_ENABLED] = + g_param_spec_boolean ("progress-bar-enabled", + "Progress bar", + "Whether to show progress bar within embed", + TRUE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); + g_object_class_install_properties (object_class, LAST_PROP, obj_properties); } @@ -736,12 +751,14 @@ ephy_embed_constructed (GObject *object) gtk_overlay_add_overlay (GTK_OVERLAY (embed->overlay), embed->floating_bar); - embed->progress = gtk_progress_bar_new (); - gtk_style_context_add_class (gtk_widget_get_style_context (embed->progress), - GTK_STYLE_CLASS_OSD); - gtk_widget_set_halign (embed->progress, GTK_ALIGN_FILL); - gtk_widget_set_valign (embed->progress, GTK_ALIGN_START); - gtk_overlay_add_overlay (GTK_OVERLAY (embed->overlay), embed->progress); + if (embed->progress_bar_enabled) { + embed->progress = gtk_progress_bar_new (); + gtk_style_context_add_class (gtk_widget_get_style_context (embed->progress), + GTK_STYLE_CLASS_OSD); + gtk_widget_set_halign (embed->progress, GTK_ALIGN_FILL); + gtk_widget_set_valign (embed->progress, GTK_ALIGN_START); + gtk_overlay_add_overlay (GTK_OVERLAY (embed->overlay), embed->progress); + } embed->find_toolbar = ephy_find_toolbar_new (embed->web_view); g_signal_connect (embed->find_toolbar, "close", @@ -754,8 +771,10 @@ ephy_embed_constructed (GObject *object) paned = GTK_WIDGET (embed->paned); - embed->progress_update_handler_id = g_signal_connect (embed->web_view, "notify::estimated-load-progress", - G_CALLBACK (progress_update), object); + if (embed->progress_bar_enabled) + embed->progress_update_handler_id = g_signal_connect (embed->web_view, "notify::estimated-load-progress", + G_CALLBACK (progress_update), object); + gtk_paned_pack1 (GTK_PANED (paned), GTK_WIDGET (embed->overlay), TRUE, FALSE); diff --git a/lib/widgets/ephy-location-entry.c b/lib/widgets/ephy-location-entry.c index 6b51590b4..0a3fcbb42 100644 --- a/lib/widgets/ephy-location-entry.c +++ b/lib/widgets/ephy-location-entry.c @@ -57,6 +57,7 @@ struct _EphyLocationEntry { GtkOverlay parent_instance; GtkWidget *url_entry; + GtkWidget *progress_bar; GtkWidget *bookmark; GtkWidget *bookmark_event_box; GtkWidget *reader_mode; @@ -84,6 +85,9 @@ struct _EphyLocationEntry { guint hash; + guint progress_timeout; + gdouble progress_fraction; + gulong dns_prefetch_handler; guint user_changed : 1; @@ -368,6 +372,20 @@ ephy_location_entry_title_widget_interface_init (EphyTitleWidgetInterface *iface } static void +ephy_location_entry_dispose (GObject *object) +{ + EphyLocationEntry *entry = EPHY_LOCATION_ENTRY (object); + + if (entry->progress_timeout) { + g_source_remove (entry->progress_timeout); + entry->progress_timeout = 0; + } + + G_OBJECT_CLASS (ephy_location_entry_parent_class)->dispose (object); +} + + +static void ephy_location_entry_class_init (EphyLocationEntryClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); @@ -377,6 +395,7 @@ ephy_location_entry_class_init (EphyLocationEntryClass *klass) object_class->set_property = ephy_location_entry_set_property; object_class->constructed = ephy_location_entry_constructed; object_class->finalize = ephy_location_entry_finalize; + object_class->dispose = ephy_location_entry_dispose; widget_class->get_preferred_width = ephy_location_entry_get_preferred_width; widget_class->get_preferred_height = ephy_location_entry_get_preferred_height; @@ -783,6 +802,14 @@ ephy_location_entry_construct_contents (EphyLocationEntry *entry) gtk_widget_show (entry->url_entry); gtk_overlay_add_overlay (GTK_OVERLAY (entry), entry->url_entry); + /* Progress bar */ + entry->progress_bar = gtk_progress_bar_new (); + gtk_style_context_add_class (gtk_widget_get_style_context (entry->progress_bar), "url_progress"); + gtk_widget_set_halign (entry->progress_bar, GTK_ALIGN_FILL); + gtk_widget_set_valign (entry->progress_bar, GTK_ALIGN_END); + gtk_widget_show (entry->progress_bar); + gtk_overlay_add_overlay (GTK_OVERLAY (entry), entry->progress_bar); + /* Button Box */ button_box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL); gtk_box_set_homogeneous (GTK_BOX (button_box), FALSE); @@ -1371,3 +1398,72 @@ ephy_location_entry_get_reader_mode_state (EphyLocationEntry *entry) { return entry->reader_mode_active; } + +static gboolean +progress_hide (gpointer user_data) +{ + EphyLocationEntry *entry = EPHY_LOCATION_ENTRY (user_data); + + gtk_widget_hide (entry->progress_bar); + gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (entry->progress_bar), 0); + + if (entry->progress_timeout) { + g_source_remove (entry->progress_timeout); + entry->progress_timeout = 0; + } + + return G_SOURCE_REMOVE; +} + +static gboolean +ephy_location_entry_set_fraction_internal (gpointer user_data) +{ + EphyLocationEntry *entry = EPHY_LOCATION_ENTRY (user_data); + gint ms; + gdouble progress; + gdouble current; + + entry->progress_timeout = 0; + current = gtk_progress_bar_get_fraction (GTK_PROGRESS_BAR (entry->progress_bar)); + + if ((entry->progress_fraction - current) > 0.5 || entry->progress_fraction == 1.0) + ms = 10; + else + ms = 25; + + progress = current + 0.025; + if (progress < entry->progress_fraction) { + gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (entry->progress_bar), + progress); + entry->progress_timeout = g_timeout_add (ms, ephy_location_entry_set_fraction_internal, entry); + } else { + gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (entry->progress_bar), + entry->progress_fraction); + if (entry->progress_fraction == 1.0) + entry->progress_timeout = g_timeout_add (500, progress_hide, entry); + } + + return G_SOURCE_REMOVE; +} + +void +ephy_location_entry_set_progress (EphyLocationEntry *entry, + gdouble fraction, + gboolean loading) +{ + if (entry->progress_timeout) { + g_source_remove (entry->progress_timeout); + entry->progress_timeout = 0; + } + + if (!loading) { + gtk_widget_hide (entry->progress_bar); + return; + } + + if (!gtk_widget_is_visible (entry->progress_bar)) + gtk_widget_show (entry->progress_bar); + + entry->progress_fraction = fraction; + ephy_location_entry_set_fraction_internal (entry); +} diff --git a/lib/widgets/ephy-location-entry.h b/lib/widgets/ephy-location-entry.h index 013a65a8f..7056df801 100644 --- a/lib/widgets/ephy-location-entry.h +++ b/lib/widgets/ephy-location-entry.h @@ -93,4 +93,8 @@ void ephy_location_entry_set_reader_mode_state (EphyLocationEntr gboolean ephy_location_entry_get_reader_mode_state (EphyLocationEntry *entry); +void ephy_location_entry_set_progress (EphyLocationEntry *entry, + gdouble progress, + gboolean loading); + G_END_DECLS diff --git a/src/ephy-shell.c b/src/ephy-shell.c index 917b82388..d38d2450e 100644 --- a/src/ephy-shell.c +++ b/src/ephy-shell.c @@ -788,6 +788,7 @@ ephy_shell_new_tab_full (EphyShell *shell, embed = EPHY_EMBED (g_object_new (EPHY_TYPE_EMBED, "web-view", web_view, "title", title, + "progress-bar-enabled", ephy_embed_shell_get_mode (embed_shell) == EPHY_EMBED_SHELL_MODE_APPLICATION, NULL)); gtk_widget_show (GTK_WIDGET (embed)); ephy_embed_container_add_child (EPHY_EMBED_CONTAINER (window), embed, position, jump_to); diff --git a/src/ephy-window.c b/src/ephy-window.c index 3697315c4..a86fd45b2 100644 --- a/src/ephy-window.c +++ b/src/ephy-window.c @@ -2110,11 +2110,30 @@ decide_policy_cb (WebKitWebView *web_view, } static void +progress_update (WebKitWebView *web_view, + GParamSpec *pspec, + EphyWindow *window) +{ + EphyTitleWidget *title_widget; + gdouble progress; + gboolean loading; + + progress = webkit_web_view_get_estimated_load_progress (web_view); + loading = ephy_web_view_is_loading (EPHY_WEB_VIEW (web_view)); + + title_widget = ephy_header_bar_get_title_widget (EPHY_HEADER_BAR (window->header_bar)); + + ephy_location_entry_set_progress (EPHY_LOCATION_ENTRY (title_widget), progress, loading); +} + + +static void ephy_window_connect_active_embed (EphyWindow *window) { EphyEmbed *embed; WebKitWebView *web_view; EphyWebView *view; + EphyTitleWidget *title_widget; g_assert (window->active_embed != NULL); @@ -2137,6 +2156,18 @@ ephy_window_connect_active_embed (EphyWindow *window) sync_tab_zoom (web_view, NULL, window); + title_widget = ephy_header_bar_get_title_widget (EPHY_HEADER_BAR (window->header_bar)); + + if (EPHY_IS_LOCATION_ENTRY (title_widget)) { + gdouble progress = webkit_web_view_get_estimated_load_progress (web_view); + gboolean loading = ephy_web_view_is_loading (EPHY_WEB_VIEW (web_view)); + + ephy_location_entry_set_progress (EPHY_LOCATION_ENTRY (title_widget), progress, loading); + g_signal_connect_object (web_view, "notify::estimated-load-progress", + G_CALLBACK (progress_update), + window, 0); + } + g_signal_connect_object (web_view, "notify::zoom-level", G_CALLBACK (sync_tab_zoom), window, 0); @@ -2204,6 +2235,9 @@ ephy_window_disconnect_active_embed (EphyWindow *window) ephy_embed_detach_notification_container (window->active_embed); g_signal_handlers_disconnect_by_func (web_view, + G_CALLBACK (progress_update), + window); + g_signal_handlers_disconnect_by_func (web_view, G_CALLBACK (sync_tab_zoom), window); g_signal_handlers_disconnect_by_func (web_view, diff --git a/src/resources/themes/shared.css b/src/resources/themes/shared.css index e2aa4c9e9..a283bbd71 100644 --- a/src/resources/themes/shared.css +++ b/src/resources/themes/shared.css @@ -138,3 +138,23 @@ button.active-menu { border-radius: 18px; background: rgba(0, 0, 0, 0.65); color: white; } + +.url_progress { + border: none; + background-color: transparent; + background-image: none; + padding-top: 0px; + padding-bottom: 0px; + margin-top: 0px; + margin-bottom: 6px; } + +.url_progress progress { + background-color: @theme_selected_bg_color; + background-image: none; + border: none; + min-height: 2px; } + +.url_progress trough { + border: none; + background-color: transparent; + background-image: none; }
\ No newline at end of file diff --git a/src/resources/themes/shared.scss b/src/resources/themes/shared.scss index 73be89e85..c09e1eb66 100644 --- a/src/resources/themes/shared.scss +++ b/src/resources/themes/shared.scss @@ -144,3 +144,23 @@ $close_button_fg_color: lighten($fg_color, 10%); background: rgba(0, 0, 0, 0.65); color: white; } + +.url_progress { + border: none; + background-color: transparent; + background-image: none; + padding-top: 0px; + padding-bottom: 0px; + margin-top: 0px; + margin-bottom: 6px; } + +.url_progress progress { + background-color: @theme_selected_bg_color; + background-image: none; + border: none; + min-height: 2px; } + +.url_progress trough { + border: none; + background-color: transparent; + background-image: none; } |