Commit 250bb7f8 authored by Jan-Michael Brummer's avatar Jan-Michael Brummer Committed by Michael Catanzaro

Move progress bar into url box

Moving loading progress bar into url box for EphyLocationEntry widgets. App mode keeps
progress bar within embed widget.
parent 2d166afc
...@@ -87,6 +87,7 @@ struct _EphyEmbed { ...@@ -87,6 +87,7 @@ struct _EphyEmbed {
gulong status_handler_id; gulong status_handler_id;
gulong progress_update_handler_id; gulong progress_update_handler_id;
gboolean inspector_loaded; gboolean inspector_loaded;
gboolean progress_bar_enabled;
}; };
G_DEFINE_TYPE (EphyEmbed, ephy_embed, GTK_TYPE_BOX) G_DEFINE_TYPE (EphyEmbed, ephy_embed, GTK_TYPE_BOX)
...@@ -95,6 +96,7 @@ enum { ...@@ -95,6 +96,7 @@ enum {
PROP_0, PROP_0,
PROP_WEB_VIEW, PROP_WEB_VIEW,
PROP_TITLE, PROP_TITLE,
PROP_PROGRESS_BAR_ENABLED,
LAST_PROP LAST_PROP
}; };
...@@ -444,6 +446,9 @@ ephy_embed_set_property (GObject *object, ...@@ -444,6 +446,9 @@ ephy_embed_set_property (GObject *object,
case PROP_TITLE: case PROP_TITLE:
ephy_embed_set_title (embed, g_value_get_string (value)); ephy_embed_set_title (embed, g_value_get_string (value));
break; break;
case PROP_PROGRESS_BAR_ENABLED:
embed->progress_bar_enabled = g_value_get_boolean (value);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
...@@ -465,6 +470,9 @@ ephy_embed_get_property (GObject *object, ...@@ -465,6 +470,9 @@ ephy_embed_get_property (GObject *object,
case PROP_TITLE: case PROP_TITLE:
g_value_set_string (value, ephy_embed_get_title (embed)); g_value_set_string (value, ephy_embed_get_title (embed));
break; break;
case PROP_PROGRESS_BAR_ENABLED:
g_value_set_boolean (value, embed->progress_bar_enabled);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
...@@ -507,6 +515,13 @@ ephy_embed_class_init (EphyEmbedClass *klass) ...@@ -507,6 +515,13 @@ ephy_embed_class_init (EphyEmbedClass *klass)
NULL, NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); 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); g_object_class_install_properties (object_class, LAST_PROP, obj_properties);
} }
...@@ -736,12 +751,14 @@ ephy_embed_constructed (GObject *object) ...@@ -736,12 +751,14 @@ ephy_embed_constructed (GObject *object)
gtk_overlay_add_overlay (GTK_OVERLAY (embed->overlay), embed->floating_bar); gtk_overlay_add_overlay (GTK_OVERLAY (embed->overlay), embed->floating_bar);
if (embed->progress_bar_enabled) {
embed->progress = gtk_progress_bar_new (); embed->progress = gtk_progress_bar_new ();
gtk_style_context_add_class (gtk_widget_get_style_context (embed->progress), gtk_style_context_add_class (gtk_widget_get_style_context (embed->progress),
GTK_STYLE_CLASS_OSD); GTK_STYLE_CLASS_OSD);
gtk_widget_set_halign (embed->progress, GTK_ALIGN_FILL); gtk_widget_set_halign (embed->progress, GTK_ALIGN_FILL);
gtk_widget_set_valign (embed->progress, GTK_ALIGN_START); gtk_widget_set_valign (embed->progress, GTK_ALIGN_START);
gtk_overlay_add_overlay (GTK_OVERLAY (embed->overlay), embed->progress); gtk_overlay_add_overlay (GTK_OVERLAY (embed->overlay), embed->progress);
}
embed->find_toolbar = ephy_find_toolbar_new (embed->web_view); embed->find_toolbar = ephy_find_toolbar_new (embed->web_view);
g_signal_connect (embed->find_toolbar, "close", g_signal_connect (embed->find_toolbar, "close",
...@@ -754,8 +771,10 @@ ephy_embed_constructed (GObject *object) ...@@ -754,8 +771,10 @@ ephy_embed_constructed (GObject *object)
paned = GTK_WIDGET (embed->paned); paned = GTK_WIDGET (embed->paned);
if (embed->progress_bar_enabled)
embed->progress_update_handler_id = g_signal_connect (embed->web_view, "notify::estimated-load-progress", embed->progress_update_handler_id = g_signal_connect (embed->web_view, "notify::estimated-load-progress",
G_CALLBACK (progress_update), object); G_CALLBACK (progress_update), object);
gtk_paned_pack1 (GTK_PANED (paned), GTK_WIDGET (embed->overlay), gtk_paned_pack1 (GTK_PANED (paned), GTK_WIDGET (embed->overlay),
TRUE, FALSE); TRUE, FALSE);
......
...@@ -57,6 +57,7 @@ struct _EphyLocationEntry { ...@@ -57,6 +57,7 @@ struct _EphyLocationEntry {
GtkOverlay parent_instance; GtkOverlay parent_instance;
GtkWidget *url_entry; GtkWidget *url_entry;
GtkWidget *progress_bar;
GtkWidget *bookmark; GtkWidget *bookmark;
GtkWidget *bookmark_event_box; GtkWidget *bookmark_event_box;
GtkWidget *reader_mode; GtkWidget *reader_mode;
...@@ -84,6 +85,9 @@ struct _EphyLocationEntry { ...@@ -84,6 +85,9 @@ struct _EphyLocationEntry {
guint hash; guint hash;
guint progress_timeout;
gdouble progress_fraction;
gulong dns_prefetch_handler; gulong dns_prefetch_handler;
guint user_changed : 1; guint user_changed : 1;
...@@ -367,6 +371,20 @@ ephy_location_entry_title_widget_interface_init (EphyTitleWidgetInterface *iface ...@@ -367,6 +371,20 @@ ephy_location_entry_title_widget_interface_init (EphyTitleWidgetInterface *iface
iface->set_security_level = ephy_location_entry_title_widget_set_security_level; iface->set_security_level = ephy_location_entry_title_widget_set_security_level;
} }
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 static void
ephy_location_entry_class_init (EphyLocationEntryClass *klass) ephy_location_entry_class_init (EphyLocationEntryClass *klass)
{ {
...@@ -377,6 +395,7 @@ ephy_location_entry_class_init (EphyLocationEntryClass *klass) ...@@ -377,6 +395,7 @@ ephy_location_entry_class_init (EphyLocationEntryClass *klass)
object_class->set_property = ephy_location_entry_set_property; object_class->set_property = ephy_location_entry_set_property;
object_class->constructed = ephy_location_entry_constructed; object_class->constructed = ephy_location_entry_constructed;
object_class->finalize = ephy_location_entry_finalize; 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_width = ephy_location_entry_get_preferred_width;
widget_class->get_preferred_height = ephy_location_entry_get_preferred_height; widget_class->get_preferred_height = ephy_location_entry_get_preferred_height;
...@@ -783,6 +802,14 @@ ephy_location_entry_construct_contents (EphyLocationEntry *entry) ...@@ -783,6 +802,14 @@ ephy_location_entry_construct_contents (EphyLocationEntry *entry)
gtk_widget_show (entry->url_entry); gtk_widget_show (entry->url_entry);
gtk_overlay_add_overlay (GTK_OVERLAY (entry), 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 */
button_box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL); button_box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
gtk_box_set_homogeneous (GTK_BOX (button_box), FALSE); gtk_box_set_homogeneous (GTK_BOX (button_box), FALSE);
...@@ -1371,3 +1398,72 @@ ephy_location_entry_get_reader_mode_state (EphyLocationEntry *entry) ...@@ -1371,3 +1398,72 @@ ephy_location_entry_get_reader_mode_state (EphyLocationEntry *entry)
{ {
return entry->reader_mode_active; 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);
}
...@@ -93,4 +93,8 @@ void ephy_location_entry_set_reader_mode_state (EphyLocationEntr ...@@ -93,4 +93,8 @@ void ephy_location_entry_set_reader_mode_state (EphyLocationEntr
gboolean ephy_location_entry_get_reader_mode_state (EphyLocationEntry *entry); 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 G_END_DECLS
...@@ -788,6 +788,7 @@ ephy_shell_new_tab_full (EphyShell *shell, ...@@ -788,6 +788,7 @@ ephy_shell_new_tab_full (EphyShell *shell,
embed = EPHY_EMBED (g_object_new (EPHY_TYPE_EMBED, embed = EPHY_EMBED (g_object_new (EPHY_TYPE_EMBED,
"web-view", web_view, "web-view", web_view,
"title", title, "title", title,
"progress-bar-enabled", ephy_embed_shell_get_mode (embed_shell) == EPHY_EMBED_SHELL_MODE_APPLICATION,
NULL)); NULL));
gtk_widget_show (GTK_WIDGET (embed)); gtk_widget_show (GTK_WIDGET (embed));
ephy_embed_container_add_child (EPHY_EMBED_CONTAINER (window), embed, position, jump_to); ephy_embed_container_add_child (EPHY_EMBED_CONTAINER (window), embed, position, jump_to);
......
...@@ -2109,12 +2109,31 @@ decide_policy_cb (WebKitWebView *web_view, ...@@ -2109,12 +2109,31 @@ decide_policy_cb (WebKitWebView *web_view,
return decide_navigation_policy (web_view, decision, decision_type, window); return decide_navigation_policy (web_view, decision, decision_type, window);
} }
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 static void
ephy_window_connect_active_embed (EphyWindow *window) ephy_window_connect_active_embed (EphyWindow *window)
{ {
EphyEmbed *embed; EphyEmbed *embed;
WebKitWebView *web_view; WebKitWebView *web_view;
EphyWebView *view; EphyWebView *view;
EphyTitleWidget *title_widget;
g_assert (window->active_embed != NULL); g_assert (window->active_embed != NULL);
...@@ -2137,6 +2156,18 @@ ephy_window_connect_active_embed (EphyWindow *window) ...@@ -2137,6 +2156,18 @@ ephy_window_connect_active_embed (EphyWindow *window)
sync_tab_zoom (web_view, NULL, 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_signal_connect_object (web_view, "notify::zoom-level",
G_CALLBACK (sync_tab_zoom), G_CALLBACK (sync_tab_zoom),
window, 0); window, 0);
...@@ -2203,6 +2234,9 @@ ephy_window_disconnect_active_embed (EphyWindow *window) ...@@ -2203,6 +2234,9 @@ ephy_window_disconnect_active_embed (EphyWindow *window)
ephy_embed_detach_notification_container (window->active_embed); 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_signal_handlers_disconnect_by_func (web_view,
G_CALLBACK (sync_tab_zoom), G_CALLBACK (sync_tab_zoom),
window); window);
......
...@@ -138,3 +138,23 @@ button.active-menu { ...@@ -138,3 +138,23 @@ button.active-menu {
border-radius: 18px; border-radius: 18px;
background: rgba(0, 0, 0, 0.65); background: rgba(0, 0, 0, 0.65);
color: white; } 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
...@@ -144,3 +144,23 @@ $close_button_fg_color: lighten($fg_color, 10%); ...@@ -144,3 +144,23 @@ $close_button_fg_color: lighten($fg_color, 10%);
background: rgba(0, 0, 0, 0.65); background: rgba(0, 0, 0, 0.65);
color: white; 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; }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment