summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McDermott <pj@pehjota.net>2017-10-13 01:40:01 (EDT)
committer Patrick McDermott <pj@pehjota.net>2017-10-13 01:40:01 (EDT)
commit95cdf910aa8056ed266f4ae1c701387c7cbe53a8 (patch)
tree54b3825750dcad6f7ede4c29dcb550a9627e5959
parent755ebc8390359a48e134f962c21550e1bda18ba4 (diff)
downloadmarquee-95cdf910aa8056ed266f4ae1c701387c7cbe53a8.zip
marquee-95cdf910aa8056ed266f4ae1c701387c7cbe53a8.tar.gz
marquee-95cdf910aa8056ed266f4ae1c701387c7cbe53a8.tar.bz2
MqTabChrome: Use MqUriEntry
-rw-r--r--src/tab-chrome.c166
-rw-r--r--src/tab-chrome.h4
2 files changed, 2 insertions, 168 deletions
diff --git a/src/tab-chrome.c b/src/tab-chrome.c
index 2472f78..9f78d75 100644
--- a/src/tab-chrome.c
+++ b/src/tab-chrome.c
@@ -28,6 +28,7 @@
#include "tab-chrome.h"
#include "tab.h"
#include "back-forward-button-box.h"
+#include "uri-entry.h"
#include "main-menu.h"
#include "find-toolbar.h"
@@ -43,16 +44,6 @@ stop_reload_clicked_cb(GtkToolButton G_GNUC_UNUSED *toolbutton,
}
static void
-uri_activate_cb(GtkEntry *entry, MqTabChrome *chrome)
-{
- const gchar *uri;
-
- uri = gtk_entry_get_text(GTK_ENTRY(entry));
-
- mq_web_view_load_uri(chrome->web_view, uri);
-}
-
-static void
home_clicked_cb(GtkToolButton G_GNUC_UNUSED *toolbutton,
MqTabChrome *chrome)
{
@@ -64,127 +55,6 @@ home_clicked_cb(GtkToolButton G_GNUC_UNUSED *toolbutton,
}
static void
-load_changed_cb(MqWebView *web_view, WebKitLoadEvent load_event,
- MqTabChrome *chrome)
-{
- const gchar *uri;
-
- switch (load_event) {
- case WEBKIT_LOAD_STARTED:
- case WEBKIT_LOAD_REDIRECTED:
- case WEBKIT_LOAD_COMMITTED:
- uri = mq_web_view_get_uri(web_view);
- gtk_entry_set_text(GTK_ENTRY(chrome->uri_entry), uri);
- gtk_entry_set_attributes(GTK_ENTRY(chrome->uri_entry),
- NULL);
- break;
- case WEBKIT_LOAD_FINISHED:
- gtk_entry_set_progress_fraction(
- GTK_ENTRY(chrome->uri_entry), 0.0);
- break;
- }
-}
-
-static gboolean
-load_failed_cb(WebKitWebView G_GNUC_UNUSED *web_view,
- WebKitLoadEvent G_GNUC_UNUSED load_event,
- gchar G_GNUC_UNUSED *failing_uri, GError G_GNUC_UNUSED *error,
- MqTabChrome *chrome)
-{
- chrome->load_failed = TRUE;
- return FALSE;
-}
-
-/* TODO: <Esc> key in URI bar should reset to URI of current hovered link, if
- * any, even if different from chrome->hovered_link_uri. */
-static void
-mouse_target_changed_cb(MqWebView G_GNUC_UNUSED *web_view,
- WebKitHitTestResult *hit_test_result, guint G_GNUC_UNUSED modifiers,
- MqTabChrome *chrome)
-{
- const gchar *uri;
-
- uri = mq_web_view_get_uri(web_view);
- if (webkit_hit_test_result_context_is_link(hit_test_result)) {
- if (gtk_widget_has_focus(chrome->uri_entry)) {
- } else if (chrome->hovered_link_uri &&
- g_strcmp0(gtk_entry_get_text(
- GTK_ENTRY(chrome->uri_entry)),
- chrome->hovered_link_uri) != 0) {
- /* The user has edited the hovered link URI in the URI
- * bar. */
- } else if (g_strcmp0(gtk_entry_get_text(
- GTK_ENTRY(chrome->uri_entry)), uri) ==
- 0) {
- g_free(chrome->hovered_link_uri);
- chrome->hovered_link_uri = g_strdup(
- webkit_hit_test_result_get_link_uri(
- hit_test_result));
- gtk_entry_set_text(GTK_ENTRY(chrome->uri_entry),
- chrome->hovered_link_uri);
- gtk_entry_set_attributes(GTK_ENTRY(chrome->uri_entry),
- chrome->hovered_link_style);
- } else if (gtk_entry_get_attributes(
- GTK_ENTRY(chrome->uri_entry)) ==
- chrome->hovered_link_style) {
- /* The URI bar's text differs from the Web view's URI
- * because the mouse was already targeting a different
- * link. */
- g_free(chrome->hovered_link_uri);
- chrome->hovered_link_uri = g_strdup(
- webkit_hit_test_result_get_link_uri(
- hit_test_result));
- gtk_entry_set_text(GTK_ENTRY(chrome->uri_entry),
- chrome->hovered_link_uri);
- }
- } else if (gtk_entry_get_attributes(GTK_ENTRY(chrome->uri_entry)) ==
- chrome->hovered_link_style) {
- if (gtk_widget_has_focus(chrome->uri_entry)) {
- } else if (g_strcmp0(gtk_entry_get_text(
- GTK_ENTRY(chrome->uri_entry)),
- chrome->hovered_link_uri) == 0) {
- /* The user hasn't edited the hovered link URI in the
- * URI bar. */
- g_free(chrome->hovered_link_uri);
- chrome->hovered_link_uri = NULL;
- gtk_entry_set_text(GTK_ENTRY(chrome->uri_entry), uri);
- gtk_entry_set_attributes(GTK_ENTRY(chrome->uri_entry),
- NULL);
- }
- }
-}
-
-static void
-load_progress_cb(WebKitWebView *web_view, GParamSpec G_GNUC_UNUSED *paramspec,
- MqTabChrome *chrome)
-{
- /*
- * If loading fails, the WebKitWebView's "estimated-load-progress" is
- * set to 1.0 after signals like "load-changed" and "load-failed" are
- * emitted. So the only way to avoid leaving behind a full progress bar
- * after, for example, canceling a page load is to save a flag on a
- * failed load and only update the progress bar if the flag is unset.
- */
- if (chrome->load_failed) {
- chrome->load_failed = FALSE;
- return;
- }
- gtk_entry_set_progress_fraction(GTK_ENTRY(chrome->uri_entry),
- webkit_web_view_get_estimated_load_progress(web_view));
-}
-
-static void
-uri_cb(MqWebView *web_view, GParamSpec G_GNUC_UNUSED *paramspec,
- MqTabChrome *chrome)
-{
- const gchar *uri;
-
- uri = mq_web_view_get_uri(web_view);
- gtk_entry_set_text(GTK_ENTRY(chrome->uri_entry), uri);
- gtk_entry_set_attributes(GTK_ENTRY(chrome->uri_entry), NULL);
-}
-
-static void
loading_cb(MqWebView *web_view, GParamSpec G_GNUC_UNUSED *paramspec,
MqTabChrome *chrome)
{
@@ -246,28 +116,9 @@ navigation_toolbar_new(MqTabChrome *chrome, const gchar *uri)
gtk_toolbar_insert(navigation_toolbar, chrome->stop_reload_button, -1);
/* URI bar */
- uri_tool_item = gtk_tool_item_new();
- chrome->uri_entry = gtk_entry_new();
- if (uri) {
- gtk_entry_set_text(GTK_ENTRY(chrome->uri_entry), uri);
- }
- gtk_entry_set_placeholder_text(GTK_ENTRY(chrome->uri_entry),
- "URI...");
- gtk_entry_set_icon_from_icon_name(GTK_ENTRY(chrome->uri_entry),
- GTK_ENTRY_ICON_PRIMARY, "text-x-generic");
- gtk_entry_set_progress_fraction(GTK_ENTRY(chrome->uri_entry), 0.0);
- g_signal_connect(chrome->uri_entry, "activate",
- G_CALLBACK(uri_activate_cb), chrome);
- gtk_container_add(GTK_CONTAINER(uri_tool_item),
- chrome->uri_entry);
- gtk_tool_item_set_expand(uri_tool_item, TRUE);
+ uri_tool_item = mq_uri_entry_new(chrome->web_view, uri);
gtk_toolbar_insert(navigation_toolbar, uri_tool_item, -1);
- /* URI bar hovered link style */
- chrome->hovered_link_style = pango_attr_list_new();
- pango_attr_list_insert(chrome->hovered_link_style,
- pango_attr_style_new(PANGO_STYLE_ITALIC));
-
/* Home button */
home_button = gtk_tool_button_new(gtk_image_new_from_icon_name(
"go-home", GTK_ICON_SIZE_SMALL_TOOLBAR), "Home");
@@ -284,19 +135,6 @@ navigation_toolbar_new(MqTabChrome *chrome, const gchar *uri)
gtk_widget_set_hexpand(GTK_WIDGET(navigation_toolbar), TRUE);
- chrome->load_failed = FALSE;
- chrome->hovered_link_uri = NULL;
-
- g_signal_connect(chrome->web_view, "load-changed",
- G_CALLBACK(load_changed_cb), chrome);
- g_signal_connect(chrome->web_view, "load-failed",
- G_CALLBACK(load_failed_cb), chrome);
- g_signal_connect(chrome->web_view, "mouse-target-changed",
- G_CALLBACK(mouse_target_changed_cb), chrome);
- g_signal_connect(chrome->web_view, "notify::estimated-load-progress",
- G_CALLBACK(load_progress_cb), chrome);
- g_signal_connect(chrome->web_view, "notify::rewritten-uri",
- G_CALLBACK(uri_cb), chrome);
g_signal_connect(chrome->web_view, "notify::is-loading",
G_CALLBACK(loading_cb), chrome);
diff --git a/src/tab-chrome.h b/src/tab-chrome.h
index b5e434a..e8293ea 100644
--- a/src/tab-chrome.h
+++ b/src/tab-chrome.h
@@ -38,12 +38,8 @@ struct MqTabChrome {
GtkWidget *stop_icon;
GtkWidget *reload_icon;
GtkToolItem *stop_reload_button;
- GtkWidget *uri_entry;
- PangoAttrList *hovered_link_style;
MqFindToolbar *find_toolbar;
MqWebView *web_view;
- gboolean load_failed;
- gchar *hovered_link_uri;
};
MqTabChrome *